PlayBack

Dependencies:   TPixy-Interface

Fork of ManualControlFinal by ECE4333 - 2018 - Ahmed & Brandon

Revision:
0:a355e511bc5d
Child:
1:3e9684e81312
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui.cpp	Thu Feb 01 03:58:00 2018 +0000
@@ -0,0 +1,102 @@
+#include "mbed.h"
+#include "WatchdogThread.h"
+#include "ui.h"
+
+Serial bluetooth(p9,p10); // Define the bluetooth channel and IO pins
+Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel
+
+Mutex setpoint_mutex;
+
+// speed
+int setpoint;
+
+// variable to store character recieved from terminal
+char x;
+
+extern uint16_t dPosition, dTime;
+
+uint16_t position;
+
+/******************************************************************************
+            A function to test blutooth communication
+******************************************************************************/
+void twoTerminalsTest()
+{
+    if (pc.readable()) { // If a key is pressed on the pc channel
+        x=pc.getc(); // read the character and send it to both the
+        bluetooth.putc(x); // bluetooth channel and the pc channel for
+        pc.putc(x); // display.
+    }
+    if (bluetooth.readable()) {
+        x=bluetooth.getc(); // If there’s a keypress on the bluetooth
+        pc.putc(x); // channel, read the character and send it to
+        bluetooth.putc(x); // both the pc channel and the bluetooth
+    } // channel for display
+}
+
+
+/******************************************************************************
+            A function to Display startup Messsage
+******************************************************************************/
+void displayStartupMsg()
+{
+    pc.printf("\r\n************************************");
+    pc.printf("\r\n**** DC Motor Control using PWM ****");
+    pc.printf("\r\n************************************");
+    pc.printf("\r\n-Enter r to reset the watchdog timer");
+    pc.printf("\r\n-press w to increase motor speed");
+    pc.printf("\r\n-press s to decrease motor speed");
+}
+
+
+/******************************************************************************
+                            Console interface
+******************************************************************************/
+void consoleUI(void)
+{
+    if (pc.readable()) {
+        x = pc.getc();
+
+        // if input from console is the letter 'r'
+        if(x == 'r') {
+            // reset watchdog timer
+            WatchdogReset();
+            pc.printf("\r\nWatchdog has been reset");
+        }
+
+        // if w is pressed increase the speed
+        // by incrementing u
+        else if(x == 'w') {
+            // convert to integer
+            if(setpoint<=10000) {
+                setpoint_mutex.lock();
+                setpoint = setpoint + SPEED_STEP;
+                setpoint_mutex.unlock();
+            }
+            // display speed
+            pc.printf("\r\n %5d", setpoint);
+        }
+
+        // if s is pressed decrease the speed
+        // by decrementing u
+        else if(x == 's') {
+            // convert to integer
+            if(setpoint>-10000) {
+                setpoint_mutex.lock();
+                setpoint = setpoint - SPEED_STEP;
+                setpoint_mutex.unlock();
+            }
+            // display speed
+            pc.printf("\r\n %5d", setpoint);
+        }
+
+        // error wrong input
+        else {
+            pc.printf("\r\nwrong input please enter \'w\' to increase the speed, \'s\' to reduce it or move in the opposite direction and \'r\' to reset the watchdog");
+        }
+    }
+    position += dPosition;
+    pc.printf("\r\nposition: %d, dPosition: %d, dTime: %d", position, dPosition, dTime);
+    
+}
+