Mitchell Hatfield / Mbed 2 deprecated Component_Test_Interface

Dependencies:   BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed

Device.hpp

Committer:
mehatfie
Date:
2014-09-16
Revision:
0:22618cf06f45
Child:
2:3e7baa3e3fec

File content as of revision 0:22618cf06f45:

#ifndef DEVICE_HPP
#define DEVICE_HPP

#include "Initialization.hpp"
#include "mbed.h"
#include "LocalPinNames.h"
#include "BridgeDriver.h"
#include "DeviceClasses.h"
//#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;
    char name[MAX_LINE_LENGTH];
    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;
    }

    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
    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