Changed version to 0.12.2-bl1

Optimised strings in Animated Staircase usermod.
Minor typos.
pull/2737/head
Blaž Kristan 2021-04-23 14:32:18 +02:00
rodzic 1be8e7e216
commit f96a5ec774
4 zmienionych plików z 86 dodań i 50 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
{ {
"name": "wled", "name": "wled",
"version": "0.12.1-a1", "version": "0.12.2-bl1",
"description": "Tools for WLED project", "description": "Tools for WLED project",
"main": "tools/cdata.js", "main": "tools/cdata.js",
"directories": { "directories": {

Wyświetl plik

@ -77,6 +77,21 @@ class Animated_Staircase : public Usermod {
bool bottomSensorRead = false; bool bottomSensorRead = false;
bool bottomSensorWrite = false; bool bottomSensorWrite = false;
// strings to reduce flash memory usage (used more than twice)
static const char _name[];
static const char _enabled[];
static const char _segmentDelay[];
static const char _onTime[];
static const char _useTopUltrasoundSensor[];
static const char _topPIRorTrigger_pin[];
static const char _topEcho_pin[];
static const char _useBottomUltrasoundSensor[];
static const char _bottomPIRorTrigger_pin[];
static const char _bottomEcho_pin[];
static const char _topEchoTime[];
static const char _bottomEchoTime[];
static const char _[];
void updateSegments() { void updateSegments() {
// mainSegmentId = strip.getMainSegmentId(); // mainSegmentId = strip.getMainSegmentId();
// WS2812FX::Segment mainsegment = strip.getSegment(mainSegmentId); // WS2812FX::Segment mainsegment = strip.getSegment(mainSegmentId);
@ -183,6 +198,7 @@ class Animated_Staircase : public Usermod {
} }
void autoPowerOff() { void autoPowerOff() {
// TODO: add logic to wait until PIR sensor deactivates
if (on && ((millis() - lastSwitchTime) > on_time_ms)) { if (on && ((millis() - lastSwitchTime) > on_time_ms)) {
// Swipe OFF in the direction of the last sensor detection // Swipe OFF in the direction of the last sensor detection
swipe = lastSensor; swipe = lastSensor;
@ -219,17 +235,14 @@ class Animated_Staircase : public Usermod {
} }
} }
void writeSensorsToJson(JsonObject& root) { // send sesnor values to JSON API
JsonObject staircase = root[F("staircase")]; void writeSensorsToJson(JsonObject& staircase) {
if (staircase.isNull()) {
staircase = root.createNestedObject(F("staircase"));
}
staircase[F("top-sensor")] = topSensorRead; staircase[F("top-sensor")] = topSensorRead;
staircase[F("bottom-sensor")] = bottomSensorRead; staircase[F("bottom-sensor")] = bottomSensorRead;
} }
void readSensorsFromJson(JsonObject& root) { // allow overrides from JSON API
JsonObject staircase = root[F("staircase")]; void readSensorsFromJson(JsonObject& staircase) {
bottomSensorWrite = bottomSensorRead || (staircase[F("bottom-sensor")].as<bool>()); bottomSensorWrite = bottomSensorRead || (staircase[F("bottom-sensor")].as<bool>());
topSensorWrite = topSensorRead || (staircase[F("top-sensor")].as<bool>()); topSensorWrite = topSensorRead || (staircase[F("top-sensor")].as<bool>());
} }
@ -243,6 +256,7 @@ class Animated_Staircase : public Usermod {
DEBUG_PRINT(on_time_ms / 1000); DEBUG_PRINT(on_time_ms / 1000);
DEBUG_PRINTLN(F(" seconds.")); DEBUG_PRINTLN(F(" seconds."));
// TODO: attach interrupts
if (!useUSSensorBottom) if (!useUSSensorBottom)
pinMode(bottomPIRorTriggerPin, INPUT); pinMode(bottomPIRorTriggerPin, INPUT);
else { else {
@ -292,6 +306,7 @@ class Animated_Staircase : public Usermod {
if (!pinManager.allocatePin(bottomPIRorTriggerPin,false)) if (!pinManager.allocatePin(bottomPIRorTriggerPin,false))
bottomEchoPin = -1; bottomEchoPin = -1;
} }
// TODO: attach interrupts in enable()
// validate pins // validate pins
if ( topPIRorTriggerPin < 0 || bottomPIRorTriggerPin < 0 || if ( topPIRorTriggerPin < 0 || bottomPIRorTriggerPin < 0 ||
@ -312,9 +327,12 @@ class Animated_Staircase : public Usermod {
uint16_t getId() { return USERMOD_ID_ANIMATED_STAIRCASE; } uint16_t getId() { return USERMOD_ID_ANIMATED_STAIRCASE; }
void addToJsonState(JsonObject& root) { void addToJsonState(JsonObject& root) {
// writeSettingsToJson(root); JsonObject staircase = root[FPSTR(_name)];
// writeSensorsToJson(root); if (staircase.isNull()) {
// DEBUG_PRINTLN(F("Staircase config exposed in API.")); staircase = root.createNestedObject(FPSTR(_name));
}
writeSensorsToJson(staircase);
DEBUG_PRINTLN(F("Staircase sensor state exposed in API."));
} }
/* /*
@ -323,14 +341,16 @@ class Animated_Staircase : public Usermod {
*/ */
void readFromJsonState(JsonObject& root) { void readFromJsonState(JsonObject& root) {
if (!initDone) return; // prevent crash on boot applyPreset() if (!initDone) return; // prevent crash on boot applyPreset()
JsonObject staircase = root[F("staircase")]; JsonObject staircase = root[FPSTR(_name)];
if (!staircase.isNull()) { if (!staircase.isNull()) {
if (staircase[F("enabled")].is<bool>()) { if (staircase[FPSTR(_enabled)].is<bool>()) {
enabled = staircase[F("enabled")].as<bool>(); enabled = staircase[FPSTR(_enabled)].as<bool>();
} else { } else {
String str = staircase[F("enabled")]; // checkbox -> off or on String str = staircase[FPSTR(_enabled)]; // checkbox -> off or on
enabled = (bool)(str!="off"); // off is guaranteed to be present enabled = (bool)(str!="off"); // off is guaranteed to be present
} }
readSensorsFromJson(root);
DEBUG_PRINTLN(F("Staircase sensor state read from API."));
} }
} }
@ -338,21 +358,21 @@ class Animated_Staircase : public Usermod {
* Writes the configuration to internal flash memory. * Writes the configuration to internal flash memory.
*/ */
void addToConfig(JsonObject& root) { void addToConfig(JsonObject& root) {
JsonObject staircase = root[F("staircase")]; JsonObject staircase = root[FPSTR(_name)];
if (staircase.isNull()) { if (staircase.isNull()) {
staircase = root.createNestedObject(F("staircase")); staircase = root.createNestedObject(FPSTR(_name));
} }
staircase[F("enabled")] = enabled; staircase[FPSTR(_enabled)] = enabled;
staircase[F("segment-delay-ms")] = segment_delay_ms; staircase[FPSTR(_segmentDelay)] = segment_delay_ms;
staircase[F("on-time-s")] = on_time_ms / 1000; staircase[FPSTR(_onTime)] = on_time_ms / 1000;
staircase[F("useTopUltrasoundSensor")] = useUSSensorTop; staircase[FPSTR(_useTopUltrasoundSensor)] = useUSSensorTop;
staircase[F("topPIRorTrigger_pin")] = topPIRorTriggerPin; staircase[FPSTR(_topPIRorTrigger_pin)] = topPIRorTriggerPin;
staircase[F("topEcho_pin")] = topEchoPin; staircase[FPSTR(_topEcho_pin)] = useUSSensorTop ? topEchoPin : -1;
staircase[F("useBottomUltrasoundSensor")] = useUSSensorBottom; staircase[FPSTR(_useBottomUltrasoundSensor)] = useUSSensorBottom;
staircase[F("bottomPIRorTrigger_pin")] = bottomPIRorTriggerPin; staircase[FPSTR(_bottomPIRorTrigger_pin)] = bottomPIRorTriggerPin;
staircase[F("bottomEcho_pin")] = bottomEchoPin; staircase[FPSTR(_bottomEcho_pin)] = useUSSensorBottom ? bottomEchoPin : -1;
staircase[F("top-echo-us")] = topMaxTimeUs; staircase[FPSTR(_topEchoTime)] = topMaxTimeUs;
staircase[F("bottom-echo-us")] = bottomMaxTimeUs; staircase[FPSTR(_bottomEchoTime)] = bottomMaxTimeUs;
DEBUG_PRINTLN(F("Staircase config saved.")); DEBUG_PRINTLN(F("Staircase config saved."));
} }
@ -367,35 +387,37 @@ class Animated_Staircase : public Usermod {
int8_t oldBottomAPin = bottomPIRorTriggerPin; int8_t oldBottomAPin = bottomPIRorTriggerPin;
int8_t oldBottomBPin = bottomEchoPin; int8_t oldBottomBPin = bottomEchoPin;
JsonObject staircase = root[F("staircase")]; JsonObject staircase = root[FPSTR(_name)];
if (!staircase.isNull()) { if (!staircase.isNull()) {
if (staircase[F("enabled")].is<bool>()) { if (staircase[FPSTR(_enabled)].is<bool>()) {
enabled = staircase[F("enabled")].as<bool>(); enabled = staircase[FPSTR(_enabled)].as<bool>();
} else { } else {
String str = staircase[F("enabled")]; // checkbox -> off or on String str = staircase[FPSTR(_enabled)]; // checkbox -> off or on
enabled = (bool)(str!="off"); // off is guaranteed to be present enabled = (bool)(str!="off"); // off is guaranteed to be present
} }
segment_delay_ms = staircase[F("segment-delay-ms")]; segment_delay_ms = min(10000,max(10,staircase[FPSTR(_segmentDelay)].as<int>())); // max delay 10s
on_time_ms = (int)staircase[F("on-time-s")] * 1000; on_time_ms = min(900,max(10,staircase[FPSTR(_onTime)].as<int>())) * 1000; // min 10s, max 15min
if (staircase[F("useTopUltrasoundSensor")].is<bool>()) {
useUSSensorTop = staircase[F("useTopUltrasoundSensor")].as<bool>(); if (staircase[FPSTR(_useTopUltrasoundSensor)].is<bool>()) {
useUSSensorTop = staircase[FPSTR(_useTopUltrasoundSensor)].as<bool>();
} else { } else {
String str = staircase[F("useTopUltrasoundSensor")]; // checkbox -> off or on String str = staircase[FPSTR(_useTopUltrasoundSensor)]; // checkbox -> off or on
useUSSensorTop = (bool)(str!="off"); // off is guaranteed to be present useUSSensorTop = (bool)(str!="off"); // off is guaranteed to be present
} }
topPIRorTriggerPin = staircase[F("topPIRorTrigger_pin")];
topEchoPin = staircase[F("topEcho_pin")]; topPIRorTriggerPin = min(39,max(-1,staircase[FPSTR(_topPIRorTrigger_pin)].as<int>()));
useUSSensorBottom = staircase[F("useBottomUltrasoundSensor")].as<bool>(); topEchoPin = min(39,max(-1,staircase[FPSTR(_topEcho_pin)].as<int>()));
if (staircase[F("useBottomUltrasoundSensor")].is<bool>()) {
useUSSensorBottom = staircase[F("useBottomUltrasoundSensor")].as<bool>(); if (staircase[FPSTR(_useBottomUltrasoundSensor)].is<bool>()) {
useUSSensorBottom = staircase[FPSTR(_useBottomUltrasoundSensor)].as<bool>();
} else { } else {
String str = staircase[F("useBottomUltrasoundSensor")]; // checkbox -> off or on String str = staircase[FPSTR(_useBottomUltrasoundSensor)]; // checkbox -> off or on
useUSSensorBottom = (bool)(str!="off"); // off is guaranteed to be present useUSSensorBottom = (bool)(str!="off"); // off is guaranteed to be present
} }
bottomPIRorTriggerPin = staircase[F("bottomPIRorTrigger_pin")]; bottomPIRorTriggerPin = min(39,max(-1,staircase[FPSTR(_bottomPIRorTrigger_pin)].as<int>()));
bottomEchoPin = staircase[F("bottomEcho_pin")]; bottomEchoPin = min(39,max(-1,staircase[FPSTR(_bottomEcho_pin)].as<int>()));
topMaxTimeUs = staircase[F("top-echo-us")]; topMaxTimeUs = min(18000,max(300,staircase[FPSTR(_topEchoTime)].as<int>())); // max distnace ~3m (a noticable lag of 18ms may be expected)
bottomMaxTimeUs = staircase[F("bottom-echo-us")]; bottomMaxTimeUs = min(18000,max(300,staircase[FPSTR(_bottomEchoTime)].as<int>())); // max distance ~3m (a noticable lag of 18ms may be expected)
DEBUG_PRINTLN(F("Staircase config (re)loaded.")); DEBUG_PRINTLN(F("Staircase config (re)loaded."));
} else { } else {
DEBUG_PRINTLN(F("No config found. (Using defaults.)")); DEBUG_PRINTLN(F("No config found. (Using defaults.)"));
@ -448,3 +470,17 @@ class Animated_Staircase : public Usermod {
} }
} }
}; };
// strings to reduce flash memory usage (used more than twice)
const char Animated_Staircase::_name[] PROGMEM = "staircase";
const char Animated_Staircase::_enabled[] PROGMEM = "enabled";
const char Animated_Staircase::_segmentDelay[] PROGMEM = "segment-delay-ms";
const char Animated_Staircase::_onTime[] PROGMEM = "on-time-s";
const char Animated_Staircase::_useTopUltrasoundSensor[] PROGMEM = "useTopUltrasoundSensor";
const char Animated_Staircase::_topPIRorTrigger_pin[] PROGMEM = "topPIRorTrigger_pin";
const char Animated_Staircase::_topEcho_pin[] PROGMEM = "topEcho_pin";
const char Animated_Staircase::_useBottomUltrasoundSensor[] PROGMEM = "useBottomUltrasoundSensor";
const char Animated_Staircase::_bottomPIRorTrigger_pin[] PROGMEM = "bottomPIRorTrigger_pin";
const char Animated_Staircase::_bottomEcho_pin[] PROGMEM = "bottomEcho_pin";
const char Animated_Staircase::_topEchoTime[] PROGMEM = "top-echo-us";
const char Animated_Staircase::_bottomEchoTime[] PROGMEM = "bottom-echo-us";

Wyświetl plik

@ -65,7 +65,7 @@ typedef enum {
NONE = 0, NONE = 0,
SSD1306, // U8X8_SSD1306_128X32_UNIVISION_HW_I2C SSD1306, // U8X8_SSD1306_128X32_UNIVISION_HW_I2C
SH1106, // U8X8_SH1106_128X64_WINSTAR_HW_I2C SH1106, // U8X8_SH1106_128X64_WINSTAR_HW_I2C
SSD1306_64 // U8X8_SSD1306_128X64_UNIVISION_HW_I2C SSD1306_64 // U8X8_SSD1306_128X64_NONAME_HW_I2C
} DisplayType; } DisplayType;
class FourLineDisplayUsermod : public Usermod { class FourLineDisplayUsermod : public Usermod {

Wyświetl plik

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2104231 #define VERSION 2104241
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG