7 Commits

2 changed files with 116 additions and 107 deletions

180
.gitignore vendored
View File

@@ -1,107 +1,111 @@
# ---> C
# Prerequisites
*.d
# Object files
.config
*.o
*.ko
*.obj
*.elf
*.pyc
# Linker output
*.ilk
*.map
*.exp
# gtags
GTAGS
GRTAGS
GPATH
# Precompiled Headers
*.gch
*.pch
# emacs
.dir-locals.el
# Libraries
*.lib
*.a
*.la
*.lo
# emacs temp file suffixes
*~
.#*
\#*#
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# eclipse setting
.settings
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# MacOS directory files
.DS_Store
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# cache dir
.cache/
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# Doc build artifacts
docs/_build/
docs/doxygen_sqlite3.db
# ---> C++
# Prerequisites
*.d
# Downloaded font files
docs/_static/DejaVuSans.ttf
docs/_static/NotoSansSC-Regular.otf
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Components Unit Test Apps files
components/**/build/
components/**/build_*_*/
components/**/sdkconfig
components/**/sdkconfig.old
# Precompiled Headers
*.gch
*.pch
# Example project files
examples/**/build/
examples/**/build_*_*/
examples/**/sdkconfig
examples/**/sdkconfig.old
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Unit test app files
tools/unit-test-app/build
tools/unit-test-app/build_*_*/
tools/unit-test-app/sdkconfig
tools/unit-test-app/sdkconfig.old
# Fortran module files
*.mod
*.smod
# test application build files
tools/test_apps/**/build/
tools/test_apps/**/build_*_*/
tools/test_apps/**/sdkconfig
tools/test_apps/**/sdkconfig.old
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
TEST_LOGS/
build_summary_*.xml
# Executables
*.exe
*.out
*.app
# gcov coverage reports
*.gcda
*.gcno
coverage.info
coverage_report/
# ---> CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
test_multi_heap_host
# Build directory
# VS Code Settings
.vscode/
# VIM files
*.swp
*.swo
# Sublime Text files
*.sublime-project
*.sublime-workspace
# Clion IDE CMake build & config
.idea/
cmake-build-*/
# Results for the checking of the Python coding style and static analysis
.mypy_cache
flake8_output.txt
# ESP-IDF default build directory name
build
# unity-app directory
unity-app
# lock files for examples and components
dependencies.lock
# managed_components for examples
managed_components
# pytest log
pytest-embedded/
# legacy one
pytest_embedded_log/
list_job*.txt
size_info*.txt
XUNIT_RESULT*.xml
.manifest_sha
# clang config (for LSP)
.clangd
# Vale
.vale/styles/*

View File

@@ -15,6 +15,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "esp_err.h"
#include "esp_check.h"
#include "esp_log.h"
#include "esp_task.h"
#include "driver/gpio.h"
@@ -279,7 +280,8 @@ static esp_err_t relay_chn_create_event_loop()
.task_core_id = tskNO_AFFINITY
};
esp_err_t ret = esp_event_loop_create(&loop_args, &relay_chn_event_loop);
ret |= esp_event_handler_register_with(relay_chn_event_loop,
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to create event loop for relay channel");
ret = esp_event_handler_register_with(relay_chn_event_loop,
RELAY_CHN_CMD_EVENT,
ESP_EVENT_ANY_ID,
relay_chn_event_handler, NULL);
@@ -320,14 +322,14 @@ esp_err_t relay_chn_create(const gpio_num_t* gpio_map, uint8_t gpio_count)
// Initialize the GPIOs
ret = gpio_reset_pin(forward_pin);
ret |= gpio_set_direction(forward_pin, GPIO_MODE_OUTPUT);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to reset GPIO forward pin for channel %d", i);
ret = gpio_set_direction(forward_pin, GPIO_MODE_OUTPUT);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set GPIO direction for forward pin for channel %d", i);
ret |= gpio_reset_pin(reverse_pin);
ret |= gpio_set_direction(reverse_pin, GPIO_MODE_OUTPUT);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize GPIOs relay channel %d!", i);
return ret;
}
ret = gpio_reset_pin(reverse_pin);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to reset GPIO reverse pin for channel %d", i);
ret = gpio_set_direction(reverse_pin, GPIO_MODE_OUTPUT);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set GPIO direction for reverse pin for channel %d", i);
// Initialize the GPIOs
// Initialize the relay channel
@@ -339,22 +341,22 @@ esp_err_t relay_chn_create(const gpio_num_t* gpio_map, uint8_t gpio_count)
relay_chn->state = RELAY_CHN_STATE_FREE;
relay_chn->pending_cmd = RELAY_CHN_CMD_NONE;
relay_chn->run_info.last_run_cmd = RELAY_CHN_CMD_NONE;
ret |= relay_chn_init_timer(relay_chn); // Create direction change inertia timer
ret = relay_chn_init_timer(relay_chn); // Create direction change inertia timer
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to create relay channel timer for channel %d", i);
#if RELAY_CHN_ENABLE_TILTING == 1
ret |= relay_chn_init_tilt_control(relay_chn);
ret = relay_chn_init_tilt_control(relay_chn);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to initialize tilt control for channel %d", i);
#endif
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialize relay channel %d!", i);
return ret;
}
}
// Create relay channel command event loop
ret |= relay_chn_create_event_loop();
ret = relay_chn_create_event_loop();
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to create relay channel event loop");
#if RELAY_CHN_ENABLE_TILTING == 1
// Must call after the event loop is initialized
ret |= relay_chn_tilt_init(); // Initialize tilt feature
ret = relay_chn_tilt_init(); // Initialize tilt feature
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to initialize tilt feature");
#endif
// Init the state listener manager
@@ -700,7 +702,8 @@ static esp_err_t relay_chn_output_stop(relay_chn_t *relay_chn)
{
esp_err_t ret;
ret = gpio_set_level(relay_chn->output.forward_pin, 0);
ret |= gpio_set_level(relay_chn->output.reverse_pin, 0);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set forward pin to LOW for relay channel #%d", relay_chn->id);
ret = gpio_set_level(relay_chn->output.reverse_pin, 0);
return ret;
}
@@ -708,7 +711,8 @@ static esp_err_t relay_chn_output_forward(relay_chn_t *relay_chn)
{
esp_err_t ret;
ret = gpio_set_level(relay_chn->output.forward_pin, 1);
ret |= gpio_set_level(relay_chn->output.reverse_pin, 0);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set forward pin to HIGH for relay channel #%d", relay_chn->id);
ret = gpio_set_level(relay_chn->output.reverse_pin, 0);
return ret;
}
@@ -716,7 +720,8 @@ static esp_err_t relay_chn_output_reverse(relay_chn_t *relay_chn)
{
esp_err_t ret;
ret = gpio_set_level(relay_chn->output.forward_pin, 0);
ret |= gpio_set_level(relay_chn->output.reverse_pin, 1);
ESP_RETURN_ON_ERROR(ret, TAG, "Failed to set forward pin to LOW for relay channel #%d", relay_chn->id);
ret = gpio_set_level(relay_chn->output.reverse_pin, 1);
return ret;
}