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:
Thu Dec 11 17:15:04 2014 +0000
Revision:
32:c957a1948ac1
Parent:
31:389416beb4c3
Child:
33:d39c30e9264b
Updated for height.

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 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
erigow01 32:c957a1948ac1 35 Timer sonarTimer;
erigow01 32:c957a1948ac1 36 Timer debounceHeight;
erigow01 32:c957a1948ac1 37 Sonar sonar(PTC10, sonarTimer); //(AnalogIn required, Leave as SW2.)
erigow01 32:c957a1948ac1 38
erigow01 32:c957a1948ac1 39 #define DOOR_HEIGHT_START_MEASURING_THRESHOLD_CM 150
erigow01 32:c957a1948ac1 40 #define DOOR_HEIGHT_STOP_MEASURING_THRESHOLD_CM 140
erigow01 32:c957a1948ac1 41 #define DOOR_HEIGHT_STOP_MEASURING_SAMPLE_COUNT 2
erigow01 32:c957a1948ac1 42 #define DOOR_HEIGHT_SENSOR_MOUNT_HEIGHT_CM 220
erigow01 27:6017a643f386 43 #endif //NODE HEIGHT STATION
erigow01 27:6017a643f386 44 #endif //NODE_SENSOR_STATION
andcor02 25:cb16c5248769 45
andcor02 25:cb16c5248769 46
andcor02 25:cb16c5248769 47 //Variables provided to rest of applications
erigow01 26:4cac6b346e4f 48 float current_temperature_value = 0;
erigow01 26:4cac6b346e4f 49 float current_ambient_noise_value = 0;
andcor02 25:cb16c5248769 50 //Either height XOR kiosk presence XOR PIR station...
andcor02 30:b74aa0729b07 51 float current_height_value = 0;
erigow01 26:4cac6b346e4f 52 bool current_presence_value = false; //Either from Kiosk or PIR
andcor02 25:cb16c5248769 53 //And it might have a door trip..
erigow01 26:4cac6b346e4f 54 bool current_door_trip_value = false;
erigow01 26:4cac6b346e4f 55
erigow01 31:389416beb4c3 56 //Door trip...
erigow01 26:4cac6b346e4f 57 float door_trip_starting_volts = 0;
erigow01 32:c957a1948ac1 58
erigow01 32:c957a1948ac1 59 //Door Height...
erigow01 32:c957a1948ac1 60 float door_height_max_value = 0;
erigow01 32:c957a1948ac1 61 bool door_height_measuring = 0;
erigow01 32:c957a1948ac1 62 bool door_height_sample_count = 0;
erigow01 31:389416beb4c3 63
erigow01 31:389416beb4c3 64
andcor02 25:cb16c5248769 65 //Initialisation
andcor02 25:cb16c5248769 66 void init_sensors() {
erigow01 26:4cac6b346e4f 67 #if NODE_DOOR_TRIP_STATION
erigow01 26:4cac6b346e4f 68 door_trip_starting_volts = sharpir.volt();
erigow01 26:4cac6b346e4f 69 #endif
erigow01 32:c957a1948ac1 70 #if NODE_HEIGHT_STATION
erigow01 32:c957a1948ac1 71 sonarTimer.start();
erigow01 32:c957a1948ac1 72 #endif
andcor02 25:cb16c5248769 73 }
andcor02 25:cb16c5248769 74
erigow01 27:6017a643f386 75 #if NODE_SENSOR_STATION
erigow01 27:6017a643f386 76
andcor02 25:cb16c5248769 77 //timer handler functions
andcor02 25:cb16c5248769 78 void handle_temperature_report_timer() {
andcor02 25:cb16c5248769 79 if(temperature.readData() == RHT_ERROR_NONE) {
andcor02 25:cb16c5248769 80 //Only report valid data...
andcor02 25:cb16c5248769 81 current_temperature_value = temperature.getTemperatureC();
andcor02 25:cb16c5248769 82 printf("Temperature Sample: %2.2f\r\n", current_temperature_value);
erigow01 26:4cac6b346e4f 83 temperature_report();
andcor02 25:cb16c5248769 84 } else {
andcor02 25:cb16c5248769 85 printf("Temperature Sampleing Failure\r\n");
andcor02 25:cb16c5248769 86 }
andcor02 25:cb16c5248769 87 }
andcor02 25:cb16c5248769 88
andcor02 25:cb16c5248769 89 void handle_microphone_sample_timer()
andcor02 25:cb16c5248769 90 {
andcor02 25:cb16c5248769 91 float sample = microphone.sound_level();
erigow01 26:4cac6b346e4f 92 //printf("Sound Sample: %2.2f\r\n", sample);
andcor02 25:cb16c5248769 93 if (sample > current_ambient_noise_value){
andcor02 25:cb16c5248769 94 current_ambient_noise_value = sample;
andcor02 25:cb16c5248769 95 }
andcor02 25:cb16c5248769 96 }
andcor02 25:cb16c5248769 97
andcor02 25:cb16c5248769 98 void handle_microphone_report_timer()
andcor02 25:cb16c5248769 99 {
andcor02 25:cb16c5248769 100 //Report.
erigow01 26:4cac6b346e4f 101 sound_level_report();
andcor02 25:cb16c5248769 102 //Reset noise...
andcor02 25:cb16c5248769 103 current_ambient_noise_value = 0;
andcor02 25:cb16c5248769 104 }
andcor02 25:cb16c5248769 105
erigow01 27:6017a643f386 106 #if NODE_PIR_STATION
erigow01 26:4cac6b346e4f 107 void handle_motion_report_timer(){
erigow01 27:6017a643f386 108 bool new_pir = pir.isPresent();
erigow01 26:4cac6b346e4f 109 //printf("PIR Sample: %d\r\n", new_pir);
erigow01 26:4cac6b346e4f 110 //printf("Old PIR Sample: %d\r\n", current_presence_value);
erigow01 26:4cac6b346e4f 111 if(new_pir != current_presence_value) {
erigow01 26:4cac6b346e4f 112 //printf("Reporting PIR...\r\n");
erigow01 26:4cac6b346e4f 113 current_presence_value = new_pir;
erigow01 27:6017a643f386 114 presence_report();
erigow01 26:4cac6b346e4f 115 }
erigow01 26:4cac6b346e4f 116 }
erigow01 27:6017a643f386 117 #endif //NODE_PIR_STATION
erigow01 26:4cac6b346e4f 118
erigow01 27:6017a643f386 119 #if NODE_KIOSK_STATION
erigow01 26:4cac6b346e4f 120 void handle_kiosk_report_timer(){
erigow01 27:6017a643f386 121 bool new_kiosk = kiosk.isPresent();
erigow01 26:4cac6b346e4f 122 if(new_kiosk != current_presence_value) {
erigow01 26:4cac6b346e4f 123 current_presence_value = new_kiosk;
erigow01 27:6017a643f386 124 presence_report();
erigow01 26:4cac6b346e4f 125 }
erigow01 26:4cac6b346e4f 126 }
erigow01 27:6017a643f386 127 #endif //NODE_KIOSK_STATION
erigow01 26:4cac6b346e4f 128
erigow01 27:6017a643f386 129 #if NODE_DOOR_TRIP_STATION
erigow01 26:4cac6b346e4f 130 void handle_door_trip_report_timer(){
erigow01 26:4cac6b346e4f 131 float value= sharpir.volt();
erigow01 26:4cac6b346e4f 132 bool new_door_trip = 0;
erigow01 26:4cac6b346e4f 133 if (value>door_trip_starting_volts+0.15) {
erigow01 26:4cac6b346e4f 134 new_door_trip=true;
erigow01 26:4cac6b346e4f 135 } else if (value<door_trip_starting_volts+0.15) {
erigow01 26:4cac6b346e4f 136 new_door_trip=false;
erigow01 26:4cac6b346e4f 137 }
erigow01 26:4cac6b346e4f 138
erigow01 26:4cac6b346e4f 139 if (new_door_trip != current_door_trip_value) {
erigow01 26:4cac6b346e4f 140 current_door_trip_value = new_door_trip;
erigow01 26:4cac6b346e4f 141 door_trip_report();
erigow01 26:4cac6b346e4f 142 }
erigow01 26:4cac6b346e4f 143 }
erigow01 27:6017a643f386 144 #endif //NODE_DOOR_TRIP_STATION
erigow01 26:4cac6b346e4f 145
erigow01 27:6017a643f386 146 #if NODE_HEIGHT_STATION
andcor02 29:9599a156f78b 147 void handle_door_height_sample_timer(){
erigow01 32:c957a1948ac1 148 int height_sample = DOOR_HEIGHT_SENSOR_MOUNT_HEIGHT_CM-sonar.read();
erigow01 32:c957a1948ac1 149 if(height_sample > DOOR_HEIGHT_START_MEASURING_THRESHOLD_CM) {
erigow01 32:c957a1948ac1 150 door_height_sample_count=0;
erigow01 32:c957a1948ac1 151 if (height_sample > door_height_max_value) {
erigow01 32:c957a1948ac1 152 door_height_max_value = height_sample;
erigow01 32:c957a1948ac1 153 }
erigow01 32:c957a1948ac1 154 door_height_measuring=true;
andcor02 29:9599a156f78b 155 }
andcor02 29:9599a156f78b 156
erigow01 32:c957a1948ac1 157 if((height_sample < DOOR_HEIGHT_STOP_MEASURING_THRESHOLD_CM && door_height_measuring )){
erigow01 32:c957a1948ac1 158 door_height_sample_count++;
erigow01 32:c957a1948ac1 159 if (door_height_sample_count > DOOR_HEIGHT_STOP_MEASURING_SAMPLE_COUNT){
erigow01 32:c957a1948ac1 160 current_height_value=door_height_max_value;
erigow01 32:c957a1948ac1 161 door_height_max_value=0,door_height_measuring=false;
erigow01 32:c957a1948ac1 162 door_height_sample_count = 0;
erigow01 32:c957a1948ac1 163 height_report();
erigow01 32:c957a1948ac1 164 }
andcor02 29:9599a156f78b 165 }
andcor02 25:cb16c5248769 166 }
erigow01 32:c957a1948ac1 167 #endif //NODE HEIGHT STATION
andcor02 25:cb16c5248769 168
erigow01 27:6017a643f386 169 #endif //NODE_SENSOR_STATION