This project will enable remote control of a motorised turntable via a WiFi enabled TCP link using ACKme's (http://ack.me/) Wi-Fi enablement platform

Dependencies:   mbed

Revision:
2:a73037a7d85d
Parent:
1:7b420a2ea7db
--- a/main.cpp	Tue Aug 26 12:33:27 2014 +0000
+++ b/main.cpp	Wed Aug 27 12:28:48 2014 +0000
@@ -1,116 +1,45 @@
 #include "mbed.h"
+#include "TurntableControl.h"
+#include "ConsoleSerial.h"
 
-enum calib_state_t {
-    UNCALIBRATED,
-    INITIALISING,
-    CALIBRATING,
-    CALIBRATED};
+#define CONSOLE_BAUD 115200
+
+
 
 DigitalOut my_led(LED1); // Sanity LED
-DigitalOut ttDrive(PA_14); // the drive signal for the turntable
-InterruptIn encoder(PA_13); // Signal from encoder
-InterruptIn limitSwitch(PA_15); // Signal from limit switch
-
-calib_state_t calib_state = UNCALIBRATED; // Flag for calibration state
-int encoderMax = 0; // Calibrated maximum value for the encoder
-int encoderCurrent = 0; // Keeps track of the current position of the turn table
-bool limitFlag = 0;
-
-void calibrate(); // synchronises and calibrates MCU to turntable
-void incrementEncoder(); // increments value i, used as an interrupt target
-void resetEncoder();
+TurntableControl tc; // Turntable controller
 
 
-ConsoleSerial consoleSerial(SERIAL_TX, SERIAL_RX);
+ConsoleSerial cs(SERIAL_TX, SERIAL_RX);
 
 
 int main() {
     
     
-    consoleSerial.setBaud(CONSOLE_BAUD);
+    cs.setBaud(CONSOLE_BAUD);
+    
+    cs.printf("resetting\n\r");
     
-    my_led = 0;
-    
-    // Step 1: Attach interrupt signals to appropriate functions
+    // Step 1: reset the turntable
+    tc.reset();
+    cs.printf("reset\n\rcalibrating\n\r");
     
-    limitSwitch.mode(PullUp);
-    limitSwitch.fall(&resetEncoder);  //****Ask someone about correct handling of interrupts, including; naming convention (resetEncoder also handles calib_state), potential coupling realted to having a function perform two tasks
-    encoder.mode(PullDown);
-    encoder.fall(&incrementEncoder);
-    encoder.rise(&incrementEncoder);
+    // Step 2: calibrate the turntable
+    cs.printf("Max encoder = %d\n\r", tc.calibrate());
     
-    // Step 2: Calibrate MCU to the turn table
-    calibrate();
-    // Step 3: Control turntable using hard coded commands
+    // Step 3: rotate to a specified quarter
+    tc.quarterTurns(4);
+    
+    cs.printf("Done incrementing\r\n");
+    cs.printf("Encoder Current = %d\r\n", tc.getEncoderCurrent());
+    
     // Step 4: Include WiConnect Library
     // Step 5: Interpret commands sent over TCP
     
     
     // Configure sanity LED to blink
     while(1) {
-        //my_led = !my_led;
+        my_led = !my_led;
         wait(0.5);
     }
 }
-
-void calibrate()
-{
-    // Step 1:  Set status to uncalibrated
-    calib_state = UNCALIBRATED;
-    // Step 2:  Get the motor turning
-    ttDrive = 1;
-    calib_state = INITIALISING;
-    encoderMax = 0; // reset the maximum encoder value
-    
-    // Step 2:  Continue turning until calibration state is "CALIBRATED"
-    //          the actual calibration will be handled by interrupts
-    
-    while (calib_state != CALIBRATED)
-    {
-        // run time reaches here....my_led = 1;
-        my_led = limitFlag;
-        if(limitFlag == 1)
-        {
-            my_led = 1;
-            // run time does not reach here
-            // Step 2: Process the calibration state
-            limitFlag = 0;
-            switch(calib_state)
-            {
-                case (UNCALIBRATED):
-                    calib_state = INITIALISING;
-                    break;
-                case (INITIALISING):
-                    calib_state = CALIBRATING;
-                    break;
-                case (CALIBRATING):
-                    calib_state = CALIBRATED;
-                    break;
-                case (CALIBRATED):
-                    break;
-                default:
-                    calib_state = UNCALIBRATED;
-            }
-        }
-    }
-}
-
-void incrementEncoder()
-{
-    // Step 1: De-refference pointer and increment the value
-    if (calib_state == CALIBRATING)
-        ++encoderMax;
-    else
-        ++encoderCurrent;
-}
-
-void resetEncoder()
-{
-    // code reaches here...my_led = 1;
-    // Step 1: Set encoderCurrent value to zero
-    encoderCurrent = 0;
-    
-    // Show that the limit switch has been pressed
-    limitFlag = 1;
-    my_led = limitFlag;
-}
\ No newline at end of file