mbed2 pre-final

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Revision:
2:7dc265489818
Child:
4:a8494b656292
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/servo_gui.cpp	Sun Jun 14 11:13:56 2020 +0000
@@ -0,0 +1,95 @@
+#include "servo_gui.h"
+
+#define PI 3.14159
+#define SERVO_FREQUENCY 50
+
+extern DigitalIn UserButton;
+
+ServoGui::ServoGui(void)
+{
+    lcd.Clear(LCD_COLOR_WHITE);
+    DrawServo();
+    
+    uiMarkerStartPos = 0;
+    uiMarkerPos = 0;
+    ucLedPos = 0;
+    
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    unsigned char ucLedXpos = 55;
+    for(unsigned char ucLedCounter = 0; ucLedCounter < 4; ucLedCounter++) {
+        lcd.DrawCircle(ucLedXpos, 280, 16);
+        ucLedXpos += 40;
+    }
+}
+
+void ServoGui::LedStepRight(void) {
+    LedStep(RIGHT);
+}
+
+void ServoGui::LedStepLeft(void) {
+    LedStep(LEFT);
+}
+
+enum DetectorState ServoGui::eReadDetector(void) {
+    if (UserButton == 1) {
+        return ACTIVE;
+    }
+    else {
+        return INACTIVE;
+    }
+}
+
+void ServoGui::LedOn(unsigned char ucLedIndex) {
+    LedClear();
+    lcd.SetTextColor(LCD_COLOR_BLUE);
+    lcd.FillCircle(55 + (40 * ucLedIndex), 280, 15);
+}
+
+void ServoGui::LedStep(enum Direction eStepDirection) {
+    
+    static unsigned int uiLedPoint = 0;
+
+    switch(eStepDirection) {
+        case LEFT:
+            uiLedPoint--;
+            if(uiMarkerPos == 0) {
+                uiMarkerPos = 359;
+            }
+            else {
+                uiMarkerPos--;
+            }
+            break;
+        case RIGHT:
+            uiLedPoint++;
+            uiMarkerPos++;
+            break;
+    }
+    LedOn(uiLedPoint % 4);
+   // wait(0.01);
+    uiMarkerPos = uiMarkerPos % 360;
+    DrawServo();
+    //wait(0.01);
+    DrawMarker(uiMarkerPos);
+}
+
+void ServoGui::LedClear(void)
+{
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    unsigned char ucLedXpos =  55;
+    for(unsigned char ucLedCounter = 0; ucLedCounter < 4; ucLedCounter++) {
+        lcd.FillCircle(ucLedXpos, 280, 15);
+        ucLedXpos += 40;
+    }
+}
+
+void ServoGui::DrawServo(void) {
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.FillCircle(120, 120, 100);
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    lcd.FillCircle(120, 120, 20);
+}
+
+void ServoGui::DrawMarker(unsigned int uiPosition) {
+    lcd.SetTextColor(LCD_COLOR_WHITE); 
+    lcd.DrawLine(120, 120, (120 + (100 * cos((uiMarkerStartPos + uiPosition) * PI / 180))), (120 + (100 * sin((uiMarkerStartPos + uiPosition) * PI / 180))));
+}