Convert new WS2812FX spped format to McLighting
Keep McLighting speeds (0-255) unchanged and convert to WS2812FX speeds. (65535-0)
This commit is contained in:
parent
b726aee15a
commit
2e58d55eec
3 changed files with 21 additions and 8 deletions
Arduino/McLighting
|
@ -166,7 +166,7 @@ void setup() {
|
|||
// ***************************************************************************
|
||||
strip.init();
|
||||
strip.setBrightness(brightness);
|
||||
strip.setSpeed(ws2812fx_speed);
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
//strip.setMode(FX_MODE_RAINBOW_CYCLE);
|
||||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
strip.start();
|
||||
|
@ -450,7 +450,7 @@ void setup() {
|
|||
if (server.arg("d").toInt() >= 0) {
|
||||
ws2812fx_speed = server.arg("d").toInt();
|
||||
ws2812fx_speed = constrain(ws2812fx_speed, 0, 255);
|
||||
strip.setSpeed(ws2812fx_speed);
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
}
|
||||
|
||||
getStatusJSON();
|
||||
|
|
|
@ -44,8 +44,8 @@ enum MODE { SET_MODE, HOLD, OFF, ALL, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE,
|
|||
|
||||
MODE mode = RAINBOW; // Standard mode that is active when software starts
|
||||
|
||||
int ws2812fx_speed = 10; // Global variable for storing the delay between color changes --> smaller == faster
|
||||
int brightness = 192; // Global variable for storing the brightness (255 == 100%)
|
||||
int ws2812fx_speed = 196; // Global variable for storing the delay between color changes --> smaller == faster
|
||||
int brightness = 196; // Global variable for storing the brightness (255 == 100%)
|
||||
|
||||
int ws2812fx_mode = 0; // Helper variable to set WS2812FX modes
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ void getArgs() {
|
|||
}
|
||||
ws2812fx_speed = constrain(server.arg("s").toInt(), 0, 255);
|
||||
if (server.arg("s") == "") {
|
||||
ws2812fx_speed = 128;
|
||||
ws2812fx_speed = 196;
|
||||
}
|
||||
|
||||
ws2812fx_mode = constrain(server.arg("m").toInt(), 0, strip.getModeCount()-1);
|
||||
|
@ -38,6 +38,19 @@ void getArgs() {
|
|||
}
|
||||
|
||||
|
||||
long convertSpeed(int mcl_speed) {
|
||||
long ws2812_speed = mcl_speed * 256;
|
||||
ws2812_speed = SPEED_MAX - ws2812_speed;
|
||||
if (ws2812_speed < SPEED_MIN) {
|
||||
ws2812_speed = SPEED_MIN;
|
||||
}
|
||||
if (ws2812_speed > SPEED_MAX) {
|
||||
ws2812_speed = SPEED_MAX;
|
||||
}
|
||||
return ws2812_speed;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
// Handler functions for WS and MQTT
|
||||
// ***************************************************************************
|
||||
|
@ -260,7 +273,7 @@ int autoCount = 0;
|
|||
|
||||
void autoTick() {
|
||||
strip.setColor(autoParams[autoCount][0]);
|
||||
strip.setSpeed((uint8_t)autoParams[autoCount][1]);
|
||||
strip.setSpeed(convertSpeed((uint8_t)autoParams[autoCount][1]));
|
||||
strip.setMode((uint8_t)autoParams[autoCount][2]);
|
||||
autoTicker.once((float)autoParams[autoCount][3], autoTick);
|
||||
DBG_OUTPUT_PORT.print("autoTick ");
|
||||
|
@ -313,7 +326,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
|||
if (payload[0] == '?') {
|
||||
uint8_t d = (uint8_t) strtol((const char *) &payload[1], NULL, 10);
|
||||
ws2812fx_speed = constrain(d, 0, 255);
|
||||
strip.setSpeed(ws2812fx_speed);
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
DBG_OUTPUT_PORT.printf("WS: Set speed to: [%u]\n", ws2812fx_speed);
|
||||
webSocket.sendTXT(num, "OK");
|
||||
}
|
||||
|
@ -428,7 +441,7 @@ void checkForRequests() {
|
|||
if (payload[0] == '?') {
|
||||
uint8_t d = (uint8_t) strtol((const char *) &payload[1], NULL, 10);
|
||||
ws2812fx_speed = constrain(d, 0, 255);
|
||||
strip.setSpeed(ws2812fx_speed);
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
DBG_OUTPUT_PORT.printf("MQTT: Set speed to [%u]\n", ws2812fx_speed);
|
||||
mqtt_client.publish(mqtt_outtopic, String(String("OK ") + String((char *)payload)).c_str());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue