Merge pull request #560 from penfold42/master

Add invert option for ws281x

Former-commit-id: 999f822a22aae7158f5d62afef65b045190e8f99
This commit is contained in:
brindosch 2016-03-22 23:04:33 +01:00
commit dcd518b6cc
3 changed files with 10 additions and 6 deletions

View File

@ -324,12 +324,13 @@ 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 pwmchannel = deviceConfig.get("pwmchannel", 0).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; device = ledDeviceWS281x;
} }
#endif #endif

View File

@ -3,7 +3,7 @@
#include "LedDeviceWS281x.h" #include "LedDeviceWS281x.h"
// Constructor // 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; initialized = false;
led_string.freq = freq; led_string.freq = freq;
@ -14,13 +14,13 @@ LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t
} }
chan = pwmchannel; chan = pwmchannel;
led_string.channel[chan].gpionum = gpio; 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].count = leds;
led_string.channel[chan].brightness = 255; led_string.channel[chan].brightness = 255;
led_string.channel[chan].strip_type = WS2811_STRIP_RGB; led_string.channel[chan].strip_type = WS2811_STRIP_RGB;
led_string.channel[!chan].gpionum = 0; 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].count = 0;
led_string.channel[!chan].brightness = 0; led_string.channel[!chan].brightness = 0;
led_string.channel[!chan].strip_type = WS2811_STRIP_RGB; led_string.channel[!chan].strip_type = WS2811_STRIP_RGB;

View File

@ -16,8 +16,11 @@ 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 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 /// Destructor of the LedDevice, waits for DMA to complete and then cleans up