Skip to content

Commit 17dc6cc

Browse files
committed
Make swd / red led configurable
1 parent 043f31b commit 17dc6cc

6 files changed

+21
-10
lines changed

BoxConfig.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ String BoxConfig::getAsJson() {
7575
JsonObject miscDoc = doc.createNestedObject("misc");
7676
ConfigMisc* miscCfg = &_config.misc;
7777
miscDoc["autodump"] = miscCfg->autodump;
78+
miscDoc["swd"] = miscCfg->swd;
7879

7980
_json = "";
8081
serializeJson(doc, _json);
@@ -116,6 +117,7 @@ bool BoxConfig::setFromJson(String json) {
116117
JsonObject miscDoc = doc["misc"];
117118
ConfigMisc* miscCfg = &_config.misc;
118119
miscCfg->autodump = miscDoc["autodump"].as<bool>();
120+
miscCfg->swd = miscDoc["swd"].as<bool>();
119121

120122
// Convert old config version to latest one.
121123
if (_config.version != CONFIG_ACTIVE_VERSION) {
@@ -127,6 +129,9 @@ bool BoxConfig::setFromJson(String json) {
127129
case 3:
128130
miscCfg->autodump = false;
129131
_config.version = 4;
132+
case 4:
133+
miscCfg->swd = false;
134+
_config.version = 5;
130135
write();
131136
break;
132137
default:
@@ -167,4 +172,5 @@ void BoxConfig::_initializeConfig() {
167172

168173
ConfigMisc* misc = &_config.misc;
169174
misc->autodump = false;
175+
misc->swd = false;
170176
}

BoxConfig.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "BoxSD.h"
77

88

9-
#define BOXCONFIG_JSON_SIZE 515
10-
//{"version":255,"battery":{"voltageFactor":4294967295,"voltageChargerFactor":4294967295,"lowAdc":65535,"criticalAdc":65535,"sleepMinutes":255},"buttonEars":{"longPressMs":65535,"veryLongPressMs":65535},"wifi":{"ssid":"12345678901234567890123456789012","password":"1234567890123456789012345678901234567890123456789012345678901234"},"log":{"sdLog":false},"misc":{"autodump":false}}
9+
#define BOXCONFIG_JSON_SIZE 528
10+
//{"version":255,"battery":{"voltageFactor":4294967295,"voltageChargerFactor":4294967295,"lowAdc":65535,"criticalAdc":65535,"sleepMinutes":255},"buttonEars":{"longPressMs":65535,"veryLongPressMs":65535},"wifi":{"ssid":"12345678901234567890123456789012","password":"1234567890123456789012345678901234567890123456789012345678901234"},"log":{"sdLog":false},"misc":{"autodump":false,"swd":false}}
1111
//Size from https://arduinojson.org/v6/assistant/
1212

1313
class BoxConfig {

BoxLEDs.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#include "wiring_private.h"
33
#include "Hackiebox.h"
44

5-
void BoxLEDs::begin() {
6-
PWMPrepare(PIN_RED);
7-
//disableRedLED(true);
5+
void BoxLEDs::begin(bool swd) {
6+
disableRedLED(swd); //PWMPrepare(PIN_RED);
7+
if (swd)
8+
Log.info("Keep red LED inactive to enable SWD");
89

910
PWMPrepare(PIN_GREEN);
1011
PWMPrepare(PIN_BLUE);
@@ -70,13 +71,16 @@ void BoxLEDs::_handleAnimation(ANIMATION* animation) {
7071
}
7172

7273
void BoxLEDs::disableRedLED(bool disabled) {
73-
_redLedDisabled = disabled;
74+
if (_redLedDisabled == disabled)
75+
return;
76+
7477
if (disabled) {
7578
MAP_PinModeSet(PIN_19, PIN_MODE_1); //TCK
7679
MAP_PinModeSet(PIN_20, PIN_MODE_1); //TMS
7780
} else {
7881
PWMPrepare(PIN_RED);
7982
}
83+
_redLedDisabled = disabled;
8084
}
8185

8286
unsigned long BoxLEDs::getDurationByIterations(uint8_t iterations, ANIMATION_TYPE animationType) {

BoxLEDs.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class BoxLEDs : public EnhancedThread {
198198
};
199199

200200
void
201-
begin(),
201+
begin(bool swd),
202202
loop();
203203

204204
void testLEDs();
@@ -257,7 +257,7 @@ class BoxLEDs : public EnhancedThread {
257257
CRGB _wheel(uint8_t wheelPos);
258258
void _handleAnimation(ANIMATION* animation);
259259

260-
bool _redLedDisabled;
260+
bool _redLedDisabled = true;
261261
};
262262

263263
#endif

ConfigStructures.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ConfigStructures_h
22
#define ConfigStructures_h
33

4-
#define CONFIG_ACTIVE_VERSION 4
4+
#define CONFIG_ACTIVE_VERSION 5
55

66
typedef struct {
77
uint32_t voltageFactor;
@@ -41,6 +41,7 @@ typedef struct {
4141

4242
typedef struct {
4343
bool autodump;
44+
bool swd;
4445
} ConfigMisc;
4546

4647
typedef struct {

Hackiebox.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void Hackiebox::setup() {
6464

6565
boxPower.begin();
6666
boxI2C.begin();
67-
boxLEDs.begin();
67+
boxLEDs.begin(config->misc.swd);
6868
boxLEDs.setAll(BoxLEDs::CRGB::White);
6969
boxBattery.begin();
7070
boxLEDs.setAll(BoxLEDs::CRGB::Orange);

0 commit comments

Comments
 (0)