Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
864be4475c | ||
|
|
f0c611c5c8 | ||
|
|
74e449a214 | ||
|
|
e8e32b8993 | ||
|
|
be80536843 | ||
|
|
6494380cb5 | ||
|
|
1afcb24daf | ||
|
|
c884a61f6e | ||
|
|
b57a9eac15 | ||
|
|
2a7b9e17bc | ||
|
|
3bfbcc7779 | ||
|
|
1f319b33f8 |
No files matched your search
@@ -0,0 +1,7 @@
|
||||
.DS_Store
|
||||
.vscode
|
||||
build
|
||||
managed_components
|
||||
dependencies.lock
|
||||
sdkconfig.old
|
||||
sdkconfig
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(zh_sim_race_button_box)
|
||||
@@ -0,0 +1,73 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
idf_component_register(SRCS "zh_sim_race_button_box.c" INCLUDE_DIRS "" REQUIRES zh_160x_i2c zh_encoder zh_ota_server zh_menu zh_aht esp_wifi nvs_flash)
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
description: In progress
|
||||
url: https://github.com/aZholtikov/zh_sim_race_button_box
|
||||
version: "1.0.0"
|
||||
license: "Apache-2.0"
|
||||
maintainers:
|
||||
- "Alexey Zholtikov <alexey.zholtikov@yandex.ru>"
|
||||
dependencies:
|
||||
idf: ">=5.0"
|
||||
zh_160x_i2c:
|
||||
git: "https://github.com/aZholtikov/zh_160x_i2c.git"
|
||||
zh_ota_server:
|
||||
git: "https://github.com/aZholtikov/zh_ota_server.git"
|
||||
zh_encoder:
|
||||
git: "https://github.com/aZholtikov/zh_encoder.git"
|
||||
zh_menu:
|
||||
git: "https://github.com/aZholtikov/zh_menu.git"
|
||||
zh_aht:
|
||||
git: "https://github.com/aZholtikov/zh_aht.git"
|
||||
Executable
+702
@@ -0,0 +1,702 @@
|
||||
#include "zh_sim_race_button_box.h"
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#define VALUE_CLAMP(v, lo, hi) ((v) < (lo) ? (lo) : ((v) > (hi) ? (hi) : (v)))
|
||||
#define CLEAR_ROW_CACHE() memset(_row_valid, 0, sizeof(_row_valid))
|
||||
|
||||
#define LABEL_BOOT_SCREEN "Boot: "
|
||||
#define LABEL_MAIN_SCREEN "Main: "
|
||||
#define LABEL_AIR_CONDITION_TEMP_ON "Temp ON: "
|
||||
#define LABEL_AIR_CONDITION_TEMP_OFF "Temp OFF: "
|
||||
#define LABEL_EXIT_CHANNEL_1_POWER "PW CH 1: "
|
||||
#define LABEL_EXIT_CHANNEL_2_POWER "PW CH 2: "
|
||||
#define LABEL_EXIT_CHANNEL_3_POWER "PW CH 3: "
|
||||
#define LABEL_EXIT_CHANNEL_4_POWER "PW CH 4: "
|
||||
#define LABEL_BULB_BRIGHTNESS "PW BULB: "
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t air_condition_temp_on;
|
||||
uint8_t air_condition_temp_off;
|
||||
uint8_t exit_channel_power[4];
|
||||
uint8_t bulb_brightness;
|
||||
uint8_t boot_screen_number;
|
||||
uint8_t main_screen_number;
|
||||
} _zh_nvs_setting_data_blob_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
const char *const lines[LCD_TOTAL_ROWS];
|
||||
char *values[LCD_TOTAL_ROWS];
|
||||
} _zh_main_screen_description_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
const char *const lines[LCD_TOTAL_ROWS];
|
||||
} _zh_boot_screen_description_t;
|
||||
|
||||
static httpd_handle_t _http_server_handle = NULL;
|
||||
static zh_encoder_handle_t *_mode_encoder_handle = NULL;
|
||||
static zh_menu_handle_t *_menu_handle = NULL;
|
||||
// static zh_pcf8574_handle_t *_button_handle = NULL;
|
||||
static zh_pcf8574_handle_t *_lcd_handle = NULL;
|
||||
static zh_160x_i2c_handle_t *_lcd_160x_handle = NULL;
|
||||
static zh_aht_handle_t *_aht_handle = NULL;
|
||||
static TaskHandle_t _stats_task_handle = NULL;
|
||||
static TaskHandle_t _aht_task_handle = NULL;
|
||||
|
||||
static void _zh_load_settings(void);
|
||||
static void _zh_save_settings(void);
|
||||
static void _zh_wifi_init(void);
|
||||
static void _zh_webserver_init(void);
|
||||
static void _zh_encoder_init(void);
|
||||
static void _zh_pcf8574_init(void);
|
||||
static void _zh_menu_init(void);
|
||||
static void _zh_aht_init(void);
|
||||
static void _zh_system_load(void);
|
||||
static void _zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
|
||||
static void _zh_stats_processing_task(void *pvParameter);
|
||||
static void _zh_aht_processing_task(void *pvParameter);
|
||||
static void _zh_menu_enter_main_menu_callback(void *arg);
|
||||
static void _zh_menu_exit_main_menu_callback(void *arg);
|
||||
static void _zh_menu_change_menu_callback(zh_menu_node_t *current_node, uint8_t current_index);
|
||||
static void _zh_menu_selectable_item_callback(void *arg);
|
||||
static void _zh_menu_back_command_callback(void *arg);
|
||||
static void _zh_menu_boot_screen_callback(void *arg);
|
||||
static void _zh_menu_main_screen_callback(void *arg);
|
||||
static void _zh_draw_main_screen(void);
|
||||
static void _zh_draw_boot_screen(void);
|
||||
static void _zh_draw_main_menu(zh_menu_node_t *current_node, uint8_t current_index, const zh_menu_status_t *status);
|
||||
|
||||
static const _zh_boot_screen_description_t _boot_screens[] = {
|
||||
{"Boot", {"Booting...", "RAM: OK", "I2C: OK", "Starting..."}},
|
||||
{"Version", {"FW v1.0", "Build 2025-10", "ESP-IDF v5.4", ""}},
|
||||
{"Diag", {"I2C: OK", "LCD: OK", "ENC: OK", "All: OK"}},
|
||||
{"Ready", {"System ready", "Ready for race", "Let's go", ""}},
|
||||
{"Blank", {"---", "---", "---", "---"}},
|
||||
};
|
||||
|
||||
static char _cabin_temperature_status[5] = "";
|
||||
static char _cabin_humidity_status[5] = "";
|
||||
static char _air_condition_status[5] = "AUTO";
|
||||
static char _side_light_status[5] = "ON";
|
||||
static char _flash_light_status[5] = "OFF";
|
||||
|
||||
static _zh_main_screen_description_t _main_screens[] = {
|
||||
{"Race", {"CABIN TEMP:", "AIR COND:", "SIDE LT:", "FLASH LT:"}, {_cabin_temperature_status, _air_condition_status, _side_light_status, _flash_light_status}},
|
||||
{"Test", {"Temperature:", "Humidity:", "Lights:", "Strobe:"}, {_cabin_temperature_status, _cabin_humidity_status, _side_light_status, _flash_light_status}},
|
||||
};
|
||||
|
||||
static char _label_boot_screen[LCD_TOTAL_COLS + 1] = LABEL_BOOT_SCREEN;
|
||||
static char _label_main_screen[LCD_TOTAL_COLS + 1] = LABEL_MAIN_SCREEN;
|
||||
static char _label_air_condition_temp_on[LCD_TOTAL_COLS + 1] = LABEL_AIR_CONDITION_TEMP_ON;
|
||||
static char _label_air_condition_temp_off[LCD_TOTAL_COLS + 1] = LABEL_AIR_CONDITION_TEMP_OFF;
|
||||
static char _label_exit_channel_1_power[LCD_TOTAL_COLS + 1] = LABEL_EXIT_CHANNEL_1_POWER;
|
||||
static char _label_exit_channel_2_power[LCD_TOTAL_COLS + 1] = LABEL_EXIT_CHANNEL_2_POWER;
|
||||
static char _label_exit_channel_3_power[LCD_TOTAL_COLS + 1] = LABEL_EXIT_CHANNEL_3_POWER;
|
||||
static char _label_exit_channel_4_power[LCD_TOTAL_COLS + 1] = LABEL_EXIT_CHANNEL_4_POWER;
|
||||
static char _label_bulb_brightness[LCD_TOTAL_COLS + 1] = LABEL_BULB_BRIGHTNESS;
|
||||
|
||||
static zh_menu_node_t _main_menu = {
|
||||
.label = "Settings",
|
||||
.submenu = (zh_menu_node_t[]){
|
||||
{.label = "Screens", .submenu = (zh_menu_node_t[]){
|
||||
{.label = _label_boot_screen, .item_cb = &_zh_menu_boot_screen_callback, .selectable = true},
|
||||
{.label = _label_main_screen, .item_cb = &_zh_menu_main_screen_callback, .selectable = true},
|
||||
{.label = "Back", .item_cb = &_zh_menu_back_command_callback},
|
||||
},
|
||||
.item_numbers = 3},
|
||||
{.label = "Air condition", .submenu = (zh_menu_node_t[]){
|
||||
{.label = _label_air_condition_temp_on, .item_cb = &_zh_menu_selectable_item_callback, .selectable = true},
|
||||
{.label = _label_air_condition_temp_off, .item_cb = &_zh_menu_selectable_item_callback, .selectable = true},
|
||||
{.label = "Back", .item_cb = &_zh_menu_back_command_callback},
|
||||
},
|
||||
.item_numbers = 3},
|
||||
{.label = "Lights", .submenu = (zh_menu_node_t[]){
|
||||
{.label = _label_exit_channel_1_power, .item_cb = &_zh_menu_selectable_item_callback, .selectable = true},
|
||||
{.label = _label_exit_channel_2_power, .item_cb = &_zh_menu_selectable_item_callback, .selectable = true},
|
||||
{.label = _label_exit_channel_3_power, .item_cb = &_zh_menu_selectable_item_callback, .selectable = true},
|
||||
{.label = _label_exit_channel_4_power, .item_cb = &_zh_menu_selectable_item_callback, .selectable = true},
|
||||
{.label = _label_bulb_brightness, .item_cb = &_zh_menu_selectable_item_callback, .selectable = true},
|
||||
{.label = "Back", .item_cb = &_zh_menu_back_command_callback},
|
||||
},
|
||||
.item_numbers = 6},
|
||||
{.label = "Exit", .item_cb = &_zh_menu_back_command_callback},
|
||||
},
|
||||
.item_numbers = 4,
|
||||
};
|
||||
|
||||
static zh_menu_node_t *_last_node = NULL;
|
||||
static uint8_t _last_index = 0;
|
||||
static zh_menu_node_t *_cached_node = NULL;
|
||||
static bool _prev_selected = false;
|
||||
static char _row_cache[LCD_TOTAL_ROWS][LCD_TOTAL_COLS] = {0};
|
||||
static bool _row_valid[LCD_TOTAL_ROWS] = {0};
|
||||
volatile static uint8_t _air_condition_temp_on = 30;
|
||||
volatile static uint8_t _air_condition_temp_off = 15;
|
||||
volatile static uint8_t _exit_channel_power[4] = {100, 100, 100, 100};
|
||||
volatile static uint8_t _bulb_brightness = 100;
|
||||
volatile static uint8_t _boot_screen_number = 0;
|
||||
volatile static uint8_t _main_screen_number = 0;
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
}
|
||||
esp_event_loop_create_default();
|
||||
_zh_load_settings();
|
||||
_zh_pcf8574_init();
|
||||
_zh_aht_init();
|
||||
_zh_encoder_init();
|
||||
_zh_menu_init();
|
||||
_zh_wifi_init();
|
||||
_zh_webserver_init();
|
||||
_zh_system_load();
|
||||
const esp_partition_t *running = esp_ota_get_running_partition();
|
||||
esp_ota_img_states_t ota_state = {0};
|
||||
esp_ota_get_state_partition(running, &ota_state);
|
||||
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY)
|
||||
{
|
||||
vTaskDelay(60000 / portTICK_PERIOD_MS);
|
||||
esp_ota_mark_app_valid_cancel_rollback();
|
||||
}
|
||||
}
|
||||
|
||||
static void _zh_load_settings(void)
|
||||
{
|
||||
nvs_handle_t nvs;
|
||||
if (nvs_open(NVS_NAMESPACE, NVS_READONLY, &nvs) != ESP_OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_zh_nvs_setting_data_blob_t setting_data_blob = {0};
|
||||
size_t size = sizeof(setting_data_blob);
|
||||
if (nvs_get_blob(nvs, NVS_KEY_SETTINGS, &setting_data_blob, &size) != ESP_OK)
|
||||
{
|
||||
nvs_close(nvs);
|
||||
return;
|
||||
}
|
||||
nvs_close(nvs);
|
||||
_air_condition_temp_on = setting_data_blob.air_condition_temp_on;
|
||||
_air_condition_temp_off = setting_data_blob.air_condition_temp_off;
|
||||
_exit_channel_power[0] = setting_data_blob.exit_channel_power[0];
|
||||
_exit_channel_power[1] = setting_data_blob.exit_channel_power[1];
|
||||
_exit_channel_power[2] = setting_data_blob.exit_channel_power[2];
|
||||
_exit_channel_power[3] = setting_data_blob.exit_channel_power[3];
|
||||
_bulb_brightness = setting_data_blob.bulb_brightness;
|
||||
_boot_screen_number = VALUE_CLAMP(setting_data_blob.boot_screen_number, 0, ARRAY_SIZE(_boot_screens) - 1);
|
||||
_main_screen_number = VALUE_CLAMP(setting_data_blob.main_screen_number, 0, ARRAY_SIZE(_main_screens) - 1);
|
||||
}
|
||||
|
||||
static void _zh_save_settings(void)
|
||||
{
|
||||
nvs_handle_t nvs = 0;
|
||||
if (nvs_open(NVS_NAMESPACE, NVS_READWRITE, &nvs) != ESP_OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_zh_nvs_setting_data_blob_t setting_data_blob = {0};
|
||||
setting_data_blob.air_condition_temp_on = _air_condition_temp_on;
|
||||
setting_data_blob.air_condition_temp_off = _air_condition_temp_off;
|
||||
setting_data_blob.exit_channel_power[0] = _exit_channel_power[0];
|
||||
setting_data_blob.exit_channel_power[1] = _exit_channel_power[1];
|
||||
setting_data_blob.exit_channel_power[2] = _exit_channel_power[2];
|
||||
setting_data_blob.exit_channel_power[3] = _exit_channel_power[3];
|
||||
setting_data_blob.bulb_brightness = _bulb_brightness;
|
||||
setting_data_blob.boot_screen_number = _boot_screen_number;
|
||||
setting_data_blob.main_screen_number = _main_screen_number;
|
||||
nvs_set_blob(nvs, NVS_KEY_SETTINGS, &setting_data_blob, sizeof(setting_data_blob));
|
||||
nvs_commit(nvs);
|
||||
nvs_close(nvs);
|
||||
}
|
||||
|
||||
static void _zh_wifi_init(void)
|
||||
{
|
||||
esp_netif_init();
|
||||
esp_netif_create_default_wifi_ap();
|
||||
wifi_init_config_t wifi_config = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_wifi_init(&wifi_config);
|
||||
wifi_config_t ap_config = {
|
||||
.ap = {
|
||||
.ssid = WIFI_AP_SSID,
|
||||
.password = WIFI_AP_PASS,
|
||||
.max_connection = MAX_AP_CONNECTION,
|
||||
.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
.channel = WIFI_AP_CHANNEL,
|
||||
},
|
||||
};
|
||||
esp_wifi_set_mode(WIFI_MODE_AP);
|
||||
esp_wifi_set_config(WIFI_IF_AP, &ap_config);
|
||||
esp_wifi_start();
|
||||
}
|
||||
|
||||
static void _zh_webserver_init(void)
|
||||
{
|
||||
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
||||
httpd_start(&_http_server_handle, &config);
|
||||
zh_ota_server_init(_http_server_handle, "/");
|
||||
}
|
||||
|
||||
static void _zh_encoder_init(void)
|
||||
{
|
||||
esp_event_handler_instance_register(ZH_ENCODER, ESP_EVENT_ANY_ID, &_zh_encoder_event_handler, NULL, NULL);
|
||||
zh_encoder_init_config_t config = ZH_ENCODER_INIT_CONFIG_DEFAULT();
|
||||
config.task_priority = ENCODER_TASK_PRIORITY;
|
||||
config.stack_size = ENCODER_TASK_STACK_SIZE;
|
||||
config.queue_size = ENCODER_QUEUE_SIZE;
|
||||
config.a_gpio_number = MODE_ENCODER_A_GPIO;
|
||||
config.b_gpio_number = MODE_ENCODER_B_GPIO;
|
||||
config.s_gpio_number = MODE_ENCODER_S_GPIO;
|
||||
config.encoder_min_value = -1000000;
|
||||
config.encoder_max_value = 1000000;
|
||||
config.encoder_step = 1;
|
||||
config.encoder_number = MODE_ENCODER_NUMBER;
|
||||
zh_encoder_init(&config, &_mode_encoder_handle);
|
||||
}
|
||||
|
||||
static void _zh_pcf8574_init(void)
|
||||
{
|
||||
i2c_master_bus_handle_t i2c_bus_handle = NULL;
|
||||
i2c_master_bus_config_t i2c_bus_config = {
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.i2c_port = -1,
|
||||
.scl_io_num = EXPANDERS_I2C_SCL_GPIO,
|
||||
.sda_io_num = EXPANDERS_I2C_SDA_GPIO,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.flags.enable_internal_pullup = true,
|
||||
};
|
||||
i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle);
|
||||
esp_event_handler_instance_register(ZH_PCF8574, ESP_EVENT_ANY_ID, &_zh_pcf8574_event_handler, NULL, NULL);
|
||||
zh_pcf8574_init_config_t config = ZH_PCF8574_INIT_CONFIG_DEFAULT();
|
||||
config.task_priority = EXPANDER_TASK_PRIORITY;
|
||||
config.stack_size = EXPANDER_TASK_STACK_SIZE;
|
||||
config.i2c_handle = i2c_bus_handle;
|
||||
config.i2c_address = LCD_I2C_ADDRESS;
|
||||
zh_pcf8574_init(&config, &_lcd_handle);
|
||||
zh_160x_init(&_lcd_handle, &_lcd_160x_handle, ZH_LCD_16X4);
|
||||
// config.p0_gpio_work_mode = ZH_PCF8574_GPIO_INPUT;
|
||||
// config.p1_gpio_work_mode = ZH_PCF8574_GPIO_INPUT;
|
||||
// config.p2_gpio_work_mode = ZH_PCF8574_GPIO_INPUT;
|
||||
// config.p3_gpio_work_mode = ZH_PCF8574_GPIO_INPUT;
|
||||
// config.p4_gpio_work_mode = ZH_PCF8574_GPIO_INPUT;
|
||||
// config.interrupt_gpio = EXPANDERS_INT_GPIO;
|
||||
// config.i2c_address = BUTTON_I2C_ADDRESS;
|
||||
// zh_pcf8574_init(&config, &_button_handle);
|
||||
}
|
||||
|
||||
static void _zh_menu_init(void)
|
||||
{
|
||||
zh_menu_init_config_t config = ZH_MENU_INIT_CONFIG_DEFAULT();
|
||||
config.task_priority = MENU_TASK_PRIORITY;
|
||||
config.stack_size = MENU_TASK_STACK_SIZE;
|
||||
config.queue_size = MENU_QUEUE_SIZE;
|
||||
config.root = &_main_menu;
|
||||
config.loop = false;
|
||||
config.viewport_rows = LCD_TOTAL_ROWS - 1;
|
||||
config.enter_cb = &_zh_menu_enter_main_menu_callback;
|
||||
config.exit_cb = &_zh_menu_exit_main_menu_callback;
|
||||
config.change_cb = &_zh_menu_change_menu_callback;
|
||||
zh_menu_init(&config, &_menu_handle);
|
||||
}
|
||||
|
||||
static void _zh_aht_init(void)
|
||||
{
|
||||
i2c_master_bus_handle_t i2c_bus_handle = NULL;
|
||||
i2c_master_bus_config_t i2c_bus_config = {
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.i2c_port = -1,
|
||||
.scl_io_num = AHT_I2C_SCL_GPIO,
|
||||
.sda_io_num = AHT_I2C_SDA_GPIO,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.flags.enable_internal_pullup = true,
|
||||
};
|
||||
i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle);
|
||||
zh_aht_init_config_t config = ZH_AHT_INIT_CONFIG_DEFAULT();
|
||||
config.i2c_handle = i2c_bus_handle;
|
||||
zh_aht_init(&config, &_aht_handle);
|
||||
}
|
||||
|
||||
static void _zh_system_load(void)
|
||||
{
|
||||
zh_160x_lcd_clear(&_lcd_160x_handle);
|
||||
_zh_draw_boot_screen();
|
||||
float humidity = 0.0;
|
||||
float temperature = 0.0;
|
||||
zh_aht_read(&_aht_handle, &humidity, &temperature);
|
||||
snprintf(_cabin_temperature_status, sizeof(_cabin_temperature_status), "%dC", (int)lroundf(temperature));
|
||||
snprintf(_cabin_humidity_status, sizeof(_cabin_humidity_status), "%d%%", (int)lroundf(humidity));
|
||||
vTaskDelay(5000);
|
||||
zh_160x_lcd_clear(&_lcd_160x_handle);
|
||||
CLEAR_ROW_CACHE();
|
||||
_zh_draw_main_screen();
|
||||
xTaskCreatePinnedToCore(&_zh_stats_processing_task, "stats_processing_task", STATS_TASK_STACK_SIZE, NULL, STATS_TASK_PRIORITY, &_stats_task_handle, tskNO_AFFINITY);
|
||||
xTaskCreatePinnedToCore(&_zh_aht_processing_task, "aht_processing_task", AHT_TASK_STACK_SIZE, NULL, AHT_TASK_PRIORITY, &_aht_task_handle, tskNO_AFFINITY);
|
||||
}
|
||||
|
||||
static void _zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
// TO DO
|
||||
}
|
||||
|
||||
void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
(void)arg;
|
||||
zh_menu_status_t menu_status = {0};
|
||||
zh_menu_get(&_menu_handle, &menu_status);
|
||||
switch (event_id)
|
||||
{
|
||||
case ZH_BUTTON_EVENT:
|
||||
{
|
||||
zh_encoder_button_event_on_isr_t *button_event = (zh_encoder_button_event_on_isr_t *)event_data;
|
||||
if (button_event->button_status == ZH_ENCODER_BUTTON_STATUS_RELEASED)
|
||||
{
|
||||
menu_status.is_active == false ? zh_menu_set(&_menu_handle, ZH_MENU_ENTER, NULL, 0) : menu_status.is_selected == false ? zh_menu_set(&_menu_handle, ZH_MENU_SELECT, NULL, 0)
|
||||
: zh_menu_set(&_menu_handle, ZH_MENU_BACK, NULL, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ZH_ENCODER_EVENT:
|
||||
{
|
||||
zh_encoder_event_on_isr_t *encoder_event = (zh_encoder_event_on_isr_t *)event_data;
|
||||
if (menu_status.is_active == true)
|
||||
{
|
||||
if (menu_status.is_selected == true)
|
||||
{
|
||||
zh_menu_set(&_menu_handle, ZH_MENU_SELECT, encoder_event, sizeof(zh_encoder_event_on_isr_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_event->encoder_status == ZH_ENCODER_STATUS_INCREASED ? zh_menu_set(&_menu_handle, ZH_MENU_UP, NULL, 0) : zh_menu_set(&_menu_handle, ZH_MENU_DOWN, NULL, 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void _zh_stats_processing_task(void *pvParameter)
|
||||
{
|
||||
(void)pvParameter;
|
||||
for (;;)
|
||||
{
|
||||
const zh_encoder_stats_t *encoder_stats = zh_encoder_get_stats();
|
||||
const zh_pcf8574_stats_t *pcf8574_stats = zh_pcf8574_get_stats();
|
||||
const zh_menu_stats_t *menu_stats = zh_menu_get_stats();
|
||||
const zh_aht_stats_t *aht_stats = zh_aht_get_stats();
|
||||
printf("Stats task minimum free stack size: %lu.\n", (uint32_t)uxTaskGetStackHighWaterMark(NULL));
|
||||
printf("AHT task minimum free stack size: %lu.\n", (uint32_t)uxTaskGetStackHighWaterMark(_aht_task_handle));
|
||||
printf("AHT i2c driver error: %lu.\n", aht_stats->i2c_driver_error);
|
||||
printf("Encoder task minimum free stack size: %lu.\n", encoder_stats->min_stack_size);
|
||||
printf("Encoder event post error: %lu.\n", encoder_stats->event_post_error);
|
||||
printf("Encoder queue overflow error: %lu.\n", encoder_stats->queue_overflow_error);
|
||||
printf("Expander task minimum free stack size: %lu.\n", pcf8574_stats->min_stack_size);
|
||||
printf("Expander i2c driver error: %lu.\n", pcf8574_stats->i2c_driver_error);
|
||||
printf("Expander event post error: %lu.\n", pcf8574_stats->event_post_error);
|
||||
printf("Expander queue overflow error: %lu.\n", pcf8574_stats->queue_overflow_error);
|
||||
printf("Expander vector error: %lu.\n", pcf8574_stats->vector_error);
|
||||
printf("Menu task minimum free stack size: %lu.\n", menu_stats->min_stack_size);
|
||||
printf("Menu queue overflow error: %lu.\n", menu_stats->queue_overflow_error);
|
||||
printf("\n");
|
||||
vTaskDelay(60000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static void _zh_aht_processing_task(void *pvParameter)
|
||||
{
|
||||
(void)pvParameter;
|
||||
for (;;)
|
||||
{
|
||||
float humidity = 0.0;
|
||||
float temperature = 0.0;
|
||||
zh_aht_read(&_aht_handle, &humidity, &temperature);
|
||||
snprintf(_cabin_temperature_status, sizeof(_cabin_temperature_status), "%dC", (int)lroundf(temperature));
|
||||
snprintf(_cabin_humidity_status, sizeof(_cabin_humidity_status), "%d%%", (int)lroundf(humidity));
|
||||
zh_menu_status_t menu_status = {0};
|
||||
zh_menu_get(&_menu_handle, &menu_status);
|
||||
if (menu_status.is_active == false)
|
||||
{
|
||||
_zh_draw_main_screen();
|
||||
}
|
||||
// Здесь будет управление кондеем.
|
||||
vTaskDelay(10000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
static void _zh_menu_enter_main_menu_callback(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
_cached_node = NULL;
|
||||
CLEAR_ROW_CACHE();
|
||||
}
|
||||
|
||||
static void _zh_menu_exit_main_menu_callback(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
_zh_save_settings();
|
||||
_prev_selected = false;
|
||||
zh_160x_lcd_clear(&_lcd_160x_handle);
|
||||
CLEAR_ROW_CACHE();
|
||||
_zh_draw_main_screen();
|
||||
_cached_node = NULL;
|
||||
}
|
||||
|
||||
static void _zh_menu_change_menu_callback(zh_menu_node_t *current_node, uint8_t current_index)
|
||||
{
|
||||
_last_node = current_node;
|
||||
_last_index = current_index;
|
||||
zh_menu_status_t status = {0};
|
||||
zh_menu_get(&_menu_handle, &status);
|
||||
if (_prev_selected == true && status.is_selected == false)
|
||||
{
|
||||
_zh_save_settings();
|
||||
}
|
||||
_prev_selected = status.is_selected;
|
||||
_zh_draw_main_menu(current_node, current_index, &status);
|
||||
}
|
||||
|
||||
static void _zh_menu_selectable_item_callback(void *arg)
|
||||
{
|
||||
if (_last_node == NULL || _last_node->submenu == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_last_index >= _last_node->item_numbers)
|
||||
{
|
||||
return;
|
||||
}
|
||||
zh_menu_node_t *item = &_last_node->submenu[_last_index];
|
||||
if (arg == NULL)
|
||||
{
|
||||
zh_menu_set(&_menu_handle, ZH_MENU_SHOW, NULL, 0);
|
||||
return;
|
||||
}
|
||||
zh_encoder_event_on_isr_t *encoder = (zh_encoder_event_on_isr_t *)arg;
|
||||
int8_t dir = encoder->encoder_status == ZH_ENCODER_STATUS_INCREASED ? +1 : -1;
|
||||
bool changed = false;
|
||||
if (item->label == _label_air_condition_temp_on)
|
||||
{
|
||||
_air_condition_temp_on = VALUE_CLAMP(_air_condition_temp_on + dir, 15, 30);
|
||||
changed = true;
|
||||
}
|
||||
else if (item->label == _label_air_condition_temp_off)
|
||||
{
|
||||
_air_condition_temp_off = VALUE_CLAMP(_air_condition_temp_off + dir, 15, 30);
|
||||
changed = true;
|
||||
}
|
||||
else if (item->label == _label_exit_channel_1_power)
|
||||
{
|
||||
_exit_channel_power[0] = VALUE_CLAMP(_exit_channel_power[0] + dir * 5, 0, 100);
|
||||
changed = true;
|
||||
}
|
||||
else if (item->label == _label_exit_channel_2_power)
|
||||
{
|
||||
_exit_channel_power[1] = VALUE_CLAMP(_exit_channel_power[1] + dir * 5, 0, 100);
|
||||
changed = true;
|
||||
}
|
||||
else if (item->label == _label_exit_channel_3_power)
|
||||
{
|
||||
_exit_channel_power[2] = VALUE_CLAMP(_exit_channel_power[2] + dir * 5, 0, 100);
|
||||
changed = true;
|
||||
}
|
||||
else if (item->label == _label_exit_channel_4_power)
|
||||
{
|
||||
_exit_channel_power[3] = VALUE_CLAMP(_exit_channel_power[3] + dir * 5, 0, 100);
|
||||
changed = true;
|
||||
}
|
||||
else if (item->label == _label_bulb_brightness)
|
||||
{
|
||||
_bulb_brightness = VALUE_CLAMP(_bulb_brightness + dir * 5, 0, 100);
|
||||
changed = true;
|
||||
}
|
||||
if (changed == true)
|
||||
{
|
||||
zh_menu_set(&_menu_handle, ZH_MENU_SHOW, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void _zh_menu_boot_screen_callback(void *arg)
|
||||
{
|
||||
if (arg == NULL)
|
||||
{
|
||||
zh_menu_set(&_menu_handle, ZH_MENU_SHOW, NULL, 0);
|
||||
return;
|
||||
}
|
||||
zh_encoder_event_on_isr_t *encoder = (zh_encoder_event_on_isr_t *)arg;
|
||||
int8_t dir = encoder->encoder_status == ZH_ENCODER_STATUS_INCREASED ? +1 : -1;
|
||||
int next = _boot_screen_number + dir;
|
||||
if (next < 0)
|
||||
{
|
||||
next = ARRAY_SIZE(_boot_screens) - 1;
|
||||
}
|
||||
if (next >= ARRAY_SIZE(_boot_screens))
|
||||
{
|
||||
next = 0;
|
||||
}
|
||||
if (next != _boot_screen_number)
|
||||
{
|
||||
_boot_screen_number = next;
|
||||
zh_menu_set(&_menu_handle, ZH_MENU_SHOW, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void _zh_menu_main_screen_callback(void *arg)
|
||||
{
|
||||
if (arg == NULL)
|
||||
{
|
||||
zh_menu_set(&_menu_handle, ZH_MENU_SHOW, NULL, 0);
|
||||
return;
|
||||
}
|
||||
zh_encoder_event_on_isr_t *encoder = (zh_encoder_event_on_isr_t *)arg;
|
||||
int8_t dir = encoder->encoder_status == ZH_ENCODER_STATUS_INCREASED ? +1 : -1;
|
||||
int next = _main_screen_number + dir;
|
||||
if (next < 0)
|
||||
{
|
||||
next = ARRAY_SIZE(_main_screens) - 1;
|
||||
}
|
||||
if (next >= ARRAY_SIZE(_main_screens))
|
||||
{
|
||||
next = 0;
|
||||
}
|
||||
if (next != _main_screen_number)
|
||||
{
|
||||
_main_screen_number = next;
|
||||
zh_menu_set(&_menu_handle, ZH_MENU_SHOW, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void _zh_menu_back_command_callback(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
zh_menu_set(&_menu_handle, ZH_MENU_BACK, NULL, 0);
|
||||
}
|
||||
|
||||
static void _zh_draw_main_screen(void)
|
||||
{
|
||||
const _zh_main_screen_description_t *main_screen = &_main_screens[_main_screen_number];
|
||||
for (uint8_t i = 0; i < LCD_TOTAL_ROWS; ++i)
|
||||
{
|
||||
char buf[LCD_TOTAL_COLS + 1];
|
||||
snprintf(buf, sizeof(buf), "%-12.12s%-4s", main_screen->lines[i], main_screen->values[i]);
|
||||
if (_row_valid[i] == false || memcmp(_row_cache[i], buf, LCD_TOTAL_COLS) != 0)
|
||||
{
|
||||
zh_160x_set_cursor(&_lcd_160x_handle, i, 0);
|
||||
zh_160x_print_char(&_lcd_160x_handle, buf);
|
||||
memcpy(_row_cache[i], buf, LCD_TOTAL_COLS);
|
||||
_row_valid[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void _zh_draw_boot_screen(void)
|
||||
{
|
||||
const _zh_boot_screen_description_t *boot_screen = &_boot_screens[_boot_screen_number];
|
||||
for (uint8_t i = 0; i < LCD_TOTAL_ROWS; ++i)
|
||||
{
|
||||
char buf[LCD_TOTAL_COLS + 1];
|
||||
snprintf(buf, sizeof(buf), "%-*.*s", LCD_TOTAL_COLS, LCD_TOTAL_COLS, boot_screen->lines[i]);
|
||||
if (_row_valid[i] == false || memcmp(_row_cache[i], buf, LCD_TOTAL_COLS) != 0)
|
||||
{
|
||||
zh_160x_set_cursor(&_lcd_160x_handle, i, 0);
|
||||
zh_160x_print_char(&_lcd_160x_handle, buf);
|
||||
memcpy(_row_cache[i], buf, LCD_TOTAL_COLS);
|
||||
_row_valid[i] = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static void _zh_draw_main_menu(zh_menu_node_t *current_node, uint8_t current_index, const zh_menu_status_t *status)
|
||||
{
|
||||
if (current_node != _cached_node)
|
||||
{
|
||||
CLEAR_ROW_CACHE();
|
||||
_cached_node = current_node;
|
||||
}
|
||||
for (uint8_t i = 0; i < current_node->item_numbers; ++i)
|
||||
{
|
||||
const char *label = current_node->submenu[i].label;
|
||||
if (label == _label_air_condition_temp_on)
|
||||
{
|
||||
snprintf(_label_air_condition_temp_on, sizeof(_label_air_condition_temp_on), LABEL_AIR_CONDITION_TEMP_ON "%2dC", (uint8_t)_air_condition_temp_on);
|
||||
}
|
||||
else if (label == _label_air_condition_temp_off)
|
||||
{
|
||||
snprintf(_label_air_condition_temp_off, sizeof(_label_air_condition_temp_off), LABEL_AIR_CONDITION_TEMP_OFF "%2dC", (uint8_t)_air_condition_temp_off);
|
||||
}
|
||||
else if (label == _label_exit_channel_1_power)
|
||||
{
|
||||
snprintf(_label_exit_channel_1_power, sizeof(_label_exit_channel_1_power), LABEL_EXIT_CHANNEL_1_POWER "%3d%%", (uint8_t)_exit_channel_power[0]);
|
||||
}
|
||||
else if (label == _label_exit_channel_2_power)
|
||||
{
|
||||
snprintf(_label_exit_channel_2_power, sizeof(_label_exit_channel_2_power), LABEL_EXIT_CHANNEL_2_POWER "%3d%%", (uint8_t)_exit_channel_power[1]);
|
||||
}
|
||||
else if (label == _label_exit_channel_3_power)
|
||||
{
|
||||
snprintf(_label_exit_channel_3_power, sizeof(_label_exit_channel_3_power), LABEL_EXIT_CHANNEL_3_POWER "%3d%%", (uint8_t)_exit_channel_power[2]);
|
||||
}
|
||||
else if (label == _label_exit_channel_4_power)
|
||||
{
|
||||
snprintf(_label_exit_channel_4_power, sizeof(_label_exit_channel_4_power), LABEL_EXIT_CHANNEL_4_POWER "%3d%%", (uint8_t)_exit_channel_power[3]);
|
||||
}
|
||||
else if (label == _label_bulb_brightness)
|
||||
{
|
||||
snprintf(_label_bulb_brightness, sizeof(_label_bulb_brightness), LABEL_BULB_BRIGHTNESS "%3d%%", (uint8_t)_bulb_brightness);
|
||||
}
|
||||
else if (label == _label_boot_screen)
|
||||
{
|
||||
snprintf(_label_boot_screen, sizeof(_label_boot_screen), LABEL_BOOT_SCREEN "%s", _boot_screens[_boot_screen_number].name);
|
||||
}
|
||||
else if (label == _label_main_screen)
|
||||
{
|
||||
snprintf(_label_main_screen, sizeof(_label_main_screen), LABEL_MAIN_SCREEN "%s", _main_screens[_main_screen_number].name);
|
||||
}
|
||||
}
|
||||
zh_menu_view_t view = {0};
|
||||
zh_menu_get_view(&_menu_handle, &view);
|
||||
char header[LCD_TOTAL_COLS + 1];
|
||||
snprintf(header, sizeof(header), "%-*.*s", LCD_TOTAL_COLS, LCD_TOTAL_COLS, current_node->label);
|
||||
if (_row_valid[0] == false || memcmp(_row_cache[0], header, LCD_TOTAL_COLS) != 0)
|
||||
{
|
||||
zh_160x_set_cursor(&_lcd_160x_handle, 0, 0);
|
||||
zh_160x_print_char(&_lcd_160x_handle, header);
|
||||
memcpy(_row_cache[0], header, LCD_TOTAL_COLS);
|
||||
_row_valid[0] = true;
|
||||
};
|
||||
for (uint8_t i = 0; i < LCD_TOTAL_ROWS - 1; ++i)
|
||||
{
|
||||
char buf[LCD_TOTAL_COLS + 1];
|
||||
if (i < view.visible_count)
|
||||
{
|
||||
uint8_t idx = view.first_visible + i;
|
||||
bool is_cursor = (idx == current_index);
|
||||
bool is_edit = is_cursor && status->is_selected && current_node->submenu[idx].selectable;
|
||||
bool arrow_up = (i == 0) && (view.first_visible > 0);
|
||||
bool arrow_down = (i == (view.visible_count - 1)) && ((uint8_t)(view.first_visible + view.visible_count) < current_node->item_numbers);
|
||||
uint8_t text_cols = LCD_TOTAL_COLS - 1 - (arrow_up || arrow_down);
|
||||
snprintf(buf, sizeof(buf), "%c%-*.*s%c", is_edit == true ? '*' : (is_cursor == true ? '>' : ' '), text_cols, text_cols, current_node->submenu[idx].label, arrow_up == true ? '^' : (arrow_down == true ? 'v' : ' '));
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(buf, ' ', LCD_TOTAL_COLS);
|
||||
buf[LCD_TOTAL_COLS] = '\0';
|
||||
}
|
||||
if (_row_valid[i + 1] == false || memcmp(_row_cache[i + 1], buf, LCD_TOTAL_COLS) != 0)
|
||||
{
|
||||
zh_160x_set_cursor(&_lcd_160x_handle, i + 1, 0);
|
||||
zh_160x_print_char(&_lcd_160x_handle, buf);
|
||||
memcpy(_row_cache[i + 1], buf, LCD_TOTAL_COLS);
|
||||
_row_valid[i + 1] = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "math.h"
|
||||
#include "zh_menu.h"
|
||||
#include "zh_160x_i2c.h"
|
||||
#include "zh_encoder.h"
|
||||
#include "zh_ota_server.h"
|
||||
#include "zh_aht.h"
|
||||
|
||||
#define LCD_TOTAL_ROWS 4
|
||||
#define LCD_TOTAL_COLS 16
|
||||
|
||||
#define NVS_NAMESPACE "sim_race_box"
|
||||
#define NVS_KEY_SETTINGS "settings"
|
||||
|
||||
#define STATS_TASK_PRIORITY tskIDLE_PRIORITY
|
||||
#define STATS_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define AHT_TASK_PRIORITY tskIDLE_PRIORITY + 3
|
||||
#define AHT_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define EXPANDER_TASK_PRIORITY tskIDLE_PRIORITY + 5
|
||||
#define EXPANDER_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define ENCODER_TASK_PRIORITY tskIDLE_PRIORITY + 4
|
||||
#define ENCODER_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
|
||||
#define ENCODER_QUEUE_SIZE 5
|
||||
#define MENU_TASK_PRIORITY tskIDLE_PRIORITY + 4
|
||||
#define MENU_TASK_STACK_SIZE configMINIMAL_STACK_SIZE + 1280
|
||||
#define MENU_QUEUE_SIZE 20
|
||||
|
||||
#define WIFI_AP_SSID "CABANLEO"
|
||||
#define WIFI_AP_PASS "cabanleo"
|
||||
#define WIFI_AP_CHANNEL 1
|
||||
#define MAX_AP_CONNECTION 4
|
||||
|
||||
#define MODE_ENCODER_NUMBER 1
|
||||
#define MODE_ENCODER_A_GPIO GPIO_NUM_4
|
||||
#define MODE_ENCODER_B_GPIO GPIO_NUM_16
|
||||
#define MODE_ENCODER_S_GPIO GPIO_NUM_15
|
||||
|
||||
#define EXPANDERS_I2C_SCL_GPIO GPIO_NUM_26
|
||||
#define EXPANDERS_I2C_SDA_GPIO GPIO_NUM_25
|
||||
#define EXPANDERS_INT_GPIO GPIO_NUM_17
|
||||
|
||||
#define AHT_I2C_SCL_GPIO GPIO_NUM_22
|
||||
#define AHT_I2C_SDA_GPIO GPIO_NUM_21
|
||||
|
||||
#define LCD_I2C_ADDRESS 0x27
|
||||
#define BUTTON_I2C_ADDRESS 0x24
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
1.0.0
|
||||
Reference in new issue
Block a user