2d1
Fork of TS_DISCO_F429ZI by
Revision 1:972c0d202476, committed 2017-05-05
- Comitter:
- Robsonik16
- Date:
- Fri May 05 19:38:00 2017 +0000
- Parent:
- 0:4f8b6df8e235
- Commit message:
- a
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Keyboard_Ts.cpp Fri May 05 19:38:00 2017 +0000 @@ -0,0 +1,65 @@ +//#include "mbed.h" +//#include "TS_DISCO_F429ZI.h" +//#include "LCD_DISCO_F429ZI.h" +#include "Keyboard_Ts.h" + + +TS_DISCO_F429ZI ts; +TS_StateTypeDef TS_State; + + + +KeyboardTs::KeyboardTs(unsigned char _ucColIndex){ + uint8_t status; + + ucColIndex= _ucColIndex; + status = ts.Init(LedLcd::GetXSize(), LedLcd::GetYSize()); + if (status != TS_OK) { + LedLcd::Clear(LCD_COLOR_RED); + LedLcd::SetBackColor(LCD_COLOR_RED); + LedLcd::SetTextColor(LCD_COLOR_WHITE); + LedLcd::DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); + LedLcd::DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE); + } else { + LedLcd::Clear(LCD_COLOR_GREEN); + LedLcd::SetBackColor(LCD_COLOR_GREEN); + LedLcd::SetTextColor(LCD_COLOR_WHITE); + LedLcd::DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE); + LedLcd::DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE); + } + wait_ms(500); + BSP_LCD_SetFont(&Font20); + + LedLcd::Clear(LCD_COLOR_BLACK); + LedLcd::SetBackColor(LCD_COLOR_BLACK); + LedLcd::SetTextColor(LCD_COLOR_GREEN); + + for(uint8_t i=0; i<4; i++) + LedLcd::DrawRect(0+80*ucColIndex,0+80*i,80,80); +} + + +bool KeyboardTs::touchInRect(uint16_t TouchXpos, uint16_t TouchYpos,uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) +{ + if((TouchXpos>=Xpos)&&(TouchXpos<=Xpos+Width)&&(TouchYpos>=Ypos)&&(TouchYpos<=Ypos+Height))return (true); + else return(false); +} + +enum KeyboardState KeyboardTs::eRead(void){ + + ts.GetState(&TS_State); + if (TS_State.TouchDetected) { + //LedLcd::DrawNumber(); + x = TS_State.X; + y = TS_State.Y; + if(touchInRect(x,y,1+80*ucColIndex,1+80*0,79,79)) return (BUTTON_0); + if(touchInRect(x,y,1+80*ucColIndex,1+80*1,79,79)) return (BUTTON_1); + if(touchInRect(x,y,1+80*ucColIndex,1+80*2,79,79)) return (BUTTON_2); + if(touchInRect(x,y,1+80*ucColIndex,1+80*3,79,79)) return (BUTTON_3); + return(RELASED); + }else{ + return(RELASED); + } +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Keyboard_Ts.h Fri May 05 19:38:00 2017 +0000 @@ -0,0 +1,32 @@ + +#ifndef KEYBOARD_H +#define KEYBOARD_H + +#include "mbed.h" +#include "TS_DISCO_F429ZI.h" +#include "Keyboard_Ts.h" +#include "Led_Lcd.h" + + +enum KeyboardState{ + RELASED, + BUTTON_0, + BUTTON_1, + BUTTON_2, + BUTTON_3}; + +class KeyboardTs +:public LedLcd +{ + public: + KeyboardTs(unsigned char _ucColIndex=0); + enum KeyboardState eRead(void); + private: + bool touchInRect(uint16_t TouchXpos, uint16_t TouchYpos,uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height); + uint16_t x, y; + unsigned char ucColIndex; +}; +#endif + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Keyboard_TsLcd.cpp Fri May 05 19:38:00 2017 +0000 @@ -0,0 +1,28 @@ + + +#include "Keyboard_TsLcd.h" +KeyboardTsLcd::KeyboardTsLcd(unsigned char _ucColumn){ + pLed = new LedLcd(_ucColumn); + pKeyboard = new KeyboardTs(_ucColumn); +} +enum KeyboardState KeyboardTsLcd::eRead(){ + switch(pKeyboard->eRead()) { + case BUTTON_0: + pLed->On(0); + return (BUTTON_0); + case BUTTON_1: + pLed->On(1); + return (BUTTON_1); + case BUTTON_2: + pLed->On(2); + return (BUTTON_2); + case BUTTON_3: + pLed->On(3); + return (BUTTON_3); + default : + pLed->On(4); + return (RELASED); + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Keyboard_TsLcd.h Fri May 05 19:38:00 2017 +0000 @@ -0,0 +1,18 @@ +#ifndef KeyboardTsLcd_H +#define KeyboardTsLcd_H + +#include "Led_Lcd.h" +#include "Keyboard_Ts.h" + +#include "mbed.h" +class KeyboardTsLcd{ + + public: + KeyboardTsLcd(unsigned char _ucColumn); + enum KeyboardState eRead(); + private: + KeyboardTs *pKeyboard; + LedLcd *pLed; +}; +#endif +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Led_Lcd.cpp Fri May 05 19:38:00 2017 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" +#include "LCD_DISCO_F429ZI.h" +#include "Led_Lcd.h" + +//LCD_DISCO_F429ZI lcd; +LedLcd::LedLcd(unsigned char _ucCol){ + ucCol=_ucCol; + + LedLcd::SetFont(&Font24); +} + + + +void LedLcd::On(unsigned char ucLedIndex){ + LedLcd::SetTextColor(LCD_COLOR_BLUE); + for(uint8_t i=0; i<4; i++) LedLcd::FillRect(1+80*ucCol,1+80*i,79,79); + LedLcd::SetTextColor(LCD_COLOR_GREEN); + LedLcd::FillRect(1+80*ucCol,1+80*ucLedIndex,79,79); + LedLcd::DrawNumber(); +} + +void LedLcd::DrawNumber() +{ + uint8_t text[3]; + LedLcd::SetTextColor(LCD_COLOR_WHITE); + LedLcd::SetBackColor(LCD_COLOR_RED); + for(uint8_t i=0; i<4; i++) { + sprintf((char*)text, "%d", i); + LedLcd::DisplayStringAt(0+80*ucCol, 0+i*80, (uint8_t *)&text, LEFT_MODE); + } + LedLcd::SetBackColor(LCD_COLOR_BLACK); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Led_Lcd.h Fri May 05 19:38:00 2017 +0000 @@ -0,0 +1,24 @@ +#ifndef LED_H +#define LED_H + +#include "mbed.h" +#include "LCD_DISCO_F429ZI.h" + +class LedLcd +:public LCD_DISCO_F429ZI +{ + public: + LedLcd(unsigned char _ucCol=0); + //protected: + void On(unsigned char ucLedIndex); + void DrawNumber(); + private: + unsigned char ucCol; + +}; +#endif + + + + +