Basic demo showing how to use the touch screen present on the DISCO_F469NI board.
Dependencies: BSP_DISCO_F469NI LCD_DISCO_F469NI TS_DISCO_F469NI mbed
main.cpp@3:98e2c23d57b2, 2017-07-05 (annotated)
- Committer:
- jeromecoutant
- Date:
- Wed Jul 05 06:50:17 2017 +0000
- Revision:
- 3:98e2c23d57b2
- Parent:
- 0:0e730157c767
Update with MBED rev145
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:0e730157c767 | 1 | #include "mbed.h" |
bcostm | 0:0e730157c767 | 2 | #include "TS_DISCO_F469NI.h" |
bcostm | 0:0e730157c767 | 3 | #include "LCD_DISCO_F469NI.h" |
bcostm | 0:0e730157c767 | 4 | |
bcostm | 0:0e730157c767 | 5 | LCD_DISCO_F469NI lcd; |
bcostm | 0:0e730157c767 | 6 | TS_DISCO_F469NI ts; |
bcostm | 0:0e730157c767 | 7 | |
bcostm | 0:0e730157c767 | 8 | int main() |
bcostm | 0:0e730157c767 | 9 | { |
bcostm | 0:0e730157c767 | 10 | TS_StateTypeDef TS_State; |
bcostm | 0:0e730157c767 | 11 | uint16_t x, y; |
bcostm | 0:0e730157c767 | 12 | uint8_t text[30]; |
bcostm | 0:0e730157c767 | 13 | uint8_t status; |
bcostm | 0:0e730157c767 | 14 | uint8_t idx; |
bcostm | 0:0e730157c767 | 15 | uint8_t cleared = 0; |
bcostm | 0:0e730157c767 | 16 | uint8_t prev_nb_touches = 0; |
bcostm | 0:0e730157c767 | 17 | |
bcostm | 0:0e730157c767 | 18 | BSP_LCD_SetFont(&Font24); |
bcostm | 0:0e730157c767 | 19 | |
bcostm | 0:0e730157c767 | 20 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN DEMO", CENTER_MODE); |
bcostm | 0:0e730157c767 | 21 | wait(1); |
bcostm | 0:0e730157c767 | 22 | |
bcostm | 0:0e730157c767 | 23 | status = ts.Init(lcd.GetXSize(), lcd.GetYSize()); |
bcostm | 0:0e730157c767 | 24 | if (status != TS_OK) |
bcostm | 0:0e730157c767 | 25 | { |
bcostm | 0:0e730157c767 | 26 | lcd.Clear(LCD_COLOR_RED); |
bcostm | 0:0e730157c767 | 27 | lcd.SetBackColor(LCD_COLOR_RED); |
bcostm | 0:0e730157c767 | 28 | lcd.SetTextColor(LCD_COLOR_WHITE); |
bcostm | 0:0e730157c767 | 29 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE); |
bcostm | 0:0e730157c767 | 30 | } |
bcostm | 0:0e730157c767 | 31 | else |
bcostm | 0:0e730157c767 | 32 | { |
bcostm | 0:0e730157c767 | 33 | lcd.Clear(LCD_COLOR_GREEN); |
bcostm | 0:0e730157c767 | 34 | lcd.SetBackColor(LCD_COLOR_GREEN); |
bcostm | 0:0e730157c767 | 35 | lcd.SetTextColor(LCD_COLOR_WHITE); |
bcostm | 0:0e730157c767 | 36 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE); |
bcostm | 0:0e730157c767 | 37 | } |
bcostm | 0:0e730157c767 | 38 | |
bcostm | 0:0e730157c767 | 39 | wait(1); |
bcostm | 0:0e730157c767 | 40 | lcd.SetBackColor(LCD_COLOR_BLUE); |
bcostm | 0:0e730157c767 | 41 | lcd.SetTextColor(LCD_COLOR_WHITE); |
bcostm | 0:0e730157c767 | 42 | |
bcostm | 0:0e730157c767 | 43 | while(1) |
bcostm | 0:0e730157c767 | 44 | { |
bcostm | 0:0e730157c767 | 45 | |
bcostm | 0:0e730157c767 | 46 | ts.GetState(&TS_State); |
bcostm | 0:0e730157c767 | 47 | if (TS_State.touchDetected) |
bcostm | 0:0e730157c767 | 48 | { |
bcostm | 0:0e730157c767 | 49 | // Clear lines corresponding to old touches coordinates |
bcostm | 0:0e730157c767 | 50 | if (TS_State.touchDetected < prev_nb_touches) |
bcostm | 0:0e730157c767 | 51 | { |
bcostm | 0:0e730157c767 | 52 | for (idx = (TS_State.touchDetected + 1); idx <= 5; idx++) |
bcostm | 0:0e730157c767 | 53 | { |
bcostm | 0:0e730157c767 | 54 | lcd.ClearStringLine(idx); |
bcostm | 0:0e730157c767 | 55 | } |
bcostm | 0:0e730157c767 | 56 | } |
bcostm | 0:0e730157c767 | 57 | prev_nb_touches = TS_State.touchDetected; |
bcostm | 0:0e730157c767 | 58 | |
bcostm | 0:0e730157c767 | 59 | cleared = 0; |
bcostm | 0:0e730157c767 | 60 | |
bcostm | 0:0e730157c767 | 61 | sprintf((char*)text, "Touches: %d", TS_State.touchDetected); |
bcostm | 0:0e730157c767 | 62 | lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); |
bcostm | 0:0e730157c767 | 63 | |
bcostm | 0:0e730157c767 | 64 | for (idx = 0; idx < TS_State.touchDetected; idx++) |
bcostm | 0:0e730157c767 | 65 | { |
bcostm | 0:0e730157c767 | 66 | x = TS_State.touchX[idx]; |
bcostm | 0:0e730157c767 | 67 | y = TS_State.touchY[idx]; |
bcostm | 0:0e730157c767 | 68 | sprintf((char*)text, "Touch %d: x=%d y=%d ", idx+1, x, y); |
bcostm | 0:0e730157c767 | 69 | lcd.DisplayStringAt(0, LINE(idx+1), (uint8_t *)&text, LEFT_MODE); |
bcostm | 0:0e730157c767 | 70 | lcd.FillCircle(TS_State.touchX[idx], TS_State.touchY[idx], 20); |
bcostm | 0:0e730157c767 | 71 | } |
bcostm | 0:0e730157c767 | 72 | } |
bcostm | 0:0e730157c767 | 73 | else |
bcostm | 0:0e730157c767 | 74 | { |
bcostm | 0:0e730157c767 | 75 | if (!cleared) |
bcostm | 0:0e730157c767 | 76 | { |
bcostm | 0:0e730157c767 | 77 | lcd.Clear(LCD_COLOR_BLUE); |
bcostm | 0:0e730157c767 | 78 | sprintf((char*)text, "Touches: 0"); |
bcostm | 0:0e730157c767 | 79 | lcd.DisplayStringAt(0, LINE(0), (uint8_t *)&text, LEFT_MODE); |
bcostm | 0:0e730157c767 | 80 | cleared = 1; |
bcostm | 0:0e730157c767 | 81 | } |
bcostm | 0:0e730157c767 | 82 | } |
bcostm | 0:0e730157c767 | 83 | } |
bcostm | 0:0e730157c767 | 84 | } |