This commit is contained in:
2025-11-30 13:27:20 +03:00
parent f8bc7e65ff
commit 4239dd8bf2
2 changed files with 104 additions and 25 deletions

View File

@@ -17,7 +17,7 @@ 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 bool _is_initialized = false;
volatile static uint8_t _current_component = 0;
volatile static bool _is_num_1_fixed = false;
volatile static bool _is_num_2_fixed = false;
@@ -29,6 +29,7 @@ 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);
@@ -42,12 +43,15 @@ void app_main(void)
esp_event_loop_create_default();
_zh_wifi_softap_init();
_zh_webserver_init();
// _zh_encoder_init();
// _zh_ac_dimmer_init();
_zh_pcf8574_init();
// zh_pcf8574_write_gpio(&led_handle, TS_LED_GREEN, LED_ON);
// zh_pcf8574_write_gpio(&led_handle, RET_LED_BLUE, LED_ON);
// zh_pcf8574_write_gpio(&led_handle, EXT_LED_BLUE, LED_ON);
_zh_system_load();
_zh_encoder_init();
_zh_ac_dimmer_init();
gpio_set_level(GPIO_NUM_4, 1);
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)
@@ -80,18 +84,18 @@ 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 = PORTC0;
// config.b_gpio_number = PORTC1;
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 = 5;
config.encoder_number = POWER_ENCODER;
zh_encoder_init(&config, &_power_encoder_handle);
zh_encoder_set(&_power_encoder_handle, 100);
// config.a_gpio_number = PORTC2;
// config.b_gpio_number = PORTC3;
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_cmm) / sizeof(component_cmm[0])) - 1;
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);
@@ -138,6 +142,32 @@ static void _zh_pcf8574_init(void)
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;
@@ -299,12 +329,22 @@ static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, in
switch (event->encoder_number)
{
case POWER_ENCODER:
zh_160x_set_cursor(&_lcd_handle, 0, 11);
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(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:
@@ -314,19 +354,33 @@ static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, in
static void _zh_component_select(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);
_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);

View File

@@ -72,6 +72,31 @@ 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