Add seven_seg debug build
This commit is contained in:
parent
22fc58d93b
commit
3ac772badc
@ -12,7 +12,7 @@
|
||||
; default_envs = travis_esp8266, travis_esp32
|
||||
|
||||
# Release binaries
|
||||
default_envs = nodemcuv2, esp01_1m_full, esp32dev, esp32_eth
|
||||
;default_envs = nodemcuv2, esp01_1m_full, esp32dev, esp32_eth
|
||||
|
||||
# Build everything
|
||||
; default_envs = esp32dev, esp8285_4CH_MagicHome, esp8285_4CH_H801, codm-controller-0.6-rev2, codm-controller-0.6, esp32s2_saola, d1_mini_5CH_Shojo_PCB, d1_mini, sp501e, travis_esp8266, travis_esp32, nodemcuv2, esp32_eth, anavi_miracle_controller, esp07, esp01_1m_full, m5atom, h803wf, d1_mini_ota, heltec_wifi_kit_8, esp8285_5CH_H801, d1_mini_debug, wemos_shield_esp32, elekstube_ips
|
||||
@ -23,6 +23,7 @@ default_envs = nodemcuv2, esp01_1m_full, esp32dev, esp32_eth
|
||||
; default_envs = esp01_1m_full
|
||||
; default_envs = esp07
|
||||
; default_envs = d1_mini
|
||||
default_envs = d1_mini_seven_seg
|
||||
; default_envs = heltec_wifi_kit_8
|
||||
; default_envs = h803wf
|
||||
; default_envs = d1_mini_debug
|
||||
@ -498,3 +499,16 @@ monitor_filters = esp32_exception_decoder
|
||||
lib_deps =
|
||||
${esp32.lib_deps}
|
||||
TFT_eSPI @ ^2.3.70
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# User Mod SevenSegment
|
||||
# ------------------------------------------------------------------------------
|
||||
[env:d1_mini_seven_seg]
|
||||
board = d1_mini
|
||||
build_type = debug
|
||||
platform = ${common.platform_wled_default}
|
||||
platform_packages = ${common.platform_packages}
|
||||
board_build.ldscript = ${common.ldscript_4m1m}
|
||||
build_unflags = ${common.build_unflags}
|
||||
build_flags = ${common.build_flags_esp8266} ${common.debug_flags} -D USERMOD_SEVEN_SEGMENT
|
||||
lib_deps = ${esp8266.lib_deps}
|
||||
|
@ -256,199 +256,199 @@ class SevenSegmentDisplay : public Usermod {
|
||||
_overlaySevenSegmentDraw();
|
||||
}
|
||||
|
||||
void onMqttConnect(bool sessionPresent)
|
||||
{
|
||||
if (mqttDeviceTopic[0] == 0)
|
||||
return;
|
||||
// void onMqttConnect(bool sessionPresent)
|
||||
// {
|
||||
// if (mqttDeviceTopic[0] == 0)
|
||||
// return;
|
||||
|
||||
for (int pinNr = 0; pinNr < NUM_SWITCH_PINS; pinNr++) {
|
||||
char buf[128];
|
||||
StaticJsonDocument<1024> json;
|
||||
sprintf(buf, "%s Switch %d", serverDescription, pinNr + 1);
|
||||
json[F("name")] = buf;
|
||||
// for (int pinNr = 0; pinNr < NUM_SWITCH_PINS; pinNr++) {
|
||||
// char buf[128];
|
||||
// StaticJsonDocument<1024> json;
|
||||
// sprintf(buf, "%s Switch %d", serverDescription, pinNr + 1);
|
||||
// json[F("name")] = buf;
|
||||
|
||||
sprintf(buf, "%s/switch/%d", mqttDeviceTopic, pinNr);
|
||||
json["~"] = buf;
|
||||
strcat(buf, "/set");
|
||||
mqtt->subscribe(buf, 0);
|
||||
// sprintf(buf, "%s/switch/%d", mqttDeviceTopic, pinNr);
|
||||
// json["~"] = buf;
|
||||
// strcat(buf, "/set");
|
||||
// mqtt->subscribe(buf, 0);
|
||||
|
||||
json[F("stat_t")] = "~/state";
|
||||
json[F("cmd_t")] = "~/set";
|
||||
json[F("pl_off")] = F("OFF");
|
||||
json[F("pl_on")] = F("ON");
|
||||
// json[F("stat_t")] = "~/state";
|
||||
// json[F("cmd_t")] = "~/set";
|
||||
// json[F("pl_off")] = F("OFF");
|
||||
// json[F("pl_on")] = F("ON");
|
||||
|
||||
char uid[16];
|
||||
sprintf(uid, "%s_sw%d", escapedMac.c_str(), pinNr);
|
||||
json[F("unique_id")] = uid;
|
||||
// char uid[16];
|
||||
// sprintf(uid, "%s_sw%d", escapedMac.c_str(), pinNr);
|
||||
// json[F("unique_id")] = uid;
|
||||
|
||||
strcpy(buf, mqttDeviceTopic);
|
||||
strcat(buf, "/status");
|
||||
json[F("avty_t")] = buf;
|
||||
json[F("pl_avail")] = F("online");
|
||||
json[F("pl_not_avail")] = F("offline");
|
||||
//TODO: dev
|
||||
sprintf(buf, "homeassistant/switch/%s/config", uid);
|
||||
char json_str[1024];
|
||||
size_t payload_size = serializeJson(json, json_str);
|
||||
mqtt->publish(buf, 0, true, json_str, payload_size);
|
||||
updateState(pinNr);
|
||||
}
|
||||
}
|
||||
// strcpy(buf, mqttDeviceTopic);
|
||||
// strcat(buf, "/status");
|
||||
// json[F("avty_t")] = buf;
|
||||
// json[F("pl_avail")] = F("online");
|
||||
// json[F("pl_not_avail")] = F("offline");
|
||||
// //TODO: dev
|
||||
// sprintf(buf, "homeassistant/switch/%s/config", uid);
|
||||
// char json_str[1024];
|
||||
// size_t payload_size = serializeJson(json, json_str);
|
||||
// mqtt->publish(buf, 0, true, json_str, payload_size);
|
||||
// updateState(pinNr);
|
||||
// }
|
||||
// }
|
||||
|
||||
bool onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)
|
||||
{
|
||||
//Note: Payload is not necessarily null terminated. Check "len" instead.
|
||||
for (int pinNr = 0; pinNr < NUM_SWITCH_PINS; pinNr++) {
|
||||
char buf[64];
|
||||
sprintf(buf, "%s/switch/%d/set", mqttDeviceTopic, pinNr);
|
||||
if (strcmp(topic, buf) == 0) {
|
||||
//Any string starting with "ON" is interpreted as ON, everything else as OFF
|
||||
setState(pinNr, len >= 2 && payload[0] == 'O' && payload[1] == 'N');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// bool onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)
|
||||
// {
|
||||
// //Note: Payload is not necessarily null terminated. Check "len" instead.
|
||||
// for (int pinNr = 0; pinNr < NUM_SWITCH_PINS; pinNr++) {
|
||||
// char buf[64];
|
||||
// sprintf(buf, "%s/switch/%d/set", mqttDeviceTopic, pinNr);
|
||||
// if (strcmp(topic, buf) == 0) {
|
||||
// //Any string starting with "ON" is interpreted as ON, everything else as OFF
|
||||
// setState(pinNr, len >= 2 && payload[0] == 'O' && payload[1] == 'N');
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
int reading = 20;
|
||||
//this code adds "u":{"Light":[20," lux"]} to the info object
|
||||
JsonObject user = root["u"];
|
||||
if (user.isNull()) user = root.createNestedObject("u");
|
||||
// /*
|
||||
// * 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)
|
||||
// {
|
||||
// int reading = 20;
|
||||
// //this code adds "u":{"Light":[20," lux"]} to the info object
|
||||
// JsonObject user = root["u"];
|
||||
// if (user.isNull()) user = root.createNestedObject("u");
|
||||
|
||||
JsonArray lightArr = user.createNestedArray("Light"); //name
|
||||
lightArr.add(reading); //value
|
||||
lightArr.add(" lux"); //unit
|
||||
}
|
||||
*/
|
||||
// JsonArray lightArr = user.createNestedArray("Light"); //name
|
||||
// lightArr.add(reading); //value
|
||||
// lightArr.add(" lux"); //unit
|
||||
// }
|
||||
// */
|
||||
|
||||
|
||||
/*
|
||||
* addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
|
||||
* Values in the state object may be modified by connected clients
|
||||
*/
|
||||
void addToJsonState(JsonObject& root)
|
||||
{
|
||||
//root["user0"] = userVar0;
|
||||
}
|
||||
// /*
|
||||
// * addToJsonState() can be used to add custom entries to the /json/state part of the JSON API (state object).
|
||||
// * Values in the state object may be modified by connected clients
|
||||
// */
|
||||
// void addToJsonState(JsonObject& root)
|
||||
// {
|
||||
// //root["user0"] = userVar0;
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
* readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
|
||||
* Values in the state object may be modified by connected clients
|
||||
*/
|
||||
void readFromJsonState(JsonObject& root)
|
||||
{
|
||||
userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value
|
||||
//if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!"));
|
||||
}
|
||||
// /*
|
||||
// * readFromJsonState() can be used to receive data clients send to the /json/state part of the JSON API (state object).
|
||||
// * Values in the state object may be modified by connected clients
|
||||
// */
|
||||
// void readFromJsonState(JsonObject& root)
|
||||
// {
|
||||
// userVar0 = root["user0"] | userVar0; //if "user0" key exists in JSON, update, else keep old value
|
||||
// //if (root["bri"] == 255) Serial.println(F("Don't burn down your garage!"));
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
* addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object.
|
||||
* It will be called by WLED when settings are actually saved (for example, LED settings are saved)
|
||||
* If you want to force saving the current state, use serializeConfig() in your loop().
|
||||
*
|
||||
* CAUTION: serializeConfig() will initiate a filesystem write operation.
|
||||
* It might cause the LEDs to stutter and will cause flash wear if called too often.
|
||||
* Use it sparingly and always in the loop, never in network callbacks!
|
||||
*
|
||||
* addToConfig() will make your settings editable through the Usermod Settings page automatically.
|
||||
*
|
||||
* Usermod Settings Overview:
|
||||
* - Numeric values are treated as floats in the browser.
|
||||
* - If the numeric value entered into the browser contains a decimal point, it will be parsed as a C float
|
||||
* before being returned to the Usermod. The float data type has only 6-7 decimal digits of precision, and
|
||||
* doubles are not supported, numbers will be rounded to the nearest float value when being parsed.
|
||||
* The range accepted by the input field is +/- 1.175494351e-38 to +/- 3.402823466e+38.
|
||||
* - If the numeric value entered into the browser doesn't contain a decimal point, it will be parsed as a
|
||||
* C int32_t (range: -2147483648 to 2147483647) before being returned to the usermod.
|
||||
* Overflows or underflows are truncated to the max/min value for an int32_t, and again truncated to the type
|
||||
* used in the Usermod when reading the value from ArduinoJson.
|
||||
* - Pin values can be treated differently from an integer value by using the key name "pin"
|
||||
* - "pin" can contain a single or array of integer values
|
||||
* - On the Usermod Settings page there is simple checking for pin conflicts and warnings for special pins
|
||||
* - Red color indicates a conflict. Yellow color indicates a pin with a warning (e.g. an input-only pin)
|
||||
* - Tip: use int8_t to store the pin value in the Usermod, so a -1 value (pin not set) can be used
|
||||
*
|
||||
* See usermod_v2_auto_save.h for an example that saves Flash space by reusing ArduinoJson key name strings
|
||||
*
|
||||
* If you need a dedicated settings page with custom layout for your Usermod, that takes a lot more work.
|
||||
* You will have to add the setting to the HTML, xml.cpp and set.cpp manually.
|
||||
* See the WLED Soundreactive fork (code and wiki) for reference. https://github.com/atuline/WLED
|
||||
*
|
||||
* I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings!
|
||||
*/
|
||||
void addToConfig(JsonObject& root)
|
||||
{
|
||||
JsonObject top = root.createNestedObject("exampleUsermod");
|
||||
top["great"] = userVar0; //save these vars persistently whenever settings are saved
|
||||
top["testBool"] = testBool;
|
||||
top["testInt"] = testInt;
|
||||
top["testLong"] = testLong;
|
||||
top["testULong"] = testULong;
|
||||
top["testFloat"] = testFloat;
|
||||
top["testString"] = testString;
|
||||
JsonArray pinArray = top.createNestedArray("pin");
|
||||
pinArray.add(testPins[0]);
|
||||
pinArray.add(testPins[1]);
|
||||
}
|
||||
// /*
|
||||
// * addToConfig() can be used to add custom persistent settings to the cfg.json file in the "um" (usermod) object.
|
||||
// * It will be called by WLED when settings are actually saved (for example, LED settings are saved)
|
||||
// * If you want to force saving the current state, use serializeConfig() in your loop().
|
||||
// *
|
||||
// * CAUTION: serializeConfig() will initiate a filesystem write operation.
|
||||
// * It might cause the LEDs to stutter and will cause flash wear if called too often.
|
||||
// * Use it sparingly and always in the loop, never in network callbacks!
|
||||
// *
|
||||
// * addToConfig() will make your settings editable through the Usermod Settings page automatically.
|
||||
// *
|
||||
// * Usermod Settings Overview:
|
||||
// * - Numeric values are treated as floats in the browser.
|
||||
// * - If the numeric value entered into the browser contains a decimal point, it will be parsed as a C float
|
||||
// * before being returned to the Usermod. The float data type has only 6-7 decimal digits of precision, and
|
||||
// * doubles are not supported, numbers will be rounded to the nearest float value when being parsed.
|
||||
// * The range accepted by the input field is +/- 1.175494351e-38 to +/- 3.402823466e+38.
|
||||
// * - If the numeric value entered into the browser doesn't contain a decimal point, it will be parsed as a
|
||||
// * C int32_t (range: -2147483648 to 2147483647) before being returned to the usermod.
|
||||
// * Overflows or underflows are truncated to the max/min value for an int32_t, and again truncated to the type
|
||||
// * used in the Usermod when reading the value from ArduinoJson.
|
||||
// * - Pin values can be treated differently from an integer value by using the key name "pin"
|
||||
// * - "pin" can contain a single or array of integer values
|
||||
// * - On the Usermod Settings page there is simple checking for pin conflicts and warnings for special pins
|
||||
// * - Red color indicates a conflict. Yellow color indicates a pin with a warning (e.g. an input-only pin)
|
||||
// * - Tip: use int8_t to store the pin value in the Usermod, so a -1 value (pin not set) can be used
|
||||
// *
|
||||
// * See usermod_v2_auto_save.h for an example that saves Flash space by reusing ArduinoJson key name strings
|
||||
// *
|
||||
// * If you need a dedicated settings page with custom layout for your Usermod, that takes a lot more work.
|
||||
// * You will have to add the setting to the HTML, xml.cpp and set.cpp manually.
|
||||
// * See the WLED Soundreactive fork (code and wiki) for reference. https://github.com/atuline/WLED
|
||||
// *
|
||||
// * I highly recommend checking out the basics of ArduinoJson serialization and deserialization in order to use custom settings!
|
||||
// */
|
||||
// void addToConfig(JsonObject& root)
|
||||
// {
|
||||
// JsonObject top = root.createNestedObject("exampleUsermod");
|
||||
// top["great"] = userVar0; //save these vars persistently whenever settings are saved
|
||||
// top["testBool"] = testBool;
|
||||
// top["testInt"] = testInt;
|
||||
// top["testLong"] = testLong;
|
||||
// top["testULong"] = testULong;
|
||||
// top["testFloat"] = testFloat;
|
||||
// top["testString"] = testString;
|
||||
// JsonArray pinArray = top.createNestedArray("pin");
|
||||
// pinArray.add(testPins[0]);
|
||||
// pinArray.add(testPins[1]);
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
* readFromConfig() can be used to read back the custom settings you added with addToConfig().
|
||||
* This is called by WLED when settings are loaded (currently this only happens immediately after boot, or after saving on the Usermod Settings page)
|
||||
*
|
||||
* readFromConfig() is called BEFORE setup(). This means you can use your persistent values in setup() (e.g. pin assignments, buffer sizes),
|
||||
* but also that if you want to write persistent values to a dynamic buffer, you'd need to allocate it here instead of in setup.
|
||||
* If you don't know what that is, don't fret. It most likely doesn't affect your use case :)
|
||||
*
|
||||
* Return true in case the config values returned from Usermod Settings were complete, or false if you'd like WLED to save your defaults to disk (so any missing values are editable in Usermod Settings)
|
||||
*
|
||||
* getJsonValue() returns false if the value is missing, or copies the value into the variable provided and returns true if the value is present
|
||||
* The configComplete variable is true only if the "exampleUsermod" object and all values are present. If any values are missing, WLED will know to call addToConfig() to save them
|
||||
*
|
||||
* This function is guaranteed to be called on boot, but could also be called every time settings are updated
|
||||
*/
|
||||
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)
|
||||
// /*
|
||||
// * readFromConfig() can be used to read back the custom settings you added with addToConfig().
|
||||
// * This is called by WLED when settings are loaded (currently this only happens immediately after boot, or after saving on the Usermod Settings page)
|
||||
// *
|
||||
// * readFromConfig() is called BEFORE setup(). This means you can use your persistent values in setup() (e.g. pin assignments, buffer sizes),
|
||||
// * but also that if you want to write persistent values to a dynamic buffer, you'd need to allocate it here instead of in setup.
|
||||
// * If you don't know what that is, don't fret. It most likely doesn't affect your use case :)
|
||||
// *
|
||||
// * Return true in case the config values returned from Usermod Settings were complete, or false if you'd like WLED to save your defaults to disk (so any missing values are editable in Usermod Settings)
|
||||
// *
|
||||
// * getJsonValue() returns false if the value is missing, or copies the value into the variable provided and returns true if the value is present
|
||||
// * The configComplete variable is true only if the "exampleUsermod" object and all values are present. If any values are missing, WLED will know to call addToConfig() to save them
|
||||
// *
|
||||
// * This function is guaranteed to be called on boot, but could also be called every time settings are updated
|
||||
// */
|
||||
// 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["exampleUsermod"];
|
||||
// JsonObject top = root["exampleUsermod"];
|
||||
|
||||
bool configComplete = !top.isNull();
|
||||
// bool configComplete = !top.isNull();
|
||||
|
||||
configComplete &= getJsonValue(top["great"], userVar0);
|
||||
configComplete &= getJsonValue(top["testBool"], testBool);
|
||||
configComplete &= getJsonValue(top["testULong"], testULong);
|
||||
configComplete &= getJsonValue(top["testFloat"], testFloat);
|
||||
configComplete &= getJsonValue(top["testString"], testString);
|
||||
// configComplete &= getJsonValue(top["great"], userVar0);
|
||||
// configComplete &= getJsonValue(top["testBool"], testBool);
|
||||
// configComplete &= getJsonValue(top["testULong"], testULong);
|
||||
// configComplete &= getJsonValue(top["testFloat"], testFloat);
|
||||
// configComplete &= getJsonValue(top["testString"], testString);
|
||||
|
||||
// A 3-argument getJsonValue() assigns the 3rd argument as a default value if the Json value is missing
|
||||
configComplete &= getJsonValue(top["testInt"], testInt, 42);
|
||||
configComplete &= getJsonValue(top["testLong"], testLong, -42424242);
|
||||
configComplete &= getJsonValue(top["pin"][0], testPins[0], -1);
|
||||
configComplete &= getJsonValue(top["pin"][1], testPins[1], -1);
|
||||
// // A 3-argument getJsonValue() assigns the 3rd argument as a default value if the Json value is missing
|
||||
// configComplete &= getJsonValue(top["testInt"], testInt, 42);
|
||||
// configComplete &= getJsonValue(top["testLong"], testLong, -42424242);
|
||||
// configComplete &= getJsonValue(top["pin"][0], testPins[0], -1);
|
||||
// configComplete &= getJsonValue(top["pin"][1], testPins[1], -1);
|
||||
|
||||
return configComplete;
|
||||
}
|
||||
// return configComplete;
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
* 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_SEVEN_SEGMENT_DISPLAY;
|
||||
}
|
||||
// /*
|
||||
// * 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_SEVEN_SEGMENT_DISPLAY;
|
||||
// }
|
||||
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user