2018-04-13 00:28:29 +02:00
|
|
|
//this code is a modified version of https://github.com/Makuna/NeoPixelBus/issues/103
|
2018-09-04 15:51:38 +02:00
|
|
|
#ifndef NpbWrapper_h
|
|
|
|
#define NpbWrapper_h
|
2018-04-13 00:28:29 +02:00
|
|
|
|
2018-11-18 00:31:45 +01:00
|
|
|
//PIN CONFIGURATION
|
2020-02-22 17:20:34 +01:00
|
|
|
#ifndef LEDPIN
|
2020-03-21 00:57:54 +01:00
|
|
|
#define LEDPIN 2 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos)
|
2020-02-22 17:20:34 +01:00
|
|
|
#endif
|
2020-01-13 18:24:23 +01:00
|
|
|
//#define USE_APA102 // Uncomment for using APA102 LEDs.
|
|
|
|
//#define USE_WS2801 // Uncomment for using WS2801 LEDs (make sure you have NeoPixelBus v2.5.6 or newer)
|
|
|
|
//#define USE_LPD8806 // Uncomment for using LPD8806
|
2020-04-10 12:30:08 +02:00
|
|
|
//#define USE_P9813 // Uncomment for using P9813 LEDs (make sure you have NeoPixelBus v2.5.8 or newer)
|
2019-12-19 20:59:36 +01:00
|
|
|
//#define WLED_USE_ANALOG_LEDS //Uncomment for using "dumb" PWM controlled LEDs (see pins below, default R: gpio5, G: 12, B: 15, W: 13)
|
2019-12-19 21:31:14 +01:00
|
|
|
//#define WLED_USE_H801 //H801 controller. Please uncomment #define WLED_USE_ANALOG_LEDS as well
|
2020-01-27 00:45:30 +01:00
|
|
|
//#define WLED_USE_5CH_LEDS //5 Channel H801 for cold and warm white
|
2019-05-22 00:23:09 +02:00
|
|
|
|
2020-02-24 18:48:21 +01:00
|
|
|
#ifndef BTNPIN
|
2019-12-19 20:59:36 +01:00
|
|
|
#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
|
2020-02-24 18:48:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef IR_PIN
|
2019-12-19 20:59:36 +01:00
|
|
|
#define IR_PIN 4 //infrared pin (-1 to disable) MagicHome: 4, H801 Wifi: 0
|
2020-02-24 18:48:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef RLYPIN
|
2019-12-19 20:59:36 +01:00
|
|
|
#define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,...
|
2020-02-24 18:48:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef AUXPIN
|
2019-12-19 20:59:36 +01:00
|
|
|
#define AUXPIN -1 //debug auxiliary output pin (-1 to disable)
|
2020-02-24 18:48:21 +01:00
|
|
|
#endif
|
2019-05-22 00:23:09 +02:00
|
|
|
|
2020-02-24 18:48:21 +01:00
|
|
|
#ifndef RLYMDE
|
2020-02-25 02:25:17 +01:00
|
|
|
#define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on
|
2020-02-24 18:48:21 +01:00
|
|
|
#endif
|
2019-05-22 00:23:09 +02:00
|
|
|
|
2019-12-19 20:59:36 +01:00
|
|
|
//END CONFIGURATION
|
2019-05-22 00:23:09 +02:00
|
|
|
|
2020-04-10 12:30:08 +02:00
|
|
|
#if defined(USE_APA102) || defined(USE_WS2801) || defined(USE_LPD8806) || defined(USE_P9813)
|
2019-05-01 03:09:08 +02:00
|
|
|
#define CLKPIN 0
|
|
|
|
#define DATAPIN 2
|
2019-05-01 16:52:22 +02:00
|
|
|
#if BTNPIN == CLKPIN || BTNPIN == DATAPIN
|
|
|
|
#undef BTNPIN // Deactivate button pin if it conflicts with one of the APA102 pins.
|
|
|
|
#endif
|
2019-05-01 03:09:08 +02:00
|
|
|
#endif
|
2019-05-01 16:52:22 +02:00
|
|
|
|
2019-12-18 15:35:32 +01:00
|
|
|
#ifdef WLED_USE_ANALOG_LEDS
|
|
|
|
//PWM pins - PINs 15,13,12,14 (W2 = 04)are used with H801 Wifi LED Controller
|
|
|
|
#ifdef WLED_USE_H801
|
|
|
|
#define RPIN 15 //R pin for analog LED strip
|
|
|
|
#define GPIN 13 //G pin for analog LED strip
|
|
|
|
#define BPIN 12 //B pin for analog LED strip
|
2020-01-28 13:48:59 +01:00
|
|
|
#define WPIN 14 //W pin for analog LED strip
|
2019-12-19 20:59:36 +01:00
|
|
|
#define W2PIN 04 //W2 pin for analog LED strip
|
|
|
|
#undef BTNPIN
|
|
|
|
#undef IR_PIN
|
|
|
|
#define IR_PIN 0 //infrared pin (-1 to disable) MagicHome: 4, H801 Wifi: 0
|
2019-12-18 15:35:32 +01:00
|
|
|
#else
|
2019-11-05 15:52:18 +01:00
|
|
|
//PWM pins - PINs 5,12,13,15 are used with Magic Home LED Controller
|
2019-12-18 15:35:32 +01:00
|
|
|
#define RPIN 5 //R pin for analog LED strip
|
|
|
|
#define GPIN 12 //G pin for analog LED strip
|
|
|
|
#define BPIN 15 //B pin for analog LED strip
|
2020-01-28 13:48:59 +01:00
|
|
|
#define WPIN 13 //W pin for analog LED strip
|
2019-12-18 15:35:32 +01:00
|
|
|
#endif
|
2019-12-19 20:59:36 +01:00
|
|
|
#undef RLYPIN
|
|
|
|
#define RLYPIN -1 //disable as pin 12 is used by analog LEDs
|
2019-11-05 15:52:18 +01:00
|
|
|
#endif
|
2018-11-18 00:31:45 +01:00
|
|
|
|
2018-04-13 00:28:29 +02:00
|
|
|
//automatically uses the right driver method for each platform
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
2019-09-26 14:02:58 +02:00
|
|
|
#ifdef USE_APA102
|
|
|
|
#define PIXELMETHOD DotStarMethod
|
2020-01-12 15:16:45 +01:00
|
|
|
#elif defined(USE_WS2801)
|
|
|
|
#define PIXELMETHOD NeoWs2801Method
|
|
|
|
#elif defined(USE_LPD8806)
|
|
|
|
#define PIXELMETHOD Lpd8806Method
|
2020-04-10 12:30:08 +02:00
|
|
|
#elif defined(USE_P9813)
|
|
|
|
#define PIXELMETHOD P9813Method
|
2019-09-26 14:02:58 +02:00
|
|
|
#else
|
|
|
|
#define PIXELMETHOD NeoEsp32Rmt0Ws2812xMethod
|
|
|
|
#endif
|
2018-09-04 15:51:38 +02:00
|
|
|
#else //esp8266
|
2018-11-09 17:00:36 +01:00
|
|
|
//autoselect the right method depending on strip pin
|
2019-05-01 03:09:08 +02:00
|
|
|
#ifdef USE_APA102
|
|
|
|
#define PIXELMETHOD DotStarMethod
|
2020-01-12 15:16:45 +01:00
|
|
|
#elif defined(USE_WS2801)
|
|
|
|
#define PIXELMETHOD NeoWs2801Method
|
|
|
|
#elif defined(USE_LPD8806)
|
|
|
|
#define PIXELMETHOD Lpd8806Method
|
2020-04-10 12:30:08 +02:00
|
|
|
#elif defined(USE_P9813)
|
|
|
|
#define PIXELMETHOD P9813Method
|
2019-05-01 03:09:08 +02:00
|
|
|
#elif LEDPIN == 2
|
2019-03-05 10:59:15 +01:00
|
|
|
#define PIXELMETHOD NeoEsp8266Uart1Ws2813Method //if you get an error here, try to change to NeoEsp8266UartWs2813Method or update Neopixelbus
|
2018-11-09 17:00:36 +01:00
|
|
|
#elif LEDPIN == 3
|
|
|
|
#define PIXELMETHOD NeoEsp8266Dma800KbpsMethod
|
|
|
|
#else
|
2019-03-07 23:22:52 +01:00
|
|
|
#define PIXELMETHOD NeoEsp8266BitBang800KbpsMethod
|
2018-11-09 17:00:36 +01:00
|
|
|
#pragma message "Software BitBang will be used because of your selected LED pin. This may cause flicker. Use GPIO 2 or 3 for best results."
|
|
|
|
#endif
|
2018-04-13 00:28:29 +02:00
|
|
|
#endif
|
2018-09-04 15:51:38 +02:00
|
|
|
|
2018-11-28 12:24:32 +01:00
|
|
|
|
|
|
|
//you can now change the color order in the web settings
|
2019-05-01 03:09:08 +02:00
|
|
|
#ifdef USE_APA102
|
|
|
|
#define PIXELFEATURE3 DotStarBgrFeature
|
|
|
|
#define PIXELFEATURE4 DotStarLbgrFeature
|
2020-01-12 15:16:45 +01:00
|
|
|
#elif defined(USE_LPD8806)
|
|
|
|
#define PIXELFEATURE3 Lpd8806GrbFeature
|
2020-04-10 12:30:08 +02:00
|
|
|
#define PIXELFEATURE4 Lpd8806GrbFeature
|
|
|
|
#elif defined(USE_P9813)
|
|
|
|
#define PIXELFEATURE3 P9813BgrFeature
|
|
|
|
#define PIXELFEATURE4 NeoGrbwFeature
|
2019-05-01 03:09:08 +02:00
|
|
|
#else
|
|
|
|
#define PIXELFEATURE3 NeoGrbFeature
|
|
|
|
#define PIXELFEATURE4 NeoGrbwFeature
|
|
|
|
#endif
|
2018-11-28 12:24:32 +01:00
|
|
|
|
2018-04-13 00:28:29 +02:00
|
|
|
|
|
|
|
#include <NeoPixelBrightnessBus.h>
|
|
|
|
|
|
|
|
enum NeoPixelType
|
|
|
|
{
|
|
|
|
NeoPixelType_None = 0,
|
|
|
|
NeoPixelType_Grb = 1,
|
|
|
|
NeoPixelType_Grbw = 2,
|
|
|
|
NeoPixelType_End = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
class NeoPixelWrapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NeoPixelWrapper() :
|
2018-11-09 17:00:36 +01:00
|
|
|
// initialize each member to null
|
|
|
|
_pGrb(NULL),
|
|
|
|
_pGrbw(NULL),
|
|
|
|
_type(NeoPixelType_None)
|
2018-04-13 00:28:29 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~NeoPixelWrapper()
|
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
2018-09-04 15:51:38 +02:00
|
|
|
void Begin(NeoPixelType type, uint16_t countPixels)
|
2018-04-13 00:28:29 +02:00
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
_type = type;
|
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
switch (_type)
|
|
|
|
{
|
2018-04-13 00:28:29 +02:00
|
|
|
case NeoPixelType_Grb:
|
2020-04-10 12:30:08 +02:00
|
|
|
#if defined(USE_APA102) || defined(USE_WS2801) || defined(USE_LPD8806) || defined(USE_P9813)
|
2019-05-01 03:09:08 +02:00
|
|
|
_pGrb = new NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>(countPixels, CLKPIN, DATAPIN);
|
|
|
|
#else
|
2018-09-04 15:51:38 +02:00
|
|
|
_pGrb = new NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>(countPixels, LEDPIN);
|
2019-05-01 03:09:08 +02:00
|
|
|
#endif
|
2018-04-13 00:28:29 +02:00
|
|
|
_pGrb->Begin();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NeoPixelType_Grbw:
|
2020-04-10 12:30:08 +02:00
|
|
|
#if defined(USE_APA102) || defined(USE_WS2801) || defined(USE_LPD8806) || defined(USE_P9813)
|
2019-05-01 03:09:08 +02:00
|
|
|
_pGrbw = new NeoPixelBrightnessBus<PIXELFEATURE4,PIXELMETHOD>(countPixels, CLKPIN, DATAPIN);
|
|
|
|
#else
|
2018-09-04 15:51:38 +02:00
|
|
|
_pGrbw = new NeoPixelBrightnessBus<PIXELFEATURE4,PIXELMETHOD>(countPixels, LEDPIN);
|
2019-05-01 03:09:08 +02:00
|
|
|
#endif
|
2018-04-13 00:28:29 +02:00
|
|
|
_pGrbw->Begin();
|
2019-12-30 17:34:15 +01:00
|
|
|
break;
|
2018-04-13 00:28:29 +02:00
|
|
|
}
|
2019-12-30 17:34:15 +01:00
|
|
|
|
2020-01-07 23:58:15 +01:00
|
|
|
#ifdef WLED_USE_ANALOG_LEDS
|
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
|
|
|
ledcSetup(0, 5000, 8);
|
|
|
|
ledcAttachPin(RPIN, 0);
|
|
|
|
ledcSetup(1, 5000, 8);
|
|
|
|
ledcAttachPin(GPIN, 1);
|
|
|
|
ledcSetup(2, 5000, 8);
|
|
|
|
ledcAttachPin(BPIN, 2);
|
|
|
|
if(_type == NeoPixelType_Grbw)
|
|
|
|
{
|
|
|
|
ledcSetup(3, 5000, 8);
|
|
|
|
ledcAttachPin(WPIN, 3);
|
|
|
|
#ifdef WLED_USE_5CH_LEDS
|
|
|
|
ledcSetup(4, 5000, 8);
|
|
|
|
ledcAttachPin(W2PIN, 4);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#else // ESP8266
|
2020-02-22 17:20:34 +01:00
|
|
|
//init PWM pins
|
2020-01-07 23:58:15 +01:00
|
|
|
pinMode(RPIN, OUTPUT);
|
|
|
|
pinMode(GPIN, OUTPUT);
|
|
|
|
pinMode(BPIN, OUTPUT);
|
|
|
|
if(_type == NeoPixelType_Grbw)
|
|
|
|
{
|
|
|
|
pinMode(WPIN, OUTPUT);
|
|
|
|
#ifdef WLED_USE_5CH_LEDS
|
|
|
|
pinMode(W2PIN, OUTPUT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
analogWriteRange(255); //same range as one RGB channel
|
|
|
|
analogWriteFreq(880); //PWM frequency proven as good for LEDs
|
|
|
|
#endif
|
2019-12-30 17:34:15 +01:00
|
|
|
#endif
|
2018-04-13 00:28:29 +02:00
|
|
|
}
|
|
|
|
|
2019-12-18 15:35:32 +01:00
|
|
|
#ifdef WLED_USE_ANALOG_LEDS
|
|
|
|
void SetRgbwPwm(uint8_t r, uint8_t g, uint8_t b, uint8_t w, uint8_t w2=0)
|
2019-11-05 15:52:18 +01:00
|
|
|
{
|
2020-01-07 23:58:15 +01:00
|
|
|
#ifdef ARDUINO_ARCH_ESP32
|
2020-02-22 17:20:34 +01:00
|
|
|
ledcWrite(0, r);
|
|
|
|
ledcWrite(1, g);
|
|
|
|
ledcWrite(2, b);
|
2020-01-07 23:58:15 +01:00
|
|
|
switch (_type) {
|
|
|
|
case NeoPixelType_Grb: break;
|
|
|
|
#ifdef WLED_USE_5CH_LEDS
|
|
|
|
case NeoPixelType_Grbw: ledcWrite(3, w); ledcWrite(4, w2); break;
|
|
|
|
#else
|
|
|
|
case NeoPixelType_Grbw: ledcWrite(3, w); break;
|
|
|
|
#endif
|
|
|
|
}
|
2020-02-22 17:20:34 +01:00
|
|
|
#else // ESP8266
|
2020-01-07 23:58:15 +01:00
|
|
|
analogWrite(RPIN, r);
|
|
|
|
analogWrite(GPIN, g);
|
|
|
|
analogWrite(BPIN, b);
|
|
|
|
switch (_type) {
|
|
|
|
case NeoPixelType_Grb: break;
|
|
|
|
#ifdef WLED_USE_5CH_LEDS
|
|
|
|
case NeoPixelType_Grbw: analogWrite(WPIN, w); analogWrite(W2PIN, w2); break;
|
|
|
|
#else
|
|
|
|
case NeoPixelType_Grbw: analogWrite(WPIN, w); break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2019-11-05 15:52:18 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-13 00:28:29 +02:00
|
|
|
void Show()
|
|
|
|
{
|
2019-11-05 15:52:18 +01:00
|
|
|
byte b;
|
2018-11-09 17:00:36 +01:00
|
|
|
switch (_type)
|
|
|
|
{
|
2019-12-19 20:59:36 +01:00
|
|
|
case NeoPixelType_Grb: _pGrb->Show(); break;
|
|
|
|
case NeoPixelType_Grbw: _pGrbw->Show(); break;
|
2018-04-13 00:28:29 +02:00
|
|
|
}
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2018-04-13 00:28:29 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
void SetPixelColor(uint16_t indexPixel, RgbwColor color)
|
|
|
|
{
|
|
|
|
switch (_type) {
|
2019-11-05 15:52:18 +01:00
|
|
|
case NeoPixelType_Grb: {
|
2019-12-19 20:59:36 +01:00
|
|
|
_pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B));
|
2019-11-05 15:52:18 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NeoPixelType_Grbw: {
|
2020-01-13 18:23:06 +01:00
|
|
|
#ifdef USE_LPD8806
|
|
|
|
_pGrbw->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B));
|
|
|
|
#else
|
2019-12-19 20:59:36 +01:00
|
|
|
_pGrbw->SetPixelColor(indexPixel, color);
|
2020-01-13 18:23:06 +01:00
|
|
|
#endif
|
2019-11-05 15:52:18 +01:00
|
|
|
}
|
|
|
|
break;
|
2018-04-13 00:28:29 +02:00
|
|
|
}
|
2019-12-19 20:59:36 +01:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2018-04-13 00:28:29 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
void SetBrightness(byte b)
|
|
|
|
{
|
|
|
|
switch (_type) {
|
|
|
|
case NeoPixelType_Grb: _pGrb->SetBrightness(b); break;
|
|
|
|
case NeoPixelType_Grbw:_pGrbw->SetBrightness(b); break;
|
2018-04-13 00:28:29 +02:00
|
|
|
}
|
2018-11-09 17:00:36 +01:00
|
|
|
}
|
2018-04-13 00:28:29 +02:00
|
|
|
|
2018-11-09 17:00:36 +01:00
|
|
|
// NOTE: Due to feature differences, some support RGBW but the method name
|
|
|
|
// here needs to be unique, thus GetPixeColorRgbw
|
|
|
|
RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const
|
|
|
|
{
|
|
|
|
switch (_type) {
|
|
|
|
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
|
|
|
|
case NeoPixelType_Grbw: return _pGrbw->GetPixelColor(indexPixel); break;
|
2018-04-13 00:28:29 +02:00
|
|
|
}
|
2018-11-09 17:00:36 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2018-04-13 00:28:29 +02:00
|
|
|
|
2020-02-17 11:01:05 +01:00
|
|
|
uint8_t* GetPixels(void)
|
|
|
|
{
|
|
|
|
switch (_type) {
|
|
|
|
case NeoPixelType_Grb: return _pGrb->Pixels(); break;
|
|
|
|
case NeoPixelType_Grbw: return _pGrbw->Pixels(); break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 00:28:29 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
NeoPixelType _type;
|
|
|
|
|
|
|
|
// have a member for every possible type
|
|
|
|
NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>* _pGrb;
|
|
|
|
NeoPixelBrightnessBus<PIXELFEATURE4,PIXELMETHOD>* _pGrbw;
|
|
|
|
|
|
|
|
void cleanup()
|
|
|
|
{
|
|
|
|
switch (_type) {
|
|
|
|
case NeoPixelType_Grb: delete _pGrb ; _pGrb = NULL; break;
|
|
|
|
case NeoPixelType_Grbw: delete _pGrbw; _pGrbw = NULL; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-09-04 15:51:38 +02:00
|
|
|
#endif
|