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
Diff: Devices/PinIN.cpp
- Revision:
- 9:5a0c4c6e39c7
- Parent:
- 5:e36e0538a903
- Child:
- 10:e8db892fbc52
--- a/Devices/PinIN.cpp Wed Sep 24 01:46:02 2014 +0000 +++ b/Devices/PinIN.cpp Wed Sep 24 22:23:00 2014 +0000 @@ -6,6 +6,10 @@ //Constructor PinIN::PinIN(LineData lineData){ + //Order of Line: Command, Local_Name, PIN_IN, pinName, pinMode + if (lineData.numWords != 5) + this->errorFlag = 1; + string _pinName = lineData.word[3]; // Local Pin string _pinMode = lineData.word[4]; // Pin Mode to Select @@ -46,7 +50,10 @@ this->pinName = AI4; else if(_pinName.compare("AI5") == 0) this->pinName = AI5; - + + //Pin Name not recognized + else + this->errorFlag = 1; if(_pinMode.compare("PU") == 0) this->pinMode = PullUp; @@ -57,48 +64,16 @@ else if(_pinMode.compare("OD") == 0) this->pinMode = OpenDrain; + //Pin Mode not recognized + else + this->errorFlag = 1; } -/* - #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(LineData &lineData){ - /* - lcd.setAddress(0,2); - lcd.printf("CHECK Motor 123456"); - lcd.setAddress(0,3); - lcd.printf("func: %s ", lineData.word[1]); - wait(2);*/ - + + //Initialize the Pin with appropriate values DigitalIn signal(pinName, pinMode); //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,....... @@ -110,15 +85,26 @@ if (func.compare("wait") == 0){ if (lineData.numWords != 3){ - //Error Check, incorrect number of parameter, error out - return 0; + ErrorOut("Incorrect number of parameters", lineData.lineNumber); + return -1; } //Initialize and Convert Parameters string pinValue = lineData.word[2]; int pinValue_Value = 0; - sscanf(pinValue.c_str(), "%d", &pinValue_Value); + + int numValuesFound = sscanf(pinValue.c_str(), "%d", &pinValue_Value); + if (numValuesFound < 1){ + ErrorOut("Parameter Unknown, pin value can't be converted", lineData.lineNumber); + return -1; + } + if(pinValue_Value < 0 && pinValue_Value > 1){ + ErrorOut("Pin Value must be either 0 or 1", lineData.lineNumber); + return -1; + } + + //Wait on the signal to turn to the specified value while(signal.read() != pinValue_Value); } @@ -127,18 +113,28 @@ /*** <Func: val> ***/ /******************************************************************************/ // returns 1 if the check value is equal to the current check value of the Pin - if (func.compare("val") == 0){ + else if (func.compare("val") == 0){ if (lineData.numWords != 3){ - //Error Check, incorrect number of parameter, error out - return 0; + ErrorOut("Incorrect number of parameters", lineData.lineNumber); + return -1; } //Initialize and Convert Parameters string checkValue = lineData.word[2]; int checkValue_Value = 0; - sscanf(checkValue.c_str(), "%d", &checkValue_Value); + int numValuesFound = sscanf(checkValue.c_str(), "%d", &checkValue_Value); + if (numValuesFound < 1){ + ErrorOut("Parameter Unknown, pin value can't be converted", lineData.lineNumber); + return -1; + } + if(checkValue_Value < 0 && checkValue_Value > 1){ + ErrorOut("Pin Value must be either 0 or 1", lineData.lineNumber); + return -1; + } + + //Return one if value meets the wanted pin value, return 0 if it doesn't if(signal.read() == checkValue_Value) return 1; else @@ -146,10 +142,13 @@ } else { - return 0; - + ErrorOut("Unknown Command for PinIn Class", lineData.lineNumber); + return -1; } - - return 0; + + return 0; //Return success as 0 since no condition had to be met } +int PinIN::off(void){ + //Do Nothing as you don't need to turn a Pin off +} \ No newline at end of file