From f0259172fd1c5a0da8250fefe08f2ec32101466f Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sat, 25 Mar 2023 23:32:14 +0000 Subject: [PATCH 01/48] Implement ftdi led device --- CMakeLists.txt | 1 + assets/webconfig/i18n/en.json | 6 + assets/webconfig/js/content_leds.js | 9 +- include/utils/RgbToRgbw.h | 7 +- libsrc/leddevice/CMakeLists.txt | 14 + libsrc/leddevice/LedDeviceSchemas.qrc | 3 + .../dev_ftdi/LedDeviceAPA102_ftdi.cpp | 61 +++++ .../leddevice/dev_ftdi/LedDeviceAPA102_ftdi.h | 50 ++++ .../dev_ftdi/LedDeviceSk6812_ftdi.cpp | 93 +++++++ .../leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h | 56 ++++ .../dev_ftdi/LedDeviceWs2812_ftdi.cpp | 102 +++++++ .../leddevice/dev_ftdi/LedDeviceWs2812_ftdi.h | 49 ++++ libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 248 ++++++++++++++++++ libsrc/leddevice/dev_ftdi/ProviderFtdi.h | 79 ++++++ .../leddevice/schemas/schema-apa102_ftdi.json | 25 ++ .../leddevice/schemas/schema-sk6812_ftdi.json | 60 +++++ .../leddevice/schemas/schema-ws2812_ftdi.json | 19 ++ libsrc/utils/RgbToRgbw.cpp | 84 +++++- 18 files changed, 962 insertions(+), 4 deletions(-) create mode 100644 libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp create mode 100644 libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.h create mode 100644 libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp create mode 100644 libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h create mode 100644 libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp create mode 100644 libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.h create mode 100644 libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp create mode 100644 libsrc/leddevice/dev_ftdi/ProviderFtdi.h create mode 100644 libsrc/leddevice/schemas/schema-apa102_ftdi.json create mode 100644 libsrc/leddevice/schemas/schema-sk6812_ftdi.json create mode 100644 libsrc/leddevice/schemas/schema-ws2812_ftdi.json diff --git a/CMakeLists.txt b/CMakeLists.txt index e0c458828..a9b5efff2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ SET ( DEFAULT_DEV_SPI OFF ) SET ( DEFAULT_DEV_TINKERFORGE OFF ) SET ( DEFAULT_DEV_USB_HID OFF ) SET ( DEFAULT_DEV_WS281XPWM OFF ) +SET ( DEFAULT_ENABLE_FTDIDEV OFF ) # Services SET ( DEFAULT_EFFECTENGINE ON ) diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 6845685d1..986af06c8 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -158,6 +158,7 @@ "conf_leds_optgroup_network": "Network", "conf_leds_optgroup_other": "Other", "conf_leds_optgroup_usb": "USB/Serial", + "conf_leds_optgroup_ftdi": "USB/Ftdi", "conf_logging_btn_autoscroll": "Auto scrolling", "conf_logging_btn_clipboard": "Copy Log to Clipboard", "conf_logging_btn_pbupload": "Upload a report for support requests", @@ -567,6 +568,11 @@ "edt_dev_enum_sub_min_cool_adjust": "Subtract cool white", "edt_dev_enum_sub_min_warm_adjust": "Subtract warm white", "edt_dev_enum_subtract_minimum": "Subtract minimum", + "edt_dev_enum_hyperserial_cold_white": "Hyperserial, cold white", + "edt_dev_enum_hyperserial_neutral_white": "Hyperserial, neutral white", + "edt_dev_enum_wled_auto": "Wled auto", + "edt_dev_enum_wled_auto_max": "Wled auto max", + "edt_dev_enum_wled_auto_accurate": "Wled auto accurate", "edt_dev_enum_white_off": "White off", "edt_dev_general_autostart_title": "Autostart", "edt_dev_general_autostart_title_info": "The LED device is switched-on during startup or not", diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index 5cff7fd32..02ebefc60 100755 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -1645,8 +1645,10 @@ $(document).ready(function () { optArr[3] = []; optArr[4] = []; optArr[5] = []; + optArr[6] = []; for (var idx = 0; idx < ledDevices.length; idx++) { + var isFtdi = ledDevices[idx].endsWith("_ftdi"); if ($.inArray(ledDevices[idx], devRPiSPI) != -1) optArr[0].push(ledDevices[idx]); else if ($.inArray(ledDevices[idx], devRPiPWM) != -1) @@ -1659,8 +1661,10 @@ $(document).ready(function () { optArr[4].push(ledDevices[idx]); else if ($.inArray(ledDevices[idx], devHID) != -1) optArr[4].push(ledDevices[idx]); - else + else if (isFtdi) optArr[5].push(ledDevices[idx]); + else + optArr[6].push(ledDevices[idx]); } $("#leddevices").append(createSel(optArr[0], $.i18n('conf_leds_optgroup_RPiSPI'))); @@ -1668,9 +1672,10 @@ $(document).ready(function () { $("#leddevices").append(createSel(optArr[2], $.i18n('conf_leds_optgroup_RPiGPIO'))); $("#leddevices").append(createSel(optArr[3], $.i18n('conf_leds_optgroup_network'))); $("#leddevices").append(createSel(optArr[4], $.i18n('conf_leds_optgroup_usb'))); + $("#leddevices").append(createSel(optArr[5], $.i18n('conf_leds_optgroup_ftdi'))); if (storedAccess === 'expert' || window.serverConfig.device.type === "file") { - $("#leddevices").append(createSel(optArr[5], $.i18n('conf_leds_optgroup_other'))); + $("#leddevices").append(createSel(optArr[6], $.i18n('conf_leds_optgroup_other'))); } $("#leddevices").val(window.serverConfig.device.type); diff --git a/include/utils/RgbToRgbw.h b/include/utils/RgbToRgbw.h index 0bcd6f463..dd6a3eaa8 100644 --- a/include/utils/RgbToRgbw.h +++ b/include/utils/RgbToRgbw.h @@ -11,7 +11,12 @@ namespace RGBW { SUBTRACT_MINIMUM, SUB_MIN_WARM_ADJUST, SUB_MIN_COOL_ADJUST, - WHITE_OFF + WHITE_OFF, + HYPERSERIAL_COLD_WHITE, + HYPERSERIAL_NEUTRAL_WHITE, + WLED_AUTO, + WLED_AUTO_MAX, + WLED_AUTO_ACCURATE }; WhiteAlgorithm stringToWhiteAlgorithm(const QString& str); diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index 233bb9fd2..0f7f245e1 100644 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -19,6 +19,7 @@ include_directories( dev_spi dev_rpi_pwm dev_tinker + dev_ftdi ) FILE ( GLOB Leddevice_SOURCES @@ -64,6 +65,10 @@ if ( ENABLE_DEV_WS281XPWM ) FILE ( GLOB Leddevice_PWM_SOURCES "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.h" "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.cpp") endif() +if (ENABLE_FTDIDEV) + FILE ( GLOB Leddevice_FTDI_SOURCES "${CURRENT_SOURCE_DIR}/dev_ftdi/*.h" "${CURRENT_SOURCE_DIR}/dev_ftdi/*.cpp") +endif() + set(LedDevice_RESOURCES ${CURRENT_SOURCE_DIR}/LedDeviceSchemas.qrc ) SET( Leddevice_SOURCES @@ -75,6 +80,7 @@ SET( Leddevice_SOURCES ${Leddevice_SPI_SOURCES} ${Leddevice_TINKER_SOURCES} ${Leddevice_USB_HID_SOURCES} + ${Leddevice_FTDI_SOURCES} ) # auto generate header file that include all available leddevice headers @@ -164,3 +170,11 @@ if(ENABLE_MDNS) target_link_libraries(leddevice mdns) endif() +if( ENABLE_FTDIDEV ) + FIND_PACKAGE(PkgConfig REQUIRED) + pkg_check_modules(LIB_FTDI REQUIRED libftdi1) + add_library(libftdi1 SHARED IMPORTED) + target_include_directories(leddevice PUBLIC ${LIB_FTDI_INCLUDE_DIRS}) + target_link_libraries(leddevice ${LIB_FTDI_LINK_LIBRARIES}) +endif() + diff --git a/libsrc/leddevice/LedDeviceSchemas.qrc b/libsrc/leddevice/LedDeviceSchemas.qrc index be976000c..d2a93fb55 100644 --- a/libsrc/leddevice/LedDeviceSchemas.qrc +++ b/libsrc/leddevice/LedDeviceSchemas.qrc @@ -38,5 +38,8 @@ schemas/schema-yeelight.json schemas/schema-razer.json schemas/schema-cololight.json + schemas/schema-ws2812_ftdi.json + schemas/schema-apa102_ftdi.json + schemas/schema-sk6812_ftdi.json diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp new file mode 100644 index 000000000..2b0cd94f5 --- /dev/null +++ b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp @@ -0,0 +1,61 @@ +#include "LedDeviceAPA102_ftdi.h" + +#define LED_HEADER 0b11100000 +#define LED_BRIGHTNESS_FULL 31 + +LedDeviceAPA102_ftdi::LedDeviceAPA102_ftdi(const QJsonObject &deviceConfig) : ProviderFtdi(deviceConfig) +{ +} + +LedDevice *LedDeviceAPA102_ftdi::construct(const QJsonObject &deviceConfig) +{ + return new LedDeviceAPA102_ftdi(deviceConfig); +} + +bool LedDeviceAPA102_ftdi::init(const QJsonObject &deviceConfig) +{ + bool isInitOK = false; + + _brightnessControlMaxLevel = deviceConfig["brightnessControlMaxLevel"].toInt(LED_BRIGHTNESS_FULL); + Info(_log, "[%s] Setting maximum brightness to [%d] = %d%%", QSTRING_CSTR(_activeDeviceType), _brightnessControlMaxLevel, _brightnessControlMaxLevel * 100 / LED_BRIGHTNESS_FULL); + + // Initialise sub-class + if (ProviderFtdi::init(deviceConfig)) + { + CreateHeader(); + isInitOK = true; + } + return isInitOK; +} + +void LedDeviceAPA102_ftdi::CreateHeader() +{ + const unsigned int startFrameSize = 4; + // Endframe, add additional 4 bytes to cover SK9922 Reset frame (in case SK9922 were sold as AP102) - has no effect on APA102 + const unsigned int endFrameSize = (_ledCount / 32) * 4 + 4; + const unsigned int APAbufferSize = (_ledCount * 4) + startFrameSize + endFrameSize; + _ledBuffer.resize(APAbufferSize, 0); + Debug(_log, "APA102 buffer created. Led's number: %d", _ledCount); +} + +int LedDeviceAPA102_ftdi::write(const std::vector &ledValues) +{ + if (_ledCount != ledValues.size()) + { + Warning(_log, "APA102 led's number has changed (old: %d, new: %d). Rebuilding buffer.", _ledCount, ledValues.size()); + _ledCount = ledValues.size(); + + CreateHeader(); + } + + for (signed iLed = 0; iLed < static_cast(_ledCount); ++iLed) + { + const ColorRgb &rgb = ledValues[iLed]; + _ledBuffer[4 + iLed * 4 + 0] = LED_HEADER | _brightnessControlMaxLevel; + _ledBuffer[4 + iLed * 4 + 1] = rgb.red; + _ledBuffer[4 + iLed * 4 + 2] = rgb.green; + _ledBuffer[4 + iLed * 4 + 3] = rgb.blue; + } + + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.h b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.h new file mode 100644 index 000000000..699332d73 --- /dev/null +++ b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.h @@ -0,0 +1,50 @@ +#ifndef LEDEVICET_APA102_H +#define LEDEVICET_APA102_H +#include "ProviderFtdi.h" + +class LedDeviceAPA102_ftdi : public ProviderFtdi +{ + Q_OBJECT + +public: + + /// + /// @brief Constructs an APA102 LED-device + /// + /// @param deviceConfig Device's configuration as JSON-Object + /// + explicit LedDeviceAPA102_ftdi(const QJsonObject& deviceConfig); + + /// + /// @brief Constructs the LED-device + /// + /// @param[in] deviceConfig Device's configuration as JSON-Object + /// @return LedDevice constructed + static LedDevice* construct(const QJsonObject& deviceConfig); + +private: + + /// + /// @brief Initialise the device's configuration + /// + /// @param[in] deviceConfig the JSON device configuration + /// @return True, if success + /// + bool init(const QJsonObject& deviceConfig) override; + + void CreateHeader(); + + /// + /// @brief Writes the RGB-Color values to the LEDs. + /// + /// @param[in] ledValues The RGB-color per LED + /// @return Zero on success, else negative + /// + int write(const std::vector& ledValues) override; + + /// The brighness level. Possibile values 1 .. 31. + int _brightnessControlMaxLevel; + +}; + +#endif // LEDEVICET_APA102_H diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp new file mode 100644 index 000000000..b52c0667a --- /dev/null +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp @@ -0,0 +1,93 @@ +#include "LedDeviceSk6812_ftdi.h" + +LedDeviceSk6812_ftdi::LedDeviceSk6812_ftdi(const QJsonObject &deviceConfig) + : ProviderFtdi(deviceConfig), + SPI_BYTES_PER_COLOUR(4), + bitpair_to_byte{ + 0b10001000, + 0b10001100, + 0b11001000, + 0b11001100} +{ +} + +LedDevice *LedDeviceSk6812_ftdi::construct(const QJsonObject &deviceConfig) +{ + return new LedDeviceSk6812_ftdi(deviceConfig); +} + +bool LedDeviceSk6812_ftdi::init(const QJsonObject &deviceConfig) +{ + + bool isInitOK = false; + + // Initialise sub-class + if (ProviderFtdi::init(deviceConfig)) + { + _brightnessControlMaxLevel = deviceConfig["brightnessControlMaxLevel"].toInt(255); + + QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off"); + + _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm); + + Debug(_log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm)); + + WarningIf((_baudRate_Hz < 2050000 || _baudRate_Hz > 4000000), _log, "SPI rate %d outside recommended range (2050000 -> 4000000)", _baudRate_Hz); + + const int SPI_FRAME_END_LATCH_BYTES = 3; + _ledBuffer.resize(_ledRGBWCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); + + isInitOK = true; + } + return isInitOK; +} + + +inline __attribute__((always_inline)) uint8_t LedDeviceSk6812_ftdi::scale(uint8_t i, uint8_t scale) { + return (((uint16_t)i) * (1+(uint16_t)(scale))) >> 8; +} + +int LedDeviceSk6812_ftdi::write(const std::vector &ledValues) +{ + unsigned spi_ptr = 0; + const int SPI_BYTES_PER_LED = sizeof(ColorRgbw) * SPI_BYTES_PER_COLOUR; + + if (_ledCount != ledValues.size()) + { + Warning(_log, "Sk6812SPI led's number has changed (old: %d, new: %d). Rebuilding buffer.", _ledCount, ledValues.size()); + _ledCount = ledValues.size(); + + const int SPI_FRAME_END_LATCH_BYTES = 3; + _ledBuffer.resize(0, 0x00); + _ledBuffer.resize(_ledRGBWCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); + } + ColorRgbw temp_rgbw; + ColorRgb scaled_color; + for (const ColorRgb &color : ledValues) + { + scaled_color.red = scale(color.red, _brightnessControlMaxLevel); + scaled_color.green = scale(color.green, _brightnessControlMaxLevel); + scaled_color.blue = scale(color.blue, _brightnessControlMaxLevel); + + RGBW::Rgb_to_Rgbw(scaled_color, &temp_rgbw, _whiteAlgorithm); + + uint32_t colorBits = + ((uint32_t)temp_rgbw.red << 24) + + ((uint32_t)temp_rgbw.green << 16) + + ((uint32_t)temp_rgbw.blue << 8) + + temp_rgbw.white; + + for (int j = SPI_BYTES_PER_LED - 1; j >= 0; j--) + { + _ledBuffer[spi_ptr + j] = bitpair_to_byte[colorBits & 0x3]; + colorBits >>= 2; + } + spi_ptr += SPI_BYTES_PER_LED; + } + + _ledBuffer[spi_ptr++] = 0; + _ledBuffer[spi_ptr++] = 0; + _ledBuffer[spi_ptr++] = 0; + + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h new file mode 100644 index 000000000..1a1d70b65 --- /dev/null +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h @@ -0,0 +1,56 @@ +#ifndef LEDEVICESK6812ftdi_H +#define LEDEVICESK6812ftdi_H + +// HyperHDR includes +#include "ProviderFtdi.h" + +/// +/// Implementation of the LedDevice interface for writing to Sk6801 LED-device via SPI. +/// +class LedDeviceSk6812_ftdi : public ProviderFtdi +{ +public: + + /// + /// @brief Constructs a Sk6801 LED-device + /// + /// @param deviceConfig Device's configuration as JSON-Object + /// + explicit LedDeviceSk6812_ftdi(const QJsonObject& deviceConfig); + + /// + /// @brief Constructs the LED-device + /// + /// @param[in] deviceConfig Device's configuration as JSON-Object + /// @return LedDevice constructed + static LedDevice* construct(const QJsonObject& deviceConfig); + +private: + + /// + /// @brief Initialise the device's configuration + /// + /// @param[in] deviceConfig the JSON device configuration + /// @return True, if success + /// + bool init(const QJsonObject& deviceConfig) override; + + /// + /// @brief Writes the RGB-Color values to the LEDs. + /// + /// @param[in] ledValues The RGB-color per LED + /// @return Zero on success, else negative + /// + int write(const std::vector& ledValues) override; + + inline __attribute__((always_inline)) uint8_t scale(uint8_t i, uint8_t scale); + + RGBW::WhiteAlgorithm _whiteAlgorithm; + + const int SPI_BYTES_PER_COLOUR; + uint8_t bitpair_to_byte[4]; + + int _brightnessControlMaxLevel; +}; + +#endif // LEDEVICESK6812ftdi_H diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp new file mode 100644 index 000000000..2fe82f1da --- /dev/null +++ b/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp @@ -0,0 +1,102 @@ +#include "LedDeviceWs2812_ftdi.h" + +/* +From the data sheet: + +(TH+TL=1.25μs±600ns) + +T0H, 0 code, high level time, 0.40µs ±0.150ns +T0L, 0 code, low level time, 0.85µs ±0.150ns +T1H, 1 code, high level time, 0.80µs ±0.150ns +T1L, 1 code, low level time, 0.45µs ±0.150ns +WT, Wait for the processing time, NA +Trst, Reset code,low level time, 50µs (not anymore... need 300uS for latest revision) + +To normalise the pulse times so they fit in 4 SPI bits: + +On the assumption that the "low" time doesnt matter much + +A SPI bit time of 0.40uS = 2.5 Mbit/sec +T0 is sent as 1000 +T1 is sent as 1100 + +With a bit of excel testing, we can work out the maximum and minimum speeds: +2106000 MIN +2590500 AVG +3075000 MAX + +Wait time: +Not Applicable for WS2812 + +Reset time: +using the max of 3075000, the bit time is 0.325 +Reset time is 300uS = 923 bits = 116 bytes + +*/ + +LedDeviceWs2812_ftdi::LedDeviceWs2812_ftdi(const QJsonObject &deviceConfig) + : ProviderFtdi(deviceConfig), + SPI_BYTES_PER_COLOUR(4), + SPI_FRAME_END_LATCH_BYTES(116), + bitpair_to_byte{ + 0b10001000, + 0b10001100, + 0b11001000, + 0b11001100, + } +{ +} + +LedDevice *LedDeviceWs2812_ftdi::construct(const QJsonObject &deviceConfig) +{ + return new LedDeviceWs2812_ftdi(deviceConfig); +} + +bool LedDeviceWs2812_ftdi::init(const QJsonObject &deviceConfig) +{ + bool isInitOK = false; + + // Initialise sub-class + if (ProviderFtdi::init(deviceConfig)) + { + WarningIf((_baudRate_Hz < 2106000 || _baudRate_Hz > 3075000), _log, "SPI rate %d outside recommended range (2106000 -> 3075000)", _baudRate_Hz); + _ledBuffer.resize(_ledRGBCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); + isInitOK = true; + } + + return isInitOK; +} + +int LedDeviceWs2812_ftdi::write(const std::vector &ledValues) +{ + unsigned spi_ptr = 0; + const int SPI_BYTES_PER_LED = sizeof(ColorRgb) * SPI_BYTES_PER_COLOUR; + + if (_ledCount != ledValues.size()) + { + Warning(_log, "Led's number has changed (old: %d, new: %d). Rebuilding buffer.", _ledCount, ledValues.size()); + _ledCount = ledValues.size(); + + _ledBuffer.resize(0, 0x00); + _ledBuffer.resize(_ledRGBCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); + } + + for (const ColorRgb &color : ledValues) + { + uint32_t colorBits = ((unsigned int)color.red << 16) | ((unsigned int)color.green << 8) | color.blue; + + for (int j = SPI_BYTES_PER_LED - 1; j >= 0; j--) + { + _ledBuffer[spi_ptr + j] = bitpair_to_byte[colorBits & 0x3]; + colorBits >>= 2; + } + spi_ptr += SPI_BYTES_PER_LED; + } + + for (int j = 0; j < SPI_FRAME_END_LATCH_BYTES; j++) + { + _ledBuffer[spi_ptr++] = 0; + } + + return writeBytes(_ledBuffer.size(), _ledBuffer.data()); +} diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.h b/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.h new file mode 100644 index 000000000..972b935b9 --- /dev/null +++ b/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.h @@ -0,0 +1,49 @@ +#ifndef LEDEVICEWS2812_ftdi_H +#define LEDEVICEWS2812_ftdi_H + +#include "ProviderFtdi.h" + + +class LedDeviceWs2812_ftdi : public ProviderFtdi +{ +public: + + /// + /// @brief Constructs a Ws2812 LED-device + /// + /// @param deviceConfig Device's configuration as JSON-Object + /// + explicit LedDeviceWs2812_ftdi(const QJsonObject& deviceConfig); + + /// + /// @brief Constructs the LED-device + /// + /// @param[in] deviceConfig Device's configuration as JSON-Object + /// @return LedDevice constructed + static LedDevice* construct(const QJsonObject& deviceConfig); + +private: + + /// + /// @brief Initialise the device's configuration + /// + /// @param[in] deviceConfig the JSON device configuration + /// @return True, if success + /// + bool init(const QJsonObject& deviceConfig) override; + + /// + /// @brief Writes the RGB-Color values to the LEDs. + /// + /// @param[in] ledValues The RGB-color per LED + /// @return Zero on success, else negative + /// + int write(const std::vector& ledValues) override; + + const int SPI_BYTES_PER_COLOUR; + const int SPI_FRAME_END_LATCH_BYTES; + + uint8_t bitpair_to_byte[4]; +}; + +#endif // LEDEVICEWS2812_ftdi_H diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp new file mode 100644 index 000000000..509619a66 --- /dev/null +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -0,0 +1,248 @@ +// LedDevice includes +#include +#include "ProviderFtdi.h" + +#include +#include +#include + +#define ANY_FTDI_VENDOR 0x0 +#define ANY_FTDI_PRODUCT 0x0 + +namespace Pin +{ + // enumerate the AD bus for conveniance. + enum bus_t + { + SK = 0x01, // ADBUS0, SPI data clock + DO = 0x02, // ADBUS1, SPI data out + CS = 0x08, // ADBUS3, SPI chip select, active low + L0 = 0x10, // ADBUS4, SPI chip select, active high + }; +} + +// Use these pins as outputs +const unsigned char pinDirection = Pin::SK | Pin::DO | Pin::CS | Pin::L0; + +const QString ProviderFtdi::AUTO_SETTING = QString("auto"); + +ProviderFtdi::ProviderFtdi(const QJsonObject &deviceConfig) + : LedDevice(deviceConfig), + _ftdic(NULL), + _baudRate_Hz(1000000) +{ +} + +bool ProviderFtdi::init(const QJsonObject &deviceConfig) +{ + bool isInitOK = false; + + if (LedDevice::init(deviceConfig)) + { + _baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz); + _deviceName = deviceConfig["output"].toString(AUTO_SETTING); + + Debug(_log, "_baudRate_Hz [%d]", _baudRate_Hz); + Debug(_log, "_deviceName [%s]", QSTRING_CSTR(_deviceName)); + + isInitOK = true; + } + return isInitOK; +} + +int ProviderFtdi::openDevice() +{ + _ftdic = ftdi_new(); + + bool autoDiscovery = (QString::compare(_deviceName, ProviderFtdi::AUTO_SETTING, Qt::CaseInsensitive) == 0); + Debug(_log, "Opening FTDI device=%s autoDiscovery=%s", QSTRING_CSTR(_deviceName), autoDiscovery ? "true" : "false"); + if (autoDiscovery) + { + struct ftdi_device_list *devlist; + int devicesDetected = 0; + if ((devicesDetected = ftdi_usb_find_all(_ftdic, &devlist, ANY_FTDI_VENDOR, ANY_FTDI_PRODUCT)) < 0) + { + setInError(ftdi_get_error_string(_ftdic)); + return -1; + } + if (devicesDetected == 0) + { + setInError("No ftdi devices detected"); + return 0; + } + + if (ftdi_usb_open_dev(_ftdic, devlist[0].dev) < 0) + { + setInError(ftdi_get_error_string(_ftdic)); + ftdi_list_free(&devlist); + return -1; + } + + ftdi_list_free(&devlist); + return 1; + } + else + { + if (ftdi_usb_open_string(_ftdic, QSTRING_CSTR(_deviceName)) < 0) + { + setInError(ftdi_get_error_string(_ftdic)); + return -1; + } + return 1; + } +} +int ProviderFtdi::open() +{ + int rc = 0; + + if ((rc = openDevice()) != 1) + { + return -1; + } + + /* doing this disable resets things if they were in a bad state */ + if ((rc = ftdi_disable_bitbang(_ftdic)) < 0) + { + setInError(ftdi_get_error_string(_ftdic)); + return rc; + } + if ((rc = ftdi_setflowctrl(_ftdic, SIO_DISABLE_FLOW_CTRL)) < 0) + { + setInError(ftdi_get_error_string(_ftdic)); + return rc; + } + if ((rc = ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET)) < 0) + { + setInError(ftdi_get_error_string(_ftdic)); + return rc; + } + + if ((rc = ftdi_set_bitmode(_ftdic, 0xff, BITMODE_MPSSE)) < 0) + { + setInError(ftdi_get_error_string(_ftdic)); + return rc; + } + + double reference_clock = 60e6; + int divisor = (reference_clock / 2 / _baudRate_Hz) - 1; + uint8_t buf[10] = {0}; + unsigned int icmd = 0; + buf[icmd++] = DIS_DIV_5; + buf[icmd++] = TCK_DIVISOR; + buf[icmd++] = divisor; + buf[icmd++] = divisor >> 8; + buf[icmd++] = SET_BITS_LOW; // opcode: set low bits (ADBUS[0-7]) + buf[icmd++] = Pin::CS & ~Pin::L0; // argument: inital pin states + buf[icmd++] = pinDirection; + if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) + { + setInError(ftdi_get_error_string(_ftdic)); + return rc; + } + + _isDeviceReady = true; + return rc; +} + +int ProviderFtdi::close() +{ + // allow to clock out remaining data from powerOff()->writeBlack() + if (_ftdic != NULL) + { + std::this_thread::sleep_for(std::chrono::milliseconds(15)); + Debug(_log, "Closing FTDI device"); + ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); + ftdi_usb_close(_ftdic); + _ftdic = NULL; + } + return LedDevice::close(); +} + +void ProviderFtdi::setInError(const QString &errorMsg, bool isRecoverable) +{ + close(); + + LedDevice::setInError(errorMsg); +} + +int ProviderFtdi::writeBytes(const qint64 size, const uint8_t *data) +{ + uint8_t buf[10] = {0}; + unsigned int icmd = 0; + int rc = 0; + + int count_arg = size - 1; + buf[icmd++] = SET_BITS_LOW; + buf[icmd++] = Pin::L0 & ~Pin::CS; + buf[icmd++] = pinDirection; + buf[icmd++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG; + buf[icmd++] = count_arg; + buf[icmd++] = count_arg >> 8; + + if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) + { + setInError(ftdi_get_error_string(_ftdic)); + return rc; + } + if ((rc = ftdi_write_data(_ftdic, data, size)) != size) + { + setInError(ftdi_get_error_string(_ftdic)); + return rc; + } + icmd = 0; + buf[icmd++] = SET_BITS_LOW; + buf[icmd++] = Pin::CS & ~Pin::L0; + buf[icmd++] = pinDirection; + if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) + { + setInError(ftdi_get_error_string(_ftdic)); + return rc; + } + return rc; +} + +QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) +{ + QJsonObject devicesDiscovered; + QJsonArray deviceList; + struct ftdi_device_list *devlist; + struct ftdi_context *ftdic; + + QJsonObject autoDevice = QJsonObject{{"value", AUTO_SETTING}, {"name", "Auto"}}; + deviceList.push_back(autoDevice); + + ftdic = ftdi_new(); + + if (ftdi_usb_find_all(ftdic, &devlist, ANY_FTDI_VENDOR, ANY_FTDI_PRODUCT) > 0) + { + struct ftdi_device_list *curdev = devlist; + while (curdev) + { + char manufacturer[128], description[128]; + ftdi_usb_get_strings(ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0); + + libusb_device_descriptor desc; + libusb_get_device_descriptor(curdev->dev, &desc); + QString value = QString("i:0x%1:0x%2") + .arg(desc.idVendor, 4, 16, QChar{'0'}) + .arg(desc.idProduct, 4, 16, QChar{'0'}); + + QString name = QString("%1 (%2)").arg(manufacturer, description); + deviceList.push_back(QJsonObject{ + {"value", value}, + {"name", name}}); + + curdev = curdev->next; + } + } + + ftdi_list_free(&devlist); + ftdi_free(ftdic); + + devicesDiscovered.insert("ledDeviceType", _activeDeviceType); + devicesDiscovered.insert("devices", deviceList); + + Debug(_log, "FTDI devices discovered: [%s]", QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData()); + + return devicesDiscovered; +} \ No newline at end of file diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.h b/libsrc/leddevice/dev_ftdi/ProviderFtdi.h new file mode 100644 index 000000000..afaba68f4 --- /dev/null +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.h @@ -0,0 +1,79 @@ +#ifndef PROVIDERFtdi_H +#define PROVIDERFtdi_H + +// LedDevice includes +#include + +#include + +/// +/// The ProviderFtdi implements an abstract base-class for LedDevices using a Ftdi-device. +/// +class ProviderFtdi : public LedDevice +{ + Q_OBJECT + +public: + + /// + /// @brief Constructs a Ftdi LED-device + /// + ProviderFtdi(const QJsonObject& deviceConfig); + + static const QString AUTO_SETTING; + +protected: + /// + /// @brief Opens the output device. + /// + /// @return Zero on success (i.e. device is ready), else negative + /// + int open() override; + + /// + /// Sets configuration + /// + /// @param deviceConfig the json device config + /// @return true if success + bool init(const QJsonObject& deviceConfig) override; + + /// + /// @brief Closes the UDP device. + /// + /// @return Zero on success (i.e. device is closed), else negative + /// + int close() override; + + + /// @brief Write the given bytes to the Ftdi-device + /// + /// @param[in[ size The length of the data + /// @param[in] data The data + /// @return Zero on success, else negative + /// + int writeBytes(const qint64 size, const uint8_t* data); + + + QJsonObject discover(const QJsonObject& params) override; + + /// The Ftdi serial-device + struct ftdi_context *_ftdic; + + /// The used baud-rate of the output device + qint32 _baudRate_Hz; + QString _deviceName; + +protected slots: + + /// + /// @brief Set device in error state + /// + /// @param errorMsg The error message to be logged + /// + void setInError(const QString& errorMsg, bool isRecoverable=true) override; + +private: + int openDevice(); +}; + +#endif // PROVIDERFtdi_H diff --git a/libsrc/leddevice/schemas/schema-apa102_ftdi.json b/libsrc/leddevice/schemas/schema-apa102_ftdi.json new file mode 100644 index 000000000..69fd380c1 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-apa102_ftdi.json @@ -0,0 +1,25 @@ +{ + "type": "object", + "required": true, + "properties": { + "output": { + "type": "string", + "title":"edt_dev_spec_outputPath_title", + "default":"auto" + }, + "rate": { + "type": "integer", + "title": "edt_dev_spec_baudrate_title", + "default": 5000000 + }, + "brightnessControlMaxLevel": { + "type": "integer", + "title": "edt_conf_color_brightness_title", + "default": 31, + "minimum": 1, + "maximum": 31 + + } + }, + "additionalProperties": true +} \ No newline at end of file diff --git a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json new file mode 100644 index 000000000..526f440c0 --- /dev/null +++ b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json @@ -0,0 +1,60 @@ +{ + "type": "object", + "required": true, + "properties": { + "output": { + "type": "string", + "title": "edt_dev_spec_outputPath_title", + "default": "auto", + "required": true, + "propertyOrder": 1 + }, + "rate": { + "type": "integer", + "format": "stepper", + "step": 100000, + "title": "edt_dev_spec_baudrate_title", + "default": 3200000, + "propertyOrder": 2 + }, + "brightnessControlMaxLevel": { + "type": "integer", + "title": "edt_conf_color_brightness_title", + "default": 255, + "minimum": 1, + "maximum": 255, + "propertyOrder": 3 + }, + "whiteAlgorithm": { + "type": "string", + "title": "edt_dev_spec_whiteLedAlgor_title", + "enum": [ + "subtract_minimum", + "sub_min_cool_adjust", + "sub_min_warm_adjust", + "hyperserial_cold_white", + "hyperserial_neutral_white", + "wled_auto", + "wled_auto_max", + "wled_auto_accurate", + "white_off" + ], + "default": "white_off", + "options": { + "enum_titles": [ + "edt_dev_enum_subtract_minimum", + "edt_dev_enum_sub_min_cool_adjust", + "edt_dev_enum_sub_min_warm_adjust", + "edt_dev_enum_hyperserial_cold_white", + "edt_dev_enum_hyperserial_neutral_white", + "edt_dev_enum_wled_auto", + "edt_dev_enum_wled_auto_max", + "edt_dev_enum_wled_auto_accurate", + "edt_dev_enum_white_off" + ] + }, + "propertyOrder": 5 + } + }, + "additionalProperties": true +} \ No newline at end of file diff --git a/libsrc/leddevice/schemas/schema-ws2812_ftdi.json b/libsrc/leddevice/schemas/schema-ws2812_ftdi.json new file mode 100644 index 000000000..f8c9e04ec --- /dev/null +++ b/libsrc/leddevice/schemas/schema-ws2812_ftdi.json @@ -0,0 +1,19 @@ +{ + "type": "object", + "required": true, + "properties": { + "output": { + "type": "string", + "title": "edt_dev_spec_outputPath_title", + "default": "auto" + }, + "rate": { + "type": "integer", + "title": "edt_dev_spec_baudrate_title", + "default": 3075000, + "minimum": 2106000, + "maximum": 3075000 + } + }, + "additionalProperties": true +} \ No newline at end of file diff --git a/libsrc/utils/RgbToRgbw.cpp b/libsrc/utils/RgbToRgbw.cpp index f82fadf58..84a1cedc9 100644 --- a/libsrc/utils/RgbToRgbw.cpp +++ b/libsrc/utils/RgbToRgbw.cpp @@ -3,6 +3,8 @@ #include #include +#define ROUND_DIVIDE(number, denom) (((number) + (denom) / 2) / (denom)) + namespace RGBW { WhiteAlgorithm stringToWhiteAlgorithm(const QString& str) @@ -19,7 +21,30 @@ WhiteAlgorithm stringToWhiteAlgorithm(const QString& str) { return WhiteAlgorithm::SUB_MIN_COOL_ADJUST; } - if (str.isEmpty() || str == "white_off") + if (str == "hyperserial_cold_white") + { + return WhiteAlgorithm::HYPERSERIAL_COLD_WHITE; + } + if (str == "hyperserial_neutral_white") + { + return WhiteAlgorithm::HYPERSERIAL_NEUTRAL_WHITE; + } + if (str == "wled_auto") + { + return WhiteAlgorithm::WLED_AUTO; + } + + if (str == "wled_auto_max") + { + return WhiteAlgorithm::WLED_AUTO_MAX; + } + + if (str == "wled_auto_accurate") + { + return WhiteAlgorithm::WLED_AUTO_ACCURATE; + } + + if (str.isEmpty() || str == "white_off") { return WhiteAlgorithm::WHITE_OFF; } @@ -77,6 +102,63 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, WhiteAlgorithm algorithm) output->white = 0; break; } + + case WhiteAlgorithm::WLED_AUTO_MAX: + { + output->red = input.red; + output->green = input.green; + output->blue = input.blue; + output->white = input.red > input.green ? (input.red > input.blue ? input.red : input.blue) : (input.green > input.blue ? input.green : input.blue); + break; + } + + case WhiteAlgorithm::WLED_AUTO_ACCURATE: + { + output->white = input.red < input.green ? (input.red < input.blue ? input.red : input.blue) : (input.green < input.blue ? input.green : input.blue); + output->red = input.red - output->white; + output->green = input.green - output->white; + output->blue = input.blue - output->white; + break; + } + + case WhiteAlgorithm::WLED_AUTO: + { + + output->red = input.red; + output->green = input.green; + output->blue = input.blue; + output->white = input.red < input.green ? (input.red < input.blue ? input.red : input.blue) : (input.green < input.blue ? input.green : input.blue); + break; + } + case WhiteAlgorithm::HYPERSERIAL_NEUTRAL_WHITE: + case WhiteAlgorithm::HYPERSERIAL_COLD_WHITE: + { + //cold white config + uint8_t gain = 0xFF; + uint8_t red = 0xA0; + uint8_t green = 0xA0; + uint8_t blue = 0xA0; + + if (algorithm == WhiteAlgorithm::HYPERSERIAL_NEUTRAL_WHITE) { + gain = 0xFF; + red = 0xB0; + green = 0xB0; + blue = 0x70; + } + + uint8_t _r = qMin((uint32_t)(ROUND_DIVIDE(red * input.red, 0xFF)), (uint32_t)0xFF); + uint8_t _g = qMin((uint32_t)(ROUND_DIVIDE(green * input.green, 0xFF)), (uint32_t)0xFF); + uint8_t _b = qMin((uint32_t)(ROUND_DIVIDE(blue * input.blue, 0xFF)), (uint32_t)0xFF); + + output->white = qMin(_r, qMin(_g, _b)); + output->red = input.red - _r; + output->green = input.green - _g; + output->blue = input.blue - _b; + + uint8_t _w = qMin((uint32_t)(ROUND_DIVIDE(gain * output->white, 0xFF)), (uint32_t)0xFF); + output->white = _w; + break; + } default: break; } From f4100f0cfe8f0f1fccda6c34017c82374629841d Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 12:54:37 +0000 Subject: [PATCH 02/48] Update CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9b5efff2..da0df3eaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ SET ( DEFAULT_DEV_SPI OFF ) SET ( DEFAULT_DEV_TINKERFORGE OFF ) SET ( DEFAULT_DEV_USB_HID OFF ) SET ( DEFAULT_DEV_WS281XPWM OFF ) -SET ( DEFAULT_ENABLE_FTDIDEV OFF ) +SET ( DEFAULT_ENABLE_FTDIDEV ON ) # Services SET ( DEFAULT_EFFECTENGINE ON ) From 99a26166aeef8c186c77cfbdd730553155f5bd4f Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 14:44:06 +0000 Subject: [PATCH 03/48] Add build option --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index da0df3eaa..14ebb94c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,6 +342,9 @@ message(STATUS "ENABLE_DEV_USB_HID = ${ENABLE_DEV_USB_HID}") option(ENABLE_DEV_WS281XPWM "Enable the WS281x-PWM device" ${DEFAULT_DEV_WS281XPWM} ) message(STATUS "ENABLE_DEV_WS281XPWM = ${ENABLE_DEV_WS281XPWM}") +option(ENABLE_FTDIDEV "Enable the FTDI led device" ${DEFAULT_ENABLE_FTDIDEV} ) +message(STATUS "ENABLE_FTDIDEV = ${ENABLE_FTDIDEV}") + removeIndent() message(STATUS "Services options:") From 7e5b87bbdce6039ae10ce8191b5cebc1a75ec575 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 14:44:25 +0000 Subject: [PATCH 04/48] Add ftdilib mac os dependency --- .ci/ci_install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/ci_install.sh b/.ci/ci_install.sh index 86c6ffd4b..69e34dd8e 100755 --- a/.ci/ci_install.sh +++ b/.ci/ci_install.sh @@ -35,6 +35,6 @@ function installAndUpgrade() if [[ $CI_NAME == 'osx' || $CI_NAME == 'darwin' ]]; then echo "Install dependencies" brew update - dependencies=("qt5" "python" "libusb" "cmake" "doxygen") + dependencies=("qt5" "python" "libusb" "cmake" "doxygen", "libftdi") installAndUpgrade "${dependencies[@]}" fi From 18b7df52e9fb521fc021cc0d47a5df0c27fe2d52 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 15:26:34 +0000 Subject: [PATCH 05/48] Statically link libftdi1 --- libsrc/leddevice/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index 0f7f245e1..b185bf7e1 100644 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -173,7 +173,7 @@ endif() if( ENABLE_FTDIDEV ) FIND_PACKAGE(PkgConfig REQUIRED) pkg_check_modules(LIB_FTDI REQUIRED libftdi1) - add_library(libftdi1 SHARED IMPORTED) + add_library(libftdi1 STATIC IMPORTED) target_include_directories(leddevice PUBLIC ${LIB_FTDI_INCLUDE_DIRS}) target_link_libraries(leddevice ${LIB_FTDI_LINK_LIBRARIES}) endif() From 29cab3938256cbc85a5f0db917e6a79cfeca54d9 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:25:16 +0000 Subject: [PATCH 06/48] Rename flag --- CMakeLists.txt | 6 +++--- libsrc/leddevice/CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14ebb94c1..30245b90c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ SET ( DEFAULT_DEV_SPI OFF ) SET ( DEFAULT_DEV_TINKERFORGE OFF ) SET ( DEFAULT_DEV_USB_HID OFF ) SET ( DEFAULT_DEV_WS281XPWM OFF ) -SET ( DEFAULT_ENABLE_FTDIDEV ON ) +SET ( DEFAULT_DEV_FTDI ON ) # Services SET ( DEFAULT_EFFECTENGINE ON ) @@ -342,8 +342,8 @@ message(STATUS "ENABLE_DEV_USB_HID = ${ENABLE_DEV_USB_HID}") option(ENABLE_DEV_WS281XPWM "Enable the WS281x-PWM device" ${DEFAULT_DEV_WS281XPWM} ) message(STATUS "ENABLE_DEV_WS281XPWM = ${ENABLE_DEV_WS281XPWM}") -option(ENABLE_FTDIDEV "Enable the FTDI led device" ${DEFAULT_ENABLE_FTDIDEV} ) -message(STATUS "ENABLE_FTDIDEV = ${ENABLE_FTDIDEV}") +option(ENABLE_DEV_FTDI "Enable the FTDI devices" ${DEFAULT_DEV_FTDI} ) +message(STATUS "ENABLE_DEV_FTDI = ${ENABLE_DEV_FTDI}") removeIndent() diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index b185bf7e1..e6f47c820 100644 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -65,7 +65,7 @@ if ( ENABLE_DEV_WS281XPWM ) FILE ( GLOB Leddevice_PWM_SOURCES "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.h" "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.cpp") endif() -if (ENABLE_FTDIDEV) +if (DEFAULT_DEV_FTDI) FILE ( GLOB Leddevice_FTDI_SOURCES "${CURRENT_SOURCE_DIR}/dev_ftdi/*.h" "${CURRENT_SOURCE_DIR}/dev_ftdi/*.cpp") endif() @@ -170,7 +170,7 @@ if(ENABLE_MDNS) target_link_libraries(leddevice mdns) endif() -if( ENABLE_FTDIDEV ) +if( DEFAULT_DEV_FTDI ) FIND_PACKAGE(PkgConfig REQUIRED) pkg_check_modules(LIB_FTDI REQUIRED libftdi1) add_library(libftdi1 STATIC IMPORTED) From f359c1786c443bafe83e309866b6cbd417646c13 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:25:56 +0000 Subject: [PATCH 07/48] Refactor condition --- assets/webconfig/js/content_leds.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index 02ebefc60..25dde3407 100755 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -1648,7 +1648,6 @@ $(document).ready(function () { optArr[6] = []; for (var idx = 0; idx < ledDevices.length; idx++) { - var isFtdi = ledDevices[idx].endsWith("_ftdi"); if ($.inArray(ledDevices[idx], devRPiSPI) != -1) optArr[0].push(ledDevices[idx]); else if ($.inArray(ledDevices[idx], devRPiPWM) != -1) @@ -1661,7 +1660,7 @@ $(document).ready(function () { optArr[4].push(ledDevices[idx]); else if ($.inArray(ledDevices[idx], devHID) != -1) optArr[4].push(ledDevices[idx]); - else if (isFtdi) + else if (ledDevices[idx].endsWith("_ftdi")) optArr[5].push(ledDevices[idx]); else optArr[6].push(ledDevices[idx]); From 24e5c6109c9ab6e7f2f4c1665f44899660727fa9 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:28:24 +0000 Subject: [PATCH 08/48] Remove comment --- libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h index 1a1d70b65..4536e23f9 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h @@ -1,7 +1,6 @@ #ifndef LEDEVICESK6812ftdi_H #define LEDEVICESK6812ftdi_H -// HyperHDR includes #include "ProviderFtdi.h" /// From 93a0c60edb09eef20ad8e7df2d4e4929bd495c34 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:32:24 +0000 Subject: [PATCH 09/48] Remove algo source --- assets/webconfig/i18n/en.json | 10 +++--- include/utils/RgbToRgbw.h | 10 +++--- .../leddevice/schemas/schema-sk6812_ftdi.json | 10 +++--- libsrc/utils/RgbToRgbw.cpp | 35 +++++++++---------- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index 986af06c8..c923ad5e2 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -568,11 +568,11 @@ "edt_dev_enum_sub_min_cool_adjust": "Subtract cool white", "edt_dev_enum_sub_min_warm_adjust": "Subtract warm white", "edt_dev_enum_subtract_minimum": "Subtract minimum", - "edt_dev_enum_hyperserial_cold_white": "Hyperserial, cold white", - "edt_dev_enum_hyperserial_neutral_white": "Hyperserial, neutral white", - "edt_dev_enum_wled_auto": "Wled auto", - "edt_dev_enum_wled_auto_max": "Wled auto max", - "edt_dev_enum_wled_auto_accurate": "Wled auto accurate", + "edt_dev_enum_cold_white": "Cold white", + "edt_dev_enum_neutral_white": "Neutral white", + "edt_dev_enum_auto": "Auto", + "edt_dev_enum_auto_max": "Auto max", + "edt_dev_enum_auto_accurate": "Auto accurate", "edt_dev_enum_white_off": "White off", "edt_dev_general_autostart_title": "Autostart", "edt_dev_general_autostart_title_info": "The LED device is switched-on during startup or not", diff --git a/include/utils/RgbToRgbw.h b/include/utils/RgbToRgbw.h index dd6a3eaa8..4fb4e34b0 100644 --- a/include/utils/RgbToRgbw.h +++ b/include/utils/RgbToRgbw.h @@ -12,11 +12,11 @@ namespace RGBW { SUB_MIN_WARM_ADJUST, SUB_MIN_COOL_ADJUST, WHITE_OFF, - HYPERSERIAL_COLD_WHITE, - HYPERSERIAL_NEUTRAL_WHITE, - WLED_AUTO, - WLED_AUTO_MAX, - WLED_AUTO_ACCURATE + COLD_WHITE, + NEUTRAL_WHITE, + AUTO, + AUTO_MAX, + AUTO_ACCURATE }; WhiteAlgorithm stringToWhiteAlgorithm(const QString& str); diff --git a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json index 526f440c0..56df8b340 100644 --- a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json +++ b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json @@ -45,11 +45,11 @@ "edt_dev_enum_subtract_minimum", "edt_dev_enum_sub_min_cool_adjust", "edt_dev_enum_sub_min_warm_adjust", - "edt_dev_enum_hyperserial_cold_white", - "edt_dev_enum_hyperserial_neutral_white", - "edt_dev_enum_wled_auto", - "edt_dev_enum_wled_auto_max", - "edt_dev_enum_wled_auto_accurate", + "edt_dev_enum_cold_white", + "edt_dev_enum_neutral_white", + "edt_dev_enum_auto", + "edt_dev_enum_auto_max", + "edt_dev_enum_auto_accurate", "edt_dev_enum_white_off" ] }, diff --git a/libsrc/utils/RgbToRgbw.cpp b/libsrc/utils/RgbToRgbw.cpp index 84a1cedc9..7e96a1b6f 100644 --- a/libsrc/utils/RgbToRgbw.cpp +++ b/libsrc/utils/RgbToRgbw.cpp @@ -21,29 +21,26 @@ WhiteAlgorithm stringToWhiteAlgorithm(const QString& str) { return WhiteAlgorithm::SUB_MIN_COOL_ADJUST; } - if (str == "hyperserial_cold_white") + if (str == "cold_white") { - return WhiteAlgorithm::HYPERSERIAL_COLD_WHITE; + return WhiteAlgorithm::COLD_WHITE; } - if (str == "hyperserial_neutral_white") + if (str == "neutral_white") { - return WhiteAlgorithm::HYPERSERIAL_NEUTRAL_WHITE; + return WhiteAlgorithm::NEUTRAL_WHITE; } - if (str == "wled_auto") + if (str == "auto") { - return WhiteAlgorithm::WLED_AUTO; + return WhiteAlgorithm::AUTO; } - - if (str == "wled_auto_max") + if (str == "auto_max") { - return WhiteAlgorithm::WLED_AUTO_MAX; + return WhiteAlgorithm::AUTO_MAX; } - - if (str == "wled_auto_accurate") + if (str == "auto_accurate") { - return WhiteAlgorithm::WLED_AUTO_ACCURATE; + return WhiteAlgorithm::AUTO_ACCURATE; } - if (str.isEmpty() || str == "white_off") { return WhiteAlgorithm::WHITE_OFF; @@ -103,7 +100,7 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, WhiteAlgorithm algorithm) break; } - case WhiteAlgorithm::WLED_AUTO_MAX: + case WhiteAlgorithm::AUTO_MAX: { output->red = input.red; output->green = input.green; @@ -112,7 +109,7 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, WhiteAlgorithm algorithm) break; } - case WhiteAlgorithm::WLED_AUTO_ACCURATE: + case WhiteAlgorithm::AUTO_ACCURATE: { output->white = input.red < input.green ? (input.red < input.blue ? input.red : input.blue) : (input.green < input.blue ? input.green : input.blue); output->red = input.red - output->white; @@ -121,7 +118,7 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, WhiteAlgorithm algorithm) break; } - case WhiteAlgorithm::WLED_AUTO: + case WhiteAlgorithm::AUTO: { output->red = input.red; @@ -130,8 +127,8 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, WhiteAlgorithm algorithm) output->white = input.red < input.green ? (input.red < input.blue ? input.red : input.blue) : (input.green < input.blue ? input.green : input.blue); break; } - case WhiteAlgorithm::HYPERSERIAL_NEUTRAL_WHITE: - case WhiteAlgorithm::HYPERSERIAL_COLD_WHITE: + case WhiteAlgorithm::NEUTRAL_WHITE: + case WhiteAlgorithm::COLD_WHITE: { //cold white config uint8_t gain = 0xFF; @@ -139,7 +136,7 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, WhiteAlgorithm algorithm) uint8_t green = 0xA0; uint8_t blue = 0xA0; - if (algorithm == WhiteAlgorithm::HYPERSERIAL_NEUTRAL_WHITE) { + if (algorithm == WhiteAlgorithm::NEUTRAL_WHITE) { gain = 0xFF; red = 0xB0; green = 0xB0; From 20bd8edb5fddccd0521588e0c74489d7a47e56e2 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:35:35 +0000 Subject: [PATCH 10/48] Refactor schemas --- libsrc/leddevice/schemas/schema-apa102_ftdi.json | 8 +++++--- libsrc/leddevice/schemas/schema-sk6812_ftdi.json | 13 ++++++------- libsrc/leddevice/schemas/schema-ws2812_ftdi.json | 5 +++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/libsrc/leddevice/schemas/schema-apa102_ftdi.json b/libsrc/leddevice/schemas/schema-apa102_ftdi.json index 69fd380c1..35ace3d01 100644 --- a/libsrc/leddevice/schemas/schema-apa102_ftdi.json +++ b/libsrc/leddevice/schemas/schema-apa102_ftdi.json @@ -5,19 +5,21 @@ "output": { "type": "string", "title":"edt_dev_spec_outputPath_title", - "default":"auto" + "propertyOrder": 1 }, "rate": { "type": "integer", "title": "edt_dev_spec_baudrate_title", - "default": 5000000 + "default": 5000000, + "propertyOrder": 2 }, "brightnessControlMaxLevel": { "type": "integer", "title": "edt_conf_color_brightness_title", "default": 31, "minimum": 1, - "maximum": 31 + "maximum": 31, + "propertyOrder": 3 } }, diff --git a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json index 56df8b340..5bdd07011 100644 --- a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json +++ b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json @@ -5,7 +5,6 @@ "output": { "type": "string", "title": "edt_dev_spec_outputPath_title", - "default": "auto", "required": true, "propertyOrder": 1 }, @@ -32,11 +31,11 @@ "subtract_minimum", "sub_min_cool_adjust", "sub_min_warm_adjust", - "hyperserial_cold_white", - "hyperserial_neutral_white", - "wled_auto", - "wled_auto_max", - "wled_auto_accurate", + "cold_white", + "neutral_white", + "auto", + "auto_max", + "auto_accurate", "white_off" ], "default": "white_off", @@ -53,7 +52,7 @@ "edt_dev_enum_white_off" ] }, - "propertyOrder": 5 + "propertyOrder": 4 } }, "additionalProperties": true diff --git a/libsrc/leddevice/schemas/schema-ws2812_ftdi.json b/libsrc/leddevice/schemas/schema-ws2812_ftdi.json index f8c9e04ec..c6e7a5753 100644 --- a/libsrc/leddevice/schemas/schema-ws2812_ftdi.json +++ b/libsrc/leddevice/schemas/schema-ws2812_ftdi.json @@ -5,14 +5,15 @@ "output": { "type": "string", "title": "edt_dev_spec_outputPath_title", - "default": "auto" + "propertyOrder": 1 }, "rate": { "type": "integer", "title": "edt_dev_spec_baudrate_title", "default": 3075000, "minimum": 2106000, - "maximum": 3075000 + "maximum": 3075000, + "propertyOrder": 2 } }, "additionalProperties": true From e6f6954f1a0aa04b7e43c103ba8498f33a6abb6e Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:36:35 +0000 Subject: [PATCH 11/48] Remove redundant validation --- libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp | 8 -------- libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp | 9 --------- libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp | 9 --------- 3 files changed, 26 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp index 2b0cd94f5..69a6165c8 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp @@ -40,14 +40,6 @@ void LedDeviceAPA102_ftdi::CreateHeader() int LedDeviceAPA102_ftdi::write(const std::vector &ledValues) { - if (_ledCount != ledValues.size()) - { - Warning(_log, "APA102 led's number has changed (old: %d, new: %d). Rebuilding buffer.", _ledCount, ledValues.size()); - _ledCount = ledValues.size(); - - CreateHeader(); - } - for (signed iLed = 0; iLed < static_cast(_ledCount); ++iLed) { const ColorRgb &rgb = ledValues[iLed]; diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp index b52c0667a..1a81e169c 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp @@ -52,15 +52,6 @@ int LedDeviceSk6812_ftdi::write(const std::vector &ledValues) unsigned spi_ptr = 0; const int SPI_BYTES_PER_LED = sizeof(ColorRgbw) * SPI_BYTES_PER_COLOUR; - if (_ledCount != ledValues.size()) - { - Warning(_log, "Sk6812SPI led's number has changed (old: %d, new: %d). Rebuilding buffer.", _ledCount, ledValues.size()); - _ledCount = ledValues.size(); - - const int SPI_FRAME_END_LATCH_BYTES = 3; - _ledBuffer.resize(0, 0x00); - _ledBuffer.resize(_ledRGBWCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); - } ColorRgbw temp_rgbw; ColorRgb scaled_color; for (const ColorRgb &color : ledValues) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp index 2fe82f1da..d2a7f8507 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp @@ -72,15 +72,6 @@ int LedDeviceWs2812_ftdi::write(const std::vector &ledValues) unsigned spi_ptr = 0; const int SPI_BYTES_PER_LED = sizeof(ColorRgb) * SPI_BYTES_PER_COLOUR; - if (_ledCount != ledValues.size()) - { - Warning(_log, "Led's number has changed (old: %d, new: %d). Rebuilding buffer.", _ledCount, ledValues.size()); - _ledCount = ledValues.size(); - - _ledBuffer.resize(0, 0x00); - _ledBuffer.resize(_ledRGBCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); - } - for (const ColorRgb &color : ledValues) { uint32_t colorBits = ((unsigned int)color.red << 16) | ((unsigned int)color.green << 8) | color.blue; From d5dc60db31be05e21f9004b12f47a2fcb5a955bd Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:38:24 +0000 Subject: [PATCH 12/48] Remove auto discovery --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 47 ++++------------------ 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 509619a66..6826e04e7 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -54,42 +54,14 @@ int ProviderFtdi::openDevice() { _ftdic = ftdi_new(); - bool autoDiscovery = (QString::compare(_deviceName, ProviderFtdi::AUTO_SETTING, Qt::CaseInsensitive) == 0); - Debug(_log, "Opening FTDI device=%s autoDiscovery=%s", QSTRING_CSTR(_deviceName), autoDiscovery ? "true" : "false"); - if (autoDiscovery) - { - struct ftdi_device_list *devlist; - int devicesDetected = 0; - if ((devicesDetected = ftdi_usb_find_all(_ftdic, &devlist, ANY_FTDI_VENDOR, ANY_FTDI_PRODUCT)) < 0) - { - setInError(ftdi_get_error_string(_ftdic)); - return -1; - } - if (devicesDetected == 0) - { - setInError("No ftdi devices detected"); - return 0; - } - - if (ftdi_usb_open_dev(_ftdic, devlist[0].dev) < 0) - { - setInError(ftdi_get_error_string(_ftdic)); - ftdi_list_free(&devlist); - return -1; - } - - ftdi_list_free(&devlist); - return 1; - } - else - { - if (ftdi_usb_open_string(_ftdic, QSTRING_CSTR(_deviceName)) < 0) - { - setInError(ftdi_get_error_string(_ftdic)); - return -1; - } - return 1; - } + Debug(_log, "Opening FTDI device=%s", QSTRING_CSTR(_deviceName)); + + if (ftdi_usb_open_string(_ftdic, QSTRING_CSTR(_deviceName)) < 0) + { + setInError(ftdi_get_error_string(_ftdic)); + return -1; + } + return 1; } int ProviderFtdi::open() { @@ -208,9 +180,6 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) struct ftdi_device_list *devlist; struct ftdi_context *ftdic; - QJsonObject autoDevice = QJsonObject{{"value", AUTO_SETTING}, {"name", "Auto"}}; - deviceList.push_back(autoDevice); - ftdic = ftdi_new(); if (ftdi_usb_find_all(ftdic, &devlist, ANY_FTDI_VENDOR, ANY_FTDI_PRODUCT) > 0) From f7c6c13f2a2ab9dae800107eb754c1aa5245f8c2 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:41:26 +0000 Subject: [PATCH 13/48] Typo --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 6826e04e7..a8a80b738 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -104,7 +104,7 @@ int ProviderFtdi::open() buf[icmd++] = divisor; buf[icmd++] = divisor >> 8; buf[icmd++] = SET_BITS_LOW; // opcode: set low bits (ADBUS[0-7]) - buf[icmd++] = Pin::CS & ~Pin::L0; // argument: inital pin states + buf[icmd++] = Pin::CS & ~Pin::L0; // argument: initial pin states buf[icmd++] = pinDirection; if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) { From 040b45d7ea10bb2ae1553401c09a78d3a01d8acb Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:42:32 +0000 Subject: [PATCH 14/48] Remove openDevice --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 18 +++++------------- libsrc/leddevice/dev_ftdi/ProviderFtdi.h | 3 --- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index a8a80b738..a2b4dee97 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -50,27 +50,19 @@ bool ProviderFtdi::init(const QJsonObject &deviceConfig) return isInitOK; } -int ProviderFtdi::openDevice() +int ProviderFtdi::open() { - _ftdic = ftdi_new(); + int rc = 0; + + _ftdic = ftdi_new(); - Debug(_log, "Opening FTDI device=%s", QSTRING_CSTR(_deviceName)); + Debug(_log, "Opening FTDI device=%s", QSTRING_CSTR(_deviceName)); if (ftdi_usb_open_string(_ftdic, QSTRING_CSTR(_deviceName)) < 0) { setInError(ftdi_get_error_string(_ftdic)); return -1; } - return 1; -} -int ProviderFtdi::open() -{ - int rc = 0; - - if ((rc = openDevice()) != 1) - { - return -1; - } /* doing this disable resets things if they were in a bad state */ if ((rc = ftdi_disable_bitbang(_ftdic)) < 0) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.h b/libsrc/leddevice/dev_ftdi/ProviderFtdi.h index afaba68f4..955b26727 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.h +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.h @@ -71,9 +71,6 @@ protected slots: /// @param errorMsg The error message to be logged /// void setInError(const QString& errorMsg, bool isRecoverable=true) override; - -private: - int openDevice(); }; #endif // PROVIDERFtdi_H From af65f6f12865ef84e5c2838aa96650889cc88ee2 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 18:44:19 +0000 Subject: [PATCH 15/48] Remove close delay --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index a2b4dee97..b01a48e7e 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -4,7 +4,6 @@ #include #include -#include #define ANY_FTDI_VENDOR 0x0 #define ANY_FTDI_PRODUCT 0x0 @@ -110,10 +109,8 @@ int ProviderFtdi::open() int ProviderFtdi::close() { - // allow to clock out remaining data from powerOff()->writeBlack() if (_ftdic != NULL) { - std::this_thread::sleep_for(std::chrono::milliseconds(15)); Debug(_log, "Closing FTDI device"); ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); ftdi_usb_close(_ftdic); From 7bf2ad2cbfc3d3c8fe487a88c055ef03399ea2a2 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 19:30:32 +0000 Subject: [PATCH 16/48] Refactor device identifiers --- assets/webconfig/js/content_leds.js | 9 +++++++-- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 22 ++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index 25dde3407..2050a0b68 100755 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -1119,6 +1119,9 @@ $(document).ready(function () { case "karate": case "sedu": case "tpm2": + case "ws2812_ftdi": + case "sk6812_ftdi": + case "apa102_ftdi": if (storedAccess === 'expert') { filter.discoverAll = true; } @@ -1901,7 +1904,7 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { if ($.inArray(ledType, devNET) != -1) { ledTypeGroup = "devNET"; - } else if ($.inArray(ledType, devSerial) != -1) { + } else if ($.inArray(ledType, devSerial) != -1 || ledType.endsWith("_ftdi")) { ledTypeGroup = "devSerial"; } else if ($.inArray(ledType, devRPiSPI) != -1) { ledTypeGroup = "devRPiSPI"; @@ -1998,6 +2001,9 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { case "karate": case "sedu": case "tpm2": + case "ws2812_ftdi": + case "sk6812_ftdi": + case "apa102_ftdi": for (const device of discoveryInfo.devices) { if (device.udev) { enumVals.push(device.systemLocation); @@ -2093,7 +2099,6 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { async function discover_device(ledType, params) { const result = await requestLedDeviceDiscovery(ledType, params); - var discoveryResult = {}; if (result) { if (result.error) { diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index b01a48e7e..66192dd23 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -181,14 +181,24 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) libusb_device_descriptor desc; libusb_get_device_descriptor(curdev->dev, &desc); - QString value = QString("i:0x%1:0x%2") - .arg(desc.idVendor, 4, 16, QChar{'0'}) - .arg(desc.idProduct, 4, 16, QChar{'0'}); + uint8_t bus_number = libusb_get_bus_number(curdev->dev); + uint8_t device_address = libusb_get_device_address(curdev->dev); + + QString portName = QString("d:%1/%2") + .arg(bus_number, 3, 10, QChar{'0'}) + .arg(device_address, 3, 10, 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 name = QString("%1 (%2)").arg(manufacturer, description); deviceList.push_back(QJsonObject{ - {"value", value}, - {"name", name}}); + {"portName", portName}, + {"vendorIdentifier", vendorIdentifier}, + {"productIdentifier", productIdentifier}, + {"manufacturer", manufacturer}, + {"description", description}, + }); curdev = curdev->next; } From bc560b90d67d3efc8dacd03801320491a70218ff Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 19:33:14 +0000 Subject: [PATCH 17/48] Add setting to log --- libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp index 1a81e169c..46b867621 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp @@ -25,8 +25,10 @@ bool LedDeviceSk6812_ftdi::init(const QJsonObject &deviceConfig) if (ProviderFtdi::init(deviceConfig)) { _brightnessControlMaxLevel = deviceConfig["brightnessControlMaxLevel"].toInt(255); + Info(_log, "[%s] Setting maximum brightness to [%d]", QSTRING_CSTR(_activeDeviceType), _brightnessControlMaxLevel); - QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off"); + + QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off"); _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm); From cbb43dfa5ad54aba101dfa9d3b9f866bbb891bbf Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 19:34:06 +0000 Subject: [PATCH 18/48] Remove commen --- libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h index 4536e23f9..017b0f30e 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.h @@ -3,9 +3,6 @@ #include "ProviderFtdi.h" -/// -/// Implementation of the LedDevice interface for writing to Sk6801 LED-device via SPI. -/// class LedDeviceSk6812_ftdi : public ProviderFtdi { public: From 77da8be5cdabb8f26278a36807ea05365c44e7b1 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 19:35:34 +0000 Subject: [PATCH 19/48] Refactor _brightnessControlMaxLevel --- libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp index 69a6165c8..efa42cc67 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp @@ -15,14 +15,13 @@ LedDevice *LedDeviceAPA102_ftdi::construct(const QJsonObject &deviceConfig) bool LedDeviceAPA102_ftdi::init(const QJsonObject &deviceConfig) { bool isInitOK = false; - - _brightnessControlMaxLevel = deviceConfig["brightnessControlMaxLevel"].toInt(LED_BRIGHTNESS_FULL); - Info(_log, "[%s] Setting maximum brightness to [%d] = %d%%", QSTRING_CSTR(_activeDeviceType), _brightnessControlMaxLevel, _brightnessControlMaxLevel * 100 / LED_BRIGHTNESS_FULL); - // Initialise sub-class if (ProviderFtdi::init(deviceConfig)) { - CreateHeader(); + _brightnessControlMaxLevel = deviceConfig["brightnessControlMaxLevel"].toInt(LED_BRIGHTNESS_FULL); + Info(_log, "[%s] Setting maximum brightness to [%d] = %d%%", QSTRING_CSTR(_activeDeviceType), _brightnessControlMaxLevel, _brightnessControlMaxLevel * 100 / LED_BRIGHTNESS_FULL); + + CreateHeader(); isInitOK = true; } return isInitOK; From b1e6b8efddae0b937b1ff489d04fad289c37346a Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 19:36:29 +0000 Subject: [PATCH 20/48] Change wording --- libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp index 46b867621..5d91b0325 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp @@ -34,7 +34,7 @@ bool LedDeviceSk6812_ftdi::init(const QJsonObject &deviceConfig) Debug(_log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm)); - WarningIf((_baudRate_Hz < 2050000 || _baudRate_Hz > 4000000), _log, "SPI rate %d outside recommended range (2050000 -> 4000000)", _baudRate_Hz); + WarningIf((_baudRate_Hz < 2050000 || _baudRate_Hz > 4000000), _log, "Baud rate %d outside recommended range (2050000 -> 4000000)", _baudRate_Hz); const int SPI_FRAME_END_LATCH_BYTES = 3; _ledBuffer.resize(_ledRGBWCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); From b631dd22d9e2264b30d17de3932cb4ff94c6506a Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 Mar 2023 19:59:05 +0000 Subject: [PATCH 21/48] Disable default ftdi for windows --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30245b90c..fbaab491e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ IF ( ${CMAKE_SYSTEM} MATCHES "Linux" ) ELSEIF ( WIN32 ) SET ( DEFAULT_DX ON ) SET ( DEFAULT_MF ON ) + SET ( DEFAULT_DEV_FTDI OFF ) ELSE() SET ( DEFAULT_FB OFF ) SET ( DEFAULT_V4L2 OFF ) From 0d67ed3248d1429a2c5638bf12c21ea102e8f57e Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 15:32:29 +0000 Subject: [PATCH 22/48] Fix ENABLE_DEV_FTDI --- libsrc/leddevice/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index e6f47c820..373e63f0f 100644 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -65,7 +65,7 @@ if ( ENABLE_DEV_WS281XPWM ) FILE ( GLOB Leddevice_PWM_SOURCES "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.h" "${CURRENT_SOURCE_DIR}/dev_rpi_pwm/*.cpp") endif() -if (DEFAULT_DEV_FTDI) +if (ENABLE_DEV_FTDI) FILE ( GLOB Leddevice_FTDI_SOURCES "${CURRENT_SOURCE_DIR}/dev_ftdi/*.h" "${CURRENT_SOURCE_DIR}/dev_ftdi/*.cpp") endif() @@ -170,7 +170,7 @@ if(ENABLE_MDNS) target_link_libraries(leddevice mdns) endif() -if( DEFAULT_DEV_FTDI ) +if( ENABLE_DEV_FTDI ) FIND_PACKAGE(PkgConfig REQUIRED) pkg_check_modules(LIB_FTDI REQUIRED libftdi1) add_library(libftdi1 STATIC IMPORTED) From 0dd56206cf1756bc67e0d31f4b7c4922bcafa579 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 15:33:58 +0000 Subject: [PATCH 23/48] Fix wording --- libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp index d2a7f8507..57c0ac035 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceWs2812_ftdi.cpp @@ -59,7 +59,7 @@ bool LedDeviceWs2812_ftdi::init(const QJsonObject &deviceConfig) // Initialise sub-class if (ProviderFtdi::init(deviceConfig)) { - WarningIf((_baudRate_Hz < 2106000 || _baudRate_Hz > 3075000), _log, "SPI rate %d outside recommended range (2106000 -> 3075000)", _baudRate_Hz); + WarningIf((_baudRate_Hz < 2106000 || _baudRate_Hz > 3075000), _log, "Baud rate %d outside recommended range (2106000 -> 3075000)", _baudRate_Hz); _ledBuffer.resize(_ledRGBCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); isInitOK = true; } From 184b173decc0890f36eac4089ef51033de43ec3b Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 15:35:33 +0000 Subject: [PATCH 24/48] Fix CMakeLists.txt --- libsrc/leddevice/CMakeLists.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libsrc/leddevice/CMakeLists.txt b/libsrc/leddevice/CMakeLists.txt index 373e63f0f..e4d16bab0 100644 --- a/libsrc/leddevice/CMakeLists.txt +++ b/libsrc/leddevice/CMakeLists.txt @@ -171,10 +171,9 @@ if(ENABLE_MDNS) endif() if( ENABLE_DEV_FTDI ) - FIND_PACKAGE(PkgConfig REQUIRED) - pkg_check_modules(LIB_FTDI REQUIRED libftdi1) - add_library(libftdi1 STATIC IMPORTED) - target_include_directories(leddevice PUBLIC ${LIB_FTDI_INCLUDE_DIRS}) - target_link_libraries(leddevice ${LIB_FTDI_LINK_LIBRARIES}) + find_package(PkgConfig REQUIRED) + pkg_check_modules(LIB_FTDI REQUIRED IMPORTED_TARGET libftdi1 ) + target_include_directories(leddevice PRIVATE PkgConfig::LIB_FTDI) + target_link_libraries(leddevice PkgConfig::LIB_FTDI) endif() From b467c7e8fd0236390c3aa6f6e5b68ef1753439d9 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 15:41:18 +0000 Subject: [PATCH 25/48] Refactor labels --- assets/webconfig/js/content_leds.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index 2050a0b68..5b0c84e9d 100755 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -1663,8 +1663,10 @@ $(document).ready(function () { optArr[4].push(ledDevices[idx]); else if ($.inArray(ledDevices[idx], devHID) != -1) optArr[4].push(ledDevices[idx]); - else if (ledDevices[idx].endsWith("_ftdi")) - optArr[5].push(ledDevices[idx]); + else if (ledDevices[idx].endsWith("_ftdi")) { + var title = ledDevices[idx].replace('_ftdi',''); + optArr[5].push(ledDevices[idx] + ":" + title); + } else optArr[6].push(ledDevices[idx]); } @@ -1674,7 +1676,7 @@ $(document).ready(function () { $("#leddevices").append(createSel(optArr[2], $.i18n('conf_leds_optgroup_RPiGPIO'))); $("#leddevices").append(createSel(optArr[3], $.i18n('conf_leds_optgroup_network'))); $("#leddevices").append(createSel(optArr[4], $.i18n('conf_leds_optgroup_usb'))); - $("#leddevices").append(createSel(optArr[5], $.i18n('conf_leds_optgroup_ftdi'))); + $("#leddevices").append(createSel(optArr[5], $.i18n('conf_leds_optgroup_ftdi'), true)); if (storedAccess === 'expert' || window.serverConfig.device.type === "file") { $("#leddevices").append(createSel(optArr[6], $.i18n('conf_leds_optgroup_other'))); From 56d136f5cbf10fba3e757fd9dce70f902dbeacb3 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 15:41:41 +0000 Subject: [PATCH 26/48] Removeing "format": "stepper", --- libsrc/leddevice/schemas/schema-sk6812_ftdi.json | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json index 5bdd07011..0e1868866 100644 --- a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json +++ b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json @@ -10,7 +10,6 @@ }, "rate": { "type": "integer", - "format": "stepper", "step": 100000, "title": "edt_dev_spec_baudrate_title", "default": 3200000, From af8457d5f1b3274fd8fff3a12b11c555b277e8c3 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 15:55:54 +0000 Subject: [PATCH 27/48] Add libftdi1-dev to codeql.yml --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 1565d699c..bf41f3aec 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -32,7 +32,7 @@ jobs: if: ${{ matrix.language == 'cpp' }} run: | sudo apt-get update - sudo apt-get install --yes git cmake build-essential qtbase5-dev libqt5serialport5-dev libqt5sql5-sqlite libqt5svg5-dev libqt5x11extras5-dev libusb-1.0-0-dev python3-dev libcec-dev libxcb-image0-dev libxcb-util0-dev libxcb-shm0-dev libxcb-render0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libasound2-dev libturbojpeg0-dev libjpeg-dev libssl-dev + sudo apt-get install --yes git cmake build-essential qtbase5-dev libqt5serialport5-dev libqt5sql5-sqlite libqt5svg5-dev libqt5x11extras5-dev libusb-1.0-0-dev python3-dev libcec-dev libxcb-image0-dev libxcb-util0-dev libxcb-shm0-dev libxcb-render0-dev libxcb-randr0-dev libxrandr-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev libasound2-dev libturbojpeg0-dev libjpeg-dev libssl-dev libftdi1-dev - name: Initialize CodeQL uses: github/codeql-action/init@v2 From dce599e64d14295794ecea4bbb52f4a9015211ba Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 16:00:40 +0000 Subject: [PATCH 28/48] Add libftdi1-dev to CompileHowto.md --- doc/development/CompileHowto.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/development/CompileHowto.md b/doc/development/CompileHowto.md index f3b5502ce..25e28e826 100644 --- a/doc/development/CompileHowto.md +++ b/doc/development/CompileHowto.md @@ -87,14 +87,14 @@ cd $HYPERION_HOME ```console sudo apt-get update -sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libqt5sql5-sqlite libqt5svg5-dev libqt5x11extras5-dev libusb-1.0-0-dev python3-dev libasound2-dev libturbojpeg0-dev libjpeg-dev libssl-dev +sudo apt-get install git cmake build-essential qtbase5-dev libqt5serialport5-dev libqt5sql5-sqlite libqt5svg5-dev libqt5x11extras5-dev libusb-1.0-0-dev python3-dev libasound2-dev libturbojpeg0-dev libjpeg-dev libssl-dev libftdi1-dev ``` **Ubuntu (22.04+) - Qt6 based** ```console sudo apt-get update -sudo apt-get install git cmake build-essential qt6-base-dev libqt6serialport6-dev libvulkan-dev libgl1-mesa-dev libusb-1.0-0-dev python3-dev libasound2-dev libturbojpeg0-dev libjpeg-dev libssl-dev pkg-config +sudo apt-get install git cmake build-essential qt6-base-dev libqt6serialport6-dev libvulkan-dev libgl1-mesa-dev libusb-1.0-0-dev python3-dev libasound2-dev libturbojpeg0-dev libjpeg-dev libssl-dev pkg-config libftdi1-dev ``` **For Linux X11/XCB grabber support** @@ -136,7 +136,7 @@ See [AUR](https://aur.archlinux.org/packages/?O=0&SeB=nd&K=hyperion&outdated=&SB The following dependencies are needed to build hyperion.ng on fedora. ```console sudo dnf -y groupinstall "Development Tools" -sudo dnf install python3-devel qt-devel qt5-qtbase-devel qt5-qtserialport-devel xrandr xcb-util-image-devel qt5-qtx11extras-devel alsa-lib-devel turbojpeg-devel libusb-devel xcb-util-devel dbus-devel openssl-devel fedora-packager rpmdevtools gcc libcec-devel +sudo dnf install python3-devel qt-devel qt5-qtbase-devel qt5-qtserialport-devel xrandr xcb-util-image-devel qt5-qtx11extras-devel alsa-lib-devel turbojpeg-devel libusb-devel xcb-util-devel dbus-devel openssl-devel fedora-packager rpmdevtools gcc libcec-devel libftdi1-dev ``` After installing the dependencies, you can continue with the compile instructions later on this page (the more detailed way..). @@ -145,7 +145,7 @@ To install on OS X you either need Homebrew or Macport but Homebrew is the recom First you need to install the dependencies: ```console -brew install qt5 python3 cmake libusb doxygen +brew install qt5 python3 cmake libusb doxygen libftdi ``` ## Windows From c800235ef60af9e8e3552b992d10becd741d97cf Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 18:49:11 +0000 Subject: [PATCH 29/48] Fix spaces --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbaab491e..aba68c497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ SET ( DEFAULT_DEV_SPI OFF ) SET ( DEFAULT_DEV_TINKERFORGE OFF ) SET ( DEFAULT_DEV_USB_HID OFF ) SET ( DEFAULT_DEV_WS281XPWM OFF ) -SET ( DEFAULT_DEV_FTDI ON ) +SET ( DEFAULT_DEV_FTDI ON ) # Services SET ( DEFAULT_EFFECTENGINE ON ) From 1d6b620d881c44c6964453aa585c929871b16ab8 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 Mar 2023 22:33:09 +0000 Subject: [PATCH 30/48] Refactor device identifier --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 66192dd23..933eb2d6b 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -174,6 +174,7 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) if (ftdi_usb_find_all(ftdic, &devlist, ANY_FTDI_VENDOR, ANY_FTDI_PRODUCT) > 0) { struct ftdi_device_list *curdev = devlist; + QMap deviceIndexes; while (curdev) { char manufacturer[128], description[128]; @@ -181,16 +182,15 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) libusb_device_descriptor desc; libusb_get_device_descriptor(curdev->dev, &desc); - uint8_t bus_number = libusb_get_bus_number(curdev->dev); - uint8_t device_address = libusb_get_device_address(curdev->dev); - - QString portName = QString("d:%1/%2") - .arg(bus_number, 3, 10, QChar{'0'}) - .arg(device_address, 3, 10, 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 vendorAndProduct = QString("i:%1:%2") + .arg(vendorIdentifier) + .arg(productIdentifier); + uint8_t deviceIndex = deviceIndexes.value(vendorAndProduct, 0); + QString portName = QString("%1:%2").arg(vendorAndProduct).arg(deviceIndex); deviceList.push_back(QJsonObject{ {"portName", portName}, @@ -201,6 +201,8 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) }); curdev = curdev->next; + + deviceIndexes.insert(vendorAndProduct, deviceIndex + 1); } } From 6941f4c4f74b036d488658263d03c748ec6c6ac7 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Fri, 31 Mar 2023 14:04:45 +0000 Subject: [PATCH 31/48] Add wait in close() --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 933eb2d6b..c5088097d 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -1,6 +1,7 @@ // LedDevice includes #include #include "ProviderFtdi.h" +#include #include #include @@ -112,6 +113,7 @@ int ProviderFtdi::close() if (_ftdic != NULL) { Debug(_log, "Closing FTDI device"); + wait(15); // Delay to give time to push color black from writeBlack() into the led ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); ftdi_usb_close(_ftdic); _ftdic = NULL; From 5586381a68ffd3d82b882884c7f7105858ef74ff Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 2 Apr 2023 12:53:03 +0000 Subject: [PATCH 32/48] Update Sk6812 baud range and ensure range in UI --- libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp | 2 +- libsrc/leddevice/schemas/schema-sk6812_ftdi.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp index 5d91b0325..81e8dadc5 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp @@ -34,7 +34,7 @@ bool LedDeviceSk6812_ftdi::init(const QJsonObject &deviceConfig) Debug(_log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm)); - WarningIf((_baudRate_Hz < 2050000 || _baudRate_Hz > 4000000), _log, "Baud rate %d outside recommended range (2050000 -> 4000000)", _baudRate_Hz); + WarningIf((_baudRate_Hz < 2050000 || _baudRate_Hz > 3750000), _log, "Baud rate %d outside recommended range (2050000 -> 3750000)", _baudRate_Hz); const int SPI_FRAME_END_LATCH_BYTES = 3; _ledBuffer.resize(_ledRGBWCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); diff --git a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json index 0e1868866..5667909b4 100644 --- a/libsrc/leddevice/schemas/schema-sk6812_ftdi.json +++ b/libsrc/leddevice/schemas/schema-sk6812_ftdi.json @@ -13,6 +13,8 @@ "step": 100000, "title": "edt_dev_spec_baudrate_title", "default": 3200000, + "minimum": 2050000, + "maximum": 3750000, "propertyOrder": 2 }, "brightnessControlMaxLevel": { @@ -55,4 +57,4 @@ } }, "additionalProperties": true -} \ No newline at end of file +} From 26f32a01019e356330f8d1452606452a730ccbac Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 2 Apr 2023 12:53:27 +0000 Subject: [PATCH 33/48] Minor update --- libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp index efa42cc67..32ae75701 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceAPA102_ftdi.cpp @@ -34,7 +34,7 @@ void LedDeviceAPA102_ftdi::CreateHeader() const unsigned int endFrameSize = (_ledCount / 32) * 4 + 4; const unsigned int APAbufferSize = (_ledCount * 4) + startFrameSize + endFrameSize; _ledBuffer.resize(APAbufferSize, 0); - Debug(_log, "APA102 buffer created. Led's number: %d", _ledCount); + Debug(_log, "APA102 buffer created for %d LEDs", _ledCount); } int LedDeviceAPA102_ftdi::write(const std::vector &ledValues) From 349bbadd8e66f13afc74a91b1df35cf216c05ce3 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 2 Apr 2023 12:55:27 +0000 Subject: [PATCH 34/48] Support addressing device via SerialNumber and handle add more error handlingin discovery --- assets/webconfig/js/content_leds.js | 88 +++++++++++++++++-- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 98 ++++++++++++++-------- 2 files changed, 146 insertions(+), 40 deletions(-) diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index 5b0c84e9d..efcf1c6ed 100755 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -19,6 +19,7 @@ var bottomLeft2topLeft = null; var toggleKeystoneCorrectionArea = false; var devRPiSPI = ['apa102', 'apa104', 'ws2801', 'lpd6803', 'lpd8806', 'p9813', 'sk6812spi', 'sk6822spi', 'sk9822', 'ws2812spi']; +var devFTDI = ['apa102_ftdi', 'sk6812_ftdi', 'ws2812_ftdi']; var devRPiPWM = ['ws281x']; var devRPiGPIO = ['piblaster']; var devNET = ['atmoorb', 'cololight', 'fadecandy', 'philipshue', 'nanoleaf', 'razer', 'tinkerforge', 'tpm2net', 'udpe131', 'udpartnet', 'udpddp', 'udph801', 'udpraw', 'wled', 'yeelight']; @@ -1119,9 +1120,12 @@ $(document).ready(function () { case "karate": case "sedu": case "tpm2": - case "ws2812_ftdi": - case "sk6812_ftdi": + + //FTDI devices case "apa102_ftdi": + case "sk6812_ftdi": + case "ws2812_ftdi": + if (storedAccess === 'expert') { filter.discoverAll = true; } @@ -1142,7 +1146,16 @@ $(document).ready(function () { }); hwLedCountDefault = 1; - colorOrderDefault = "rgb"; + + switch (ledType) { + case "sk6812spi": + case "sk6812_ftdi": + colorOrderDefault = "grb"; + break; + default: + colorOrderDefault = "rgb"; + } + break; case "philipshue": @@ -1425,6 +1438,9 @@ $(document).ready(function () { case "sk9822": case "ws2812spi": case "piblaster": + case "apa102_ftdi": + case "sk6812_ftdi": + case "ws2812_ftdi": default: } @@ -1856,6 +1872,9 @@ function saveLedConfig(genDefLayout = false) { case "sk9822": case "ws2812spi": case "piblaster": + case "apa102_ftdi": + case "sk6812_ftdi": + case "ws2812_ftdi": default: if (genDefLayout === true) { ledConfig = { @@ -1906,10 +1925,12 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { if ($.inArray(ledType, devNET) != -1) { ledTypeGroup = "devNET"; - } else if ($.inArray(ledType, devSerial) != -1 || ledType.endsWith("_ftdi")) { + } else if ($.inArray(ledType, devSerial) != -1) { ledTypeGroup = "devSerial"; } else if ($.inArray(ledType, devRPiSPI) != -1) { ledTypeGroup = "devRPiSPI"; + } else if ($.inArray(ledType, devFTDI) != -1) { + ledTypeGroup = "devFTDI"; } else if ($.inArray(ledType, devRPiGPIO) != -1) { ledTypeGroup = "devRPiGPIO"; } else if ($.inArray(ledType, devRPiPWM) != -1) { @@ -2003,9 +2024,6 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { case "karate": case "sedu": case "tpm2": - case "ws2812_ftdi": - case "sk6812_ftdi": - case "apa102_ftdi": for (const device of discoveryInfo.devices) { if (device.udev) { enumVals.push(device.systemLocation); @@ -2035,6 +2053,62 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { } } break; + + case "devFTDI": + key = "output"; + + if (discoveryInfo.devices.length == 0) { + enumVals.push("NONE"); + enumTitleVals.push($.i18n('edt_dev_spec_devices_discovered_none')); + $('#btn_submit_controller').prop('disabled', true); + showAllDeviceInputOptions(key, false); + } + else { + switch (ledType) { + case "ws2812_ftdi": + case "sk6812_ftdi": + case "apa102_ftdi": + for (const device of discoveryInfo.devices) { + enumVals.push(device.ftdiOpenString); + + var title = "FTDI"; + if (device.manufacturer) { + title = device.manufacturer + } + + if (device.serialNumber) { + title += " - " + device.serialNumber; + } + title += " (" + device.vendorIdentifier + "|" + device.productIdentifier + ")"; + + if (device.description) { + title += " " + device.description; + } + + enumTitleVals.push(title); + } + + // Select configured device + var configuredDeviceType = window.serverConfig.device.type; + var configuredOutput = window.serverConfig.device.output; + if (ledType === configuredDeviceType) { + if ($.inArray(configuredOutput, enumVals) != -1) { + enumDefaultVal = configuredOutput; + } else { + enumVals.push(window.serverConfig.device.output); + enumDefaultVal = configuredOutput; + } + } + else { + addSelect = true; + } + + break; + default: + } + } + break; + case "devRPiSPI": case "devRPiGPIO": key = "output"; diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index c5088097d..2463f8d33 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -11,7 +11,7 @@ namespace Pin { - // enumerate the AD bus for conveniance. + // enumerate the AD bus for convenience. enum bus_t { SK = 0x01, // ADBUS0, SPI data clock @@ -28,7 +28,7 @@ const QString ProviderFtdi::AUTO_SETTING = QString("auto"); ProviderFtdi::ProviderFtdi(const QJsonObject &deviceConfig) : LedDevice(deviceConfig), - _ftdic(NULL), + _ftdic(nullptr), _baudRate_Hz(1000000) { } @@ -90,7 +90,7 @@ int ProviderFtdi::open() double reference_clock = 60e6; int divisor = (reference_clock / 2 / _baudRate_Hz) - 1; uint8_t buf[10] = {0}; - unsigned int icmd = 0; + int icmd = 0; buf[icmd++] = DIS_DIV_5; buf[icmd++] = TCK_DIVISOR; buf[icmd++] = divisor; @@ -110,13 +110,13 @@ int ProviderFtdi::open() int ProviderFtdi::close() { - if (_ftdic != NULL) + if (_ftdic != nullptr) { Debug(_log, "Closing FTDI device"); wait(15); // Delay to give time to push color black from writeBlack() into the led ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); ftdi_usb_close(_ftdic); - _ftdic = NULL; + _ftdic = nullptr; } return LedDevice::close(); } @@ -125,13 +125,13 @@ void ProviderFtdi::setInError(const QString &errorMsg, bool isRecoverable) { close(); - LedDevice::setInError(errorMsg); + LedDevice::setInError(errorMsg, isRecoverable); } int ProviderFtdi::writeBytes(const qint64 size, const uint8_t *data) { uint8_t buf[10] = {0}; - unsigned int icmd = 0; + int icmd = 0; int rc = 0; int count_arg = size - 1; @@ -176,35 +176,67 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) if (ftdi_usb_find_all(ftdic, &devlist, ANY_FTDI_VENDOR, ANY_FTDI_PRODUCT) > 0) { struct ftdi_device_list *curdev = devlist; - QMap deviceIndexes; + QMap deviceIndexes; + while (curdev) { - char manufacturer[128], description[128]; - ftdi_usb_get_strings(ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0); - libusb_device_descriptor desc; - libusb_get_device_descriptor(curdev->dev, &desc); - - 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 vendorAndProduct = QString("i:%1:%2") - .arg(vendorIdentifier) - .arg(productIdentifier); - uint8_t deviceIndex = deviceIndexes.value(vendorAndProduct, 0); - - QString portName = QString("%1:%2").arg(vendorAndProduct).arg(deviceIndex); - - deviceList.push_back(QJsonObject{ - {"portName", portName}, - {"vendorIdentifier", vendorIdentifier}, - {"productIdentifier", productIdentifier}, - {"manufacturer", manufacturer}, - {"description", description}, - }); - + int rc = libusb_get_device_descriptor(curdev->dev, &desc); + if (rc == 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 vendorAndProduct = QString("%1:%2") + .arg(vendorIdentifier) + .arg(productIdentifier); + uint8_t deviceIndex = deviceIndexes.value(vendorAndProduct, 0); + + QString serialNumber; + char serial_string[128]; + rc = ftdi_usb_get_strings2(ftdic, curdev->dev, nullptr, 0, nullptr, 0, serial_string, 128); + if (rc == 0) + { + serialNumber = serial_string; + } + + QString ftdiOpenString; + if(!serialNumber.isEmpty()) + { + ftdiOpenString = QString("s:%1:%2").arg(vendorAndProduct).arg(serialNumber); + } + else + { + ftdiOpenString = QString("i:%1:%2").arg(vendorAndProduct).arg(deviceIndex); + } + + QString manufacturer; + char manufacturer_string[128]; + rc = ftdi_usb_get_strings2(ftdic, curdev->dev, manufacturer_string, 128, nullptr, 0, nullptr, 0); + if (rc == 0) + { + manufacturer = manufacturer_string; + } + + QString description; + char description_string[128]; + rc = ftdi_usb_get_strings2(ftdic, curdev->dev, nullptr, 0, description_string, 128, nullptr, 0); + if (rc == 0) + { + description = description_string; + } + + deviceList.push_back(QJsonObject{ + {"ftdiOpenString", ftdiOpenString}, + {"vendorIdentifier", vendorIdentifier}, + {"productIdentifier", productIdentifier}, + {"deviceIndex", deviceIndex}, + {"serialNumber", serialNumber}, + {"manufacturer", manufacturer}, + {"description", description} + }); + deviceIndexes.insert(vendorAndProduct, deviceIndex + 1); + } curdev = curdev->next; - - deviceIndexes.insert(vendorAndProduct, deviceIndex + 1); } } @@ -217,4 +249,4 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) Debug(_log, "FTDI devices discovered: [%s]", QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData()); return devicesDiscovered; -} \ No newline at end of file +} From 916b3f3ba7773ec0f99d81fe238aad86ce95d4f3 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 2 Apr 2023 14:31:04 +0000 Subject: [PATCH 35/48] Simplify discovery with proper string initialization --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 32 +++++----------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 2463f8d33..c5e2edf35 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -191,14 +191,12 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) .arg(productIdentifier); uint8_t deviceIndex = deviceIndexes.value(vendorAndProduct, 0); - QString serialNumber; - char serial_string[128]; - rc = ftdi_usb_get_strings2(ftdic, curdev->dev, nullptr, 0, nullptr, 0, serial_string, 128); - if (rc == 0) - { - serialNumber = serial_string; - } + char serial_string[128] = {0}; + char manufacturer_string[128] = {0}; + char description_string[128] = {0}; + ftdi_usb_get_strings2(ftdic, curdev->dev, manufacturer_string, 128, description_string, 128, serial_string, 128); + QString serialNumber {serial_string}; QString ftdiOpenString; if(!serialNumber.isEmpty()) { @@ -209,30 +207,14 @@ QJsonObject ProviderFtdi::discover(const QJsonObject & /*params*/) ftdiOpenString = QString("i:%1:%2").arg(vendorAndProduct).arg(deviceIndex); } - QString manufacturer; - char manufacturer_string[128]; - rc = ftdi_usb_get_strings2(ftdic, curdev->dev, manufacturer_string, 128, nullptr, 0, nullptr, 0); - if (rc == 0) - { - manufacturer = manufacturer_string; - } - - QString description; - char description_string[128]; - rc = ftdi_usb_get_strings2(ftdic, curdev->dev, nullptr, 0, description_string, 128, nullptr, 0); - if (rc == 0) - { - description = description_string; - } - deviceList.push_back(QJsonObject{ {"ftdiOpenString", ftdiOpenString}, {"vendorIdentifier", vendorIdentifier}, {"productIdentifier", productIdentifier}, {"deviceIndex", deviceIndex}, {"serialNumber", serialNumber}, - {"manufacturer", manufacturer}, - {"description", description} + {"manufacturer", manufacturer_string}, + {"description", description_string} }); deviceIndexes.insert(vendorAndProduct, deviceIndex + 1); } From 20409c1cc1796e1e2c59d6e9e209afa14bc7482d Mon Sep 17 00:00:00 2001 From: LordGrey Date: Fri, 7 Apr 2023 13:51:19 +0000 Subject: [PATCH 36/48] Do not reset mpsee engine on close --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index c5e2edf35..f1b8e2e2c 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -1,7 +1,6 @@ // LedDevice includes #include #include "ProviderFtdi.h" -#include #include #include @@ -110,14 +109,9 @@ int ProviderFtdi::open() int ProviderFtdi::close() { - if (_ftdic != nullptr) - { - Debug(_log, "Closing FTDI device"); - wait(15); // Delay to give time to push color black from writeBlack() into the led - ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); - ftdi_usb_close(_ftdic); - _ftdic = nullptr; - } + Debug(_log, "Closing FTDI device"); + ftdi_usb_close(_ftdic); + _ftdic = nullptr; return LedDevice::close(); } From db903cb5396ba5adb5fce213fae3109bfa144d3b Mon Sep 17 00:00:00 2001 From: LordGrey Date: Fri, 7 Apr 2023 23:50:57 +0000 Subject: [PATCH 37/48] Reset mpsse on close and properly free _ftdic --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index f1b8e2e2c..ed61b303a 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -110,7 +110,9 @@ int ProviderFtdi::open() int ProviderFtdi::close() { Debug(_log, "Closing FTDI device"); + ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); ftdi_usb_close(_ftdic); + ftdi_free(_ftdic); _ftdic = nullptr; return LedDevice::close(); } From ba6feb81ceca0f8cd9e4329258108b3c4842d453 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sat, 8 Apr 2023 10:09:31 +0000 Subject: [PATCH 38/48] Check _ftdic for null --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index ed61b303a..8c8c30523 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -109,11 +109,13 @@ int ProviderFtdi::open() int ProviderFtdi::close() { - Debug(_log, "Closing FTDI device"); - ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); - ftdi_usb_close(_ftdic); - ftdi_free(_ftdic); - _ftdic = nullptr; + if (_ftdic != nullptr) { + Debug(_log, "Closing FTDI device"); + ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); + ftdi_usb_close(_ftdic); + ftdi_free(_ftdic); + _ftdic = nullptr; + } return LedDevice::close(); } From d3e8d3a34139fd2cd26971f59684e7379c5956b4 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sat, 8 Apr 2023 10:55:40 +0000 Subject: [PATCH 39/48] Add wait in close() --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 8c8c30523..043202873 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -1,6 +1,7 @@ // LedDevice includes #include #include "ProviderFtdi.h" +#include #include #include @@ -110,7 +111,10 @@ int ProviderFtdi::open() int ProviderFtdi::close() { if (_ftdic != nullptr) { - Debug(_log, "Closing FTDI device"); + Debug(_log, "Closing FTDI device"); +// Delay to give time to push color black from writeBlack() into the led, +// otherwise frame transmission will be terminated half way through + wait(30); ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); ftdi_usb_close(_ftdic); ftdi_free(_ftdic); From 82aba826a49753b9112d1c221b9d7dc6c5eac556 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sat, 8 Apr 2023 19:18:08 +0000 Subject: [PATCH 40/48] Remove L0 --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 043202873..33b59a2b4 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -17,12 +17,12 @@ namespace Pin SK = 0x01, // ADBUS0, SPI data clock DO = 0x02, // ADBUS1, SPI data out CS = 0x08, // ADBUS3, SPI chip select, active low - L0 = 0x10, // ADBUS4, SPI chip select, active high }; } +const unsigned char pinInitialState = Pin::CS; // Use these pins as outputs -const unsigned char pinDirection = Pin::SK | Pin::DO | Pin::CS | Pin::L0; +const unsigned char pinDirection = Pin::SK | Pin::DO | Pin::CS; const QString ProviderFtdi::AUTO_SETTING = QString("auto"); @@ -96,7 +96,7 @@ int ProviderFtdi::open() buf[icmd++] = divisor; buf[icmd++] = divisor >> 8; buf[icmd++] = SET_BITS_LOW; // opcode: set low bits (ADBUS[0-7]) - buf[icmd++] = Pin::CS & ~Pin::L0; // argument: initial pin states + buf[icmd++] = pinInitialState; // argument: initial pin states buf[icmd++] = pinDirection; if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) { @@ -138,7 +138,7 @@ int ProviderFtdi::writeBytes(const qint64 size, const uint8_t *data) int count_arg = size - 1; buf[icmd++] = SET_BITS_LOW; - buf[icmd++] = Pin::L0 & ~Pin::CS; + buf[icmd++] = pinInitialState & ~Pin::CS; buf[icmd++] = pinDirection; buf[icmd++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG; buf[icmd++] = count_arg; @@ -156,7 +156,7 @@ int ProviderFtdi::writeBytes(const qint64 size, const uint8_t *data) } icmd = 0; buf[icmd++] = SET_BITS_LOW; - buf[icmd++] = Pin::CS & ~Pin::L0; + buf[icmd++] = pinInitialState | Pin::CS; buf[icmd++] = pinDirection; if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) { From d8fbfd24a92aa3e1215f789b776625c51e6a7fec Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sat, 8 Apr 2023 23:04:25 +0000 Subject: [PATCH 41/48] Reduce ftdi_write_data call count from 3 to 1 --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 46 +++++++++------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 33b59a2b4..74506e866 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -132,33 +132,25 @@ void ProviderFtdi::setInError(const QString &errorMsg, bool isRecoverable) int ProviderFtdi::writeBytes(const qint64 size, const uint8_t *data) { - uint8_t buf[10] = {0}; - int icmd = 0; - int rc = 0; - - int count_arg = size - 1; - buf[icmd++] = SET_BITS_LOW; - buf[icmd++] = pinInitialState & ~Pin::CS; - buf[icmd++] = pinDirection; - buf[icmd++] = MPSSE_DO_WRITE | MPSSE_WRITE_NEG; - buf[icmd++] = count_arg; - buf[icmd++] = count_arg >> 8; - - if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) - { - setInError(ftdi_get_error_string(_ftdic)); - return rc; - } - if ((rc = ftdi_write_data(_ftdic, data, size)) != size) - { - setInError(ftdi_get_error_string(_ftdic)); - return rc; - } - icmd = 0; - buf[icmd++] = SET_BITS_LOW; - buf[icmd++] = pinInitialState | Pin::CS; - buf[icmd++] = pinDirection; - if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) + int rc; + int count_arg = size - 1; + std::vector buf = { + SET_BITS_LOW, + pinInitialState & ~Pin::CS, + pinDirection, + MPSSE_DO_WRITE | MPSSE_WRITE_NEG, + static_cast(count_arg), + static_cast(count_arg >> 8), +// LED's data will be inserted here + SET_BITS_LOW, + pinInitialState | Pin::CS, + pinDirection + }; + // insert before last SET_BITS_LOW command + // SET_BITS_LOW takes 2 arguments, so we're inserting data in -3 position from the end + buf.insert(buf.end() - 3, &data[0], &data[size]); + + if ((rc = ftdi_write_data(_ftdic, buf.data(), buf.size())) != buf.size()) { setInError(ftdi_get_error_string(_ftdic)); return rc; From 757fd399821be1185c330a5157da50889bea7e8a Mon Sep 17 00:00:00 2001 From: LordGrey Date: Tue, 11 Apr 2023 19:59:22 +0000 Subject: [PATCH 42/48] Refactor ftdi provider --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 76 +++++++--------------- 1 file changed, 25 insertions(+), 51 deletions(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 74506e866..77afaf89b 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -9,6 +9,8 @@ #define ANY_FTDI_VENDOR 0x0 #define ANY_FTDI_PRODUCT 0x0 +#define FTDI_CHECK_RESULT(statement) if (statement) {setInError(ftdi_get_error_string(_ftdic)); return rc;} + namespace Pin { // enumerate the AD bus for convenience. @@ -58,54 +60,30 @@ int ProviderFtdi::open() Debug(_log, "Opening FTDI device=%s", QSTRING_CSTR(_deviceName)); - if (ftdi_usb_open_string(_ftdic, QSTRING_CSTR(_deviceName)) < 0) - { - setInError(ftdi_get_error_string(_ftdic)); - return -1; - } - - /* doing this disable resets things if they were in a bad state */ - if ((rc = ftdi_disable_bitbang(_ftdic)) < 0) - { - setInError(ftdi_get_error_string(_ftdic)); - return rc; - } - if ((rc = ftdi_setflowctrl(_ftdic, SIO_DISABLE_FLOW_CTRL)) < 0) - { - setInError(ftdi_get_error_string(_ftdic)); - return rc; - } - if ((rc = ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET)) < 0) - { - setInError(ftdi_get_error_string(_ftdic)); - return rc; - } - - if ((rc = ftdi_set_bitmode(_ftdic, 0xff, BITMODE_MPSSE)) < 0) - { - setInError(ftdi_get_error_string(_ftdic)); - return rc; - } + FTDI_CHECK_RESULT((rc = ftdi_usb_open_string(_ftdic, QSTRING_CSTR(_deviceName))) < 0); + /* doing this disable resets things if they were in a bad state */ + FTDI_CHECK_RESULT((rc = ftdi_disable_bitbang(_ftdic)) < 0); + FTDI_CHECK_RESULT((rc = ftdi_setflowctrl(_ftdic, SIO_DISABLE_FLOW_CTRL)) < 0); + FTDI_CHECK_RESULT((rc = ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET)) < 0); + FTDI_CHECK_RESULT((rc = ftdi_set_bitmode(_ftdic, 0xff, BITMODE_MPSSE)) < 0); + + + double reference_clock = 60e6; + int divisor = (reference_clock / 2 / _baudRate_Hz) - 1; + std::vector buf = { + DIS_DIV_5, + TCK_DIVISOR, + static_cast(divisor), + static_cast(divisor >> 8), + SET_BITS_LOW, // opcode: set low bits (ADBUS[0-7] + pinInitialState, // argument: inital pin state + pinDirection + }; - double reference_clock = 60e6; - int divisor = (reference_clock / 2 / _baudRate_Hz) - 1; - uint8_t buf[10] = {0}; - int icmd = 0; - buf[icmd++] = DIS_DIV_5; - buf[icmd++] = TCK_DIVISOR; - buf[icmd++] = divisor; - buf[icmd++] = divisor >> 8; - buf[icmd++] = SET_BITS_LOW; // opcode: set low bits (ADBUS[0-7]) - buf[icmd++] = pinInitialState; // argument: initial pin states - buf[icmd++] = pinDirection; - if ((rc = ftdi_write_data(_ftdic, buf, icmd)) != icmd) - { - setInError(ftdi_get_error_string(_ftdic)); - return rc; - } + FTDI_CHECK_RESULT((rc = ftdi_write_data(_ftdic, buf.data(), buf.size())) != buf.size()); - _isDeviceReady = true; - return rc; + _isDeviceReady = true; + return rc; } int ProviderFtdi::close() @@ -150,11 +128,7 @@ int ProviderFtdi::writeBytes(const qint64 size, const uint8_t *data) // SET_BITS_LOW takes 2 arguments, so we're inserting data in -3 position from the end buf.insert(buf.end() - 3, &data[0], &data[size]); - if ((rc = ftdi_write_data(_ftdic, buf.data(), buf.size())) != buf.size()) - { - setInError(ftdi_get_error_string(_ftdic)); - return rc; - } + FTDI_CHECK_RESULT((rc = ftdi_write_data(_ftdic, buf.data(), buf.size())) != buf.size()); return rc; } From 6f3f721c2684a334d8334375b89f2ec74a8f0b8f Mon Sep 17 00:00:00 2001 From: LordGrey Date: Sun, 26 May 2024 16:15:03 +0200 Subject: [PATCH 43/48] On top updates --- assets/webconfig/i18n/en.json | 2 +- assets/webconfig/js/content_leds.js | 10 +- .../dev_ftdi/LedDeviceSk6812_ftdi.cpp | 24 ++-- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 109 +++++++++--------- .../leddevice/schemas/schema-sk6812spi.json | 24 +++- libsrc/leddevice/schemas/schema-ws281x.json | 24 +++- 6 files changed, 124 insertions(+), 69 deletions(-) diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json index c5641c752..c8e52eeab 100644 --- a/assets/webconfig/i18n/en.json +++ b/assets/webconfig/i18n/en.json @@ -161,7 +161,7 @@ "conf_leds_note_layout_overwrite": "Note: Overwrite creates a default layout for {{plural:$1| one LED| all $1 LEDs}} given by the hardware LED count", "conf_leds_optgroup_RPiGPIO": "RPi GPIO", "conf_leds_optgroup_RPiPWM": "RPi PWM", - "conf_leds_optgroup_RPiSPI": "RPi SPI", + "conf_leds_optgroup_SPI": "SPI", "conf_leds_optgroup_debug": "Debug", "conf_leds_optgroup_network": "Network", "conf_leds_optgroup_other": "Other", diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index df0b689b8..d621f62f9 100755 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -18,7 +18,7 @@ var bottomRight2bottomLeft = null; var bottomLeft2topLeft = null; var toggleKeystoneCorrectionArea = false; -var devRPiSPI = ['apa102', 'apa104', 'ws2801', 'lpd6803', 'lpd8806', 'p9813', 'sk6812spi', 'sk6822spi', 'sk9822', 'ws2812spi']; +var devSPI = ['apa102', 'apa104', 'ws2801', 'lpd6803', 'lpd8806', 'p9813', 'sk6812spi', 'sk6822spi', 'sk9822', 'ws2812spi']; var devFTDI = ['apa102_ftdi', 'sk6812_ftdi', 'ws2812_ftdi']; var devRPiPWM = ['ws281x']; var devRPiGPIO = ['piblaster']; @@ -1671,7 +1671,7 @@ $(document).ready(function () { optArr[6] = []; for (var idx = 0; idx < ledDevices.length; idx++) { - if ($.inArray(ledDevices[idx], devRPiSPI) != -1) + if ($.inArray(ledDevices[idx], devSPI) != -1) optArr[0].push(ledDevices[idx]); else if ($.inArray(ledDevices[idx], devRPiPWM) != -1) optArr[1].push(ledDevices[idx]); @@ -1958,8 +1958,8 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { ledTypeGroup = "devNET"; } else if ($.inArray(ledType, devSerial) != -1) { ledTypeGroup = "devSerial"; - } else if ($.inArray(ledType, devRPiSPI) != -1) { - ledTypeGroup = "devRPiSPI"; + } else if ($.inArray(ledType, devSPI) != -1) { + ledTypeGroup = "devSPI"; } else if ($.inArray(ledType, devFTDI) != -1) { ledTypeGroup = "devFTDI"; } else if ($.inArray(ledType, devRPiGPIO) != -1) { @@ -2140,7 +2140,7 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { } break; - case "devRPiSPI": + case "devSPI": case "devRPiGPIO": key = "output"; diff --git a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp index 81e8dadc5..03dcd0392 100644 --- a/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp +++ b/libsrc/leddevice/dev_ftdi/LedDeviceSk6812_ftdi.cpp @@ -2,6 +2,7 @@ LedDeviceSk6812_ftdi::LedDeviceSk6812_ftdi(const QJsonObject &deviceConfig) : ProviderFtdi(deviceConfig), + _whiteAlgorithm(RGBW::WhiteAlgorithm::INVALID), SPI_BYTES_PER_COLOUR(4), bitpair_to_byte{ 0b10001000, @@ -25,21 +26,30 @@ bool LedDeviceSk6812_ftdi::init(const QJsonObject &deviceConfig) if (ProviderFtdi::init(deviceConfig)) { _brightnessControlMaxLevel = deviceConfig["brightnessControlMaxLevel"].toInt(255); - Info(_log, "[%s] Setting maximum brightness to [%d]", QSTRING_CSTR(_activeDeviceType), _brightnessControlMaxLevel); + Info(_log, "[%s] Setting maximum brightness to [%d]", QSTRING_CSTR(_activeDeviceType), _brightnessControlMaxLevel); - QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off"); + QString whiteAlgorithm = deviceConfig["whiteAlgorithm"].toString("white_off"); _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm); + if (_whiteAlgorithm == RGBW::WhiteAlgorithm::INVALID) + { + QString errortext = QString ("unknown whiteAlgorithm: %1").arg(whiteAlgorithm); + this->setInError(errortext); + isInitOK = false; + } + else + { - Debug(_log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm)); + Debug(_log, "whiteAlgorithm : %s", QSTRING_CSTR(whiteAlgorithm)); - WarningIf((_baudRate_Hz < 2050000 || _baudRate_Hz > 3750000), _log, "Baud rate %d outside recommended range (2050000 -> 3750000)", _baudRate_Hz); + WarningIf((_baudRate_Hz < 2050000 || _baudRate_Hz > 3750000), _log, "Baud rate %d outside recommended range (2050000 -> 3750000)", _baudRate_Hz); - const int SPI_FRAME_END_LATCH_BYTES = 3; - _ledBuffer.resize(_ledRGBWCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); + const int SPI_FRAME_END_LATCH_BYTES = 3; + _ledBuffer.resize(_ledRGBWCount * SPI_BYTES_PER_COLOUR + SPI_FRAME_END_LATCH_BYTES, 0x00); - isInitOK = true; + isInitOK = true; + } } return isInitOK; } diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 77afaf89b..3dcfc9e70 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -13,18 +13,18 @@ namespace Pin { - // enumerate the AD bus for convenience. - enum bus_t - { - SK = 0x01, // ADBUS0, SPI data clock - DO = 0x02, // ADBUS1, SPI data out - CS = 0x08, // ADBUS3, SPI chip select, active low - }; +// enumerate the AD bus for convenience. +enum bus_t +{ + SK = 0x01, // ADBUS0, SPI data clock + DO = 0x02, // ADBUS1, SPI data out + CS = 0x08, // ADBUS3, SPI chip select, active low +}; } -const unsigned char pinInitialState = Pin::CS; +const uint8_t pinInitialState = Pin::CS; // Use these pins as outputs -const unsigned char pinDirection = Pin::SK | Pin::DO | Pin::CS; +const uint8_t pinDirection = Pin::SK | Pin::DO | Pin::CS; const QString ProviderFtdi::AUTO_SETTING = QString("auto"); @@ -56,43 +56,49 @@ int ProviderFtdi::open() { int rc = 0; - _ftdic = ftdi_new(); + _ftdic = ftdi_new(); - Debug(_log, "Opening FTDI device=%s", QSTRING_CSTR(_deviceName)); + if (ftdi_init(_ftdic) < 0) + { + _ftdic = nullptr; + setInError("Could not initialize the ftdi library"); + return -1; + } - FTDI_CHECK_RESULT((rc = ftdi_usb_open_string(_ftdic, QSTRING_CSTR(_deviceName))) < 0); - /* doing this disable resets things if they were in a bad state */ - FTDI_CHECK_RESULT((rc = ftdi_disable_bitbang(_ftdic)) < 0); - FTDI_CHECK_RESULT((rc = ftdi_setflowctrl(_ftdic, SIO_DISABLE_FLOW_CTRL)) < 0); - FTDI_CHECK_RESULT((rc = ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET)) < 0); - FTDI_CHECK_RESULT((rc = ftdi_set_bitmode(_ftdic, 0xff, BITMODE_MPSSE)) < 0); + Debug(_log, "Opening FTDI device=%s", QSTRING_CSTR(_deviceName)); + FTDI_CHECK_RESULT((rc = ftdi_usb_open_string(_ftdic, QSTRING_CSTR(_deviceName))) < 0); + /* doing this disable resets things if they were in a bad state */ + FTDI_CHECK_RESULT((rc = ftdi_disable_bitbang(_ftdic)) < 0); + FTDI_CHECK_RESULT((rc = ftdi_setflowctrl(_ftdic, SIO_DISABLE_FLOW_CTRL)) < 0); + FTDI_CHECK_RESULT((rc = ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET)) < 0); + FTDI_CHECK_RESULT((rc = ftdi_set_bitmode(_ftdic, 0xff, BITMODE_MPSSE)) < 0); - double reference_clock = 60e6; - int divisor = (reference_clock / 2 / _baudRate_Hz) - 1; - std::vector buf = { - DIS_DIV_5, - TCK_DIVISOR, - static_cast(divisor), - static_cast(divisor >> 8), - SET_BITS_LOW, // opcode: set low bits (ADBUS[0-7] - pinInitialState, // argument: inital pin state - pinDirection - }; + double reference_clock = 60e6; + int divisor = (reference_clock / 2 / _baudRate_Hz) - 1; + std::vector buf = { + DIS_DIV_5, + TCK_DIVISOR, + static_cast(divisor), + static_cast(divisor >> 8), + SET_BITS_LOW, // opcode: set low bits (ADBUS[0-7] + pinInitialState, // argument: inital pin state + pinDirection + }; - FTDI_CHECK_RESULT((rc = ftdi_write_data(_ftdic, buf.data(), buf.size())) != buf.size()); + FTDI_CHECK_RESULT((rc = ftdi_write_data(_ftdic, buf.data(), buf.size())) != buf.size()); - _isDeviceReady = true; - return rc; + _isDeviceReady = true; + return rc; } int ProviderFtdi::close() { if (_ftdic != nullptr) { Debug(_log, "Closing FTDI device"); -// Delay to give time to push color black from writeBlack() into the led, -// otherwise frame transmission will be terminated half way through - wait(30); + // Delay to give time to push color black from writeBlack() into the led, + // otherwise frame transmission will be terminated half way through + wait(30); ftdi_set_bitmode(_ftdic, 0x00, BITMODE_RESET); ftdi_usb_close(_ftdic); ftdi_free(_ftdic); @@ -110,25 +116,24 @@ void ProviderFtdi::setInError(const QString &errorMsg, bool isRecoverable) int ProviderFtdi::writeBytes(const qint64 size, const uint8_t *data) { - int rc; - int count_arg = size - 1; + int rc; + int count_arg = size - 1; std::vector buf = { - SET_BITS_LOW, - pinInitialState & ~Pin::CS, - pinDirection, - MPSSE_DO_WRITE | MPSSE_WRITE_NEG, - static_cast(count_arg), - static_cast(count_arg >> 8), -// LED's data will be inserted here - SET_BITS_LOW, - pinInitialState | Pin::CS, - pinDirection - }; - // insert before last SET_BITS_LOW command - // SET_BITS_LOW takes 2 arguments, so we're inserting data in -3 position from the end - buf.insert(buf.end() - 3, &data[0], &data[size]); - - FTDI_CHECK_RESULT((rc = ftdi_write_data(_ftdic, buf.data(), buf.size())) != buf.size()); + SET_BITS_LOW, + pinInitialState & ~Pin::CS, + pinDirection, + MPSSE_DO_WRITE | MPSSE_WRITE_NEG, + static_cast(count_arg), + static_cast(count_arg >> 8), + SET_BITS_LOW, + pinInitialState | Pin::CS, + pinDirection + }; + // insert before last SET_BITS_LOW command + // SET_BITS_LOW takes 2 arguments, so we're inserting data in -3 position from the end + buf.insert(buf.end() - 3, &data[0], &data[size]); + + FTDI_CHECK_RESULT((rc = ftdi_write_data(_ftdic, buf.data(), buf.size())) != buf.size()); return rc; } diff --git a/libsrc/leddevice/schemas/schema-sk6812spi.json b/libsrc/leddevice/schemas/schema-sk6812spi.json index 49b7fef75..41cd5bf11 100644 --- a/libsrc/leddevice/schemas/schema-sk6812spi.json +++ b/libsrc/leddevice/schemas/schema-sk6812spi.json @@ -22,10 +22,30 @@ "whiteAlgorithm": { "type": "string", "title":"edt_dev_spec_whiteLedAlgor_title", - "enum" : ["subtract_minimum","sub_min_cool_adjust","sub_min_warm_adjust","white_off"], + "enum" : [ + "subtract_minimum", + "sub_min_cool_adjust", + "sub_min_warm_adjust", + "cold_white", + "neutral_white", + "auto", + "auto_max", + "auto_accurate", + "white_off" + ], "default": "subtract_minimum", "options" : { - "enum_titles" : ["edt_dev_enum_subtract_minimum", "edt_dev_enum_sub_min_cool_adjust","edt_dev_enum_sub_min_warm_adjust", "edt_dev_enum_white_off"] + "enum_titles" : [ + "edt_dev_enum_subtract_minimum", + "edt_dev_enum_sub_min_cool_adjust", + "edt_dev_enum_sub_min_warm_adjust", + "edt_dev_enum_cold_white", + "edt_dev_enum_neutral_white", + "edt_dev_enum_auto", + "edt_dev_enum_auto_max", + "edt_dev_enum_auto_accurate", + "edt_dev_enum_white_off" + ] }, "propertyOrder" : 4 }, diff --git a/libsrc/leddevice/schemas/schema-ws281x.json b/libsrc/leddevice/schemas/schema-ws281x.json index 2ccfb16d0..1af09eee4 100644 --- a/libsrc/leddevice/schemas/schema-ws281x.json +++ b/libsrc/leddevice/schemas/schema-ws281x.json @@ -43,10 +43,30 @@ "whiteAlgorithm": { "type": "string", "title":"edt_dev_spec_whiteLedAlgor_title", - "enum" : ["subtract_minimum","sub_min_cool_adjust","sub_min_warm_adjust","white_off"], + "enum" : [ + "subtract_minimum", + "sub_min_cool_adjust", + "sub_min_warm_adjust", + "cold_white", + "neutral_white", + "auto", + "auto_max", + "auto_accurate", + "white_off" + ], "default": "subtract_minimum", "options" : { - "enum_titles" : ["edt_dev_enum_subtract_minimum", "edt_dev_enum_sub_min_cool_adjust","edt_dev_enum_sub_min_warm_adjust", "edt_dev_enum_white_off"] + "enum_titles" : [ + "edt_dev_enum_subtract_minimum", + "edt_dev_enum_sub_min_cool_adjust", + "edt_dev_enum_sub_min_warm_adjust", + "edt_dev_enum_cold_white", + "edt_dev_enum_neutral_white", + "edt_dev_enum_auto", + "edt_dev_enum_auto_max", + "edt_dev_enum_auto_accurate", + "edt_dev_enum_white_off" + ] }, "propertyOrder" : 7 }, From fb574b812f7cd9ed0d01a51dc59d8ec37f791911 Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Sun, 26 May 2024 17:50:44 +0200 Subject: [PATCH 44/48] MacOS build - install libftdi --- .github/workflows/qt5_6.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/qt5_6.yml b/.github/workflows/qt5_6.yml index 9cd59df80..789e8a6c9 100644 --- a/.github/workflows/qt5_6.yml +++ b/.github/workflows/qt5_6.yml @@ -117,7 +117,7 @@ jobs: echo '::group::Update/Install dependencies' brew untap --force homebrew/core homebrew/cask brew update || true - brew install qt${{ inputs.qt_version }} vulkan-headers ninja || true + brew install qt${{ inputs.qt_version }} vulkan-headers ninja libftdi || true echo '::endgroup::' - name: 👷 Build From bd08cabe80926c8aebf4ecedb27fb5a6e6b6cdd4 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 May 2024 19:51:01 +0200 Subject: [PATCH 45/48] Disable device's readiness before closing --- libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp index 3dcfc9e70..ce168821c 100644 --- a/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp +++ b/libsrc/leddevice/dev_ftdi/ProviderFtdi.cpp @@ -94,6 +94,7 @@ int ProviderFtdi::open() int ProviderFtdi::close() { + LedDevice::close(); if (_ftdic != nullptr) { Debug(_log, "Closing FTDI device"); // Delay to give time to push color black from writeBlack() into the led, @@ -104,7 +105,7 @@ int ProviderFtdi::close() ftdi_free(_ftdic); _ftdic = nullptr; } - return LedDevice::close(); + return 0; } void ProviderFtdi::setInError(const QString &errorMsg, bool isRecoverable) From cd688beca7ec344488811dcebb1ca7deee058166 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Mon, 27 May 2024 20:18:00 +0200 Subject: [PATCH 46/48] fix master branch merge --- .github/workflows/qt5_6.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/qt5_6.yml b/.github/workflows/qt5_6.yml index fe5fa41d9..d47c7bb8b 100644 --- a/.github/workflows/qt5_6.yml +++ b/.github/workflows/qt5_6.yml @@ -117,7 +117,7 @@ jobs: echo '::group::Update/Install dependencies' brew untap --force homebrew/core homebrew/cask brew update || true - brew install qt@${{ inputs.qt_version }} vulkan-headers ninja || true + brew install qt@${{ inputs.qt_version }} vulkan-headers ninja libftdi || true echo '::endgroup::' - name: 👷 Build From 0ef3f14f877786636280ebdd4591c46de1d15773 Mon Sep 17 00:00:00 2001 From: LordGrey Date: Thu, 30 May 2024 14:02:54 +0200 Subject: [PATCH 47/48] Correct CodeQL finding --- assets/webconfig/js/content_leds.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/webconfig/js/content_leds.js b/assets/webconfig/js/content_leds.js index d621f62f9..9ddf7bcfe 100755 --- a/assets/webconfig/js/content_leds.js +++ b/assets/webconfig/js/content_leds.js @@ -2104,7 +2104,7 @@ var updateOutputSelectList = function (ledType, discoveryInfo) { var title = "FTDI"; if (device.manufacturer) { - title = device.manufacturer + title = device.manufacturer; } if (device.serialNumber) { From f245fdb0c40567fedfba6b6137e262b3b9bc4e9d Mon Sep 17 00:00:00 2001 From: LordGrey Date: Thu, 30 May 2024 14:07:29 +0200 Subject: [PATCH 48/48] Update change-log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ea84fc11..547d1a85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Support for ftdi chip based LED-devices with ws2812, sk6812 apa102 LED types (Many thanks to @nurikk) (#1746) - Support gaps on Matrix Layout (#1696) **JSON-API**