Skip to content

Commit 6eaa8f3

Browse files
authored
Add direct 32-bit rendering for RGBW with dithering (#123)
1 parent b7b22ea commit 6eaa8f3

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

include/calibration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#ifdef NEOPIXEL_RGBW
2929
typedef RgbwColor ColorDefinition;
30+
#elif defined(SPILED_APA102)
31+
typedef RgbwColor ColorDefinition;
3032
#else
3133
typedef RgbColor ColorDefinition;
3234
#endif

include/framestate.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
enum class AwaProtocol
3636
{
3737
HEADER_A,
38+
HEADER_W,
3839
HEADER_w,
3940
HEADER_a,
4041
HEADER_HI,
@@ -47,6 +48,7 @@ enum class AwaProtocol
4748
RED,
4849
GREEN,
4950
BLUE,
51+
EXTRA_COLOR_BYTE_4,
5052
FLETCHER1,
5153
FLETCHER2,
5254
FLETCHER_EXT
@@ -60,6 +62,7 @@ class
6062
{
6163
volatile AwaProtocol state = AwaProtocol::HEADER_A;
6264
bool protocolVersion2 = false;
65+
bool protocolVersion3 = false;
6366
uint8_t CRC = 0;
6467
uint16_t count = 0;
6568
uint16_t currentLed = 0;
@@ -158,6 +161,27 @@ class
158161
protocolVersion2 = newVer;
159162
}
160163

164+
/**
165+
* @brief Set if frame protocol version 3 (direct 32bit mode)
166+
*
167+
* @param newVer
168+
*/
169+
inline void setProtocolVersion3(bool newVer)
170+
{
171+
protocolVersion3 = newVer;
172+
}
173+
174+
/**
175+
* @brief Verify if frame protocol version 3 (direct 32bit mode)
176+
*
177+
* @return true
178+
* @return false
179+
*/
180+
inline bool isProtocolVersion3() const
181+
{
182+
return protocolVersion3;
183+
}
184+
161185
/**
162186
* @brief Verify if frame protocol version 2 (contains calibration data)
163187
*

include/main.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define MAIN_H
3030

3131
#define MAX_BUFFER (3013 * 3 + 1)
32-
#define HELLO_MESSAGE "\r\nWelcome!\r\nAwa driver 9."
32+
#define HELLO_MESSAGE "\r\nWelcome!\r\nAwa driver 11."
3333

3434
#include "calibration.h"
3535
#include "statistics.h"
@@ -113,13 +113,28 @@ void processData()
113113
case AwaProtocol::HEADER_A:
114114
// assume it's protocol version 1, verify it later
115115
frameState.setProtocolVersion2(false);
116+
frameState.setProtocolVersion3(false);
116117
if (input == 'A')
117118
frameState.setState(AwaProtocol::HEADER_w);
118119
break;
119120

120121
case AwaProtocol::HEADER_w:
121122
if (input == 'w')
122123
frameState.setState(AwaProtocol::HEADER_a);
124+
#if defined(NEOPIXEL_RGBW) || defined(SPILED_APA102)
125+
else if (input == 'W')
126+
frameState.setState(AwaProtocol::HEADER_W);
127+
#endif
128+
else
129+
frameState.setState(AwaProtocol::HEADER_A);
130+
break;
131+
case AwaProtocol::HEADER_W:
132+
// detect protocol version 3
133+
if (input == 'a')
134+
{
135+
frameState.setState(AwaProtocol::HEADER_HI);
136+
frameState.setProtocolVersion3(true);
137+
}
123138
else
124139
frameState.setState(AwaProtocol::HEADER_A);
125140
break;
@@ -196,10 +211,38 @@ void processData()
196211
frameState.setState(AwaProtocol::BLUE);
197212
break;
198213

214+
case AwaProtocol::EXTRA_COLOR_BYTE_4:
215+
#ifdef NEOPIXEL_RGBW
216+
frameState.color.W = input;
217+
#elif defined(SPILED_APA102)
218+
frameState.color.W = input;
219+
#endif
220+
frameState.addFletcher(input);
221+
222+
if (base.setStripPixel(frameState.getCurrentLedIndex(), frameState.color))
223+
{
224+
frameState.setState(AwaProtocol::RED);
225+
}
226+
else
227+
{
228+
frameState.setState(AwaProtocol::FLETCHER1);
229+
}
230+
break;
231+
199232
case AwaProtocol::BLUE:
200233
frameState.color.B = input;
201234
frameState.addFletcher(input);
202235

236+
if (frameState.isProtocolVersion3())
237+
{
238+
frameState.setState(AwaProtocol::EXTRA_COLOR_BYTE_4);
239+
break;
240+
}
241+
242+
#if defined(SPILED_APA102)
243+
frameState.color.W = 0xFF;
244+
#endif
245+
203246
#ifdef NEOPIXEL_RGBW
204247
// calculate RGBW from RGB using provided calibration data
205248
frameState.rgb2rgbw();

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
#endif
7575

7676
#ifdef SPILED_APA102
77-
#define LED_DRIVER NeoPixelBus<DotStarBgrFeature, DotStarEsp32DmaHspiMethod>
77+
#define LED_DRIVER NeoPixelBus<DotStarLbgrFeature, DotStarEsp32DmaHspiMethod>
7878
#elif SPILED_WS2801
7979
#define LED_DRIVER NeoPixelBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod>
8080
#endif
@@ -111,7 +111,7 @@
111111
#define LED_DRIVER2 NeoPixelBus<NeoGrbFeature, NeoEsp32I2s0Ws2812xMethod>
112112
#endif
113113
#elif SPILED_APA102
114-
#define LED_DRIVER2 NeoPixelBus<DotStarBgrFeature, DotStarEsp32DmaHspiMethod>
114+
#define LED_DRIVER2 NeoPixelBus<DotStarLbgrFeature, DotStarEsp32DmaHspiMethod>
115115
#elif SPILED_WS2801
116116
#define LED_DRIVER2 NeoPixelBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod>
117117
#endif
@@ -133,7 +133,7 @@
133133
#define LED_DRIVER2 NeoPixelBus<NeoGrbFeature, NeoEsp32I2s0Ws2812xMethod>
134134
#endif
135135
#elif SPILED_APA102
136-
#define LED_DRIVER2 NeoPixelBus<DotStarBgrFeature, DotStarEsp32DmaVspiMethod>
136+
#define LED_DRIVER2 NeoPixelBus<DotStarLbgrFeature, DotStarEsp32DmaVspiMethod>
137137
#elif SPILED_WS2801
138138
#define LED_DRIVER2 NeoPixelBus<NeoRbgFeature, NeoWs2801Spi2MhzMethod>
139139
#endif

0 commit comments

Comments
 (0)