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

Revision:
25:cb16c5248769
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sensor_ctl.cpp	Wed Dec 03 09:03:29 2014 +0000
@@ -0,0 +1,147 @@
+/** Implements Sensor Control for CES Instrumented Booth */
+
+#include "mbed.h"
+#include "sensor_ctl.h"
+//#include "node_cfg.h"
+
+//Sensor Drivers
+#include "RHT03.h"
+#include "MAX9814.h"
+#include "sonar.h"
+#include "PIR.h"
+#include "SHARPIR.h"
+
+//Sensor MDS Resources
+#include "door_trip.h"
+#include "height.h"
+#include "kiosk_presence.h"
+#include "motion.h"
+#include "sound_level.h"
+#include "temperature.h"
+
+//Common Sensors
+RHT03 temperature(PTB2);
+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
+
+
+//Variables provided to rest of applications
+float    current_temperature_value;
+float  current_ambient_noise_value;
+//Either height XOR kiosk presence XOR PIR station...
+float    current_door_height_value;
+bool     current_presence_value;         //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;
+
+//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
+}
+
+//timer handler functions
+void handle_temperature_report_timer() {
+    if(temperature.readData() == RHT_ERROR_NONE) { 
+        //Only report valid data...
+        current_temperature_value = temperature.getTemperatureC();
+        printf("Temperature Sample: %2.2f\r\n", current_temperature_value);
+//        temperature_report();
+    } else {
+        printf("Temperature Sampleing Failure\r\n");
+    }
+}
+
+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;
+    }
+}
+
+void handle_microphone_report_timer()
+{
+    //Report.
+    //sound_level_report();
+    //Reset noise...
+    current_ambient_noise_value = 0;
+}
+
+void handle_door_height_sample_timer()
+{
+
+}
+
+void drive_height()
+{
+//    current_height_value=/*obj*/.data_conversion_m();
+//    
+//    if(current_height_value>1) {
+//         if (current_height_value>maxValue){
+//            maxValue = current_height_value;   
+//         }   
+//        set=true;
+//    }
+//    
+//    if(current_height_value<1 && set) {
+//        current_height_value=maxValue;
+//        height_report();
+//        maxValue=0,set=false;
+//    }
+
+}
+
+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()
+{
+//
+//    if (kiosk.getdetection()) {
+//        current_kiosk_presence_value=1;
+//    }
+//
+//    else current_kiosk_presence_value=0;
+//    
+//    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