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:
Wed Dec 03 15:39:09 2014 +0000
Revision:
26:4cac6b346e4f
Parent:
25:cb16c5248769
Child:
27:6017a643f386
UPdated sensor integration.

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"
andcor02 25:cb16c5248769 11 #include "PIR.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"
andcor02 25:cb16c5248769 17 #include "kiosk_presence.h"
andcor02 25:cb16c5248769 18 #include "motion.h"
andcor02 25:cb16c5248769 19 #include "sound_level.h"
andcor02 25:cb16c5248769 20 #include "temperature.h"
andcor02 25:cb16c5248769 21
andcor02 25:cb16c5248769 22 //Common Sensors
andcor02 25:cb16c5248769 23 RHT03 temperature(PTB2);
andcor02 25:cb16c5248769 24 MAX9814 microphone(PTB3); //Analogue in required.
andcor02 25:cb16c5248769 25 Timer sonarTimer;
andcor02 25:cb16c5248769 26 Sonar Sonar(PTB10, sonarTimer); //(AnalogIn required, Leave as SW2.)
erigow01 26:4cac6b346e4f 27 PIR pir(PTB11); //(InterruptPin), for PIR sensor,
erigow01 26:4cac6b346e4f 28 SHARPIR sharpir(PTC11); //(AnalogIn required), for IR door trip
andcor02 25:cb16c5248769 29
andcor02 25:cb16c5248769 30
andcor02 25:cb16c5248769 31 //Variables provided to rest of applications
erigow01 26:4cac6b346e4f 32 float current_temperature_value = 0;
erigow01 26:4cac6b346e4f 33 float current_ambient_noise_value = 0;
andcor02 25:cb16c5248769 34 //Either height XOR kiosk presence XOR PIR station...
erigow01 26:4cac6b346e4f 35 float current_door_height_value = 0;
erigow01 26:4cac6b346e4f 36 bool current_presence_value = false; //Either from Kiosk or PIR
andcor02 25:cb16c5248769 37 #define KIOSK_MAX_RANGE 200; //Max range, centimetres...
andcor02 25:cb16c5248769 38 //And it might have a door trip..
erigow01 26:4cac6b346e4f 39 bool current_door_trip_value = false;
erigow01 26:4cac6b346e4f 40
erigow01 26:4cac6b346e4f 41 float door_trip_starting_volts = 0;
andcor02 25:cb16c5248769 42
andcor02 25:cb16c5248769 43 //Initialisation
andcor02 25:cb16c5248769 44 void init_sensors() {
erigow01 26:4cac6b346e4f 45
andcor02 25:cb16c5248769 46 //Start the sonar pulse width timer...
andcor02 25:cb16c5248769 47 #if NODE_HEIGHT_STATION
andcor02 25:cb16c5248769 48 sonarTimer.start();
andcor02 25:cb16c5248769 49 #elif NODE_KIOSK_STATION
andcor02 25:cb16c5248769 50 sonarTimer.start();
andcor02 25:cb16c5248769 51 #endif
erigow01 26:4cac6b346e4f 52
erigow01 26:4cac6b346e4f 53 #if NODE_DOOR_TRIP_STATION
erigow01 26:4cac6b346e4f 54 door_trip_starting_volts = sharpir.volt();
erigow01 26:4cac6b346e4f 55 #endif
andcor02 25:cb16c5248769 56 }
andcor02 25:cb16c5248769 57
andcor02 25:cb16c5248769 58 //timer handler functions
andcor02 25:cb16c5248769 59 void handle_temperature_report_timer() {
andcor02 25:cb16c5248769 60 if(temperature.readData() == RHT_ERROR_NONE) {
andcor02 25:cb16c5248769 61 //Only report valid data...
andcor02 25:cb16c5248769 62 current_temperature_value = temperature.getTemperatureC();
andcor02 25:cb16c5248769 63 printf("Temperature Sample: %2.2f\r\n", current_temperature_value);
erigow01 26:4cac6b346e4f 64 temperature_report();
andcor02 25:cb16c5248769 65 } else {
andcor02 25:cb16c5248769 66 printf("Temperature Sampleing Failure\r\n");
andcor02 25:cb16c5248769 67 }
andcor02 25:cb16c5248769 68 }
andcor02 25:cb16c5248769 69
andcor02 25:cb16c5248769 70 void handle_microphone_sample_timer()
andcor02 25:cb16c5248769 71 {
andcor02 25:cb16c5248769 72 float sample = microphone.sound_level();
erigow01 26:4cac6b346e4f 73 //printf("Sound Sample: %2.2f\r\n", sample);
andcor02 25:cb16c5248769 74 if (sample > current_ambient_noise_value){
andcor02 25:cb16c5248769 75 current_ambient_noise_value = sample;
andcor02 25:cb16c5248769 76 }
andcor02 25:cb16c5248769 77 }
andcor02 25:cb16c5248769 78
andcor02 25:cb16c5248769 79 void handle_microphone_report_timer()
andcor02 25:cb16c5248769 80 {
andcor02 25:cb16c5248769 81 //Report.
erigow01 26:4cac6b346e4f 82 sound_level_report();
andcor02 25:cb16c5248769 83 //Reset noise...
andcor02 25:cb16c5248769 84 current_ambient_noise_value = 0;
andcor02 25:cb16c5248769 85 }
andcor02 25:cb16c5248769 86
andcor02 25:cb16c5248769 87 void handle_door_height_sample_timer()
andcor02 25:cb16c5248769 88 {
andcor02 25:cb16c5248769 89
andcor02 25:cb16c5248769 90 }
andcor02 25:cb16c5248769 91
erigow01 26:4cac6b346e4f 92 void handle_motion_report_timer(){
erigow01 26:4cac6b346e4f 93 bool new_pir = pir.getdetection();
erigow01 26:4cac6b346e4f 94 //printf("PIR Sample: %d\r\n", new_pir);
erigow01 26:4cac6b346e4f 95 //printf("Old PIR Sample: %d\r\n", current_presence_value);
erigow01 26:4cac6b346e4f 96 if(new_pir != current_presence_value) {
erigow01 26:4cac6b346e4f 97 //printf("Reporting PIR...\r\n");
erigow01 26:4cac6b346e4f 98 current_presence_value = new_pir;
erigow01 26:4cac6b346e4f 99 motion_report();
erigow01 26:4cac6b346e4f 100 }
erigow01 26:4cac6b346e4f 101 }
erigow01 26:4cac6b346e4f 102
erigow01 26:4cac6b346e4f 103
erigow01 26:4cac6b346e4f 104 DigitalOut led1(LED1);
erigow01 26:4cac6b346e4f 105 void handle_kiosk_report_timer(){
erigow01 26:4cac6b346e4f 106 bool new_kiosk = Sonar.read() < KIOSK_MAX_RANGE;
erigow01 26:4cac6b346e4f 107 if(new_kiosk != current_presence_value) {
erigow01 26:4cac6b346e4f 108 current_presence_value = new_kiosk;
erigow01 26:4cac6b346e4f 109 if(current_presence_value) led1 = 1; else led1 = 0;
erigow01 26:4cac6b346e4f 110 kiosk_presence_report();
erigow01 26:4cac6b346e4f 111 }
erigow01 26:4cac6b346e4f 112 }
erigow01 26:4cac6b346e4f 113
erigow01 26:4cac6b346e4f 114 void handle_door_trip_report_timer(){
erigow01 26:4cac6b346e4f 115 float value= sharpir.volt();
erigow01 26:4cac6b346e4f 116 bool new_door_trip = 0;
erigow01 26:4cac6b346e4f 117 if (value>door_trip_starting_volts+0.15) {
erigow01 26:4cac6b346e4f 118 new_door_trip=true;
erigow01 26:4cac6b346e4f 119 } else if (value<door_trip_starting_volts+0.15) {
erigow01 26:4cac6b346e4f 120 new_door_trip=false;
erigow01 26:4cac6b346e4f 121 }
erigow01 26:4cac6b346e4f 122
erigow01 26:4cac6b346e4f 123 if (new_door_trip != current_door_trip_value) {
erigow01 26:4cac6b346e4f 124 current_door_trip_value = new_door_trip;
erigow01 26:4cac6b346e4f 125 door_trip_report();
erigow01 26:4cac6b346e4f 126 }
erigow01 26:4cac6b346e4f 127 }
erigow01 26:4cac6b346e4f 128
andcor02 25:cb16c5248769 129 void drive_height()
andcor02 25:cb16c5248769 130 {
andcor02 25:cb16c5248769 131 // current_height_value=/*obj*/.data_conversion_m();
andcor02 25:cb16c5248769 132 //
andcor02 25:cb16c5248769 133 // if(current_height_value>1) {
andcor02 25:cb16c5248769 134 // if (current_height_value>maxValue){
andcor02 25:cb16c5248769 135 // maxValue = current_height_value;
andcor02 25:cb16c5248769 136 // }
andcor02 25:cb16c5248769 137 // set=true;
andcor02 25:cb16c5248769 138 // }
andcor02 25:cb16c5248769 139 //
andcor02 25:cb16c5248769 140 // if(current_height_value<1 && set) {
andcor02 25:cb16c5248769 141 // current_height_value=maxValue;
andcor02 25:cb16c5248769 142 // height_report();
andcor02 25:cb16c5248769 143 // maxValue=0,set=false;
andcor02 25:cb16c5248769 144 // }
andcor02 25:cb16c5248769 145
andcor02 25:cb16c5248769 146 }
andcor02 25:cb16c5248769 147
andcor02 25:cb16c5248769 148
andcor02 25:cb16c5248769 149
andcor02 25:cb16c5248769 150 void drive_kiosk_presence()
andcor02 25:cb16c5248769 151 {
andcor02 25:cb16c5248769 152 //
andcor02 25:cb16c5248769 153 // if (kiosk.getdetection()) {
andcor02 25:cb16c5248769 154 // current_kiosk_presence_value=1;
andcor02 25:cb16c5248769 155 // }
andcor02 25:cb16c5248769 156 //
andcor02 25:cb16c5248769 157 // else current_kiosk_presence_value=0;
andcor02 25:cb16c5248769 158 //
andcor02 25:cb16c5248769 159 // if (last_reported_kiosk_presence != current_kiosk_presence)
andcor02 25:cb16c5248769 160 // kiosk_presence_report();
andcor02 25:cb16c5248769 161 }