Skip to content

Commit a3bef49

Browse files
authored
Refactored code to improve readability (merge dev PR)
Refactored code to improve readability Fixed non-2-char indentations
2 parents 640188f + a5cf553 commit a3bef49

16 files changed

+1110
-1098
lines changed

wled00/NpbWrapper.h

Lines changed: 82 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,34 @@
1010
//uncomment this if red and green are swapped
1111
//#define SWAPRG
1212

13+
1314
//automatically uses the right driver method for each platform
1415
#ifdef ARDUINO_ARCH_ESP32
15-
#ifdef WORKAROUND_ESP32_BITBANG
16-
#define PIXELMETHOD NeoEsp32BitBangWs2813Method
17-
#pragma message "Software BitBang is used because of your NeoPixelBus version. Look in NpbWrapper.h for instructions on how to mitigate flickering."
18-
#else
19-
#define PIXELMETHOD NeoEsp32RmtWS2813_V3Method
20-
#endif
16+
#ifdef WORKAROUND_ESP32_BITBANG
17+
#define PIXELMETHOD NeoEsp32BitBangWs2813Method
18+
#pragma message "Software BitBang is used because of your NeoPixelBus version. Look in NpbWrapper.h for instructions on how to mitigate flickering."
19+
#else
20+
#define PIXELMETHOD NeoEsp32RmtWS2813_V3Method
21+
#endif
2122
#else //esp8266
22-
//autoselect the right method depending on strip pin
23-
#if LEDPIN == 2
24-
#define PIXELMETHOD NeoEsp8266Uart800KbpsMethod
25-
#elif LEDPIN == 3
26-
#define PIXELMETHOD NeoEsp8266Dma800KbpsMethod
27-
#else
28-
#define PIXELMETHOD NeoEsp8266BitBang800KbpsMethod
29-
#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."
30-
#endif
23+
//autoselect the right method depending on strip pin
24+
#if LEDPIN == 2
25+
#define PIXELMETHOD NeoEsp8266Uart800KbpsMethod
26+
#elif LEDPIN == 3
27+
#define PIXELMETHOD NeoEsp8266Dma800KbpsMethod
28+
#else
29+
#define PIXELMETHOD NeoEsp8266BitBang800KbpsMethod
30+
#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."
31+
#endif
3132
#endif
3233

3334
//handle swapping Red and Green automatically
3435
#ifdef SWAPRG
35-
#define PIXELFEATURE3 NeoRgbFeature
36-
#define PIXELFEATURE4 NeoRgbwFeature
36+
#define PIXELFEATURE3 NeoRgbFeature
37+
#define PIXELFEATURE4 NeoRgbwFeature
3738
#else
38-
#define PIXELFEATURE3 NeoGrbFeature
39-
#define PIXELFEATURE4 NeoGrbwFeature
39+
#define PIXELFEATURE3 NeoGrbFeature
40+
#define PIXELFEATURE4 NeoGrbwFeature
4041
#endif
4142

4243
#include <NeoPixelBrightnessBus.h>
@@ -53,10 +54,10 @@ class NeoPixelWrapper
5354
{
5455
public:
5556
NeoPixelWrapper() :
56-
// initialize each member to null
57-
_pGrb(NULL),
58-
_pGrbw(NULL),
59-
_type(NeoPixelType_None)
57+
// initialize each member to null
58+
_pGrb(NULL),
59+
_pGrbw(NULL),
60+
_type(NeoPixelType_None)
6061
{
6162

6263
}
@@ -71,8 +72,8 @@ class NeoPixelWrapper
7172
cleanup();
7273
_type = type;
7374

74-
switch (_type) {
75-
75+
switch (_type)
76+
{
7677
case NeoPixelType_Grb:
7778
_pGrb = new NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>(countPixels, LEDPIN);
7879
_pGrb->Begin();
@@ -88,23 +89,25 @@ class NeoPixelWrapper
8889
void Show()
8990
{
9091
#ifdef ARDUINO_ARCH_ESP32
91-
#ifdef WORKAROUND_ESP32_BITBANG
92-
delay(1);
93-
portDISABLE_INTERRUPTS(); //this is a workaround to prevent flickering (see https://github.com/adafruit/Adafruit_NeoPixel/issues/139)
94-
#endif
92+
#ifdef WORKAROUND_ESP32_BITBANG
93+
delay(1);
94+
portDISABLE_INTERRUPTS(); //this is a workaround to prevent flickering (see https://github.com/adafruit/Adafruit_NeoPixel/issues/139)
95+
#endif
9596
#endif
9697

97-
switch (_type) {
98+
switch (_type)
99+
{
98100
case NeoPixelType_Grb: _pGrb->Show(); break;
99101
case NeoPixelType_Grbw: _pGrbw->Show(); break;
100102
}
101103

102104
#ifdef ARDUINO_ARCH_ESP32
103-
#ifdef WORKAROUND_ESP32_BITBANG
104-
portENABLE_INTERRUPTS();
105-
#endif
105+
#ifdef WORKAROUND_ESP32_BITBANG
106+
portENABLE_INTERRUPTS();
107+
#endif
106108
#endif
107109
}
110+
108111
bool CanShow() const
109112
{
110113
switch (_type) {
@@ -113,65 +116,65 @@ class NeoPixelWrapper
113116
}
114117
}
115118

116-
void SetPixelColor(uint16_t indexPixel, RgbColor color)
117-
{
118-
switch (_type) {
119-
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, color); break;
120-
case NeoPixelType_Grbw:_pGrbw->SetPixelColor(indexPixel, color); break;
121-
}
119+
void SetPixelColor(uint16_t indexPixel, RgbColor color)
120+
{
121+
switch (_type) {
122+
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, color); break;
123+
case NeoPixelType_Grbw:_pGrbw->SetPixelColor(indexPixel, color); break;
122124
}
125+
}
123126

124-
void SetPixelColor(uint16_t indexPixel, RgbwColor color)
125-
{
126-
switch (_type) {
127-
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); break;
128-
case NeoPixelType_Grbw: _pGrbw->SetPixelColor(indexPixel, color); break;
129-
}
127+
void SetPixelColor(uint16_t indexPixel, RgbwColor color)
128+
{
129+
switch (_type) {
130+
case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); break;
131+
case NeoPixelType_Grbw: _pGrbw->SetPixelColor(indexPixel, color); break;
130132
}
133+
}
131134

132-
void SetBrightness(byte b)
133-
{
134-
switch (_type) {
135-
case NeoPixelType_Grb: _pGrb->SetBrightness(b); break;
136-
case NeoPixelType_Grbw:_pGrbw->SetBrightness(b); break;
137-
}
135+
void SetBrightness(byte b)
136+
{
137+
switch (_type) {
138+
case NeoPixelType_Grb: _pGrb->SetBrightness(b); break;
139+
case NeoPixelType_Grbw:_pGrbw->SetBrightness(b); break;
138140
}
141+
}
139142

140-
RgbColor GetPixelColor(uint16_t indexPixel) const
141-
{
142-
switch (_type) {
143-
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
144-
case NeoPixelType_Grbw: /*doesn't support it so we don't return it*/ break;
145-
}
146-
return 0;
143+
RgbColor GetPixelColor(uint16_t indexPixel) const
144+
{
145+
switch (_type) {
146+
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
147+
case NeoPixelType_Grbw: /*doesn't support it so we don't return it*/ break;
147148
}
149+
return 0;
150+
}
148151

149-
// NOTE: Due to feature differences, some support RGBW but the method name
150-
// here needs to be unique, thus GetPixeColorRgbw
151-
RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const
152-
{
153-
switch (_type) {
154-
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
155-
case NeoPixelType_Grbw: return _pGrbw->GetPixelColor(indexPixel); break;
156-
}
157-
return 0;
152+
// NOTE: Due to feature differences, some support RGBW but the method name
153+
// here needs to be unique, thus GetPixeColorRgbw
154+
RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const
155+
{
156+
switch (_type) {
157+
case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
158+
case NeoPixelType_Grbw: return _pGrbw->GetPixelColor(indexPixel); break;
158159
}
160+
return 0;
161+
}
159162

160-
void ClearTo(RgbColor color)
161-
{
162-
switch (_type) {
163-
case NeoPixelType_Grb: _pGrb->ClearTo(color); break;
164-
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
165-
}
163+
void ClearTo(RgbColor color)
164+
{
165+
switch (_type) {
166+
case NeoPixelType_Grb: _pGrb->ClearTo(color); break;
167+
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
166168
}
169+
}
167170

168-
void ClearTo(RgbwColor color)
169-
{
170-
switch (_type) {
171-
case NeoPixelType_Grb: break;
172-
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
173-
}
171+
void ClearTo(RgbwColor color)
172+
{
173+
switch (_type) {
174+
case NeoPixelType_Grb: break;
175+
case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
174176
}
177+
}
175178

176179
private:
177180
NeoPixelType _type;

wled00/WS2812FX.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ void WS2812FX::service() {
6767
if(_running || _triggered) {
6868
unsigned long now = millis(); // Be aware, millis() rolls over every 49 days
6969
bool doShow = false;
70-
for(uint8_t i=0; i < _num_segments; i++) {
70+
for(uint8_t i=0; i < _num_segments; i++)
71+
{
7172
_segment_index = i;
72-
if(now > SEGMENT_RUNTIME.next_time || _triggered) {
73+
if(now > SEGMENT_RUNTIME.next_time || _triggered)
74+
{
7375
doShow = true;
7476
handle_palette();
7577
uint16_t delay = (this->*_mode[SEGMENT.mode])();

wled00/WS2812FX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define WS2812FX_h
4141

4242
#include "NpbWrapper.h"
43+
44+
#define FASTLED_INTERNAL //remove annoying pragma messages
4345
#include "FastLED.h"
4446

4547
#define DEFAULT_BRIGHTNESS (uint8_t)50

0 commit comments

Comments
 (0)