Added support to invert the WS281x LED data.

This supports 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: 44ab64329641f0e1450174314a955d241641d149
This commit is contained in:
penfold42 2016-03-21 15:43:30 +11:00
parent ae218b85ff
commit e352dea7a6
3 changed files with 7 additions and 5 deletions

View File

@ -324,11 +324,12 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
else if (type == "ws281x") else if (type == "ws281x")
{ {
const int gpio = deviceConfig.get("gpio", 18).asInt(); 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 uint32_t freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt();
const int dmanum = deviceConfig.get("dmanum", 5).asInt(); const int dmanum = deviceConfig.get("dmanum", 5).asInt();
const int invert = deviceConfig.get("invert", 0).asInt();
LedDeviceWS281x * ledDeviceWS281x = new LedDeviceWS281x(gpio, leds, freq, dmanum); LedDeviceWS281x * ledDeviceWS281x = new LedDeviceWS281x(gpio, leds, freq, dmanum, invert);
device = ledDeviceWS281x; device = ledDeviceWS281x;
} }
#endif #endif

View File

@ -3,13 +3,13 @@
#include "LedDeviceWS281x.h" #include "LedDeviceWS281x.h"
// Constructor // Constructor
LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum) LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum, const int invert)
{ {
initialized = false; initialized = false;
led_string.freq = freq; led_string.freq = freq;
led_string.dmanum = dmanum; led_string.dmanum = dmanum;
led_string.channel[0].gpionum = gpio; led_string.channel[0].gpionum = gpio;
led_string.channel[0].invert = 0; led_string.channel[0].invert = invert;
led_string.channel[0].count = leds; led_string.channel[0].count = leds;
led_string.channel[0].brightness = 255; led_string.channel[0].brightness = 255;
led_string.channel[0].strip_type = WS2811_STRIP_RGB; led_string.channel[0].strip_type = WS2811_STRIP_RGB;

View File

@ -16,8 +16,9 @@ public:
/// @param leds The number of leds attached to the gpio pin /// @param leds The number of leds attached to the gpio pin
/// @param freq The target frequency for the data line, default is 800000 /// @param freq The target frequency for the data line, default is 800000
/// @param dmanum The DMA channel to use, default is 5 /// @param dmanum The DMA channel to use, default is 5
/// @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); LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum, const int invert);
/// ///
/// Destructor of the LedDevice, waits for DMA to complete and then cleans up /// Destructor of the LedDevice, waits for DMA to complete and then cleans up