vector

Dependencies:   MBED1zadD2 mbed BSP_DISCO_F429ZI

Files at this revision

API Documentation at this revision

Comitter:
filipksiezyc
Date:
Mon Jun 15 12:27:46 2020 +0000
Parent:
1:05446788fe9c
Commit message:
VECTOR;

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
KeyboardTsLcd.cpp Show diff for this revision Revisions of this file
KeyboardTsLcd.h 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
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keyboard.cpp	Mon Jun 15 12:27:46 2020 +0000
@@ -0,0 +1,29 @@
+#include "Keyboard.h"
+
+Keyboard::Keyboard(unsigned char ucColumn){
+        LCD_Touch.Init(420, 272);   
+        uiColumnNumber=ucColumn;
+}
+
+enum eButtonStates Keyboard::eRead(){
+    TS_StateTypeDef TS_State;   
+    LCD_Touch.GetState(&TS_State);
+    
+    if((TS_State.X>(80*uiColumnNumber))&&(TS_State.X<(81+uiColumnNumber*80))){
+        if((TS_State.Y>0)&&(TS_State.Y<81))
+            return BUTTON_0;
+        else if((TS_State.Y>80)&&(TS_State.Y<161))
+            return BUTTON_1;
+        else if((TS_State.Y>160)&&(TS_State.Y<241))
+            return BUTTON_2;
+        else if((TS_State.Y>240)&&(TS_State.Y<320))
+            return BUTTON_3;
+        else 
+        return NONE;
+    }
+    else {
+        return NONE;
+        }  
+}
+
+  
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keyboard.h	Mon Jun 15 12:27:46 2020 +0000
@@ -0,0 +1,16 @@
+#ifndef   KEYBOARD_H
+#define   KEYBOARD_H
+#include "TS_DISCO_F429ZI.h"
+
+enum eButtonStates{NONE, BUTTON_0, BUTTON_1, BUTTON_2, BUTTON_3};   
+
+class Keyboard{
+    private:
+        TS_DISCO_F429ZI LCD_Touch;   
+        uint16_t uiColumnNumber;
+    public:
+        Keyboard(unsigned char ucColumn=0);
+        enum eButtonStates eRead();
+};
+
+#endif 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KeyboardLed.cpp	Mon Jun 15 12:27:46 2020 +0000
@@ -0,0 +1,34 @@
+#include "KeyboardLed.h"
+
+KeyboardLed::KeyboardLed(unsigned char _ucColumn){
+    pKeyboard = new Keyboard(_ucColumn);   
+    pLedboard = new Ledboard(_ucColumn);
+}
+
+enum eButtonStates KeyboardLed::eRead(){
+      enum eButtonStates eReturnValue;
+      
+      switch(pKeyboard->eRead()) {
+            case BUTTON_0:
+                eReturnValue=BUTTON_0;
+                pLedboard->On(0);
+                break;
+            case BUTTON_1:
+                eReturnValue=BUTTON_1;
+                pLedboard->On(1);
+                break;
+            case BUTTON_2:
+                eReturnValue=BUTTON_2;
+                pLedboard->On(2);
+                break;
+            case BUTTON_3:
+                eReturnValue=BUTTON_3;
+                pLedboard->On(3);
+                break;
+            default :
+                eReturnValue=NONE;
+                pLedboard->Off();
+                break;
+            }  
+            return eReturnValue;
+}    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KeyboardLed.h	Mon Jun 15 12:27:46 2020 +0000
@@ -0,0 +1,15 @@
+#ifndef KEYBOARDLED_H
+#define KEYBOARDLED_H
+#include "Keyboard.h"
+#include "Ledboard.h"
+
+class KeyboardLed{
+    private:  
+        Keyboard* pKeyboard;
+        Ledboard* pLedboard;    
+    public:
+        KeyboardLed(unsigned char _ucColumn=0);
+        enum eButtonStates eRead();
+};
+
+#endif
\ No newline at end of file
--- a/KeyboardTsLcd.cpp	Mon May 25 13:41:17 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-#include "KeyboardTsLcd.h"
-
-KeyboardTsLcd::KeyboardTsLcd(unsigned char _ucColumn){
-    pKeyboard = new KeyboardTs(_ucColumn);   
-    pLed = new LedLcd(_ucColumn);
-}
-
-enum eButtonStates KeyboardTsLcd::eRead(){
-      enum eButtonStates eReturnValue;
-      switch(pKeyboard->eRead()) {
-            case BUTTON_0:
-                eReturnValue=BUTTON_0;
-                pLed->On(0);
-                break;
-            case BUTTON_1:
-                eReturnValue=BUTTON_1;
-                pLed->On(1);
-                break;
-            case BUTTON_2:
-                eReturnValue=BUTTON_2;
-                pLed->On(2);
-                break;
-            case BUTTON_3:
-                eReturnValue=BUTTON_3;
-                pLed->On(3);
-                break;
-            default :
-                eReturnValue=NONE;
-                pLed->On(4);
-                break;
-            }  
-            return eReturnValue;
-}    
\ No newline at end of file
--- a/KeyboardTsLcd.h	Mon May 25 13:41:17 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#ifndef KEYBOARDTSLCD_H
-#define KEYBOARDTSLCD_H
-#include "Keyboard_Ts.h"
-#include "Led_Lcd.h"
-
-class KeyboardTsLcd{
-    private:  
-        KeyboardTs* pKeyboard;
-        LedLcd* pLed;    
-    public:
-        KeyboardTsLcd(unsigned char _ucColumn=0);
-        enum eButtonStates eRead();
-};
-
-#endif
\ No newline at end of file
--- a/Keyboard_Ts.cpp	Mon May 25 13:41:17 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){
-        LCD_Touch.Init(420, 272);   
-        uiColumnNumber=ucColumn;
-}
-
-enum eButtonStates KeyboardTs::eRead(){
-    TS_StateTypeDef TS_State;   
-    LCD_Touch.GetState(&TS_State);
-    
-    if((TS_State.X>(80*uiColumnNumber))&&(TS_State.X<(81+uiColumnNumber*80))){
-        if((TS_State.Y>0)&&(TS_State.Y<81))
-            return BUTTON_0;
-        else if((TS_State.Y>80)&&(TS_State.Y<161))
-            return BUTTON_1;
-        else if((TS_State.Y>160)&&(TS_State.Y<241))
-            return BUTTON_2;
-        else if((TS_State.Y>240)&&(TS_State.Y<320))
-            return BUTTON_3;
-        else 
-        return NONE;
-    }
-    else {
-        return NONE;
-        }  
-}
-
-  
\ No newline at end of file
--- a/Keyboard_Ts.h	Mon May 25 13:41:17 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-#ifndef   KEYBOARD_TS_H
-#define   KEYBOARD_TS_H
-#include "TS_DISCO_F429ZI.h"
-
-enum eButtonStates{NONE, BUTTON_0, BUTTON_1, BUTTON_2, BUTTON_3};   
-
-class KeyboardTs{
-    private:
-        TS_DISCO_F429ZI LCD_Touch;   
-        uint16_t uiColumnNumber;
-    public:
-        KeyboardTs(unsigned char ucColumn=0);
-        enum eButtonStates eRead();
-};
-
-#endif 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.cpp	Mon Jun 15 12:27:46 2020 +0000
@@ -0,0 +1,38 @@
+#include "Led.h"
+
+
+extern LCD_DISCO_F429ZI LCD_Display;
+
+Led::Led(unsigned char ucColumnNr, unsigned char ucRowNr){
+    LCD_Display.Clear(LCD_COLOR_BLACK);
+    LCD_Display.SetBackColor(LCD_COLOR_RED);
+    LCD_Display.SetFont(&Font24); 
+    ucColumn=ucColumnNr;
+    ucRow=ucRowNr;
+    
+    Off();
+}   
+
+void  Led::Redraw(uint32_t Color){
+    LCD_Display.SetTextColor(LCD_COLOR_GREEN);  
+    LCD_Display.DrawRect((80*ucColumn) ,ucRow*80,80,80);
+    LCD_Display.SetTextColor(Color);
+    LCD_Display.FillRect(1+80*ucColumn , 1+ucRow*80, 79, 79);
+    
+    LCD_Display.SetTextColor(LCD_COLOR_RED);
+    LCD_Display.FillRect(80*ucColumn, ucRow*80, 20, 25);
+    LCD_Display.SetTextColor(LCD_COLOR_WHITE);
+    char cDisplay[2];
+    sprintf(cDisplay, "%d", ucRow);
+    LCD_Display.DisplayStringAt(2+80*ucColumn, 2+ucRow*80,(uint8_t *) cDisplay, LEFT_MODE);
+}
+ 
+
+void Led::On(){
+    Redraw(LCD_COLOR_GREEN);
+}     
+    
+void Led::Off(){
+    Redraw(LCD_COLOR_BLUE);
+}
+      
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Led.h	Mon Jun 15 12:27:46 2020 +0000
@@ -0,0 +1,15 @@
+#ifndef LED_H
+#define LED_H
+#include "LCD_DISCO_F429ZI.h"
+
+class Led {
+    public:
+        Led(unsigned char ucColumnNr, unsigned char ucRowNr);
+        void On();
+        void Off();
+    private:
+        unsigned char ucColumn, ucRow;
+        void Redraw(uint32_t Color);
+};
+
+#endif
\ No newline at end of file
--- a/Led_Lcd.cpp	Mon May 25 13:41:17 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-#include "Led_Lcd.h"
-#define MAX_DISPLAY_NUMBER 3
-
-LedLcd::LedLcd(unsigned char ucColumn){
-    LCD_Display.Clear(LCD_COLOR_BLACK);
-    LCD_Display.SetBackColor(LCD_COLOR_RED);
-    LCD_Display.SetFont(&Font24); 
-    uiColumnNumber=ucColumn;
-    
-    On(4);
-    }   
-
-void  LedLcd::DrawKey(unsigned char ucKeyNumber){
-    LCD_Display.SetTextColor(LCD_COLOR_GREEN);  
-    LCD_Display.DrawRect((80*uiColumnNumber) ,ucKeyNumber*80,80,80);
-    LCD_Display.SetTextColor(uiColor[ucKeyNumber]);
-    LCD_Display.FillRect(1+80*uiColumnNumber , 1+ucKeyNumber*80, 79, 79);
-    
-    LCD_Display.SetTextColor(LCD_COLOR_RED);
-    LCD_Display.FillRect(80*uiColumnNumber, ucKeyNumber*80, 20, 25);
-    LCD_Display.SetTextColor(LCD_COLOR_WHITE);
-    char cDisplay[MAX_DISPLAY_NUMBER];
-    sprintf(cDisplay, "%d", ucKeyNumber);
-    LCD_Display.DisplayStringAt(2+80*uiColumnNumber, 2+ucKeyNumber*80,(uint8_t *) cDisplay, LEFT_MODE);
-}
- 
-
-void LedLcd::On(unsigned char ucKeyNumber){
-    uint8_t CurrentKey;
-    for(CurrentKey=0; CurrentKey<NUMBER_OF_KEYS; CurrentKey++){
-        if(CurrentKey==ucKeyNumber){
-            uiColor[CurrentKey]=LCD_COLOR_GREEN;
-            }
-        else{
-            uiColor[CurrentKey]=LCD_COLOR_BLUE;
-            }
-        DrawKey(CurrentKey);
-        }
-    }     
-    
\ No newline at end of file
--- a/Led_Lcd.h	Mon May 25 13:41:17 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-#ifndef   LED_LCD_H
-#define   LED_LCD_H
-#include "LCD_DISCO_F429ZI.h"
-
-#define NUMBER_OF_KEYS 4
-
-class LedLcd{
-    private:
-        uint32_t uiColor[NUMBER_OF_KEYS];
-        uint16_t uiColumnNumber;
-        LCD_DISCO_F429ZI LCD_Display;
-        void DrawKey(unsigned char ucKeyNumber);
-    public:
-        LedLcd(unsigned char ucColumn=0);
-        void On(unsigned char ucKeyNumber);        
-};
-
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ledboard.cpp	Mon Jun 15 12:27:46 2020 +0000
@@ -0,0 +1,24 @@
+#include "Ledboard.h"
+
+
+
+Ledboard::Ledboard(unsigned char ucColumn){
+    
+    unsigned char ucCurrentKey;
+    for(ucCurrentKey=0; ucCurrentKey<NUMBER_OF_KEYS; ucCurrentKey++){ 
+        Leds.push_back(Led(ucColumn, ucCurrentKey));
+        }
+    Off();
+}   
+ 
+void Ledboard::On(unsigned char ucKeyNumber){
+    Off();
+    Leds[ucKeyNumber].On();
+}     
+    
+void Ledboard::Off(){
+    for(viCurrentLed=Leds.begin(); viCurrentLed!=Leds.end(); viCurrentLed++){
+            viCurrentLed->Off();;
+            }
+}
+      
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ledboard.h	Mon Jun 15 12:27:46 2020 +0000
@@ -0,0 +1,19 @@
+#ifndef   LEDBOARD_H
+#define   LEDBOARD_H
+
+#include "Led.h"
+#include <vector>
+
+#define NUMBER_OF_KEYS 4
+
+class Ledboard {
+    public:
+        Ledboard (unsigned char ucColumn);
+        void Off();
+        void On(unsigned char);
+    private:
+        std::vector<Led> Leds;
+        std::vector<Led>::iterator viCurrentLed;
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp	Mon May 25 13:41:17 2020 +0000
+++ b/main.cpp	Mon Jun 15 12:27:46 2020 +0000
@@ -1,11 +1,12 @@
 #include "mbed.h"
-#include "KeyboardTsLcd.h"
+#include "KeyboardLed.h"
+#include "LCD_DISCO_F429ZI.h"
 
-
+LCD_DISCO_F429ZI LCD_Display;
 
 int main() {
-    KeyboardTsLcd LeftKeyboard(0);
-    LedLcd RightLed(2);
+    KeyboardLed LeftKeyboard(0);
+    Ledboard RightLed(2);
     
     while(1) {
          switch(LeftKeyboard.eRead()) {
@@ -22,7 +23,7 @@
                 RightLed.On(0);
                 break;
             default :
-                RightLed.On(4);
+                RightLed.Off();
                 break;
             }
         wait(0.1);