Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add projection to watch and map max once/sec, varsToWatch to model #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/App/AppLedsV.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ enum Projections
p_None,
p_Random,
p_DistanceFromPoint,
p_DistanceFromCentre
p_DistanceFromCentre,
count
};

class LedsV {
Expand Down
34 changes: 20 additions & 14 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

#include "AppLedsV.h"
#include "AppEffects.h"
#ifdef USERMOD_E131
#include "../User/UserModE131.h"
#endif

#include <vector>
#include "FastLED.h"
Expand All @@ -32,6 +29,8 @@ class AppModLeds:public Module {

//need to make these static as they are called in lambda functions
static uint16_t fps;
unsigned long lastMappingMillis = 0;
static bool doMap;

AppModLeds() :Module("Leds") {};

Expand Down Expand Up @@ -62,11 +61,11 @@ class AppModLeds:public Module {
// if (LedsV::projectionNr == p_DistanceFromPoint) {
if (fx == 9 && LedsV::fxDimension != 2) { // 9 = "Frizzles2D"
LedsV::fxDimension = 2;
ledsV.ledFixProjectAndMap(); //luckily not called during reboot as ledFixNr not defined yet then
doMap = true;
}
if (fx != 9 && LedsV::fxDimension != 1) { // 9 = "Frizzles2D"
LedsV::fxDimension = 1;
ledsV.ledFixProjectAndMap(); //luckily not called during reboot as ledFixNr not defined yet then
doMap = true;
}

// if (false) {
Expand Down Expand Up @@ -136,7 +135,7 @@ class AppModLeds:public Module {
print->print("%s Change %s to %d\n", "initSelect chFun", var["id"].as<const char *>(), var["value"].as<int>());

LedsV::projectionNr = var["value"];
ledsV.ledFixProjectAndMap(); //luckily not called during reboot as ledFixNr not defined yet then
doMap = true;
});

ui->initCanvas(parentVar, "pview", -1, false, [](JsonObject var) { //uiFun
Expand Down Expand Up @@ -172,7 +171,7 @@ class AppModLeds:public Module {
print->print("%s Change %s to %d\n", "initSelect chFun", var["id"].as<const char *>(), var["value"].as<int>());

LedsV::ledFixNr = var["value"];
ledsV.ledFixProjectAndMap();
doMap = true;

char fileName[30] = "";
if (files->seqNrToName(fileName, LedsV::ledFixNr)) {
Expand Down Expand Up @@ -234,18 +233,17 @@ class AppModLeds:public Module {
// FastLED.addLeds<NEOPIXEL, 6>(leds, 1);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(ledsP, NUM_LEDS_FastLed);

#ifdef USERMOD_E131
e131mod->addWatch(1, "bri", 256);
e131mod->addWatch(2, "fx", effects.size());
#endif
mdl->addWatch(1, "bri", 256);
mdl->addWatch(2, "fx", effects.size());
mdl->addWatch(3, "projection", Projections::count);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to add a new "common" param then the effects will need to be updated to use new channel. Might be best that the per effect parameters start at 10


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

void loop() {
// Module::loop();

if(millis() - frameMillis >= 1000.0/fps) {
if (millis() - frameMillis >= 1000.0/fps) {
frameMillis = millis();

Effect* effect = effects[mdl->getValue("fx")];
Expand All @@ -257,12 +255,19 @@ class AppModLeds:public Module {
frameCounter++;
call++;
}
if (millis() - secondMillis >= 1000 || !secondMillis) {

if (millis() - secondMillis >= 1000) {
secondMillis = millis();
mdl->setValueV("realFps", "%lu /s", frameCounter);
frameCounter = 0;
}

if (millis() - lastMappingMillis >= 1000 && doMap) { //not more then once per second (for E131)
lastMappingMillis = millis();
doMap = false;
ledsV.ledFixProjectAndMap();
}

// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
}
Expand All @@ -271,4 +276,5 @@ class AppModLeds:public Module {

static AppModLeds *lds;

uint16_t AppModLeds::fps = 40;
uint16_t AppModLeds::fps = 40;
bool AppModLeds::doMap = false;
15 changes: 15 additions & 0 deletions src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@

#include "ArduinoJson.h"

struct VarToWatch {
const char * id = nullptr;
uint16_t max = -1;
uint8_t savedValue = -1;
};

#define maxChannels 10

class SysModModel:public Module {

public:

// StaticJsonDocument<24576> model; //not static as that blows up the stack. Use extern??
static DynamicJsonDocument *model;

VarToWatch varsToWatch[maxChannels];

SysModModel();
void setup();
void loop();
Expand Down Expand Up @@ -65,6 +75,11 @@ class SysModModel:public Module {
//returns the var defined by id (parent to recursively call findVar)
static JsonObject findVar(const char * id, JsonArray parent = JsonArray()); //static for processJson

void addWatch(uint8_t channel, const char * id, uint16_t max) {
varsToWatch[channel].id = id;
varsToWatch[channel].max = max;
}

private:
static bool doWriteModel;
static bool doShowObsolete;
Expand Down
27 changes: 6 additions & 21 deletions src/User/UserModE131.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@

#include <vector>

#define maxChannels 10

struct VarToWatch {
const char * id = nullptr;
uint16_t max = -1;
uint8_t savedValue = -1;
};

class UserModE131:public Module {

public:

VarToWatch varsToWatch[maxChannels]; //up to 513

UserModE131() :Module("e131/sACN support") {
print->print("%s %s\n", __PRETTY_FUNCTION__, name);

Expand Down Expand Up @@ -69,22 +59,22 @@ class UserModE131:public Module {
e131.pull(&packet); // Pull packet from ring buffer

for (int i=0; i < maxChannels; i++) {
if (packet.property_values[i] != varsToWatch[i].savedValue) {
if (packet.property_values[i] != mdl->varsToWatch[i].savedValue) {

print->print("Universe %u / %u Channels | Packet#: %u / Errors: %u / CH%d: %u -> %u",
htons(packet.universe), // The Universe for this packet
htons(packet.property_value_count) - 1, // Start code is ignored, we're interested in dimmer data
e131.stats.num_packets, // Packet counter
e131.stats.packet_errors, // Packet error counter
i,
varsToWatch[i].savedValue,
mdl->varsToWatch[i].savedValue,
packet.property_values[i]); // Dimmer data for Channel i

varsToWatch[i].savedValue = packet.property_values[i];
mdl->varsToWatch[i].savedValue = packet.property_values[i];

if (varsToWatch[i].id != nullptr) {
print->print(" var: %s\n", varsToWatch[i].id);
mdl->setValueI(varsToWatch[i].id, varsToWatch[i].savedValue%varsToWatch[i].max); // TODO: ugly to have magic string
if (mdl->varsToWatch[i].id != nullptr) {
print->print(" var: %s\n", mdl->varsToWatch[i].id);
mdl->setValueI(mdl->varsToWatch[i].id, mdl->varsToWatch[i].savedValue%mdl->varsToWatch[i].max); // TODO: ugly to have magic string
}
else
print->print("\n");
Expand All @@ -93,11 +83,6 @@ class UserModE131:public Module {
}
}

void addWatch(uint8_t channel, const char * id, uint16_t max) {
varsToWatch[channel].id = id;
varsToWatch[channel].max = max;
}

private:
ESPAsyncE131 e131;
boolean e131Created = false;
Expand Down