Mitchell Hatfield / Mbed 2 deprecated Component_Test_Interface

Dependencies:   BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed

Committer:
mehatfie
Date:
Tue Sep 16 15:28:59 2014 +0000
Revision:
0:22618cf06f45
Child:
2:3e7baa3e3fec
- Initial Commit; - Code is a mess (in mid transition of general code architecture); - Functionality work to drive motors in both direction and turn off; - Delay functionality working; - Able to read a program from a txt file and perform functionality

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mehatfie 0:22618cf06f45 1 #ifndef DEVICE_HPP
mehatfie 0:22618cf06f45 2 #define DEVICE_HPP
mehatfie 0:22618cf06f45 3
mehatfie 0:22618cf06f45 4 #include "Initialization.hpp"
mehatfie 0:22618cf06f45 5 #include "mbed.h"
mehatfie 0:22618cf06f45 6 #include "LocalPinNames.h"
mehatfie 0:22618cf06f45 7 #include "BridgeDriver.h"
mehatfie 0:22618cf06f45 8 #include "DeviceClasses.h"
mehatfie 0:22618cf06f45 9 //#include "Motor.hpp"
mehatfie 0:22618cf06f45 10 //#include "VoltageDriver.hpp"
mehatfie 0:22618cf06f45 11
mehatfie 0:22618cf06f45 12 enum DeviceType{MOTOR, VOLTAGE_DRIVER};
mehatfie 0:22618cf06f45 13 static const enum DeviceType Device_Map[] = {MOTOR, VOLTAGE_DRIVER};
mehatfie 0:22618cf06f45 14 const char *DeviceNames[] = {"MOTOR", "VOLTAGE_DRIVER"};
mehatfie 0:22618cf06f45 15 extern int numDevices = sizeof(DeviceNames)/sizeof(DeviceNames[0]);
mehatfie 0:22618cf06f45 16 extern int currNumDevices = 0;
mehatfie 0:22618cf06f45 17
mehatfie 0:22618cf06f45 18 /*
mehatfie 0:22618cf06f45 19 class Device{
mehatfie 0:22618cf06f45 20
mehatfie 0:22618cf06f45 21 public:
mehatfie 0:22618cf06f45 22 char name[100];
mehatfie 0:22618cf06f45 23 static Device* newDevice(int);
mehatfie 0:22618cf06f45 24 int interpret();
mehatfie 0:22618cf06f45 25 };
mehatfie 0:22618cf06f45 26
mehatfie 0:22618cf06f45 27 extern Device devices[15]; //Initialize array of devices, initially assume 15 devices will be used (will expand as needed)
mehatfie 0:22618cf06f45 28
mehatfie 0:22618cf06f45 29 void addDevice(int deviceFound){
mehatfie 0:22618cf06f45 30
mehatfie 0:22618cf06f45 31 //devices[currNumDevices] = Device::newDevice(deviceFound);
mehatfie 0:22618cf06f45 32 currNumDevices++;
mehatfie 0:22618cf06f45 33 }
mehatfie 0:22618cf06f45 34 */
mehatfie 0:22618cf06f45 35
mehatfie 0:22618cf06f45 36
mehatfie 0:22618cf06f45 37
mehatfie 0:22618cf06f45 38
mehatfie 0:22618cf06f45 39 struct DeviceData {
mehatfie 0:22618cf06f45 40 DeviceType type;
mehatfie 0:22618cf06f45 41 char name[MAX_LINE_LENGTH];
mehatfie 0:22618cf06f45 42 union {
mehatfie 0:22618cf06f45 43 Voltage_Driver VOLTAGE_DRIVER;
mehatfie 0:22618cf06f45 44 Motor MOTOR;
mehatfie 0:22618cf06f45 45 };
mehatfie 0:22618cf06f45 46 };
mehatfie 0:22618cf06f45 47
mehatfie 0:22618cf06f45 48 extern struct DeviceData devices[15]; //Initialize array of devices, initially assume 15 devices will be used (will expand as needed)
mehatfie 0:22618cf06f45 49
mehatfie 0:22618cf06f45 50 void relayLine(DeviceData device){
mehatfie 0:22618cf06f45 51 switch(device.type){
mehatfie 0:22618cf06f45 52 case MOTOR: device.MOTOR.interpret(); break;
mehatfie 0:22618cf06f45 53 case VOLTAGE_DRIVER: device.VOLTAGE_DRIVER.interpret(); break;
mehatfie 0:22618cf06f45 54 }
mehatfie 0:22618cf06f45 55 }
mehatfie 0:22618cf06f45 56
mehatfie 0:22618cf06f45 57 void addDevice(int deviceFound){
mehatfie 0:22618cf06f45 58
mehatfie 0:22618cf06f45 59 //Save the device type
mehatfie 0:22618cf06f45 60 switch (Device_Map[deviceFound]){
mehatfie 0:22618cf06f45 61 case MOTOR: devices[currNumDevices].type = MOTOR; break;
mehatfie 0:22618cf06f45 62 case VOLTAGE_DRIVER: devices[currNumDevices].type = VOLTAGE_DRIVER; break;
mehatfie 0:22618cf06f45 63 }
mehatfie 0:22618cf06f45 64
mehatfie 0:22618cf06f45 65 strcpy(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
mehatfie 0:22618cf06f45 66 relayLine(devices[currNumDevices]); //Give the command to the appropraite class in order to initialize itself based on the line
mehatfie 0:22618cf06f45 67 currNumDevices++; //Increment the total number of devices created
mehatfie 0:22618cf06f45 68 }
mehatfie 0:22618cf06f45 69
mehatfie 0:22618cf06f45 70
mehatfie 0:22618cf06f45 71
mehatfie 0:22618cf06f45 72 #endif
mehatfie 0:22618cf06f45 73