Skip to content

Commit

Permalink
Add mDNS (usermod) and serveJson for /json
Browse files Browse the repository at this point in the history
AppEffects: Add Octopus2D (empty, wip)

Main: activate mDNS

SysModModel: setValueI, add table column (array) support (WIP)

SysModSystem: - add serverName (instance name) field

SysModUI: add serveJson on URL /json

SysModWeb:
- loop: update clTbl columns evert second, instead of whole table (WIP)
- add serveJson

UserModInstances
- remove inactive node bugfix
- user serverName from mdl
  • Loading branch information
ewowi committed Oct 16, 2023
1 parent f9581a8 commit fe816bd
Show file tree
Hide file tree
Showing 39 changed files with 230 additions and 89 deletions.
2 changes: 1 addition & 1 deletion data/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @title StarMod
// @file app.js
// @date 20230810
// @date 20231016
// @repo https://github.com/ewowi/StarMod
// @Authors https://github.com/ewowi/StarMod/commits/main
// @Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion data/index.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file index.css
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion data/index.htm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- @title StarMod
@file index.htm
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion data/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @title StarMod
// @file index.css
// @date 20230810
// @date 20231016
// @repo https://github.com/ewowi/StarMod
// @Authors https://github.com/ewowi/StarMod/commits/main
// @Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; @title StarMod
; @file platformio.ini
; @date 20230810
; @date 20231016
; @repo https://github.com/ewowi/StarMod
; @Authors https://github.com/ewowi/StarMod/commits/main
; @Copyright (c) 2023 Github StarMod Commit Authors
Expand All @@ -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/ewowi/ESPAsyncWebServer.git
; https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
https://github.com/bblanchon/ArduinoJson.git

[appmod_leds]
Expand Down
74 changes: 71 additions & 3 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file AppEffects.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down Expand Up @@ -334,7 +334,7 @@ class DistortionWaves2D: public Effect {
Effect::loop();

const uint16_t cols = LedsV::widthV;
const uint16_t rows = LedsV::widthV;
const uint16_t rows = LedsV::heightV;

uint8_t speed = mdl->getValue("speed").as<int>()/32;
uint8_t scale = mdl->getValue("scale").as<int>()/32;
Expand Down Expand Up @@ -383,6 +383,73 @@ class DistortionWaves2D: public Effect {
}
}; // DistortionWaves2D

class Octopus2D: public Effect {
public:
const char * name() {
return "Octopus 2D";
}

// typedef struct {
// uint8_t angle;
// uint8_t radius;
// } map_t;

// map_t rMap ;

void setup() {
// fadeToBlackBy( ledsP, LedsV::nrOfLedsP, 100); //like more the gradual change
}

void loop() {
Effect::loop();

const uint16_t cols = LedsV::widthV;
const uint16_t rows = LedsV::widthV;

uint8_t offsX = mdl->getValue("Offset X").as<uint8_t>();
uint8_t offsYX = mdl->getValue("Offset Y").as<uint8_t>();
uint8_t legs = mdl->getValue("Legs").as<uint8_t>();

// const uint8_t mapp = 180 / MAX(cols,rows);

// // re-init if SEGMENT dimensions or offset changed
// if (SEGENV.call == 0 || SEGENV.aux0 != cols || SEGENV.aux1 != rows || offsX != *offsX || offsY != *offsY) {
// SEGENV.step = 0; // t
// SEGENV.aux0 = cols;
// SEGENV.aux1 = rows;
// *offsX = offsX;
// *offsY = offsY;
// const uint8_t C_X = cols / 2 + (offsX - 128)*cols/255;
// const uint8_t C_Y = rows / 2 + (offsY - 128)*rows/255;
// for (int x = 0; x < cols; x++) {
// for (int y = 0; y < rows; y++) {
// rMap[XY(x, y)].angle = 40.7436f * atan2f(y - C_Y, x - C_X); // avoid 128*atan2()/PI
// rMap[XY(x, y)].radius = hypotf(x - C_X, y - C_Y) * mapp; //thanks Sutaburosu
// }
// }
// }

// SEGENV.step += SEGMENT.speed / 32 + 1; // 1-4 range
// for (int x = 0; x < cols; x++) {
// for (int y = 0; y < rows; y++) {
// byte angle = rMap[XY(x,y)].angle;
// byte radius = rMap[XY(x,y)].radius;
// //CRGB c = CHSV(SEGENV.step / 2 - radius, 255, sin8(sin8((angle * 4 - radius) / 4 + SEGENV.step) + radius - SEGENV.step * 2 + angle * (legs/3+1)));
// uint16_t intensity = sin8(sin8((angle * 4 - radius) / 4 + SEGENV.step/2) + radius - SEGENV.step + angle * (legs/4+1));
// intensity = map(intensity*intensity, 0, 65535, 0, 255); // add a bit of non-linearity for cleaner display
// CRGB c = ColorFromPalette(SEGPALETTE, SEGENV.step / 2 - radius, intensity);
// SEGMENT.setPixelColorXY(x, y, c);
// }
// }
}
bool controls(JsonObject parentVar) {
ui->initSlider(parentVar, "Offset X", false, false);
ui->initSlider(parentVar, "Offset Y", false, false);
ui->initSlider(parentVar, "Legs", false, false);
return true;
}
}; // Octopus2D


//BouncingBalls1D inspired by WLED
//each needs 12 bytes
Expand Down Expand Up @@ -464,7 +531,7 @@ class BouncingBalls1D: public Effect {
ui->initSlider(parentVar, "nrOfBalls", 128, false);
return true;
}
}; // DistortionWaves2D
}; // BouncingBalls2D

class RingEffect:public Effect {
protected:
Expand Down Expand Up @@ -675,6 +742,7 @@ class Effects {
effects.push_back(new Frizzles2D);
effects.push_back(new Lines2D);
effects.push_back(new DistortionWaves2D);
effects.push_back(new Octopus2D);
effects.push_back(new BouncingBalls1D);
effects.push_back(new RingRandomFlow);
#ifdef USERMOD_WLEDAUDIO
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppLedsV.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file AppModLeds.cpp
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppLedsV.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file AppLedsV.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppModLedFixGen.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file AppModLedFixGen.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/App/AppModLeds.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file AppModLeds.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Module.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file Module.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysJsonRDWS.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysJsonRDWS.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModFiles.cpp
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
4 changes: 1 addition & 3 deletions src/Sys/SysModFiles.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModFiles.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand All @@ -19,8 +19,6 @@ class SysModFiles:public Module {
void setup();
void loop();

// void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final);

bool remove(const char * path);

size_t usedBytes();
Expand Down
33 changes: 27 additions & 6 deletions src/Sys/SysModModel.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModModel.cpp
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down Expand Up @@ -162,13 +162,34 @@ JsonObject SysModModel::setValueC(const char * id, const char * value) {
}

//setValue int
JsonObject SysModModel::setValueI(const char * id, int value) {
JsonObject SysModModel::setValueI(const char * id, int value, uint8_t rowNr) {
JsonObject var = findVar(id);
if (!var.isNull()) {
if (var["value"].isNull() || var["value"] != value) {
// USER_PRINTF("setValue changed %s %s->%s\n", id, var["value"].as<String>().c_str(), value);
var["value"] = value;
ui->setChFunAndWs(var);
if (rowNr == (uint8_t)-1) { //normal situation
if (var["value"].isNull() || var["value"] != value) {
// USER_PRINTF("setValue changed %s %s->%s\n", id, var["value"].as<String>().c_str(), value);
var["value"] = value;
ui->setChFunAndWs(var);
}
}
else {
//if we deal with multiple rows, value should be an array, if not we create one

if (var["value"].isNull() || !var["value"].is<JsonArray>()) {
USER_PRINTF("setValueB var %s (%d) value %s not array, creating\n", id, rowNr, var["value"].as<String>().c_str());
// print->printJson("setValueB var %s value %s not array, creating", id, var["value"].as<String>().c_str());
var.createNestedArray("value");
}

if (var["value"].is<JsonArray>()) {
//set the right value in the array (if array did not contain values yet, all values before rownr are set to false)
if (var["value"][rowNr] != value) {
var["value"][rowNr] = value;
ui->setChFunAndWs(var);
}
}
else
USER_PRINTF("setValueB %s could not create value array\n", id);
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModModel.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down Expand Up @@ -31,7 +31,7 @@ class SysModModel:public Module {
static JsonObject setValueC(const char * id, const char * value);

//setValue int
static JsonObject setValueI(const char * id, int value);
static JsonObject setValueI(const char * id, int value, uint8_t rowNr=-1);

//setValue bool
static JsonObject setValueB(const char * id, bool value, uint8_t rowNr=-1);
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModModules.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file Modules.cpp
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModModules.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModModules.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModNetwork.cpp
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModNetwork.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModNetwork.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModPins.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModPins.cpp
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModPins.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModPins.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModPrint.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModPrint.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModPrint.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModPrint.h
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand Down
6 changes: 5 additions & 1 deletion src/Sys/SysModSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
@title StarMod
@file SysModSystem.cpp
@date 20230810
@date 20231016
@repo https://github.com/ewowi/StarMod
@Authors https://github.com/ewowi/StarMod/commits/main
@Copyright (c) 2023 Github StarMod Commit Authors
Expand All @@ -26,6 +26,10 @@ void SysModSystem::setup() {

parentVar = ui->initModule(parentVar, name);

ui->initText(parentVar, "serverName", "StarMod", false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Name");
web->addResponse(var["id"], "comment", "Instance name");
});
ui->initText(parentVar, "upTime", nullptr, true, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "comment", "Uptime of board");
});
Expand Down
Loading

0 comments on commit fe816bd

Please sign in to comment.