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
Diff: sensor_ctl.cpp
- Revision:
- 26:4cac6b346e4f
- Parent:
- 25:cb16c5248769
- Child:
- 27:6017a643f386
--- a/sensor_ctl.cpp Wed Dec 03 09:03:29 2014 +0000 +++ b/sensor_ctl.cpp Wed Dec 03 15:39:09 2014 +0000 @@ -2,7 +2,7 @@ #include "mbed.h" #include "sensor_ctl.h" -//#include "node_cfg.h" +#include "node_cfg.h" //Sensor Drivers #include "RHT03.h" @@ -24,29 +24,35 @@ MAX9814 microphone(PTB3); //Analogue in required. Timer sonarTimer; Sonar Sonar(PTB10, sonarTimer); //(AnalogIn required, Leave as SW2.) -PIR pir(PTB2); //(InterruptPin), for PIR sensor, -SHARPIR sharpir(PTB11); //(AnalogIn required), for IR door trip +PIR pir(PTB11); //(InterruptPin), for PIR sensor, +SHARPIR sharpir(PTC11); //(AnalogIn required), for IR door trip //Variables provided to rest of applications -float current_temperature_value; -float current_ambient_noise_value; +float current_temperature_value = 0; +float current_ambient_noise_value = 0; //Either height XOR kiosk presence XOR PIR station... -float current_door_height_value; -bool current_presence_value; //Either from Kiosk or PIR +float current_door_height_value = 0; +bool current_presence_value = false; //Either from Kiosk or PIR #define KIOSK_MAX_RANGE 200; //Max range, centimetres... //And it might have a door trip.. -bool current_door_trip_value; +bool current_door_trip_value = false; + +float door_trip_starting_volts = 0; //Initialisation void init_sensors() { - //TODO Initiate sensors, interrupts, etc. + //Start the sonar pulse width timer... #if NODE_HEIGHT_STATION sonarTimer.start(); #elif NODE_KIOSK_STATION sonarTimer.start(); #endif + + #if NODE_DOOR_TRIP_STATION + door_trip_starting_volts = sharpir.volt(); + #endif } //timer handler functions @@ -55,7 +61,7 @@ //Only report valid data... current_temperature_value = temperature.getTemperatureC(); printf("Temperature Sample: %2.2f\r\n", current_temperature_value); -// temperature_report(); + temperature_report(); } else { printf("Temperature Sampleing Failure\r\n"); } @@ -64,7 +70,7 @@ void handle_microphone_sample_timer() { float sample = microphone.sound_level(); - printf("Sound Sample: %2.2f\r\n", sample); + //printf("Sound Sample: %2.2f\r\n", sample); if (sample > current_ambient_noise_value){ current_ambient_noise_value = sample; } @@ -73,7 +79,7 @@ void handle_microphone_report_timer() { //Report. - //sound_level_report(); + sound_level_report(); //Reset noise... current_ambient_noise_value = 0; } @@ -83,6 +89,43 @@ } +void handle_motion_report_timer(){ + bool new_pir = pir.getdetection(); + //printf("PIR Sample: %d\r\n", new_pir); + //printf("Old PIR Sample: %d\r\n", current_presence_value); + if(new_pir != current_presence_value) { + //printf("Reporting PIR...\r\n"); + current_presence_value = new_pir; + motion_report(); + } +} + + +DigitalOut led1(LED1); +void handle_kiosk_report_timer(){ + bool new_kiosk = Sonar.read() < KIOSK_MAX_RANGE; + if(new_kiosk != current_presence_value) { + current_presence_value = new_kiosk; + if(current_presence_value) led1 = 1; else led1 = 0; + kiosk_presence_report(); + } +} + +void handle_door_trip_report_timer(){ + float value= sharpir.volt(); + bool new_door_trip = 0; + if (value>door_trip_starting_volts+0.15) { + new_door_trip=true; + } else if (value<door_trip_starting_volts+0.15) { + new_door_trip=false; + } + + if (new_door_trip != current_door_trip_value) { + current_door_trip_value = new_door_trip; + door_trip_report(); + } +} + void drive_height() { // current_height_value=/*obj*/.data_conversion_m(); @@ -102,22 +145,6 @@ } -void drive_door_trip() -{ -//// wait_ms(50); -// value=.volt(); -// -// if (value>min+0.15) { -// current_door_trip_value=1; -// } -// -// else if (value<min+0.15) { -// current_door_trip_value=0; -// } -// -// if (last_reported_door_trip != current_door_trip) -// door_trip_report(); -} void drive_kiosk_presence() @@ -131,17 +158,4 @@ // // if (last_reported_kiosk_presence != current_kiosk_presence) // kiosk_presence_report(); -} - -void drive_motion() -{ -// -// if (pir.getdetection()) { -// current_motion_value=1; -// } -// -// else current_motion_value=0; -// -// if (last_reported_motion!= current_door_motion) -// motion_report(); } \ No newline at end of file