2d1
Fork of TS_DISCO_F429ZI by
Keyboard_Ts.cpp@1:972c0d202476, 2017-05-05 (annotated)
- Committer:
- Robsonik16
- Date:
- Fri May 05 19:38:00 2017 +0000
- Revision:
- 1:972c0d202476
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Robsonik16 | 1:972c0d202476 | 1 | //#include "mbed.h" |
Robsonik16 | 1:972c0d202476 | 2 | //#include "TS_DISCO_F429ZI.h" |
Robsonik16 | 1:972c0d202476 | 3 | //#include "LCD_DISCO_F429ZI.h" |
Robsonik16 | 1:972c0d202476 | 4 | #include "Keyboard_Ts.h" |
Robsonik16 | 1:972c0d202476 | 5 | |
Robsonik16 | 1:972c0d202476 | 6 | |
Robsonik16 | 1:972c0d202476 | 7 | TS_DISCO_F429ZI ts; |
Robsonik16 | 1:972c0d202476 | 8 | TS_StateTypeDef TS_State; |
Robsonik16 | 1:972c0d202476 | 9 | |
Robsonik16 | 1:972c0d202476 | 10 | |
Robsonik16 | 1:972c0d202476 | 11 | |
Robsonik16 | 1:972c0d202476 | 12 | KeyboardTs::KeyboardTs(unsigned char _ucColIndex){ |
Robsonik16 | 1:972c0d202476 | 13 | uint8_t status; |
Robsonik16 | 1:972c0d202476 | 14 | |
Robsonik16 | 1:972c0d202476 | 15 | ucColIndex= _ucColIndex; |
Robsonik16 | 1:972c0d202476 | 16 | status = ts.Init(LedLcd::GetXSize(), LedLcd::GetYSize()); |
Robsonik16 | 1:972c0d202476 | 17 | if (status != TS_OK) { |
Robsonik16 | 1:972c0d202476 | 18 | LedLcd::Clear(LCD_COLOR_RED); |
Robsonik16 | 1:972c0d202476 | 19 | LedLcd::SetBackColor(LCD_COLOR_RED); |
Robsonik16 | 1:972c0d202476 | 20 | LedLcd::SetTextColor(LCD_COLOR_WHITE); |
Robsonik16 | 1:972c0d202476 | 21 | LedLcd::DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); |
Robsonik16 | 1:972c0d202476 | 22 | LedLcd::DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE); |
Robsonik16 | 1:972c0d202476 | 23 | } else { |
Robsonik16 | 1:972c0d202476 | 24 | LedLcd::Clear(LCD_COLOR_GREEN); |
Robsonik16 | 1:972c0d202476 | 25 | LedLcd::SetBackColor(LCD_COLOR_GREEN); |
Robsonik16 | 1:972c0d202476 | 26 | LedLcd::SetTextColor(LCD_COLOR_WHITE); |
Robsonik16 | 1:972c0d202476 | 27 | LedLcd::DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); |
Robsonik16 | 1:972c0d202476 | 28 | LedLcd::DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE); |
Robsonik16 | 1:972c0d202476 | 29 | } |
Robsonik16 | 1:972c0d202476 | 30 | wait_ms(500); |
Robsonik16 | 1:972c0d202476 | 31 | BSP_LCD_SetFont(&Font20); |
Robsonik16 | 1:972c0d202476 | 32 | |
Robsonik16 | 1:972c0d202476 | 33 | LedLcd::Clear(LCD_COLOR_BLACK); |
Robsonik16 | 1:972c0d202476 | 34 | LedLcd::SetBackColor(LCD_COLOR_BLACK); |
Robsonik16 | 1:972c0d202476 | 35 | LedLcd::SetTextColor(LCD_COLOR_GREEN); |
Robsonik16 | 1:972c0d202476 | 36 | |
Robsonik16 | 1:972c0d202476 | 37 | for(uint8_t i=0; i<4; i++) |
Robsonik16 | 1:972c0d202476 | 38 | LedLcd::DrawRect(0+80*ucColIndex,0+80*i,80,80); |
Robsonik16 | 1:972c0d202476 | 39 | } |
Robsonik16 | 1:972c0d202476 | 40 | |
Robsonik16 | 1:972c0d202476 | 41 | |
Robsonik16 | 1:972c0d202476 | 42 | bool KeyboardTs::touchInRect(uint16_t TouchXpos, uint16_t TouchYpos,uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) |
Robsonik16 | 1:972c0d202476 | 43 | { |
Robsonik16 | 1:972c0d202476 | 44 | if((TouchXpos>=Xpos)&&(TouchXpos<=Xpos+Width)&&(TouchYpos>=Ypos)&&(TouchYpos<=Ypos+Height))return (true); |
Robsonik16 | 1:972c0d202476 | 45 | else return(false); |
Robsonik16 | 1:972c0d202476 | 46 | } |
Robsonik16 | 1:972c0d202476 | 47 | |
Robsonik16 | 1:972c0d202476 | 48 | enum KeyboardState KeyboardTs::eRead(void){ |
Robsonik16 | 1:972c0d202476 | 49 | |
Robsonik16 | 1:972c0d202476 | 50 | ts.GetState(&TS_State); |
Robsonik16 | 1:972c0d202476 | 51 | if (TS_State.TouchDetected) { |
Robsonik16 | 1:972c0d202476 | 52 | //LedLcd::DrawNumber(); |
Robsonik16 | 1:972c0d202476 | 53 | x = TS_State.X; |
Robsonik16 | 1:972c0d202476 | 54 | y = TS_State.Y; |
Robsonik16 | 1:972c0d202476 | 55 | if(touchInRect(x,y,1+80*ucColIndex,1+80*0,79,79)) return (BUTTON_0); |
Robsonik16 | 1:972c0d202476 | 56 | if(touchInRect(x,y,1+80*ucColIndex,1+80*1,79,79)) return (BUTTON_1); |
Robsonik16 | 1:972c0d202476 | 57 | if(touchInRect(x,y,1+80*ucColIndex,1+80*2,79,79)) return (BUTTON_2); |
Robsonik16 | 1:972c0d202476 | 58 | if(touchInRect(x,y,1+80*ucColIndex,1+80*3,79,79)) return (BUTTON_3); |
Robsonik16 | 1:972c0d202476 | 59 | return(RELASED); |
Robsonik16 | 1:972c0d202476 | 60 | }else{ |
Robsonik16 | 1:972c0d202476 | 61 | return(RELASED); |
Robsonik16 | 1:972c0d202476 | 62 | } |
Robsonik16 | 1:972c0d202476 | 63 | } |
Robsonik16 | 1:972c0d202476 | 64 | |
Robsonik16 | 1:972c0d202476 | 65 |