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:
andcor02
Date:
Fri Dec 05 16:45:56 2014 +0000
Revision:
30:b74aa0729b07
Parent:
29:9599a156f78b
Child:
31:389416beb4c3
Working on height integration follow on

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
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 26:4cac6b346e4f 49 float door_trip_starting_volts = 0;
andcor02 30:b74aa0729b07 50 float maxValue=0;
andcor02 30:b74aa0729b07 51 bool set=0;
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 30:b74aa0729b07 57
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_PIR_STATION
erigow01 26:4cac6b346e4f 97 void handle_motion_report_timer(){
erigow01 27:6017a643f386 98 bool new_pir = pir.isPresent();
erigow01 26:4cac6b346e4f 99 //printf("PIR Sample: %d\r\n", new_pir);
erigow01 26:4cac6b346e4f 100 //printf("Old PIR Sample: %d\r\n", current_presence_value);
erigow01 26:4cac6b346e4f 101 if(new_pir != current_presence_value) {
erigow01 26:4cac6b346e4f 102 //printf("Reporting PIR...\r\n");
erigow01 26:4cac6b346e4f 103 current_presence_value = new_pir;
erigow01 27:6017a643f386 104 presence_report();
erigow01 26:4cac6b346e4f 105 }
erigow01 26:4cac6b346e4f 106 }
erigow01 27:6017a643f386 107 #endif //NODE_PIR_STATION
erigow01 26:4cac6b346e4f 108
erigow01 27:6017a643f386 109 #if NODE_KIOSK_STATION
erigow01 26:4cac6b346e4f 110 void handle_kiosk_report_timer(){
erigow01 27:6017a643f386 111 bool new_kiosk = kiosk.isPresent();
erigow01 26:4cac6b346e4f 112 if(new_kiosk != current_presence_value) {
erigow01 26:4cac6b346e4f 113 current_presence_value = new_kiosk;
erigow01 27:6017a643f386 114 presence_report();
erigow01 26:4cac6b346e4f 115 }
erigow01 26:4cac6b346e4f 116 }
erigow01 27:6017a643f386 117 #endif //NODE_KIOSK_STATION
erigow01 26:4cac6b346e4f 118
erigow01 27:6017a643f386 119 #if NODE_DOOR_TRIP_STATION
erigow01 26:4cac6b346e4f 120 void handle_door_trip_report_timer(){
erigow01 26:4cac6b346e4f 121 float value= sharpir.volt();
erigow01 26:4cac6b346e4f 122 bool new_door_trip = 0;
erigow01 26:4cac6b346e4f 123 if (value>door_trip_starting_volts+0.15) {
erigow01 26:4cac6b346e4f 124 new_door_trip=true;
erigow01 26:4cac6b346e4f 125 } else if (value<door_trip_starting_volts+0.15) {
erigow01 26:4cac6b346e4f 126 new_door_trip=false;
erigow01 26:4cac6b346e4f 127 }
erigow01 26:4cac6b346e4f 128
erigow01 26:4cac6b346e4f 129 if (new_door_trip != current_door_trip_value) {
erigow01 26:4cac6b346e4f 130 current_door_trip_value = new_door_trip;
erigow01 26:4cac6b346e4f 131 door_trip_report();
erigow01 26:4cac6b346e4f 132 }
erigow01 26:4cac6b346e4f 133 }
erigow01 27:6017a643f386 134 #endif //NODE_DOOR_TRIP_STATION
erigow01 26:4cac6b346e4f 135
erigow01 27:6017a643f386 136 #if NODE_HEIGHT_STATION
andcor02 29:9599a156f78b 137 void handle_door_height_sample_timer(){
andcor02 30:b74aa0729b07 138
andcor02 30:b74aa0729b07 139
andcor02 30:b74aa0729b07 140 current_height_value=Sonar.data_conversion_m();
andcor02 30:b74aa0729b07 141
andcor02 29:9599a156f78b 142 if(current_height_value>1) {
andcor02 29:9599a156f78b 143 if (current_height_value>maxValue) {
andcor02 29:9599a156f78b 144 maxValue = current_height_value;
andcor02 29:9599a156f78b 145 }
andcor02 29:9599a156f78b 146 set=true;
andcor02 29:9599a156f78b 147 }
andcor02 29:9599a156f78b 148
andcor02 29:9599a156f78b 149 if(current_height_value<1 && set) {
andcor02 29:9599a156f78b 150 current_height_value=maxValue;
andcor02 29:9599a156f78b 151 maxValue=0,set=false;
andcor02 30:b74aa0729b07 152 height_report();
andcor02 29:9599a156f78b 153 }
andcor02 25:cb16c5248769 154
andcor02 25:cb16c5248769 155 }
andcor02 25:cb16c5248769 156
erigow01 27:6017a643f386 157 #endif //NODE HEIGHT STATION
erigow01 27:6017a643f386 158 #endif //NODE_SENSOR_STATION