Mateusz Garwol / Mbed 2 deprecated 2_5

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Files at this revision

API Documentation at this revision

Comitter:
matis755
Date:
Fri May 22 07:21:44 2020 +0000
Parent:
4:e48aee3e8d09
Child:
6:06ff453bb16e
Commit message:
Add GUI,; Get ready to deploy

Changed in this revision

BSP_DISCO_F429ZI.lib Show annotated file Show diff for this revision Revisions of this file
LCD_DISCO_F429ZI.lib Show annotated file Show diff for this revision Revisions of this file
decoder.cpp Show annotated file Show diff for this revision Revisions of this file
decoder.h Show annotated file Show diff for this revision Revisions of this file
gui.cpp Show annotated file Show diff for this revision Revisions of this file
gui.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
stepper.cpp Show annotated file Show diff for this revision Revisions of this file
stepper.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_DISCO_F429ZI.lib	Fri May 22 07:21:44 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/BSP_DISCO_F429ZI/#53d9067a4feb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_DISCO_F429ZI.lib	Fri May 22 07:21:44 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/LCD_DISCO_F429ZI/#dc55a068bc1a
--- a/decoder.cpp	Thu May 21 11:03:32 2020 +0000
+++ b/decoder.cpp	Fri May 22 07:21:44 2020 +0000
@@ -121,3 +121,7 @@
 enum KeywordCode Decoder::eGetKeyword(unsigned char ucIdx) {
     return asToken[ucIdx].uValue.eKeyword;    
 }
+
+unsigned int Decoder::uiGetNumber(unsigned char ucIdx) {
+    return asToken[ucIdx].uValue.uiNumber;    
+}
--- a/decoder.h	Thu May 21 11:03:32 2020 +0000
+++ b/decoder.h	Fri May 22 07:21:44 2020 +0000
@@ -1,8 +1,10 @@
 #ifndef DECODER
 #define DECODER
 
+
 #include "mbed.h"
 
+
 #define NULL 0
 #define TERMINATOR '\r'
 #define DELIMITER_CHAR 0x20
@@ -12,7 +14,6 @@
 #define MAX_KEYWORD_STRING_LTH 6
 #define MAX_KEYWORD_NR 4
 
-
 typedef enum TokenType 
 {KEYWORD, NUMBER, STRING} TokenType;
 
@@ -40,8 +41,6 @@
 } Keyword;
 
 
-
-
 class Decoder {
     private:
         struct Token asToken[MAX_TOKEN_NR];
@@ -55,6 +54,7 @@
         void DecodeMsg(char *pcString);
         enum TokenType eGetTokenType(unsigned char ucIdx);
         enum KeywordCode eGetKeyword(unsigned char ucIdx);
+        unsigned int uiGetNumber(unsigned char ucIdx);
         unsigned char GetTokenCnt(void);
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui.cpp	Fri May 22 07:21:44 2020 +0000
@@ -0,0 +1,61 @@
+#include "gui.h"
+
+#define pi 3.14159265359
+
+Gui::Gui() {
+    Clear(LCD_COLOR_WHITE);
+    SetTextColor(LCD_COLOR_BLACK);
+    for(unsigned char i=0; i<4; i++) {
+        DrawCircle((32 + i*58), 284, 25);
+    }   
+    DrawTop();
+    DrawLine(120, 130, 120, 25);
+    ucInitialPos = 0;
+}
+
+void Gui::DrawTop(void) {
+    SetTextColor(LCD_COLOR_BLACK);
+    DrawCircle(120, 130, 105);
+    FillCircle(120, 130, 105);
+    SetTextColor(LCD_COLOR_WHITE);
+    FillCircle(120, 130, 25);
+}
+
+void Gui::RefreshLeds(unsigned char ucIdx) {
+    SetTextColor(LCD_COLOR_WHITE);
+    for(unsigned char i=0; i<4; i++) {
+        FillCircle((32 + i*58), 284, 24);
+    }
+    SetTextColor(LCD_COLOR_CYAN);
+    switch(ucIdx){
+        case 0:
+            FillCircle(32, 284, 24);
+            break;
+        case 1:
+            FillCircle(90, 284, 24);
+            break;
+        case 2:
+            FillCircle(148, 284, 24);
+            break;
+        case 3:
+            FillCircle(206, 284, 24);
+            break;
+        default:
+            break;
+    }
+    SetTextColor(LCD_COLOR_BLACK);
+    for(unsigned char i=0; i<4; i++) {
+        DrawCircle((32 + i*58), 284, 25);
+    }
+}
+
+void Gui::RefreshTop(unsigned char ucPos){
+    float fAngle = (((ucPos+ucInitialPos)*pi)/24);
+    DrawTop();
+    SetTextColor(LCD_COLOR_WHITE);
+    DrawLine(120, 130, 120+105*sin(fAngle), 130-105*cos(fAngle));   
+}
+
+void Gui::SetRelAngle(unsigned char ucInitial){
+    ucInitialPos = ucInitial;    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui.h	Fri May 22 07:21:44 2020 +0000
@@ -0,0 +1,18 @@
+#ifndef GUI
+#define GUI
+
+#include "LCD_DISCO_F429ZI.h"
+
+class Gui : private LCD_DISCO_F429ZI{
+    private:
+        void DrawTop(void);
+        unsigned char ucInitialPos;
+    public:
+        Gui();
+        void RefreshLeds(unsigned char ucIdx);
+        void RefreshTop(unsigned char ucPos);
+        void SetRelAngle(unsigned char ucInitial);
+};
+
+
+#endif
\ No newline at end of file
--- a/main.cpp	Thu May 21 11:03:32 2020 +0000
+++ b/main.cpp	Fri May 22 07:21:44 2020 +0000
@@ -3,11 +3,6 @@
 #include "uart.h"
 #include "stepper.h"
 
-
-DigitalOut led_green(LED1);
-DigitalOut led_red(LED2);
-
-
 int main() {
     Decoder MyDecoder;
     Uart MyUart;
@@ -27,17 +22,15 @@
                         MyUart.puts(cIdentifier, BUFFER_SIZE);
                         break;
                     case (CLB):
-                        led_green = !led_green;
                         MyStepper.Callib();
                         MyUart.puts(cCorrectResponse, BUFFER_SIZE);
                         break;
                     case (GT):
-                        led_red = !led_red;
-                        MyStepper.Goto(4);
+                        MyStepper.Goto(MyDecoder.uiGetNumber(1));
                         MyUart.puts(cCorrectResponse, BUFFER_SIZE);
                         break;
                     case (ST):
-                        MyStepper.Step(5);
+                        MyStepper.Step(MyDecoder.uiGetNumber(1));
                         MyUart.puts(cCorrectResponse, BUFFER_SIZE);
                         break;
                     default:
--- a/stepper.cpp	Thu May 21 11:03:32 2020 +0000
+++ b/stepper.cpp	Fri May 22 07:21:44 2020 +0000
@@ -1,48 +1,54 @@
 #include "stepper.h"
 
+#define TDELAY 0.2
+
 enum Step{LEFT,RIGHT};
 
-Stepper::Stepper() : Button(USER_BUTTON){
+Stepper::Stepper(void) : Button(USER_BUTTON){
 }
 
 void Stepper::Step(enum Step eStep){
     if(eStep == LEFT){
-        ucLedIdx++;
+        ucLedIdx --;
     }
     else if(eStep == RIGHT){
-        ucLedIdx--;
+        ucLedIdx ++;
     }
     else{}
     ucLedIdx = ucLedIdx % 4;
     MyLed.On(ucLedIdx);
+    MyGui.RefreshLeds(ucLedIdx);
+    MyGui.RefreshTop(ucCurrentPos);
 }
 
 void Stepper::StepLeft(void){
+    ucCurrentPos --;
     Step(LEFT);
 }
 
 void Stepper::StepRight(void){
+    ucCurrentPos ++;
     Step(RIGHT);
 }
 
 void Stepper::Callib(void) {
     while(!Button) {
         StepRight();
-        wait(0.1);
+        wait(TDELAY);
     }
+    MyGui.SetRelAngle(ucCurrentPos);
+    ucCurrentPos = 0;
 }
 
 void Stepper::Goto(unsigned char ucDestination) {
     ucDesiredPos = ucDestination;
     while (ucCurrentPos > ucDesiredPos) {
         StepLeft();
-        ucCurrentPos --;
-        wait(0.2);
+        wait(TDELAY);
     }
     while (ucCurrentPos < ucDesiredPos) {
         StepRight();
-        ucCurrentPos ++;
-        wait(0.2);
+        wait(TDELAY);
     } 
 }
 
@@ -50,8 +56,6 @@
     ucDesiredPos = ucCurrentPos + ucSteps;
     while (ucCurrentPos < ucDesiredPos) {
         StepRight();
-        ucCurrentPos ++;
-        wait(0.2);
+        wait(TDELAY);
     } 
 }
-
--- a/stepper.h	Thu May 21 11:03:32 2020 +0000
+++ b/stepper.h	Fri May 22 07:21:44 2020 +0000
@@ -2,17 +2,19 @@
 #define STEPPER
 
 #include "led.h"
+#include "gui.h"
 
 class Stepper {
     private:
         DigitalIn Button;
         Led MyLed;
+        Gui MyGui;
         unsigned char ucLedIdx, ucCurrentPos, ucDesiredPos;
         void Step(enum Step);
         void StepLeft(void);
         void StepRight(void);
     public:
-        Stepper();
+        Stepper(void);
         void Callib(void);
         void Goto(unsigned char);
         void Step(unsigned char);