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
sensor_ctl.cpp@31:389416beb4c3, 2014-12-09 (annotated)
- Committer:
- erigow01
- Date:
- Tue Dec 09 11:41:28 2014 +0000
- Revision:
- 31:389416beb4c3
- Parent:
- 30:b74aa0729b07
- Child:
- 32:c957a1948ac1
Updates.
Who changed what in which revision?
User | Revision | Line number | New 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 | 25:cb16c5248769 | 13 | |
andcor02 | 25:cb16c5248769 | 14 | //Sensor MDS Resources |
andcor02 | 25:cb16c5248769 | 15 | #include "door_trip.h" |
andcor02 | 25:cb16c5248769 | 16 | #include "height.h" |
erigow01 | 27:6017a643f386 | 17 | #include "presence_resource.h" |
andcor02 | 25:cb16c5248769 | 18 | #include "sound_level.h" |
andcor02 | 25:cb16c5248769 | 19 | #include "temperature.h" |
andcor02 | 25:cb16c5248769 | 20 | |
andcor02 | 25:cb16c5248769 | 21 | //Common Sensors |
erigow01 | 27:6017a643f386 | 22 | #if NODE_SENSOR_STATION |
andcor02 | 25:cb16c5248769 | 23 | RHT03 temperature(PTB2); |
andcor02 | 25:cb16c5248769 | 24 | MAX9814 microphone(PTB3); //Analogue in required. |
erigow01 | 27:6017a643f386 | 25 | #if NODE_PIR_STATION |
erigow01 | 28:908a6f58aa7f | 26 | Presence pir(PTB11, false, PIR_SENSOR_DEBOUNCE_MS); //(InterruptPin), for PIR sensor, |
erigow01 | 27:6017a643f386 | 27 | #endif //NODE PIR STATION |
erigow01 | 27:6017a643f386 | 28 | #if NODE_KIOSK_STATION |
erigow01 | 28:908a6f58aa7f | 29 | Presence kiosk(PTB10, true, KIOSK_SENSOR_DEBOUNCE_MS); //(Interrupt pinrequired, no timeout) |
erigow01 | 27:6017a643f386 | 30 | #endif //NODE KIOSK STATION |
erigow01 | 27:6017a643f386 | 31 | #if NODE_DOOR_TRIP_STATION |
erigow01 | 27:6017a643f386 | 32 | SHARPIR sharpir(PTC11); //(AnalogIn required), for IR door trip |
erigow01 | 27:6017a643f386 | 33 | #endif //NODE TRIP STATION |
erigow01 | 27:6017a643f386 | 34 | #if NODE_HEIGHT_STATION |
andcor02 | 30:b74aa0729b07 | 35 | MAXBOTIX Sonar(PTC10, SW2); //(AnalogIn required, Leave as SW2.) |
erigow01 | 27:6017a643f386 | 36 | #endif //NODE HEIGHT STATION |
erigow01 | 27:6017a643f386 | 37 | #endif //NODE_SENSOR_STATION |
andcor02 | 25:cb16c5248769 | 38 | |
andcor02 | 25:cb16c5248769 | 39 | |
andcor02 | 25:cb16c5248769 | 40 | //Variables provided to rest of applications |
erigow01 | 26:4cac6b346e4f | 41 | float current_temperature_value = 0; |
erigow01 | 26:4cac6b346e4f | 42 | float current_ambient_noise_value = 0; |
andcor02 | 25:cb16c5248769 | 43 | //Either height XOR kiosk presence XOR PIR station... |
andcor02 | 30:b74aa0729b07 | 44 | float current_height_value = 0; |
erigow01 | 26:4cac6b346e4f | 45 | bool current_presence_value = false; //Either from Kiosk or PIR |
andcor02 | 25:cb16c5248769 | 46 | //And it might have a door trip.. |
erigow01 | 26:4cac6b346e4f | 47 | bool current_door_trip_value = false; |
erigow01 | 26:4cac6b346e4f | 48 | |
erigow01 | 31:389416beb4c3 | 49 | //Door trip... |
erigow01 | 26:4cac6b346e4f | 50 | float door_trip_starting_volts = 0; |
erigow01 | 31:389416beb4c3 | 51 | float maxValue=0; |
erigow01 | 31:389416beb4c3 | 52 | bool set=0; |
erigow01 | 31:389416beb4c3 | 53 | |
erigow01 | 31:389416beb4c3 | 54 | |
andcor02 | 25:cb16c5248769 | 55 | //Initialisation |
andcor02 | 25:cb16c5248769 | 56 | void init_sensors() { |
erigow01 | 26:4cac6b346e4f | 57 | #if NODE_DOOR_TRIP_STATION |
erigow01 | 26:4cac6b346e4f | 58 | door_trip_starting_volts = sharpir.volt(); |
erigow01 | 26:4cac6b346e4f | 59 | #endif |
andcor02 | 25:cb16c5248769 | 60 | } |
andcor02 | 25:cb16c5248769 | 61 | |
erigow01 | 27:6017a643f386 | 62 | #if NODE_SENSOR_STATION |
erigow01 | 27:6017a643f386 | 63 | |
andcor02 | 25:cb16c5248769 | 64 | //timer handler functions |
andcor02 | 25:cb16c5248769 | 65 | void handle_temperature_report_timer() { |
andcor02 | 25:cb16c5248769 | 66 | if(temperature.readData() == RHT_ERROR_NONE) { |
andcor02 | 25:cb16c5248769 | 67 | //Only report valid data... |
andcor02 | 25:cb16c5248769 | 68 | current_temperature_value = temperature.getTemperatureC(); |
andcor02 | 25:cb16c5248769 | 69 | printf("Temperature Sample: %2.2f\r\n", current_temperature_value); |
erigow01 | 26:4cac6b346e4f | 70 | temperature_report(); |
andcor02 | 25:cb16c5248769 | 71 | } else { |
andcor02 | 25:cb16c5248769 | 72 | printf("Temperature Sampleing Failure\r\n"); |
andcor02 | 25:cb16c5248769 | 73 | } |
andcor02 | 25:cb16c5248769 | 74 | } |
andcor02 | 25:cb16c5248769 | 75 | |
andcor02 | 25:cb16c5248769 | 76 | void handle_microphone_sample_timer() |
andcor02 | 25:cb16c5248769 | 77 | { |
andcor02 | 25:cb16c5248769 | 78 | float sample = microphone.sound_level(); |
erigow01 | 26:4cac6b346e4f | 79 | //printf("Sound Sample: %2.2f\r\n", sample); |
andcor02 | 25:cb16c5248769 | 80 | if (sample > current_ambient_noise_value){ |
andcor02 | 25:cb16c5248769 | 81 | current_ambient_noise_value = sample; |
andcor02 | 25:cb16c5248769 | 82 | } |
andcor02 | 25:cb16c5248769 | 83 | } |
andcor02 | 25:cb16c5248769 | 84 | |
andcor02 | 25:cb16c5248769 | 85 | void handle_microphone_report_timer() |
andcor02 | 25:cb16c5248769 | 86 | { |
andcor02 | 25:cb16c5248769 | 87 | //Report. |
erigow01 | 26:4cac6b346e4f | 88 | sound_level_report(); |
andcor02 | 25:cb16c5248769 | 89 | //Reset noise... |
andcor02 | 25:cb16c5248769 | 90 | current_ambient_noise_value = 0; |
andcor02 | 25:cb16c5248769 | 91 | } |
andcor02 | 25:cb16c5248769 | 92 | |
erigow01 | 27:6017a643f386 | 93 | #if NODE_PIR_STATION |
erigow01 | 26:4cac6b346e4f | 94 | void handle_motion_report_timer(){ |
erigow01 | 27:6017a643f386 | 95 | bool new_pir = pir.isPresent(); |
erigow01 | 26:4cac6b346e4f | 96 | //printf("PIR Sample: %d\r\n", new_pir); |
erigow01 | 26:4cac6b346e4f | 97 | //printf("Old PIR Sample: %d\r\n", current_presence_value); |
erigow01 | 26:4cac6b346e4f | 98 | if(new_pir != current_presence_value) { |
erigow01 | 26:4cac6b346e4f | 99 | //printf("Reporting PIR...\r\n"); |
erigow01 | 26:4cac6b346e4f | 100 | current_presence_value = new_pir; |
erigow01 | 27:6017a643f386 | 101 | presence_report(); |
erigow01 | 26:4cac6b346e4f | 102 | } |
erigow01 | 26:4cac6b346e4f | 103 | } |
erigow01 | 27:6017a643f386 | 104 | #endif //NODE_PIR_STATION |
erigow01 | 26:4cac6b346e4f | 105 | |
erigow01 | 27:6017a643f386 | 106 | #if NODE_KIOSK_STATION |
erigow01 | 26:4cac6b346e4f | 107 | void handle_kiosk_report_timer(){ |
erigow01 | 27:6017a643f386 | 108 | bool new_kiosk = kiosk.isPresent(); |
erigow01 | 26:4cac6b346e4f | 109 | if(new_kiosk != current_presence_value) { |
erigow01 | 26:4cac6b346e4f | 110 | current_presence_value = new_kiosk; |
erigow01 | 27:6017a643f386 | 111 | presence_report(); |
erigow01 | 26:4cac6b346e4f | 112 | } |
erigow01 | 26:4cac6b346e4f | 113 | } |
erigow01 | 27:6017a643f386 | 114 | #endif //NODE_KIOSK_STATION |
erigow01 | 26:4cac6b346e4f | 115 | |
erigow01 | 27:6017a643f386 | 116 | #if NODE_DOOR_TRIP_STATION |
erigow01 | 26:4cac6b346e4f | 117 | void handle_door_trip_report_timer(){ |
erigow01 | 26:4cac6b346e4f | 118 | float value= sharpir.volt(); |
erigow01 | 26:4cac6b346e4f | 119 | bool new_door_trip = 0; |
erigow01 | 26:4cac6b346e4f | 120 | if (value>door_trip_starting_volts+0.15) { |
erigow01 | 26:4cac6b346e4f | 121 | new_door_trip=true; |
erigow01 | 26:4cac6b346e4f | 122 | } else if (value<door_trip_starting_volts+0.15) { |
erigow01 | 26:4cac6b346e4f | 123 | new_door_trip=false; |
erigow01 | 26:4cac6b346e4f | 124 | } |
erigow01 | 26:4cac6b346e4f | 125 | |
erigow01 | 26:4cac6b346e4f | 126 | if (new_door_trip != current_door_trip_value) { |
erigow01 | 26:4cac6b346e4f | 127 | current_door_trip_value = new_door_trip; |
erigow01 | 26:4cac6b346e4f | 128 | door_trip_report(); |
erigow01 | 26:4cac6b346e4f | 129 | } |
erigow01 | 26:4cac6b346e4f | 130 | } |
erigow01 | 27:6017a643f386 | 131 | #endif //NODE_DOOR_TRIP_STATION |
erigow01 | 26:4cac6b346e4f | 132 | |
erigow01 | 27:6017a643f386 | 133 | #if NODE_HEIGHT_STATION |
andcor02 | 29:9599a156f78b | 134 | void handle_door_height_sample_timer(){ |
andcor02 | 30:b74aa0729b07 | 135 | |
erigow01 | 31:389416beb4c3 | 136 | float height_sample = Sonar.data_conversion_m(); |
erigow01 | 31:389416beb4c3 | 137 | printf("Height Sample: %2.2f \r\n", height_sample); |
erigow01 | 31:389416beb4c3 | 138 | if(height_sample>1) { |
erigow01 | 31:389416beb4c3 | 139 | if (height_sample>maxValue) { |
erigow01 | 31:389416beb4c3 | 140 | maxValue = height_sample; |
andcor02 | 29:9599a156f78b | 141 | } |
andcor02 | 29:9599a156f78b | 142 | set=true; |
andcor02 | 29:9599a156f78b | 143 | } |
andcor02 | 29:9599a156f78b | 144 | |
erigow01 | 31:389416beb4c3 | 145 | if(height_sample<1 && set) { |
andcor02 | 29:9599a156f78b | 146 | current_height_value=maxValue; |
andcor02 | 29:9599a156f78b | 147 | maxValue=0,set=false; |
erigow01 | 31:389416beb4c3 | 148 | printf("Height Update: %2.2f \r\n", current_height_value); |
andcor02 | 30:b74aa0729b07 | 149 | height_report(); |
andcor02 | 29:9599a156f78b | 150 | } |
andcor02 | 25:cb16c5248769 | 151 | |
andcor02 | 25:cb16c5248769 | 152 | } |
andcor02 | 25:cb16c5248769 | 153 | |
erigow01 | 27:6017a643f386 | 154 | #endif //NODE HEIGHT STATION |
erigow01 | 27:6017a643f386 | 155 | #endif //NODE_SENSOR_STATION |