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@27:6017a643f386, 2014-12-03 (annotated)
- Committer:
- erigow01
- Date:
- Wed Dec 03 17:33:34 2014 +0000
- Revision:
- 27:6017a643f386
- Parent:
- 26:4cac6b346e4f
- Child:
- 28:908a6f58aa7f
Integration of kiosk/mic/temp to Eth device complete. Possible bug causes LED to blink and main loop to lock up.
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 | 27:6017a643f386 | 26 | Presence pir(PTB11, false, 5000); //(InterruptPin), for PIR sensor, |
erigow01 | 27:6017a643f386 | 27 | #endif //NODE PIR STATION |
erigow01 | 27:6017a643f386 | 28 | #if NODE_KIOSK_STATION |
erigow01 | 27:6017a643f386 | 29 | Presence kiosk(PTB10, true, 500); //(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 | 25:cb16c5248769 | 35 | Timer sonarTimer; |
andcor02 | 25:cb16c5248769 | 36 | Sonar Sonar(PTB10, sonarTimer); //(AnalogIn required, Leave as SW2.) |
erigow01 | 27:6017a643f386 | 37 | #endif //NODE HEIGHT STATION |
erigow01 | 27:6017a643f386 | 38 | #endif //NODE_SENSOR_STATION |
andcor02 | 25:cb16c5248769 | 39 | |
andcor02 | 25:cb16c5248769 | 40 | |
andcor02 | 25:cb16c5248769 | 41 | //Variables provided to rest of applications |
erigow01 | 26:4cac6b346e4f | 42 | float current_temperature_value = 0; |
erigow01 | 26:4cac6b346e4f | 43 | float current_ambient_noise_value = 0; |
andcor02 | 25:cb16c5248769 | 44 | //Either height XOR kiosk presence XOR PIR station... |
erigow01 | 26:4cac6b346e4f | 45 | float current_door_height_value = 0; |
erigow01 | 26:4cac6b346e4f | 46 | bool current_presence_value = false; //Either from Kiosk or PIR |
andcor02 | 25:cb16c5248769 | 47 | //And it might have a door trip.. |
erigow01 | 26:4cac6b346e4f | 48 | bool current_door_trip_value = false; |
erigow01 | 26:4cac6b346e4f | 49 | |
erigow01 | 26:4cac6b346e4f | 50 | float door_trip_starting_volts = 0; |
andcor02 | 25:cb16c5248769 | 51 | |
andcor02 | 25:cb16c5248769 | 52 | //Initialisation |
andcor02 | 25:cb16c5248769 | 53 | void init_sensors() { |
erigow01 | 26:4cac6b346e4f | 54 | |
andcor02 | 25:cb16c5248769 | 55 | //Start the sonar pulse width timer... |
andcor02 | 25:cb16c5248769 | 56 | #if NODE_HEIGHT_STATION |
andcor02 | 25:cb16c5248769 | 57 | sonarTimer.start(); |
andcor02 | 25:cb16c5248769 | 58 | #endif |
erigow01 | 26:4cac6b346e4f | 59 | |
erigow01 | 26:4cac6b346e4f | 60 | #if NODE_DOOR_TRIP_STATION |
erigow01 | 26:4cac6b346e4f | 61 | door_trip_starting_volts = sharpir.volt(); |
erigow01 | 26:4cac6b346e4f | 62 | #endif |
andcor02 | 25:cb16c5248769 | 63 | } |
andcor02 | 25:cb16c5248769 | 64 | |
erigow01 | 27:6017a643f386 | 65 | #if NODE_SENSOR_STATION |
erigow01 | 27:6017a643f386 | 66 | |
andcor02 | 25:cb16c5248769 | 67 | //timer handler functions |
andcor02 | 25:cb16c5248769 | 68 | void handle_temperature_report_timer() { |
andcor02 | 25:cb16c5248769 | 69 | if(temperature.readData() == RHT_ERROR_NONE) { |
andcor02 | 25:cb16c5248769 | 70 | //Only report valid data... |
andcor02 | 25:cb16c5248769 | 71 | current_temperature_value = temperature.getTemperatureC(); |
andcor02 | 25:cb16c5248769 | 72 | printf("Temperature Sample: %2.2f\r\n", current_temperature_value); |
erigow01 | 26:4cac6b346e4f | 73 | temperature_report(); |
andcor02 | 25:cb16c5248769 | 74 | } else { |
andcor02 | 25:cb16c5248769 | 75 | printf("Temperature Sampleing Failure\r\n"); |
andcor02 | 25:cb16c5248769 | 76 | } |
andcor02 | 25:cb16c5248769 | 77 | } |
andcor02 | 25:cb16c5248769 | 78 | |
andcor02 | 25:cb16c5248769 | 79 | void handle_microphone_sample_timer() |
andcor02 | 25:cb16c5248769 | 80 | { |
andcor02 | 25:cb16c5248769 | 81 | float sample = microphone.sound_level(); |
erigow01 | 26:4cac6b346e4f | 82 | //printf("Sound Sample: %2.2f\r\n", sample); |
andcor02 | 25:cb16c5248769 | 83 | if (sample > current_ambient_noise_value){ |
andcor02 | 25:cb16c5248769 | 84 | current_ambient_noise_value = sample; |
andcor02 | 25:cb16c5248769 | 85 | } |
andcor02 | 25:cb16c5248769 | 86 | } |
andcor02 | 25:cb16c5248769 | 87 | |
andcor02 | 25:cb16c5248769 | 88 | void handle_microphone_report_timer() |
andcor02 | 25:cb16c5248769 | 89 | { |
andcor02 | 25:cb16c5248769 | 90 | //Report. |
erigow01 | 26:4cac6b346e4f | 91 | sound_level_report(); |
andcor02 | 25:cb16c5248769 | 92 | //Reset noise... |
andcor02 | 25:cb16c5248769 | 93 | current_ambient_noise_value = 0; |
andcor02 | 25:cb16c5248769 | 94 | } |
andcor02 | 25:cb16c5248769 | 95 | |
erigow01 | 27:6017a643f386 | 96 | #if NODE_HEIGHT_STATION |
andcor02 | 25:cb16c5248769 | 97 | void handle_door_height_sample_timer() |
andcor02 | 25:cb16c5248769 | 98 | { |
andcor02 | 25:cb16c5248769 | 99 | |
andcor02 | 25:cb16c5248769 | 100 | } |
erigow01 | 27:6017a643f386 | 101 | #endif //NODE_HEIGHT_STATION |
andcor02 | 25:cb16c5248769 | 102 | |
erigow01 | 27:6017a643f386 | 103 | #if NODE_PIR_STATION |
erigow01 | 26:4cac6b346e4f | 104 | void handle_motion_report_timer(){ |
erigow01 | 27:6017a643f386 | 105 | bool new_pir = pir.isPresent(); |
erigow01 | 26:4cac6b346e4f | 106 | //printf("PIR Sample: %d\r\n", new_pir); |
erigow01 | 26:4cac6b346e4f | 107 | //printf("Old PIR Sample: %d\r\n", current_presence_value); |
erigow01 | 26:4cac6b346e4f | 108 | if(new_pir != current_presence_value) { |
erigow01 | 26:4cac6b346e4f | 109 | //printf("Reporting PIR...\r\n"); |
erigow01 | 26:4cac6b346e4f | 110 | current_presence_value = new_pir; |
erigow01 | 27:6017a643f386 | 111 | presence_report(); |
erigow01 | 26:4cac6b346e4f | 112 | } |
erigow01 | 26:4cac6b346e4f | 113 | } |
erigow01 | 27:6017a643f386 | 114 | #endif //NODE_PIR_STATION |
erigow01 | 26:4cac6b346e4f | 115 | |
erigow01 | 27:6017a643f386 | 116 | #if NODE_KIOSK_STATION |
erigow01 | 26:4cac6b346e4f | 117 | void handle_kiosk_report_timer(){ |
erigow01 | 27:6017a643f386 | 118 | bool new_kiosk = kiosk.isPresent(); |
erigow01 | 26:4cac6b346e4f | 119 | if(new_kiosk != current_presence_value) { |
erigow01 | 26:4cac6b346e4f | 120 | current_presence_value = new_kiosk; |
erigow01 | 27:6017a643f386 | 121 | presence_report(); |
erigow01 | 26:4cac6b346e4f | 122 | } |
erigow01 | 26:4cac6b346e4f | 123 | } |
erigow01 | 27:6017a643f386 | 124 | #endif //NODE_KIOSK_STATION |
erigow01 | 26:4cac6b346e4f | 125 | |
erigow01 | 27:6017a643f386 | 126 | #if NODE_DOOR_TRIP_STATION |
erigow01 | 26:4cac6b346e4f | 127 | void handle_door_trip_report_timer(){ |
erigow01 | 26:4cac6b346e4f | 128 | float value= sharpir.volt(); |
erigow01 | 26:4cac6b346e4f | 129 | bool new_door_trip = 0; |
erigow01 | 26:4cac6b346e4f | 130 | if (value>door_trip_starting_volts+0.15) { |
erigow01 | 26:4cac6b346e4f | 131 | new_door_trip=true; |
erigow01 | 26:4cac6b346e4f | 132 | } else if (value<door_trip_starting_volts+0.15) { |
erigow01 | 26:4cac6b346e4f | 133 | new_door_trip=false; |
erigow01 | 26:4cac6b346e4f | 134 | } |
erigow01 | 26:4cac6b346e4f | 135 | |
erigow01 | 26:4cac6b346e4f | 136 | if (new_door_trip != current_door_trip_value) { |
erigow01 | 26:4cac6b346e4f | 137 | current_door_trip_value = new_door_trip; |
erigow01 | 26:4cac6b346e4f | 138 | door_trip_report(); |
erigow01 | 26:4cac6b346e4f | 139 | } |
erigow01 | 26:4cac6b346e4f | 140 | } |
erigow01 | 27:6017a643f386 | 141 | #endif //NODE_DOOR_TRIP_STATION |
erigow01 | 26:4cac6b346e4f | 142 | |
erigow01 | 27:6017a643f386 | 143 | #if NODE_HEIGHT_STATION |
erigow01 | 27:6017a643f386 | 144 | void drive_height(){ |
andcor02 | 25:cb16c5248769 | 145 | // current_height_value=/*obj*/.data_conversion_m(); |
andcor02 | 25:cb16c5248769 | 146 | // |
andcor02 | 25:cb16c5248769 | 147 | // if(current_height_value>1) { |
andcor02 | 25:cb16c5248769 | 148 | // if (current_height_value>maxValue){ |
andcor02 | 25:cb16c5248769 | 149 | // maxValue = current_height_value; |
andcor02 | 25:cb16c5248769 | 150 | // } |
andcor02 | 25:cb16c5248769 | 151 | // set=true; |
andcor02 | 25:cb16c5248769 | 152 | // } |
andcor02 | 25:cb16c5248769 | 153 | // |
andcor02 | 25:cb16c5248769 | 154 | // if(current_height_value<1 && set) { |
andcor02 | 25:cb16c5248769 | 155 | // current_height_value=maxValue; |
andcor02 | 25:cb16c5248769 | 156 | // height_report(); |
andcor02 | 25:cb16c5248769 | 157 | // maxValue=0,set=false; |
andcor02 | 25:cb16c5248769 | 158 | // } |
andcor02 | 25:cb16c5248769 | 159 | |
andcor02 | 25:cb16c5248769 | 160 | } |
andcor02 | 25:cb16c5248769 | 161 | |
erigow01 | 27:6017a643f386 | 162 | #endif //NODE HEIGHT STATION |
erigow01 | 27:6017a643f386 | 163 | #endif //NODE_SENSOR_STATION |