added klipper usermod

This commit is contained in:
lost-hope 2023-01-01 15:13:57 +01:00
parent 50875d5759
commit 0ab35a3ca3
4 changed files with 521 additions and 289 deletions

View File

@ -0,0 +1,23 @@
# Klipper Percentage Usermod
This usermod polls the Klipper API every 10s for the progressvalue.
A corresponding curl command would be:
```
curl --location --request GET 'http://[]/printer/objects/query?virtual_sdcard=progress'
```
## Usage
Compile the source with the buildflag `-D USERMOD_KLIPPER_PERCENTAGE` added.
You can also use the WLBD bot in the Discord by simply extending an exsisting build enviroment:
```
[env:esp32klipper]
extends = env:esp32dev
build_flags = -D USERMOD_KLIPPER_PERCENTAGE
```
-----
Author:
Sören Willrodt
Discord: Sören#5281

View File

@ -0,0 +1,202 @@
#pragma once
#include "wled.h"
class klipper_percentage : public Usermod
{
private:
unsigned long lastTime = 0;
String ip = "192.168.25.207";
WiFiClient wifiClient;
char errorMessage[100] = "";
int printPercent = 0;
int direction = 0; // 0 for along the strip, 1 for reversed direction
static const char _name[];
static const char _enabled[];
bool enabled = false;
void httpGet(WiFiClient &client, char *errorMessage)
{
// https://arduinojson.org/v6/example/http-client/
// is this the most compact way to do http get and put it in arduinojson object???
// would like async response ... ???
client.setTimeout(10000);
if (!client.connect("192.168.25.209", 80))
{
strcat(errorMessage, PSTR("Connection failed"));
}
else
{
// Send HTTP request
client.println(F("GET /printer/objects/query?virtual_sdcard=progress HTTP/1.0"));
client.println(F("Host: 192.168.25.209"));
client.println(F("Connection: close"));
if (client.println() == 0)
{
strcat(errorMessage, PSTR("Failed to send request"));
}
else
{
// Check HTTP status
char status[32] = {0};
client.readBytesUntil('\r', status, sizeof(status));
if (strcmp(status, "HTTP/1.1 200 OK") != 0)
{
strcat(errorMessage, PSTR("Unexpected response: "));
strcat(errorMessage, status);
}
else
{
// Skip HTTP headers
char endOfHeaders[] = "\r\n\r\n";
if (!client.find(endOfHeaders))
{
strcat(errorMessage, PSTR("Invalid response"));
}
}
}
}
}
public:
void setup()
{
}
void connected()
{
}
void loop()
{
if (WLED_CONNECTED)
{
if (millis() - lastTime > 10000)
{
httpGet(wifiClient, errorMessage);
if (strcmp(errorMessage, "") == 0)
{
PSRAMDynamicJsonDocument klipperDoc(4096); // in practive about 2673
DeserializationError error = deserializeJson(klipperDoc, wifiClient);
if (error)
{
strcat(errorMessage, PSTR("deserializeJson() failed: "));
strcat(errorMessage, error.c_str());
}
printPercent = (int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as<float>() * 100);
//DEBUG_PRINTLN(errorMessage);
DEBUG_PRINT("Percent: " );
DEBUG_PRINTLN((int)(klipperDoc["result"]["status"]["virtual_sdcard"]["progress"].as<float>() * 100));
DEBUG_PRINT("LEDs: " );
DEBUG_PRINTLN(strip.getLengthTotal() * printPercent / 100);
}
lastTime = millis();
}
}
}
void addToConfig(JsonObject &root)
{
JsonObject top = root.createNestedObject("Klipper Printing Percentage");
top["Enabled"] = enabled;
top["Klipper IP"] = ip;
top["Direction"] = direction;
}
bool readFromConfig(JsonObject &root)
{
// default settings values could be set here (or below using the 3-argument getJsonValue()) instead of in the class definition or constructor
// setting them inside readFromConfig() is slightly more robust, handling the rare but plausible use case of single value being missing after boot (e.g. if the cfg.json was manually edited and a value was removed)
JsonObject top = root["Klipper Printing Percentage"];
bool configComplete = !top.isNull();
configComplete &= getJsonValue(top["Klipper IP"], ip);
configComplete &= getJsonValue(top["Enabled"], enabled);
configComplete &= getJsonValue(top["Direction"], direction);
return configComplete;
}
/*
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
* Below it is shown how this could be used for e.g. a light sensor
*/
void addToJsonInfo(JsonObject &root)
{
JsonObject user = root["u"];
if (user.isNull())
user = root.createNestedObject("u");
JsonArray infoArr = user.createNestedArray(FPSTR(_name));
String uiDomString = F("<button class=\"btn btn-xs\" onclick=\"requestJson({");
uiDomString += FPSTR(_name);
uiDomString += F(":{");
uiDomString += FPSTR(_enabled);
uiDomString += enabled ? F(":false}});\">") : F(":true}});\">");
uiDomString += F("<i class=\"icons");
uiDomString += enabled ? F(" on") : F(" off");
uiDomString += F("\">&#xe08f;</i>");
uiDomString += F("</button>");
infoArr.add(uiDomString);
}
void addToJsonState(JsonObject &root)
{
JsonObject usermod = root[FPSTR(_name)];
if (usermod.isNull())
{
usermod = root.createNestedObject(FPSTR(_name));
}
usermod["on"] = enabled;
}
void readFromJsonState(JsonObject& root)
{
JsonObject usermod = root[FPSTR(_name)];
if (!usermod.isNull()) {
if (usermod[FPSTR(_enabled)].is<bool>()) {
enabled = usermod[FPSTR(_enabled)].as<bool>();
}
}
}
/*
* handleOverlayDraw() is called just before every show() (LED strip update frame) after effects have set the colors.
* Use this to blank out some LEDs or set them to a different color regardless of the set effect mode.
* Commonly used for custom clocks (Cronixie, 7 segment)
*/
void handleOverlayDraw()
{
if (enabled)
{
if (direction == 0) // normal
{
for (int i = 0; i < strip.getLengthTotal() * printPercent / 100; i++)
{
strip.setPixelColor(i, strip.getSegment(0).colors[1]);
}
}
else // reversed
{
for (int i = 0; i < strip.getLengthTotal() * printPercent / 100; i++)
{
strip.setPixelColor(strip.getLengthTotal() - i, strip.getSegment(0).colors[1]);
}
}
}
}
/*
* getId() allows you to optionally give your V2 usermod an unique ID (please define it in const.h!).
* This could be used in the future for the system to determine whether your usermod is installed.
*/
uint16_t getId()
{
return USERMOD_ID_KLIPPER;
}
};
const char klipper_percentage::_name[] PROGMEM = "Klipper Percentage";
const char klipper_percentage::_enabled[] PROGMEM = "enabled";

View File

@ -7,50 +7,50 @@
#define GRADIENT_PALETTE_COUNT 58
//Defaults
// Defaults
#define DEFAULT_CLIENT_SSID "Your_Network"
#define DEFAULT_AP_PASS "wled1234"
#define DEFAULT_OTA_PASS "wledota"
//increase if you need more
// increase if you need more
#ifndef WLED_MAX_USERMODS
#ifdef ESP8266
#define WLED_MAX_USERMODS 4
#else
#define WLED_MAX_USERMODS 6
#endif
#ifdef ESP8266
#define WLED_MAX_USERMODS 4
#else
#define WLED_MAX_USERMODS 6
#endif
#endif
#ifndef WLED_MAX_BUSSES
#ifdef ESP8266
#define WLED_MAX_BUSSES 3
#else
#if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM
#define WLED_MAX_BUSSES 3 // will allow 2 digital & 1 analog (or the other way around)
#elif defined(CONFIG_IDF_TARGET_ESP32S2) // 4 RMT, 8 LEDC, only has 1 I2S bus, supported in NPB
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog
#else
#define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog
#endif
#elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog
#else
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
#define WLED_MAX_BUSSES 8
#else
#define WLED_MAX_BUSSES 10
#endif
#endif
#endif
#ifdef ESP8266
#define WLED_MAX_BUSSES 3
#else
#if defined(CONFIG_IDF_TARGET_ESP32C3) // 2 RMT, 6 LEDC, only has 1 I2S but NPB does not support it ATM
#define WLED_MAX_BUSSES 3 // will allow 2 digital & 1 analog (or the other way around)
#elif defined(CONFIG_IDF_TARGET_ESP32S2) // 4 RMT, 8 LEDC, only has 1 I2S bus, supported in NPB
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog
#else
#define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog
#endif
#elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM
#define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog
#else
#if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33
#define WLED_MAX_BUSSES 8
#else
#define WLED_MAX_BUSSES 10
#endif
#endif
#endif
#endif
#ifndef WLED_MAX_BUTTONS
#ifdef ESP8266
#define WLED_MAX_BUTTONS 2
#else
#define WLED_MAX_BUTTONS 4
#endif
#ifdef ESP8266
#define WLED_MAX_BUTTONS 2
#else
#define WLED_MAX_BUTTONS 4
#endif
#endif
#ifdef ESP8266
@ -59,73 +59,74 @@
#define WLED_MAX_COLOR_ORDER_MAPPINGS 10
#endif
//Usermod IDs
#define USERMOD_ID_RESERVED 0 //Unused. Might indicate no usermod present
#define USERMOD_ID_UNSPECIFIED 1 //Default value for a general user mod that does not specify a custom ID
#define USERMOD_ID_EXAMPLE 2 //Usermod "usermod_v2_example.h"
#define USERMOD_ID_TEMPERATURE 3 //Usermod "usermod_temperature.h"
#define USERMOD_ID_FIXNETSERVICES 4 //Usermod "usermod_Fix_unreachable_netservices.h"
#define USERMOD_ID_PIRSWITCH 5 //Usermod "usermod_PIR_sensor_switch.h"
#define USERMOD_ID_IMU 6 //Usermod "usermod_mpu6050_imu.h"
#define USERMOD_ID_FOUR_LINE_DISP 7 //Usermod "usermod_v2_four_line_display.h
#define USERMOD_ID_ROTARY_ENC_UI 8 //Usermod "usermod_v2_rotary_encoder_ui.h"
#define USERMOD_ID_AUTO_SAVE 9 //Usermod "usermod_v2_auto_save.h"
#define USERMOD_ID_DHT 10 //Usermod "usermod_dht.h"
#define USERMOD_ID_MODE_SORT 11 //Usermod "usermod_v2_mode_sort.h"
#define USERMOD_ID_VL53L0X 12 //Usermod "usermod_vl53l0x_gestures.h"
#define USERMOD_ID_MULTI_RELAY 13 //Usermod "usermod_multi_relay.h"
#define USERMOD_ID_ANIMATED_STAIRCASE 14 //Usermod "Animated_Staircase.h"
#define USERMOD_ID_RTC 15 //Usermod "usermod_rtc.h"
#define USERMOD_ID_ELEKSTUBE_IPS 16 //Usermod "usermod_elekstube_ips.h"
#define USERMOD_ID_SN_PHOTORESISTOR 17 //Usermod "usermod_sn_photoresistor.h"
#define USERMOD_ID_BATTERY_STATUS_BASIC 18 //Usermod "usermod_v2_battery_status_basic.h"
#define USERMOD_ID_PWM_FAN 19 //Usermod "usermod_PWM_fan.h"
#define USERMOD_ID_BH1750 20 //Usermod "usermod_bh1750.h"
#define USERMOD_ID_SEVEN_SEGMENT_DISPLAY 21 //Usermod "usermod_v2_seven_segment_display.h"
#define USERMOD_RGB_ROTARY_ENCODER 22 //Usermod "rgb-rotary-encoder.h"
#define USERMOD_ID_QUINLED_AN_PENTA 23 //Usermod "quinled-an-penta.h"
#define USERMOD_ID_SSDR 24 //Usermod "usermod_v2_seven_segment_display_reloaded.h"
#define USERMOD_ID_CRONIXIE 25 //Usermod "usermod_cronixie.h"
#define USERMOD_ID_WIZLIGHTS 26 //Usermod "wizlights.h"
#define USERMOD_ID_WORDCLOCK 27 //Usermod "usermod_v2_word_clock.h"
#define USERMOD_ID_MY9291 28 //Usermod "usermod_MY9291.h"
#define USERMOD_ID_SI7021_MQTT_HA 29 //Usermod "usermod_si7021_mqtt_ha.h"
#define USERMOD_ID_BME280 30 //Usermod "usermod_bme280.h
#define USERMOD_ID_SMARTNEST 31 //Usermod "usermod_smartnest.h"
#define USERMOD_ID_AUDIOREACTIVE 32 //Usermod "audioreactive.h"
#define USERMOD_ID_ANALOG_CLOCK 33 //Usermod "Analog_Clock.h"
#define USERMOD_ID_PING_PONG_CLOCK 34 //Usermod "usermod_v2_ping_pong_clock.h"
#define USERMOD_ID_ADS1115 35 //Usermod "usermod_ads1115.h"
// Usermod IDs
#define USERMOD_ID_RESERVED 0 // Unused. Might indicate no usermod present
#define USERMOD_ID_UNSPECIFIED 1 // Default value for a general user mod that does not specify a custom ID
#define USERMOD_ID_EXAMPLE 2 // Usermod "usermod_v2_example.h"
#define USERMOD_ID_TEMPERATURE 3 // Usermod "usermod_temperature.h"
#define USERMOD_ID_FIXNETSERVICES 4 // Usermod "usermod_Fix_unreachable_netservices.h"
#define USERMOD_ID_PIRSWITCH 5 // Usermod "usermod_PIR_sensor_switch.h"
#define USERMOD_ID_IMU 6 // Usermod "usermod_mpu6050_imu.h"
#define USERMOD_ID_FOUR_LINE_DISP 7 // Usermod "usermod_v2_four_line_display.h
#define USERMOD_ID_ROTARY_ENC_UI 8 // Usermod "usermod_v2_rotary_encoder_ui.h"
#define USERMOD_ID_AUTO_SAVE 9 // Usermod "usermod_v2_auto_save.h"
#define USERMOD_ID_DHT 10 // Usermod "usermod_dht.h"
#define USERMOD_ID_MODE_SORT 11 // Usermod "usermod_v2_mode_sort.h"
#define USERMOD_ID_VL53L0X 12 // Usermod "usermod_vl53l0x_gestures.h"
#define USERMOD_ID_MULTI_RELAY 13 // Usermod "usermod_multi_relay.h"
#define USERMOD_ID_ANIMATED_STAIRCASE 14 // Usermod "Animated_Staircase.h"
#define USERMOD_ID_RTC 15 // Usermod "usermod_rtc.h"
#define USERMOD_ID_ELEKSTUBE_IPS 16 // Usermod "usermod_elekstube_ips.h"
#define USERMOD_ID_SN_PHOTORESISTOR 17 // Usermod "usermod_sn_photoresistor.h"
#define USERMOD_ID_BATTERY_STATUS_BASIC 18 // Usermod "usermod_v2_battery_status_basic.h"
#define USERMOD_ID_PWM_FAN 19 // Usermod "usermod_PWM_fan.h"
#define USERMOD_ID_BH1750 20 // Usermod "usermod_bh1750.h"
#define USERMOD_ID_SEVEN_SEGMENT_DISPLAY 21 // Usermod "usermod_v2_seven_segment_display.h"
#define USERMOD_RGB_ROTARY_ENCODER 22 // Usermod "rgb-rotary-encoder.h"
#define USERMOD_ID_QUINLED_AN_PENTA 23 // Usermod "quinled-an-penta.h"
#define USERMOD_ID_SSDR 24 // Usermod "usermod_v2_seven_segment_display_reloaded.h"
#define USERMOD_ID_CRONIXIE 25 // Usermod "usermod_cronixie.h"
#define USERMOD_ID_WIZLIGHTS 26 // Usermod "wizlights.h"
#define USERMOD_ID_WORDCLOCK 27 // Usermod "usermod_v2_word_clock.h"
#define USERMOD_ID_MY9291 28 // Usermod "usermod_MY9291.h"
#define USERMOD_ID_SI7021_MQTT_HA 29 // Usermod "usermod_si7021_mqtt_ha.h"
#define USERMOD_ID_BME280 30 // Usermod "usermod_bme280.h
#define USERMOD_ID_SMARTNEST 31 // Usermod "usermod_smartnest.h"
#define USERMOD_ID_AUDIOREACTIVE 32 // Usermod "audioreactive.h"
#define USERMOD_ID_ANALOG_CLOCK 33 // Usermod "Analog_Clock.h"
#define USERMOD_ID_PING_PONG_CLOCK 34 // Usermod "usermod_v2_ping_pong_clock.h"
#define USERMOD_ID_ADS1115 35 // Usermod "usermod_ads1115.h"
#define USERMOD_ID_KLIPPER 36 // Usermod Klipper percentage
//Access point behavior
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot
#define AP_BEHAVIOR_NO_CONN 1 //Open when no connection (either after boot or if connection is lost)
#define AP_BEHAVIOR_ALWAYS 2 //Always open
#define AP_BEHAVIOR_BUTTON_ONLY 3 //Only when button pressed for 6 sec
// Access point behavior
#define AP_BEHAVIOR_BOOT_NO_CONN 0 // Open AP when no connection after boot
#define AP_BEHAVIOR_NO_CONN 1 // Open when no connection (either after boot or if connection is lost)
#define AP_BEHAVIOR_ALWAYS 2 // Always open
#define AP_BEHAVIOR_BUTTON_ONLY 3 // Only when button pressed for 6 sec
//Notifier callMode
#define CALL_MODE_INIT 0 //no updates on init, can be used to disable updates
// Notifier callMode
#define CALL_MODE_INIT 0 // no updates on init, can be used to disable updates
#define CALL_MODE_DIRECT_CHANGE 1
#define CALL_MODE_BUTTON 2 //default button actions applied to selected segments
#define CALL_MODE_BUTTON 2 // default button actions applied to selected segments
#define CALL_MODE_NOTIFICATION 3
#define CALL_MODE_NIGHTLIGHT 4
#define CALL_MODE_NO_NOTIFY 5
#define CALL_MODE_FX_CHANGED 6 //no longer used
#define CALL_MODE_FX_CHANGED 6 // no longer used
#define CALL_MODE_HUE 7
#define CALL_MODE_PRESET_CYCLE 8
#define CALL_MODE_BLYNK 9
#define CALL_MODE_ALEXA 10
#define CALL_MODE_WS_SEND 11 //special call mode, not for notifier, updates websocket only
#define CALL_MODE_BUTTON_PRESET 12 //button/IR JSON preset/macro
#define CALL_MODE_WS_SEND 11 // special call mode, not for notifier, updates websocket only
#define CALL_MODE_BUTTON_PRESET 12 // button/IR JSON preset/macro
//RGB to RGBW conversion mode
#define RGBW_MODE_MANUAL_ONLY 0 //No automatic white channel calculation. Manual white channel slider
#define RGBW_MODE_AUTO_BRIGHTER 1 //New algorithm. Adds as much white as the darkest RGBW channel
#define RGBW_MODE_AUTO_ACCURATE 2 //New algorithm. Adds as much white as the darkest RGBW channel and subtracts this amount from each RGB channel
#define RGBW_MODE_DUAL 3 //Manual slider + auto calculation. Automatically calculates only if manual slider is set to off (0)
#define RGBW_MODE_LEGACY 4 //Old floating algorithm. Too slow for realtime and palette support
// RGB to RGBW conversion mode
#define RGBW_MODE_MANUAL_ONLY 0 // No automatic white channel calculation. Manual white channel slider
#define RGBW_MODE_AUTO_BRIGHTER 1 // New algorithm. Adds as much white as the darkest RGBW channel
#define RGBW_MODE_AUTO_ACCURATE 2 // New algorithm. Adds as much white as the darkest RGBW channel and subtracts this amount from each RGB channel
#define RGBW_MODE_DUAL 3 // Manual slider + auto calculation. Automatically calculates only if manual slider is set to off (0)
#define RGBW_MODE_LEGACY 4 // Old floating algorithm. Too slow for realtime and palette support
//realtime modes
// realtime modes
#define REALTIME_MODE_INACTIVE 0
#define REALTIME_MODE_GENERIC 1
#define REALTIME_MODE_UDP 2
@ -136,23 +137,23 @@
#define REALTIME_MODE_TPM2NET 7
#define REALTIME_MODE_DDP 8
//realtime override modes
// realtime override modes
#define REALTIME_OVERRIDE_NONE 0
#define REALTIME_OVERRIDE_ONCE 1
#define REALTIME_OVERRIDE_ALWAYS 2
//E1.31 DMX modes
#define DMX_MODE_DISABLED 0 //not used
#define DMX_MODE_SINGLE_RGB 1 //all LEDs same RGB color (3 channels)
#define DMX_MODE_SINGLE_DRGB 2 //all LEDs same RGB color and master dimmer (4 channels)
#define DMX_MODE_EFFECT 3 //trigger standalone effects of WLED (11 channels)
#define DMX_MODE_MULTIPLE_RGB 4 //every LED is addressed with its own RGB (ledCount * 3 channels)
#define DMX_MODE_MULTIPLE_DRGB 5 //every LED is addressed with its own RGB and share a master dimmer (ledCount * 3 + 1 channels)
#define DMX_MODE_MULTIPLE_RGBW 6 //every LED is addressed with its own RGBW (ledCount * 4 channels)
// E1.31 DMX modes
#define DMX_MODE_DISABLED 0 // not used
#define DMX_MODE_SINGLE_RGB 1 // all LEDs same RGB color (3 channels)
#define DMX_MODE_SINGLE_DRGB 2 // all LEDs same RGB color and master dimmer (4 channels)
#define DMX_MODE_EFFECT 3 // trigger standalone effects of WLED (11 channels)
#define DMX_MODE_MULTIPLE_RGB 4 // every LED is addressed with its own RGB (ledCount * 3 channels)
#define DMX_MODE_MULTIPLE_DRGB 5 // every LED is addressed with its own RGB and share a master dimmer (ledCount * 3 + 1 channels)
#define DMX_MODE_MULTIPLE_RGBW 6 // every LED is addressed with its own RGBW (ledCount * 4 channels)
//Light capability byte (unused) 0bRCCCTTTT
//bits 0/1/2/3: specifies a type of LED driver. A single "driver" may have different chip models but must have the same protocol/behavior
//bits 4/5/6: specifies the class of LED driver - 0b000 (dec. 0-15) unconfigured/reserved
// Light capability byte (unused) 0bRCCCTTTT
// bits 0/1/2/3: specifies a type of LED driver. A single "driver" may have different chip models but must have the same protocol/behavior
// bits 4/5/6: specifies the class of LED driver - 0b000 (dec. 0-15) unconfigured/reserved
// - 0b001 (dec. 16-31) digital (data pin only)
// - 0b010 (dec. 32-47) analog (PWM)
// - 0b011 (dec. 48-63) digital (data + clock / SPI)
@ -160,54 +161,53 @@
// - 0b101 (dec. 80-95) virtual network busses
// - 0b110 (dec. 96-111) unused/reserved
// - 0b111 (dec. 112-127) unused/reserved
//bit 7 is reserved and set to 0
// bit 7 is reserved and set to 0
#define TYPE_NONE 0 //light is not configured
#define TYPE_RESERVED 1 //unused. Might indicate a "virtual" light
//Digital types (data pin only) (16-31)
#define TYPE_WS2812_1CH 20 //white-only chips
#define TYPE_WS2812_WWA 21 //amber + warm + cold white
#define TYPE_NONE 0 // light is not configured
#define TYPE_RESERVED 1 // unused. Might indicate a "virtual" light
// Digital types (data pin only) (16-31)
#define TYPE_WS2812_1CH 20 // white-only chips
#define TYPE_WS2812_WWA 21 // amber + warm + cold white
#define TYPE_WS2812_RGB 22
#define TYPE_GS8608 23 //same driver as WS2812, but will require signal 2x per second (else displays test pattern)
#define TYPE_WS2811_400KHZ 24 //half-speed WS2812 protocol, used by very old WS2811 units
#define TYPE_GS8608 23 // same driver as WS2812, but will require signal 2x per second (else displays test pattern)
#define TYPE_WS2811_400KHZ 24 // half-speed WS2812 protocol, used by very old WS2811 units
#define TYPE_TM1829 25
#define TYPE_SK6812_RGBW 30
#define TYPE_TM1814 31
//"Analog" types (PWM) (32-47)
#define TYPE_ONOFF 40 //binary output (relays etc.)
#define TYPE_ANALOG_1CH 41 //single channel PWM. Uses value of brightest RGBW channel
#define TYPE_ANALOG_2CH 42 //analog WW + CW
#define TYPE_ANALOG_3CH 43 //analog RGB
#define TYPE_ANALOG_4CH 44 //analog RGBW
#define TYPE_ANALOG_5CH 45 //analog RGB + WW + CW
//Digital types (data + clock / SPI) (48-63)
#define TYPE_ONOFF 40 // binary output (relays etc.)
#define TYPE_ANALOG_1CH 41 // single channel PWM. Uses value of brightest RGBW channel
#define TYPE_ANALOG_2CH 42 // analog WW + CW
#define TYPE_ANALOG_3CH 43 // analog RGB
#define TYPE_ANALOG_4CH 44 // analog RGBW
#define TYPE_ANALOG_5CH 45 // analog RGB + WW + CW
// Digital types (data + clock / SPI) (48-63)
#define TYPE_WS2801 50
#define TYPE_APA102 51
#define TYPE_LPD8806 52
#define TYPE_P9813 53
#define TYPE_LPD6803 54
//Network types (master broadcast) (80-95)
#define TYPE_NET_DDP_RGB 80 //network DDP RGB bus (master broadcast bus)
#define TYPE_NET_E131_RGB 81 //network E131 RGB bus (master broadcast bus, unused)
#define TYPE_NET_ARTNET_RGB 82 //network ArtNet RGB bus (master broadcast bus, unused)
#define TYPE_NET_DDP_RGBW 88 //network DDP RGBW bus (master broadcast bus)
// Network types (master broadcast) (80-95)
#define TYPE_NET_DDP_RGB 80 // network DDP RGB bus (master broadcast bus)
#define TYPE_NET_E131_RGB 81 // network E131 RGB bus (master broadcast bus, unused)
#define TYPE_NET_ARTNET_RGB 82 // network ArtNet RGB bus (master broadcast bus, unused)
#define TYPE_NET_DDP_RGBW 88 // network DDP RGBW bus (master broadcast bus)
#define IS_DIGITAL(t) ((t) & 0x10) //digital are 16-31 and 48-63
#define IS_DIGITAL(t) ((t)&0x10) // digital are 16-31 and 48-63
#define IS_PWM(t) ((t) > 40 && (t) < 46)
#define NUM_PWM_PINS(t) ((t) - 40) //for analog PWM 41-45 only
#define NUM_PWM_PINS(t) ((t)-40) // for analog PWM 41-45 only
#define IS_2PIN(t) ((t) > 47)
//Color orders
#define COL_ORDER_GRB 0 //GRB(w),defaut
#define COL_ORDER_RGB 1 //common for WS2811
// Color orders
#define COL_ORDER_GRB 0 // GRB(w),defaut
#define COL_ORDER_RGB 1 // common for WS2811
#define COL_ORDER_BRG 2
#define COL_ORDER_RBG 3
#define COL_ORDER_BGR 4
#define COL_ORDER_GBR 5
#define COL_ORDER_MAX 5
//Button type
// Button type
#define BTN_TYPE_NONE 0
#define BTN_TYPE_RESERVED 1
#define BTN_TYPE_PUSH 2
@ -218,7 +218,7 @@
#define BTN_TYPE_ANALOG 7
#define BTN_TYPE_ANALOG_INVERTED 8
//Ethernet board types
// Ethernet board types
#define WLED_NUM_ETH_TYPES 9
#define WLED_ETH_NONE 0
@ -229,7 +229,7 @@
#define WLED_ETH_TWILIGHTLORD 5
#define WLED_ETH_ESP32DEUX 6
//Hue error codes
// Hue error codes
#define HUE_ERROR_INACTIVE 0
#define HUE_ERROR_UNAUTHORIZED 1
#define HUE_ERROR_LIGHTID 3
@ -238,19 +238,19 @@
#define HUE_ERROR_TIMEOUT 251
#define HUE_ERROR_ACTIVE 255
//Segment option byte bits
// Segment option byte bits
#define SEG_OPTION_SELECTED 0
#define SEG_OPTION_REVERSED 1
#define SEG_OPTION_ON 2
#define SEG_OPTION_MIRROR 3 //Indicates that the effect will be mirrored within the segment
#define SEG_OPTION_FREEZE 4 //Segment contents will not be refreshed
#define SEG_OPTION_RESET 5 //Segment runtime requires reset
#define SEG_OPTION_MIRROR 3 // Indicates that the effect will be mirrored within the segment
#define SEG_OPTION_FREEZE 4 // Segment contents will not be refreshed
#define SEG_OPTION_RESET 5 // Segment runtime requires reset
#define SEG_OPTION_TRANSITIONAL 6
#define SEG_OPTION_REVERSED_Y 7
#define SEG_OPTION_MIRROR_Y 8
#define SEG_OPTION_TRANSPOSED 9
//Segment differs return byte
// Segment differs return byte
#define SEG_DIFFERS_BRI 0x01
#define SEG_DIFFERS_OPT 0x02
#define SEG_DIFFERS_COL 0x04
@ -259,7 +259,7 @@
#define SEG_DIFFERS_GSO 0x20
#define SEG_DIFFERS_SEL 0x80
//Playlist option byte
// Playlist option byte
#define PL_OPTION_SHUFFLE 0x01
// WLED Error modes
@ -276,34 +276,33 @@
#define ERR_OVERCURRENT 31 // An attached current sensor has measured a current above the threshold (not implemented)
#define ERR_UNDERVOLT 32 // An attached voltmeter has measured a voltage below the threshold (not implemented)
//Timer mode types
#define NL_MODE_SET 0 //After nightlight time elapsed, set to target brightness
#define NL_MODE_FADE 1 //Fade to target brightness gradually
#define NL_MODE_COLORFADE 2 //Fade to target brightness and secondary color gradually
#define NL_MODE_SUN 3 //Sunrise/sunset. Target brightness is set immediately, then Sunrise effect is started. Max 60 min.
// Timer mode types
#define NL_MODE_SET 0 // After nightlight time elapsed, set to target brightness
#define NL_MODE_FADE 1 // Fade to target brightness gradually
#define NL_MODE_COLORFADE 2 // Fade to target brightness and secondary color gradually
#define NL_MODE_SUN 3 // Sunrise/sunset. Target brightness is set immediately, then Sunrise effect is started. Max 60 min.
#define NTP_PACKET_SIZE 48
//maximum number of rendered LEDs - this does not have to match max. physical LEDs, e.g. if there are virtual busses
// maximum number of rendered LEDs - this does not have to match max. physical LEDs, e.g. if there are virtual busses
#ifndef MAX_LEDS
#ifdef ESP8266
#define MAX_LEDS 1664 //can't rely on memory limit to limit this to 1600 LEDs
#define MAX_LEDS 1664 // can't rely on memory limit to limit this to 1600 LEDs
#else
#define MAX_LEDS 8192
#endif
#endif
#ifndef MAX_LED_MEMORY
#ifdef ESP8266
#define MAX_LED_MEMORY 4000
#else
#if defined(ARDUINO_ARCH_ESP32S2) || defined(ARDUINO_ARCH_ESP32C3)
#define MAX_LED_MEMORY 32000
#else
#define MAX_LED_MEMORY 64000
#endif
#endif
#ifdef ESP8266
#define MAX_LED_MEMORY 4000
#else
#if defined(ARDUINO_ARCH_ESP32S2) || defined(ARDUINO_ARCH_ESP32C3)
#define MAX_LED_MEMORY 32000
#else
#define MAX_LED_MEMORY 64000
#endif
#endif
#endif
#ifndef MAX_LEDS_PER_BUS
@ -318,31 +317,31 @@
#endif
#ifdef WLED_USE_ETHERNET
#define E131_MAX_UNIVERSE_COUNT 20
#define E131_MAX_UNIVERSE_COUNT 20
#else
#ifdef ESP8266
#define E131_MAX_UNIVERSE_COUNT 9
#else
#define E131_MAX_UNIVERSE_COUNT 12
#endif
#ifdef ESP8266
#define E131_MAX_UNIVERSE_COUNT 9
#else
#define E131_MAX_UNIVERSE_COUNT 12
#endif
#endif
#ifndef ABL_MILLIAMPS_DEFAULT
#define ABL_MILLIAMPS_DEFAULT 850 // auto lower brightness to stay close to milliampere limit
#define ABL_MILLIAMPS_DEFAULT 850 // auto lower brightness to stay close to milliampere limit
#else
#if ABL_MILLIAMPS_DEFAULT == 0 // disable ABL
#elif ABL_MILLIAMPS_DEFAULT < 250 // make sure value is at least 250
#warning "make sure value is at least 250"
#define ABL_MILLIAMPS_DEFAULT 250
#endif
#if ABL_MILLIAMPS_DEFAULT == 0 // disable ABL
#elif ABL_MILLIAMPS_DEFAULT < 250 // make sure value is at least 250
#warning "make sure value is at least 250"
#define ABL_MILLIAMPS_DEFAULT 250
#endif
#endif
// PWM settings
#ifndef WLED_PWM_FREQ
#ifdef ESP8266
#define WLED_PWM_FREQ 880 //PWM frequency proven as good for LEDs
#define WLED_PWM_FREQ 880 // PWM frequency proven as good for LEDs
#else
#define WLED_PWM_FREQ 19531
#define WLED_PWM_FREQ 19531
#endif
#endif
@ -350,81 +349,81 @@
// Size of buffer for API JSON object (increase for more segments)
#ifdef ESP8266
#define JSON_BUFFER_SIZE 10240
#define JSON_BUFFER_SIZE 10240
#else
#define JSON_BUFFER_SIZE 24576
#define JSON_BUFFER_SIZE 24576
#endif
//#define MIN_HEAP_SIZE (MAX_LED_MEMORY+2048)
// #define MIN_HEAP_SIZE (MAX_LED_MEMORY+2048)
#define MIN_HEAP_SIZE (8192)
// Maximum size of node map (list of other WLED instances)
#ifdef ESP8266
#define WLED_MAX_NODES 24
#define WLED_MAX_NODES 24
#else
#define WLED_MAX_NODES 150
#define WLED_MAX_NODES 150
#endif
//this is merely a default now and can be changed at runtime
// this is merely a default now and can be changed at runtime
#ifndef LEDPIN
#if defined(ESP8266) || (defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)) || defined(CONFIG_IDF_TARGET_ESP32C3)
#define LEDPIN 2 // GPIO2 (D4) on Wemod D1 mini compatible boards
#define LEDPIN 2 // GPIO2 (D4) on Wemod D1 mini compatible boards
#else
#define LEDPIN 16 // aligns with GPIO2 (D4) on Wemos D1 mini32 compatible boards
#define LEDPIN 16 // aligns with GPIO2 (D4) on Wemos D1 mini32 compatible boards
#endif
#endif
#ifdef WLED_ENABLE_DMX
#if (LEDPIN == 2)
#undef LEDPIN
#define LEDPIN 1
#warning "Pin conflict compiling with DMX and LEDs on pin 2. The default LED pin has been changed to pin 1."
#undef LEDPIN
#define LEDPIN 1
#warning "Pin conflict compiling with DMX and LEDs on pin 2. The default LED pin has been changed to pin 1."
#endif
#endif
#ifndef DEFAULT_LED_COUNT
#define DEFAULT_LED_COUNT 30
#define DEFAULT_LED_COUNT 30
#endif
#define INTERFACE_UPDATE_COOLDOWN 2000 //time in ms to wait between websockets, alexa, and MQTT updates
#define INTERFACE_UPDATE_COOLDOWN 2000 // time in ms to wait between websockets, alexa, and MQTT updates
#if defined(ESP8266) && defined(HW_PIN_SCL)
#undef HW_PIN_SCL
#undef HW_PIN_SCL
#endif
#if defined(ESP8266) && defined(HW_PIN_SDA)
#undef HW_PIN_SDA
#undef HW_PIN_SDA
#endif
#ifndef HW_PIN_SCL
#define HW_PIN_SCL SCL
#define HW_PIN_SCL SCL
#endif
#ifndef HW_PIN_SDA
#define HW_PIN_SDA SDA
#define HW_PIN_SDA SDA
#endif
#if defined(ESP8266) && defined(HW_PIN_CLOCKSPI)
#undef HW_PIN_CLOCKSPI
#undef HW_PIN_CLOCKSPI
#endif
#if defined(ESP8266) && defined(HW_PIN_DATASPI)
#undef HW_PIN_DATASPI
#undef HW_PIN_DATASPI
#endif
#if defined(ESP8266) && defined(HW_PIN_MISOSPI)
#undef HW_PIN_MISOSPI
#undef HW_PIN_MISOSPI
#endif
#if defined(ESP8266) && defined(HW_PIN_CSSPI)
#undef HW_PIN_CSSPI
#undef HW_PIN_CSSPI
#endif
// defaults for VSPI
#ifndef HW_PIN_CLOCKSPI
#define HW_PIN_CLOCKSPI SCK
#define HW_PIN_CLOCKSPI SCK
#endif
#ifndef HW_PIN_DATASPI
#define HW_PIN_DATASPI MOSI
#define HW_PIN_DATASPI MOSI
#endif
#ifndef HW_PIN_MISOSPI
#define HW_PIN_MISOSPI MISO
#define HW_PIN_MISOSPI MISO
#endif
#ifndef HW_PIN_CSSPI
#define HW_PIN_CSSPI SS
#define HW_PIN_CSSPI SS
#endif
#endif

View File

@ -160,6 +160,10 @@
#include "../usermods/ADS1115_v2/usermod_ads1115.h"
#endif
#ifdef USERMOD_KLIPPER_PERCENTAGE
#include "..\usermods\usermod_v2_klipper_percentage\usermod_v2_klipper_percentage.h"
#endif
void registerUsermods()
{
/*
@ -307,4 +311,8 @@ void registerUsermods()
#ifdef USERMOD_ADS1115
usermods.add(new ADS1115Usermod());
#endif
#ifdef USERMOD_KLIPPER_PERCENTAGE
usermods.add(new klipper_percentage());
#endif
}