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

Files at this revision

API Documentation at this revision

Comitter:
mehatfie
Date:
Fri Sep 19 00:46:26 2014 +0000
Parent:
2:3e7baa3e3fec
Child:
4:86d0d04cc055
Commit message:
- Working properly for Motor, Voltage_Driver, and looping; - successful looping and program completion; - organizing for more readable and understandable code is starting

Changed in this revision

Initialization.cpp Show annotated file Show diff for this revision Revisions of this file
Initialization.hpp Show annotated file Show diff for this revision Revisions of this file
VoltageDriver.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Initialization.cpp	Thu Sep 18 23:38:11 2014 +0000
+++ b/Initialization.cpp	Fri Sep 19 00:46:26 2014 +0000
@@ -2,6 +2,40 @@
 #include "Motor.hpp"
 #include "VoltageDriver.hpp"
 
+
+
+/**********************************************************************************************************************************/
+/**********************************************************************************************************************************/
+/**************************                              <MUST MODIFY>                                    *************************/
+/**********************************************************************************************************************************/
+/**********************************************************************************************************************************/
+
+// 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"}; 
+
+// ADD YOUR DEVICE TO THE LIST BELOW, CALLING YOUR DEVICE CLASS AS SHOWN
+Device* Device::newDevice(int deviceFound, string _name, Line lineData){
+    
+    switch (Device_Map[deviceFound]){
+        case MOTOR:           return new Motor(lineData);          break;
+        case VOLTAGE_DRIVER:  return new VoltageDriver(lineData);  break;
+        
+        //**********  ADD NEXT DEVICE ABOVE  **************//
+        default:  break;
+    }
+}
+
+/**************************                              <MUST MODIFY>                                    *************************/
+/**********************************************************************************************************************************/
+/**********************************************************************************************************************************/
+
+
+
+/******************************************************************************/
+/***                       <Global Initializations>                         ***/
+/******************************************************************************/
+
 //Initializations
 Timer timer;    // general purpose timer
 I2C i2c( P0_10, P0_11 ); // I2C bus (SDA, SCL)
@@ -13,43 +47,10 @@
 
 const int MAX_LINE_LENGTH = 100;
 
-//struct Line lineData;
 
-Device* Device::newDevice(int deviceFound, string _name, Line lineData){
-
-    switch (Device_Map[deviceFound]){
-        case MOTOR:
-            //Device::setName(_name);
-            //Device::setType(MOTOR);
-            return new Motor(lineData); 
-        break;
-        case VOLTAGE_DRIVER:
-            //setName(_name);
-            //setType(MOTOR);
-            return new VoltageDriver(lineData); 
-        break;
-    }
-}
-/*
-void Device::setName(string _name){
-    this->name = _name;    
-}
-void Device::setType(DeviceType _type){
-    this->type = _type;
-}*/
-        
-const char *DeviceNames[] = {"MOTOR", "VOLTAGE_DRIVER"};
-int numDevices = sizeof(DeviceNames)/sizeof(DeviceNames[0]);
-int currNumDevices = 0;
-
-vector<Device*> devices;
-//Device devices[15];
-
-void addDevice(int deviceFound, Line &lineData){
-    
-    devices[currNumDevices] = Device::newDevice(deviceFound, lineData.word[1], lineData);
-    currNumDevices++;
-}
+/******************************************************************************/
+/***                     <Function Initializations>                         ***/
+/******************************************************************************/
 
 void fullInit() {
     
@@ -67,3 +68,12 @@
     lcd.printf("LCD Initialized");
 }
 
+
+/******************************************************************************/
+/***              <Parent Device Class Initializations>                     ***/
+/******************************************************************************/
+
+int numDevices = sizeof(DeviceNames)/sizeof(DeviceNames[0]);
+int currNumDevices = 0;
+
+vector<Device*> devices;
\ No newline at end of file
--- a/Initialization.hpp	Thu Sep 18 23:38:11 2014 +0000
+++ b/Initialization.hpp	Fri Sep 19 00:46:26 2014 +0000
@@ -10,6 +10,26 @@
 #include <string>
 #include <vector>
 
+
+/**********************************************************************************************************************************/
+/**********************************************************************************************************************************/
+/**************************                              <MUST MODIFY>                                    *************************/
+/**********************************************************************************************************************************/
+/**********************************************************************************************************************************/
+
+enum  DeviceType{MOTOR, VOLTAGE_DRIVER};                                //ADD DEVICE NAME
+static const enum DeviceType Device_Map[] = {MOTOR, VOLTAGE_DRIVER};    //AND HERE ***NOTE TO KEEP SAME ORDER
+
+/**************************                              <MUST MODIFY>                                    *************************/
+/**********************************************************************************************************************************/
+/**********************************************************************************************************************************/
+
+
+
+/******************************************************************************/
+/***                       <Global Initializations>                         ***/
+/******************************************************************************/
+
 //Initializations
 extern Timer timer;    // general purpose timer
 extern I2C i2c; // I2C bus (SDA, SCL)
@@ -21,10 +41,20 @@
 
 extern const int MAX_LINE_LENGTH;
 
-void fullInit();
+
+/******************************************************************************/
+/***                     <Function Initializations>                         ***/
+/******************************************************************************/
+
+void fullInit(); //Perform and call any needed initializations
  
-void initLCD(void);
+void initLCD(void); //Initialize the LCD
+
+
 
+/******************************************************************************/
+/***                 <Line Data Struct Initializations>                     ***/
+/******************************************************************************/
 
 struct Line{
     
@@ -42,10 +72,11 @@
 
 
 
+/******************************************************************************/
+/***              <Parent Device Class Initializations>                     ***/
+/******************************************************************************/
 
-enum  DeviceType{MOTOR, VOLTAGE_DRIVER}; 
-static const enum DeviceType Device_Map[] = {MOTOR, VOLTAGE_DRIVER}; 
-extern const char *DeviceNames[];
+extern const string DeviceNames[];
 extern int numDevices;
 extern int currNumDevices;
 
@@ -56,20 +87,10 @@
         string name;
         enum DeviceType type;
         static Device* newDevice(int, string, Line);
-        //void setName(string);
-        //void setType(DeviceType);
         virtual int interpret(Line&) = 0;
-        /*{
-            lcd.setAddress(0,3);
-            lcd.printf("CHECK Device   ");
-            wait(2);
-            return 0;
-        }*/
 };
 
 extern vector<Device*> devices; //Initialize array of devices, initially assume 15 devices will be used (will expand as needed)
-//extern Device devices[];
 
-void addDevice(int, Line);
 
 #endif
\ No newline at end of file
--- a/VoltageDriver.cpp	Thu Sep 18 23:38:11 2014 +0000
+++ b/VoltageDriver.cpp	Fri Sep 19 00:46:26 2014 +0000
@@ -53,7 +53,6 @@
 //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];
@@ -77,18 +76,6 @@
     /******************************************************************************/
     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
@@ -107,7 +94,7 @@
     /******************************************************************************/
     /****                           <func: off>                                ****/
     /******************************************************************************/
-    else if (func.compare("drive") == 0){
+    else if (func.compare("off") == 0){
         //order of line: local_name, drive, duration
         
         if (lineData.numWords != 2){
--- a/main.cpp	Thu Sep 18 23:38:11 2014 +0000
+++ b/main.cpp	Fri Sep 19 00:46:26 2014 +0000
@@ -172,8 +172,6 @@
         
         //Add device to the array of devices and initialize it
         else{
-            //For some reason the enum is indexed weirdly, device-- to send correct value
-            deviceFound--;
             devices.push_back(Device::newDevice(deviceFound, lineData.word[1], lineData));
             devices.back()->name = lineData.word[1];             
         }