a demo of GUI on DISCOF7 consisting of a few buttons and feeders
Dependencies: ADXL345 BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG
main.cpp
- Committer:
- habiburrahman
- Date:
- 2016-08-04
- Revision:
- 0:122b5c3cbf4d
- Child:
- 1:4f356fb65677
File content as of revision 0:122b5c3cbf4d:
#include "mbed.h" #include "TS_DISCO_F746NG.h" #include "LCD_DISCO_F746NG.h" #include "ESP8266.h" #include "TCPSocketConnection.h" #include <string> using namespace std; LCD_DISCO_F746NG lcd; TS_DISCO_F746NG ts; TS_StateTypeDef TS_State; bool touch_test_rectangle(uint16_t tx, uint16_t ty, uint16_t x, uint16_t y, uint16_t width, uint16_t height){ bool x_is_in =0; bool y_is_in = 0; //uint16_t tx, ty; //ts.GetState(&TS_State); //tx = TS_State.touchX[0]; //ty = TS_State.touchY[0]; //printf("your touches are %d , %d\r\n",tx,ty); if( (tx>x) && (tx<(x+width))) x_is_in = 1; if( (ty>y) && (ty<(y+height))) y_is_in = 1; bool buttest; buttest = x_is_in & y_is_in; //if(buttest){ // printf("welldone\r\n"); //} return (bool) buttest; } uint16_t h_feeder(uint16_t tx, uint16_t ty,uint16_t x, uint16_t y, uint16_t width, uint16_t height){ //uint16_t tx, ty; //ts.GetState(&TS_State); //tx = TS_State.touchX[0]; //ty = TS_State.touchY[0]; bool x_is_in =0; bool y_is_in =0; if( (tx>x) && (tx<(x+width))) x_is_in = 1; if( (ty>y) && (ty<(y+height))) y_is_in = 1; bool buttest; buttest = x_is_in & y_is_in; if(buttest){ return tx - x; } } bool but1=0,but2=0,but3=0; uint16_t feed1_dist = 0; uint16_t feed2_dist = 0; int main() { uint16_t x, y; uint8_t text[30]; uint8_t status; uint8_t idx; uint8_t cleared = 0; uint8_t prev_nb_touches = 0; lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE); wait(1); status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); if (status != TS_OK) { lcd.Clear(LCD_COLOR_RED); lcd.SetBackColor(LCD_COLOR_RED); lcd.SetTextColor(LCD_COLOR_WHITE); lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); } else { lcd.Clear(LCD_COLOR_BLUE); lcd.SetBackColor(LCD_COLOR_BLUE); lcd.SetTextColor(LCD_COLOR_WHITE); lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); } lcd.SetBackColor(LCD_COLOR_YELLOW); lcd.SetTextColor(LCD_COLOR_RED); lcd.Clear(LCD_COLOR_WHITE); lcd.SetTextColor(LCD_COLOR_RED); lcd.FillRect(48, 68, 96, 60); lcd.FillRect(192, 68, 96, 60); lcd.FillRect(338, 68, 96, 60); lcd.FillRect(48, 152, 384, 30); lcd.FillRect(48, 212, 384, 30); wait(1); //lcd.SetFont(&Font12); //lcd.SetBackColor(LCD_COLOR_GREEN); //lcd.SetTextColor(LCD_COLOR_WHITE); //lcd.Clear(LCD_COLOR_GREEN); while(1){ //ts.ResetTouchData(&TS_State); //ts.ITClear(); but1=0; but2=0; but3=0; ts.GetState(&TS_State); if (TS_State.touchDetected) { feed1_dist = h_feeder(TS_State.touchX[0],TS_State.touchY[0],48, 152, 384, 30); feed2_dist = h_feeder(TS_State.touchX[0],TS_State.touchY[0],48, 212, 384, 30); but1 = touch_test_rectangle(TS_State.touchX[0],TS_State.touchY[0], 48, 68, 96, 60); but2 = touch_test_rectangle(TS_State.touchX[0],TS_State.touchY[0], 192, 68, 96, 60); but3 = touch_test_rectangle(TS_State.touchX[0],TS_State.touchY[0], 338, 68, 96, 60); if(feed1_dist>0){ lcd.SetTextColor(LCD_COLOR_RED); lcd.FillRect(48, 152, 384, 30); lcd.SetTextColor(LCD_COLOR_GREEN); lcd.FillRect(48, 152, feed1_dist, 30); } if(feed2_dist>0){ lcd.SetTextColor(LCD_COLOR_RED); lcd.FillRect(48, 212, 384, 30); lcd.SetTextColor(LCD_COLOR_GREEN); lcd.FillRect(48, 212, feed2_dist, 30); } } if(but1){ lcd.SetTextColor(LCD_COLOR_GREEN); lcd.FillRect(48, 68, 96, 60); } else{ lcd.SetTextColor(LCD_COLOR_RED); lcd.FillRect(48, 68, 96, 60); } if(but2){ lcd.SetTextColor(LCD_COLOR_GREEN); lcd.FillRect(192, 68, 96, 60); } else{ lcd.SetTextColor(LCD_COLOR_RED); lcd.FillRect(192, 68, 96, 60); } if(but3){ lcd.SetTextColor(LCD_COLOR_GREEN); lcd.FillRect(338, 68, 96, 60); } else{ lcd.SetTextColor(LCD_COLOR_RED); lcd.FillRect(338, 68, 96, 60); } } }