2013-11-01 23:48:39 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Linux-SPI includes
|
|
|
|
#include <linux/spi/spidev.h>
|
|
|
|
|
|
|
|
// Hyperion includes
|
2013-12-17 19:50:15 +01:00
|
|
|
#include <leddevice/LedDevice.h>
|
2013-11-01 23:48:39 +01:00
|
|
|
|
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
/// The ProviderSpi implements an abstract base-class for LedDevices using the SPI-device.
|
2013-11-01 23:48:39 +01:00
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
class ProviderSpi : public LedDevice
|
2013-11-01 23:48:39 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
///
|
2016-08-23 20:07:12 +02:00
|
|
|
/// Constructs specific LedDevice
|
2013-11-01 23:48:39 +01:00
|
|
|
///
|
2016-10-08 08:14:36 +02:00
|
|
|
ProviderSpi();
|
2016-08-13 19:54:08 +02:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
|
|
|
/// Sets configuration
|
|
|
|
///
|
|
|
|
/// @param deviceConfig the json device config
|
|
|
|
/// @return true if success
|
2016-10-08 08:14:36 +02:00
|
|
|
virtual bool init(const Json::Value &deviceConfig);
|
2013-11-01 23:48:39 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Destructor of the LedDevice; closes the output device if it is open
|
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
virtual ~ProviderSpi();
|
2013-11-01 23:48:39 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Opens and configures the output device
|
|
|
|
///
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
|
|
|
int open();
|
|
|
|
|
2013-11-02 06:51:41 +01:00
|
|
|
protected:
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
|
|
|
/// Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the
|
|
|
|
/// values are latched.
|
|
|
|
///
|
|
|
|
/// @param[in[ size The length of the data
|
|
|
|
/// @param[in] data The data
|
|
|
|
///
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
2013-11-02 19:30:19 +01:00
|
|
|
int writeBytes(const unsigned size, const uint8_t *data);
|
2013-11-02 06:51:41 +01:00
|
|
|
|
2013-11-01 23:48:39 +01:00
|
|
|
/// The name of the output device
|
2016-08-23 20:07:12 +02:00
|
|
|
std::string _deviceName;
|
2016-08-14 10:46:44 +02:00
|
|
|
|
2013-11-01 23:48:39 +01:00
|
|
|
/// The used baudrate of the output device
|
2016-08-23 20:07:12 +02:00
|
|
|
int _baudRate_Hz;
|
2016-08-14 10:46:44 +02:00
|
|
|
|
2013-11-02 19:30:19 +01:00
|
|
|
/// The time which the device should be untouched after a write
|
2016-08-23 20:07:12 +02:00
|
|
|
int _latchTime_ns;
|
2013-11-01 23:48:39 +01:00
|
|
|
|
|
|
|
/// The File Identifier of the opened output device (or -1 if not opened)
|
2016-08-14 10:46:44 +02:00
|
|
|
int _fid;
|
2016-08-13 19:54:08 +02:00
|
|
|
|
|
|
|
/// which spi clock mode do we use? (0..3)
|
2016-08-14 10:46:44 +02:00
|
|
|
int _spiMode;
|
2016-08-13 19:54:08 +02:00
|
|
|
|
|
|
|
/// 1=>invert the data pattern
|
2016-08-14 10:46:44 +02:00
|
|
|
bool _spiDataInvert;
|
2016-08-13 19:54:08 +02:00
|
|
|
|
2013-11-01 23:48:39 +01:00
|
|
|
/// The transfer structure for writing to the spi-device
|
2016-08-14 10:46:44 +02:00
|
|
|
spi_ioc_transfer _spi;
|
2013-11-01 23:48:39 +01:00
|
|
|
};
|