Carbon Fibre / Mbed 2 deprecated Motor_test_harness

Dependencies:   Classic_PID iC_MU mbed-rtos mbed

ServiceKeyboard.cpp

Committer:
ms523
Date:
2015-05-18
Revision:
1:1ad84260ff59
Parent:
0:7ce0bc67f60f
Child:
2:dc684c402296

File content as of revision 1:1ad84260ff59:

#include "mbed.h"
#include "iC_MU.h"
#include "rtos.h"
#include "Classic_PID.h"

extern Serial pc;
extern Classic_PID PanVelocityPID;
extern Classic_PID TiltVelocityPID;

extern bool joystick;

// Returns the new set point entered via the keyboard
int ServiceKeyboard ()
{
    int key;                                            // The keypress by the user
    int value = 0;                                      // The variable to return

    key = pc.getc();                                    // Read the intial keypress

    if (key == 'j') {
        joystick = !joystick;
        if(joystick) {
            pc.printf("\n\r Under Joystick Control");
        } else {
            // Stop both axes
            PanVelocityPID.setSetPoint(0);
            TiltVelocityPID.setSetPoint(0);
            pc.printf("\n\r Under PC Control");
        }
    } 
    // Set Velocity for Pan and Tilt here...
    else if(key == 'p') {
        // We are going to set the speed of pan...
        pc.printf("\n\r New Pan Vel: ");
        key = pc.getc();
        if (key == 0x1B) {
            if(pc.getc() == 0x4F) {
                if(pc.getc() == 0x53) {
                    pc.printf("-");
                    do {
                        key = pc.getc();                            // Wait for a keypress
                        if(key >= '0' && key <= '9') {              // Check it is a number
                            value *= 10;                            // Index the old number
                            value += (key - '0');                   // Add on the new number
                            pc.printf("%c",key);                    // Display the new number
                        }
                    } while(key != 0x0D);
                    PanVelocityPID.setSetPoint(value * -1);
                }
            }
        } else if(key >= '0' && key <= '9') {                      // Check it is a number
            pc.printf("%c",key);
            value = (key - '0');
            do {
                key = pc.getc();                            // Wait for a keypress
                if(key >= '0' && key <= '9') {              // Check it is a number
                    value *= 10;                            // Index the old number
                    value += (key - '0');                   // Add on the new number
                    pc.printf("%c",key);                    // Display the new number
                }
            } while(key != 0x0D);
            PanVelocityPID.setSetPoint(value);
        }
    } else if(key == 't') {
        // We are going to set the speed of tilt...
        pc.printf("\n\r New Tilt Vel: ");
        key = pc.getc();
        if (key == 0x1B) {
            if(pc.getc() == 0x4F) {
                if(pc.getc() == 0x53) {
                    pc.printf("-");
                    do {
                        key = pc.getc();                            // Wait for a keypress
                        if(key >= '0' && key <= '9') {              // Check it is a number
                            value *= 10;                            // Index the old number
                            value += (key - '0');                   // Add on the new number
                            pc.printf("%c",key);                    // Display the new number
                        }
                    } while(key != 0x0D);
                    TiltVelocityPID.setSetPoint(value * -1);
                }
            }
        } else if(key >= '0' && key <= '9') {                      // Check it is a number
            pc.printf("%c",key);
            value = (key - '0');
            do {
                key = pc.getc();                            // Wait for a keypress
                if(key >= '0' && key <= '9') {              // Check it is a number
                    value *= 10;                            // Index the old number
                    value += (key - '0');                   // Add on the new number
                    pc.printf("%c",key);                    // Display the new number
                }
            } while(key != 0x0D);
            TiltVelocityPID.setSetPoint(value);
        }
    }
    return(1);
}