mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Reformat code
This commit is contained in:
parent
f28132b458
commit
91713c15b4
@ -7,38 +7,38 @@
|
|||||||
#include "ProviderSpi.h"
|
#include "ProviderSpi.h"
|
||||||
|
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
// Linux includes
|
// Linux includes
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
// qt includes
|
// qt includes
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_DEV_FTDI
|
#ifdef ENABLE_DEV_FTDI
|
||||||
#include <ftdi.h>
|
|
||||||
#include <libusb.h>
|
|
||||||
#include <utils/WaitTime.h>
|
|
||||||
#define FTDI_CHECK_RESULT(statement) if (statement) {setInError(ftdi_get_error_string(_ftdic)); return retVal;}
|
|
||||||
|
|
||||||
#define ANY_FTDI_VENDOR 0x0
|
#include <ftdi.h>
|
||||||
#define ANY_FTDI_PRODUCT 0x0
|
#include <libusb.h>
|
||||||
|
#include <utils/WaitTime.h>
|
||||||
|
|
||||||
|
#define FTDI_CHECK_RESULT(statement) if (statement) {setInError(ftdi_get_error_string(_ftdic)); return retVal;}
|
||||||
|
|
||||||
|
#define ANY_FTDI_VENDOR 0x0
|
||||||
|
#define ANY_FTDI_PRODUCT 0x0
|
||||||
|
|
||||||
|
|
||||||
namespace Pin
|
namespace Pin {
|
||||||
{
|
|
||||||
// enumerate the AD bus for convenience.
|
// enumerate the AD bus for convenience.
|
||||||
enum bus_t
|
enum bus_t {
|
||||||
{
|
|
||||||
SK = 0x01, // ADBUS0, SPI data clock
|
SK = 0x01, // ADBUS0, SPI data clock
|
||||||
DO = 0x02, // ADBUS1, SPI data out
|
DO = 0x02, // ADBUS1, SPI data out
|
||||||
CS = 0x08, // ADBUS3, SPI chip select, active low
|
CS = 0x08, // ADBUS3, SPI chip select, active low
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned char pinInitialState = Pin::CS;
|
const unsigned char pinInitialState = Pin::CS;
|
||||||
// Use these pins as outputs
|
// Use these pins as outputs
|
||||||
const unsigned char pinDirection = Pin::SK | Pin::DO | Pin::CS;
|
const unsigned char pinDirection = Pin::SK | Pin::DO | Pin::CS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -60,33 +60,27 @@ namespace {
|
|||||||
} //End of constants
|
} //End of constants
|
||||||
|
|
||||||
ProviderSpi::ProviderSpi(const QJsonObject &deviceConfig)
|
ProviderSpi::ProviderSpi(const QJsonObject &deviceConfig)
|
||||||
: LedDevice(deviceConfig)
|
: LedDevice(deviceConfig), _deviceName("/dev/spidev0.0"), _baudRate_Hz(1000000)
|
||||||
, _deviceName("/dev/spidev0.0")
|
|
||||||
, _baudRate_Hz(1000000)
|
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
, _fid(-1)
|
, _fid(-1)
|
||||||
, _spiMode(SPI_MODE_0)
|
, _spiMode(SPI_MODE_0)
|
||||||
, _spiDataInvert(false)
|
, _spiDataInvert(false)
|
||||||
#endif
|
#endif
|
||||||
, _spiImplementation(SPI_SPIDEV)
|
, _spiImplementation(SPI_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;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ProviderSpi::~ProviderSpi()
|
ProviderSpi::~ProviderSpi() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProviderSpi::init(const QJsonObject &deviceConfig)
|
bool ProviderSpi::init(const QJsonObject &deviceConfig) {
|
||||||
{
|
|
||||||
bool isInitOK = false;
|
bool isInitOK = false;
|
||||||
|
|
||||||
// Initialise sub-class
|
// Initialise sub-class
|
||||||
if ( LedDevice::init(deviceConfig) )
|
if (LedDevice::init(deviceConfig)) {
|
||||||
{
|
|
||||||
_deviceName = deviceConfig["output"].toString(_deviceName);
|
_deviceName = deviceConfig["output"].toString(_deviceName);
|
||||||
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
|
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
@ -94,7 +88,9 @@ bool ProviderSpi::init(const QJsonObject &deviceConfig)
|
|||||||
_spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert);
|
_spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert);
|
||||||
Debug(_log, "_spiDataInvert [%d], _spiMode [%d]", _spiDataInvert, _spiMode);
|
Debug(_log, "_spiDataInvert [%d], _spiMode [%d]", _spiDataInvert, _spiMode);
|
||||||
#endif
|
#endif
|
||||||
bool isFtdiImplementation = (QString::compare(deviceConfig["implementation"].toString(ImplementationSPIDEV), ImplementationFTDI, Qt::CaseInsensitive) == 0);
|
bool isFtdiImplementation = (
|
||||||
|
QString::compare(deviceConfig["implementation"].toString(ImplementationSPIDEV), ImplementationFTDI,
|
||||||
|
Qt::CaseInsensitive) == 0);
|
||||||
_spiImplementation = isFtdiImplementation ? SPI_FTDI : SPI_SPIDEV;
|
_spiImplementation = isFtdiImplementation ? SPI_FTDI : SPI_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,12 +101,11 @@ bool ProviderSpi::init(const QJsonObject &deviceConfig)
|
|||||||
return isInitOK;
|
return isInitOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProviderSpi::open()
|
int ProviderSpi::open() {
|
||||||
{
|
|
||||||
int retVal = -1;
|
int retVal = -1;
|
||||||
QString errortext;
|
QString errortext;
|
||||||
_isDeviceReady = false;
|
_isDeviceReady = false;
|
||||||
if (_spiImplementation == SPI_SPIDEV) {
|
if (_spiImplementation == SPI_SPIDEV) {
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
const int bitsPerWord = 8;
|
const int bitsPerWord = 8;
|
||||||
|
|
||||||
@ -158,7 +153,7 @@ if (_spiImplementation == SPI_SPIDEV) {
|
|||||||
this->setInError( errortext );
|
this->setInError( errortext );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (_spiImplementation == SPI_FTDI) {
|
} else if (_spiImplementation == SPI_FTDI) {
|
||||||
#ifdef ENABLE_DEV_FTDI
|
#ifdef ENABLE_DEV_FTDI
|
||||||
|
|
||||||
_ftdic = ftdi_new();
|
_ftdic = ftdi_new();
|
||||||
@ -189,12 +184,11 @@ if (_spiImplementation == SPI_SPIDEV) {
|
|||||||
|
|
||||||
_isDeviceReady = true;
|
_isDeviceReady = true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProviderSpi::close()
|
int ProviderSpi::close() {
|
||||||
{
|
|
||||||
// LedDevice specific closing activities
|
// LedDevice specific closing activities
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
_isDeviceReady = false;
|
_isDeviceReady = false;
|
||||||
@ -228,8 +222,7 @@ int ProviderSpi::close()
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 == SPI_SPIDEV) {
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
@ -282,10 +275,9 @@ int ProviderSpi::writeBytes(unsigned size, const uint8_t * data)
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject ProviderSpi::discover(const QJsonObject& /*params*/)
|
QJsonObject ProviderSpi::discover(const QJsonObject & /*params*/) {
|
||||||
{
|
|
||||||
QJsonObject devicesDiscovered;
|
QJsonObject devicesDiscovered;
|
||||||
devicesDiscovered.insert("ledDeviceType", _activeDeviceType );
|
devicesDiscovered.insert("ledDeviceType", _activeDeviceType);
|
||||||
QJsonArray deviceList;
|
QJsonArray deviceList;
|
||||||
|
|
||||||
#ifdef ENABLE_DEV_SPI
|
#ifdef ENABLE_DEV_SPI
|
||||||
@ -311,17 +303,14 @@ QJsonObject ProviderSpi::discover(const QJsonObject& /*params*/)
|
|||||||
|
|
||||||
ftdic = ftdi_new();
|
ftdic = ftdi_new();
|
||||||
|
|
||||||
if (ftdi_usb_find_all(ftdic, &devlist, ANY_FTDI_VENDOR, ANY_FTDI_PRODUCT) > 0)
|
if (ftdi_usb_find_all(ftdic, &devlist, ANY_FTDI_VENDOR, ANY_FTDI_PRODUCT) > 0) {
|
||||||
{
|
|
||||||
struct ftdi_device_list *curdev = devlist;
|
struct ftdi_device_list *curdev = devlist;
|
||||||
QMap<QString, uint8_t> deviceIndexes;
|
QMap<QString, uint8_t> deviceIndexes;
|
||||||
|
|
||||||
while (curdev)
|
while (curdev) {
|
||||||
{
|
|
||||||
libusb_device_descriptor desc;
|
libusb_device_descriptor desc;
|
||||||
int rc = libusb_get_device_descriptor(curdev->dev, &desc);
|
int rc = libusb_get_device_descriptor(curdev->dev, &desc);
|
||||||
if (rc == 0)
|
if (rc == 0) {
|
||||||
{
|
|
||||||
QString vendorIdentifier = QString("0x%1").arg(desc.idVendor, 4, 16, QChar{'0'});
|
QString vendorIdentifier = QString("0x%1").arg(desc.idVendor, 4, 16, QChar{'0'});
|
||||||
QString productIdentifier = QString("0x%1").arg(desc.idProduct, 4, 16, QChar{'0'});
|
QString productIdentifier = QString("0x%1").arg(desc.idProduct, 4, 16, QChar{'0'});
|
||||||
QString vendorAndProduct = QString("%1:%2")
|
QString vendorAndProduct = QString("%1:%2")
|
||||||
@ -332,16 +321,14 @@ QJsonObject ProviderSpi::discover(const QJsonObject& /*params*/)
|
|||||||
char serial_string[128] = {0};
|
char serial_string[128] = {0};
|
||||||
char manufacturer_string[128] = {0};
|
char manufacturer_string[128] = {0};
|
||||||
char description_string[128] = {0};
|
char description_string[128] = {0};
|
||||||
ftdi_usb_get_strings2(ftdic, curdev->dev, manufacturer_string, 128, description_string, 128, serial_string, 128);
|
ftdi_usb_get_strings2(ftdic, curdev->dev, manufacturer_string, 128, description_string, 128,
|
||||||
|
serial_string, 128);
|
||||||
|
|
||||||
QString serialNumber {serial_string};
|
QString serialNumber{serial_string};
|
||||||
QString ftdiOpenString;
|
QString ftdiOpenString;
|
||||||
if(!serialNumber.isEmpty())
|
if (!serialNumber.isEmpty()) {
|
||||||
{
|
|
||||||
ftdiOpenString = QString("s:%1:%2").arg(vendorAndProduct).arg(serialNumber);
|
ftdiOpenString = QString("s:%1:%2").arg(vendorAndProduct).arg(serialNumber);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ftdiOpenString = QString("i:%1:%2").arg(vendorAndProduct).arg(deviceIndex);
|
ftdiOpenString = QString("i:%1:%2").arg(vendorAndProduct).arg(deviceIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,7 +354,8 @@ QJsonObject ProviderSpi::discover(const QJsonObject& /*params*/)
|
|||||||
ftdi_free(ftdic);
|
ftdi_free(ftdic);
|
||||||
#endif
|
#endif
|
||||||
devicesDiscovered.insert("devices", deviceList);
|
devicesDiscovered.insert("devices", deviceList);
|
||||||
DebugIf(verbose,_log, "devicesDiscovered: [%s]", QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
DebugIf(verbose, _log, "devicesDiscovered: [%s]",
|
||||||
|
QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||||
|
|
||||||
return devicesDiscovered;
|
return devicesDiscovered;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user