Commit Graph

139 Commits

Author SHA1 Message Date
e30b445b91 Fix channel validity check
Fixed mistaken channel validity check in `tilt_stop` funciton
in multi mode. Refs #1111 and fixes #1114.
2025-09-11 14:21:24 +03:00
9ee974e677 Add a single channel example
Added a single channel example with run limit and tilting
features. Refs #1104 and closes #1105.
2025-09-09 18:15:32 +03:00
31e351a129 Fix tilting opposite direction when running
Fixed TILT_STOP command issuing chain that was causing a running channel
to be stopped when an opposite direction tilting requested. For exeample:
RUN_FORWARD > TILT_REVERSE. Refs #1105 and fixes #1110.
2025-09-09 17:50:02 +03:00
3ce079c2e8 Fix unwanted reverse tilts
Added a helper function to determine if the channel may perform
the requested tilt command. Refs #1105 and fixes #1109.
2025-09-09 17:09:08 +03:00
a5b320c152 Add state to string API function
Added a state to string public API function. There was already
a private function (`relay_chn_state_str`) that provides
this functionality. So this function has been renamed to
`relay_chn_state_to_str` and made publicly available.

Refs #1104, #1105 and closes #1108.
2025-09-09 10:53:56 +03:00
087deb338e Fix STOP command issuing when idle
Fixed almost unconditional STOP command issuing when the
channel is idle. Refs #1104, #1105 and closes #1107.
2025-09-09 09:26:24 +03:00
fbf8b5dfc8 Fix mispelled config parameter
Fixed a mispelled configuration parameter. Refs #1105
2025-09-09 09:14:28 +03:00
a3f83eaaee Merge pull request 'opt/1085-optimization-and-cleanup' (!37) from opt/1085-optimization-and-cleanup into dev
Reviewed-on: #37
2025-09-05 11:05:41 +03:00
61ca2197e1 Fix conditional compilation issues.
Fixed include directory settings and conditional includes in CMakeLists and test_common.c. Refs #1085.
2025-09-04 18:23:05 +03:00
86cc29a33b Fix static variable names
Fixed static variable names according to the ESP-IDF C code formatting guide.

Refs #1085 and fixes #1103
2025-09-04 18:20:51 +03:00
bf5e3a4426 General code and comment cleanup 2025-09-04 16:59:00 +03:00
7244b57061 Add SPDX license headers to multiple source files
Refs #1085 and closes #1099
2025-09-04 16:23:13 +03:00
7bafc4845f Add default tilt sensitivity get function
Added `relay_chn_tilt_get_default_sensitivity` function and test cases.

Refs #1085 and fixes #1101
2025-09-04 16:16:10 +03:00
ad377ebfc8 Fix the operation of unregistering listener
- Add check for empty listener list in find_listener_entry function.
- Reset notification queue when all listeners are removed.
- Change queue operation to send remove_listener message to the front of the queue.

Refs #1085, #1096 and fixes #1102
2025-09-04 15:46:57 +03:00
a1a54e2ca0 Stop tracking auto generated sdkconfig file 2025-09-04 15:44:26 +03:00
639533cbb6 Refactor and improve unit tests
- Refactored and improved NVS tests to accomodate latest changes in NVS module. See #1098
- Improved channel reset function that is called from `tearDown` to minimize public API calls that trigger a chain of internal calls that involve NVS and timer operations.
- Fixed test case bugs that make some test cases to fail.

Refs #1096, #1098
2025-09-04 15:06:17 +03:00
2c9ee40ff4 Enhance NVS module with a dedicated background task
- Implemented a dedicated background task to decouple long-running code from the main application task.
- Improved the NVS commit code logic, especially for batch writes to minimize flash wear.
- Updated NVS functions to support asynchronous writes and synchronous reads.
- Added default value parameters to `get` functions for better usability.
- Improved error handling and logging in NVS operations.
- Refactored related code in multiple source files to accommodate these changes.

Refs #1085, #1096 and closes #1098
2025-09-04 14:50:38 +03:00
0122ef0803 Fix NVS key bug and optimize for single mode
- Fixed a critical NVS key generation bug that would cause overwriting the values for all channels.
- Optimized the code for single channel mode since no formatting required.
- Improved multi-channel test coverage to cover that each value for each channel stored correctly.

Refs #1096, #1098 and fixes #1100
2025-09-02 17:02:05 +03:00
5e8e5a4cab Add notification system for relay channel state changes
- Introduced a new notification module to handle state change listeners.
- Added functions to register and unregister listeners for relay channel state changes.
- Implemented a queue-based system to manage notifications and listener callbacks.
- Updated core relay channel logic to utilize the new notification system.
- Removed old listener management code from relay channel core.
- Refactored the former listener tests to notify tests and added tests for the notification system, including handling of multiple listeners and queue overflow scenarios.
- Updated CMakeLists.txt to include new source files and headers for the notification module.
- Revised README.md to include warnings about callback execution context and performance considerations.

Refs #1096, #1085 and closes #1097
2025-09-02 15:46:48 +03:00
d2b38a5b4e Ignore autogenerated sdkconfig file 2025-09-02 15:31:53 +03:00
db55c0b7e4 Fix single channel tests in multi mode tests
Some test cases that were testing for only one channel in multi-channel mode are fixed to test all available channels. Fixes #1094
2025-08-29 17:41:42 +03:00
dea9f1e986 Add missing test tags 2025-08-29 14:10:18 +03:00
a2e8e3c120 Implement relay_chn_stop_prv function
Implemented `relay_chn_stop_prv` to streamline stop command handling
and avoid unnecessary code execution. Fixes #1095.
2025-08-28 17:43:14 +03:00
a6d38327b7 Add test cases for *all and *all_with functions
Added test cases for the recently implemented `*all` and `*all_with`
functions. Closes #1089.
2025-08-28 09:34:19 +03:00
0cd6b4e263 Refactor and enhance reset_channels_to_idle_state
- Refactor reset_channels_to_idle_state to reset_channels_to_defaults
and enhance functionality with direction reset logic. This is because
some tilt test cases were failing due to modified run limit values in some
of the previous core test cases. See #1089-3.
- A relay channel listener has been added to diagnose channel
states during tests.

Refs #1089
2025-08-28 09:30:43 +03:00
ec1b25d489 Add missing test cases
Some missing test cases for the public API have been added.

Closes #1090
2025-08-27 17:26:32 +03:00
4eb1bb03a0 Fix function call
Refs #1090
2025-08-27 17:16:06 +03:00
7d597f3725 Fix STOP command does not interrupt
An if statement has been added to handle the STOP command properly
when the `previous_state` is one of the `*PENDING` states.

Fixes #1093
2025-08-27 17:02:02 +03:00
71b632737e Fix esp_timer_start error handling
A helper function added for each module so that each module
handles errors by itself.

Fixes #1092
2025-08-27 15:56:24 +03:00
374647732c Fix possible integer underflow bug
Fixed a possible integer underflow bug that may cause the timer
to be set for an unexpectedly long duration.

Fixes #1091
2025-08-27 14:06:37 +03:00
ae33204a87 Optimize internal stop calls for output errors 2025-08-27 11:03:55 +03:00
79a66c19d7 Rename time_sec to limit_sec in relay channel functions for clarity
Fixes #1087
2025-08-26 18:08:05 +03:00
9a6b8c9f80 Add upper boundary checks for tilt sensitivity settings
The tilt sensitivity values were passed to the NVS module without
the boundaries being checked, even though the maximum
percent value is 100. This commit fixes this issue.
Also test cases are added to cover the upper boundary checks
for the tilt sensitivity settings.

Fixes #1086
2025-08-26 17:43:19 +03:00
0b75df35d1 Use build profiles instead of providing sdkconfig.defaults manually
ESP-IDF provides a more efficient way of handling and combining
multi-configurations for a project than the way currently used:
Build profiles.

So I switched to this method instead of providing the sdkconfig.defaults.*
files manually. This reduced the number of sdkconfig.defaults.* files
as well as the configuration parameters defined in them.

Refs #1085
2025-08-26 17:03:36 +03:00
da953846c9 Refactor function brackets
Refactor the brackets of the test case functions to align with ESP-IDF style.

Refs #1085
2025-08-26 15:19:09 +03:00
15d1673e77 Refactor and improve for batch operations
Refactor tilt test functions to use batch operations for all channels and improve state checks.

Refs #1085
2025-08-26 15:03:16 +03:00
329812aecc Enhance relay command handling
- `TILT_STOP` command is prioritized in `relay_chn_tilt_issue_cmd()` because it should override any other tilt commands.
- The debug logs are cleaned up.

Fixes #1088
Refs #1085
2025-08-26 13:37:48 +03:00
54c8dc26fc Add .ESP-IDF vscode configuration files 2025-08-26 12:10:02 +03:00
396a02b5ae Cleanup and replace constants
- Delete unused declaration of `g_is_component_initialized`.
- Replace the following constants with approprite config options:
  + `relay_chn_count` > `CONFIG_RELAY_CHN_COUNT`
  + `opposite_inerta_ms` > `CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS`
- Replace the definition of the `test_delay_margin_ms` constant with  `#define TEST_DELAY_MARGIN_MS 50` for preprocessor calculations.
2025-08-26 09:23:06 +03:00
3831384169 Implement specific *all functions
Specific `_*all` and `_*all_with` functions were implemented to make
the API more concise and clean, and to replace the use of
`RELAY_CHN_ID_ALL`, which caused confusion within the API.

Refs #1085
2025-08-26 08:42:49 +03:00
be4a2ebef6 Fix build path 2025-08-25 18:24:37 +03:00
6ff16b5797 Fix config parameters check
Unnecessary `#if CONFIG_FOO == 1` checks were removed and the
statements were simplified to` #if CONFIG_FOO`.
`#ifdef CONFIG_FOO` statements were also changed to `#if CONFIG_FOO`
to keep the style as uniform as possible.

Refs #1085
2025-08-25 10:56:01 +03:00
5afefc4dc0 Use original names for config parameters
The config parameter names defined in the relay_chn_defs.h file
have been changed back to their original names (with the CONFIG_ prefix),
so that they are not confused with application-level defines.

Refs #1085
2025-08-25 10:24:13 +03:00
9d3f8ddbff Fix implicit-fallthrough warning.
Refs #1085.
2025-08-25 09:40:18 +03:00
6a4872f194 Merge pull request 'feat/1080-run-limit' (!36) from feat/1080-run-limit into dev
Reviewed-on: #36
2025-08-22 17:56:22 +03:00
cb38f71d8e Optimize a flip test case and execute tests upon removing esp_event 2025-08-22 17:42:24 +03:00
7a0f9b1420 Optimize timer callbacks
It turned out that esp_event was adding extra complexity to the code base and it was completely unnecessary. So it has been removed from the component completely. The actions are now executed directly in the `relay_chn_distpacth_cmd()` and `relay_chn_tilt_dispatch_cmd()` functions.
This change has simplified the component as well as reduced the memory footprint.

Fixes #1084, refs #1083
2025-08-22 17:41:08 +03:00
e73c205e3d Optimize event loop resource size
The event loop queue and  task stack size is optimized to be determined by config factors.

Fixes #1083
2025-08-22 15:33:12 +03:00
fb4f34e895 Add and execute unit tests for run limit feature 2025-08-22 12:42:53 +03:00
29803c063e Enhance unit test default sdkconfig files
The sdkconfig.defaults files were enhanced to test the component against all individual configurations for more granularity, as well as with all combinations to ensure consistency and integrity across all configurations.
2025-08-22 12:41:58 +03:00