Weather control switch for connected day. NXP LPC 1768 module. Ethernet connectivity.

Dependencies:   EthernetInterface mbed-rtos mbed nanoservice_client_1_12

Fork of Trenton_Switch_LPC1768_WIFLY by Demo Team

Committer:
andcor02
Date:
Wed Dec 03 09:03:29 2014 +0000
Revision:
25:cb16c5248769
ETH CES

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"
andcor02 25:cb16c5248769 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.)
andcor02 25:cb16c5248769 27 PIR pir(PTB2); //(InterruptPin), for PIR sensor,
andcor02 25:cb16c5248769 28 SHARPIR sharpir(PTB11); //(AnalogIn required), for IR door trip
andcor02 25:cb16c5248769 29
andcor02 25:cb16c5248769 30
andcor02 25:cb16c5248769 31 //Variables provided to rest of applications
andcor02 25:cb16c5248769 32 float current_temperature_value;
andcor02 25:cb16c5248769 33 float current_ambient_noise_value;
andcor02 25:cb16c5248769 34 //Either height XOR kiosk presence XOR PIR station...
andcor02 25:cb16c5248769 35 float current_door_height_value;
andcor02 25:cb16c5248769 36 bool current_presence_value; //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..
andcor02 25:cb16c5248769 39 bool current_door_trip_value;
andcor02 25:cb16c5248769 40
andcor02 25:cb16c5248769 41 //Initialisation
andcor02 25:cb16c5248769 42 void init_sensors() {
andcor02 25:cb16c5248769 43 //TODO Initiate sensors, interrupts, etc.
andcor02 25:cb16c5248769 44 //Start the sonar pulse width timer...
andcor02 25:cb16c5248769 45 #if NODE_HEIGHT_STATION
andcor02 25:cb16c5248769 46 sonarTimer.start();
andcor02 25:cb16c5248769 47 #elif NODE_KIOSK_STATION
andcor02 25:cb16c5248769 48 sonarTimer.start();
andcor02 25:cb16c5248769 49 #endif
andcor02 25:cb16c5248769 50 }
andcor02 25:cb16c5248769 51
andcor02 25:cb16c5248769 52 //timer handler functions
andcor02 25:cb16c5248769 53 void handle_temperature_report_timer() {
andcor02 25:cb16c5248769 54 if(temperature.readData() == RHT_ERROR_NONE) {
andcor02 25:cb16c5248769 55 //Only report valid data...
andcor02 25:cb16c5248769 56 current_temperature_value = temperature.getTemperatureC();
andcor02 25:cb16c5248769 57 printf("Temperature Sample: %2.2f\r\n", current_temperature_value);
andcor02 25:cb16c5248769 58 // temperature_report();
andcor02 25:cb16c5248769 59 } else {
andcor02 25:cb16c5248769 60 printf("Temperature Sampleing Failure\r\n");
andcor02 25:cb16c5248769 61 }
andcor02 25:cb16c5248769 62 }
andcor02 25:cb16c5248769 63
andcor02 25:cb16c5248769 64 void handle_microphone_sample_timer()
andcor02 25:cb16c5248769 65 {
andcor02 25:cb16c5248769 66 float sample = microphone.sound_level();
andcor02 25:cb16c5248769 67 printf("Sound Sample: %2.2f\r\n", sample);
andcor02 25:cb16c5248769 68 if (sample > current_ambient_noise_value){
andcor02 25:cb16c5248769 69 current_ambient_noise_value = sample;
andcor02 25:cb16c5248769 70 }
andcor02 25:cb16c5248769 71 }
andcor02 25:cb16c5248769 72
andcor02 25:cb16c5248769 73 void handle_microphone_report_timer()
andcor02 25:cb16c5248769 74 {
andcor02 25:cb16c5248769 75 //Report.
andcor02 25:cb16c5248769 76 //sound_level_report();
andcor02 25:cb16c5248769 77 //Reset noise...
andcor02 25:cb16c5248769 78 current_ambient_noise_value = 0;
andcor02 25:cb16c5248769 79 }
andcor02 25:cb16c5248769 80
andcor02 25:cb16c5248769 81 void handle_door_height_sample_timer()
andcor02 25:cb16c5248769 82 {
andcor02 25:cb16c5248769 83
andcor02 25:cb16c5248769 84 }
andcor02 25:cb16c5248769 85
andcor02 25:cb16c5248769 86 void drive_height()
andcor02 25:cb16c5248769 87 {
andcor02 25:cb16c5248769 88 // current_height_value=/*obj*/.data_conversion_m();
andcor02 25:cb16c5248769 89 //
andcor02 25:cb16c5248769 90 // if(current_height_value>1) {
andcor02 25:cb16c5248769 91 // if (current_height_value>maxValue){
andcor02 25:cb16c5248769 92 // maxValue = current_height_value;
andcor02 25:cb16c5248769 93 // }
andcor02 25:cb16c5248769 94 // set=true;
andcor02 25:cb16c5248769 95 // }
andcor02 25:cb16c5248769 96 //
andcor02 25:cb16c5248769 97 // if(current_height_value<1 && set) {
andcor02 25:cb16c5248769 98 // current_height_value=maxValue;
andcor02 25:cb16c5248769 99 // height_report();
andcor02 25:cb16c5248769 100 // maxValue=0,set=false;
andcor02 25:cb16c5248769 101 // }
andcor02 25:cb16c5248769 102
andcor02 25:cb16c5248769 103 }
andcor02 25:cb16c5248769 104
andcor02 25:cb16c5248769 105 void drive_door_trip()
andcor02 25:cb16c5248769 106 {
andcor02 25:cb16c5248769 107 //// wait_ms(50);
andcor02 25:cb16c5248769 108 // value=.volt();
andcor02 25:cb16c5248769 109 //
andcor02 25:cb16c5248769 110 // if (value>min+0.15) {
andcor02 25:cb16c5248769 111 // current_door_trip_value=1;
andcor02 25:cb16c5248769 112 // }
andcor02 25:cb16c5248769 113 //
andcor02 25:cb16c5248769 114 // else if (value<min+0.15) {
andcor02 25:cb16c5248769 115 // current_door_trip_value=0;
andcor02 25:cb16c5248769 116 // }
andcor02 25:cb16c5248769 117 //
andcor02 25:cb16c5248769 118 // if (last_reported_door_trip != current_door_trip)
andcor02 25:cb16c5248769 119 // door_trip_report();
andcor02 25:cb16c5248769 120 }
andcor02 25:cb16c5248769 121
andcor02 25:cb16c5248769 122
andcor02 25:cb16c5248769 123 void drive_kiosk_presence()
andcor02 25:cb16c5248769 124 {
andcor02 25:cb16c5248769 125 //
andcor02 25:cb16c5248769 126 // if (kiosk.getdetection()) {
andcor02 25:cb16c5248769 127 // current_kiosk_presence_value=1;
andcor02 25:cb16c5248769 128 // }
andcor02 25:cb16c5248769 129 //
andcor02 25:cb16c5248769 130 // else current_kiosk_presence_value=0;
andcor02 25:cb16c5248769 131 //
andcor02 25:cb16c5248769 132 // if (last_reported_kiosk_presence != current_kiosk_presence)
andcor02 25:cb16c5248769 133 // kiosk_presence_report();
andcor02 25:cb16c5248769 134 }
andcor02 25:cb16c5248769 135
andcor02 25:cb16c5248769 136 void drive_motion()
andcor02 25:cb16c5248769 137 {
andcor02 25:cb16c5248769 138 //
andcor02 25:cb16c5248769 139 // if (pir.getdetection()) {
andcor02 25:cb16c5248769 140 // current_motion_value=1;
andcor02 25:cb16c5248769 141 // }
andcor02 25:cb16c5248769 142 //
andcor02 25:cb16c5248769 143 // else current_motion_value=0;
andcor02 25:cb16c5248769 144 //
andcor02 25:cb16c5248769 145 // if (last_reported_motion!= current_door_motion)
andcor02 25:cb16c5248769 146 // motion_report();
andcor02 25:cb16c5248769 147 }