Robot

Dependencies:   mbed QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Driver.cpp Source File

Driver.cpp

00001 #include "Driver.h"
00002 
00003 Driver::Driver(PinName adrress){
00004      communication = D_DAC;
00005      dac = new AnalogOut(adrress);
00006 }
00007 
00008 Driver::Driver(PinName RX,PinName TX){
00009      communication = D_CAN;
00010      can = new CAN(RX,TX);
00011 
00012 }
00013 
00014 Driver::Driver(PinName MOSI,PinName MISO,PinName sclk, int frecuency){
00015      communication = D_SPI;
00016      spi = new SPI(MOSI, MISO, sclk);
00017      spi->format(8,3);
00018      spi->frequency(frecuency);
00019 }
00020 
00021 int Driver::sendmessage(char data[8]){
00022     int isCorrect;
00023     char received[8];
00024     switch(communication){
00025        case D_CAN:
00026            isCorrect=can->write(CANMessage(1337, data, 8));
00027            break;
00028        case D_SPI:
00029            isCorrect = spi->write(data,8,received,8);
00030            break;
00031        default:
00032            return 0;
00033     }
00034     if(isCorrect){
00035         return 1;
00036     }else{
00037         return 0;
00038     }
00039 }
00040 
00041 int Driver::sendmessage(float data){
00042     if (communication==D_DAC){
00043         dac->write(data);
00044         return 1;
00045     }
00046     return 0;
00047 }          
00048 Driver::~Driver(){
00049     delete can, dac, spi;
00050     }