From 61430753650ab8888510af7e7f17e56d693841bd Mon Sep 17 00:00:00 2001 From: penfold42 Date: Tue, 22 Mar 2016 23:50:14 +1100 Subject: [PATCH] 1. changed default number of pwm LEDs to 256 2. Adds support for level shifters that invert the data Config option - "invert" (integer) if omitted, do not invert if == 0, do not invert if !=0, invert Former-commit-id: fd5b2863a85b11ac3a8444d1e02822f852feb556 --- libsrc/leddevice/LedDeviceFactory.cpp | 5 +++-- libsrc/leddevice/LedDeviceWS281x.cpp | 6 +++--- libsrc/leddevice/LedDeviceWS281x.h | 5 ++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/libsrc/leddevice/LedDeviceFactory.cpp b/libsrc/leddevice/LedDeviceFactory.cpp index 3c925e8d..a3dd87af 100755 --- a/libsrc/leddevice/LedDeviceFactory.cpp +++ b/libsrc/leddevice/LedDeviceFactory.cpp @@ -324,12 +324,13 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) else if (type == "ws281x") { const int gpio = deviceConfig.get("gpio", 18).asInt(); - const int leds = deviceConfig.get("leds", 12).asInt(); + const int leds = deviceConfig.get("leds", 256).asInt(); const uint32_t freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt(); const int dmanum = deviceConfig.get("dmanum", 5).asInt(); const int pwmchannel = deviceConfig.get("pwmchannel", 0).asInt(); + const int invert = deviceConfig.get("invert", 0).asInt(); - LedDeviceWS281x * ledDeviceWS281x = new LedDeviceWS281x(gpio, leds, freq, dmanum, pwmchannel); + LedDeviceWS281x * ledDeviceWS281x = new LedDeviceWS281x(gpio, leds, freq, dmanum, pwmchannel, invert); device = ledDeviceWS281x; } #endif diff --git a/libsrc/leddevice/LedDeviceWS281x.cpp b/libsrc/leddevice/LedDeviceWS281x.cpp index 3871b553..542ff80c 100644 --- a/libsrc/leddevice/LedDeviceWS281x.cpp +++ b/libsrc/leddevice/LedDeviceWS281x.cpp @@ -3,7 +3,7 @@ #include "LedDeviceWS281x.h" // Constructor -LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum, const int pwmchannel) +LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum, const int pwmchannel, const int invert) { initialized = false; led_string.freq = freq; @@ -14,13 +14,13 @@ LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t } chan = pwmchannel; led_string.channel[chan].gpionum = gpio; - led_string.channel[chan].invert = 0; + led_string.channel[chan].invert = invert; led_string.channel[chan].count = leds; led_string.channel[chan].brightness = 255; led_string.channel[chan].strip_type = WS2811_STRIP_RGB; led_string.channel[!chan].gpionum = 0; - led_string.channel[!chan].invert = 0; + led_string.channel[!chan].invert = invert; led_string.channel[!chan].count = 0; led_string.channel[!chan].brightness = 0; led_string.channel[!chan].strip_type = WS2811_STRIP_RGB; diff --git a/libsrc/leddevice/LedDeviceWS281x.h b/libsrc/leddevice/LedDeviceWS281x.h index 61a58800..29209016 100644 --- a/libsrc/leddevice/LedDeviceWS281x.h +++ b/libsrc/leddevice/LedDeviceWS281x.h @@ -16,8 +16,11 @@ public: /// @param leds The number of leds attached to the gpio pin /// @param freq The target frequency for the data line, default is 800000 /// @param dmanum The DMA channel to use, default is 5 + /// @param pwmchannel The pwm channel to use + /// @param invert Invert the output line to support an inverting level shifter + /// - LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, int dmanum, int pwmchannel); + LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, int dmanum, int pwmchannel, int invert); /// /// Destructor of the LedDevice, waits for DMA to complete and then cleans up