Smart-Home-TX Test
Dependencies: 4DGL-uLCD-SE PinDetect
Fork of Xbee-Smart-Home-Outside by
Diff: main.cpp
- Revision:
- 1:7d069ab3f551
- Parent:
- 0:9d604b1e5409
- Child:
- 2:b549ccada3c3
diff -r 9d604b1e5409 -r 7d069ab3f551 main.cpp --- a/main.cpp Mon Apr 17 12:35:31 2017 +0000 +++ b/main.cpp Tue Apr 25 22:37:54 2017 +0000 @@ -1,37 +1,124 @@ #include "mbed.h" #include <string> - +#include <stdio.h> #include "uLCD_4DGL.h" - -DigitalOut myled(LED1); +#include "rtos.h" +// #include "jpegutil.h" + +Serial pc(USBTX, USBRX); +uLCD_4DGL lcd(p28,p27,p24); Serial xbee(p9, p10); DigitalOut reset(p8); -Serial pc(USBTX, USBRX); - DigitalOut led1(LED1); DigitalOut led2(LED2); -DigitalOut led3(LED3); - -uLCD_4DGL lcd(p28,p27,p24); - +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() { - // lcd.baudrate(3000000); reset = 0; wait_ms(1); reset = 1; wait_ms(1); - lcd.printf("Waiting for char\r\n"); - while(1){ - while(xbee.readable()){ - led2 = 1; - char buffer[512]; - xbee.scanf("%s", buffer); - lcd.printf("%s", buffer); - // lcd.putc(xbee.getc()); - wait_ms(1); - led1 = 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'); } - lcd.printf("\r\n"); + Thread::wait(1000); + } -} \ No newline at end of file +} + +/* + 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. +*/ \ No newline at end of file