Ćwiczenie zrealizowane na potrzeby przedmiotu PPO przez Krzysztofa Bolka

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI

Files at this revision

API Documentation at this revision

Comitter:
bolko
Date:
Wed May 20 07:59:22 2020 +0000
Parent:
0:f4c2a4d3c318
Commit message:
Poprawiona wersja.

Changed in this revision

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_Lcd.cpp Show diff for this revision Revisions of this file
Led_Lcd.h Show diff for this revision Revisions of this file
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
keyboard_ts_lcd.cpp Show annotated file Show diff for this revision Revisions of this file
keyboard_ts_lcd.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
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Keyboard_Ts.cpp	Tue May 12 15:42:00 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-#include "Keyboard_Ts.h"
-#include "TS_DISCO_F429ZI.h"
-
-TS_DISCO_F429ZI ts;
-
-KeyboardTs::KeyboardTs(uint8_t WhichColumn){
-        ts.Init(240,320);
-        ui8Column = ((WhichColumn > 1) && (WhichColumn <= 3)) ? WhichColumn: 1;
-    };
-enum KeyboardState KeyboardTs::eRead(void){
-        TS_StateTypeDef TS_State; 
-        ts.GetState(&TS_State);
-        
-             if(TS_State.TouchDetected &&(TS_State.X > (80*(ui8Column-1))) && (TS_State.X<(80*ui8Column))){
-                 if((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;
-    };
\ No newline at end of file
--- a/Keyboard_Ts.h	Tue May 12 15:42:00 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef KEYBOARD_TS_H
-#define KEYBOARD_TS_H
-#include "mbed.h"
-
-enum KeyboardState{
-    BUTTON_0,
-    BUTTON_1,
-    BUTTON_2,
-    BUTTON_3,
-    RELEASED
-    };
-    
-class KeyboardTs{
-    public:
-        enum KeyboardState eRead();
-        KeyboardTs(uint8_t);
-    private:
-        uint8_t ui8Column;
-    };
-
-
-#endif
\ No newline at end of file
--- a/Led_Lcd.cpp	Tue May 12 15:42:00 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-#include "Led_Lcd.h"
-#include "mbed.h"
-#include "LCD_DISCO_F429ZI.h"
-#include <cstdlib> 
-
-LCD_DISCO_F429ZI lcd;
-
-LedLcd::LedLcd(uint8_t WhichColumn){
-    lcd.Clear(LCD_COLOR_BLACK);
-    ui8Column = ((WhichColumn > 1) && (WhichColumn <= 3)) ? WhichColumn: 1;  
-    };
-
-void LedLcd::Button(uint8_t ui8ButtonNumber, ButtonState eButtonState){
-     char ui8Buffer[4];
-      
-     lcd.SetTextColor(LCD_COLOR_GREEN);
-     lcd.DrawRect(((ui8Column-1)*80),80*ui8ButtonNumber,80,80);
-     
-     if(eButtonState == BUTTON_PRESSED) lcd.SetTextColor(LCD_COLOR_GREEN); 
-     else if(eButtonState == BUTTON_RELEASED) lcd.SetTextColor(LCD_COLOR_BLUE); 
-     lcd.FillRect(((ui8Column-1)*80)+2,80*ui8ButtonNumber+2,77,77);
-     
-     BSP_LCD_SetFont(&Font24);
-     lcd.SetBackColor(LCD_COLOR_RED);
-     sprintf(ui8Buffer,"%d",ui8ButtonNumber);
-     lcd.SetTextColor(LCD_COLOR_WHITE);   
-     lcd.DisplayStringAt(((ui8Column-1)*80)+1,80*ui8ButtonNumber+1,(uint8_t *)&ui8Buffer,LEFT_MODE);
-    };     
-        
-void LedLcd::On(uint8_t ui8ButtonNumber){     
-    for(uint8_t ui8Counter=0; ui8Counter<4; ui8Counter++){
-            if(ui8Counter == ui8ButtonNumber) Button(ui8Counter,BUTTON_PRESSED);
-            else Button(ui8Counter,BUTTON_RELEASED);
-        }  
-    };
\ No newline at end of file
--- a/Led_Lcd.h	Tue May 12 15:42:00 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#ifndef LED_LCD_H
-#define LED_LCD_H
-#include "LCD_DISCO_F429ZI.h"
-
-enum ButtonState {
-    BUTTON_PRESSED,
-    BUTTON_RELEASED
-    };
-
-
-class LedLcd{
-    public:
-        LedLcd(uint8_t);
-        void On(uint8_t);
-    private:
-        void Button(uint8_t,ButtonState);
-        uint8_t ui8Column;
-    };
-    
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keyboard_ts.cpp	Wed May 20 07:59:22 2020 +0000
@@ -0,0 +1,29 @@
+#include "keyboard_ts.h"
+#include "TS_DISCO_F429ZI.h"
+
+TS_DISCO_F429ZI ts;
+
+KeyboardTs::KeyboardTs(uint8_t WhichColumn){
+        ts.Init(240,320);
+        ui8Column = ((WhichColumn > 1) && (WhichColumn <= 3)) ? WhichColumn: 1;
+};
+enum KeyboardState KeyboardTs::eRead(void){
+        TS_StateTypeDef TS_State; 
+        ts.GetState(&TS_State);
+        
+             if(TS_State.TouchDetected &&(TS_State.X > (80*(ui8Column-1))) && (TS_State.X<(80*ui8Column))){
+                 if((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;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/keyboard_ts.h	Wed May 20 07:59:22 2020 +0000
@@ -0,0 +1,22 @@
+#ifndef KEYBOARD_TS_H
+#define KEYBOARD_TS_H
+#include "mbed.h"
+
+enum KeyboardState{
+    BUTTON_0,
+    BUTTON_1,
+    BUTTON_2,
+    BUTTON_3,
+    RELEASED
+};
+    
+class KeyboardTs{
+    public:
+        enum KeyboardState eRead();
+        KeyboardTs(uint8_t);
+    private:
+        uint8_t ui8Column;
+};
+
+
+#endif
\ No newline at end of file
--- a/keyboard_ts_lcd.cpp	Tue May 12 15:42:00 2020 +0000
+++ b/keyboard_ts_lcd.cpp	Wed May 20 07:59:22 2020 +0000
@@ -23,5 +23,5 @@
             default :
                 pLed->On(4);
                 return RELEASED;         
-            }
+         }   
     };
\ No newline at end of file
--- a/keyboard_ts_lcd.h	Tue May 12 15:42:00 2020 +0000
+++ b/keyboard_ts_lcd.h	Wed May 20 07:59:22 2020 +0000
@@ -1,7 +1,7 @@
 #ifndef KEYBOARD_TS_LCD_H
 #define KEYBOARD_TS_LCD_H
-#include "Led_Lcd.h"
-#include "Keyboard_Ts.h"
+#include "led_lcd.h"
+#include "keyboard_ts.h"
 
 class KeyboardTsLcd{
     public:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led_lcd.cpp	Wed May 20 07:59:22 2020 +0000
@@ -0,0 +1,51 @@
+#include "led_lcd.h"
+#include "mbed.h"
+#include "LCD_DISCO_F429ZI.h"
+
+LCD_DISCO_F429ZI lcd;
+
+LedLcd::LedLcd(uint8_t WhichColumn){
+    lcd.Clear(LCD_COLOR_BLACK);
+    ui8Column = ((WhichColumn > 1) && (WhichColumn <= 3)) ? WhichColumn: 1;
+      
+};
+
+void LedLcd::DrawLed(uint8_t ui8LedNumber, LedState eLedState){
+     char cBuffer[2];
+      
+     lcd.SetTextColor(LCD_COLOR_GREEN);
+     lcd.DrawRect(((ui8Column-1)*80),80*ui8LedNumber,80,80);
+     
+     if(eLedState == LED_PRESSED){
+          lcd.SetTextColor(LCD_COLOR_GREEN); 
+     }
+    else if(eLedState == LED_RELEASED){
+          lcd.SetTextColor(LCD_COLOR_BLUE); 
+    }
+    
+     lcd.FillRect(((ui8Column-1)*80)+2,80*ui8LedNumber+2,77,77);
+     
+     BSP_LCD_SetFont(&Font24);
+     lcd.SetBackColor(LCD_COLOR_RED);
+     sprintf(cBuffer,"%d",ui8LedNumber);
+     lcd.SetTextColor(LCD_COLOR_WHITE);   
+     lcd.DisplayStringAt(((ui8Column-1)*80)+1,80*ui8LedNumber+1,(uint8_t *)&cBuffer,LEFT_MODE);
+};     
+        
+/*void LedLcd::On(uint8_t ui8LedNumber){     
+    
+    for(uint8_t ui8LedCounter=0; ui8LedCounter<4; ui8LedCounter++){
+            if(ui8LedCounter == ui8LedNumber){ 
+                DrawLed(ui8LedCounter,LED_PRESSED);
+            }
+            else {
+                DrawLed(ui8LedCounter,LED_RELEASED);
+            }
+    }*/
+void LedLcd::On(uint8_t ui8LedNumber){ 
+
+     for(uint8_t ui8LedCounter = 0; ui8LedCounter <= 3; ui8LedCounter++){
+            DrawLed(ui8LedCounter, LED_RELEASED);
+     } 
+     DrawLed(ui8LedNumber,LED_PRESSED);                                                  
+};  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led_lcd.h	Wed May 20 07:59:22 2020 +0000
@@ -0,0 +1,20 @@
+#ifndef LED_LCD_H
+#define LED_LCD_H
+#include "LCD_DISCO_F429ZI.h"
+
+enum LedState {
+    LED_PRESSED,
+    LED_RELEASED
+    };
+
+
+class LedLcd{
+    public:
+        LedLcd(uint8_t);
+        void On(uint8_t);
+    private:
+        void DrawLed(uint8_t,LedState);
+        uint8_t ui8Column;
+    };
+    
+#endif
\ No newline at end of file
--- a/main.cpp	Tue May 12 15:42:00 2020 +0000
+++ b/main.cpp	Wed May 20 07:59:22 2020 +0000
@@ -1,16 +1,30 @@
 #include "mbed.h"
 #include "keyboard_ts_lcd.h"
-#define BUTTONS 3
 
 int main()
 {  
-    KeyboardTsLcd MyKeyboard(1);
+    KeyboardTsLcd MyKeyboardTsLcd(1);
     LedLcd MyLed(3);
   
-    while(1){
-       MyLed.On(BUTTONS - MyKeyboard.eRead());
-       wait(0.1); 
-        } 
-  
+    while(1){  
+       switch(MyKeyboardTsLcd.eRead()){
+           case BUTTON_0:
+                MyLed.On(3);
+                break;
+            case BUTTON_1:
+                MyLed.On(2);
+                break; 
+            case BUTTON_2:
+                MyLed.On(1);
+                break;    
+            case BUTTON_3:
+                MyLed.On(0);
+                break;   
+            default:
+                MyLed.On(4);
+            break; 
+        }
+     wait(0.1); 
+     } 
 }