add drawing circles at every touch points.

Dependencies:   BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG mbed

Fork of DISCO-F746NG_LCDTS_demo by ST

Committer:
forester3
Date:
Sun May 06 09:26:02 2018 +0000
Revision:
3:88826e6d7e30
Parent:
0:9933f7db9a9b
draw yellow circle to touch points

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:9933f7db9a9b 1 #include "mbed.h"
bcostm 0:9933f7db9a9b 2 #include "TS_DISCO_F746NG.h"
bcostm 0:9933f7db9a9b 3 #include "LCD_DISCO_F746NG.h"
bcostm 0:9933f7db9a9b 4
bcostm 0:9933f7db9a9b 5 LCD_DISCO_F746NG lcd;
bcostm 0:9933f7db9a9b 6 TS_DISCO_F746NG ts;
bcostm 0:9933f7db9a9b 7
bcostm 0:9933f7db9a9b 8 int main()
bcostm 0:9933f7db9a9b 9 {
bcostm 0:9933f7db9a9b 10 TS_StateTypeDef TS_State;
bcostm 0:9933f7db9a9b 11 uint16_t x, y;
bcostm 0:9933f7db9a9b 12 uint8_t text[30];
bcostm 0:9933f7db9a9b 13 uint8_t status;
bcostm 0:9933f7db9a9b 14 uint8_t idx;
bcostm 0:9933f7db9a9b 15 uint8_t cleared = 0;
bcostm 0:9933f7db9a9b 16 uint8_t prev_nb_touches = 0;
bcostm 0:9933f7db9a9b 17
bcostm 0:9933f7db9a9b 18 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE);
bcostm 0:9933f7db9a9b 19 wait(1);
bcostm 0:9933f7db9a9b 20
bcostm 0:9933f7db9a9b 21 status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
bcostm 0:9933f7db9a9b 22 if (status != TS_OK) {
bcostm 0:9933f7db9a9b 23 lcd.Clear(LCD_COLOR_RED);
bcostm 0:9933f7db9a9b 24 lcd.SetBackColor(LCD_COLOR_RED);
bcostm 0:9933f7db9a9b 25 lcd.SetTextColor(LCD_COLOR_WHITE);
bcostm 0:9933f7db9a9b 26 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
bcostm 0:9933f7db9a9b 27 } else {
bcostm 0:9933f7db9a9b 28 lcd.Clear(LCD_COLOR_GREEN);
bcostm 0:9933f7db9a9b 29 lcd.SetBackColor(LCD_COLOR_GREEN);
bcostm 0:9933f7db9a9b 30 lcd.SetTextColor(LCD_COLOR_WHITE);
bcostm 0:9933f7db9a9b 31 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
bcostm 0:9933f7db9a9b 32 }
bcostm 0:9933f7db9a9b 33
bcostm 0:9933f7db9a9b 34 wait(1);
bcostm 0:9933f7db9a9b 35 lcd.SetFont(&Font12);
bcostm 0:9933f7db9a9b 36 lcd.SetBackColor(LCD_COLOR_BLUE);
bcostm 0:9933f7db9a9b 37 lcd.SetTextColor(LCD_COLOR_WHITE);
bcostm 0:9933f7db9a9b 38
bcostm 0:9933f7db9a9b 39 while(1) {
bcostm 0:9933f7db9a9b 40
bcostm 0:9933f7db9a9b 41 ts.GetState(&TS_State);
bcostm 0:9933f7db9a9b 42 if (TS_State.touchDetected) {
bcostm 0:9933f7db9a9b 43 // Clear lines corresponding to old touches coordinates
bcostm 0:9933f7db9a9b 44 if (TS_State.touchDetected < prev_nb_touches) {
bcostm 0:9933f7db9a9b 45 for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) {
bcostm 0:9933f7db9a9b 46 lcd.ClearStringLine(idx);
bcostm 0:9933f7db9a9b 47 }
bcostm 0:9933f7db9a9b 48 }
bcostm 0:9933f7db9a9b 49 prev_nb_touches = TS_State.touchDetected;
bcostm 0:9933f7db9a9b 50
bcostm 0:9933f7db9a9b 51 cleared = 0;
bcostm 0:9933f7db9a9b 52
bcostm 0:9933f7db9a9b 53 sprintf((char*)text, "Touches: %d", TS_State.touchDetected);
bcostm 0:9933f7db9a9b 54 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
bcostm 0:9933f7db9a9b 55
bcostm 0:9933f7db9a9b 56 for (idx = 0; idx < TS_State.touchDetected; idx++) {
bcostm 0:9933f7db9a9b 57 x = TS_State.touchX[idx];
bcostm 0:9933f7db9a9b 58 y = TS_State.touchY[idx];
bcostm 0:9933f7db9a9b 59 sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y);
forester3 3:88826e6d7e30 60 lcd.SetTextColor(LCD_COLOR_WHITE);
bcostm 0:9933f7db9a9b 61 lcd.DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE);
forester3 3:88826e6d7e30 62 lcd.SetTextColor(LCD_COLOR_YELLOW);
forester3 3:88826e6d7e30 63 lcd.DrawCircle(x, y, 20);
bcostm 0:9933f7db9a9b 64 }
bcostm 0:9933f7db9a9b 65
bcostm 0:9933f7db9a9b 66 } else {
bcostm 0:9933f7db9a9b 67 if (!cleared) {
bcostm 0:9933f7db9a9b 68 lcd.Clear(LCD_COLOR_BLUE);
bcostm 0:9933f7db9a9b 69 sprintf((char*)text, "Touches: 0");
forester3 3:88826e6d7e30 70 lcd.SetTextColor(LCD_COLOR_WHITE);
bcostm 0:9933f7db9a9b 71 lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE);
bcostm 0:9933f7db9a9b 72 cleared = 1;
bcostm 0:9933f7db9a9b 73 }
bcostm 0:9933f7db9a9b 74 }
bcostm 0:9933f7db9a9b 75 }
bcostm 0:9933f7db9a9b 76 }