Refactor spi implementation type
This commit is contained in:
parent
ecd82d7c90
commit
dee253d376
|
@ -66,7 +66,7 @@ ProviderSpi::ProviderSpi(const QJsonObject &deviceConfig)
|
||||||
, _spiMode(SPI_MODE_0)
|
, _spiMode(SPI_MODE_0)
|
||||||
, _spiDataInvert(false)
|
, _spiDataInvert(false)
|
||||||
#endif
|
#endif
|
||||||
, _spiImplementation(SPI_SPIDEV) {
|
, _spiImplementation(SPIDEV) {
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
memset(&_spi, 0, sizeof(_spi));
|
memset(&_spi, 0, sizeof(_spi));
|
||||||
_latchTime_ms = 1;
|
_latchTime_ms = 1;
|
||||||
|
@ -91,7 +91,7 @@ bool ProviderSpi::init(const QJsonObject &deviceConfig) {
|
||||||
bool isFtdiImplementation = (
|
bool isFtdiImplementation = (
|
||||||
QString::compare(deviceConfig["implementation"].toString(ImplementationSPIDEV), ImplementationFTDI,
|
QString::compare(deviceConfig["implementation"].toString(ImplementationSPIDEV), ImplementationFTDI,
|
||||||
Qt::CaseInsensitive) == 0);
|
Qt::CaseInsensitive) == 0);
|
||||||
_spiImplementation = isFtdiImplementation ? SPI_FTDI : SPI_SPIDEV;
|
_spiImplementation = isFtdiImplementation ? FTDI : SPIDEV;
|
||||||
|
|
||||||
Debug(_log, "_baudRate_Hz [%d], _latchTime_ms [%d]", _baudRate_Hz, _latchTime_ms);
|
Debug(_log, "_baudRate_Hz [%d], _latchTime_ms [%d]", _baudRate_Hz, _latchTime_ms);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ int ProviderSpi::open() {
|
||||||
int retVal = -1;
|
int retVal = -1;
|
||||||
QString errortext;
|
QString errortext;
|
||||||
_isDeviceReady = false;
|
_isDeviceReady = false;
|
||||||
if (_spiImplementation == SPI_SPIDEV) {
|
if (_spiImplementation == SPIDEV) {
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
const int bitsPerWord = 8;
|
const int bitsPerWord = 8;
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ int ProviderSpi::open() {
|
||||||
this->setInError( errortext );
|
this->setInError( errortext );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (_spiImplementation == SPI_FTDI) {
|
} else if (_spiImplementation == FTDI) {
|
||||||
#ifdef ENABLE_DEV_FTDI
|
#ifdef ENABLE_DEV_FTDI
|
||||||
|
|
||||||
_ftdic = ftdi_new();
|
_ftdic = ftdi_new();
|
||||||
|
@ -192,7 +192,7 @@ int ProviderSpi::close() {
|
||||||
// LedDevice specific closing activities
|
// LedDevice specific closing activities
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
_isDeviceReady = false;
|
_isDeviceReady = false;
|
||||||
if (_spiImplementation == SPI_SPIDEV) {
|
if (_spiImplementation == SPIDEV) {
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
// Test, if device requires closing
|
// Test, if device requires closing
|
||||||
if ( _fid > -1 )
|
if ( _fid > -1 )
|
||||||
|
@ -205,7 +205,7 @@ int ProviderSpi::close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (_spiImplementation == SPI_FTDI) {
|
} else if (_spiImplementation == FTDI) {
|
||||||
#ifdef ENABLE_DEV_FTDI
|
#ifdef ENABLE_DEV_FTDI
|
||||||
if (_ftdic != nullptr) {
|
if (_ftdic != nullptr) {
|
||||||
Debug(_log, "Closing FTDI device");
|
Debug(_log, "Closing FTDI device");
|
||||||
|
@ -224,7 +224,7 @@ int ProviderSpi::close() {
|
||||||
|
|
||||||
int ProviderSpi::writeBytes(unsigned size, const uint8_t *data) {
|
int ProviderSpi::writeBytes(unsigned size, const uint8_t *data) {
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
if (_spiImplementation == SPI_SPIDEV) {
|
if (_spiImplementation == SPIDEV) {
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
if (_fid < 0)
|
if (_fid < 0)
|
||||||
{
|
{
|
||||||
|
@ -250,7 +250,7 @@ int ProviderSpi::writeBytes(unsigned size, const uint8_t *data) {
|
||||||
|
|
||||||
free (newdata);
|
free (newdata);
|
||||||
#endif
|
#endif
|
||||||
} else if (_spiImplementation == SPI_FTDI) {
|
} else if (_spiImplementation == FTDI) {
|
||||||
#ifdef ENABLE_DEV_FTDI
|
#ifdef ENABLE_DEV_FTDI
|
||||||
int count_arg = size - 1;
|
int count_arg = size - 1;
|
||||||
std::vector<uint8_t> buf = {
|
std::vector<uint8_t> buf = {
|
||||||
|
|
|
@ -13,8 +13,10 @@
|
||||||
// Hyperion includes
|
// Hyperion includes
|
||||||
#include <leddevice/LedDevice.h>
|
#include <leddevice/LedDevice.h>
|
||||||
|
|
||||||
#define SPI_SPIDEV 0
|
|
||||||
#define SPI_FTDI 1
|
|
||||||
|
enum SpiImplementation { SPIDEV, FTDI };
|
||||||
|
|
||||||
///
|
///
|
||||||
/// The ProviderSpi implements an abstract base-class for LedDevices using the SPI-device.
|
/// The ProviderSpi implements an abstract base-class for LedDevices using the SPI-device.
|
||||||
///
|
///
|
||||||
|
@ -94,5 +96,5 @@ protected:
|
||||||
struct ftdi_context *_ftdic;
|
struct ftdi_context *_ftdic;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t _spiImplementation;
|
SpiImplementation _spiImplementation;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue