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

sensor_ctl.cpp

Committer:
erigow01
Date:
2014-12-05
Revision:
28:908a6f58aa7f
Parent:
27:6017a643f386
Child:
29:9599a156f78b

File content as of revision 28:908a6f58aa7f:

/** 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 "Presence.h"
#include "SHARPIR.h"

//Sensor MDS Resources
#include "door_trip.h"
#include "height.h"
#include "presence_resource.h"
#include "sound_level.h"
#include "temperature.h"

//Common Sensors
#if NODE_SENSOR_STATION
RHT03 temperature(PTB2);
MAX9814 microphone(PTB3); //Analogue in required.
#if NODE_PIR_STATION
Presence pir(PTB11, false, PIR_SENSOR_DEBOUNCE_MS); //(InterruptPin), for PIR sensor, 
#endif //NODE PIR STATION
#if NODE_KIOSK_STATION
Presence kiosk(PTB10, true, KIOSK_SENSOR_DEBOUNCE_MS); //(Interrupt pinrequired, no timeout)
#endif //NODE KIOSK STATION
#if NODE_DOOR_TRIP_STATION
SHARPIR sharpir(PTC11); //(AnalogIn required), for IR door trip
#endif //NODE TRIP STATION
#if NODE_HEIGHT_STATION
Timer sonarTimer;
Sonar Sonar(PTB10, sonarTimer); //(AnalogIn required, Leave as SW2.)
#endif //NODE HEIGHT STATION
#endif //NODE_SENSOR_STATION


//Variables provided to rest of applications
float    current_temperature_value = 0;
float  current_ambient_noise_value = 0;
//Either height XOR kiosk presence XOR PIR station...
float    current_door_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;

float door_trip_starting_volts = 0;

//Initialisation
void init_sensors() {

    //Start the sonar pulse width timer...
    #if NODE_HEIGHT_STATION
    sonarTimer.start();
    #endif
    
    #if NODE_DOOR_TRIP_STATION
    door_trip_starting_volts = sharpir.volt();
    #endif
}

#if NODE_SENSOR_STATION

//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;
}

#if NODE_HEIGHT_STATION
void handle_door_height_sample_timer()
{

}
#endif //NODE_HEIGHT_STATION

#if NODE_PIR_STATION
void handle_motion_report_timer(){
    bool new_pir = pir.isPresent();
    //printf("PIR Sample: %d\r\n", new_pir);
    //printf("Old PIR Sample: %d\r\n", current_presence_value);
    if(new_pir != current_presence_value) {
        //printf("Reporting PIR...\r\n");
        current_presence_value = new_pir;
        presence_report();
    }
}
#endif //NODE_PIR_STATION

#if NODE_KIOSK_STATION
void handle_kiosk_report_timer(){
    bool new_kiosk = kiosk.isPresent();
    if(new_kiosk != current_presence_value) {
        current_presence_value = new_kiosk;
        presence_report();
    }
}
#endif //NODE_KIOSK_STATION

#if NODE_DOOR_TRIP_STATION
void handle_door_trip_report_timer(){
    float value= sharpir.volt();
    bool new_door_trip = 0;
    if (value>door_trip_starting_volts+0.15) {
        new_door_trip=true;
    } else if (value<door_trip_starting_volts+0.15) {
        new_door_trip=false;
    }
    
    if (new_door_trip != current_door_trip_value) {
        current_door_trip_value = new_door_trip;
        door_trip_report();
    }
}
#endif //NODE_DOOR_TRIP_STATION

#if NODE_HEIGHT_STATION
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;
//    }

}

#endif //NODE HEIGHT STATION
#endif //NODE_SENSOR_STATION