Component Test's Software to work with "Universal Controller Box" - Software is an interpreter or "compiler" for programs to be done with a .txt file and read off of the SD Card
Dependencies: BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed
Revision 4:86d0d04cc055, committed 2014-09-19
- Comitter:
- mehatfie
- Date:
- Fri Sep 19 01:54:00 2014 +0000
- Parent:
- 3:078e9a1e8be3
- Child:
- 5:e36e0538a903
- Commit message:
- - fixed bug where "deviceFound" was not matching correct value; "if (lineData.word[2].compare(DeviceNames[i]) == 0)"... forgot the "== 0"; ; - Added Device PinIN, works as expected for current "wait" function
Changed in this revision
--- a/Device.cpp Fri Sep 19 00:46:26 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-//#include "Device.hpp"
-//#include "Motor.hpp"
-//#include "VoltageDriver.hpp"
-//
-//Device* Device::newDevice(int deviceFound){
-//
-// if(MOTOR)
-// return new Motor();
-// else if(VOLTAGE_DRIVER)
-// return new VoltageDriver();
-//
-//}
-//
-//
-//
\ No newline at end of file
--- a/Device.hpp Fri Sep 19 00:46:26 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-//#ifndef DEVICE_HPP
-//#define DEVICE_HPP
-//
-//#include "Initialization.hpp"
-//#include "mbed.h"
-//#include "LocalPinNames.h"
-//#include "BridgeDriver.h"
-////#include "DeviceClasses.hpp"
-////#include "Motor.hpp"
-////#include "VoltageDriver.hpp"
-//
-//enum DeviceType{MOTOR, VOLTAGE_DRIVER};
-//static const enum DeviceType Device_Map[] = {MOTOR, VOLTAGE_DRIVER};
-//const char *DeviceNames[] = {"MOTOR", "VOLTAGE_DRIVER"};
-//extern int numDevices = sizeof(DeviceNames)/sizeof(DeviceNames[0]);
-//extern int currNumDevices = 0;
-//
-//
-//class Device{
-//
-// public:
-// char name[100];
-// static Device* newDevice(int);
-// int interpret();
-//};
-//
-//extern Device devices[15]; //Initialize array of devices, initially assume 15 devices will be used (will expand as needed)
-//
-//void addDevice(int deviceFound){
-//
-// //devices[currNumDevices] = Device::newDevice(deviceFound);
-// currNumDevices++;
-//}
-//
-//
-//
-//
-///*
-//struct DeviceData {
-// DeviceType type;
-// string name;
-// union {
-// Voltage_Driver VOLTAGE_DRIVER;
-// Motor MOTOR;
-// };
-//};
-//
-//extern struct DeviceData devices[15]; //Initialize array of devices, initially assume 15 devices will be used (will expand as needed)
-//
-//void relayLine(DeviceData device){
-// switch(device.type){
-// case MOTOR: device.MOTOR.interpret(); break;
-// case VOLTAGE_DRIVER: device.VOLTAGE_DRIVER.interpret(); break;
-// }
-//}
-//
-//void addDevice(int deviceFound){
-//
-// //Save the device type
-// switch (Device_Map[deviceFound]){
-// case MOTOR: devices[currNumDevices].type = MOTOR; break;
-// case VOLTAGE_DRIVER: devices[currNumDevices].type = VOLTAGE_DRIVER; break;
-// }
-//
-// devices[currNumDevices].name = lineData.word[1]; //Save the Local Name of the Device, the second word in a device adding line is the Local_Name
-// relayLine(devices[currNumDevices]); //Give the command to the appropraite class in order to initialize itself based on the line
-// currNumDevices++; //Increment the total number of devices created
-//}*/
-//
-//
-//
-//#endif
-//
--- a/DeviceClasses.hpp Fri Sep 19 00:46:26 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,406 +0,0 @@
-///*#include "mbed.h"
-//#include "LocalPinNames.h"
-//#include "TextLCD.h"
-//#include "BridgeDriver.h"
-//*/
-//#include "Device.hpp"
-////#include <string>
-//
-///**********************************************************************************************************************************/
-///**********************************************************************************************************************************/
-///*************************** <CLASS: Voltage_Driver> ****************************/
-///**********************************************************************************************************************************/
-///**********************************************************************************************************************************/
-//
-//class Voltage_Driver{
-//
-// public :
-// //uint8_t ch123; //Channel value this device is set to
-// int ch;
-// int test;
-//
-// int interpret();
-// int forceBrake();
-// //int forceFloat();
-// float drive();
-//
-// //Voltage_Driver();
-// void setChannel(int channel){
-// Voltage_Driver::ch = channel;
-// }
-//
-// int getChannel(){
-// return Voltage_Driver::ch;
-// }
-//};
-//
-////Voltage_Driver::Voltage_Driver(void){
-////}
-//
-////A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on]
-//int Voltage_Driver::interpret(){
-// /*
-// lcd.cls(); //clear the display
-// lcd.setAddress(0,3);
-// lcd.printf("Test2 ");
-// lcd.setAddress(0,1);
-// lcd.printf("wrd1: %s", lineData.word[0]);
-// lcd.setAddress(0,2);
-// lcd.printf("wrd2: %s", lineData.word[1]);
-// wait(3);
-//*/
-//
-//
-// string firstWord = lineData.word[0]; //get the first word in the line
-///*
-// lcd.setAddress(0,2);
-// lcd.printf("fW: %s", firstWord);
-// lcd.setAddress(0,3);
-// lcd.printf("ch: %d", ch);
-// wait(3);*/
-//
-// //Initialize the class and device
-// if (firstWord.compare("device") == 0){
-// //Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8)
-//
-// test = 10;
-//
-// if (lineData.numWords != 4){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-//
-// string channel = lineData.word[3]; //Parameter is a number
-// int channelValue = 0;
-// sscanf(channel.c_str(), "%d", &channelValue);
-//
-// //Channel Value between 1 to 8
-// if (channelValue >= 1 && channelValue <= 8){
-//
-// setChannel(channelValue);
-// //ch = channelValue;
-//
-// lcd.setAddress(0,2);
-// lcd.printf("fW: %s", firstWord);
-// //lcd.setAddress(0,3);
-// //lcd.printf("ch: %d", getChannel());
-// lcd.setAddress(0,3);
-// lcd.printf("test: %d", test);
-// //lcd.setAddress(0,3);
-// //lcd.printf("chString: %s", chString);
-// wait(2);
-//
-// switch (channelValue){
-// case 1:
-// case 2:
-// bridges.enablePwm(BridgeDriver::MOTOR_A, 0);
-// break;
-// case 3:
-// case 4:
-// bridges.enablePwm(BridgeDriver::MOTOR_B, 0);
-// break;
-// case 5:
-// case 6:
-// bridges.enablePwm(BridgeDriver::MOTOR_C, 0);
-// break;
-// case 7:
-// case 8:
-// bridges.enablePwm(BridgeDriver::MOTOR_D, 0);
-// break;
-// }
-// /* lcd.setAddress(0,2);
-// lcd.printf("AchannelVal: %d", channelValue);
-// lcd.setAddress(0,3);
-// lcd.printf("Ach: %d", ch);
-// wait(3);*/
-//
-// }
-// else{
-// //ERROR Out
-// //Unacceptable channel, or conversion function failed when converting string to int
-// }
-// }
-//
-// //if the first word is not "device" it means that it's trying to perform a function to a specific Motor
-// else{
-//
-//
-//
-// //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,.......
-// string localname = lineData.word[0]; //just for the sake of following the variable easily and understanding
-// string func = lineData.word[1];
-//
-// /******************************************************************************/
-// /*** <Func: forceBrake> ***/
-// /******************************************************************************/
-// if (func.compare("forceBrake") == 0){
-//
-// if (lineData.numWords != 3){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-//
-// bridges.forceBrake(ch);
-// }
-//
-//
-// /******************************************************************************/
-// /*** <Func: drive> ***/
-// /******************************************************************************/
-// else if (func.compare("drive") == 0){
-// //Order of Line: Local_Name, drive
-//
-// lcd.setAddress(0,0);
-// lcd.printf("lclN: %s ", localname);
-// lcd.setAddress(0,2);
-// lcd.printf("func: %s ", func);
-// //lcd.setAddress(0,3);
-// //lcd.printf("3ch: %d ", getChannel());
-// lcd.setAddress(0,3);
-// lcd.printf("test: %d", test);
-// //lcd.setAddress(0,3);
-// //lcd.printf("chString: %s ", chString);
-// wait(3);
-//
-// if (lineData.numWords != 2){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-// /*
-// int State = 2;
-// int channelValue = atoi(chString);
-// State = bridges.drive(channelValue, 1); //Turn channel on
-// lcd.setAddress(0,2);
-// lcd.printf("TEST ch: %d, State: %d", channelValue, State);
-// wait(3);*/
-//
-// }
-//
-//
-// /******************************************************************************/
-// /**** <Func: off> ****/
-// /******************************************************************************/
-// else if (func.compare("drive") == 0){
-// //Order of Line: Local_Name, drive, duration
-//
-// if (lineData.numWords != 2){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-//
-// bridges.drive(getChannel(), 0); //Turn channel off
-// }
-//
-// else {
-// return 0;
-//
-// }
-// }
-// /*
-// lcd.setAddress(0,3);
-// lcd.printf("ENDch: %d ", getChannel());
-// wait(3);*/
-//
-// return 1;
-//}
-//
-//
-//
-///**********************************************************************************************************************************/
-///**********************************************************************************************************************************/
-///******************************** <CLASS: Motor> ********************************/
-///**********************************************************************************************************************************/
-///**********************************************************************************************************************************/
-//
-//class Motor{
-//
-// enum BridgeDriver::Motors motor;
-//
-// public :
-// int interpret();
-// void enableBrake();
-// int forceBrake();
-// //int forceFloat();
-// float drive();
-//
-//
-// void setMotor(BridgeDriver::Motors selectedMotor){
-// motor = selectedMotor;
-// }
-//
-// enum BridgeDriver::Motors getMotor(){
-// return motor;
-// }
-//
-//};
-//
-////A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on]
-//int Motor::interpret(){
-// /*
-// lcd.cls(); //clear the display
-// lcd.setAddress(0,3);
-// lcd.printf("Test2 ");
-// lcd.setAddress(0,1);
-// lcd.printf("wrd1: %s", lineData.word[0]);
-// lcd.setAddress(0,2);
-// lcd.printf("wrd2: %s", lineData.word[1]);
-// wait(3);
-//*/
-// /*
-// lcd.setAddress(0,2);
-// lcd.printf("wrd1: %s", lineData.word[0]);
-// lcd.setAddress(0,3);
-// lcd.printf("TEST1 ");
-// wait(1);*/
-//
-// string firstWord = lineData.word[0]; //splits the str based on a space delimeter
-//
-// if (firstWord.compare("device") == 0){
-// //Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8)
-//
-// if (lineData.numWords != 4){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-//
-// string channel = lineData.word[3]; //Parameter is a single character, so dereference the point to the word
-//
-// if ((channel.compare("A") == 0) || (channel.compare("a") == 0))
-// setMotor(BridgeDriver::MOTOR_A);
-// else if ((channel.compare("B") == 0) || (channel.compare("b") == 0))
-// setMotor(BridgeDriver::MOTOR_B);
-// else if ((channel.compare("C") == 0) || (channel.compare("c") == 0))
-// setMotor(BridgeDriver::MOTOR_C);
-// else if ((channel.compare("D") == 0) || (channel.compare("d") == 0))
-// setMotor(BridgeDriver::MOTOR_D);
-// }
-//
-// //if the first word is not "device" it means that it's trying to perform a function to a specific Motor
-// else{
-// //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,.......
-// //char localname[15] = lineData.word[0]; //just for the sake of following the variable easily and understanding
-// string func = lineData.word[1];
-//
-// /******************************************************************************/
-// /*** <Func: enableBrake> ***/
-// /******************************************************************************/
-// if (func.compare("enableBrake") == 0){
-//
-// if (lineData.numWords != 4){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-//
-// //Initialize and Convert Parameters
-// string enable = lineData.word[2];
-// int enableValue = 0;
-// sscanf(enable.c_str(), "%d", &enableValue);
-//
-// bridges.enableBraking(getMotor(), enableValue);
-// }
-//
-// /******************************************************************************/
-// /*** <Func: forceBrake> ***/
-// /******************************************************************************/
-// else if (func.compare("forceBrake") == 0){
-//
-// if (lineData.numWords != 3){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-//
-// bridges.forceBrake(getMotor());
-// }
-//
-//
-// /******************************************************************************/
-// /*** <Func: drive> ***/
-// /******************************************************************************/
-// else if (func.compare("drive") == 0){
-//
-// /*lcd.setAddress(0,2);
-// lcd.printf("wrd2: %s", lineData.word[1]);
-// lcd.setAddress(0,3);
-// lcd.printf("TEST2 ");
-// wait(1);*/
-//
-// if (lineData.numWords != 4){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-//
-// //Initialize Parameters
-// string speed = lineData.word[2];
-// string dir = lineData.word[3];
-//
-// //Initialize Convertion Variables if needed
-// float speedValue;
-// int dirValue = 0;
-//
-// //Convert string to usable values
-// //NOTE both atof and atoi functions return 0 if no valid conversion could be performed
-// sscanf(speed.c_str(), "%f", &speedValue);
-// speedValue = speedValue / 100;
-//
-// if (speedValue <= 0)
-// return 0; //Error Out because a value gives no functionality or is wrong
-//
-// if (dir.compare("CC") == 0 || dir.compare("cc") == 0)
-// dirValue = -1; //Turn Clockwise
-// else if (dir.compare("C") == 0 || dir.compare("c") == 0)
-// dirValue = 1; //Turn CounterClockwise
-// else
-// return 0; //Error Out since the parameter is incorrect
-//
-// bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
-//
-// }
-// /******************************************************************************/
-// /**** <Func: off> ****/
-// /******************************************************************************/
-// else if (func.compare("off") == 0){
-//
-// /*lcd.setAddress(0,2);
-// lcd.printf("wrd2: %s", lineData.word[1]);
-// lcd.setAddress(0,3);
-// lcd.printf("TEST2 ");
-// wait(1);*/
-//
-// if (lineData.numWords != 2){
-// //Error Check, incorrect number of parameter, error out
-// return 0;
-// }
-//
-// bridges.drive(getMotor(), 0, 0); //Turn off the Motor
-// }
-//
-// else {
-// return 0;
-//
-// }
-// }
-//
-// return 1;
-//}
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
-//
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Devices/Motor.cpp Fri Sep 19 01:54:00 2014 +0000
@@ -0,0 +1,224 @@
+#include "Motor.hpp"
+//#include "mbed.h"
+//#include "LocalPinNames.h"
+//#include "BridgeDriver.h"
+
+//Constructor
+Motor::Motor(Line lineData){
+ /*
+ //Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8)
+ if (lineData.numWords != 4){
+ //Error Check, incorrect number of parameter, error out
+ //return 0;
+ }*/
+
+ /*lcd.setAddress(0,3);
+ lcd.printf("CHECK Motor Construct");
+ wait(2);*/
+
+ string channel = lineData.word[3]; //Parameter is a single character, so dereference the point to the word
+
+ if ((channel.compare("A") == 0) || (channel.compare("a") == 0))
+ this->motor = BridgeDriver::MOTOR_A;
+ else if ((channel.compare("B") == 0) || (channel.compare("b") == 0))
+ this->motor = BridgeDriver::MOTOR_B;
+ else if ((channel.compare("C") == 0) || (channel.compare("c") == 0))
+ this->motor = BridgeDriver::MOTOR_C;
+ else if ((channel.compare("D") == 0) || (channel.compare("d") == 0))
+ this->motor = BridgeDriver::MOTOR_D;
+}
+
+
+enum BridgeDriver::Motors Motor::getMotor(){
+ return this->motor;
+}
+
+//A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on]
+int Motor::interpret(Line &lineData){
+ /*
+ lcd.setAddress(0,2);
+ lcd.printf("CHECK Motor 123456");
+ lcd.setAddress(0,3);
+ lcd.printf("func: %s ", lineData.word[1]);
+ wait(2);*/
+
+ //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,.......
+ //char localname[15] = lineData.word[0]; //just for the sake of following the variable easily and understanding
+ string func = lineData.word[1];
+
+ /******************************************************************************/
+ /*** <Func: enableBrake> ***/
+ /******************************************************************************/
+ if (func.compare("enableBrake") == 0){
+
+ if (lineData.numWords != 4){
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ //Initialize and Convert Parameters
+ string enable = lineData.word[2];
+ int enableValue = 0;
+ sscanf(enable.c_str(), "%d", &enableValue);
+
+ bridges.enableBraking(getMotor(), enableValue);
+ }
+
+ /******************************************************************************/
+ /*** <Func: forceBrake> ***/
+ /******************************************************************************/
+ else if (func.compare("forceBrake") == 0){
+
+ if (lineData.numWords != 3){
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ bridges.forceBrake(getMotor());
+ }
+
+
+ /******************************************************************************/
+ /*** <Func: drive> ***/
+ /******************************************************************************/
+ else if (func.compare("drive") == 0){
+
+ /*lcd.setAddress(0,2);
+ lcd.printf("wrd2: %s", lineData.word[1]);
+ lcd.setAddress(0,3);
+ lcd.printf("TEST2 ");
+ wait(2);*/
+
+ if (lineData.numWords != 4){
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ //Initialize Parameters
+ string speed = lineData.word[2];
+ string dir = lineData.word[3];
+
+ //Initialize Convertion Variables if needed
+ float speedValue;
+ int dirValue = 0;
+
+ //Convert string to usable values
+ //NOTE both atof and atoi functions return 0 if no valid conversion could be performed
+ sscanf(speed.c_str(), "%f", &speedValue);
+ speedValue = speedValue / 100;
+
+ if (speedValue <= 0)
+ return 0; //Error Out because a value gives no functionality or is wrong
+
+ if (dir.compare("CC") == 0 || dir.compare("cc") == 0)
+ dirValue = -1; //Turn Clockwise
+ else if (dir.compare("C") == 0 || dir.compare("c") == 0)
+ dirValue = 1; //Turn CounterClockwise
+ else
+ return 0; //Error Out since the parameter is incorrect
+
+
+ bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
+
+ }
+ /******************************************************************************/
+ /**** <Func: off> ****/
+ /******************************************************************************/
+ else if (func.compare("off") == 0){
+
+ /*lcd.setAddress(0,2);
+ lcd.printf("wrd2: %s", lineData.word[1]);
+ lcd.setAddress(0,3);
+ lcd.printf("TEST2 ");
+ wait(1);*/
+
+ if (lineData.numWords != 2){
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ bridges.drive(getMotor(), 0, 0); //Turn off the Motor
+ }
+
+ else {
+ return 0;
+
+ }
+
+ return 1;
+}
+
+
+
+
+
+
+
+/*
+int Motor::enableBrake(){
+
+ if (lineData.numWords != 4){
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ //Initialize and Convert Parameters
+ char *enable = lineData.word[2];
+ int enableValue = atoi(enable);
+
+ //If the atoi returned anything besides 0, it worked properly
+ if (enableValue)
+ bridges.enableBraking(getMotor(), enableValue);
+ else{
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ return 1;
+}
+
+int Motor::forceBrake(){
+
+ if (lineData.numWords != 3){
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ bridges.forceBrake(getMotor());
+}
+
+int Motor::drive(){
+
+ if (lineData.numWords != 4){
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ //Initialize Parameters
+ char *speed = lineData.word[2];
+ char *dir = lineData.word[3];
+
+ //Initialize Convertion Variables if needed
+ float speedValue;
+ int dirValue = 0;
+
+ //Convert string to usable values
+ //NOTE both atof and atoi functions return 0 if no valid conversion could be performed
+ speedValue = atof(speed) / 100;
+
+ if (speedValue <= 0)
+ return 0; //Error Out because a value gives no functionality or is wrong
+
+ if (strncmp(dir,"CC", 2) == 0 || strncmp(dir,"cc", 2) == 0)
+ dirValue = -1; //Turn Clockwise
+ else if (strncmp(dir,"C", 1) == 0 || strncmp(dir,"c", 1) == 0)
+ dirValue = 1; //Turn CounterClockwise
+ else
+ return 0; //Error Out since the parameter is incorrect
+
+ bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
+}
+*/
+
+
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Devices/Motor.hpp Fri Sep 19 01:54:00 2014 +0000
@@ -0,0 +1,21 @@
+#ifndef MOTOR_HPP
+#define MOTOR_HPP
+
+#include "Initialization.hpp"
+
+class Motor: public Device{
+
+ private:
+ enum BridgeDriver::Motors motor;
+
+ public:
+ Motor(Line);
+ int interpret(Line&);
+ enum BridgeDriver::Motors getMotor();
+ //void enableBrake();
+ //int forceBrake();
+ //int forceFloat();
+ //float drive();
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Devices/PinIN.cpp Fri Sep 19 01:54:00 2014 +0000
@@ -0,0 +1,121 @@
+#include "PinIN.hpp"
+//#include "mbed.h"
+//#include "LocalPinNames.h"
+//#include "BridgeDriver.h"
+
+//Constructor
+PinIN::PinIN(Line lineData){
+
+ string _pinName = lineData.word[3];
+
+ if(_pinName.compare("DIO0") == 0)
+ this->pinName = DIO0;
+ else if(_pinName.compare("DIO1") == 0)
+ this->pinName = DIO1;
+ else if(_pinName.compare("DIO2") == 0)
+ this->pinName = DIO2;
+ else if(_pinName.compare("DIO3") == 0)
+ this->pinName = DIO3;
+ else if(_pinName.compare("DIO4") == 0)
+ this->pinName = DIO4;
+ else if(_pinName.compare("DIO5") == 0)
+ this->pinName = DIO5;
+ else if(_pinName.compare("DIO6") == 0)
+ this->pinName = DIO6;
+ else if(_pinName.compare("DIO7") == 0)
+ this->pinName = DIO7;
+ else if(_pinName.compare("DIO8") == 0)
+ this->pinName = DIO8;
+ else if(_pinName.compare("DIO9") == 0)
+ this->pinName = DIO9;
+ else if(_pinName.compare("DIO10") == 0)
+ this->pinName = DIO10;
+ else if(_pinName.compare("DIO11") == 0)
+ this->pinName = DIO11;
+
+ else if(_pinName.compare("AI0") == 0)
+ this->pinName = AI0;
+ else if(_pinName.compare("AI1") == 0)
+ this->pinName = AI1;
+ else if(_pinName.compare("AI2") == 0)
+ this->pinName = AI2;
+ else if(_pinName.compare("AI3") == 0)
+ this->pinName = AI3;
+ else if(_pinName.compare("AI4") == 0)
+ this->pinName = AI4;
+ else if(_pinName.compare("AI5") == 0)
+ this->pinName = AI5;
+
+}
+/*
+ #define DIO0 P2_2
+#define DIO1 P2_3
+#define DIO2 P2_4
+#define DIO3 P2_5
+#define DIO4 P2_6
+#define DIO5 P2_7
+#define DIO6 P2_8
+#define DIO7 P2_9
+#define DIO8 P1_1
+#define DIO9 P1_4
+#define DIO10 P1_8
+#define DIO11 P1_9
+#define SS1 P0_19
+#define SS2 P0_20
+#define SS3 P0_21
+#define SS4 P0_22
+#define SS_ADC P1_0
+#define AI0 P0_23
+#define AI1 P0_24
+#define AI2 P0_25
+#define AI3 P0_26
+#define AI4 P1_30
+#define AI5 P1_31
+#define KILL P2_11
+#define CAN1_RX P0_0
+#define CAN1_TX P0_1
+#define CAN2_RX P0_4
+#define CAN2_TX P0_5
+ */
+
+
+//A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on]
+int PinIN::interpret(Line &lineData){
+ /*
+ lcd.setAddress(0,2);
+ lcd.printf("CHECK Motor 123456");
+ lcd.setAddress(0,3);
+ lcd.printf("func: %s ", lineData.word[1]);
+ wait(2);*/
+
+ DigitalIn signal(pinName);
+
+ //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,.......
+ string func = lineData.word[1];
+
+ /******************************************************************************/
+ /*** <Func: wait> ***/
+ /******************************************************************************/
+ if (func.compare("wait") == 0){
+
+ if (lineData.numWords != 3){
+ //Error Check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ //Initialize and Convert Parameters
+ string pinValue = lineData.word[2];
+ int pinValue_Value = 0;
+ sscanf(pinValue.c_str(), "%d", &pinValue_Value);
+
+ while(signal.read() != pinValue_Value);
+ }
+
+ else {
+ return 0;
+
+ }
+
+ return 1;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Devices/PinIN.hpp Fri Sep 19 01:54:00 2014 +0000
@@ -0,0 +1,16 @@
+#ifndef PININ_HPP
+#define PININ_HPP
+
+#include "Initialization.hpp"
+
+class PinIN: public Device{
+
+ private:
+ PinName pinName;
+
+ public:
+ PinIN(Line);
+ int interpret(Line&);
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Devices/VoltageDriver.cpp Fri Sep 19 01:54:00 2014 +0000
@@ -0,0 +1,114 @@
+#include "VoltageDriver.hpp"
+//#include "mbed.h"
+//#include "LocalPinNames.h"
+//#include "BridgeDriver.h"
+
+//Constructor
+VoltageDriver::VoltageDriver(Line lineData){
+
+ //Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8)
+ if (lineData.numWords != 4){
+ //Error Check, incorrect number of parameter, error out
+ //return 0;
+ }
+
+ string channelstr = lineData.word[3]; //Parameter is a number
+ //int channelValue = 0;
+ sscanf(channelstr.c_str(), "%d", &channel);
+
+ //Channel Value between 1 to 8
+ if (channel >= 1 && channel <= 8){
+
+ switch (channel){
+ case 1:
+ case 2:
+ bridges.enablePwm(BridgeDriver::MOTOR_A, 0);
+ break;
+ case 3:
+ case 4:
+ bridges.enablePwm(BridgeDriver::MOTOR_B, 0);
+ break;
+ case 5:
+ case 6:
+ bridges.enablePwm(BridgeDriver::MOTOR_C, 0);
+ break;
+ case 7:
+ case 8:
+ bridges.enablePwm(BridgeDriver::MOTOR_D, 0);
+ break;
+ }
+ }
+ else{
+ //ERROR Out
+ //Unacceptable channel, or conversion function failed when converting string to int
+ }
+}
+
+
+int VoltageDriver::getChannel(){
+ return this->channel;
+}
+
+
+//A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on]
+int VoltageDriver::interpret(Line &lineData){
+
+ //order of line: local_name, function_name, param1, param2, param3,.......
+ //string localname = linedata.word[0]; //just for the sake of following the variable easily and understanding
+ string func = lineData.word[1];
+
+ /******************************************************************************/
+ /*** <func: forcebrake> ***/
+ /******************************************************************************/
+ if (func.compare("forcebrake") == 0){
+
+ if (lineData.numWords != 3){
+ //error check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ bridges.forceBrake(channel);
+ }
+
+
+ /******************************************************************************/
+ /*** <func: drive> ***/
+ /******************************************************************************/
+ else if (func.compare("drive") == 0){
+ //order of line: local_name, drive
+
+ if (lineData.numWords != 2){
+ //error check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ //int state = 2;
+ bridges.drive(channel, 1); //turn channel on
+ /*lcd.setaddress(0,2);
+ lcd.printf("test ch: %d, state: %d", channelvalue, state);
+ wait(3);*/
+
+ }
+
+
+ /******************************************************************************/
+ /**** <func: off> ****/
+ /******************************************************************************/
+ else if (func.compare("off") == 0){
+ //order of line: local_name, drive, duration
+
+ if (lineData.numWords != 2){
+ //error check, incorrect number of parameter, error out
+ return 0;
+ }
+
+ bridges.drive(getChannel(), 0); //turn channel off
+ }
+
+ else {
+ return 0;
+
+ }
+
+ return 1;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Devices/VoltageDriver.hpp Fri Sep 19 01:54:00 2014 +0000
@@ -0,0 +1,21 @@
+#ifndef VOLTAGEDRIVER_HPP
+#define VOLTAGEDRIVER_HPP
+
+#include "Initialization.hpp"
+
+class VoltageDriver: public Device{
+
+ private:
+ int channel;
+
+ public:
+ VoltageDriver(Line);
+ int interpret(Line&);
+ int getChannel();
+ //void enableBrake();
+ //int forceBrake();
+ //int forceFloat();
+ //float drive();
+};
+
+#endif
\ No newline at end of file
--- a/Initialization.cpp Fri Sep 19 00:46:26 2014 +0000
+++ b/Initialization.cpp Fri Sep 19 01:54:00 2014 +0000
@@ -1,7 +1,7 @@
#include "Initialization.hpp"
#include "Motor.hpp"
#include "VoltageDriver.hpp"
-
+#include "PinIN.hpp"
/**********************************************************************************************************************************/
@@ -12,7 +12,7 @@
// ADD YOUR DEVICE NAME THE \\EXACT SAME WAY\\ AS THE ENUM NAME YOU DECLARED IN THE.hpp
// Must Declare names in reverse order for some reason...., it's the way they're indexed I believe
-const string DeviceNames[] = {"VOLTAGE_DRIVER", "MOTOR"};
+const string DeviceNames[] = {"MOTOR", "VOLTAGE_DRIVER", "PIN_IN"};
// ADD YOUR DEVICE TO THE LIST BELOW, CALLING YOUR DEVICE CLASS AS SHOWN
Device* Device::newDevice(int deviceFound, string _name, Line lineData){
@@ -20,6 +20,7 @@
switch (Device_Map[deviceFound]){
case MOTOR: return new Motor(lineData); break;
case VOLTAGE_DRIVER: return new VoltageDriver(lineData); break;
+ case PIN_IN: return new PinIN(lineData); break;
//********** ADD NEXT DEVICE ABOVE **************//
default: break;
--- a/Initialization.hpp Fri Sep 19 00:46:26 2014 +0000
+++ b/Initialization.hpp Fri Sep 19 01:54:00 2014 +0000
@@ -17,8 +17,8 @@
/**********************************************************************************************************************************/
/**********************************************************************************************************************************/
-enum DeviceType{MOTOR, VOLTAGE_DRIVER}; //ADD DEVICE NAME
-static const enum DeviceType Device_Map[] = {MOTOR, VOLTAGE_DRIVER}; //AND HERE ***NOTE TO KEEP SAME ORDER
+enum DeviceType{MOTOR, VOLTAGE_DRIVER, PIN_IN}; //ADD DEVICE NAME
+static const enum DeviceType Device_Map[] = {MOTOR, VOLTAGE_DRIVER, PIN_IN}; //AND HERE ***NOTE TO KEEP SAME ORDER
/************************** <MUST MODIFY> *************************/
/**********************************************************************************************************************************/
--- a/Motor.cpp Fri Sep 19 00:46:26 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,224 +0,0 @@
-#include "Motor.hpp"
-//#include "mbed.h"
-//#include "LocalPinNames.h"
-//#include "BridgeDriver.h"
-
-//Constructor
-Motor::Motor(Line lineData){
- /*
- //Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8)
- if (lineData.numWords != 4){
- //Error Check, incorrect number of parameter, error out
- //return 0;
- }*/
-
- /*lcd.setAddress(0,3);
- lcd.printf("CHECK Motor Construct");
- wait(2);*/
-
- string channel = lineData.word[3]; //Parameter is a single character, so dereference the point to the word
-
- if ((channel.compare("A") == 0) || (channel.compare("a") == 0))
- this->motor = BridgeDriver::MOTOR_A;
- else if ((channel.compare("B") == 0) || (channel.compare("b") == 0))
- this->motor = BridgeDriver::MOTOR_B;
- else if ((channel.compare("C") == 0) || (channel.compare("c") == 0))
- this->motor = BridgeDriver::MOTOR_C;
- else if ((channel.compare("D") == 0) || (channel.compare("d") == 0))
- this->motor = BridgeDriver::MOTOR_D;
-}
-
-
-enum BridgeDriver::Motors Motor::getMotor(){
- return this->motor;
-}
-
-//A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on]
-int Motor::interpret(Line &lineData){
- /*
- lcd.setAddress(0,2);
- lcd.printf("CHECK Motor 123456");
- lcd.setAddress(0,3);
- lcd.printf("func: %s ", lineData.word[1]);
- wait(2);*/
-
- //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,.......
- //char localname[15] = lineData.word[0]; //just for the sake of following the variable easily and understanding
- string func = lineData.word[1];
-
- /******************************************************************************/
- /*** <Func: enableBrake> ***/
- /******************************************************************************/
- if (func.compare("enableBrake") == 0){
-
- if (lineData.numWords != 4){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- //Initialize and Convert Parameters
- string enable = lineData.word[2];
- int enableValue = 0;
- sscanf(enable.c_str(), "%d", &enableValue);
-
- bridges.enableBraking(getMotor(), enableValue);
- }
-
- /******************************************************************************/
- /*** <Func: forceBrake> ***/
- /******************************************************************************/
- else if (func.compare("forceBrake") == 0){
-
- if (lineData.numWords != 3){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- bridges.forceBrake(getMotor());
- }
-
-
- /******************************************************************************/
- /*** <Func: drive> ***/
- /******************************************************************************/
- else if (func.compare("drive") == 0){
-
- /*lcd.setAddress(0,2);
- lcd.printf("wrd2: %s", lineData.word[1]);
- lcd.setAddress(0,3);
- lcd.printf("TEST2 ");
- wait(2);*/
-
- if (lineData.numWords != 4){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- //Initialize Parameters
- string speed = lineData.word[2];
- string dir = lineData.word[3];
-
- //Initialize Convertion Variables if needed
- float speedValue;
- int dirValue = 0;
-
- //Convert string to usable values
- //NOTE both atof and atoi functions return 0 if no valid conversion could be performed
- sscanf(speed.c_str(), "%f", &speedValue);
- speedValue = speedValue / 100;
-
- if (speedValue <= 0)
- return 0; //Error Out because a value gives no functionality or is wrong
-
- if (dir.compare("CC") == 0 || dir.compare("cc") == 0)
- dirValue = -1; //Turn Clockwise
- else if (dir.compare("C") == 0 || dir.compare("c") == 0)
- dirValue = 1; //Turn CounterClockwise
- else
- return 0; //Error Out since the parameter is incorrect
-
-
- bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
-
- }
- /******************************************************************************/
- /**** <Func: off> ****/
- /******************************************************************************/
- else if (func.compare("off") == 0){
-
- /*lcd.setAddress(0,2);
- lcd.printf("wrd2: %s", lineData.word[1]);
- lcd.setAddress(0,3);
- lcd.printf("TEST2 ");
- wait(1);*/
-
- if (lineData.numWords != 2){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- bridges.drive(getMotor(), 0, 0); //Turn off the Motor
- }
-
- else {
- return 0;
-
- }
-
- return 1;
-}
-
-
-
-
-
-
-
-/*
-int Motor::enableBrake(){
-
- if (lineData.numWords != 4){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- //Initialize and Convert Parameters
- char *enable = lineData.word[2];
- int enableValue = atoi(enable);
-
- //If the atoi returned anything besides 0, it worked properly
- if (enableValue)
- bridges.enableBraking(getMotor(), enableValue);
- else{
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- return 1;
-}
-
-int Motor::forceBrake(){
-
- if (lineData.numWords != 3){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- bridges.forceBrake(getMotor());
-}
-
-int Motor::drive(){
-
- if (lineData.numWords != 4){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- //Initialize Parameters
- char *speed = lineData.word[2];
- char *dir = lineData.word[3];
-
- //Initialize Convertion Variables if needed
- float speedValue;
- int dirValue = 0;
-
- //Convert string to usable values
- //NOTE both atof and atoi functions return 0 if no valid conversion could be performed
- speedValue = atof(speed) / 100;
-
- if (speedValue <= 0)
- return 0; //Error Out because a value gives no functionality or is wrong
-
- if (strncmp(dir,"CC", 2) == 0 || strncmp(dir,"cc", 2) == 0)
- dirValue = -1; //Turn Clockwise
- else if (strncmp(dir,"C", 1) == 0 || strncmp(dir,"c", 1) == 0)
- dirValue = 1; //Turn CounterClockwise
- else
- return 0; //Error Out since the parameter is incorrect
-
- bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
-}
-*/
-
-
-
\ No newline at end of file
--- a/Motor.hpp Fri Sep 19 00:46:26 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef MOTOR_HPP
-#define MOTOR_HPP
-
-//#include "Device.hpp"
-#include "Initialization.hpp"
-
-class Motor: public Device{
-
- private:
- enum BridgeDriver::Motors motor;
-
- public:
- Motor(Line);
- int interpret(Line&);
- enum BridgeDriver::Motors getMotor();
- //void enableBrake();
- //int forceBrake();
- //int forceFloat();
- //float drive();
-};
-
-#endif
\ No newline at end of file
--- a/VoltageDriver.cpp Fri Sep 19 00:46:26 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-#include "VoltageDriver.hpp"
-//#include "mbed.h"
-//#include "LocalPinNames.h"
-//#include "BridgeDriver.h"
-
-//Constructor
-VoltageDriver::VoltageDriver(Line lineData){
-
- //Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8)
- if (lineData.numWords != 4){
- //Error Check, incorrect number of parameter, error out
- //return 0;
- }
-
- string channelstr = lineData.word[3]; //Parameter is a number
- //int channelValue = 0;
- sscanf(channelstr.c_str(), "%d", &channel);
-
- //Channel Value between 1 to 8
- if (channel >= 1 && channel <= 8){
-
- switch (channel){
- case 1:
- case 2:
- bridges.enablePwm(BridgeDriver::MOTOR_A, 0);
- break;
- case 3:
- case 4:
- bridges.enablePwm(BridgeDriver::MOTOR_B, 0);
- break;
- case 5:
- case 6:
- bridges.enablePwm(BridgeDriver::MOTOR_C, 0);
- break;
- case 7:
- case 8:
- bridges.enablePwm(BridgeDriver::MOTOR_D, 0);
- break;
- }
- }
- else{
- //ERROR Out
- //Unacceptable channel, or conversion function failed when converting string to int
- }
-}
-
-
-int VoltageDriver::getChannel(){
- return this->channel;
-}
-
-
-//A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on]
-int VoltageDriver::interpret(Line &lineData){
-
- //order of line: local_name, function_name, param1, param2, param3,.......
- //string localname = linedata.word[0]; //just for the sake of following the variable easily and understanding
- string func = lineData.word[1];
-
- /******************************************************************************/
- /*** <func: forcebrake> ***/
- /******************************************************************************/
- if (func.compare("forcebrake") == 0){
-
- if (lineData.numWords != 3){
- //error check, incorrect number of parameter, error out
- return 0;
- }
-
- bridges.forceBrake(channel);
- }
-
-
- /******************************************************************************/
- /*** <func: drive> ***/
- /******************************************************************************/
- else if (func.compare("drive") == 0){
- //order of line: local_name, drive
-
- if (lineData.numWords != 2){
- //error check, incorrect number of parameter, error out
- return 0;
- }
-
- //int state = 2;
- bridges.drive(channel, 1); //turn channel on
- /*lcd.setaddress(0,2);
- lcd.printf("test ch: %d, state: %d", channelvalue, state);
- wait(3);*/
-
- }
-
-
- /******************************************************************************/
- /**** <func: off> ****/
- /******************************************************************************/
- else if (func.compare("off") == 0){
- //order of line: local_name, drive, duration
-
- if (lineData.numWords != 2){
- //error check, incorrect number of parameter, error out
- return 0;
- }
-
- bridges.drive(getChannel(), 0); //turn channel off
- }
-
- else {
- return 0;
-
- }
-
- return 1;
-}
\ No newline at end of file
--- a/VoltageDriver.hpp Fri Sep 19 00:46:26 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-#ifndef VOLTAGEDRIVER_HPP
-#define VOLTAGEDRIVER_HPP
-
-//#include "Device.hpp"
-#include "Initialization.hpp"
-
-class VoltageDriver: public Device{
-
- private:
- int channel;
-
- public:
- VoltageDriver(Line);
- int interpret(Line&);
- int getChannel();
- //void enableBrake();
- //int forceBrake();
- //int forceFloat();
- //float drive();
-};
-
-#endif
\ No newline at end of file
--- a/main.cpp Fri Sep 19 00:46:26 2014 +0000
+++ b/main.cpp Fri Sep 19 01:54:00 2014 +0000
@@ -10,6 +10,7 @@
//#include "Device.hpp"
#include "Motor.hpp"
#include "VoltageDriver.hpp"
+#include "PinIN.hpp"
#include "TextFile.h"
#include <stdio.h>
#include <string>
@@ -86,25 +87,11 @@
lcd.printf(" "); // Clear the Line using Spaces (Emptyness) - Note one line is 20 Characters
wait(.2);
lcd.setAddress(0,3);
- lcd.printf("%s",files[nextIndex]);
+ lcd.printf("%s", files[nextIndex]);
return nextIndex; // Return the file index in the Array
}
-
-/**********************************************************************************************************************************/
-/**********************************************************************************************************************************/
-/************************** <FUNCTION: resize_StringArr> ************************/
-/**********************************************************************************************************************************/
-/**********************************************************************************************************************************/
-
-string* resize_StringArr(string oldArr[], int newSize) {
-
- string newArr[newSize];
- memcpy(newArr, oldArr, newSize * sizeof(string));
-
- return newArr;
-}
/**********************************************************************************************************************************/
@@ -161,8 +148,9 @@
int i = 0, deviceFound = -1;
for (i = 0; i < numDevices; i++){
- if (lineData.word[2].compare(DeviceNames[i]))
+ if (lineData.word[2].compare(DeviceNames[i]) == 0){
deviceFound = i;
+ }
}
//if the device type does not match any known type, error out