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:
- 44:f70163204018
- Parent:
- 40:b2e9bc654ca1
- Child:
- 45:d7b4b57574a0
--- a/sensor_ctl.cpp Thu Feb 12 15:08:59 2015 +0000 +++ b/sensor_ctl.cpp Tue May 12 10:57:33 2015 +0000 @@ -11,6 +11,7 @@ #include "Presence.h" #include "SHARPIR.h" #include "DoorTrip.h" +#include "FXOS8700Q.h" //Sensor MDS Resources #include "door_trip.h" @@ -18,6 +19,8 @@ #include "presence_resource.h" #include "sound_level.h" #include "temperature.h" +#include "accelerometer.h" + //Common Sensors #if NODE_SENSOR_STATION @@ -30,7 +33,7 @@ presence kiosk(PTB10, true, KIOSK_SENSOR_DEBOUNCE_MS); //(Interrupt pinrequired, no timeout) #endif //NODE KIOSK STATION #if NODE_DOOR_TRIP_STATION -DoorTrip laser(PTC3, true, DOOR_SENSOR_DEBOUNCE_MS ); //(AnalogIn required), for IR door trip +DoorTrip laser(PTC11, true, DOOR_SENSOR_DEBOUNCE_MS ); //(AnalogIn required), for IR door trip #endif //NODE TRIP STATION #if NODE_HEIGHT_STATION Timer sonarTimer; @@ -42,31 +45,44 @@ #define DOOR_HEIGHT_STOP_MEASURING_SAMPLE_COUNT 2 #define DOOR_HEIGHT_SENSOR_MOUNT_HEIGHT_CM 220 #endif //NODE HEIGHT STATION +#if NODE_ACCELEROMETER_STATION +FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); +#endif //NODE ACCELEROMETER STATION #endif //NODE_SENSOR_STATION //Variables provided to rest of applications -float current_temperature_value = 0; +float current_temperature_value = 0; float current_ambient_noise_value = 0; +float current_ambient_noise_sum = 0; +int current_ambient_noise_count = 0; //Either height XOR kiosk presence XOR PIR station... float current_height_value = 0; bool current_presence_value = false; //Either from Kiosk or PIR //And it might have a door trip.. bool current_door_trip_value = false; +bool current_accelerometer_value = false; //Door trip... float door_trip_starting_volts = 0; +float maxValue=0; +bool set=0; //Door Height... float door_height_max_value = 0; bool door_height_measuring = 0; int door_height_sample_count = 0; - //Initialisation void init_sensors() { - #if NODE_DOOR_TRIP_STATION - +// #if NODE_DOOR_TRIP_STATION +// door_trip_starting_volts = sharpir.volt(); +// #endif + #if NODE_PIR_STATION + wait(2); //Wait 2 seconds for sensor calibration period. + #endif //PIR STATION + #if NODE_ACCELEROMETER_STATION + acc.enable(); #endif #if NODE_HEIGHT_STATION sonarTimer.start(); @@ -87,21 +103,25 @@ } } -void handle_microphone_sample_timer() -{ +void handle_microphone_sample_timer(){ float sample = microphone.sound_level(); //printf("Sound Sample: %2.2f\r\n", sample); - if (sample > current_ambient_noise_value){ - current_ambient_noise_value = sample; - } + //Keep running sum and sample count to compute average... + current_ambient_noise_sum += sample; + current_ambient_noise_count++; + current_ambient_noise_value = current_ambient_noise_sum / current_ambient_noise_count; +// if (sample > current_ambient_noise_value){ +// current_ambient_noise_value = sample; +// } } -void handle_microphone_report_timer() -{ +void handle_microphone_report_timer(){ //Report. sound_level_report(); //Reset noise... current_ambient_noise_value = 0; + current_ambient_noise_sum = 0; + current_ambient_noise_count = 0; } #if NODE_PIR_STATION @@ -141,7 +161,6 @@ #if NODE_HEIGHT_STATION void handle_door_height_sample_timer(){ int height_sample = DOOR_HEIGHT_SENSOR_MOUNT_HEIGHT_CM-sonar.read(); - printf("\n\r %d", height_sample); if(height_sample > DOOR_HEIGHT_START_MEASURING_THRESHOLD_CM) { door_height_sample_count=0; if (height_sample > door_height_max_value) { @@ -162,4 +181,16 @@ } #endif //NODE HEIGHT STATION +#if NODE_ACCELEROMETER_STATION +void handle_accelerometer_report_timer(){ + bool new_accelerometer = acc.get_values(); + if(new_accelerometer != current_accelerometer_value) { + + current_accelerometer_value = new_accelerometer; + accelerometer_report(); + } + +} +#endif //NODE_ACCELEROMETER_STATION + #endif //NODE_SENSOR_STATION \ No newline at end of file