-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Marcel muxio patch 1 #4786
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
Marcel muxio patch 1 #4786
Changes from all commits
c13bc09
e7601f9
2892926
fb44de3
5803f8f
0de3278
caad409
6c89395
8ad8239
b3fd774
4ae3e84
25e6995
6845985
e7a5bce
d7554b8
304adc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include "wled.h" | ||
| #include "../usermods/usermod_rotaryrackdimmer/usermod_rotaryrackdimmer.h" | ||
|
|
||
| Usermod* usermod_rotary = nullptr; | ||
|
|
||
| void userSetup() { | ||
| usermod_rotary = new Usermod_RotaryRackDimmer(); | ||
| usermods.add(usermod_rotary); | ||
| Serial.println(F("[RotaryRackDimmer] usermod geladen!")); | ||
| } | ||
|
|
||
| void userConnected() { | ||
| // Optioneel | ||
| } | ||
|
|
||
| void userLoop() { | ||
| // Optioneel, laat usermod zelf zijn werk doen | ||
| } | ||
|
|
||
| void Usermod_RotaryRackDimmer::addToJsonInfo(JsonObject &root) { | ||
| JsonObject user = root["usermod"]; | ||
| user["RotaryRackDimmer"] = "Actief"; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||||||||||||||||||||||||||||
| #pragma once | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| #include "wled.h" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| class Usermod_RotaryRackDimmer : public Usermod { | ||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||
| int pinA = 33; // A (CLK) pin van de encoder | ||||||||||||||||||||||||||||||||||||||||
| int pinB = 13; // B (DT) pin van de encoder | ||||||||||||||||||||||||||||||||||||||||
| int lastState = 0; | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Make pin assignments and step size configurable. The hardcoded pin assignments and brightness step should be configurable through the WLED web interface for better usability and hardware flexibility. class Usermod_RotaryRackDimmer : public Usermod {
private:
- int pinA = 33; // A (CLK) pin van de encoder
- int pinB = 13; // B (DT) pin van de encoder
+ int pinA = 33; // A (CLK) pin of encoder - configurable
+ int pinB = 13; // B (DT) pin of encoder - configurable
+ int stepSize = 5; // Brightness step size - configurable
int lastState = 0;Then implement proper 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||
| void setup() override { | ||||||||||||||||||||||||||||||||||||||||
| pinMode(pinA, INPUT_PULLUP); | ||||||||||||||||||||||||||||||||||||||||
| pinMode(pinB, INPUT_PULLUP); | ||||||||||||||||||||||||||||||||||||||||
| lastState = digitalRead(pinA); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| void loop() override { | ||||||||||||||||||||||||||||||||||||||||
| int currentState = digitalRead(pinA); | ||||||||||||||||||||||||||||||||||||||||
| if (currentState != lastState) { | ||||||||||||||||||||||||||||||||||||||||
| if (digitalRead(pinB) != currentState) { | ||||||||||||||||||||||||||||||||||||||||
| // Rechtsom → dim omhoog | ||||||||||||||||||||||||||||||||||||||||
| bri = min(255, bri + 5); | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| // Linksom → dim omlaag | ||||||||||||||||||||||||||||||||||||||||
| bri = max(0, bri - 5); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using stepSize variable instead of hardcoded value. The brightness adjustment uses a hardcoded step of 5, but this should use the configurable if (digitalRead(pinB) != currentState) {
- bri = min(255, bri + 5);
+ bri = min(255, bri + stepSize);
} else {
- bri = max(0, bri - 5);
+ bri = max(0, bri - stepSize);
}🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| lastState = currentState; | ||||||||||||||||||||||||||||||||||||||||
| colorUpdated(CALL_MODE_DIRECT_CHANGE); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add debouncing to prevent erratic behavior. Rotary encoders are prone to bouncing, which will cause erratic brightness changes. The current implementation lacks debouncing and may trigger multiple times per detent. Add debouncing with a simple time-based approach: class Usermod_RotaryRackDimmer : public Usermod {
private:
int pinA = 33;
int pinB = 13;
int lastState = 0;
+ unsigned long lastChangeTime = 0;
+ const unsigned long debounceDelay = 2; // 2ms debounce
void loop() override {
int currentState = digitalRead(pinA);
- if (currentState != lastState) {
+ if (currentState != lastState && (millis() - lastChangeTime) > debounceDelay) {
if (digitalRead(pinB) != currentState) {
- bri = min(255, bri + 5);
+ bri = min(255, bri + stepSize);
} else {
- bri = max(0, bri - 5);
+ bri = max(0, bri - stepSize);
}
lastState = currentState;
+ lastChangeTime = millis();
colorUpdated(CALL_MODE_DIRECT_CHANGE);
}
}
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| void addToConfig(JsonObject &root) override {} | ||||||||||||||||||||||||||||||||||||||||
| bool readFromConfig(JsonObject &root) override { return true; } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Implement proper configuration methods. The configuration methods are currently empty but should handle the configurable parameters (pins and step size) to make the usermod user-friendly. - void addToConfig(JsonObject &root) override {}
- bool readFromConfig(JsonObject &root) override { return true; }
+ void addToConfig(JsonObject &root) override {
+ JsonObject top = root.createNestedObject(FPSTR("RotaryRackDimmer"));
+ top["pinA"] = pinA;
+ top["pinB"] = pinB;
+ top["stepSize"] = stepSize;
+ }
+
+ bool readFromConfig(JsonObject &root) override {
+ JsonObject top = root[FPSTR("RotaryRackDimmer")];
+ if (top.isNull()) return false;
+
+ pinA = top["pinA"] | pinA;
+ pinB = top["pinB"] | pinB;
+ stepSize = top["stepSize"] | stepSize;
+
+ return true;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| String getId() override { return F("RotaryRackDimmer"); } | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move method implementation to header file.
The
addToJsonInfomethod implementation should be in the header file since it's part of the class definition. Implementing class methods in separate files outside the class definition violates C++ best practices and can cause linking issues.Move this implementation to the header file within the class definition:
Add to the header file within the class:
🤖 Prompt for AI Agents