Skip to content

Commit 01c8097

Browse files
committed
added a LED brightness option to the system and LoRaWAN command
1 parent c445544 commit 01c8097

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

sfeIoTNodeLoRaWAN/sfeIoTNodeLoRaWAN.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const uint8_t kLoRaWANMsgLEDFastBlink = 0x04;
4343
// Set the on-board LED to flash with the given RGB color
4444
const uint8_t kLoRaWANMsgLEDFlash = 0x05;
4545

46+
// Set the brightness for the on-board LED
47+
const uint8_t kLoRaWANMsgLEDBrightness = 0x06;
4648
//---------------------------------------------------------------------------
4749

4850
// Application keys - used to encrypt runtime secrets for the app.
@@ -598,6 +600,10 @@ void sfeIoTNodeLoRaWAN::onLoRaWANReceiveEvent(uint32_t data)
598600
color = pData[1] << 16 | pData[2] << 8 | pData[3];
599601
sfeLED.flash(color);
600602
break;
603+
case kLoRaWANMsgLEDBrightness:
604+
flxLog_I("Brightness: %u", pData[1]);
605+
sfeLED.brightness(pData[1]);
606+
break;
601607
}
602608
}
603609
//---------------------------------------------------------------------------

sfeIoTNodeLoRaWAN/sfeNLLed.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ static void _sfeLED_TaskProcessing(void *parameter)
9595
// _sfeLED implementation
9696
//---------------------------------------------------------
9797

98-
_sfeLED::_sfeLED() : _current{0}, _isInitialized{false}, _blinkOn{false}, _disabled{false}
98+
_sfeLED::_sfeLED() : _current{0}, _isInitialized{false}, _blinkOn{false}, _disabled{false}, _brightness{kLEDBrightness}
9999
{
100-
_colorStack[0] = {_sfeLED::Black, 0};
100+
_colorStack[0] = {_sfeLED::Black, 0, kLEDBrightness};
101101
}
102102

103103
//---------------------------------------------------------
@@ -197,6 +197,12 @@ void _sfeLED::_eventCB(cmdStruct_t &theCommand)
197197
update();
198198
break;
199199

200+
case kCmdBrightness:
201+
_brightness = theCommand.data.brightness;
202+
_colorStack[_current].brightness = theCommand.data.brightness;
203+
update();
204+
break;
205+
200206
case kCmdReset:
201207
_current = 0;
202208
update();
@@ -224,6 +230,7 @@ void _sfeLED::update(void)
224230
return;
225231

226232
_theLED = _colorStack[_current].color;
233+
FastLED.setBrightness(_colorStack[_current].brightness);
227234
FastLED.show();
228235

229236
// check blink state - blink on, blink off?
@@ -269,7 +276,7 @@ void _sfeLED::queueCommand(cmdType_t command, sfeLEDColor_t color, uint32_t tick
269276
if (!_isInitialized)
270277
return;
271278

272-
cmdStruct_t theCommand = {command, {color, ticks}};
279+
cmdStruct_t theCommand = {command, {color, ticks, _brightness}};
273280

274281
xQueueSend(hCmdQueue, (void *)&theCommand, 10);
275282
// if (xQueueSend(hCmdQueue, (void *)&theCommand, 10) != pdPASS)
@@ -340,6 +347,16 @@ void _sfeLED::stop(bool turnoff)
340347
queueCommand(turnoff ? kCmdOff : kCmdBlink);
341348
}
342349
//---------------------------------------------------------
350+
// brightness
351+
void _sfeLED::brightness(uint8_t brightness)
352+
{
353+
if (_disabled)
354+
return;
355+
356+
_brightness = brightness;
357+
queueCommand(kCmdBrightness);
358+
}
359+
//---------------------------------------------------------
343360
// refresh
344361
void _sfeLED::refresh(void)
345362
{

sfeIoTNodeLoRaWAN/sfeNLLed.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class _sfeLED
5454
{
5555
sfeLEDColor_t color;
5656
uint32_t ticks;
57+
uint8_t brightness;
5758
} colorState_t;
5859

5960
// Command Type
@@ -65,7 +66,8 @@ class _sfeLED
6566
kCmdFlash = (1 << 2),
6667
kCmdBlink = (1 << 3),
6768
kCmdReset = (1 << 4),
68-
kCmdUpdate = (1 << 5)
69+
kCmdUpdate = (1 << 5),
70+
kCmdBrightness = (1 << 6)
6971
} cmdType_t;
7072

7173
// Command struct
@@ -82,6 +84,7 @@ class _sfeLED
8284
void blink(sfeLEDColor_t, uint32_t);
8385
void stop(bool off = true);
8486
void flash(sfeLEDColor_t color);
87+
void brightness(uint8_t);
8588
void refresh(void);
8689

8790
void _timerCB(void);
@@ -102,7 +105,7 @@ class _sfeLED
102105
void update(void);
103106
void queueCommand(cmdType_t command, sfeLEDColor_t color = 0, uint32_t ticks = 0);
104107

105-
static constexpr uint16_t kStackSize = 10;
108+
static constexpr uint16_t kStackSize = 20;
106109
colorState_t _colorStack[kStackSize];
107110

108111
int _current;
@@ -113,5 +116,7 @@ class _sfeLED
113116
CRGB _theLED;
114117

115118
bool _disabled;
119+
120+
uint8_t _brightness;
116121
};
117122
extern _sfeLED &sfeLED;

0 commit comments

Comments
 (0)