Commit Graph

67 Commits

Author SHA1 Message Date
Maxim Prokhorov
98584aecc4 settings: clean up after namespace update
missing stringview key checks
fix template specialization order when building single source
update left-over modules that werent using espurna { ... }
2022-08-29 05:52:50 +03:00
Maxim Prokhorov
cc16c36736 light: experimental sequence support
execute multiple transition-initiating functions
when we don't do any transitions or have value changes queued

main application for right now is a simple notification
routine that consists of N single channel on->off transitions
2022-08-29 05:52:47 +03:00
Maxim Prokhorov
3e36438748 settings: key check with string view
make our string comparisons nicer
also clean-up namespaces for storage access
2022-08-29 04:37:58 +03:00
Maxim Prokhorov
16fcee1786 Fix namespacing scope, export StringView
rework more namespaces to use `espurna` root
makes internal references much easier (and shorter)

view class is not specific to settings, could use it across the app
remove duplicate code from IR
2022-08-25 00:41:26 +03:00
Maxim Prokhorov
b0da3e8c7f light: external pwm support
- allow both new-pwm and analogWrite (Core) implementations
- rework new-pwm initialization, a bit more sane type for pin config
- remove pin setup from lights, everything is handled by provider already
Core prepares and initializes pins when updating duty, new-pwm does this
when pwm_init is called
- rework internals related to value scaling, allow percentage as pwm duty
and value limit (instead of absolute limit set by lights previously)
2022-08-15 12:01:20 +03:00
Maxim Prokhorov
6a0d6b0c49 sns: more flash strings 2022-05-25 05:07:04 +03:00
Maxim Prokhorov
d2c7f7ea28 ws: module names in flash 2022-05-25 03:50:17 +03:00
Maxim Prokhorov
c9e3cd65f4 sns: constrain only works on a single type
make sure we use clamp instead of constrain
2022-05-18 22:18:33 +03:00
Maxim Prokhorov
5c6a6dacfb webui: fix class typos and add more control groups 2022-01-16 03:53:20 +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
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
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
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
b9db535950 light: fix out-of-bounds access when using GPIO16
As noticed in the #2472

Internal implemementation still lacks the support for the GPIO16,
as it needs to use 'special' IO16 registers (and due to the fact that the 'normal'
registers only fit in an u16[16], from 0 to 15, so internals need to change as well)
One possible way is to attach certain implementation funcs to the
struct handling the isr, avoiding a bunch of in-line checks for `pin == 16`

Another option is to just use Core's `analogWrite`, which hides the
implementation from us and should work pretty seamlessly.
(...but, currently has 2 different waveform generator types, and it is
not really clear which one is a better default, as it needs to be set at
build-time)
2021-10-03 20:44:58 +03:00
hamed
62d83c6194 light: fix rgb hex parser swapped blue and green values (#2474)
This was causing WebUI colorpicker to jump between positions in rgb mode, after the websocket immediately reported back rgb tuple containing different values
2021-09-26 01:38:54 +03:00
Maxim Prokhorov
5134cd17c0 light: limit transition time based on internal details 2021-09-03 15:23:19 +03:00
Maxim Prokhorov
4bb0c3386a light: more refactoring
Reading clang-tidy reports... Make sure to explicitly handle instances
of float -> (unsigned) long  silently removing the fractional part.
Also, small adjustments to the way these values are parsed.

Specifically:
- calculating step & time in the transition function
- rgb channels temperature adjustment from kelvins

Get rid of input & target as bool param. Replace it with more
specific functions, named accordingly, returning the Rgb struct.
(also fixes `rgb` command not returning what the rest of the API returns)

As a side-effect, make RGB payload conversion use a more paranoid parsing & serialization methods.
2021-09-03 11:03:53 +03:00
Maxim Prokhorov
d527351364 light: trigger an update on brightness function change
So it's no longer required to change any values or the state

Slightly changed the inputValue -> value transformation classes,
actually using the recursive template to apply things in order.
Still a bit quirky, but nothing better comes to mind for this.
2021-08-31 06:07:53 +03:00
Maxim Prokhorov
32aae70374 light: more refactoring related input & value stages
Fixes color+(white or cct) brightness function factor calculation
to actually do what the comment says it does.

No more unsigned char for value, consistent integer math and
explicit clamping of the input & output values.

As a follow-up for the a55cf0b, reworks brightness functions:
- value input and application implemented as part of the channel class
- track value changes externally, no need for OnceFlag
- simple all, only-rgb, color+white and color+cct are distinct
  functions, where brightness classes implement the actual math
- avoid accidentally doing an actual function call through
  `lightChannels()` by not accessing channels elements & size directly
  through the vector (yay c++ strictness regarding *public* symbols)
2021-08-30 14:34:30 +03:00
Maxim Prokhorov
a55cf0b847 light: stop the update request from running twice
In case the rgb+white(cct) brightness function was selected by the
configuration, internal calculations will always result in 'changed' being 'true'
and as a result it will continiously re-create the transition object.

fix #2467 (at least for now, the brightness function should be actually fixed)
2021-08-27 23:28:10 +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
d482baa725 light: refactor to use namespace(s)
Also clamp the value in setters / getters.
2021-08-16 04:31:36 +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
b0819fb7b2 light: more channel info in the terminal 2021-08-02 07:14:19 +03:00
Maxim Prokhorov
527f911ffb light: provide correct data to the /ws API
RGB is a #RRGGBB hex string, not a R,G,B
Current ltSaveDelay missing from the LIGHTS page
2021-07-23 17:50:21 +03:00
Maxim Prokhorov
b71d384c26 light: allow transition values to be reset during the run()
resolve #2451

Paranoid locking doesn't really matter in the current setup (but, leave some comments about how to solve it when it actually does).
Also copy internal tuple of save+transition+report and give the copy to the callback. Thus, don't assume the consumer is always nice,
and does not declare refs to internal struct variables, making this kind of hard to track.

Refactor internal code so it does not export functions to the built .o
2021-07-23 17:50:21 +03:00
Maxim Prokhorov
b80a2e9ffa terminal: trying to fix Print API usage
- more static flash strings and flash string formats
- println() will write \r\n when we mostly just use the \n
(and avoid mixing it up in the same function)
2021-04-03 20:34:34 +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
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
f013e04e22 lights: make sure channel target stays consistent
Make gamma & invert flags only apply to the transition itself.
Revert to previous behaviour, where the modified value is only ever seen
by the provider function.
2021-02-26 23:33:32 +03:00
Maxim Prokhorov
1a5f95c02e lights: more color refactoring
- clamp values via helper functions
- unify channel access as long
  slightly more ram, but we no longer cast values that are 32bit-wide anyway
- remove css option, send unconditionally as /hex
- reimplement hsv conversion functions (based on HA / python's colorsys)
  simplify calculations and allow to return standalone value structs for
  RGB and HSV
- named channel accessors
- implement HA color inputs / outputs
2021-02-26 18:44:12 +03:00
Maxim Prokhorov
65c8db72fb lights: fix rtcmem implementation shifts
ref. https://github.com/xoseperez/espurna/issues/2422#issuecomment-786171934

stop including mireds into the brightness when unpacking uint64 value
clamp brightness via the helper function
2021-02-26 18:34:06 +03:00
Maxim Prokhorov
7434ea3878 lights: finish up provider settings
get rid of LIGHT_CHANNELS, but keep channel setting for the my92xx
also clean up recent changes, channel command did not actually work
2021-02-10 20:05:13 +03:00
Maxim Prokhorov
00b470bc83 lights: always check for transformation flags
amend bdbd127bfb
2021-02-09 23:50:10 +03:00
Maxim Prokhorov
009021118b lights: fix my92xx build 2021-02-09 22:17:41 +03:00
Maxim Prokhorov
bdbd127bfb lights: handle value transformations in the transition 2021-02-09 22:06:41 +03:00
Maxim Prokhorov
ec5311c850 lights: terminal output specific values 2021-02-09 21:36:01 +03:00
Maxim Prokhorov
f6527e4325 lights: fix channel description, remove tags table from globals 2021-02-09 13:49:34 +03:00
Maxim Prokhorov
489813864e lights: match original rtcmem union layout 2021-02-09 13:48:47 +03:00
Maxim Prokhorov
ecaa5fa457 lights: explain the brightness stub and fix the gcc-4.8.2 build 2021-02-09 12:26:20 +03:00
Maxim Prokhorov
5c620723dd lights: one more try at fixing the boot sequence
Make sure 'custom provider' `lightAdd()` scheduled function locks further channel modifications,
and take care of light sanity checks before the light update is even scheduled.

Reworked rtcmem reader / writer to use default values, instead of accidentaly using
the unitialized mem of the stack. Also, reworked const names used by the lights module
to distinguish them from the build flags.
2021-02-08 21:39:46 +03:00
Maxim Prokhorov
af4477999d lights: allow to trigger an update when brightness is 0 2021-02-06 08:37:09 +03:00