Skip to content

Commit e7157e5

Browse files
committed
Add mDNS resolution for network bus
1 parent a24420a commit e7157e5

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

wled00/bus_manager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
#include <Arduino.h>
66
#include <IPAddress.h>
7-
#include "src/dependencies/network/Network.h" // for isConnected() (& WiFi)
87
#ifdef ARDUINO_ARCH_ESP32
8+
#include <ESPmDNS.h>
9+
#include "src/dependencies/network/Network.h" // for isConnected() (& WiFi)
910
#include "driver/ledc.h"
1011
#include "soc/ledc_struct.h"
1112
#if !(defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3))
@@ -26,6 +27,7 @@
2627
#include "bus_wrapper.h"
2728
#include <bits/unique_ptr.h>
2829

30+
extern char cmDNS[];
2931
extern bool cctICused;
3032
extern bool useParallelI2S;
3133

wled00/bus_manager.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class Bus {
133133
virtual uint16_t getUsedCurrent() const { return 0; }
134134
virtual uint16_t getMaxCurrent() const { return 0; }
135135
virtual size_t getBusSize() const { return sizeof(Bus); }
136+
virtual const String getCustomText() const { return String(); }
136137

137138
inline bool hasRGB() const { return _hasRgb; }
138139
inline bool hasWhite() const { return _hasWhite; }
@@ -215,7 +216,7 @@ class Bus {
215216
uint8_t _autoWhiteMode;
216217
// global Auto White Calculation override
217218
static uint8_t _gAWM;
218-
// _cct has the following menaings (see calculateCCT() & BusManager::setSegmentCCT()):
219+
// _cct has the following meanings (see calculateCCT() & BusManager::setSegmentCCT()):
219220
// -1 means to extract approximate CCT value in K from RGB (in calcualteCCT())
220221
// [0,255] is the exact CCT value where 0 means warm and 255 cold
221222
// [1900,10060] only for color correction expressed in K (colorBalanceFromKelvin())
@@ -375,8 +376,9 @@ struct BusConfig {
375376
uint16_t frequency;
376377
uint8_t milliAmpsPerLed;
377378
uint16_t milliAmpsMax;
379+
String text;
378380

379-
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0, byte aw=RGBW_MODE_MANUAL_ONLY, uint16_t clock_kHz=0U, uint8_t maPerLed=LED_MILLIAMPS_DEFAULT, uint16_t maMax=ABL_MILLIAMPS_DEFAULT)
381+
BusConfig(uint8_t busType, uint8_t* ppins, uint16_t pstart, uint16_t len = 1, uint8_t pcolorOrder = COL_ORDER_GRB, bool rev = false, uint8_t skip = 0, byte aw=RGBW_MODE_MANUAL_ONLY, uint16_t clock_kHz=0U, uint8_t maPerLed=LED_MILLIAMPS_DEFAULT, uint16_t maMax=ABL_MILLIAMPS_DEFAULT, String sometext = "")
380382
: count(std::max(len,(uint16_t)1))
381383
, start(pstart)
382384
, colorOrder(pcolorOrder)
@@ -386,6 +388,7 @@ struct BusConfig {
386388
, frequency(clock_kHz)
387389
, milliAmpsPerLed(maPerLed)
388390
, milliAmpsMax(maMax)
391+
, text(sometext)
389392
{
390393
refreshReq = (bool) GET_BIT(busType,7);
391394
type = busType & 0x7F; // bit 7 may be/is hacked to include refresh info (1=refresh in off state, 0=no refresh)

wled00/cfg.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
235235
}
236236
ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh
237237

238-
busConfigs.emplace_back(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode, freqkHz, maPerLed, maMax);
238+
String host = elm[F("text")] | String();
239+
busConfigs.emplace_back(ledType, pins, start, length, colorOrder, reversed, skipFirst, AWmode, freqkHz, maPerLed, maMax, host);
239240
doInitBusses = true; // finalization done in beginStrip()
240241
if (!Bus::isVirtual(ledType)) s++; // have as many virtual buses as you want
241242
}
@@ -379,7 +380,7 @@ bool deserializeConfig(JsonObject doc, bool fromFS) {
379380
DEBUG_PRINTF_P(PSTR("PIN ALLOC error: GPIO%d for touch button #%d is not a touch pin!\n"), btnPin[s], s);
380381
btnPin[s] = -1;
381382
PinManager::deallocatePin(pin,PinOwner::Button);
382-
}
383+
}
383384
//if touch pin, enable the touch interrupt on ESP32 S2 & S3
384385
#ifdef SOC_TOUCH_VERSION_2 // ESP32 S2 and S3 have a function to check touch state but need to attach an interrupt to do so
385386
else
@@ -976,6 +977,7 @@ void serializeConfig(JsonObject root) {
976977
ins[F("freq")] = bus->getFrequency();
977978
ins[F("maxpwr")] = bus->getMaxCurrent();
978979
ins[F("ledma")] = bus->getLEDCurrent();
980+
ins[F("text")] = bus->getCustomText();
979981
}
980982

981983
JsonArray hw_com = hw.createNestedArray(F("com"));
@@ -1340,4 +1342,4 @@ void serializeConfigSec() {
13401342
if (f) serializeJson(root, f);
13411343
f.close();
13421344
releaseJSONBufferLock();
1343-
}
1345+
}

wled00/data/style.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ input {
7979
input:disabled {
8080
color: #888;
8181
}
82+
input:invalid {
83+
color: #f00;
84+
}
8285
input[type="text"],
8386
input[type="number"],
8487
input[type="password"],
@@ -202,4 +205,4 @@ td {
202205
#btns select {
203206
width: 144px;
204207
}
205-
}
208+
}

wled00/set.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
141141
unsigned colorOrder, type, skip, awmode, channelSwap, maPerLed;
142142
unsigned length, start, maMax;
143143
uint8_t pins[5] = {255, 255, 255, 255, 255};
144+
String text;
144145

145146
// this will set global ABL max current used when per-port ABL is not used
146147
unsigned ablMilliampsMax = request->arg(F("MA")).toInt();
@@ -174,6 +175,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
174175
char sp[4] = "SP"; sp[2] = offset+s; sp[3] = 0; //bus clock speed (DotStar & PWM)
175176
char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED mA
176177
char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max mA
178+
char hs[4] = "HS"; hs[2] = offset+s; hs[3] = 0; //hostname (for network types, custom text for others)
177179
if (!request->hasArg(lp)) {
178180
DEBUG_PRINTF_P(PSTR("# of buses: %d\n"), s+1);
179181
break;
@@ -224,9 +226,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
224226
maMax = request->arg(ma).toInt() * request->hasArg(F("PPL")); // if PP-ABL is disabled maMax (per bus) must be 0
225227
}
226228
type |= request->hasArg(rf) << 7; // off refresh override
229+
text = request->arg(hs).substring(0,31);
227230
// actual finalization is done in WLED::loop() (removing old busses and adding new)
228231
// this may happen even before this loop is finished so we do "doInitBusses" after the loop
229-
busConfigs.emplace_back(type, pins, start, length, colorOrder | (channelSwap<<4), request->hasArg(cv), skip, awmode, freq, maPerLed, maMax);
232+
busConfigs.emplace_back(type, pins, start, length, colorOrder | (channelSwap<<4), request->hasArg(cv), skip, awmode, freq, maPerLed, maMax, text);
230233
busesChanged = true;
231234
}
232235
//doInitBusses = busesChanged; // we will do that below to ensure all input data is processed

wled00/xml.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ void getSettingsJS(byte subPage, Print& settingsScript)
311311
char sp[4] = "SP"; sp[2] = offset+s; sp[3] = 0; //bus clock speed
312312
char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED current
313313
char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max per-port PSU current
314+
char hs[4] = "HS"; hs[2] = offset+s; hs[3] = 0; //hostname (for network types, custom text for others)
314315
settingsScript.print(F("addLEDs(1);"));
315316
uint8_t pins[5];
316317
int nPins = bus->getPins(pins);
@@ -350,6 +351,7 @@ void getSettingsJS(byte subPage, Print& settingsScript)
350351
printSetFormValue(settingsScript,sp,speed);
351352
printSetFormValue(settingsScript,la,bus->getLEDCurrent());
352353
printSetFormValue(settingsScript,ma,bus->getMaxCurrent());
354+
printSetFormValue(settingsScript,hs,bus->getCustomText().c_str());
353355
sumMa += bus->getMaxCurrent();
354356
}
355357
printSetFormValue(settingsScript,PSTR("MA"),BusManager::ablMilliampsMax() ? BusManager::ablMilliampsMax() : sumMa);

0 commit comments

Comments
 (0)