Commit Graph

24 Commits

Author SHA1 Message Date
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
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
bd3a588977 hardware: lightfox fixes & buttonAdd
Should be buildable once again

Restore the behaviour from #1468, where button clicks were triggered
Inject relay provider using the relayAdd, add buttonAdd to provide input handling

Remove extra button handling code from the WebUI

Still assuming that DUAL code really needs a syncronized way to handle
input & output with relays, so we can't treat it as a real button.
Without the device it is only guessing, and various issues / comments
are not really clear on that part :/
2021-06-09 11:20:07 +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
5a97329832 wifi: refactoring / rewrite
- replace JustWifi with a custom WiFi module
- re-implemented Core methods that deal with scanning, directly work with the SDK callback
- re-implemented Core method for opmode to avoid dealing with the 2.7.x pseudo modes
- re-implemented Core method for forced-(modem)-sleep (with the intention to merge with OpmodeNull... todo)
- disable reconnect and autoconnect from SDK, avoid unintentionally storing ssid & pass for these and
  make connection routine watch for events instead. timeout is implemented as a local timer
- do not store runtime data that can be retrieved via SDK calls
- settings are loaded only when starting AP or STA, networks are no longer kept in memory
- settings STA ssidN must be unique
- remove char buffer from the event callback
- trigger station-disconnected event when actually disconnected, not when connecting or explicitly requesting it
- generic rssi sorting method for initial connection, do rssi checks while connected to find a better network

Drop (temporarily?) wps and smartconfig. Both are implementable with the new approach,
but come with some weird expectations from the SDK side (no extra heap with wps, broadcasting plain-text
passphrase with smartconfig, storing station config implicitly, etc.).

Both are sort-of fixed with RTOS SDK, but it is still a big question of whether to support them at all in the current state.
2021-03-31 09:41:05 +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
0f723b0248 settings: handle old keys in the respective modules
fixes #2419
2021-02-06 04:44:26 +03:00
Maxim Prokhorov
c4f0ceb1ae sys: refactor custom reset codes 2021-01-23 21:28:01 +03:00
Maxim Prokhorov
972188c83b fan: common types and actions
update custom action callback to also get the event
buttons fan actions
ifan buttons are handled through action instead of manually
fan settings and api are (sort-of) generic
2021-01-19 23:30:12 +03:00
Maxim Prokhorov
ef194c9c24 button: custom action + ifan fixes 2021-01-14 15:24:08 +03:00
Max Prokhorov
8ceeebdb24 providers: relays, lights and buttons refactoring (#2414)
- gpio module now tracks the known providers (right now, hardware and mcp expander)
- refactored relay struct to use 'Provider' implementing setup,notify,change,boot instead of just BasePin actions
- refactored button module to use gpio provider instead of referencing types itself
- removed dual & stm code from buttons, migrate both to relay module
- added status notify and change callbacks for relayStatus (i.e. 'notify' when relay status was called, but not changed. and 'changed' when it did)  
- relays runtime configuration keys
- relay command now shows configured relays and current & target statuses
- refactor the code using relayStatus(0, blah) under LIGHT_PROVIDER check to use lightState instead
- remove rfbridge code form relay module. implement through a basic state listener in the rfbridge module, depend on RELAY_SUPPORT
- allow to bind rf codes to real relays
- drop tuya-specific lights provider, remove tuya code from relays and lights modules
- integrate tuya via relay listeners and providers, use lights custom provider
- implement channel transitions for tuya. disabled by default, and transition time and step are overridden to 2000 + 100. needs to be set to some value below the total time (i.e. `total transition time / step time == number of steps`, we need to figure out a correct time that serial comms could handle)
- lights custom provider (global, not per-pin) and state listeners
- remove lights code from relay module. implement through providers & listeners in the lights module, depend on RELAY_SUPPORT
- lights per-channel relay provider (unused atm), depend on RELAY_SUPPORT
- refactored channel transition - calculate step only once, make sure time + step values are sane, generate quick transitions with very small delay (10ms hardcoded) for transitions during OFF state i.e. we no longer waste 500ms (or whatever transition time is set to) on boot doing nothing
- transition time + step parameter for the lightUpdate
- report mask parameter for the lightUpdate
- minor fixes across the board

resolve #2222
2021-01-14 10:39:18 +03:00
Maxim Prokhorov
f497312f29 btn: option to read default value on initialization
- provide a generic way to read default status of the pin after boot
  allows us to use switch as both on and off, independent of the position on boot
- add BUTTON_DEFAULT_LOW & BUTTON_DEFAULT_BOOT (now it's not just BUTTON_DEFAULT_HIGH)
  wiki described raw numbers for some reason :/ this will break that
- clean-up 'constexpr const' and 'const' function args, both are redundant
- clean-up debounce event member defaults, put things in the header
2020-11-16 03:31:24 +03:00
Max Prokhorov
7a64a4a6bf btn: generate pressed & released events from switch changes (#2379)
- Add ::Released button event to be used specifically with switches, opposite of ::Pressed
- Always use default state for switches instead of ignoring it and using current pin reading as value. This allows us to boot with the switch held in the opposite state and trigger the correct event immediately
(meaning, switches now depend on the BUTTON_DEFAULT_HIGH presence to detect the default position)
- BREAKING: Fixup hardware.h. Any custom board needs manual changes.
- BREAKING: Rework MQTT button messages to send text from debug messages instead of numeric code
2020-10-15 19:55:23 +03:00
Maxim Prokhorov
63b6f46752 Fix superfluous whitespaces and line endings
resolve #2310
2020-09-30 10:14:25 +03:00
Max Prokhorov
c7a95bf53f buttons: resistor ladder / analog buttons support (#2357)
- Buttons events source as button property instead of a global one
- Rename events source -> provider for all settings, consistent with the other things like relay and light providers
- AnalogPin to read between a certain analogRead() range
Trying to follow defaults here - analog 'press' is digital LOW, default value is HIGH, so no additional cfg entries are needed besides pin, level and changing evt source
- (debug) Refactor gpio command, add adc to show analogRead(pin)
- (debug) Add button command

Implemented based on:
https://gitter.im/tinkerman-cat/espurna?at=5f5d44c8df4af236f902e25d
https://gitter.im/tinkerman-cat/espurna?at=5f60e7f1f969413294e95370
2020-09-24 07:51:36 +03:00
Maxim Prokhorov
436827eb90 relay: fix building with rfbridge provider 2020-07-16 22:59:13 +03:00
dpeddi
547f52fe79 hw: Implement support for ProDino WIFI (#2269)
- implement mcp23s08
- support mcp pins in relays and buttons
- add hardware profile for ProDino WiFi

Co-authored-by: dpeddi <dpeddi@gmail.com>
Co-authored-by: Maxim Prokhorov <prokhorov.max@outlook.com>
2020-07-16 05:15:34 +03:00
Max Prokhorov
84b51cf680 broker: declare and define per module (#2253)
* broker: declare and define per module

We no longer need to specify each Broker type in broker.h
But, we exchange that bit for explicit initialization of the instance

Define helper macros to generate boilerplate code
- namespace with Instance, Register(), Publish()
- forward Register(...) -> Instance.Register(...),
  Publish(...) -> Instance.Publish(...)

* don't check for broker when deps enable it
2020-05-18 02:29:17 +03:00
Max Prokhorov
025e8c82ab Load ratios after boot + show pwr defaults with get (#2241)
* emon: configure ratios without reboot

* settings: serialize() support

* debug: use vsnprintf from newlib, not from sdk

* settings/experimental: show defaults via `get`

* emon: override base methods, fix defaults

* sensor/emon: expose internal index calculation

- refactor configuration to use the correct index when accessing indexed
  sensor methods. store index value on magnitude, refactor loops to
  accomodate this new functionality
- rename slot(index) -> description(index), since we use 'slot' as
  numeric value
2020-05-12 21:17:01 +03:00
Max Prokhorov
e60c561f70 Actually apply button pulldown
Properly follow ternary else() chain, help out by pre-pending if()
Resolve #2239, thanks to @sigmafx
2020-05-01 21:54:53 +03:00
Max Prokhorov
edb23dbfc4 Convert .ino -> .cpp (#2228)
- general conversion from .ino modules into a separate .cpp files
- clean-up internal headers, place libraries into .h. guard .cpp with _SUPPORT flags 
- fix some instances of shared variables instead of public methods
- tweak build system to still build a single source file via os environment variable ESPURNA_BUILD_SINGLE_SOURCE
2020-04-30 13:55:07 +03:00