Public Access
Random refresh effect: choose which effects it picks from
The list is a new setting (hardware settings, also used by pages set to Random); an empty list is refused. The ESP32 picks an effect per frame and sends that, so the Nano needs no change. The power-on time after a frame now follows the slowest effect on the list. The settings record goes to version 8. Version 7 is a prefix of it, so it is still read, and becomes version 8 with the next save. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8fcb17c395
commit
48e29096c0
12 files changed
+140
-21
No files matched your search
@@ -160,6 +160,9 @@ See README.md for the overview.
|
|||||||
`web/web_ui.cpp` is the JSON API (endpoints listed in `web_ui.h`), `web/web_page.h` the
|
`web/web_ui.cpp` is the JSON API (endpoints listed in `web_ui.h`), `web/web_page.h` the
|
||||||
single HTML/JS page (raw string literal in PROGMEM). Keep image work in the browser; the
|
single HTML/JS page (raw string literal in PROGMEM). Keep image work in the browser; the
|
||||||
ESP32 only handles 418-character hex bitmaps (`logic/bitmap_format.h`, MSB = left dot).
|
ESP32 only handles 418-character hex bitmaps (`logic/bitmap_format.h`, MSB = left dot).
|
||||||
|
- The Random effect's list (`Settings::random_effects`) is only known to the ESP32:
|
||||||
|
`FlipdotFrames::_useEffect()` picks an effect per frame and sends that, so the Nano doesn't
|
||||||
|
run its own `EFFECT_RANDOM` (which picks from all effects).
|
||||||
- Settings: `logic/settings.h` struct with defaults = original behaviour, stored as an NVS
|
- Settings: `logic/settings.h` struct with defaults = original behaviour, stored as an NVS
|
||||||
blob with a version (`system/settings_store.cpp`). When the struct changes, bump
|
blob with a version (`system/settings_store.cpp`). When the struct changes, bump
|
||||||
`VERSION` there (old records then fall back to defaults). Only the current version is
|
`VERSION` there (old records then fall back to defaults). Only the current version is
|
||||||
|
|||||||
+2
-1
@@ -141,7 +141,8 @@ The display schedule (on/off, when the display is on, when it switches off); slo
|
|||||||
and is switched off in between, for less noise); the "No WiFi" screen; the flip time, the pause after each pulse,
|
and is switched off in between, for less noise); the "No WiFi" screen; the flip time, the pause after each pulse,
|
||||||
pulses per dot and the refresh effect (instant, sparkle, wipe, rain, from the middle out,
|
pulses per dot and the refresh effect (instant, sparkle, wipe, rain, from the middle out,
|
||||||
diagonal, spiral, flip all then reveal, push, Matrix (yellow streaks fall down the columns
|
diagonal, spiral, flip all then reveal, push, Matrix (yellow streaks fall down the columns
|
||||||
that change and leave the new image behind them), random; optionally only for small changes
|
that change and leave the new image behind them), random (with a list of the effects it can
|
||||||
|
pick from, also for pages set to random); optionally only for small changes
|
||||||
like the clock's minutes; pages can choose their own effect); how often every dot is flipped again ("Dot refresh", default
|
like the clock's minutes; pages can choose their own effect); how often every dot is flipped again ("Dot refresh", default
|
||||||
2 min) and how often the whole image is sent again ("Image resync", default 10 min; 0
|
2 min) and how often the whole image is sent again ("Image resync", default 10 min; 0
|
||||||
switches either off); test patterns; the status LED.
|
switches either off); test patterns; the status LED.
|
||||||
|
|||||||
+9
-3
@@ -93,9 +93,14 @@ static void applyOffPage()
|
|||||||
static void apply()
|
static void apply()
|
||||||
{
|
{
|
||||||
controller.setSettings(settings.schedule, settings.clock, settings.slow_mode);
|
controller.setSettings(settings.schedule, settings.clock, settings.slow_mode);
|
||||||
controller.setEffectTime(effectTime(settings.drive));
|
controller.setEffectTime(effectTime(settings.drive, settings.random_effects));
|
||||||
status.setDrive(settings.flip_time, settings.drive, settings.refresh.dots);
|
// What the Nano stores and uses until the first frame. Its own Random doesn't know the
|
||||||
frames.setDrive(settings.flip_time, settings.drive);
|
// list, so it never gets that: the first effect on the list instead.
|
||||||
|
DriveSettings stored_drive = settings.drive;
|
||||||
|
if (stored_drive.effect == DRIVE_EFFECT_RANDOM)
|
||||||
|
stored_drive.effect = pickRandomEffect(settings.random_effects, 0);
|
||||||
|
status.setDrive(settings.flip_time, stored_drive, settings.refresh.dots);
|
||||||
|
frames.setDrive(settings.flip_time, settings.drive, settings.random_effects);
|
||||||
char user[PLEX_USER_SIZE];
|
char user[PLEX_USER_SIZE];
|
||||||
plexUserSlug(settings.plex_user, user, sizeof(user));
|
plexUserSlug(settings.plex_user, user, sizeof(user));
|
||||||
haApiSetSettings(settings.home_assistant, user);
|
haApiSetSettings(settings.home_assistant, user);
|
||||||
@@ -149,6 +154,7 @@ const char *appSaveSettings(const Settings &new_settings, bool &restart_needed)
|
|||||||
bool drive_changed = settings.flip_time != new_settings.flip_time || a.flip_gap != b.flip_gap ||
|
bool drive_changed = settings.flip_time != new_settings.flip_time || a.flip_gap != b.flip_gap ||
|
||||||
a.pulses != b.pulses || a.effect != b.effect || a.effect_time != b.effect_time ||
|
a.pulses != b.pulses || a.effect != b.effect || a.effect_time != b.effect_time ||
|
||||||
a.effect_small_only != b.effect_small_only ||
|
a.effect_small_only != b.effect_small_only ||
|
||||||
|
settings.random_effects != new_settings.random_effects ||
|
||||||
settings.refresh.dots != new_settings.refresh.dots;
|
settings.refresh.dots != new_settings.refresh.dots;
|
||||||
settings = new_settings;
|
settings = new_settings;
|
||||||
saveSettings(settings);
|
saveSettings(settings);
|
||||||
|
|||||||
+1
-1
@@ -118,7 +118,7 @@ const uint32_t SETUP_AP_DELAY = 20000; // open the AP when WiFi fails thi
|
|||||||
const uint32_t WIFI_CONNECT_TIMEOUT = 30000;
|
const uint32_t WIFI_CONNECT_TIMEOUT = 30000;
|
||||||
const uint32_t WIFI_RESTART_TIME = 10UL * 60 * 1000;
|
const uint32_t WIFI_RESTART_TIME = 10UL * 60 * 1000;
|
||||||
|
|
||||||
#define FIRMWARE_VERSION "2.21.0"
|
#define FIRMWARE_VERSION "2.22.0"
|
||||||
|
|
||||||
// Home Assistant device id (do not change: Home Assistant's entities are linked to it)
|
// Home Assistant device id (do not change: Home Assistant's entities are linked to it)
|
||||||
const uint8_t HA_DEVICE_ID[] = {0x34, 0x86, 0x5d, 0x3a, 0x08, 0x28};
|
const uint8_t HA_DEVICE_ID[] = {0x34, 0x86, 0x5d, 0x3a, 0x08, 0x28};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "display/frames.h"
|
#include "display/frames.h"
|
||||||
|
|
||||||
|
#include <esp_random.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -20,16 +21,19 @@ uint32_t FlipdotFrames::dynamicPage(const LocalTime &time, uint32_t now, bool re
|
|||||||
bool moving = wait != 0;
|
bool moving = wait != 0;
|
||||||
// The Nano has no acknowledgement: the next frame waits until it has received this one
|
// The Nano has no acknowledgement: the next frame waits until it has received this one
|
||||||
// and flipped its dots, or the next frame overflows its serial buffer
|
// and flipped its dots, or the next frame overflows its serial buffer
|
||||||
_useEffect(_page_effect, redraw);
|
// Instant frames don't use the effect (moving ones come fast: no E command for each)
|
||||||
|
if (redraw || !(moving || _instant_next))
|
||||||
|
_useEffect(_page_effect, redraw);
|
||||||
uint32_t busy = _show(bitmap, !redraw, moving || _instant_next);
|
uint32_t busy = _show(bitmap, !redraw, moving || _instant_next);
|
||||||
_instant_next = false;
|
_instant_next = false;
|
||||||
return moving && wait < busy ? busy : wait;
|
return moving && wait < busy ? busy : wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlipdotFrames::setDrive(uint16_t flip_time, const DriveSettings &drive)
|
void FlipdotFrames::setDrive(uint16_t flip_time, const DriveSettings &drive, uint16_t random_effects)
|
||||||
{
|
{
|
||||||
_dot_us = (uint32_t)drive.pulses * (flip_time + drive.flip_gap);
|
_dot_us = (uint32_t)drive.pulses * (flip_time + drive.flip_gap);
|
||||||
_drive = drive;
|
_drive = drive;
|
||||||
|
_random_effects = random_effects;
|
||||||
_nano_effect = EFFECT_UNKNOWN;
|
_nano_effect = EFFECT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,6 +41,8 @@ void FlipdotFrames::_useEffect(uint8_t effect, bool full)
|
|||||||
{
|
{
|
||||||
if (effect == PAGE_EFFECT_DEFAULT || effect >= DRIVE_EFFECT_COUNT)
|
if (effect == PAGE_EFFECT_DEFAULT || effect >= DRIVE_EFFECT_COUNT)
|
||||||
effect = _drive.effect;
|
effect = _drive.effect;
|
||||||
|
if (effect == DRIVE_EFFECT_RANDOM)
|
||||||
|
effect = pickRandomEffect(_random_effects, esp_random());
|
||||||
if (effect == _nano_effect && !full)
|
if (effect == _nano_effect && !full)
|
||||||
return;
|
return;
|
||||||
uint8_t flags = EFFECT_FLAG_NO_SAVE | (_drive.effect_small_only ? EFFECT_FLAG_SMALL_ONLY : 0);
|
uint8_t flags = EFFECT_FLAG_NO_SAVE | (_drive.effect_small_only ? EFFECT_FLAG_SMALL_ONLY : 0);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public:
|
|||||||
// block that switches instantly)
|
// block that switches instantly)
|
||||||
void showNextInstant() { _instant_next = true; }
|
void showNextInstant() { _instant_next = true; }
|
||||||
// How the Nano flips the dots: for the time a frame takes, and the refresh effect
|
// How the Nano flips the dots: for the time a frame takes, and the refresh effect
|
||||||
void setDrive(uint16_t flip_time, const DriveSettings &drive);
|
void setDrive(uint16_t flip_time, const DriveSettings &drive, uint16_t random_effects);
|
||||||
// The refresh effect of the shown page (PAGE_EFFECT_DEFAULT: the one of the drive
|
// The refresh effect of the shown page (PAGE_EFFECT_DEFAULT: the one of the drive
|
||||||
// settings). Sent to the Nano before page frames, without storing it in its EEPROM;
|
// settings). Sent to the Nano before page frames, without storing it in its EEPROM;
|
||||||
// the other screens (off, live, No WiFi) use the drive settings' effect.
|
// the other screens (off, live, No WiFi) use the drive settings' effect.
|
||||||
@@ -52,6 +52,7 @@ private:
|
|||||||
DynamicPage _dynamic;
|
DynamicPage _dynamic;
|
||||||
static const uint8_t EFFECT_UNKNOWN = 254;
|
static const uint8_t EFFECT_UNKNOWN = 254;
|
||||||
DriveSettings _drive;
|
DriveSettings _drive;
|
||||||
|
uint16_t _random_effects = RANDOM_EFFECTS_ALL;
|
||||||
uint8_t _page_effect = PAGE_EFFECT_DEFAULT;
|
uint8_t _page_effect = PAGE_EFFECT_DEFAULT;
|
||||||
uint8_t _nano_effect = EFFECT_UNKNOWN; // the effect last sent by _useEffect()
|
uint8_t _nano_effect = EFFECT_UNKNOWN; // the effect last sent by _useEffect()
|
||||||
uint32_t _dot_us = 1000;
|
uint32_t _dot_us = 1000;
|
||||||
@@ -63,6 +64,7 @@ private:
|
|||||||
void _drawFullScreen(const uint8_t *bitmap);
|
void _drawFullScreen(const uint8_t *bitmap);
|
||||||
// Makes the Nano use this effect (PAGE_EFFECT_DEFAULT: the drive settings' one). Sent
|
// Makes the Nano use this effect (PAGE_EFFECT_DEFAULT: the drive settings' one). Sent
|
||||||
// when it changed, and always with full frames: a restarted Nano has the stored one.
|
// when it changed, and always with full frames: a restarted Nano has the stored one.
|
||||||
|
// Random is decided here, for each frame, as only the ESP32 knows the list.
|
||||||
void _useEffect(uint8_t effect, bool full);
|
void _useEffect(uint8_t effect, bool full);
|
||||||
uint32_t _show(const uint8_t *bitmap, bool changes_only, bool instant);
|
uint32_t _show(const uint8_t *bitmap, bool changes_only, bool instant);
|
||||||
};
|
};
|
||||||
@@ -39,6 +39,8 @@ const char *validateSettings(const Settings &s)
|
|||||||
return "Unknown refresh effect";
|
return "Unknown refresh effect";
|
||||||
if (d.effect_time < 100 || d.effect_time > 10000)
|
if (d.effect_time < 100 || d.effect_time > 10000)
|
||||||
return "The effect time must be between 100 and 10000 ms";
|
return "The effect time must be between 100 and 10000 ms";
|
||||||
|
if (s.random_effects == 0 || (s.random_effects & ~RANDOM_EFFECTS_ALL))
|
||||||
|
return "Random needs at least one effect to pick from";
|
||||||
if (s.refresh.dots > REFRESH_MINUTES_MAX || s.refresh.image > REFRESH_MINUTES_MAX)
|
if (s.refresh.dots > REFRESH_MINUTES_MAX || s.refresh.image > REFRESH_MINUTES_MAX)
|
||||||
return "Refresh intervals must be between 0 and 1440 minutes";
|
return "Refresh intervals must be between 0 and 1440 minutes";
|
||||||
|
|
||||||
@@ -63,17 +65,33 @@ bool validSlowModeMinutes(int minutes)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t effectTime(const DriveSettings &drive)
|
uint32_t effectTime(const DriveSettings &drive, uint16_t random_effects)
|
||||||
{
|
{
|
||||||
if (drive.effect == DRIVE_EFFECT_INSTANT)
|
if (drive.effect == DRIVE_EFFECT_INSTANT)
|
||||||
return 0;
|
return 0;
|
||||||
if (drive.effect == DRIVE_EFFECT_PUSH || drive.effect == DRIVE_EFFECT_RANDOM)
|
// Random: the slowest effect it can pick
|
||||||
|
bool random = drive.effect == DRIVE_EFFECT_RANDOM;
|
||||||
|
if (drive.effect == DRIVE_EFFECT_PUSH || (random && (random_effects & (1 << DRIVE_EFFECT_PUSH))))
|
||||||
return drive.effect_time + DRIVE_PUSH_EXTRA_TIME;
|
return drive.effect_time + DRIVE_PUSH_EXTRA_TIME;
|
||||||
if (drive.effect == DRIVE_EFFECT_MATRIX)
|
if (drive.effect == DRIVE_EFFECT_MATRIX || (random && (random_effects & (1 << DRIVE_EFFECT_MATRIX))))
|
||||||
return drive.effect_time + DRIVE_MATRIX_EXTRA_TIME;
|
return drive.effect_time + DRIVE_MATRIX_EXTRA_TIME;
|
||||||
return drive.effect_time;
|
return drive.effect_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t pickRandomEffect(uint16_t random_effects, uint32_t random)
|
||||||
|
{
|
||||||
|
uint8_t count = 0;
|
||||||
|
for (uint8_t effect = 0; effect < DRIVE_EFFECT_COUNT; effect++)
|
||||||
|
count += (random_effects >> effect) & 1;
|
||||||
|
if (count == 0)
|
||||||
|
return DRIVE_EFFECT_INSTANT;
|
||||||
|
uint8_t skip = random % count;
|
||||||
|
for (uint8_t effect = 0; effect < DRIVE_EFFECT_COUNT; effect++)
|
||||||
|
if (((random_effects >> effect) & 1) && skip-- == 0)
|
||||||
|
return effect;
|
||||||
|
return DRIVE_EFFECT_INSTANT; // not reached
|
||||||
|
}
|
||||||
|
|
||||||
bool parseTime(const char *text, uint16_t &minutes)
|
bool parseTime(const char *text, uint16_t &minutes)
|
||||||
{
|
{
|
||||||
if (text == nullptr)
|
if (text == nullptr)
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ const uint8_t DRIVE_EFFECT_COUNT = 11;
|
|||||||
const uint32_t DRIVE_PUSH_EXTRA_TIME = 20000;
|
const uint32_t DRIVE_PUSH_EXTRA_TIME = 20000;
|
||||||
// The matrix streaks flip most dots of a changed column twice, also more than effect_time
|
// The matrix streaks flip most dots of a changed column twice, also more than effect_time
|
||||||
const uint32_t DRIVE_MATRIX_EXTRA_TIME = 5000;
|
const uint32_t DRIVE_MATRIX_EXTRA_TIME = 5000;
|
||||||
|
// What Random can pick from: bit n = effect n. All effects but Instant and Random itself.
|
||||||
|
const uint16_t RANDOM_EFFECTS_ALL = 0x05FE;
|
||||||
|
|
||||||
struct DriveSettings
|
struct DriveSettings
|
||||||
{
|
{
|
||||||
@@ -99,11 +101,15 @@ struct Settings
|
|||||||
// Plex user name for {plex_user} in entity ids (Tautulli's sensors of that user)
|
// Plex user name for {plex_user} in entity ids (Tautulli's sensors of that user)
|
||||||
char plex_user[PLEX_USER_SIZE] = "";
|
char plex_user[PLEX_USER_SIZE] = "";
|
||||||
SlowModeSettings slow_mode;
|
SlowModeSettings slow_mode;
|
||||||
|
// What the Random effect picks from (drive settings and pages), see RANDOM_EFFECTS_ALL
|
||||||
|
uint16_t random_effects = RANDOM_EFFECTS_ALL;
|
||||||
// New fields go here, at the end (see system/settings_store.cpp)
|
// New fields go here, at the end (see system/settings_store.cpp)
|
||||||
};
|
};
|
||||||
|
|
||||||
// How long a new frame can take to appear on the dots in ms (0 when instant)
|
// How long a new frame can take to appear on the dots in ms (0 when instant)
|
||||||
uint32_t effectTime(const DriveSettings &drive);
|
uint32_t effectTime(const DriveSettings &drive, uint16_t random_effects);
|
||||||
|
// One of the effects of a valid random_effects list. random: any random number.
|
||||||
|
uint8_t pickRandomEffect(uint16_t random_effects, uint32_t random);
|
||||||
|
|
||||||
const uint16_t MINUTES_PER_DAY = 24 * 60;
|
const uint16_t MINUTES_PER_DAY = 24 * 60;
|
||||||
const uint16_t SETTINGS_FLIP_TIME_MIN = 50;
|
const uint16_t SETTINGS_FLIP_TIME_MIN = 50;
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ static const char *KEY = "settings";
|
|||||||
// Increase when the Settings struct changes; records of other versions are ignored
|
// Increase when the Settings struct changes; records of other versions are ignored
|
||||||
// (defaults). 2.15.0 stored all older records again in version 7. To keep the settings over
|
// (defaults). 2.15.0 stored all older records again in version 7. To keep the settings over
|
||||||
// a change, add a frozen copy of the old layout and convert it (see git history).
|
// a change, add a frozen copy of the old layout and convert it (see git history).
|
||||||
static const uint16_t VERSION = 7;
|
static const uint16_t VERSION = 8;
|
||||||
|
// Version 7 is version 8 without random_effects at the end, so no frozen copy is needed. It
|
||||||
|
// becomes version 8 with the next save. Remove this once the device has saved.
|
||||||
|
static const uint16_t OLD_VERSION = 7;
|
||||||
|
static const size_t OLD_SIZE = offsetof(Settings, random_effects);
|
||||||
|
static_assert(alignof(Settings) == alignof(uint16_t), "no padding before random_effects");
|
||||||
|
|
||||||
struct StoredSettings
|
struct StoredSettings
|
||||||
{
|
{
|
||||||
@@ -28,6 +33,15 @@ void loadSettings(Settings &settings)
|
|||||||
size_t read = prefs.getBytes(KEY, &stored, sizeof(stored));
|
size_t read = prefs.getBytes(KEY, &stored, sizeof(stored));
|
||||||
prefs.end();
|
prefs.end();
|
||||||
|
|
||||||
|
if (read == offsetof(StoredSettings, settings) + OLD_SIZE && stored.version == OLD_VERSION &&
|
||||||
|
stored.size == OLD_SIZE)
|
||||||
|
{
|
||||||
|
stored.settings.random_effects = RANDOM_EFFECTS_ALL;
|
||||||
|
if (validateSettings(stored.settings) == nullptr)
|
||||||
|
settings = stored.settings;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (read == offsetof(StoredSettings, settings) + sizeof(Settings) && stored.version == VERSION &&
|
if (read == offsetof(StoredSettings, settings) + sizeof(Settings) && stored.version == VERSION &&
|
||||||
stored.size == sizeof(Settings) && validateSettings(stored.settings) == nullptr)
|
stored.size == sizeof(Settings) && validateSettings(stored.settings) == nullptr)
|
||||||
settings = stored.settings;
|
settings = stored.settings;
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ details{margin-top:10px}summary{cursor:pointer;color:var(--dim);font-size:13px;m
|
|||||||
<option value="2">Wipe (left to right)</option><option value="3">Rain (top to bottom)</option><option value="4">From the middle out</option>
|
<option value="2">Wipe (left to right)</option><option value="3">Rain (top to bottom)</option><option value="4">From the middle out</option>
|
||||||
<option value="5">Diagonal</option><option value="6">Spiral (outside in)</option><option value="7">Flip all, then reveal</option>
|
<option value="5">Diagonal</option><option value="6">Spiral (outside in)</option><option value="7">Flip all, then reveal</option>
|
||||||
<option value="8">Push (slides in from the right)</option><option value="10">Matrix (falling streaks)</option><option value="9">Random</option></select>
|
<option value="8">Push (slides in from the right)</option><option value="10">Matrix (falling streaks)</option><option value="9">Random</option></select>
|
||||||
|
<label>Random picks from</label><div id="h_random"></div>
|
||||||
<label>Effect for</label><label><input type="checkbox" id="h_small"> small changes only (the clock's minutes); a new page appears at once</label>
|
<label>Effect for</label><label><input type="checkbox" id="h_small"> small changes only (the clock's minutes); a new page appears at once</label>
|
||||||
<label>Effect time</label><label><input type="number" id="h_efft" min="100" max="10000" style="width:6em"> ms (100-10000, not for Instant; Push and Matrix need more when many dots change)</label>
|
<label>Effect time</label><label><input type="number" id="h_efft" min="100" max="10000" style="width:6em"> ms (100-10000, not for Instant; Push and Matrix need more when many dots change)</label>
|
||||||
<label>Dot refresh</label><label>every <input type="number" id="h_rdots" min="0" max="1440" style="width:5em"> min (0 = off): every dot flipped again</label>
|
<label>Dot refresh</label><label>every <input type="number" id="h_rdots" min="0" max="1440" style="width:5em"> min (0 = off): every dot flipped again</label>
|
||||||
@@ -704,10 +705,12 @@ async function cycleTest(){clearInterval(testTimer);let n=0;const step=()=>live(
|
|||||||
await step();testTimer=setInterval(step,Math.max(4000,(settings.drive.effect?settings.drive.effect_time:0)+2000))}
|
await step();testTimer=setInterval(step,Math.max(4000,(settings.drive.effect?settings.drive.effect_time:0)+2000))}
|
||||||
async function stopTest(){clearInterval(testTimer);testTimer=null;await stopLive()}
|
async function stopTest(){clearInterval(testTimer);testTimer=null;await stopLive()}
|
||||||
// settings
|
// settings
|
||||||
|
function fillRandom(list){const d=$('h_random');d.textContent='';for(const o of $('h_effect').options)if(+o.value&&o.value!=9)
|
||||||
|
d.append(mk('label',{style:'display:inline-block;margin-right:1em'},mk('input',{type:'checkbox',value:o.value,checked:!!(list>>o.value&1)}),' '+o.textContent))}
|
||||||
function fill(){const s=settings;$('s_en').checked=s.schedule.enabled;$('s_day').value=s.schedule.day_start;
|
function fill(){const s=settings;$('s_en').checked=s.schedule.enabled;$('s_day').value=s.schedule.day_start;
|
||||||
$('s_night').value=s.schedule.night_start;$('s_slow').checked=s.slow_mode.enabled;$('s_slowmin').value=s.slow_mode.minutes;
|
$('s_night').value=s.schedule.night_start;$('s_slow').checked=s.slow_mode.enabled;$('s_slowmin').value=s.slow_mode.minutes;
|
||||||
$('c_nw').checked=s.clock.no_wifi_screen;$('h_flip').value=s.flip_time;$('h_led').checked=s.status_led;
|
$('c_nw').checked=s.clock.no_wifi_screen;$('h_flip').value=s.flip_time;$('h_led').checked=s.status_led;
|
||||||
$('h_gap').value=s.drive.flip_gap;$('h_pulses').value=s.drive.pulses;$('h_effect').value=s.drive.effect;$('h_efft').value=s.drive.effect_time;$('h_small').checked=s.drive.effect_small_only;$('h_rdots').value=s.refresh.dots;$('h_rimg').value=s.refresh.image;
|
$('h_gap').value=s.drive.flip_gap;$('h_pulses').value=s.drive.pulses;$('h_effect').value=s.drive.effect;$('h_efft').value=s.drive.effect_time;$('h_small').checked=s.drive.effect_small_only;fillRandom(s.drive.random_effects);$('h_rdots').value=s.refresh.dots;$('h_rimg').value=s.refresh.image;
|
||||||
$('ha_en').checked=s.home_assistant.enabled;$('ha_host').value=s.home_assistant.host;$('ha_port').value=s.home_assistant.port;$('ha_user').value=s.home_assistant.user;
|
$('ha_en').checked=s.home_assistant.enabled;$('ha_host').value=s.home_assistant.host;$('ha_port').value=s.home_assistant.port;$('ha_user').value=s.home_assistant.user;
|
||||||
$('ha_pass').placeholder=s.home_assistant.password_set?'unchanged':'none';$('ha_url').value=s.home_assistant.api_url;$('ha_plex').value=s.plex_user||'';
|
$('ha_pass').placeholder=s.home_assistant.password_set?'unchanged':'none';$('ha_url').value=s.home_assistant.api_url;$('ha_plex').value=s.plex_user||'';
|
||||||
$('ha_token').value='';$('ha_token').placeholder=s.home_assistant.token_set?'unchanged':'none'}
|
$('ha_token').value='';$('ha_token').placeholder=s.home_assistant.token_set?'unchanged':'none'}
|
||||||
@@ -717,7 +720,7 @@ function collect(){const s=JSON.parse(JSON.stringify(settings));
|
|||||||
if(sm.enabled!=settings.slow_mode.enabled||sm.minutes!=settings.slow_mode.minutes)s.slow_mode=sm;else delete s.slow_mode; // HA may have switched it meanwhile
|
if(sm.enabled!=settings.slow_mode.enabled||sm.minutes!=settings.slow_mode.minutes)s.slow_mode=sm;else delete s.slow_mode; // HA may have switched it meanwhile
|
||||||
s.clock={no_wifi_screen:$('c_nw').checked};
|
s.clock={no_wifi_screen:$('c_nw').checked};
|
||||||
s.flip_time=+$('h_flip').value;s.status_led=$('h_led').checked;
|
s.flip_time=+$('h_flip').value;s.status_led=$('h_led').checked;
|
||||||
s.drive={flip_gap:+$('h_gap').value,pulses:+$('h_pulses').value,effect:+$('h_effect').value,effect_time:+$('h_efft').value,effect_small_only:$('h_small').checked};s.refresh={dots:+$('h_rdots').value,image:+$('h_rimg').value};
|
s.drive={flip_gap:+$('h_gap').value,pulses:+$('h_pulses').value,effect:+$('h_effect').value,effect_time:+$('h_efft').value,effect_small_only:$('h_small').checked,random_effects:[...$('h_random').querySelectorAll('input')].reduce((m,c)=>c.checked?m|1<<c.value:m,0)};s.refresh={dots:+$('h_rdots').value,image:+$('h_rimg').value};
|
||||||
Object.assign(s.home_assistant,{enabled:$('ha_en').checked,host:$('ha_host').value.trim(),port:+$('ha_port').value,user:$('ha_user').value.trim(),api_url:$('ha_url').value.trim()});s.plex_user=$('ha_plex').value.trim();
|
Object.assign(s.home_assistant,{enabled:$('ha_en').checked,host:$('ha_host').value.trim(),port:+$('ha_port').value,user:$('ha_user').value.trim(),api_url:$('ha_url').value.trim()});s.plex_user=$('ha_plex').value.trim();
|
||||||
if($('ha_pass').value)s.home_assistant.password=$('ha_pass').value;if($('ha_token').value)s.home_assistant.token=$('ha_token').value.trim();return s}
|
if($('ha_pass').value)s.home_assistant.password=$('ha_pass').value;if($('ha_token').value)s.home_assistant.token=$('ha_token').value.trim();return s}
|
||||||
async function saveSettings(){const r=await post('/api/settings',collect());settings=r.settings;fill();msg(r.restart?'Saved, restarting...':'Settings saved')}
|
async function saveSettings(){const r=await post('/api/settings',collect());settings=r.settings;fill();msg(r.restart?'Saved, restarting...':'Settings saved')}
|
||||||
|
|||||||
@@ -692,6 +692,7 @@ static void settingsToJson(const Settings &s, JsonObject o)
|
|||||||
drive["effect"] = s.drive.effect;
|
drive["effect"] = s.drive.effect;
|
||||||
drive["effect_time"] = s.drive.effect_time;
|
drive["effect_time"] = s.drive.effect_time;
|
||||||
drive["effect_small_only"] = s.drive.effect_small_only;
|
drive["effect_small_only"] = s.drive.effect_small_only;
|
||||||
|
drive["random_effects"] = s.random_effects;
|
||||||
JsonObject refresh = o["refresh"].to<JsonObject>();
|
JsonObject refresh = o["refresh"].to<JsonObject>();
|
||||||
refresh["dots"] = s.refresh.dots;
|
refresh["dots"] = s.refresh.dots;
|
||||||
refresh["image"] = s.refresh.image;
|
refresh["image"] = s.refresh.image;
|
||||||
@@ -760,6 +761,8 @@ static void handleSettingsPost()
|
|||||||
if (drive["effect_time"].is<int>())
|
if (drive["effect_time"].is<int>())
|
||||||
s.drive.effect_time = constrain(drive["effect_time"].as<int>(), 0, 65535);
|
s.drive.effect_time = constrain(drive["effect_time"].as<int>(), 0, 65535);
|
||||||
copyBool(drive["effect_small_only"], s.drive.effect_small_only);
|
copyBool(drive["effect_small_only"], s.drive.effect_small_only);
|
||||||
|
if (drive["random_effects"].is<int>())
|
||||||
|
s.random_effects = constrain(drive["random_effects"].as<int>(), 0, 65535);
|
||||||
JsonVariantConst refresh = body["refresh"];
|
JsonVariantConst refresh = body["refresh"];
|
||||||
if (refresh["dots"].is<int>())
|
if (refresh["dots"].is<int>())
|
||||||
s.refresh.dots = constrain(refresh["dots"].as<int>(), 0, 65535);
|
s.refresh.dots = constrain(refresh["dots"].as<int>(), 0, 65535);
|
||||||
|
|||||||
@@ -748,21 +748,75 @@ void test_settings_drive_ranges()
|
|||||||
void test_effect_time_is_zero_when_instant()
|
void test_effect_time_is_zero_when_instant()
|
||||||
{
|
{
|
||||||
DriveSettings d;
|
DriveSettings d;
|
||||||
TEST_ASSERT_EQUAL(0, (int)effectTime(d)); // default: instant
|
TEST_ASSERT_EQUAL(0, (int)effectTime(d, RANDOM_EFFECTS_ALL)); // default: instant
|
||||||
d.effect = 1;
|
d.effect = 1;
|
||||||
d.effect_time = 2500;
|
d.effect_time = 2500;
|
||||||
TEST_ASSERT_EQUAL(2500, (int)effectTime(d));
|
TEST_ASSERT_EQUAL(2500, (int)effectTime(d, RANDOM_EFFECTS_ALL));
|
||||||
d.effect = DRIVE_EFFECT_PUSH; // can take much longer
|
d.effect = DRIVE_EFFECT_PUSH; // can take much longer
|
||||||
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_PUSH_EXTRA_TIME, (int)effectTime(d));
|
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_PUSH_EXTRA_TIME, (int)effectTime(d, 0x2));
|
||||||
d.effect = DRIVE_EFFECT_RANDOM; // can be a push
|
|
||||||
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_PUSH_EXTRA_TIME, (int)effectTime(d));
|
|
||||||
d.effect = DRIVE_EFFECT_MATRIX; // flips most dots of a changed column twice
|
d.effect = DRIVE_EFFECT_MATRIX; // flips most dots of a changed column twice
|
||||||
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_MATRIX_EXTRA_TIME, (int)effectTime(d));
|
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_MATRIX_EXTRA_TIME, (int)effectTime(d, 0x2));
|
||||||
Settings s;
|
Settings s;
|
||||||
s.drive.effect = DRIVE_EFFECT_MATRIX;
|
s.drive.effect = DRIVE_EFFECT_MATRIX;
|
||||||
TEST_ASSERT_NULL(validateSettings(s));
|
TEST_ASSERT_NULL(validateSettings(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_effect_time_of_random_is_the_slowest_on_its_list()
|
||||||
|
{
|
||||||
|
DriveSettings d;
|
||||||
|
d.effect = DRIVE_EFFECT_RANDOM;
|
||||||
|
d.effect_time = 2500;
|
||||||
|
const uint16_t push = 1 << DRIVE_EFFECT_PUSH, matrix = 1 << DRIVE_EFFECT_MATRIX, sparkle = 1 << 1;
|
||||||
|
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_PUSH_EXTRA_TIME, (int)effectTime(d, RANDOM_EFFECTS_ALL));
|
||||||
|
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_PUSH_EXTRA_TIME, (int)effectTime(d, push | sparkle));
|
||||||
|
TEST_ASSERT_EQUAL(2500 + (int)DRIVE_MATRIX_EXTRA_TIME, (int)effectTime(d, matrix | sparkle));
|
||||||
|
TEST_ASSERT_EQUAL(2500, (int)effectTime(d, sparkle));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_random_effects_list_is_validated()
|
||||||
|
{
|
||||||
|
Settings s;
|
||||||
|
TEST_ASSERT_EQUAL_HEX16(RANDOM_EFFECTS_ALL, s.random_effects); // default: everything
|
||||||
|
TEST_ASSERT_NULL(validateSettings(s));
|
||||||
|
s.random_effects = 1 << DRIVE_EFFECT_MATRIX;
|
||||||
|
TEST_ASSERT_NULL(validateSettings(s));
|
||||||
|
s.random_effects = 0; // nothing to pick from
|
||||||
|
TEST_ASSERT_NOT_NULL(validateSettings(s));
|
||||||
|
s.random_effects = 1 << DRIVE_EFFECT_INSTANT;
|
||||||
|
TEST_ASSERT_NOT_NULL(validateSettings(s));
|
||||||
|
s.random_effects = 1 << DRIVE_EFFECT_RANDOM; // would pick itself
|
||||||
|
TEST_ASSERT_NOT_NULL(validateSettings(s));
|
||||||
|
s.random_effects = 1 << DRIVE_EFFECT_COUNT;
|
||||||
|
TEST_ASSERT_NOT_NULL(validateSettings(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_random_picks_only_from_its_list_and_all_of_it()
|
||||||
|
{
|
||||||
|
// Each list of 2 or 3 of the effects, and the whole list
|
||||||
|
const uint16_t lists[] = {RANDOM_EFFECTS_ALL, 1 << 3, (1 << 3) | (1 << DRIVE_EFFECT_MATRIX),
|
||||||
|
(1 << 1) | (1 << 5) | (1 << DRIVE_EFFECT_PUSH)};
|
||||||
|
for (uint16_t list : lists)
|
||||||
|
{
|
||||||
|
int seen[DRIVE_EFFECT_COUNT] = {};
|
||||||
|
for (uint32_t r = 0; r < 990; r++)
|
||||||
|
seen[pickRandomEffect(list, r * 2654435761u)]++;
|
||||||
|
for (int effect = 0; effect < DRIVE_EFFECT_COUNT; effect++)
|
||||||
|
{
|
||||||
|
if (list & (1 << effect))
|
||||||
|
{
|
||||||
|
TEST_ASSERT_GREATER_THAN(50, seen[effect]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL(0, seen[effect]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The first on the list: what the Nano stores
|
||||||
|
TEST_ASSERT_EQUAL(DRIVE_EFFECT_MATRIX, pickRandomEffect(1 << DRIVE_EFFECT_MATRIX, 0));
|
||||||
|
TEST_ASSERT_EQUAL(3, pickRandomEffect((1 << 3) | (1 << DRIVE_EFFECT_MATRIX), 0));
|
||||||
|
}
|
||||||
|
|
||||||
void test_settings_off_page_blank_or_bitmap_name()
|
void test_settings_off_page_blank_or_bitmap_name()
|
||||||
{
|
{
|
||||||
Settings s;
|
Settings s;
|
||||||
@@ -3380,6 +3434,9 @@ int main()
|
|||||||
RUN_TEST(test_settings_slow_mode_interval);
|
RUN_TEST(test_settings_slow_mode_interval);
|
||||||
RUN_TEST(test_settings_drive_ranges);
|
RUN_TEST(test_settings_drive_ranges);
|
||||||
RUN_TEST(test_effect_time_is_zero_when_instant);
|
RUN_TEST(test_effect_time_is_zero_when_instant);
|
||||||
|
RUN_TEST(test_effect_time_of_random_is_the_slowest_on_its_list);
|
||||||
|
RUN_TEST(test_random_effects_list_is_validated);
|
||||||
|
RUN_TEST(test_random_picks_only_from_its_list_and_all_of_it);
|
||||||
RUN_TEST(test_settings_off_page_blank_or_bitmap_name);
|
RUN_TEST(test_settings_off_page_blank_or_bitmap_name);
|
||||||
RUN_TEST(test_changed_off_image_is_redrawn_while_the_display_is_on);
|
RUN_TEST(test_changed_off_image_is_redrawn_while_the_display_is_on);
|
||||||
RUN_TEST(test_settings_flip_time_and_port_ranges);
|
RUN_TEST(test_settings_flip_time_and_port_ranges);
|
||||||
|
|||||||
Reference in new issue
Block a user