Commit Graph

96 Commits

Author SHA1 Message Date
Maxim Prokhorov
2dd05f2179 types: preserve existing sv pointer when slicing out-of-bounds
consistent with string_view::substr behaviour, without the 'throw'ing part
allow to distinguish sv pointing to nothing and sv originating from some
kind of string (here, result of a slice) by comparing its pointer with nullptr
2024-09-10 16:11:27 +03:00
Maxim Prokhorov
30ae346a19 sch: events in mqtt & api
also changes internal timestamp to minutes instead of seconds
no mqtt publish, though, w/ retain defaults and no settings back-up
2024-08-29 17:26:56 +03:00
Maxim Prokhorov
eea56d7a0c sch: inconsistent DST <-> SDT transition when searching
- probe for double and missing hours when daylight saving time happens
  this is specific to local time schedules, utc should remain unaffected
- try to stay consistent with current pattern matching happening in loop
  when an hour is missing, simply skip to the next schedule
  when hour is repeated, make sure to recheck 'earlier' matches
- clean-up tests previously using very-very internal structs
  try to handle everything (sic) using `handle_*` functions
  from the corresponding namespace
2024-08-29 17:18:31 +03:00
Maxim Prokhorov
37596eb436 sch: missing tests for zero offset 2024-08-23 21:30:20 +03:00
Maxim Prokhorov
8edb7b6333 sch: relative time spec for events
Reference calendar time of other schedules, user-created named events
or the sun{rise,set} (when enabled)

For example
- '15m before sunset'
- '30m after cal#0'
- '1h15m after "foobar"'

Empty time spec is allowed, defaults to '1m'
'before sunrise' is the same as '1m before sunrise'

Internals are reworked to handle a more generalized 'Event' type, based
on the 'time point' and 'event' base classes fron sunrise and sunset

Sunrise and sunset should also track 'last' event as well as 'next
(not currently displayed anywhere, though)
2024-08-22 23:40:31 +03:00
Maxim Prokhorov
868d4886ed sys: durations & parsing in the same namespace
not part of settings directly, move them some place else
types compilation unit grows, though...
2024-08-22 23:40:31 +03:00
Maxim Prokhorov
f82cd2211e sch: restore offset for closest, not earliest match in a day
ffs -> clz minus int size, otherwise multiple match order is broken
experiment with future masking, using ffs correctly this time
update tests to handle all branches of closest_delta, both future and past
2024-08-15 14:49:17 +03:00
Maxim Prokhorov
0c52a808cc sns: safeguard against size zero
probably would not happen b/c of config restrains, but...
2024-08-10 00:28:24 +03:00
Maxim Prokhorov
bd1f734494 sch: unused code 2024-08-09 15:03:59 +03:00
Maxim Prokhorov
2d3bba9e01 utils: more duration types and shorter uptime string 2024-08-09 12:46:10 +03:00
Maxim Prokhorov
9acc95e952 sns: update tests 2024-08-09 12:46:10 +03:00
Maxim Prokhorov
d6f807d68c scheduler: midnight as default HH:MM
allow just "UTC", "Monday", "05-01", etc.
clarify webui paragraph and mention KEYWORD as an element

ignore sunrise and sunset keywords when sun module is disabled

move all of parsing to time module, test whether combined match works
2024-05-27 19:10:25 +03:00
Maxim Prokhorov
17a599f91b test: leftover printf 2024-05-27 03:34:50 +03:00
Maxim Prokhorov
c8c9150b37 scheduler: test handle_today with a future date
github actions just happen to be in pacific time / utc-7 today
2024-05-23 01:40:30 +03:00
Maxim Prokhorov
f3f797f93b scheduler: refactor restore, proper sun state
certain actions need to happen when
- starting restore()
- switching date within restore()
- stopping restore()

pretty good fit for an object and raii. so, using context struct to handle
sun{rise,set} initialization and per-schedule time match updates

sun{rise,set} event happens on a specific date, make sure it is also checked
fix double action trigger by comparing minutes, not raw timestamp seconds

experimenting with 'invalid state' i.e. when timestamp was not generated

include restore logic in tests, as code now lives in .ipp
2024-05-23 00:58:36 +03:00
Maxim Prokhorov
d2e18744dc scheduler: backport remainder impl, fix ambiguous name 2024-05-16 01:25:50 +03:00
Maxim Prokhorov
b070b908a7 test: scheduler 2024-05-16 01:25:50 +03:00
Maxim Prokhorov
7152cc67a8 sns: BaseFilter::status()
no real reason to expose internal state, just report filter readiness
2024-02-08 22:17:38 +03:00
Maxim Prokhorov
a33c71b62b sns: special cases for median-average filter 2024-02-08 22:17:38 +03:00
Maxim Prokhorov
aa74de8843 sns: moving average should be an average
ref. #2543
2024-02-08 22:17:38 +03:00
Maxim Prokhorov
b44c293fca test: expected sensor filter values 2024-02-08 22:17:38 +03:00
Maxim Prokhorov
0f5fc5acc3 test: allow double comparison in tests 2024-02-08 22:17:38 +03:00
Maxim Prokhorov
5531b93269 terminal: fix linkage, printing cmd-not-found and add tests 2023-10-17 01:57:40 +03:00
Maxim Prokhorov
06e49ccf9b uart: swserial workaround for recent Core version
fix #2592 (for real this time)
2023-10-17 00:26:53 +03:00
Maxim Prokhorov
480c72dc07 sns: broken mqtt address publishing
cannot declare constexpr objects like that with old compiler
fix #2594
2023-10-16 23:25:39 +03:00
Maxim Prokhorov
fd7f97eb24 settings: test conversions properly
separate convesions from the main source to allow test builds
extra unit to verify that both duration plain input and
spec work as intended

also fix wdt triggered when unknown symbols are encountered at the end
of duration string (e.g. 10000y)
2023-03-15 17:06:13 +03:00
Maxim Prokhorov
9211dcd785 system: lock reent object in ctor 2023-01-18 06:14:34 +03:00
Maxim Prokhorov
312c3ef2ba test: bump esp8266 version used for unit tests 2022-12-12 15:13:25 +03:00
Maxim Prokhorov
24c3ff8954 test: arduinojson header 2022-12-12 14:29:22 +03:00
Maxim Prokhorov
e53e25c8bb test: utils 2022-12-12 14:25:01 +03:00
Maxim Prokhorov
74ad71bf74 tests: fix device-only macro 2022-10-23 05:45:42 +03:00
Maxim Prokhorov
639b558100 settings: raw erase fixes
solves edge-case when we move our storage nearby a previously erased kv,
causing it to be treated as a key or a value with length 255 (... 0x00 0xff)

also stop set() from erasing data when it is not possible to store it in
the first place

additional test case similar to permutations one, make sure keys don't
disappear while we write to the storage a lot of times and possibly
introduce the two cases above
2022-10-23 03:18:57 +03:00
Maxim Prokhorov
a11942fd7b mqtt: string views in API and internal callbacks
* stateless callbacks for mqttRegister. no module uses the lambda / std
  func with captures or otherwise, so it is kind of pointless to have it
* make sure we know topic and payload length at all invocations and
  not constantly trying to re-parse the same string over and over again
* clean-up api related to string parsing and make sure we allow
  stringview as input
* clean-up id / unsigned number parsing to work with views instead of
  using a generic strto{,u}l; sometimes this works, sometimes doesn't.
  as noticed previously with IR implementation, it *will* parse until
  the '\0' is found in the input and we can't interpret parts of the
  string without doing a copy for the strtoul
* fixing additional bugs caught in ifan, leds, sensors and lights that
  were causing build failures. plus, more range-based parsing code for
  the same reason as described above
2022-10-23 03:18:57 +03:00
Maxim Prokhorov
510d68d079 system: fixup timers and loop callbacks
* globally accessible system timer class; help out with our internal
  scheduling by always using strongly typed duration and dynamic
  time adjustment for durations longer than system limits
  (see `os_timer_t` documentation)
* our own class for scheduled callbacks which are either choosing a
  simple function pointer or std function wrapper, depending on the type
  passed into the constructor. specifically for scheduled functions,
  this allows us to filter globally scheduled functions and push them to
  the front of the queue when necessary to ensure certain order of calls
* replace Ticker instances with SystemTimer
* allow types {h, cpp} in unit tests
2022-10-23 03:18:57 +03:00
Maxim Prokhorov
574fbf1960 uart: standalone configuration
- setup uart at boot instead of delaying until some module needs it
  removes global `SERIAL_BAUDRATE` and `DEBUG_PORT` in favour or
  globally accessible numbered port configurations with `MODULE_NAME_PORT`
- automagically enable uart support for sensors that need it
- allow every sensor to configure uart0 (normal and swapped), uart1
  and an optional software-serial mode support with an extra build flag
  remove individual includes across the sensors
- settings queries and runtime port configuration (prefixed with uart)
- update dependencies header to cross-reference used ports at build time
- update deprecations header with serial baudrate notice
2022-09-25 08:26:22 +03:00
Maxim Prokhorov
3d580f3577 terminal: __FlashStringHelper -> StringView
- clean-up comparison routines and get rid of most of the casts
- reduces total number of calls to terminalRegisterCommand
  replace with a func accepting list of commands, which in
  turn get instantiated as constexpr PROGMEM arrays
- reduce ram fragmentation, since we don't need to alloc as much
- reduce flash consumption b/c of lambda -> standalone func conversion
2022-09-25 06:14:54 +03:00
Maxim Prokhorov
7fc8ccdf72 system: fix view comparison
note that it is equality, not byte comparison based on
memcmp or strcmp return values
2022-09-21 04:31:20 +03:00
Maxim Prokhorov
5bc55cd1a5 hw: core -> minimal 2022-09-21 04:21:23 +03:00
Maxim Prokhorov
677f368cfa test: bump esp8266 version used for unit tests 2022-09-08 13:39:26 +03:00
Maxim Prokhorov
5f67212935 test: generate compile_commands.json 2022-09-08 13:39:26 +03:00
Maxim Prokhorov
2a5756e1b5 terminal: fix escaped characters parsing
also fix test entry incorrectly using an already escaped string
2022-09-08 13:39:26 +03:00
Maxim Prokhorov
ef202109e7 terminal: remove shared output
Make every available call site 'private'
e.g. typing command in telnet no longer prints to serial or WebUI

Serial input is now optional, see `TERMINAL_SERIAL_SUPPORT`.
Telnet using async server is a proper Print implementation now.
WebUI, MQTT and HTTP input is allowed to inject multiple lines at once.

Modernize our helper classes and remove legacy 2.3.0 quirks.
Replace global Terminal object and allow to separately
split, parse ARGV list and perform command search and invocation with
standalone function calls.
(but, notice that we still depend on a globally shared 'commands' list)

This greatly reduces used RAM (but, slightly increases our ROM).

Update our test suite to use namespaces and new calling convention.
2022-09-08 13:39:11 +03:00
Maxim Prokhorov
ff19c0889d test: fix namespaces 2022-08-29 06:01:21 +03:00
hamed
660d8c339b sns: add INA219 (current / power monitor)
resolves #2501

Co-Authored-by: Maxim Prokhorov <prokhorov.max@outlook.com>
2022-05-18 21:22:32 +03:00
Maxim Prokhorov
c04cdff200 sns: build flag for dummy sensor 2022-05-06 18:56:54 +03:00
Xose Pérez
1c9553176d hw: add support for PM1006 (IKEA Vindriktning) (#2505)
IKEA Vindriktning Air Quality Sensor
https://www.ikea.com/gb/en/p/vindriktning-air-quality-sensor-80515910/
2022-05-06 14:37:49 +03:00
Maxim Prokhorov
456d1cc586 ci: reference dump() method for the settings storage 2022-02-11 13:53:34 +03:00
Maxim Prokhorov
c37bbb42a6 ci: make sure ctest prints it's failures 2022-02-11 13:53:05 +03:00
Maxim Prokhorov
eaa2e370eb ci: use esp8266 mock framework
Resolve the issue with the UnixHostDuino not really being compatible
with the esp8266 Core String (...and the rest of the Core, as well)

Port the CMakeLists.txt from the rpnlib and update it use FetchContent
instead of either manually fetching dependencies or using PIO artifacts
Caching is *expected* to work, but might need slight adjustments
2022-01-13 04:04:37 +03:00
Maxim Prokhorov
2f580a37a2 terminal: context is a temporary
Make sure it could be moved further along, and the values inside of it
can be safely moved as well.

Also fixup commands that were missing ctx in OK / Error.
2021-12-08 18:05:25 +03:00