MTM PPO mbed cz3

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI

Files at this revision

API Documentation at this revision

Comitter:
paweler
Date:
Mon Jun 22 14:15:01 2020 +0000
Parent:
1:3f9eb24c51b2
Commit message:
ppo mbed

Changed in this revision

Keyboard.cpp Show annotated file Show diff for this revision Revisions of this file
Keyboard.h Show annotated file Show diff for this revision Revisions of this file
KeyboardLed.cpp Show annotated file Show diff for this revision Revisions of this file
KeyboardLed.h Show annotated file Show diff for this revision Revisions of this file
Keyboard_Ts.cpp Show diff for this revision Revisions of this file
Keyboard_Ts.h Show diff for this revision Revisions of this file
Keyboard_Ts_Lcd.cpp Show diff for this revision Revisions of this file
Keyboard_Ts_Lcd.h Show diff for this revision Revisions of this file
Led.cpp Show annotated file Show diff for this revision Revisions of this file
Led.h Show annotated file Show diff for this revision Revisions of this file
Led_Lcd.cpp Show diff for this revision Revisions of this file
Led_Lcd.h Show diff for this revision Revisions of this file
Ledboard.cpp Show annotated file Show diff for this revision Revisions of this file
Ledboard.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Keyboard.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keyboard.cpp	Mon Jun 22 14:15:01 2020 +0000
@@ -0,0 +1,32 @@
+#include "Keyboard.h"
+
+Keyboard::Keyboard(unsigned char ucColumn){
+    ucColumnIndex = ucColumn;
+}
+
+enum eKeyboardState Keyboard::eRead(void){
+    ts.GetState(&TS_State);   
+    if (TS_State.TouchDetected)
+    {
+        if((TS_State.X > 0 + ucColumnIndex * 80) && (TS_State.X <= 80 + ucColumnIndex * 80))
+        {
+            if ((TS_State.Y > 0) && (TS_State.Y < 80))
+            {
+                return BUTTON_0;
+            } 
+            else if ((TS_State.Y >= 80) && (TS_State.Y < 160))
+            {
+                return BUTTON_1;
+            }
+            else if ((TS_State.Y >= 160) && (TS_State.Y < 240))
+            {
+                return BUTTON_2;
+            }
+            else if ((TS_State.Y >= 240) && (TS_State.Y < 320))
+            {
+                return BUTTON_3;
+            }
+        }
+    }
+    return RELEASED;
+}
diff -r 3f9eb24c51b2 -r ce9137eb0655 Keyboard.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keyboard.h	Mon Jun 22 14:15:01 2020 +0000
@@ -0,0 +1,18 @@
+#ifndef KEYBOARD_H
+#define KEYBOARD_H
+
+#include "TS_DISCO_F429ZI.h"
+
+enum eKeyboardState {BUTTON_0 , BUTTON_1 , BUTTON_2 , BUTTON_3, RELEASED};
+
+class Keyboard{
+    public:
+        Keyboard(unsigned char);
+        enum eKeyboardState eRead(void);
+    private:
+        TS_DISCO_F429ZI ts;
+        TS_StateTypeDef TS_State;
+        unsigned char ucColumnIndex;
+};
+
+#endif
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 KeyboardLed.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KeyboardLed.cpp	Mon Jun 22 14:15:01 2020 +0000
@@ -0,0 +1,26 @@
+#include "KeyboardLed.h"
+
+KeyboardLed::KeyboardLed(unsigned char _ucColumn){
+    pKeyboard = new Keyboard(_ucColumn);
+    pLed =      new Ledboard(_ucColumn);
+}
+
+enum eKeyboardState KeyboardLed::eRead(void){
+    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->Off();
+            return RELEASED;
+        }
+}
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 KeyboardLed.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KeyboardLed.h	Mon Jun 22 14:15:01 2020 +0000
@@ -0,0 +1,16 @@
+#ifndef KEYBOARD_TS_LCD_H
+#define KEYBOARD_TS_LCD_H
+
+#include "Ledboard.h"
+#include "Keyboard.h"
+
+
+class KeyboardLed{
+    public:
+        KeyboardLed(unsigned char);
+        enum eKeyboardState  eRead(void);
+        Ledboard *pLed;
+        Keyboard *pKeyboard;
+};
+
+#endif
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Keyboard_Ts.cpp
--- a/Keyboard_Ts.cpp	Mon May 11 09:27:05 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#include "Keyboard_Ts.h"
-
-KeyboardTs::KeyboardTs(unsigned char ucColumn){
-    ucColumnIndex = ucColumn;
-}
-
-enum eKeyboardTsState KeyboardTs::eRead(void){
-    ts.GetState(&TS_State);   
-    if (TS_State.TouchDetected)
-    {
-        if ((TS_State.X > 0 + ucColumnIndex * 80) && (TS_State.X <= 80 + ucColumnIndex * 80) && (TS_State.Y > 0) && (TS_State.Y < 80))
-        {
-            return BUTTON_0;
-        } 
-        else if ((TS_State.X > 0 + ucColumnIndex * 80) && (TS_State.X <= 80 + ucColumnIndex * 80) && (TS_State.Y >= 80) && (TS_State.Y < 160))
-        {
-            return BUTTON_1;
-        }
-        else if ((TS_State.X > 0 + ucColumnIndex * 80) && (TS_State.X <= 80 + ucColumnIndex * 80) && (TS_State.Y >= 160) && (TS_State.Y < 240))
-        {
-            return BUTTON_2;
-        }
-        else if ((TS_State.X > 0 + ucColumnIndex * 80) && (TS_State.X <= 80 + ucColumnIndex * 80) && (TS_State.Y >= 240) && (TS_State.Y < 320))
-        {
-            return BUTTON_3;
-        }
-    }
-    return RELEASED;
-}
diff -r 3f9eb24c51b2 -r ce9137eb0655 Keyboard_Ts.h
--- a/Keyboard_Ts.h	Mon May 11 09:27:05 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-#ifndef KEYBOARD_TS_H
-#define KEYBOARD_TS_H
-
-#include "TS_DISCO_F429ZI.h"
-
-enum eKeyboardTsState {BUTTON_0 , BUTTON_1 , BUTTON_2 , BUTTON_3, RELEASED};
-
-class KeyboardTs{
-    public:
-        KeyboardTs(unsigned char);
-        enum eKeyboardTsState eRead(void);
-    private:
-        TS_DISCO_F429ZI ts;
-        TS_StateTypeDef TS_State;
-        unsigned char ucColumnIndex;
-};
-
-#endif
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Keyboard_Ts_Lcd.cpp
--- a/Keyboard_Ts_Lcd.cpp	Mon May 11 09:27:05 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#include "Keyboard_Ts_Lcd.h"
-
-KeyboardTsLcd::KeyboardTsLcd(unsigned char _ucColumn){
-    pKeyboard = new KeyboardTs(_ucColumn);
-    pLed =      new LedLcd(_ucColumn);
-}
-
-void KeyboardTsLcd::eRead(void){
-    switch(pKeyboard->eRead()) {
-        case BUTTON_0:
-            pLed->On(0);
-            break;
-        case BUTTON_1:
-            pLed->On(1);
-            break;
-        case BUTTON_2:
-            pLed->On(2);
-            break;
-        case BUTTON_3:
-            pLed->On(3);
-            break;
-        default :
-            pLed->On(4);
-            break;
-        }
-}
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Keyboard_Ts_Lcd.h
--- a/Keyboard_Ts_Lcd.h	Mon May 11 09:27:05 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#ifndef KEYBOARD_TS_LCD_H
-#define KEYBOARD_TS_LCD_H
-
-#include "Led_Lcd.h"
-#include "Keyboard_Ts.h"
-
-
-class KeyboardTsLcd{
-    public:
-        KeyboardTsLcd(unsigned char);
-        void eRead(void);
-        LedLcd *pLed;
-        KeyboardTs *pKeyboard;
-};
-
-#endif
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Led.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.cpp	Mon Jun 22 14:15:01 2020 +0000
@@ -0,0 +1,30 @@
+#include "Led.h"
+
+extern LCD_DISCO_F429ZI lcd;
+
+Led::Led(unsigned char ucColumn, unsigned char ucRow){
+    this->ucColumn = ucColumn;
+    this->ucRow = ucRow;
+    Off();
+}
+
+void Led::On(void){
+    Redraw(LCD_COLOR_YELLOW);
+}
+
+void Led::Off(void){
+    Redraw(LCD_COLOR_BLUE);
+}
+
+
+void Led::Redraw(uint32_t Color){
+    char pcLedNumber[1];
+    lcd.SetTextColor(LCD_COLOR_GREEN);
+    lcd.DrawRect(ucColumn * 80, ucRow * 80, 80, 80);
+    lcd.SetTextColor(Color);
+    lcd.FillRect(1 + ucColumn * 80, 1 + ucRow * 80, 78, 78);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    lcd.SetBackColor(LCD_COLOR_RED);
+    sprintf((char*)pcLedNumber, "%d", ucRow);
+    lcd.DisplayStringAt(ucColumn * 80, ucRow * 80, (uint8_t *)pcLedNumber, LEFT_MODE);
+}
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Led.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.h	Mon Jun 22 14:15:01 2020 +0000
@@ -0,0 +1,17 @@
+#ifndef LED_H
+#define LED_H
+
+#include "LCD_DISCO_F429ZI.h"
+
+class Led
+{
+    public:
+        Led(unsigned char ucColumn, unsigned char ucRow);
+        void On(void);
+        void Off(void);
+    private:
+        unsigned char ucColumn, ucRow;
+        void Redraw(uint32_t Color);
+};
+
+#endif
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Led_Lcd.cpp
--- a/Led_Lcd.cpp	Mon May 11 09:27:05 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#include "Led_Lcd.h"
-
-LedLcd::LedLcd(unsigned char ucColumn){
-    lcd.SetFont(&Font24);
-    lcd.Clear(LCD_COLOR_BLACK);
-    ucColumnIndex = ucColumn;
-}
-
-void LedLcd::On(unsigned char ucButtonIndex){
-    for(unsigned char ucButtonCounter = 0; ucButtonCounter < 4; ucButtonCounter++){
-        lcd.SetTextColor(LCD_COLOR_GREEN);
-        lcd.DrawRect(ucColumnIndex * 80, ucButtonCounter*80, 80, 80);
-        if(ucButtonIndex == ucButtonCounter)
-        {
-            lcd.SetTextColor(LCD_COLOR_YELLOW);
-        }
-        else
-        {
-            lcd.SetTextColor(LCD_COLOR_BLUE);
-        }
-        lcd.FillRect(1 + ucColumnIndex * 80, 1+ucButtonCounter*80, 78, 78);
-    }
-    lcd.SetTextColor(LCD_COLOR_WHITE);
-    lcd.SetBackColor(LCD_COLOR_RED);
-    lcd.DisplayStringAt(ucColumnIndex * 80,0, (uint8_t *) "0", LEFT_MODE);
-    lcd.DisplayStringAt(ucColumnIndex * 80,80, (uint8_t *) "1", LEFT_MODE);
-    lcd.DisplayStringAt(ucColumnIndex * 80,160, (uint8_t *) "2", LEFT_MODE);
-    lcd.DisplayStringAt(ucColumnIndex * 80,240, (uint8_t *) "3", LEFT_MODE);
-}
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Led_Lcd.h
--- a/Led_Lcd.h	Mon May 11 09:27:05 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#ifndef LED_LCD_H
-#define LED_LCD_H
-
-#include "LCD_DISCO_F429ZI.h"
-
-class LedLcd{
-    public:
-        LedLcd(unsigned char);
-        void On(unsigned char);
-    private:
-        LCD_DISCO_F429ZI lcd;
-        unsigned char ucColumnIndex;
-};
-
-#endif
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 Ledboard.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ledboard.cpp	Mon Jun 22 14:15:01 2020 +0000
@@ -0,0 +1,23 @@
+#include "Ledboard.h"
+#include "LCD_DISCO_F429ZI.h"
+
+extern LCD_DISCO_F429ZI lcd;
+
+Ledboard::Ledboard(unsigned char ucColumn){
+    lcd.SetFont(&Font24);
+    lcd.Clear(LCD_COLOR_BLACK);
+    for(unsigned char ucRow = 0; ucRow < 4; ucRow++) {
+        Leds[ucRow] = new Led(ucColumn, ucRow);
+    }
+}
+
+void Ledboard::On(unsigned char ucRow){
+    Off();
+    Leds[ucRow] -> On();
+}
+
+void Ledboard::Off(void){
+    for(unsigned char ucRow = 0; ucRow<4; ucRow++){
+        Leds[ucRow] -> Off();
+    }
+}
diff -r 3f9eb24c51b2 -r ce9137eb0655 Ledboard.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ledboard.h	Mon Jun 22 14:15:01 2020 +0000
@@ -0,0 +1,16 @@
+#ifndef LEDBOARD_H
+#define LEDBOARD_H
+
+#include "Led.h"
+
+class Ledboard
+{
+    public:
+        Ledboard (unsigned char ucColumn);
+        void On(unsigned char);
+        void Off(void);
+    private:
+        Led *Leds[4];
+};
+
+#endif
\ No newline at end of file
diff -r 3f9eb24c51b2 -r ce9137eb0655 main.cpp
--- a/main.cpp	Mon May 11 09:27:05 2020 +0000
+++ b/main.cpp	Mon Jun 22 14:15:01 2020 +0000
@@ -1,15 +1,31 @@
 #include "mbed.h"
-#include "Keyboard_Ts_Lcd.h"
+#include "KeyboardLed.h"
+
+LCD_DISCO_F429ZI lcd;
 
 int main()
 {
-    KeyboardTsLcd TouchKeyboard(0);
-    KeyboardTsLcd LedKeyboard(2);
+    KeyboardLed TouchKeyboard(0);
+    Ledboard *pLedBoard = new Ledboard(2);
     while(1) 
     {
-        TouchKeyboard.eRead();
-        wait(0.005);
-        LedKeyboard.pLed->On(3 - TouchKeyboard.pKeyboard->eRead());      
-        wait(0.095);
+        switch(TouchKeyboard.eRead()) {
+            case BUTTON_0:
+                pLedBoard->On(3);
+                break;
+            case BUTTON_1:
+                pLedBoard->On(2);
+                break;
+            case BUTTON_2:
+                pLedBoard->On(1);
+                break;
+            case BUTTON_3:
+                pLedBoard->On(0);
+                break;
+            default :
+                pLedBoard->Off();
+                break;
+        }
+    wait(0.1);
     }
 }
\ No newline at end of file