![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Smart-Home-TX Test
Dependencies: 4DGL-uLCD-SE PinDetect
Fork of Xbee-Smart-Home-Outside by
main.cpp
- Committer:
- pkoirala3
- Date:
- 2017-04-25
- Revision:
- 1:7d069ab3f551
- Parent:
- 0:9d604b1e5409
- Child:
- 2:b549ccada3c3
File content as of revision 1:7d069ab3f551:
#include "mbed.h" #include <string> #include <stdio.h> #include "uLCD_4DGL.h" #include "rtos.h" // #include "jpegutil.h" Serial pc(USBTX, USBRX); uLCD_4DGL lcd(p28,p27,p24); Serial xbee(p9, p10); DigitalOut reset(p8); DigitalOut led1(LED1); DigitalOut led2(LED2); InterruptIn getStatus(p16); InterruptIn toggleLight(p17); // LocalFileSystem local("local"); / volatile bool statusReq = false; volatile bool flipLed = false; Thread t1; Mutex serialMutex; char buffer[50]; void statusRequest() { statusReq = true; } void flipLight() { flipLed = true; } void sendcommand(char out) { while(xbee.writeable()) { led2 = 1; char outbuf = out; serialMutex.lock(); xbee.putc(outbuf); serialMutex.unlock(); led2 = 0; } } void getcommand() { while(1) { if(xbee.readable()) { led1 = 1; int x = 0; while(xbee.readable()) { serialMutex.lock(); buffer[x] = xbee.getc(); x++; serialMutex.unlock(); } led1 = 0; const char s[2] = "|"; char *token; token = strtok(buffer, s); // get the first token int j = 1; while( token != NULL ) { // walk through other tokens lcd.locate(11,j); // Print in correct place of LCD lcd.printf( "%s", token ); token = strtok(NULL, s); j++; } } Thread::wait(1000); } } int main() { reset = 0; wait_ms(1); reset = 1; wait_ms(1); getStatus.rise(&statusRequest); //attach address of function on rising edge toggleLight.rise(&flipLight); // lcd.baudrate(300000); lcd.cls(); lcd.locate(0,0); lcd.line(0, 5, 128, 5, 0xFF0000); lcd.printf("\r\nStatus:"); lcd.printf("\r\n"); lcd.printf("Temp degC:\r\n"); lcd.printf("Humidity %:\r\n"); lcd.printf("Lights: \r\n"); lcd.line(0, 45, 128, 45, 0xFF0000); // xbee.baud(115200); // May need to latter t1.start(getcommand); while(1) { if (statusReq == true) { sendcommand('c'); } else if (flipLed == true) { sendcommand('l'); } Thread::wait(1000); } } /* string file = "/local/PICT003.jpg"; lcd.locate(0, 6); ReadJPEGFromFile(file.c_str()); lcd.printf("Image Displaying:\r\n"); lcd.BLIT(0, 60, 60, 80, &color[0]); led1 = 1; BLIT(int x, int y, int w, int h, int *colors) x is the left-edge of the region. y is the top-edge of the region. w specifies the width of the region. h specifies the height of the region. colour is a pointer to the array with size = w * h. */