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
Revision 44:f70163204018, committed 2015-05-12
- Comitter:
- erigow01
- Date:
- Tue May 12 10:57:33 2015 +0000
- Parent:
- 43:8da94286ea35
- Child:
- 45:d7b4b57574a0
- Commit message:
- Computex Updates.
Changed in this revision
sensor_ctl.cpp | Show annotated file Show diff for this revision Revisions of this file |
sensor_ctl.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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
--- a/sensor_ctl.h Thu Feb 12 15:08:59 2015 +0000 +++ b/sensor_ctl.h Tue May 12 10:57:33 2015 +0000 @@ -6,24 +6,27 @@ /******* Sensor Timer/Debounce Periods (ms) **********/ #define TEMPERATURE_REPORT_PERIOD_MS 60000 // Every Minute -#define SOUND_SAMPLE_PERIOD_MS 100 // Every 500 ms +#define SOUND_SAMPLE_PERIOD_MS 100 // Every 100 ms #define SOUND_REPORT_PERIOD_MS 10000 // Every 10 seconds #define DOOR_HEIGHT_PERIOD_MS 50 // Every 50 ms -#define MOTION_REPORT_PERIOD_MS 1000 // Every Second. -#define DOOR_TRIP_REPORT_PERIOD_MS 100 // Every half second. +#define MOTION_REPORT_PERIOD_MS 250 // Every Quarter Second. +#define DOOR_TRIP_REPORT_PERIOD_MS 250 // Every quarter second. #define KIOSK_REPORT_PERIOD_MS 1000 // Every Second +#define ACCELEROMETER_PERIOD_MS 200 // Every 200ms -#define KIOSK_SENSOR_DEBOUNCE_MS 500 -#define PIR_SENSOR_DEBOUNCE_MS 5000 -#define DOOR_SENSOR_DEBOUNCE_MS 200 + +#define DOOR_SENSOR_DEBOUNCE_MS 1000 +#define KIOSK_SENSOR_DEBOUNCE_MS 10000 +#define PIR_SENSOR_DEBOUNCE_MS 300000 // Five Minutes //Externally visible values. extern float current_temperature_value; -extern float current_ambient_noise_value; +extern float current_ambient_noise_value; extern float current_height_value; extern bool current_presence_value; //Either from Kiosk or PIR extern bool current_door_trip_value; +extern bool current_accelerometer_value; @@ -38,5 +41,6 @@ void handle_door_height_sample_timer(); void handle_door_trip_report_timer(); void handle_kiosk_report_timer(); +void handle_accelerometer_report_timer(); #endif // SENSOR_CTL_H_ \ No newline at end of file