/*
 * arduino.h
 *
 *  Arduino hardware control
 *
 *  Created on: 30/08/2012
 *      Author: timothyw
 */

#ifndef INCLUDE_NEGOTIATOR_DRIVERS_FLIPPERS_FLIPPERS_ARDUINO_H_
#define INCLUDE_NEGOTIATOR_DRIVERS_FLIPPERS_FLIPPERS_ARDUINO_H_

#include "negotiator_drivers/flippers/hardware.h"
#include "negotiator_drivers/flippers/serialPort.h"

#include <string>

namespace casualty {

class FlippersArduinoInterface : public FlippersHardwareInterface {
public:

    FlippersArduinoInterface();
    virtual ~FlippersArduinoInterface();

    /**
     * Configure the drivers and USB elements
     */
    virtual void configure(crosbot::ConfigElementPtr cf);

    /**
     * Start the driver
     */
    virtual void start();

    /**
     * Stop the driver
     */
    virtual void stop();

    /**
     * Emergency Stop command
     */
    virtual void command_EMStop();

    /**
     * Move at velocity, positive velocity is forward, negative velocity is reverse
     */
    virtual void command_Velocity(double velocity);

    /**
     * Move forward at velocity
     */
    void command_Forward(char velocity);

    /**
     * Move reverse at velocity
     */
    void command_Reverse(char velocity);

    /**
     * Reads a single set of values
     */
    virtual void readValues(double &pot_val, double &setPoint, double &battery);

private:
    int flipperOffset;
    int debug;

    // Serial Port
    std::string port;
    Comms::SerialPort *commsPort;

    // Reading Thread
    pthread_t threadRead;
};

} // namespace casualty

#endif /* INCLUDE_NEGOTIATOR_DRIVERS_FLIPPERS_FLIPPERS_ARDUINO_H_ */

