![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Xbee-Smart-Home-Inside RX Test
Dependencies: Si7021 mbed-rtos JPEGCamera mbed
Fork of Xbee-Smart-Home-Inside by
Diff: main.cpp
- Revision:
- 5:81a1920e5f3d
- Parent:
- 4:df159b3382e3
- Child:
- 6:6a43e2fdb8aa
diff -r df159b3382e3 -r 81a1920e5f3d main.cpp --- a/main.cpp Wed Apr 26 04:10:32 2017 +0000 +++ b/main.cpp Wed Apr 26 14:51:31 2017 +0000 @@ -14,15 +14,19 @@ DigitalOut led1(LED1); DigitalOut led2(LED2); +DigitalOut turnSpkOff(p21); +PwmOut speaker(p22); char outBuffer[50]; // char imageBuff[4800]; // For camera buffer char inBuffer; -bool lightOnOff = false; +volatile bool lightOnOff = false; volatile bool requestIn = false; +volatile bool intrusion = false; // Mutex serialMutex; Thread t1; +Thread t2; void getcommand() { @@ -49,6 +53,19 @@ led2 = 0; } } + +void statusUpdate(){ + tempHum.measure(); + float temp = (tempHum.get_temperature()/1000.00); + float hum = (tempHum.get_humidity()/1000.00); + float lightStatus = !light; + char delimit = '|'; + char terminate = ','; + sprintf(outBuffer, "%2.2f%c%2.1f%c%0.2f%c",temp, delimit, hum, delimit, lightStatus, terminate); + sendcommand(outBuffer); +} + + /* // IRS p26, SDA p9, SCL p10 (SDA & SCL Need 4.7Kohm with 3.3, Vcc --> 3.3 InterruptIn interrupt(p26); @@ -62,7 +79,13 @@ int value=mpr121.read(0x00); value +=mpr121.read(0x01)<<8; // Implemented latter - // If wrong passcode then take pic & send it + // If wrong passcode then take pic & send it & play sound + turnSpkOff = 1; + speaker = 0.2; + intrusion = true; + Thread::wait(1000); + speaker = 0; + turnSpkOff = 0; } */ /* // Implemented latter @@ -96,38 +119,33 @@ wait_ms(1); // xbee.baud(115200); // May be need to do this to send image t1.start(getcommand); - + speaker.period(1.0/800.0); + turnSpkOff = 0; // If someone enter key in touchpad this interrupt will be evoked // interrupt.fall(&fallInterrupt); // interrupt.mode(PullUp); - + bool ledUpdate = false; while(1){ - if(requestIn == true){ // Check for input request msg + if(requestIn || ledUpdate || intrusion){ // Check for input request msg led1 = 0; - if(inBuffer == 's') { // Send the status - tempHum.measure(); - float temp = (tempHum.get_temperature()/1000.00); - float hum = (tempHum.get_humidity()/1000.00); - float lightStatus = light; - char delimit = '|'; - char terminate = ','; - sprintf(outBuffer, "%2.2f%c%2.1f%c%0.2f%c",temp, delimit, hum, delimit, lightStatus, terminate); - sendcommand(outBuffer); - led1 = 1; - inBuffer = ' '; + if(inBuffer == 's' || ledUpdate) { // Send the status + statusUpdate(); + ledUpdate = false; } else if(inBuffer == 'l') { lightOnOff = !lightOnOff; // Toggle light on/off - // (lightOnOff == true) ? ambient : 0; + // light = (lightOnOff == true) ? ambient.read() : 0; light = (lightOnOff == true) ? 1 : 0; + ledUpdate = true; led1 = 1; - inBuffer = ' '; - } else if(inBuffer == 'c') { + } else if(inBuffer == 'c' || intrusion) { // Capture pic & Send it // cameraImage(); // sendcommand(imageBuff); // Need to work more on sendcommand function to support this + intrusion = false; } + inBuffer = ' '; // Clear the buffer } Thread::wait(1000); }