2c

Fork of TS_DISCO_F429ZI by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Keyboard_Ts.cpp Source File

Keyboard_Ts.cpp

00001 //#include "mbed.h"
00002 //#include "TS_DISCO_F429ZI.h"
00003 //#include "LCD_DISCO_F429ZI.h"
00004 #include "Keyboard_Ts.h"
00005 
00006 
00007 TS_DISCO_F429ZI ts;
00008 TS_StateTypeDef TS_State;
00009 
00010 
00011 
00012 KeyboardTs::KeyboardTs(unsigned char _ucColIndex){
00013     uint8_t status;
00014     
00015     ucColIndex= _ucColIndex;        
00016     status = ts.Init(LedLcd::GetXSize(), LedLcd::GetYSize());
00017     if (status != TS_OK) {
00018         LedLcd::Clear(LCD_COLOR_RED);
00019         LedLcd::SetBackColor(LCD_COLOR_RED);
00020         LedLcd::SetTextColor(LCD_COLOR_WHITE);
00021         LedLcd::DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
00022         LedLcd::DisplayStringAt(0, LINE(6), (uint8_t *)"INIT FAIL", CENTER_MODE);
00023     } else {
00024         LedLcd::Clear(LCD_COLOR_GREEN);
00025         LedLcd::SetBackColor(LCD_COLOR_GREEN);
00026         LedLcd::SetTextColor(LCD_COLOR_WHITE);
00027         LedLcd::DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN", CENTER_MODE);
00028         LedLcd::DisplayStringAt(0, LINE(6), (uint8_t *)"INIT OK", CENTER_MODE);
00029     }
00030     wait_ms(500);
00031     BSP_LCD_SetFont(&Font20);
00032 
00033     LedLcd::Clear(LCD_COLOR_BLACK);
00034     LedLcd::SetBackColor(LCD_COLOR_BLACK);
00035     LedLcd::SetTextColor(LCD_COLOR_GREEN);
00036 
00037     for(uint8_t i=0; i<4; i++)
00038         LedLcd::DrawRect(0+80*ucColIndex,0+80*i,80,80);
00039 }
00040     
00041     
00042 bool KeyboardTs::touchInRect(uint16_t TouchXpos, uint16_t TouchYpos,uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
00043 {
00044     if((TouchXpos>=Xpos)&&(TouchXpos<=Xpos+Width)&&(TouchYpos>=Ypos)&&(TouchYpos<=Ypos+Height))return (true);
00045     else return(false);
00046 }
00047 
00048 enum KeyboardState KeyboardTs::eRead(void){
00049     
00050     ts.GetState(&TS_State);
00051     if (TS_State.TouchDetected) {
00052         x = TS_State.X;
00053         y = TS_State.Y;
00054         if(touchInRect(x,y,1+80*ucColIndex,1+80*0,79,79)) return (BUTTON_0);
00055         if(touchInRect(x,y,1+80*ucColIndex,1+80*1,79,79)) return (BUTTON_1);
00056         if(touchInRect(x,y,1+80*ucColIndex,1+80*2,79,79)) return (BUTTON_2);
00057         if(touchInRect(x,y,1+80*ucColIndex,1+80*3,79,79)) return (BUTTON_3);
00058         return(RELASED);
00059     }else{
00060         return(RELASED);
00061     }
00062 }
00063 
00064