app5
Dependencies: TFTv2 nihh-utils xpl
Diff: main.cpp
- Revision:
- 2:1335510cfb92
- Parent:
- 0:9094a94896f6
- Child:
- 3:f96822b3edb5
diff -r 65ed6aef721f -r 1335510cfb92 main.cpp --- a/main.cpp Tue Oct 09 18:56:07 2018 +0000 +++ b/main.cpp Sat Oct 13 14:32:45 2018 +0100 @@ -42,23 +42,24 @@ Watchdog wd; xPL xpl; -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); +DigitalOut led1(LED1); // green = normal startup +DigitalOut led2(LED2); // blue = ethernet data received +DigitalOut led3(LED3); // red = watchdog startup +DigitalOut led4(LED4); // ?? Serial logger(SERIAL_TX, SERIAL_RX); +// ===================================== + EthernetInterface gEth; UDPSocket _socket; UDPSocket _socketSender; char in_buffer[UDP_BUFFER_SIZE]; +// ===================================== #define PIN_RESET_TFT PC_13 /* place holder */ -// ------------- FROM WORKING VERSION - #define PIN_MOSI D11 #define PIN_MISO D12 #define PIN_SCLK D13 @@ -67,14 +68,11 @@ #define PIN_BL_TFT D7 #define PIN_CS_SD D4 -// ===================================== - #define PIN_XP A2 #define PIN_XM A0 #define PIN_YP A3 #define PIN_YM A1 - struct point { int x; int y; @@ -90,19 +88,17 @@ int readTouch(PinName p, PinName m, PinName a, PinName i); - int x_off = 22071; int y_off = 18707; int pp_tx = 373; int pp_ty = 297; -// ===================================== - DigitalOut backlight(PIN_BL_TFT) ; ILI9341 TFT(SPI_8, 10000000, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Seeed2.8") ; -int page = 1 ; +// screen pages +int page = 2 ; int numPage = 3 ; @@ -336,7 +332,6 @@ backlight = 0 ; //TFT.BusEnable(true) ; TFT.background(Black); - wait(0.1) ; TFT.foreground(White); wait(0.1) ; TFT.cls() ; @@ -388,30 +383,69 @@ void screen3(void) // Graphics { //int rowX; - int rowY; + //int rowY; //int x = Terminal6x8[1]; - int y = Terminal6x8[2]; + int y = Terminal6x8[2] + 2; + + TFT.set_font((unsigned char*) Terminal6x8); //Draw some text backlight = 0 ; TFT.background(Black); - wait(0.1) ; TFT.foreground(White); wait(0.1) ; TFT.cls() ; wait(0.1) ; - + TFT.cls() ; + backlight = 1 ; - TFT.set_font((unsigned char*) Terminal6x8); + #ifndef CONNECTED_OFF + { + // Output the network information + const char *ip = gEth.get_ip_address(); + const char *netmask = gEth.get_netmask(); + const char *gateway = gEth.get_gateway(); + TFT.locate(0, 1*y); + TFT.printf("IP address: %s\r\n", ip ? ip : "None"); + TFT.locate(0, 2*y); + TFT.printf("Netmask: %s\r\n", netmask ? netmask : "None"); + TFT.locate(0, 3*y); + TFT.printf("Gateway: %s\r\n", gateway ? gateway : "None"); + } + #endif + + //TFT.set_font((unsigned char*) Terminal6x8); - for( rowY=0; rowY<100; ++rowY ) +/* for( rowY=0; rowY<100; ++rowY ) { - TFT.locate(0, (rowY%25)*y); + //TFT.locate(0, (rowY%25)*y); + TFT.locate(0, 1*y); TFT.printf("%3d TFT width = %d, height = %d", rowY, TFT.width(), TFT.height()) ; + TFT.locate(0, 2*y); + TFT.printf("%3d FIRST TEST DATA %3d", rowY, rowY ) ; + TFT.locate(0, 3*y); + TFT.printf("%3d MORE TEST DATA %3d", rowY, rowY ) ; } - +*/ +} + +void TFT_Debug(char * pszTxt) // Graphics +{ + if (page == 2) { + int x = Terminal6x8[1]; + int y = Terminal6x8[2] + 2; + +// TFT.background(Black); +// TFT.foreground(White); +// TFT.set_font((unsigned char*) Terminal6x8); + +// backlight = 0 ; + TFT.locate(0, 10*y); + TFT.printf("%s", pszTxt ); +// backlight = 1 ; + } } void incPage(void) @@ -499,6 +533,19 @@ logger.printf("Netmask: %s\r\n", netmask ? netmask : "None"); logger.printf("Gateway: %s\r\n", gateway ? gateway : "None"); + // Output the network information to the TFT + if (page == 2) + { + int y = Terminal6x8[2] + 2; + TFT.set_font((unsigned char*) Terminal6x8); + TFT.locate(0, 1*y); + TFT.printf("IP address: %s\r\n", ip ? ip : "None"); + TFT.locate(0, 2*y); + TFT.printf("Netmask: %s\r\n", netmask ? netmask : "None"); + TFT.locate(0, 3*y); + TFT.printf("Gateway: %s\r\n", gateway ? gateway : "None"); + } + // setup a UDP listener _socket.set_blocking(true); _socket.set_timeout(3000); @@ -584,6 +631,8 @@ // ----------------------------------------------------------- void AfterParseAction(xPL_Message * message) { + char debugTxt[100]; + // is this a message for me ? if (xpl.TargetIsMe(message)) { @@ -600,7 +649,9 @@ //logger.printf("XPL: [%s]\r\n", message->source.device_id ); logger.printf("XPL: [%s] %d items\r\n", message->source.device_id, message->command_count ); - + sprintf( debugTxt, "XPL: [%s] %d items\r\n", message->source.device_id, message->command_count ); + TFT_Debug( debugTxt ); + // do we have any data ??? maybe the parse failed.... if( message->command_count == 0 ) { @@ -623,11 +674,9 @@ } - // ----------------------------------------------------------- // // ----------------------------------------------------------- -//void Receiver_Thread(void const *argument) void Receiver_Thread() { SocketAddress _sAddr; @@ -672,7 +721,8 @@ } // have we stopped receiving data ?!?!? - if( iNoDataCount > 20 ) + // roughly 100*100ms = 10s... + if( iNoDataCount > 100 ) { logger.printf("ERROR: No UDP data repeatidly...\r\n"); terminal_error_state(); @@ -682,6 +732,7 @@ // stroke the WD wd.Service(); + // sleep for 100ms ThisThread::sleep_for(100); } } @@ -690,42 +741,37 @@ // ----------------------------------------------------------- // // ----------------------------------------------------------- - Thread thread1; - int main() { const char *ip; char xpl_ip[16]; int iAppLoop=0; - point p; - - int prevPage = 99 ; bool waitTouch = false ; // FIRST THINGS FIRST!!! set the WD timeout interval... // enough to get up and running! + // 1000seconds to get connected and receive an IP address wd.Configure(1000.0); // setup the pc serial logger logger.baud(115200); logger.printf("\r\n\r\n<<<<<<<<< Basic UDP XPL Listener >>>>>>>>>>\r\n"); - - // Fireup the TFT Screen initTFT() ; printf("TFT Started {width = %d, height = %d}\n\r", TFT.width(), TFT.height()) ; //calibrate(); - - + screen3(); + prevPage = 2; - led1 = 0; - led2 = 0; - led3 = 0; - led4 = 0; + // turn all the LEDs off + led1 = 0; // green = normal startup + led2 = 0; // blue = ethernet data received + led3 = 0; // red = watchdog startup + led4 = 0; // ?? // WatchDog Startup Information logger.printf("\r\n------------------------------------------------------\r\n" ); @@ -768,7 +814,7 @@ // now set the WD to something to run with - between receving data wd.Service(); - wd.Configure(300.0); + wd.Configure(300.0); // 300s // setup xpl xpl.SendExternal = &SendUdPMessage; // pointer to the send callback @@ -786,21 +832,11 @@ xpl.SendHBeat(); #endif - // Fireup the TFT Screen - //initTFT() ; - //printf("TFT Started {width = %d, height = %d}\n\r", TFT.width(), TFT.height()) ; - //calibrate(); - - - - // start running the main processing stuff here while (true) { - - + // page details... printf("page %d of %d\r\n", page, numPage ); - switch(page) { case 0: if (prevPage != page) { @@ -828,9 +864,6 @@ do { - - ThisThread::sleep_for(10); - // allow xpl to do its thing... #ifndef CONNECTED_OFF xpl.Process(); @@ -853,7 +886,7 @@ // SIMPLE TEST - every 50 loops send a test XPL msg ++iAppLoop; - if( iAppLoop >= 20000 ) + if( iAppLoop >= 10000 ) { xPL_Message _message; @@ -881,6 +914,9 @@ iAppLoop = 0; } + // pause for a mo ! + ThisThread::sleep_for(100); + } while(waitTouch != false) ; }