int main(void) { //TM_STMPE811_TouchData instance TM_STMPE811_TouchData touchData; //TM_ILI9341_Button_t instance TM_ILI9341_Button_t button; int8_t buttonPressed, button1, button2, button3; char str[30]; //Initialize system SystemInit(); //Initialize onboard leds TM_DISCO_LedInit(); //Initialize LCD TM_ILI9341_Init(); //Fill LCD with gray color TM_ILI9341_Fill(ILI9341_COLOR_GRAY); //Select orientation TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); //Select touch screen orientation touchData.orientation = TM_STMPE811_Orientation_Portrait_2; //Initialize Touch TM_STMPE811_Init(); //Button 1, default configuration //Red with black border and black font 11x18 button.x = 10; button.y = 30; button.width = 219; button.height = 50; button.background = ILI9341_COLOR_RED; button.borderColor = ILI9341_COLOR_BLACK; button.label = "Button 1"; button.color = ILI9341_COLOR_BLACK; button.font = &TM_Font_11x18; //Add button button1 = TM_ILI9341_Button_Add(&button); //Button with custom background and without label button.x = 10; button.y = 260; button.width = 105; button.height = 50; button.background = ILI9341_COLOR_GREEN; button.borderColor = ILI9341_COLOR_BLACK; button.label = "Button 2"; //Use background image and no label button.flags = TM_BUTTON_FLAG_NOLABEL | TM_BUTTON_FLAG_IMAGE; button.color = ILI9341_COLOR_BLACK; button.font = &TM_Font_11x18; button.image = buttonBackground; //Variable stored in //Add button button2 = TM_ILI9341_Button_Add(&button); //Button with custom background and with label and without border and 7x10 fontsize button.x = 125; button.y = 260; button.background = ILI9341_COLOR_BLUE2; button.borderColor = ILI9341_COLOR_BLACK; button.label = "Button 3"; button.color = ILI9341_COLOR_BLACK; button.font = &TM_Font_7x10; button.flags = TM_BUTTON_FLAG_IMAGE | TM_BUTTON_FLAG_NOBORDER; //Use background image, without border //Add button button3 = TM_ILI9341_Button_Add(&button); if (!TM_DISCO_LedIsOn(LED_RED)) { //If led res is turned off, disable buttons 2 and 3 TM_ILI9341_Button_Disable(button2); TM_ILI9341_Button_Disable(button3); TM_ILI9341_Puts(25, 220, "Buttons disabled!", &TM_Font_11x18, ILI9341_COLOR_RED, ILI9341_COLOR_GRAY); } //Draw buttons TM_ILI9341_Button_DrawAll(); //Draw some strings TM_ILI9341_Puts(45, 245, "LED on LED off", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_GRAY); TM_ILI9341_Puts(10, 100, "Bottom buttons work\nonly if red led is turned on.\nYou can toggle red\nled with Button 1.", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_GRAY); while (1) { if (TM_STMPE811_ReadTouch(&touchData) == TM_STMPE811_State_Pressed) { buttonPressed = TM_ILI9341_Button_Touch(&touchData); if (buttonPressed >= 0) { //Any button pressed sprintf(str, "Pressed: Button %d", (buttonPressed + 1)); } else { sprintf(str, "Press the button "); } if (buttonPressed == button1) { //Red button 1 is pressed, toggle led TM_DISCO_LedToggle(LED_RED); if (TM_DISCO_LedIsOn(LED_RED)) { //If led is turned on, enable button 2 and button 3 TM_ILI9341_Button_Enable(button2); TM_ILI9341_Button_Enable(button3); TM_ILI9341_Puts(25, 220, "Buttons enabled! ", &TM_Font_11x18, ILI9341_COLOR_GREEN, ILI9341_COLOR_GRAY); } else { //otherwise disable both TM_ILI9341_Button_Disable(button2); TM_ILI9341_Button_Disable(button3); TM_ILI9341_Puts(25, 220, "Buttons disabled!", &TM_Font_11x18, ILI9341_COLOR_RED, ILI9341_COLOR_GRAY); } } else if (buttonPressed == button2) { //If button 2 is pressed, turn green led on TM_DISCO_LedOn(LED_GREEN); } else if (buttonPressed == button3) { //if button 3 is pressed, turn green led off TM_DISCO_LedOff(LED_GREEN); } } TM_ILI9341_Puts(10, 5, str, &TM_Font_11x18, ILI9341_COLOR_GREEN, ILI9341_COLOR_GRAY); } }
/* SSI server callback, always is called this callback */ uint16_t TM_ETHERNETSERVER_SSICallback(int iIndex, char *pcInsert, int iInsertLen) { uint8_t status; /* Return number of characters written */ if (iIndex < 4) { /* First 4 tags are leds */ /* Get led status */ switch (iIndex) { case 0: /* Green LED */ status = TM_DISCO_LedIsOn(LED_GREEN); break; case 1: /* Orange LED */ status = TM_DISCO_LedIsOn(LED_ORANGE); break; case 2: /* Red LED */ status = TM_DISCO_LedIsOn(LED_RED); break; case 3: /* Blue LED */ status = TM_DISCO_LedIsOn(LED_BLUE); break; default: return 0; } /* Set string according to status */ if (status) { /* Led is ON */ sprintf(pcInsert, "<span class=\"green\">On</span>"); } else { /* Led is OFF */ sprintf(pcInsert, "<span class=\"red\">Off</span>"); } } else if (iIndex == 4) { /* #serv_adr tag is requested */ sprintf(pcInsert, "%d.%d.%d.%d", TM_ETHERNET_GetLocalIP(0), TM_ETHERNET_GetLocalIP(1), TM_ETHERNET_GetLocalIP(2), TM_ETHERNET_GetLocalIP(3)); } else if (iIndex == 5) { /* #clt_a_c tag */ sprintf(pcInsert, "%u", TM_ETHERNETCLIENT_GetConnectionsCount()); } else if (iIndex == 6) { /* #clt_s_c tag */ sprintf(pcInsert, "%u", TM_ETHERNETCLIENT_GetSuccessfullConnectionsCount()); } else if (iIndex == 7) { /* #clt_per tag */ if (TM_ETHERNETCLIENT_GetConnectionsCount() == 0) { strcpy(pcInsert, "0 %"); } else { sprintf(pcInsert, "%f %%", (float)TM_ETHERNETCLIENT_GetSuccessfullConnectionsCount() / (float)TM_ETHERNETCLIENT_GetConnectionsCount() * 100); } } else if (iIndex == 8) { /* #clt_tx tag */ sprintf(pcInsert, "%llu", TM_ETHERNETCLIENT_GetTXBytes()); } else if (iIndex == 9) { /* #clt_rx tag */ sprintf(pcInsert, "%llu", TM_ETHERNETCLIENT_GetRXBytes()); } else if (iIndex == 10) { /* #srv_c tag */ sprintf(pcInsert, "%u", TM_ETHERNETSERVER_GetConnectionsCount()); } else if (iIndex == 11) { /* #srv_tx tag */ sprintf(pcInsert, "%llu", TM_ETHERNETSERVER_GetTXBytes()); } else if (iIndex == 12) { /* #srv_rx tag */ sprintf(pcInsert, "%llu", TM_ETHERNETSERVER_GetRXBytes()); } else if (iIndex == 13) { /* #mac_adr */ sprintf(pcInsert, "%02X-%02X-%02X-%02X-%02X-%02X", TM_ETHERNET_GetMACAddr(0), TM_ETHERNET_GetMACAddr(1), TM_ETHERNET_GetMACAddr(2), TM_ETHERNET_GetMACAddr(3), TM_ETHERNET_GetMACAddr(4), TM_ETHERNET_GetMACAddr(5) ); } else if (iIndex == 14) { /* #gateway */ sprintf(pcInsert, "%d.%d.%d.%d", TM_ETHERNET_GetGateway(0), TM_ETHERNET_GetGateway(1), TM_ETHERNET_GetGateway(2), TM_ETHERNET_GetGateway(3) ); } else if (iIndex == 15) { /* #netmask */ sprintf(pcInsert, "%d.%d.%d.%d", TM_ETHERNET_GetNetmask(0), TM_ETHERNET_GetNetmask(1), TM_ETHERNET_GetNetmask(2), TM_ETHERNET_GetNetmask(3) ); } else if (iIndex == 16) { /* #link */ if (TM_ETHERNET_Is100M()) { strcpy(pcInsert, "100Mbit"); } else { strcpy(pcInsert, "10Mbit"); } } else if (iIndex == 17) { /* #duplex */ if (TM_ETHERNET_IsFullDuplex()) { strcpy(pcInsert, "Full"); } else { strcpy(pcInsert, "Half"); } } else if (iIndex == 18) { /* #hardware */ strcpy(pcInsert, "STM32F4-Discovery"); } else if (iIndex == 19) { /* #rtc_time */ TM_RTC_GetDateTime(&RTC_Data, TM_RTC_Format_BIN); sprintf(pcInsert, "%04d-%02d-%02d %02d:%02d:%02d", RTC_Data.year + 2000, RTC_Data.month, RTC_Data.date, RTC_Data.hours, RTC_Data.minutes, RTC_Data.seconds ); } else if (iIndex == 20) { /* #compiled */ strcpy(pcInsert, __DATE__ " at " __TIME__); } else { /* No valid tag */ return 0; } /* Return number of characters written in buffer */ return strlen(pcInsert); }