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