2b
Fork of TS_DISCO_F429ZI by
Revision 1:ad1c1b95640c, committed 2017-05-05
- Comitter:
- Robsonik16
- Date:
- Fri May 05 19:33:30 2017 +0000
- Parent:
- 0:4f8b6df8e235
- Commit message:
- a
Changed in this revision
diff -r 4f8b6df8e235 -r ad1c1b95640c Keyboard_Ts.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Keyboard_Ts.cpp Fri May 05 19:33:30 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(void){ + + uint8_t status; + + 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,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) { + x = TS_State.X; + y = TS_State.Y; + if(touchInRect(x,y,1,1+80*0,79,79)) return (BUTTON_0); + if(touchInRect(x,y,1,1+80*1,79,79)) return (BUTTON_1); + if(touchInRect(x,y,1,1+80*2,79,79)) return (BUTTON_2); + if(touchInRect(x,y,1,1+80*3,79,79)) return (BUTTON_3); + return(RELASED); + }else{ + return(RELASED); + } +} + +
diff -r 4f8b6df8e235 -r ad1c1b95640c Keyboard_Ts.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Keyboard_Ts.h Fri May 05 19:33:30 2017 +0000 @@ -0,0 +1,31 @@ + +#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(void); + 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; +}; +#endif + + +
diff -r 4f8b6df8e235 -r ad1c1b95640c Led_Lcd.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Led_Lcd.cpp Fri May 05 19:33:30 2017 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" +#include "LCD_DISCO_F429ZI.h" +#include "Led_Lcd.h" + +//LCD_DISCO_F429ZI lcd; +LedLcd::LedLcd(void){ + + 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,1+80*i,79,79); + LedLcd::SetTextColor(LCD_COLOR_GREEN); + LedLcd::FillRect(1,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, 0+i*80, (uint8_t *)&text, LEFT_MODE); + } + LedLcd::SetBackColor(LCD_COLOR_BLACK); +} + +
diff -r 4f8b6df8e235 -r ad1c1b95640c Led_Lcd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Led_Lcd.h Fri May 05 19:33:30 2017 +0000 @@ -0,0 +1,23 @@ +#ifndef LED_H +#define LED_H + +#include "mbed.h" +#include "LCD_DISCO_F429ZI.h" + +class LedLcd +:public LCD_DISCO_F429ZI +{ + public: + LedLcd(void); + //protected: + void On(unsigned char ucLedIndex); + private: + void DrawNumber(); + +}; +#endif + + + + +