Skip to content

Commit

Permalink
Merge remote-tracking branch 'netmindz/WLED-discovery' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ewowi committed Aug 12, 2023
2 parents a44e461 + 3be83ec commit a443e64
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lib_deps =
https://github.com/me-no-dev/ESPAsyncWebServer.git
; https://github.com/lost-hope/ESPAsyncWebServer.git#master
https://github.com/bblanchon/ArduinoJson.git
https://github.com/netmindz/Dictionary.git#first

[appmod_leds]
build_flags =
Expand Down
2 changes: 1 addition & 1 deletion src/User/UserModArtNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UserModArtNet:public Module {
void setup() {
Module::setup();
print->print("%s %s\n", __PRETTY_FUNCTION__, name);
targetIp = IPAddress(192,168,178,161); // TODO allow setting at runtime
targetIp = IPAddress(0,0,0,0); // TODO allow setting at runtime
print->print("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed");
}

Expand Down
10 changes: 9 additions & 1 deletion src/User/UserModDDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class UserModDDP:public Module {
void setup() {
Module::setup();
print->print("%s %s\n", __PRETTY_FUNCTION__, name);
targetIp = IPAddress(192,168,178,161); // TODO allow setting at runtime
print->print("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed");
}

Expand All @@ -61,8 +60,17 @@ class UserModDDP:public Module {

if(!SysModModules::isConnected) return;


if((!targetIp) && (wledDiscoveryMod->nodes.length() >= 1)) {
targetIp = wledDiscoveryMod->nodes.firstKey(); // TODO: replace with WebUI setting
print->print("Start DDP to %s\n", targetIp.toString().c_str());
}

if(!targetIp) return;

if(!lds->newFrame) return;


// calculate the number of UDP packets we need to send
bool isRGBW = false;

Expand Down
61 changes: 61 additions & 0 deletions src/User/UserModWLEDDiscovery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
@title StarMod
@file UserModWLEDDiscovery.h
@date 20230730
@repo https://github.com/ewoudwijma/StarMod
@Authors https://github.com/ewoudwijma/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
@license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
*/

#include <Dictionary.h>


class UserModWLEDDiscovery:public Module {

public:

Dictionary<IPAddress, String> nodes;

UserModWLEDDiscovery() :Module("WLED Discovery") {
print->print("%s %s\n", __PRETTY_FUNCTION__, name);

print->print("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed");
};

//setup filesystem
void setup() {
Module::setup();
print->print("%s %s\n", __PRETTY_FUNCTION__, name);

print->print("%s %s %s\n", __PRETTY_FUNCTION__, name, success?"success":"failed");
}

void connected() {
isConnected = true;
udp.begin(65506);
}

void loop(){
// Module::loop();
if(!isConnected) return;

int packetSize = udp.parsePacket();

if (packetSize) {
IPAddress remoteIp = udp.remoteIP();
// TODO: actually look at the contents of the packet to fetch version, name etc
print->print("WLED: %s (%u)\n", remoteIp.toString().c_str(), packetSize);
udp.read(packetBuffer, packetSize);
nodes.set(remoteIp, remoteIp.toString().c_str());
}
}

private:
bool isConnected = false;
char packetBuffer[255];
WiFiUDP udp;

};

static UserModWLEDDiscovery *wledDiscoveryMod;
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Sys/SysModModel.h"
#include "Sys/SysModNetwork.h"
#include "Sys/SysModPins.h"
#include "User/UserModWLEDDiscovery.h"
#ifdef APPMOD_LEDS
#include "App/AppModLeds.h"
#include "App/AppModLedFixGen.h"
Expand Down Expand Up @@ -51,6 +52,7 @@ void setup() {
ui = new SysModUI();
sys = new SysModSystem();
pins = new SysModPins();
wledDiscoveryMod = new UserModWLEDDiscovery();
#ifdef APPMOD_LEDS
lds = new AppModLeds();
lfg = new AppModLedFixGen();
Expand Down Expand Up @@ -95,6 +97,7 @@ void setup() {
#ifdef USERMOD_HA
mdls->add(hamod);
#endif
mdls->add(wledDiscoveryMod);

//do not add mdls itself as it does setup and loop for itself!!! (it is the orchestrator)
mdls->setup();
Expand Down

0 comments on commit a443e64

Please sign in to comment.