2c

Fork of TS_DISCO_F429ZI by ST

Files at this revision

API Documentation at this revision

Comitter:
Robsonik16
Date:
Fri May 05 19:35:45 2017 +0000
Parent:
0:4f8b6df8e235
Commit message:
a

Changed in this revision

Keyboard_Ts.cpp Show annotated file Show diff for this revision Revisions of this file
Keyboard_Ts.h Show annotated file Show diff for this revision Revisions of this file
Led_Lcd.cpp Show annotated file Show diff for this revision Revisions of this file
Led_Lcd.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keyboard_Ts.cpp	Fri May 05 19:35:45 2017 +0000
@@ -0,0 +1,64 @@
+//#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) {
+        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:35:45 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/Led_Lcd.cpp	Fri May 05 19:35:45 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:35:45 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);
+        private:
+        void DrawNumber();
+        unsigned char ucCol;
+
+};
+#endif
+
+
+
+
+