![](/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
main.cpp
- Committer:
- pkoirala3
- Date:
- 2017-04-26
- Revision:
- 4:df159b3382e3
- Parent:
- 3:415ccd1f7ae1
- Child:
- 5:81a1920e5f3d
File content as of revision 4:df159b3382e3:
#include "mbed.h" #include "rtos.h" #include "JPEGCamera.h" #include "Si7021.h" #include "mpr121.h" Serial xbee(p9, p10); Serial pc(USBTX, USBRX); JPEGCamera camera(p13, p14); DigitalOut rst1(p8); AnalogIn ambient(p16); DigitalOut light(p17); Si7021 tempHum(p28, p27); DigitalOut led1(LED1); DigitalOut led2(LED2); char outBuffer[50]; // char imageBuff[4800]; // For camera buffer char inBuffer; bool lightOnOff = false; volatile bool requestIn = false; // Mutex serialMutex; Thread t1; void getcommand() { while(1) { if(xbee.readable()) { led1 = 1; inBuffer = xbee.getc(); requestIn = true; led1 = 0; } Thread::wait(1000); } } void sendcommand(char outBuff[]) { if(xbee.writeable()){ led2 = 1; int i = 0; while(outBuff[i] != ','){ xbee.putc(outBuff[i]); i++; } led2 = 0; } } /* // IRS p26, SDA p9, SCL p10 (SDA & SCL Need 4.7Kohm with 3.3, Vcc --> 3.3 InterruptIn interrupt(p26); I2C i2c(p9, p10); Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); // Key hit/release interrupt routine void fallInterrupt() { int key_code=0; int i=0; int value=mpr121.read(0x00); value +=mpr121.read(0x01)<<8; // Implemented latter // If wrong passcode then take pic & send it } */ /* // Implemented latter void cameraImage() { LocalFileSystem local("local"); //save images on mbed camera.setPictureSize(JPEGCamera::SIZE160x120); while(1) { if (camera.isReady()) { char filename[32]; sprintf(filename, "/local/pict.jpg"); printf("Picture: %s ", filename); if (camera.takePicture(filename)) { while (camera.isProcessing()) { camera.processPicture(); } } } // Load image from mbed to imageBuff; // Need jpg decoder and scale the image to 80*60 } } */ int main() { light = 0; rst1 = 0; wait_ms(1); rst1 = 1; wait_ms(1); // xbee.baud(115200); // May be need to do this to send image t1.start(getcommand); // If someone enter key in touchpad this interrupt will be evoked // interrupt.fall(&fallInterrupt); // interrupt.mode(PullUp); while(1){ if(requestIn == true){ // 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 = ' '; } else if(inBuffer == 'l') { lightOnOff = !lightOnOff; // Toggle light on/off // (lightOnOff == true) ? ambient : 0; light = (lightOnOff == true) ? 1 : 0; led1 = 1; inBuffer = ' '; } else if(inBuffer == 'c') { // Capture pic & Send it // cameraImage(); // sendcommand(imageBuff); // Need to work more on sendcommand function to support this } } Thread::wait(1000); } }