Commit Graph

66 Commits

Author SHA1 Message Date
Maxim Prokhorov
dfe01d1bbf relay: constexpr is already const 2022-02-09 16:00:41 +03:00
Maxim Prokhorov
9501595a16 relay: fix never attempting mqtt group subscriptions
Also, try to fix the API helper objects to persist the referenced struct
(best effort only, though, it is still possible to break things when not careful)
2022-02-09 15:43:08 +03:00
Maxim Prokhorov
2b83a883be relay: missing build flag check 2022-01-12 17:20:11 +03:00
Maxim Prokhorov
3aef6adf7d webui: update "select" options to use text values 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
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
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
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
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
d788e04616 relay: pulse as terminal command 2021-12-18 23:40:53 +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
ac9806c9e5 system: use internal duration types with nice_delay 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
16960067d8 system: some refactoring
There's no need to move a temporary which is already an rvalue

Clean-up some redundant attributes and function in settings.
Make sure C types are proxied to fixed-sized ones, not the other way around.

Clean-up webprint implementation
- use typed duration for the backlog
- don't duplicate members and types for config, just re-use the struct as-is
- don't go over-the-top with const members, just proxy through a method
2021-12-08 13:48:40 +03:00
Maxim Prokhorov
8f7f1c968f sns: unify settings & settings page actions
- remove 'local' index and replace sensor code depending on it with the
  existing 'slot' aka 'magnitude index' used in value() and type()
- common method to store and retrieve ratios for voltage, current,
  active power and energy. default implementation is no-op, sensor
  should implement ratio adjustment & calculations to use 'slot' indexes
- re-implement 'expected' values ui. display the actual ratio values,
  and have a separate page for updating them in a more apparent way
- remove legacy settings that were adjusting expected values
- remove legacy settings that were resetting ratios and analog calibration
- generic webui action caller, add ratios and analog calibration resets

all of 'emon' sensors were updated to utilize the new approach to the
ratio handling. pulsemeter is somewhat an outlier, but it is unclear
whether removing the energy ratio is justified

terminal part was also updated
- implement `expected` command that hooks into the new ratioFromValue
  (and what webui uses to calculate ratios)
- implement `energy` command to list only MAGNITUDE_ENERGY
- remove old pzem004t commands doing ratio reset and total energy count

another global update is related to espurna::duration
- rework module-local heartbeat and led durations into a global
  espurna::duration
- update sensor internals to use specific units instead of multiplying things
  on line-by-line basis. export count() to the api
2021-11-23 02:36:28 +03:00
Maxim Prokhorov
0b64bd0229 core: minimize espurna.h use in headers 2021-10-20 13:07:34 +03:00
Maxim Prokhorov
f920187a60 mqtt: buffer usage clean-up
Make sure to *not* use variable-length arrays for topics,
and use compile-time concatenation where it is possible.
2021-09-03 15:23:19 +03:00
Maxim Prokhorov
03573b783e webui: apply modules-... style globally
Otherwise, some things are still hidden
(or, depend on the order of incoming messages)

Make thermostat code use those as well, instead of injecting
thermostatVisible in every json payload
2021-08-22 06:42:16 +03:00
Maxim Prokhorov
6087becf86 mqtt: remove unnecessary const_cast of the topic 2021-08-21 02:48:27 +03:00
Maxim Prokhorov
e6a0e505b3 mqtt: payload is not const
Even if std::function compiles with the wrong (but compatible) signature
2021-08-21 02:48:27 +03:00
Maxim Prokhorov
5aa43d4bf1 all: suppress -Wunused-function for serialization helpers 2021-08-16 07:31:00 +03:00
Maxim Prokhorov
1522087112 relay: refactor inline getSetting into functions 2021-08-16 04:16:30 +03:00
Maxim Prokhorov
85e70d8a07 relay: workaround for gcc4.8 single-source build
Resolve the code generation issue with vector methods being unable to
store the exception info string in the same elf section
(which apparently becomes duplicated, somehow, when building single .cpp)

Error messages look like something like this:
```
vector.tcc:405
error: __c causes a section type conflict with __c
    _M_check_len(size_type(1), __EXCSTR("vector::_M_emplace_back_aux"));

vector.tcc:71
note: '__c' was declared here
  __throw_length_error(__EXCSTR(__N("vector::reserve")));
```
2021-08-11 18:45:55 +03:00
Maxim Prokhorov
453157c5db all: more static symbols 2021-08-07 16:49:07 +03:00
Maxim Prokhorov
658648d270 core: naming cleanup
Set -> On, when the handler could be added multiple times
Remove unused functions from the headers, and add correct names for the used ones.
2021-08-06 18:45:14 +03:00
Maxim Prokhorov
27f701773f settings: simplify migrateVersion() checks in modules
Just `if (version < N)` instead of `if (version && (version < N))`
Fix existing functions that were not checking for `version > 0`
2021-08-02 07:50:52 +03:00
Maxim Prokhorov
fa3deeffbf webui: remove jquery dependencies and clean-up websocket API
Refactor WebUI:
- remove jquery dependency from the base custom.js and use vanilla JS
- remove jquery + jquery-datatables dependency from the RFM69 module
- replace jquery-datatables handlers with pure-css table + some basic cell filtering
  (may be incomplete, but tbh it is not worth additional 50Kb to the .bin size)
- introduce a common way to notify about the app errors, show small text notification
  at the top of the page instead of relying on user to find out about errors by using the Web Developer Tools
- replace <span name=...> with <span data-settings-key=...>
- replace <div> templates with <template>, disallowing modification
  without an explicit DOM clone
- run `eslint` on html/custom.js and `html-validate` on html/index.html,
  and fix issues detected by both tools

Streamline settings group handling in custom.js & index.html
- drop module-specific button-add-... in favour of button-add-settings-group
- only enforce data-settings-max requirement when the property actually exists
- re-create label for=... and input id=... when settings group is
  modified, so checkboxes refer to the correct element
- introduce additional data-... properties to generalize settings group additions
- introduce Enumerable object to track some common list elements for
  <select>, allow to re-create <option> list when messages come in
  different order

Minor fixes that also came with this:
- fix relay code incorrectly parsing the payload, causing no relay names
  to be displayed in the SWITCHES panel
- fix scheduler code accidentally combining keys b/c of the way C parses
  string literals on separate lines, without any commas in-between
- thermostat should not reference tmpUnit directly in the webui, replace with
  module-specific thermostatUnit that is handled on the device itself
- fix index.html initial setup invalid adminPass ids
- fix index.html layout when removing specific schedules
2021-07-18 23:30:32 +03:00
Maxim Prokhorov
1600fcc133 settings: hide kv_store from the public header
More concise foreach, generic template code also no longer expands down to ::_read_kv
Also helps with needless inlining happening with recent gcc versions
2021-06-18 17:27:49 +03:00
Maxim Prokhorov
976176cfaa ws: use the same type for the schema keys array
Plus, it's not really a constexpr in this context
2021-04-15 21:41:39 +03:00
Maxim Prokhorov
a9be47937b settings: delete both variations of GPIO keys 2021-04-15 21:41:39 +03:00
Maxim Prokhorov
94169dcbb1 relay: fix sync reentrancy lock
Fix not resetting the lock when checking the size.

Don't lock in the boot and in the processing, both are executed in CONT
context. Still lock the relaySync() itself, since it will call relayStatus().
This goes back to the original implementation, but does not seem to be
relevant right now.
2021-04-15 17:33:28 +03:00
Maxim Prokhorov
f92116341e system: refactor build configurations
Namespace build configurations of modules, make more things into constexpr
(not fully finished though)

Unify code using ...Count() to parse IDs

Avoid using unsigned char aka uint8_t as index, prefer size_t
as most code already uses it anyway. Making sure we never accidentally
truncate the value or try to read it as 32bit-wide. Also, simplify
access to built in containers, since those use the wide type as well.

Renames led and button types, more consistent initialization and field access.
2021-03-31 09:41:04 +03:00
Maxim Prokhorov
ec220b7dd1 settings: clean-up helper classes & functions
Move inline classes into a separate file.
Make serialize() into a basic function, support numeric conversions with base option
Refactor numeric conversions and add some more helper functions for the
build flags.
2021-03-31 09:41:04 +03:00
Maxim Prokhorov
78b4007f01 system: use direct status updates instead of broker
Get rid of status & config brokers, register status callbacks directly with the module.
2021-03-31 09:41:04 +03:00
Maxim Prokhorov
6f4a8387ef relay: fixup sub topic generator for older gcc
Also fix a logic bug where the vector element is not actually initialized
2021-03-31 09:41:04 +03:00
Maxim Prokhorov
f5940b7083 webui: rework initialization for relay and scheduler
Send out keys as schema, fill given template based on the 4 common input types.
Also, refactor relayLastSch into schRestore and move into the schedule template.

Moving relayCount to a wide int, this will probably not build...
2021-03-31 09:41:04 +03:00
Maxim Prokhorov
04569c6a10 relay: stable configuration IDs
Custom provider cannot 'shadow' the relays from the config.
e.g. lights will use the id=0 when relay control is enabled, and
we should not use relayGpio0, relayPulse0, relayBoot0 and etc.
2021-03-31 09:41:04 +03:00
Maxim Prokhorov
dcc423ecaf relay: mqtt events and group topics refactoring
- fix relay-id check breaking group topics
- group -> pub and sub topics
- wildcard in subscription topic will be properly handled
- make sure on disconnect event only triggers when mqtt is changing
state from connected to disconnected, don't trigger every failed re-try
- replace receive-only mode with separate sub and pub topics
- some more build time settings (and some... questionable code to handle that)
2021-03-31 09:41:04 +03:00
Maxim Prokhorov
0f723b0248 settings: handle old keys in the respective modules
fixes #2419
2021-02-06 04:44:26 +03:00
Maxim Prokhorov
021f0afb86 sys: clean-up system-specific functions
- shrink utils source file, move heartbeat and boot management into system
- improvise with 'heartbeat' functionality. include scheduler implementation that will
manage the per-module heartbeat callbacks with individual 'mode' and
'interval' settings. current ones are mqtt (including relays, lights, thermostat), debug and
influxdb. preserve heartbeat NONE, ONCE and REPEAT, REPEAT_STATUS is effectively a hbReport & status bit.
- mqtt heartbeat is managed through mqttHeartbeat() callbacks
- tweak mqtt callbacks to use lists instead of the vector, slighly reducing the size of the .bin
- update WebUI, include report setting and update hbMode values
- make sure general.h settings include new heartbeat,
move constant definitions outside of the header
- correctly include dependencies through the .cpp, avoid leaking
internal details.
- as a side-effect, base headers are no longer included recursively
2021-01-24 03:38:02 +03:00
Maxim Prokhorov
4abcec8a2b settings: fix indirect conversions and getSetting specializations 2021-01-20 15:44:36 +03:00
Maxim Prokhorov
acf299582b relay: use helper type alias for the provider 2021-01-20 01:04:22 +03:00