Commit Graph

3341 Commits

Author SHA1 Message Date
Maxim Prokhorov
5dd2009214 webui: fix checkbox styling under pure-form
Using a more 'specific' CSS rule to override it's width and height
2021-12-30 02:03:03 +03:00
Maxim Prokhorov
9e390084c9 system: these are in ROM 2021-12-30 02:03:03 +03:00
Maxim Prokhorov
3aef6adf7d webui: update "select" options to use text values 2021-12-30 02:03:03 +03:00
Maxim Prokhorov
710f45c2b1 webui: magnitude should not print missing unit
In case the measurement is unitless, make sure to substitute the empty
.units[id] value with an empty string instead of the ambigious 'undefined'
2021-12-30 02:03:03 +03:00
Maxim Prokhorov
40c50f910e webui: do not lose select original=value when nothing is selected 2021-12-30 02:03:03 +03:00
Maxim Prokhorov
e213b58db2 settings: continue refactoring internal constants
Settling on naming 'options' for enumerations (...possibly, everything
else in the future, would that make sense to store for 'setting' object)

Update terminal commands that were reporting status to also report a
full list of 'indexed' settings for the specific entity
Also updates the WebUI outputs which are (hopefuly) are already handled
as-is through the .js processing pipeline and the .html properties
receiving certain special string values

More namespacing and save ~2KiB of RAM by reducing the amount of loaded keys strings
However, ROM side of things may suffer b/c of template specializations for the
generic conversion functions when there are many different types involved.
2021-12-30 02:03:03 +03:00
Maxim Prokhorov
7727d7f824 light: __cplusplus match only needed for < c++17 2021-12-23 14:42:10 +03:00
Maxim Prokhorov
76b11470f0 led: add more PROGMEM to the internal constants
Since we know the key-defaults ahead of time, move those there as well
Also tweak alignment of the resulting structs to be % 4
2021-12-23 14:42:03 +03:00
Maxim Prokhorov
5865654950 led: fixup findme-wifi and relays modes
Renamings, and fix duplicate code paths and actually use all of relays
for the status check instead of just one (like the FOLLOW does)
2021-12-23 12:51:43 +03:00
Maxim Prokhorov
167eb6c939 sensor: send action results to the specific client 2021-12-23 12:51:43 +03:00
Maxim Prokhorov
e78cfd00cb relay: use both settings and build flags for mqtt disconnection event
And since WebUI payload used it, this was not reported as 'unused'
2021-12-23 12:51:43 +03:00
Maxim Prokhorov
514bc938c2 settings: rework string<->enum conversion
Make sure we seamlessly handle 'convert' for the number and the string version.
And since it is a two-way map, update 'serialize' to use it as well instead of
either a simple static_cast<int> or duplicating the same strings used in 'convert'

Only string literals or static vars can be used in constexpr context,
but those can still be shoved into the flash region via PROGMEM.
Notably, PSTR(...) inside of a lambda is not a constexpr.

Some quirks to work out
- we don't 'enumerate' things through compiler, enum values may go
  missing since it is not a switch-case
- 'get' default value via query still requires us to know the settings
  key in the first place. and it still needs an explicit call to
  'serialize'
- sensor units are stringified as their display value.
  but, this also avoids two different 'string' versions of those
- EnumOptions struct instance may also be in PROGMEM, but one needs
  to be very careful to only allow aligned access to it's members
  (which currently means we can't use 8bit or 16bit 'enum class'es)
2021-12-23 12:51:43 +03:00
Maxim Prokhorov
ec33ee3242 relay: disarm and reset the timer after callback 2021-12-20 14:23:37 +03:00
Maxim Prokhorov
196bb5bc7a api: relax 'accept:' requirements
If the endpoint receives no header, treat it as '*/*'

Don't fail prematurely, since asyncwebserver handler needs to claim the
request to issue a custom response code.
ref.
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406
- https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.6
2021-12-20 14:11:52 +03:00
Maxim Prokhorov
b67269f9ef relay: fixup pulse handlers
cstring's *cmp* return result is integer, not boolean
Pulse processing should only trigger when *current* state is not normal
2021-12-20 14:00:20 +03:00
Maxim Prokhorov
0c57f0bcf9 relay: synchronize in loop task
Remove the ticker dependency, and make sure 'save' callback does not
override itself when at least one relay does not set the 'persist' flag
2021-12-20 14:00:20 +03:00
Maxim Prokhorov
f7ba4eda72 relay: pulse command status is for 'normal' state
Also fixing accidental copies of the timer object.
2021-12-19 20:43:28 +03:00
Maxim Prokhorov
b2c900b799 ntp: fix terminal newlines 2021-12-19 17:48:40 +03:00
Maxim Prokhorov
64d70b1324 utils: mode is always null 2021-12-19 17:48:40 +03:00
Maxim Prokhorov
907cba1518 utils: comments 2021-12-19 17:48:40 +03:00
Maxim Prokhorov
bffc484c47 relay: comments 2021-12-19 17:48:40 +03:00
Maxim Prokhorov
3f2d2308f8 relay: set initial status for pulse 2021-12-19 17:48:40 +03:00
Maxim Prokhorov
ba90b76020 relay: pulse api returns seconds 2021-12-19 17:48:40 +03:00
Maxim Prokhorov
e271eaa019 sensor: fix crash when trying to read ratio settings 2021-12-18 23:47:20 +03:00
Maxim Prokhorov
a5bb8e457a system: fix ticker arg cast
Don't introduce our callback to the type system, continue to bind the
ticker instance as the timer's arg and just use the lambda to pass the
argument to the reset function

```
libraries/Ticker/src/Ticker.h:136:41: warning: cast between incompatible function types from 'void (*)(CustomResetReason)' to 'Ticker::callback_with_arg_t' {aka 'void (*)(void*)'} [-Wcast-function-type]
  136 |         _attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), reinterpret_cast<void*>(arg));
      |                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
2021-12-18 23:47:20 +03:00
Maxim Prokhorov
19963fb8ce system: some unused params 2021-12-18 23:47:20 +03:00
Maxim Prokhorov
20fc3a655c system: clean-up types 2021-12-18 23:46:37 +03:00
Maxim Prokhorov
81862e420a api: check content-type detected by the server
Don't fail when the header also has charset=...
Also, fallback to text/plain when there's no Accept
2021-12-18 23:46:37 +03:00
Maxim Prokhorov
493bbcfa2a relay: accept {hh}h{mm}m{ss}s syntax for pulse
Attempt to either parse with newer syntax, or fallback to the floating
point seconds as default. Settings also return a 'result' instead of the
default zero, fallback to build value otherwise (which is still floating point, though)

Update /pulse API endpoint to report the actual pulse timer value that
is active right now, not just the value attached via the setting
2021-12-18 23:40:53 +03:00
Maxim Prokhorov
f4813fe303 api: fix warnings
Unused variables, bogus const-qualifiers and some strict switch-case rules with -Wextra
2021-12-18 23:40:53 +03:00
Maxim Prokhorov
5940f0aa8c alexa: always read the specified length of the payload
Make sure we don't try to strlen some empty space or neighbouring
segments, that may or may not contain nulls

Also tweak the function to warn about large messages, since it is not
(yet) clear whether we actually want those. At least something to log.
2021-12-18 23:40:53 +03:00
Maxim Prokhorov
79e4fac010 wifi: make sure settings are in namespaces
Localize build constants & settings use, no need to prefix where
namespacing already does this (and also removes some duplicates)
2021-12-18 23:40:53 +03:00
Maxim Prokhorov
202243dc0f rfbridge: don't printf without any args
Also calm down clangd, mark template specializations as unused
2021-12-18 23:40:53 +03:00
Maxim Prokhorov
d788e04616 relay: pulse as terminal command 2021-12-18 23:40:53 +03:00
Maxim Prokhorov
6bce23d23c ntp: rework internals and use namespacing
Make sure to properly clamp delay times, as the recent issue had shown
it is possible to go below the update limit. SNTP app does not do any
runtime checks, so it's up to us to enforce these limits

Update internal random number generator from raw `secureRandom()` to a custom
'std::random_device'-look-alike, where we could also use it with STL functions
(current implementation is `os_random()` aka `esp_random()`)
2021-12-18 23:40:53 +03:00
Maxim Prokhorov
2f0b8e47bc ws: localize info access 2021-12-14 17:43:53 +03:00
m-kozlowski
21a8c2678f ntp: use milliseconds in sntp_*_delay functions (#2490) 2021-12-12 12:25:05 +03:00
Maxim Prokhorov
26d28db0ef relay: fixup stm relay change delay 2021-12-09 03:16:13 +03:00
Maxim Prokhorov
1b27fa5316 relay: preliminary support for internal duration types
Not as clean as other modules, but at least prepare for the further changes.
Implement settings for float duration conversion, and test it out with pulse
and flood window time values.

More safe-guards for an externally-defined pulse time, make sure it is
not either inf or nan and is an actual finite number

Also use EnumerableConfig for the WebUI output, and make sure to use
internal _relays.size() instead of doing a function call
2021-12-09 03:07:57 +03:00
Maxim Prokhorov
67d4463652 ota: last remaining un-typed deferredReset 2021-12-09 01:57:03 +03:00
Maxim Prokhorov
f881b83ea8 hass: flash-strings for json keys
Saves ~100bytes in RAM
2021-12-09 01:24:17 +03:00
Maxim Prokhorov
de35f9bfe1 light: use internal duration type(s)
Get rid of 'assumed' units and use strong types instead
Also update HomeAssistant conversion code as float -> uint durations
2021-12-09 01:15:11 +03:00
Maxim Prokhorov
ac9806c9e5 system: use internal duration types with nice_delay 2021-12-09 01:15:11 +03:00
Maxim Prokhorov
f44aab5fdb system: simple deferred reset function
No need for specific delay for each instance, just use a shared one
2021-12-09 01:15:11 +03:00
Maxim Prokhorov
f9ad9d44e1 webui: find all span elements, not just one 2021-12-09 01:15:11 +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
Maxim Prokhorov
a0e090489b terminal: get rid of ctx.argc
No need to duplicate argv::size()
2021-12-08 17:42:12 +03:00
Maxim Prokhorov
f2a7dcffe1 ntp: fix terminal ntp.settime and implement ntp.sync
Use internal duration types, store time in seconds and propogate as
uint32_t when it is necessary. Update tick values as well.

Instead of generic `toInt(), overload between `strtol` and `strtoll`.
Current implementation of `settimeofday` rejects `struct tz` pointer,
make sure it's nullptr.

Sync is a simple enough routine... But, expect an already synced system
before triggering the sntp restart.
2021-12-08 17:31:29 +03:00
Maxim Prokhorov
a8cf30832e wifi: use internal types for timeouts
For this, keep things as milliseconds (at least for now)

Make sure to use __builtin_strlen in constexpr context
Remove `has*()` functions that are no longer used

Update WebUI callback to use EnumerableConfig
2021-12-08 13:48:44 +03:00
Maxim Prokhorov
baac061d27 telnet: destroy the specific client when disconnecting 2021-12-08 13:48:44 +03:00