Compare commits

..

75 Commits

Author SHA1 Message Date
7515612c01 wip: 2025-11-27 12:48:55 +03:00
38ea08e798 wip: 2025-11-27 11:13:13 +03:00
0f559a79da wip: 2025-11-27 09:15:09 +03:00
95f4ea4017 wip: 2025-11-19 09:16:25 +03:00
2d15b5e7b5 wip: 2025-11-07 07:29:37 +03:00
37dd6b5a1e wip: 2025-10-12 20:30:39 +03:00
0786846040 wip: 2025-10-12 10:35:39 +03:00
b37586ff1a wip: 2025-10-11 12:54:25 +03:00
05ed2c3bb9 wip: 2025-10-11 12:24:25 +03:00
bfdd6ee8a1 wip: 2025-10-11 11:10:18 +03:00
b6b3c3f6af Merge branch 'dev' of http://git.zh.com.ru/aerotech/ate0003.000.000 into dev 2025-10-10 10:30:54 +03:00
93758b5f72 wip: 2025-10-10 10:30:52 +03:00
f0398e1222 wip: 2025-10-09 19:10:24 +03:00
8d813d7eab wip: 2025-10-09 10:36:48 +03:00
806e645056 Merge commit '8934925c89ca79834efc89ca0a85116e3fac615e' into dev 2025-10-08 13:42:38 +03:00
230402e002 wip: 2025-10-08 13:40:26 +03:00
8934925c89 wip: 2025-10-07 16:30:35 +03:00
eb9fefbf36 wip: 2025-10-06 18:24:03 +03:00
6476bf4d1a wip: 2025-10-06 18:23:38 +03:00
479e78be84 wip: 2025-10-06 14:33:54 +03:00
e2c71c9d0d wip: 2025-10-05 17:27:58 +03:00
5b22dff0d5 wip: 2025-10-05 15:52:05 +03:00
daff1f6d24 wip: 2025-10-05 14:13:23 +03:00
51f6d00ebb wip: 2025-10-05 14:11:35 +03:00
bab0c181bd wip: 2025-10-05 10:58:44 +03:00
8b46ced5ef wip: 2025-10-05 10:44:57 +03:00
1f6866e915 wip: 2025-10-05 10:01:00 +03:00
a4b4e2c68d wip: 2025-10-03 13:07:57 +03:00
907095940b wip: 2025-10-03 10:30:41 +03:00
4b46feee01 wip: 2025-10-02 09:32:51 +03:00
3f5d93a579 wip: 2025-10-01 15:16:55 +03:00
c1e4fd5b29 wip: 2025-10-01 11:45:22 +03:00
d065924e9c wip: 2025-10-01 11:16:06 +03:00
d883c84335 wip: 2025-10-01 11:03:06 +03:00
5e06d058ce wip: 2025-10-01 07:58:22 +03:00
f33a5cf85f wip: 2025-09-30 21:05:02 +03:00
803e53544c wip: 2025-09-30 20:59:26 +03:00
1bfdecc5ba wip: 2025-09-30 15:00:39 +03:00
22f8a25246 wip: 2025-09-30 09:10:43 +03:00
7b02ba6b0a wip: 2025-09-30 09:05:50 +03:00
e26cf65079 wip: 2025-09-30 08:32:47 +03:00
5633b050e5 wip: 2025-09-29 17:40:40 +03:00
a3b23eeeba wip: 2025-09-29 15:45:54 +03:00
5158538e29 wip: 2025-09-29 12:27:25 +03:00
3c98736017 wip: 2025-09-29 10:54:54 +03:00
d08c591b11 wip: 2025-09-29 09:12:10 +03:00
751c8ee385 wip: 2025-09-26 18:12:48 +03:00
514ddd1a3b wip: 2025-09-26 10:43:35 +03:00
a1a7327e39 wip: 2025-09-25 19:18:13 +03:00
46850b548f wip: 2025-09-25 15:15:12 +03:00
731a29a1d4 wip: 2025-09-19 13:40:28 +03:00
4effada5b8 wip: 2025-09-18 07:39:50 +03:00
f065074027 wip: 2025-09-16 18:43:09 +03:00
55098d8642 wip: 2025-09-15 14:28:22 +03:00
295bba4113 wip: 2025-09-14 08:28:33 +03:00
93ef4dd906 wip: 2025-09-14 08:24:36 +03:00
28eace8311 wip: 2025-09-14 08:19:27 +03:00
efebbb6310 wip: 2025-09-12 12:40:23 +03:00
438bb3b11b wip: 2025-09-11 16:17:34 +03:00
251d86940b wip: 2025-09-11 13:38:49 +03:00
ac5d8c5d88 wip: 2025-09-11 09:52:26 +03:00
3369b138cc wip: 2025-09-11 08:53:32 +03:00
ec63d718d9 wip: 2025-09-11 08:24:10 +03:00
67b6c6e8fc wip: 2025-09-11 08:22:44 +03:00
a516568399 wip: 2025-09-10 19:50:27 +03:00
3b815fe2d8 wip: 2025-09-10 14:07:15 +03:00
edda0e5236 wip: 2025-09-09 07:42:15 +03:00
8840b7afb0 wip: 2025-09-08 18:53:39 +03:00
b578c2ee40 wip: 2025-09-08 11:53:16 +03:00
87b50dceeb wip: 2025-09-07 20:48:23 +03:00
28f3018696 wip: 2025-09-07 11:00:19 +03:00
86712bd939 wip: 2025-09-06 10:05:49 +03:00
e51603693b wip: 2025-09-06 09:59:59 +03:00
c99f82eee9 wip: 2025-09-05 13:02:17 +03:00
178503cdfa wip: 2025-09-04 08:42:04 +03:00
57 changed files with 1645 additions and 3887 deletions

4
.gitignore vendored
View File

@@ -1,6 +1,4 @@
.pio
.vscode .vscode
.DS_Store .DS_Store
build
sdkconfig.old
desktop.ini desktop.ini
.PVS-Studio

42
.gitmodules vendored
View File

@@ -1,18 +1,24 @@
[submodule "components/zh_ota_server"] [submodule "lib/zh_avr_free_rtos"]
path = components/zh_ota_server path = lib/zh_avr_free_rtos
url = http://git.zh.com.ru/esp_components/zh_ota_server url = http://git.zh.com.ru/avr_libraries/zh_avr_free_rtos
[submodule "components/zh_pcf8574"] [submodule "lib/zh_avr_vector"]
path = components/zh_pcf8574 path = lib/zh_avr_vector
url = http://git.zh.com.ru/esp_components/zh_pcf8574 url = http://git.zh.com.ru/avr_libraries/zh_avr_vector
[submodule "components/zh_ac_dimmer"] [submodule "lib/zh_avr_i2c"]
path = components/zh_ac_dimmer path = lib/zh_avr_i2c
url = http://git.zh.com.ru/esp_components/zh_ac_dimmer url = http://git.zh.com.ru/avr_libraries/zh_avr_i2c
[submodule "components/zh_encoder"] [submodule "lib/zh_avr_common"]
path = components/zh_encoder path = lib/zh_avr_common
url = http://git.zh.com.ru/esp_components/zh_encoder url = http://git.zh.com.ru/avr_libraries/zh_avr_common
[submodule "components/zh_160x_i2c"] [submodule "lib/zh_avr_pcf8574"]
path = components/zh_160x_i2c path = lib/zh_avr_pcf8574
url = http://git.zh.com.ru/esp_components/zh_160x_i2c url = http://git.zh.com.ru/avr_libraries/zh_avr_pcf8574
[submodule "components/zh_vector"] [submodule "lib/zh_avr_160x_i2c"]
path = components/zh_vector path = lib/zh_avr_160x_i2c
url = http://git.zh.com.ru/esp_components/zh_vector url = http://git.zh.com.ru/avr_libraries/zh_avr_160x_i2c
[submodule "lib/zh_avr_encoder"]
path = lib/zh_avr_encoder
url = http://git.zh.com.ru/avr_libraries/zh_avr_encoder
[submodule "lib/zh_avr_ac_dimmer"]
path = lib/zh_avr_ac_dimmer
url = http://git.zh.com.ru/avr_libraries/zh_avr_ac_dimmer

View File

@@ -1,3 +0,0 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ate0003)

View File

@@ -1,21 +1,3 @@
# Universal Phase-Controlled Aircraft Light Activation Box # ate0003.000.000
## Tested on git clone --recurse-submodules -b dev http://git.zh.com.ru/aerotech/ate0003.000.000
1. [ESP32 ESP-IDF v5.5.1](https://docs.espressif.com/projects/esp-idf/en/v5.5.1/esp32/index.html)
## SAST Tools
[PVS-Studio](https://pvs-studio.com/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source) - static analyzer for C, C++, C#, and Java code.
## Build and flash
Run the following command to firmware build and flash module:
```text
cd your_projects_folder
git clone --recurse-submodules http://git.zh.com.ru/aerotech/ate0003
cd ate0003
idf.py build
idf.py flash
```

BIN
ds/171611890.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
ds/BL-L515.pdf Normal file

Binary file not shown.

BIN
ds/BTA12-600BWRG.pdf Normal file

Binary file not shown.

BIN
ds/DOC000309400.pdf Normal file

Binary file not shown.

BIN
ds/DOC002468502.pdf Normal file

Binary file not shown.

BIN
ds/DOC005805734.pdf Normal file

Binary file not shown.

BIN
ds/DOC017422707.pdf Normal file

Binary file not shown.

BIN
ds/DOC042891075.pdf Normal file

Binary file not shown.

BIN
ds/DOC043994357.pdf Normal file

Binary file not shown.

BIN
ds/DOC053950523.pdf Normal file

Binary file not shown.

Binary file not shown.

BIN
ds/FOD814.pdf Normal file

Binary file not shown.

BIN
ds/KLS5-254.pdf Normal file

Binary file not shown.

BIN
ds/MMBT2222.pdf Normal file

Binary file not shown.

BIN
ds/MOC3011.pdf Normal file

Binary file not shown.

BIN
ds/MOC3063SM.pdf Normal file

Binary file not shown.

BIN
ds/PCF8574.pdf Normal file

Binary file not shown.

BIN
ds/RS-15-5.pdf Normal file

Binary file not shown.

BIN
ds/TTP223.pdf Normal file

Binary file not shown.

BIN
ds/W14.pdf Normal file

Binary file not shown.

1
lib/zh_avr_160x_i2c Submodule

Submodule lib/zh_avr_160x_i2c added at d95823281b

1
lib/zh_avr_ac_dimmer Submodule

Submodule lib/zh_avr_ac_dimmer added at 41c23732f2

1
lib/zh_avr_common Submodule

Submodule lib/zh_avr_common added at 1cb4a4cc76

1
lib/zh_avr_encoder Submodule

Submodule lib/zh_avr_encoder added at eac1c45093

1
lib/zh_avr_free_rtos Submodule

Submodule lib/zh_avr_free_rtos added at abfe2ea922

1
lib/zh_avr_i2c Submodule

Submodule lib/zh_avr_i2c added at da2fd0d2a8

1
lib/zh_avr_pcf8574 Submodule

Submodule lib/zh_avr_pcf8574 added at 3fa55b8fa2

1
lib/zh_avr_vector Submodule

Submodule lib/zh_avr_vector added at eddd461e96

View File

@@ -1 +0,0 @@
idf_component_register(SRCS "ate0003.c" INCLUDE_DIRS "" REQUIRES zh_160x_i2c zh_ac_dimmer zh_encoder esp_wifi nvs_flash zh_ota_server)

View File

@@ -1,440 +0,0 @@
#include "ate0003.h"
static i2c_master_bus_handle_t _i2c_bus_handle = NULL;
static httpd_handle_t _webserver_handle = NULL;
static zh_pcf8574_handle_t _button_handle = {0};
static zh_pcf8574_handle_t _led_1_handle = {0};
static zh_pcf8574_handle_t _led_2_handle = {0};
static zh_pcf8574_handle_t _relay_handle = {0};
static zh_pcf8574_handle_t _lcd_handle = {0};
static zh_encoder_handle_t _power_encoder_handle = {0};
static zh_encoder_handle_t _component_encoder_handle = {0};
volatile static bool _is_work = false;
volatile static bool _is_dmm_enabled = false;
volatile static bool _is_fix_enabled = false;
volatile static uint8_t _permitted_channels = 0;
volatile static uint8_t _used_channels = 0;
volatile static uint8_t _current_component = 0;
volatile static bool _is_num_1_fixed = false;
volatile static bool _is_num_2_fixed = false;
volatile static bool _is_num_3_fixed = false;
volatile static bool _is_num_4_fixed = false;
static void _zh_wifi_softap_init(void);
static void _zh_webserver_init(void);
static void _zh_encoder_init(void);
static void _zh_ac_dimmer_init(void);
static void _zh_pcf8574_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_component_select(uint8_t component);
static void _zh_relay_on(uint8_t relay_number);
static void _zh_relay_off(uint8_t relay_number);
void app_main(void)
{
nvs_flash_init();
esp_event_loop_create_default();
_zh_wifi_softap_init();
_zh_webserver_init();
_zh_pcf8574_init();
_zh_system_load();
_zh_encoder_init();
_zh_ac_dimmer_init();
zh_pcf8574_write_gpio(&_led_1_handle, DMM_LED_RED, LED_ON);
zh_pcf8574_write_gpio(&_led_1_handle, FIX_LED_BLUE, LED_ON);
zh_pcf8574_write_gpio(&_relay_handle, DMM_RELAY, RELAY_ON);
_zh_component_select(0);
}
static void _zh_wifi_softap_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_SSID,
.password = WIFI_PASS,
.max_connection = 4,
.authmode = WIFI_AUTH_WPA2_PSK,
},
};
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(&_webserver_handle, &config);
zh_ota_server_init(_webserver_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.a_gpio_number = GPIO_NUM_27;
config.b_gpio_number = GPIO_NUM_26;
config.encoder_min_value = 0;
config.encoder_max_value = 100;
config.encoder_step = 1;
config.encoder_number = POWER_ENCODER;
zh_encoder_init(&config, &_power_encoder_handle);
zh_encoder_set(&_power_encoder_handle, 100);
config.a_gpio_number = GPIO_NUM_18;
config.b_gpio_number = GPIO_NUM_19;
config.encoder_min_value = 0;
config.encoder_max_value = (sizeof(_component) / sizeof(_component[0])) - 1;
config.encoder_step = 1;
config.encoder_number = COMPONENT_ENCODER;
zh_encoder_init(&config, &_component_encoder_handle);
zh_encoder_set(&_component_encoder_handle, 0);
}
static void _zh_ac_dimmer_init(void)
{
zh_ac_dimmer_init_config_t config = ZH_AC_DIMMER_INIT_CONFIG_DEFAULT();
config.zero_cross_gpio = GPIO_NUM_16;
config.triac_gpio = GPIO_NUM_4;
zh_ac_dimmer_init(&config);
zh_ac_dimmer_set(100);
}
static void _zh_pcf8574_init(void)
{
i2c_master_bus_config_t i2c_bus_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.scl_io_num = GPIO_NUM_22,
.sda_io_num = GPIO_NUM_21,
.glitch_ignore_cnt = 7,
};
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.i2c_handle = _i2c_bus_handle;
config.i2c_address = LED_1_I2C_ADDRESS;
zh_pcf8574_init(&config, &_led_1_handle);
config.i2c_address = LED_2_I2C_ADDRESS;
zh_pcf8574_init(&config, &_led_2_handle);
config.i2c_address = RELAY_I2C_ADDRESS;
zh_pcf8574_init(&config, &_relay_handle);
config.i2c_address = LCD_I2C_ADDRESS;
zh_pcf8574_init(&config, &_lcd_handle);
zh_160x_init(&_lcd_handle, ZH_LCD_16X4);
config.p0_gpio_work_mode = true;
config.p1_gpio_work_mode = true;
config.p2_gpio_work_mode = true;
config.p3_gpio_work_mode = true;
config.p4_gpio_work_mode = true;
config.p5_gpio_work_mode = true;
config.interrupt_gpio = GPIO_NUM_17;
config.i2c_address = BUTTON_I2C_ADDRESS;
zh_pcf8574_init(&config, &_button_handle);
}
static void _zh_system_load(void)
{
zh_160x_set_cursor(&_lcd_handle, 0, 0);
zh_160x_print_char(&_lcd_handle, "LLC AEROTECH");
zh_160x_set_cursor(&_lcd_handle, 1, 0);
zh_160x_print_char(&_lcd_handle, "ATE0003");
zh_160x_set_cursor(&_lcd_handle, 2, 0);
zh_160x_print_char(&_lcd_handle, "Firmware v1.0.0");
for (uint8_t i = 0; i <= 100; i += 10)
{
zh_160x_print_progress_bar(&_lcd_handle, 3, i);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
zh_160x_lcd_clear(&_lcd_handle);
zh_160x_set_cursor(&_lcd_handle, 0, 0);
zh_160x_print_char(&_lcd_handle, "P/N:");
zh_160x_set_cursor(&_lcd_handle, 1, 0);
zh_160x_print_char(&_lcd_handle, "P:100%");
zh_160x_set_cursor(&_lcd_handle, 1, 8);
zh_160x_print_char(&_lcd_handle, "C:");
zh_160x_set_cursor(&_lcd_handle, 2, 0);
zh_160x_print_char(&_lcd_handle, "1: 2: ");
zh_160x_set_cursor(&_lcd_handle, 3, 0);
zh_160x_print_char(&_lcd_handle, "3: 4: ");
}
static void _zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
zh_pcf8574_event_on_isr_t *event = event_data;
switch (event->gpio_number)
{
case DMM_BUTTON:
if (event->gpio_level == LOW && _is_work == false)
{
if (_is_dmm_enabled == true)
{
zh_pcf8574_write_gpio(&_led_1_handle, DMM_LED_RED, LED_ON);
zh_pcf8574_write_gpio(&_led_1_handle, DMM_LED_GREEN, LED_OFF);
zh_pcf8574_write_gpio(&_relay_handle, DMM_RELAY, RELAY_ON);
_is_dmm_enabled = false;
}
else
{
zh_pcf8574_write_gpio(&_led_1_handle, DMM_LED_RED, LED_OFF);
zh_pcf8574_write_gpio(&_led_1_handle, DMM_LED_GREEN, LED_ON);
zh_pcf8574_write_gpio(&_relay_handle, DMM_RELAY, RELAY_OFF);
_is_dmm_enabled = true;
}
}
break;
case FIX_BUTTON:
if (event->gpio_level == LOW)
{
zh_pcf8574_write_gpio(&_led_1_handle, FIX_LED_BLUE, LED_OFF);
zh_pcf8574_write_gpio(&_led_1_handle, FIX_LED_GREEN, LED_ON);
_is_fix_enabled = true;
}
else
{
zh_pcf8574_write_gpio(&_led_1_handle, FIX_LED_BLUE, LED_ON);
zh_pcf8574_write_gpio(&_led_1_handle, FIX_LED_GREEN, LED_OFF);
_is_fix_enabled = false;
}
break;
case NUM_1_BUTTON:
if ((_permitted_channels & CHANNEL_1) == 0)
{
break;
}
if (event->gpio_level == LOW)
{
if (_is_num_1_fixed == true)
{
break;
}
zh_pcf8574_write_gpio(&_led_1_handle, NUM_1_LED_BLUE, LED_OFF);
zh_pcf8574_write_gpio(&_led_1_handle, NUM_1_LED_GREEN, LED_ON);
_zh_relay_on(L_1_RELAY);
}
else
{
if (_is_fix_enabled == true)
{
_is_num_1_fixed = true;
break;
}
zh_pcf8574_write_gpio(&_led_1_handle, NUM_1_LED_BLUE, LED_ON);
zh_pcf8574_write_gpio(&_led_1_handle, NUM_1_LED_GREEN, LED_OFF);
_zh_relay_off(L_1_RELAY);
_is_num_1_fixed = false;
}
break;
case NUM_2_BUTTON:
if ((_permitted_channels & CHANNEL_2) == 0)
{
break;
}
if (event->gpio_level == LOW)
{
if (_is_num_2_fixed == true)
{
break;
}
zh_pcf8574_write_gpio(&_led_1_handle, NUM_2_LED_BLUE, LED_OFF);
zh_pcf8574_write_gpio(&_led_1_handle, NUM_2_LED_GREEN, LED_ON);
_zh_relay_on(L_2_RELAY);
}
else
{
if (_is_fix_enabled == true)
{
_is_num_2_fixed = true;
break;
}
zh_pcf8574_write_gpio(&_led_1_handle, NUM_2_LED_BLUE, LED_ON);
zh_pcf8574_write_gpio(&_led_1_handle, NUM_2_LED_GREEN, LED_OFF);
_zh_relay_off(L_2_RELAY);
_is_num_2_fixed = false;
}
break;
case NUM_3_BUTTON:
if ((_permitted_channels & CHANNEL_3) == 0)
{
break;
}
if (event->gpio_level == LOW)
{
if (_is_num_3_fixed == true)
{
break;
}
zh_pcf8574_write_gpio(&_led_2_handle, NUM_3_LED_BLUE, LED_OFF);
zh_pcf8574_write_gpio(&_led_2_handle, NUM_3_LED_GREEN, LED_ON);
_zh_relay_on(L_3_RELAY);
}
else
{
if (_is_fix_enabled == true)
{
_is_num_3_fixed = true;
break;
}
zh_pcf8574_write_gpio(&_led_2_handle, NUM_3_LED_BLUE, LED_ON);
zh_pcf8574_write_gpio(&_led_2_handle, NUM_3_LED_GREEN, LED_OFF);
_zh_relay_off(L_3_RELAY);
_is_num_3_fixed = false;
}
break;
case NUM_4_BUTTON:
if ((_permitted_channels & CHANNEL_4) == 0)
{
break;
}
if (event->gpio_level == LOW)
{
if (_is_num_4_fixed == true)
{
break;
}
zh_pcf8574_write_gpio(&_led_2_handle, NUM_4_LED_BLUE, LED_OFF);
zh_pcf8574_write_gpio(&_led_2_handle, NUM_4_LED_GREEN, LED_ON);
_zh_relay_on(L_4_RELAY);
}
else
{
if (_is_fix_enabled == true)
{
_is_num_4_fixed = true;
break;
}
zh_pcf8574_write_gpio(&_led_2_handle, NUM_4_LED_BLUE, LED_ON);
zh_pcf8574_write_gpio(&_led_2_handle, NUM_4_LED_GREEN, LED_OFF);
_zh_relay_off(L_4_RELAY);
_is_num_4_fixed = false;
}
break;
default:
break;
}
}
static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
zh_encoder_event_on_isr_t *event = event_data;
switch (event->encoder_number)
{
case POWER_ENCODER:
zh_160x_set_cursor(&_lcd_handle, 1, 2);
zh_160x_print_int(&_lcd_handle, (uint8_t)event->encoder_position);
zh_160x_print_char(&_lcd_handle, "% ");
zh_ac_dimmer_set((uint8_t)event->encoder_position);
break;
case COMPONENT_ENCODER:
if (_is_work == true)
{
zh_encoder_set(&_component_encoder_handle, _current_component);
break;
}
if ((uint8_t)event->encoder_position == 0)
{
zh_encoder_set(&_component_encoder_handle, 1);
break;
}
_zh_component_select((uint8_t)event->encoder_position);
break;
default:
break;
}
}
static void _zh_component_select(uint8_t component)
{
_current_component = component;
_component_t temp = _component[component];
_permitted_channels = temp._used_channel;
zh_160x_set_cursor(&_lcd_handle, 0, 4);
zh_160x_print_char(&_lcd_handle, " ");
zh_160x_set_cursor(&_lcd_handle, 0, 4);
zh_160x_print_char(&_lcd_handle, temp._pn);
zh_160x_set_cursor(&_lcd_handle, 1, 10);
zh_160x_print_char(&_lcd_handle, temp._doc);
zh_160x_set_cursor(&_lcd_handle, 2, 2);
zh_160x_print_char(&_lcd_handle, " ");
zh_160x_set_cursor(&_lcd_handle, 2, 2);
zh_160x_print_char(&_lcd_handle, temp._channel_1);
zh_160x_set_cursor(&_lcd_handle, 2, 10);
zh_160x_print_char(&_lcd_handle, " ");
zh_160x_set_cursor(&_lcd_handle, 2, 10);
zh_160x_print_char(&_lcd_handle, temp._channel_2);
zh_160x_set_cursor(&_lcd_handle, 3, 2);
zh_160x_print_char(&_lcd_handle, " ");
zh_160x_set_cursor(&_lcd_handle, 3, 2);
zh_160x_print_char(&_lcd_handle, temp._channel_3);
zh_160x_set_cursor(&_lcd_handle, 3, 10);
zh_160x_print_char(&_lcd_handle, " ");
zh_160x_set_cursor(&_lcd_handle, 3, 10);
zh_160x_print_char(&_lcd_handle, temp._channel_4);
zh_pcf8574_write(&_led_1_handle, _is_dmm_enabled == true ? 0x06 : 0x05);
zh_pcf8574_write(&_led_2_handle, 0x00);
if ((_permitted_channels & CHANNEL_1) == CHANNEL_1)
{
zh_pcf8574_write_gpio(&_led_1_handle, NUM_1_LED_BLUE, LED_ON);
}
if ((_permitted_channels & CHANNEL_2) == CHANNEL_2)
{
zh_pcf8574_write_gpio(&_led_1_handle, NUM_2_LED_BLUE, LED_ON);
}
if ((_permitted_channels & CHANNEL_3) == CHANNEL_3)
{
zh_pcf8574_write_gpio(&_led_2_handle, NUM_3_LED_BLUE, LED_ON);
}
if ((_permitted_channels & CHANNEL_4) == CHANNEL_4)
{
zh_pcf8574_write_gpio(&_led_2_handle, NUM_4_LED_BLUE, LED_ON);
}
}
static void _zh_relay_on(uint8_t relay_number)
{
if (++_used_channels > 1)
{
zh_ac_dimmer_stop();
vTaskDelay(5);
zh_pcf8574_write_gpio(&_relay_handle, relay_number, RELAY_ON);
vTaskDelay(20);
zh_ac_dimmer_start();
}
else
{
_is_work = true;
zh_pcf8574_write_gpio(&_relay_handle, relay_number, RELAY_ON);
zh_pcf8574_write_gpio(&_relay_handle, GROUND_RELAY, RELAY_ON);
vTaskDelay(20);
zh_ac_dimmer_start();
}
}
static void _zh_relay_off(uint8_t relay_number)
{
if (--_used_channels > 0)
{
zh_ac_dimmer_stop();
vTaskDelay(5);
zh_pcf8574_write_gpio(&_relay_handle, relay_number, RELAY_OFF);
vTaskDelay(20);
zh_ac_dimmer_start();
}
else
{
zh_ac_dimmer_stop();
vTaskDelay(5);
zh_pcf8574_write_gpio(&_relay_handle, relay_number, RELAY_OFF);
zh_pcf8574_write_gpio(&_relay_handle, GROUND_RELAY, RELAY_OFF);
_is_work = false;
}
}

View File

@@ -1,102 +0,0 @@
/**
* @file ate0003.h
*/
#pragma once
#include "zh_160x_i2c.h"
#include "zh_ac_dimmer.h"
#include "zh_encoder.h"
#include "nvs_flash.h"
#include "esp_wifi.h"
#include "zh_ota_server.h"
#define HIGH true
#define LOW false
#define LED_OFF LOW
#define LED_ON HIGH
#define RELAY_OFF LOW
#define RELAY_ON HIGH
#define WIFI_SSID "ATE0003"
#define WIFI_PASS "repairlab"
#define WIFI_CHANNEL 1
#define MAX_STA_CONNECTION 4
#define LCD_I2C_ADDRESS 0x20 /*!< U4. */
#define BUTTON_I2C_ADDRESS 0x24 /*!< U5. */
#define LED_1_I2C_ADDRESS 0x22 /*!< U6. */
#define LED_2_I2C_ADDRESS 0x21 /*!< U7. */
#define RELAY_I2C_ADDRESS 0x23 /*!< U8. */
#define GROUND_RELAY 0x00 /*!< Relay K1. RL1 pin on U8. */
#define DMM_RELAY 0x01 /*!< Relay K2. RL2 pin on U8. */
#define L_1_RELAY 0x03 /*!< Relay K4. RL4 pin on U8. */
#define L_2_RELAY 0x04 /*!< Relay K3. RL3 pin on U8. */
#define L_3_RELAY 0x05 /*!< Relay K6. RL6 pin on U8. */
#define L_4_RELAY 0x02 /*!< Relay K5. RL5 pin on U8. */
#define L5_RELAY 0x06 /*!< Relay K7. RL7 pin on U8. */
#define POWER_ENCODER 0x01 /*!< Connector EN2. */
#define COMPONENT_ENCODER 0x02 /*!< Connector EN1. */
#define DMM_BUTTON 0x00 /*!< Connector BT1. BT1-0 on U5. */
#define FIX_BUTTON 0x01 /*!< Connector BT2. BT2-1 on U5. */
#define NUM_1_BUTTON 0x02 /*!< Connector BT3. BT3-2 on U5. */
#define NUM_2_BUTTON 0x03 /*!< Connector BT4. BT4-3 on U5. */
#define NUM_3_BUTTON 0x04 /*!< Connector BT5. BT5-4 on U5. */
#define NUM_4_BUTTON 0x05 /*!< Connector BT6. BT6-5 on U5. */
#define DMM_LED_RED 0x00 /*!< Connector LE1. 2 PIN. L1-0 pin on U6. */
#define DMM_LED_GREEN 0x01 /*!< Connector LE1. 1 PIN. L1-1 pin on U6. */
#define FIX_LED_BLUE 0x02 /*!< Connector LE2. 2 PIN. L2-2 pin on U6. */
#define FIX_LED_GREEN 0x03 /*!< Connector LE2. 1 PIN. L2-3 pin on U6. */
#define NUM_1_LED_BLUE 0x04 /*!< Connector LE3. 2 PIN. L3-4 pin on U6. */
#define NUM_1_LED_GREEN 0x05 /*!< Connector LE3. 1 PIN. L3-5 pin on U6. */
#define NUM_2_LED_BLUE 0x06 /*!< Connector LE4. 2 PIN. L4-6 pin on U6. */
#define NUM_2_LED_GREEN 0x07 /*!< Connector LE4. 1 PIN. L4-7 pin on U6. */
#define NUM_3_LED_BLUE 0x00 /*!< Connector LE5. 2 PIN. L5-0 pin on U7. */
#define NUM_3_LED_GREEN 0x01 /*!< Connector LE5. 1 PIN. L5-1 pin on U7. */
#define NUM_4_LED_BLUE 0x02 /*!< Connector LE6. 2 PIN. L6-2 pin on U7. */
#define NUM_4_LED_GREEN 0x03 /*!< Connector LE6. 1 PIN. L6-3 pin on U7. */
#define CHANNEL_1 0x08
#define CHANNEL_2 0x04
#define CHANNEL_3 0x02
#define CHANNEL_4 0x01
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct
{
char *_pn;
char *_doc;
char *_channel_1;
char *_channel_2;
char *_channel_3;
char *_channel_4;
uint8_t _used_channel;
} _component_t;
const _component_t _component[] =
{
{"SELECT P/N", "N/A", "N/A", "N/A", "N/A", "N/A", 0x00},
{"30-2581-3", "334230", "LOGO", "N/A", "N/A", "N/A", 0x08},
{"4298117", "334612", "400W", "600W", "N/A", "N/A", 0x0C},
{"4236534", "334303", "RUNW", "N/A", "N/A", "N/A", 0x08},
{"8000306Y00", "334303", "RUNW", "N/A", "N/A", "N/A", 0x08},
{"8000281Y00", "334303", "RUNW", "N/A", "N/A", "N/A", 0x08},
{"4292491", "334711", "LOGO", "N/A", "N/A", "N/A", 0x08},
{"4328733", "334711", "LOGO", "N/A", "N/A", "N/A", 0x08},
{"4358532", "334711", "LOGO", "N/A", "N/A", "N/A", 0x08},
{"ANY", "ANY ", "RED", "GRN", "ORG", "WHT", 0x0F}};
#ifdef __cplusplus
}
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 MiB

File diff suppressed because it is too large Load Diff

13
platformio.ini Normal file
View File

@@ -0,0 +1,13 @@
[env:ATmega328P]
platform = atmelavr
board = ATmega328P
board_build.mcu = atmega328p
board_build.f_cpu = 8000000L
framework = arduino
upload_protocol = usbasp
board_fuses.hfuse = 0xDF
board_fuses.lfuse = 0xE2
board_fuses.efuse = 0x07
upload_flags =
-Pusb
-e

2252
sdkconfig

File diff suppressed because it is too large Load Diff

467
src/ate0003.c Normal file
View File

@@ -0,0 +1,467 @@
#include "FreeRTOS.h"
#include "task.h"
#include "avr/io.h"
#include "zh_avr_160x_i2c.h"
#include "zh_avr_encoder.h"
#include "zh_avr_ac_dimmer.h"
#include "ate0003.h"
// #define DEBUG
#define SYSTEM_SETUP_STACK 189
#define ENCODER_STACK 165
#define PCF8574_STACK 105
const char *component_cmm[] = {component_1_cmm, component_2_cmm, component_3_cmm, component_4_cmm, component_5_cmm};
const char *component_line_1[] = {component_1_line_1, component_2_line_1, component_3_line_1, component_4_line_1, component_5_line_1};
const char *component_line_2[] = {component_1_line_2, component_2_line_2, component_3_line_2, component_4_line_2, component_5_line_2};
const uint8_t component_channel[] = {0x0F, 0x04, 0x02, 0x08, 0x0C};
#ifdef DEBUG
#define BAUD_RATE 9600
#define BAUD_PRESCALE (F_CPU / 16 / BAUD_RATE - 1)
int usart(char byte, FILE *stream)
{
while ((UCSR0A & (1 << UDRE0)) == 0)
{
}
UDR0 = byte;
return 0;
}
FILE uart = FDEV_SETUP_STREAM(usart, NULL, _FDEV_SETUP_WRITE);
#endif
void system_setup_task(void *pvParameters);
void component_setup_function(uint8_t component);
void relay_on_function(uint8_t relay_number);
void relay_off_function(uint8_t relay_number);
TaskHandle_t system_setup_task_handle = {0};
zh_avr_pcf8574_handle_t button_handle = {0};
zh_avr_pcf8574_handle_t led1_handle = {0};
zh_avr_pcf8574_handle_t led2_handle = {0};
zh_avr_pcf8574_handle_t relay_handle = {0};
zh_avr_pcf8574_handle_t lcd_handle = {0};
zh_avr_encoder_handle_t power_encoder_handle = {0};
zh_avr_encoder_handle_t component_encoder_handle = {0};
volatile static bool is_work = false; // Work status.
volatile static bool is_dmm = false; // DMM using status.
volatile static bool is_fix = false; // FIX button status.
volatile static uint8_t permitted_channels = 0; // Permitted channels. Depends of the selected component.
volatile static uint8_t used_channels = 0; // Counter of currently enabled channels.
volatile static bool is_initialized = false; // Normal loading status.
volatile static bool is_num1_fixed = false; // NUM 1 button FIX status.
volatile static bool is_num2_fixed = false; // NUM 2 button FIX status.
volatile static bool is_num3_fixed = false; // NUM 3 button FIX status.
volatile static bool is_num4_fixed = false; // NUM 4 button FIX status.
int main(void)
{
#ifdef DEBUG
UBRR0H = (BAUD_PRESCALE >> 8);
UBRR0L = BAUD_PRESCALE;
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
stdout = &uart;
#endif
xTaskCreate(system_setup_task, "system_setup", SYSTEM_SETUP_STACK, NULL, tskIDLE_PRIORITY, &system_setup_task_handle);
vTaskStartScheduler();
return 0;
}
#ifdef DEBUG
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
{
printf("Task %s Stack Owerflow.\n", pcTaskName);
printf("Free Heap %d.\n", xPortGetFreeHeapSize());
}
#endif
void system_setup_task(void *pvParameters)
{
char text_buffer[LCD_TEXT_BUFFER];
zh_avr_i2c_master_init(false);
zh_avr_pcf8574_init_config_t pcf8574_init_config = ZH_AVR_PCF8574_INIT_CONFIG_DEFAULT();
pcf8574_init_config.stack_size = PCF8574_STACK;
//** LED 1 extender init. **/
pcf8574_init_config.i2c_address = LED1_I2C_ADDRESS;
zh_avr_pcf8574_init(&pcf8574_init_config, &led1_handle);
zh_avr_pcf8574_write(&led1_handle, 0xFF);
//** LED 2 extender init. **/
pcf8574_init_config.i2c_address = LED2_I2C_ADDRESS;
zh_avr_pcf8574_init(&pcf8574_init_config, &led2_handle);
zh_avr_pcf8574_write(&led2_handle, 0xFF);
//** RELAY extender init. **/
pcf8574_init_config.i2c_address = RELAY_I2C_ADDRESS;
zh_avr_pcf8574_init(&pcf8574_init_config, &relay_handle);
zh_avr_pcf8574_write(&relay_handle, 0x00);
//** LCD init. **/
pcf8574_init_config.i2c_address = LCD_I2C_ADDRESS;
zh_avr_pcf8574_init(&pcf8574_init_config, &lcd_handle);
zh_avr_160x_init(&lcd_handle, ZH_LCD_16X4);
//** BUTTON extender init. **/
pcf8574_init_config.p0_gpio_work_mode = true;
pcf8574_init_config.p1_gpio_work_mode = true;
pcf8574_init_config.p2_gpio_work_mode = true;
pcf8574_init_config.p3_gpio_work_mode = true;
pcf8574_init_config.p4_gpio_work_mode = true;
pcf8574_init_config.p5_gpio_work_mode = true;
pcf8574_init_config.interrupt_port = AVR_PORTD;
pcf8574_init_config.interrupt_gpio = PORTD2;
pcf8574_init_config.i2c_address = BUTTON_I2C_ADDRESS;
zh_avr_pcf8574_init(&pcf8574_init_config, &button_handle);
//** Loading. Just for fun. **/
zh_avr_160x_set_cursor(&lcd_handle, 0, 0);
strcpy_P(text_buffer, text_company);
zh_avr_160x_print_char(&lcd_handle, text_buffer);
zh_avr_160x_set_cursor(&lcd_handle, 1, 0);
strcpy_P(text_buffer, text_model);
zh_avr_160x_print_char(&lcd_handle, text_buffer);
zh_avr_160x_set_cursor(&lcd_handle, 2, 0);
strcpy_P(text_buffer, text_firmware);
zh_avr_160x_print_char(&lcd_handle, text_buffer);
for (uint8_t i = 0; i <= 100; i += 10)
{
zh_avr_160x_print_progress_bar(&lcd_handle, 3, i);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
//** LCD default text print. **/
zh_avr_160x_lcd_clear(&lcd_handle);
zh_avr_160x_set_cursor(&lcd_handle, 0, 0);
strcpy_P(text_buffer, text_ac_power);
zh_avr_160x_print_char(&lcd_handle, text_buffer);
zh_avr_160x_set_cursor(&lcd_handle, 0, 11);
zh_avr_160x_print_int(&lcd_handle, 100);
zh_avr_160x_print_char(&lcd_handle, "%");
zh_avr_160x_set_cursor(&lcd_handle, 1, 0);
strcpy_P(text_buffer, text_component);
zh_avr_160x_print_char(&lcd_handle, text_buffer);
//**"ANY" component setup after loading. **/
zh_avr_pcf8574_write_gpio(&led1_handle, DMM_LED_RED, LED_ON);
zh_avr_pcf8574_write_gpio(&led1_handle, FIX_LED_BLUE, LED_ON);
zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_ON);
component_setup_function(0);
//** Encoders init **/
zh_avr_encoder_init_config_t encoder_init_config = ZH_AVR_ENCODER_INIT_CONFIG_DEFAULT();
encoder_init_config.stack_size = ENCODER_STACK;
encoder_init_config.queue_size = 5;
encoder_init_config.gpio_port = AVR_PORTC;
encoder_init_config.a_gpio_number = PORTC0;
encoder_init_config.b_gpio_number = PORTC1;
encoder_init_config.encoder_min_value = 0;
encoder_init_config.encoder_max_value = 100;
encoder_init_config.encoder_step = 5;
encoder_init_config.encoder_number = POWER_ENCODER;
zh_avr_encoder_init(&encoder_init_config, &power_encoder_handle);
zh_avr_encoder_set(&power_encoder_handle, 100);
encoder_init_config.a_gpio_number = PORTC2;
encoder_init_config.b_gpio_number = PORTC3;
encoder_init_config.encoder_min_value = 0;
encoder_init_config.encoder_max_value = (sizeof(component_cmm) / sizeof(component_cmm[0])) - 1;
encoder_init_config.encoder_step = 1;
encoder_init_config.encoder_number = COMPONENT_ENCODER;
zh_avr_encoder_init(&encoder_init_config, &component_encoder_handle);
zh_avr_encoder_set(&component_encoder_handle, 0);
//** AC dimmer init **/
zh_avr_ac_dimmer_init_config_t ac_dimmer_init_config = ZH_AVR_AC_DIMMER_INIT_CONFIG_DEFAULT();
ac_dimmer_init_config.ac_dimmer_frequency = ZH_50HZ;
ac_dimmer_init_config.zero_cross_port = AVR_PORTD;
ac_dimmer_init_config.zero_cross_gpio = PORTD3;
ac_dimmer_init_config.triac_port = AVR_PORTD;
ac_dimmer_init_config.triac_gpio = PORTD4;
zh_avr_ac_dimmer_init(&ac_dimmer_init_config);
zh_avr_ac_dimmer_set(100);
is_initialized = true;
#ifdef DEBUG
printf("%d.\n", uxTaskGetStackHighWaterMark(NULL));
#endif
vTaskDelete(NULL);
}
void zh_avr_pcf8574_event_handler(zh_avr_pcf8574_event_on_isr_t *event)
{
switch (event->gpio_number)
{
case DMM_BUTTON:
if (event->gpio_level == LOW && is_work == false)
{
if (is_dmm == true)
{
zh_avr_pcf8574_write_gpio(&led1_handle, DMM_LED_RED, LED_ON);
zh_avr_pcf8574_write_gpio(&led1_handle, DMM_LED_GREEN, LED_OFF);
zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_ON);
is_dmm = false;
}
else
{
zh_avr_pcf8574_write_gpio(&led1_handle, DMM_LED_RED, LED_OFF);
zh_avr_pcf8574_write_gpio(&led1_handle, DMM_LED_GREEN, LED_ON);
zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_OFF);
is_dmm = true;
}
}
break;
case FIX_BUTTON:
if (event->gpio_level == LOW)
{
zh_avr_pcf8574_write_gpio(&led1_handle, FIX_LED_BLUE, LED_OFF);
zh_avr_pcf8574_write_gpio(&led1_handle, FIX_LED_GREEN, LED_ON);
is_fix = true;
}
else
{
zh_avr_pcf8574_write_gpio(&led1_handle, FIX_LED_BLUE, LED_ON);
zh_avr_pcf8574_write_gpio(&led1_handle, FIX_LED_GREEN, LED_OFF);
is_fix = false;
}
break;
case NUM1_BUTTON:
if ((permitted_channels & CHANNEL1) == 0)
{
break;
}
if (event->gpio_level == LOW)
{
if (is_num1_fixed == true)
{
break;
}
zh_avr_pcf8574_write_gpio(&led1_handle, NUM1_LED_BLUE, LED_OFF);
zh_avr_pcf8574_write_gpio(&led1_handle, NUM1_LED_GREEN, LED_ON);
relay_on_function(L1_RELAY);
}
else
{
if (is_fix == true)
{
is_num1_fixed = true;
break;
}
zh_avr_pcf8574_write_gpio(&led1_handle, NUM1_LED_BLUE, LED_ON);
zh_avr_pcf8574_write_gpio(&led1_handle, NUM1_LED_GREEN, LED_OFF);
relay_off_function(L1_RELAY);
is_num1_fixed = false;
}
break;
case NUM2_BUTTON:
if ((permitted_channels & CHANNEL2) == 0)
{
break;
}
if (event->gpio_level == LOW)
{
if (is_num2_fixed == true)
{
break;
}
zh_avr_pcf8574_write_gpio(&led1_handle, NUM2_LED_BLUE, LED_OFF);
zh_avr_pcf8574_write_gpio(&led1_handle, NUM2_LED_GREEN, LED_ON);
relay_on_function(L2_RELAY);
}
else
{
if (is_fix == true)
{
is_num2_fixed = true;
break;
}
zh_avr_pcf8574_write_gpio(&led1_handle, NUM2_LED_BLUE, LED_ON);
zh_avr_pcf8574_write_gpio(&led1_handle, NUM2_LED_GREEN, LED_OFF);
relay_off_function(L2_RELAY);
is_num2_fixed = false;
}
break;
case NUM3_BUTTON:
if ((permitted_channels & CHANNEL3) == 0)
{
break;
}
if (event->gpio_level == LOW)
{
if (is_num3_fixed == true)
{
break;
}
zh_avr_pcf8574_write_gpio(&led2_handle, NUM3_LED_BLUE, LED_OFF);
zh_avr_pcf8574_write_gpio(&led2_handle, NUM3_LED_GREEN, LED_ON);
relay_on_function(L3_RELAY);
}
else
{
if (is_fix == true)
{
is_num3_fixed = true;
break;
}
zh_avr_pcf8574_write_gpio(&led2_handle, NUM3_LED_BLUE, LED_ON);
zh_avr_pcf8574_write_gpio(&led2_handle, NUM3_LED_GREEN, LED_OFF);
relay_off_function(L3_RELAY);
is_num3_fixed = false;
}
break;
case NUM4_BUTTON:
if ((permitted_channels & CHANNEL4) == 0)
{
break;
}
if (event->gpio_level == LOW)
{
if (is_num4_fixed == true)
{
break;
}
zh_avr_pcf8574_write_gpio(&led2_handle, NUM4_LED_BLUE, LED_OFF);
zh_avr_pcf8574_write_gpio(&led2_handle, NUM4_LED_GREEN, LED_ON);
relay_on_function(L4_RELAY);
}
else
{
if (is_fix == true)
{
is_num4_fixed = true;
break;
}
zh_avr_pcf8574_write_gpio(&led2_handle, NUM4_LED_BLUE, LED_ON);
zh_avr_pcf8574_write_gpio(&led2_handle, NUM4_LED_GREEN, LED_OFF);
relay_off_function(L4_RELAY);
is_num4_fixed = false;
}
break;
default:
break;
}
#ifdef DEBUG
printf("%d.\n", uxTaskGetStackHighWaterMark(NULL));
#endif
}
void zh_avr_encoder_event_handler(zh_avr_encoder_event_on_isr_t *event)
{
switch (event->encoder_number)
{
case POWER_ENCODER:
zh_avr_160x_set_cursor(&lcd_handle, 0, 11);
zh_avr_160x_print_int(&lcd_handle, (uint8_t)event->encoder_position);
zh_avr_160x_print_char(&lcd_handle, "% ");
zh_avr_ac_dimmer_set(event->encoder_position);
break;
case COMPONENT_ENCODER:
component_setup_function((uint8_t)event->encoder_position);
break;
default:
break;
}
#ifdef DEBUG
printf("%d.\n", uxTaskGetStackHighWaterMark(NULL));
#endif
}
ISR(PCINT1_vect)
{
if (is_initialized == false)
{
return;
}
if (zh_avr_encoder_isr_handler(&power_encoder_handle) == pdTRUE)
{
portYIELD();
}
if (is_work == false)
{
if (zh_avr_encoder_isr_handler(&component_encoder_handle) == pdTRUE)
{
portYIELD();
}
}
}
ISR(PCINT2_vect)
{
if (is_initialized == false)
{
return;
}
zh_avr_ac_dimmer_isr_handler();
if (zh_avr_pcf8574_isr_handler() == pdTRUE)
{
portYIELD();
}
}
void component_setup_function(uint8_t component)
{
char text_buffer[LCD_TEXT_BUFFER];
permitted_channels = component_channel[component];
zh_avr_160x_set_cursor(&lcd_handle, 1, 10);
strcpy_P(text_buffer, component_cmm[component]);
zh_avr_160x_print_char(&lcd_handle, text_buffer);
zh_avr_160x_set_cursor(&lcd_handle, 2, 0);
strcpy_P(text_buffer, component_line_1[component]);
zh_avr_160x_print_char(&lcd_handle, text_buffer);
zh_avr_160x_set_cursor(&lcd_handle, 3, 0);
strcpy_P(text_buffer, component_line_2[component]);
zh_avr_160x_print_char(&lcd_handle, text_buffer);
zh_avr_pcf8574_write(&led1_handle, is_dmm == true ? 0xF9 : 0xFA);
zh_avr_pcf8574_write(&led2_handle, 0x0F);
if ((permitted_channels & CHANNEL1) == CHANNEL1)
{
zh_avr_pcf8574_write_gpio(&led1_handle, NUM1_LED_BLUE, LED_ON);
}
if ((permitted_channels & CHANNEL2) == CHANNEL2)
{
zh_avr_pcf8574_write_gpio(&led1_handle, NUM2_LED_BLUE, LED_ON);
}
if ((permitted_channels & CHANNEL3) == CHANNEL3)
{
zh_avr_pcf8574_write_gpio(&led2_handle, NUM3_LED_BLUE, LED_ON);
}
if ((permitted_channels & CHANNEL4) == CHANNEL4)
{
zh_avr_pcf8574_write_gpio(&led2_handle, NUM4_LED_BLUE, LED_ON);
}
}
void relay_on_function(uint8_t relay_number)
{
if (++used_channels > 1) // If any other channel already work.
{
zh_avr_ac_dimmer_stop();
vTaskDelay(1);
zh_avr_pcf8574_write_gpio(&relay_handle, relay_number, RELAY_ON);
vTaskDelay(10);
zh_avr_ac_dimmer_start();
}
else
{
is_work = true;
zh_avr_pcf8574_write_gpio(&relay_handle, relay_number, RELAY_ON);
zh_avr_pcf8574_write_gpio(&relay_handle, GROUND_RELAY, RELAY_ON);
vTaskDelay(10);
zh_avr_ac_dimmer_start();
}
}
void relay_off_function(uint8_t relay_number)
{
if (--used_channels > 0) // If any other channel already work.
{
zh_avr_ac_dimmer_stop();
vTaskDelay(1);
zh_avr_pcf8574_write_gpio(&relay_handle, relay_number, RELAY_OFF);
vTaskDelay(10);
zh_avr_ac_dimmer_start();
}
else
{
zh_avr_ac_dimmer_stop();
vTaskDelay(1);
zh_avr_pcf8574_write_gpio(&relay_handle, relay_number, RELAY_OFF);
zh_avr_pcf8574_write_gpio(&relay_handle, GROUND_RELAY, RELAY_OFF);
is_work = false;
}
}

88
src/ate0003.h Normal file
View File

@@ -0,0 +1,88 @@
#pragma once
#include "stdint.h"
#define HIGH true
#define LOW false
#define LED_OFF HIGH
#define LED_ON LOW
#define RELAY_OFF LOW
#define RELAY_ON HIGH
#define LCD_TEXT_BUFFER 16
#define BUTTON_I2C_ADDRESS 0x27 // U5.
#define LED1_I2C_ADDRESS 0x25 // U6.
#define LED2_I2C_ADDRESS 0x26 // U7.
#define RELAY_I2C_ADDRESS 0x23 // U8.
#define LCD_I2C_ADDRESS 0x24 // U4.
#define GROUND_RELAY 0x00 // Relay K1. RL1 pin on U8.
#define DMM_RELAY 0x01 // Relay K2. RL2 pin on U8.
#define L1_RELAY 0x03 // Relay K4. RL4 pin on U8.
#define L2_RELAY 0x04 // Relay K3. RL3 pin on U8.
#define L3_RELAY 0x05 // Relay K6. RL6 pin on U8.
#define L4_RELAY 0x02 // Relay K5. RL5 pin on U8.
#define L5_RELAY 0x06 // Relay K7. RL7 pin on U8.
#define POWER_ENCODER 0x01 // Connector EN2.
#define COMPONENT_ENCODER 0x02 // Connector EN1.
#define DMM_BUTTON 0x00 // Connector BT1. BT1-0 on U5.
#define FIX_BUTTON 0x01 // Connector BT2. BT2-1 on U5.
#define NUM1_BUTTON 0x02 // Connector BT3. BT3-2 on U5.
#define NUM2_BUTTON 0x03 // Connector BT4. BT4-3 on U5.
#define NUM3_BUTTON 0x04 // Connector BT5. BT5-4 on U5.
#define NUM4_BUTTON 0x05 // Connector BT6. BT6-5 on U5.
#define DMM_LED_RED 0x00 // Connector LE1. 2 PIN. L1-0 pin on U6.
#define DMM_LED_GREEN 0x01 // Connector LE1. 1 PIN. L1-1 pin on U6.
#define FIX_LED_BLUE 0x02 // Connector LE2. 2 PIN. L2-2 pin on U6.
#define FIX_LED_GREEN 0x03 // Connector LE2. 1 PIN. L2-3 pin on U6.
#define NUM1_LED_BLUE 0x04 // Connector LE3. 2 PIN. L3-4 pin on U6.
#define NUM1_LED_GREEN 0x05 // Connector LE3. 1 PIN. L3-5 pin on U6.
#define NUM2_LED_BLUE 0x06 // Connector LE4. 2 PIN. L4-6 pin on U6.
#define NUM2_LED_GREEN 0x07 // Connector LE4. 1 PIN. L4-7 pin on U6.
#define NUM3_LED_BLUE 0x00 // Connector LE5. 2 PIN. L5-0 pin on U7.
#define NUM3_LED_GREEN 0x01 // Connector LE5. 1 PIN. L5-1 pin on U7.
#define NUM4_LED_BLUE 0x02 // Connector LE6. 2 PIN. L6-2 pin on U7.
#define NUM4_LED_GREEN 0x03 // Connector LE6. 1 PIN. L6-3 pin on U7.
#define CHANNEL1 0x08
#define CHANNEL2 0x04
#define CHANNEL3 0x02
#define CHANNEL4 0x01
#ifdef __cplusplus
extern "C"
{
#endif
const char text_company[] PROGMEM = "LLC AEROTECH";
const char text_model[] PROGMEM = "ATE0003.000.000";
const char text_firmware[] PROGMEM = "Firmware v1.0.0";
const char text_ac_power[] PROGMEM = "A/C POWER: ";
const char text_component[] PROGMEM = "COMPONENT: ";
const char component_1_cmm[] PROGMEM = " ANY ";
const char component_2_cmm[] PROGMEM = "334230";
const char component_3_cmm[] PROGMEM = "334303";
const char component_4_cmm[] PROGMEM = "334711";
const char component_5_cmm[] PROGMEM = "334612";
const char component_1_line_1[] PROGMEM = "1:RED 2:GREEN";
const char component_1_line_2[] PROGMEM = "3:ORANG 4:WHITE";
const char component_2_line_1[] PROGMEM = "1:N/A 2:LOGO ";
const char component_2_line_2[] PROGMEM = "3:N/A 4:N/A ";
const char component_3_line_1[] PROGMEM = "1:N/A 2:N/A ";
const char component_3_line_2[] PROGMEM = "3:RUNWA 4:N/A ";
const char component_4_line_1[] PROGMEM = "1:LOGO 2:N/A ";
const char component_4_line_2[] PROGMEM = "3:N/A 4:N/A ";
const char component_5_line_1[] PROGMEM = "1:400W 2:600W ";
const char component_5_line_2[] PROGMEM = "3:N/A 4:N/A ";
#ifdef __cplusplus
}
#endif