mbed Sensor node for Instrumented Booth over ETH.

Dependencies:   EthernetInterface-1 MaxbotixDriver Presence HTU21D_TEMP_HUMID_SENSOR_SAMPLE Resources SHARPIR mbed-rtos mbed-src WDT_K64F nsdl_lib

Fork of Trenton_Switch_LPC1768_ETH by Demo Team

Committer:
erigow01
Date:
Tue May 12 10:57:33 2015 +0000
Revision:
44:f70163204018
Parent:
40:b2e9bc654ca1
Child:
45:d7b4b57574a0
Computex Updates.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andcor02 25:cb16c5248769 1 /** Implements Sensor Control for CES Instrumented Booth */
andcor02 25:cb16c5248769 2
andcor02 25:cb16c5248769 3 #include "mbed.h"
andcor02 25:cb16c5248769 4 #include "sensor_ctl.h"
erigow01 26:4cac6b346e4f 5 #include "node_cfg.h"
andcor02 25:cb16c5248769 6
andcor02 25:cb16c5248769 7 //Sensor Drivers
andcor02 25:cb16c5248769 8 #include "RHT03.h"
andcor02 25:cb16c5248769 9 #include "MAX9814.h"
andcor02 25:cb16c5248769 10 #include "sonar.h"
erigow01 27:6017a643f386 11 #include "Presence.h"
andcor02 25:cb16c5248769 12 #include "SHARPIR.h"
andcor02 40:b2e9bc654ca1 13 #include "DoorTrip.h"
erigow01 44:f70163204018 14 #include "FXOS8700Q.h"
andcor02 25:cb16c5248769 15
andcor02 25:cb16c5248769 16 //Sensor MDS Resources
andcor02 25:cb16c5248769 17 #include "door_trip.h"
andcor02 25:cb16c5248769 18 #include "height.h"
erigow01 27:6017a643f386 19 #include "presence_resource.h"
andcor02 25:cb16c5248769 20 #include "sound_level.h"
andcor02 25:cb16c5248769 21 #include "temperature.h"
erigow01 44:f70163204018 22 #include "accelerometer.h"
erigow01 44:f70163204018 23
andcor02 25:cb16c5248769 24
andcor02 25:cb16c5248769 25 //Common Sensors
erigow01 27:6017a643f386 26 #if NODE_SENSOR_STATION
andcor02 25:cb16c5248769 27 RHT03 temperature(PTB2);
andcor02 25:cb16c5248769 28 MAX9814 microphone(PTB3); //Analogue in required.
erigow01 27:6017a643f386 29 #if NODE_PIR_STATION
andcor02 40:b2e9bc654ca1 30 presence pir(PTB11, false, PIR_SENSOR_DEBOUNCE_MS); //(InterruptPin), for PIR sensor,
erigow01 27:6017a643f386 31 #endif //NODE PIR STATION
erigow01 27:6017a643f386 32 #if NODE_KIOSK_STATION
andcor02 40:b2e9bc654ca1 33 presence kiosk(PTB10, true, KIOSK_SENSOR_DEBOUNCE_MS); //(Interrupt pinrequired, no timeout)
erigow01 27:6017a643f386 34 #endif //NODE KIOSK STATION
erigow01 27:6017a643f386 35 #if NODE_DOOR_TRIP_STATION
erigow01 44:f70163204018 36 DoorTrip laser(PTC11, true, DOOR_SENSOR_DEBOUNCE_MS ); //(AnalogIn required), for IR door trip
erigow01 27:6017a643f386 37 #endif //NODE TRIP STATION
erigow01 27:6017a643f386 38 #if NODE_HEIGHT_STATION
erigow01 32:c957a1948ac1 39 Timer sonarTimer;
erigow01 32:c957a1948ac1 40 Timer debounceHeight;
erigow01 32:c957a1948ac1 41 Sonar sonar(PTC10, sonarTimer); //(AnalogIn required, Leave as SW2.)
erigow01 32:c957a1948ac1 42
erigow01 32:c957a1948ac1 43 #define DOOR_HEIGHT_START_MEASURING_THRESHOLD_CM 150
erigow01 32:c957a1948ac1 44 #define DOOR_HEIGHT_STOP_MEASURING_THRESHOLD_CM 140
erigow01 32:c957a1948ac1 45 #define DOOR_HEIGHT_STOP_MEASURING_SAMPLE_COUNT 2
erigow01 32:c957a1948ac1 46 #define DOOR_HEIGHT_SENSOR_MOUNT_HEIGHT_CM 220
erigow01 27:6017a643f386 47 #endif //NODE HEIGHT STATION
erigow01 44:f70163204018 48 #if NODE_ACCELEROMETER_STATION
erigow01 44:f70163204018 49 FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
erigow01 44:f70163204018 50 #endif //NODE ACCELEROMETER STATION
erigow01 27:6017a643f386 51 #endif //NODE_SENSOR_STATION
andcor02 25:cb16c5248769 52
andcor02 25:cb16c5248769 53
andcor02 25:cb16c5248769 54 //Variables provided to rest of applications
erigow01 44:f70163204018 55 float current_temperature_value = 0;
erigow01 26:4cac6b346e4f 56 float current_ambient_noise_value = 0;
erigow01 44:f70163204018 57 float current_ambient_noise_sum = 0;
erigow01 44:f70163204018 58 int current_ambient_noise_count = 0;
andcor02 25:cb16c5248769 59 //Either height XOR kiosk presence XOR PIR station...
andcor02 30:b74aa0729b07 60 float current_height_value = 0;
erigow01 26:4cac6b346e4f 61 bool current_presence_value = false; //Either from Kiosk or PIR
andcor02 25:cb16c5248769 62 //And it might have a door trip..
erigow01 26:4cac6b346e4f 63 bool current_door_trip_value = false;
erigow01 44:f70163204018 64 bool current_accelerometer_value = false;
erigow01 26:4cac6b346e4f 65
erigow01 31:389416beb4c3 66 //Door trip...
erigow01 26:4cac6b346e4f 67 float door_trip_starting_volts = 0;
erigow01 44:f70163204018 68 float maxValue=0;
erigow01 44:f70163204018 69 bool set=0;
erigow01 32:c957a1948ac1 70
erigow01 32:c957a1948ac1 71 //Door Height...
erigow01 32:c957a1948ac1 72 float door_height_max_value = 0;
erigow01 32:c957a1948ac1 73 bool door_height_measuring = 0;
andcor02 33:d39c30e9264b 74 int door_height_sample_count = 0;
erigow01 31:389416beb4c3 75
andcor02 25:cb16c5248769 76 //Initialisation
andcor02 25:cb16c5248769 77 void init_sensors() {
erigow01 44:f70163204018 78 // #if NODE_DOOR_TRIP_STATION
erigow01 44:f70163204018 79 // door_trip_starting_volts = sharpir.volt();
erigow01 44:f70163204018 80 // #endif
erigow01 44:f70163204018 81 #if NODE_PIR_STATION
erigow01 44:f70163204018 82 wait(2); //Wait 2 seconds for sensor calibration period.
erigow01 44:f70163204018 83 #endif //PIR STATION
erigow01 44:f70163204018 84 #if NODE_ACCELEROMETER_STATION
erigow01 44:f70163204018 85 acc.enable();
erigow01 26:4cac6b346e4f 86 #endif
erigow01 32:c957a1948ac1 87 #if NODE_HEIGHT_STATION
erigow01 32:c957a1948ac1 88 sonarTimer.start();
erigow01 32:c957a1948ac1 89 #endif
andcor02 25:cb16c5248769 90 }
andcor02 25:cb16c5248769 91
erigow01 27:6017a643f386 92 #if NODE_SENSOR_STATION
erigow01 27:6017a643f386 93
andcor02 25:cb16c5248769 94 //timer handler functions
andcor02 25:cb16c5248769 95 void handle_temperature_report_timer() {
andcor02 25:cb16c5248769 96 if(temperature.readData() == RHT_ERROR_NONE) {
andcor02 25:cb16c5248769 97 //Only report valid data...
andcor02 25:cb16c5248769 98 current_temperature_value = temperature.getTemperatureC();
andcor02 25:cb16c5248769 99 printf("Temperature Sample: %2.2f\r\n", current_temperature_value);
erigow01 26:4cac6b346e4f 100 temperature_report();
andcor02 25:cb16c5248769 101 } else {
andcor02 25:cb16c5248769 102 printf("Temperature Sampleing Failure\r\n");
andcor02 25:cb16c5248769 103 }
andcor02 25:cb16c5248769 104 }
andcor02 25:cb16c5248769 105
erigow01 44:f70163204018 106 void handle_microphone_sample_timer(){
andcor02 25:cb16c5248769 107 float sample = microphone.sound_level();
erigow01 26:4cac6b346e4f 108 //printf("Sound Sample: %2.2f\r\n", sample);
erigow01 44:f70163204018 109 //Keep running sum and sample count to compute average...
erigow01 44:f70163204018 110 current_ambient_noise_sum += sample;
erigow01 44:f70163204018 111 current_ambient_noise_count++;
erigow01 44:f70163204018 112 current_ambient_noise_value = current_ambient_noise_sum / current_ambient_noise_count;
erigow01 44:f70163204018 113 // if (sample > current_ambient_noise_value){
erigow01 44:f70163204018 114 // current_ambient_noise_value = sample;
erigow01 44:f70163204018 115 // }
andcor02 25:cb16c5248769 116 }
andcor02 25:cb16c5248769 117
erigow01 44:f70163204018 118 void handle_microphone_report_timer(){
andcor02 25:cb16c5248769 119 //Report.
erigow01 26:4cac6b346e4f 120 sound_level_report();
andcor02 25:cb16c5248769 121 //Reset noise...
andcor02 25:cb16c5248769 122 current_ambient_noise_value = 0;
erigow01 44:f70163204018 123 current_ambient_noise_sum = 0;
erigow01 44:f70163204018 124 current_ambient_noise_count = 0;
andcor02 25:cb16c5248769 125 }
andcor02 25:cb16c5248769 126
erigow01 27:6017a643f386 127 #if NODE_PIR_STATION
erigow01 26:4cac6b346e4f 128 void handle_motion_report_timer(){
erigow01 27:6017a643f386 129 bool new_pir = pir.isPresent();
erigow01 26:4cac6b346e4f 130 //printf("PIR Sample: %d\r\n", new_pir);
erigow01 26:4cac6b346e4f 131 //printf("Old PIR Sample: %d\r\n", current_presence_value);
erigow01 26:4cac6b346e4f 132 if(new_pir != current_presence_value) {
erigow01 26:4cac6b346e4f 133 //printf("Reporting PIR...\r\n");
erigow01 26:4cac6b346e4f 134 current_presence_value = new_pir;
erigow01 27:6017a643f386 135 presence_report();
erigow01 26:4cac6b346e4f 136 }
erigow01 26:4cac6b346e4f 137 }
erigow01 27:6017a643f386 138 #endif //NODE_PIR_STATION
erigow01 26:4cac6b346e4f 139
erigow01 27:6017a643f386 140 #if NODE_KIOSK_STATION
erigow01 26:4cac6b346e4f 141 void handle_kiosk_report_timer(){
erigow01 27:6017a643f386 142 bool new_kiosk = kiosk.isPresent();
erigow01 26:4cac6b346e4f 143 if(new_kiosk != current_presence_value) {
erigow01 26:4cac6b346e4f 144 current_presence_value = new_kiosk;
erigow01 27:6017a643f386 145 presence_report();
erigow01 26:4cac6b346e4f 146 }
erigow01 26:4cac6b346e4f 147 }
erigow01 27:6017a643f386 148 #endif //NODE_KIOSK_STATION
erigow01 26:4cac6b346e4f 149
erigow01 27:6017a643f386 150 #if NODE_DOOR_TRIP_STATION
erigow01 26:4cac6b346e4f 151 void handle_door_trip_report_timer(){
andcor02 40:b2e9bc654ca1 152 bool new_laser = laser.isPresent();
andcor02 40:b2e9bc654ca1 153
andcor02 40:b2e9bc654ca1 154 if(new_laser != current_door_trip_value) {
andcor02 40:b2e9bc654ca1 155 current_door_trip_value = new_laser;
erigow01 26:4cac6b346e4f 156 door_trip_report();
erigow01 26:4cac6b346e4f 157 }
erigow01 26:4cac6b346e4f 158 }
erigow01 27:6017a643f386 159 #endif //NODE_DOOR_TRIP_STATION
erigow01 26:4cac6b346e4f 160
erigow01 27:6017a643f386 161 #if NODE_HEIGHT_STATION
andcor02 29:9599a156f78b 162 void handle_door_height_sample_timer(){
erigow01 32:c957a1948ac1 163 int height_sample = DOOR_HEIGHT_SENSOR_MOUNT_HEIGHT_CM-sonar.read();
erigow01 32:c957a1948ac1 164 if(height_sample > DOOR_HEIGHT_START_MEASURING_THRESHOLD_CM) {
erigow01 32:c957a1948ac1 165 door_height_sample_count=0;
erigow01 32:c957a1948ac1 166 if (height_sample > door_height_max_value) {
erigow01 32:c957a1948ac1 167 door_height_max_value = height_sample;
erigow01 32:c957a1948ac1 168 }
erigow01 32:c957a1948ac1 169 door_height_measuring=true;
andcor02 29:9599a156f78b 170 }
andcor02 29:9599a156f78b 171
erigow01 32:c957a1948ac1 172 if((height_sample < DOOR_HEIGHT_STOP_MEASURING_THRESHOLD_CM && door_height_measuring )){
erigow01 32:c957a1948ac1 173 door_height_sample_count++;
erigow01 32:c957a1948ac1 174 if (door_height_sample_count > DOOR_HEIGHT_STOP_MEASURING_SAMPLE_COUNT){
erigow01 32:c957a1948ac1 175 current_height_value=door_height_max_value;
erigow01 32:c957a1948ac1 176 door_height_max_value=0,door_height_measuring=false;
erigow01 32:c957a1948ac1 177 door_height_sample_count = 0;
erigow01 32:c957a1948ac1 178 height_report();
erigow01 32:c957a1948ac1 179 }
andcor02 29:9599a156f78b 180 }
andcor02 25:cb16c5248769 181 }
erigow01 32:c957a1948ac1 182 #endif //NODE HEIGHT STATION
andcor02 25:cb16c5248769 183
erigow01 44:f70163204018 184 #if NODE_ACCELEROMETER_STATION
erigow01 44:f70163204018 185 void handle_accelerometer_report_timer(){
erigow01 44:f70163204018 186 bool new_accelerometer = acc.get_values();
erigow01 44:f70163204018 187 if(new_accelerometer != current_accelerometer_value) {
erigow01 44:f70163204018 188
erigow01 44:f70163204018 189 current_accelerometer_value = new_accelerometer;
erigow01 44:f70163204018 190 accelerometer_report();
erigow01 44:f70163204018 191 }
erigow01 44:f70163204018 192
erigow01 44:f70163204018 193 }
erigow01 44:f70163204018 194 #endif //NODE_ACCELEROMETER_STATION
erigow01 44:f70163204018 195
erigow01 27:6017a643f386 196 #endif //NODE_SENSOR_STATION