From 3c987360178f32143b49fec4a36a276f6a159aed Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Mon, 29 Sep 2025 10:54:54 +0300 Subject: [PATCH] wip: --- src/ate0003.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- src/ate0003.h | 5 +++++ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/ate0003.c b/src/ate0003.c index 6c1fe16..21ed550 100644 --- a/src/ate0003.c +++ b/src/ate0003.c @@ -38,7 +38,7 @@ const char component_5_line_2[] PROGMEM = "3: 4: "; 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[] = {0b0001111, 0b0001000, 0b0001000, 0b0001000, 0b0001100}; +const uint8_t component_channel[] = {0x0F, 0x08, 0x08, 0x08, 0x0C}; const char text_company[] PROGMEM = "LLC AEROTECH"; const char text_model[] PROGMEM = "ATE0003.000.000"; @@ -47,8 +47,6 @@ const char text_loading[] PROGMEM = "Loading:"; const char text_ac_power[] PROGMEM = "AC POWER: "; const char text_component[] PROGMEM = "COMPONENT: "; -static bool is_initialized = false; - #ifdef DEBUG #define BAUD_RATE 9600 #define BAUD_PRESCALE (F_CPU / 16 / BAUD_RATE - 1) @@ -80,10 +78,11 @@ 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 bool is_work = false; -volatile bool is_dmm = false; // DMM using status. -volatile bool is_fix = false; -volatile uint8_t component_num = 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. +static uint8_t current_channels = 0; // Permitted channels status. Depends of the selected component. +static bool is_initialized = false; // Normal loading status. int main(void) { @@ -107,7 +106,7 @@ int main(void) 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.ac_dimmer_frequency = ZH_60HZ; 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; @@ -132,16 +131,22 @@ void system_setup_task(void *pvParameters) 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 = 255; + //** LED 1 extender init. All LED off. DMM red on. FIX blue on. **/ pcf8574_init_config.i2c_address = LED1_I2C_ADDRESS; zh_avr_pcf8574_init(&pcf8574_init_config, &led1_handle); - zh_avr_pcf8574_write(&led1_handle, 0xFF); // All LED off. + zh_avr_pcf8574_write(&led1_handle, 0xFA); + //** LED 2 extender init. All LED off. **/ pcf8574_init_config.i2c_address = LED2_I2C_ADDRESS; zh_avr_pcf8574_init(&pcf8574_init_config, &led2_handle); - zh_avr_pcf8574_write(&led2_handle, 0xFF); // All LED off. + zh_avr_pcf8574_write(&led2_handle, 0xFF); + //** RELAY extender init. All relay off. DMM relay on. **/ pcf8574_init_config.i2c_address = RELAY_I2C_ADDRESS; zh_avr_pcf8574_init(&pcf8574_init_config, &relay_handle); + zh_avr_pcf8574_write(&relay_handle, 0x02); + //** LCD extender init **/ pcf8574_init_config.i2c_address = LCD_I2C_ADDRESS; zh_avr_pcf8574_init(&pcf8574_init_config, &lcd_handle); + //** 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; @@ -152,6 +157,7 @@ void system_setup_task(void *pvParameters) 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_init(&lcd_handle, ZH_LCD_16X4); zh_avr_160x_set_cursor(&lcd_handle, 0, 0); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_company)); @@ -168,11 +174,17 @@ void system_setup_task(void *pvParameters) zh_avr_160x_print_char(&lcd_handle, "%"); vTaskDelay(50 / portTICK_PERIOD_MS); } + //** Initial LCD text init. **/ zh_avr_160x_lcd_clear(&lcd_handle); zh_avr_160x_set_cursor(&lcd_handle, 0, 0); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_ac_power)); + zh_avr_160x_set_cursor(&lcd_handle, 0, 10); + zh_avr_160x_print_int(&lcd_handle, 100); + zh_avr_160x_print_char(&lcd_handle, "%"); zh_avr_160x_set_cursor(&lcd_handle, 1, 0); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_component)); + //**"ANY" component setup after loading **/ + current_channels = component_channel[0]; component_setup_function(0); is_initialized = true; vTaskDelete(NULL); @@ -309,4 +321,22 @@ void component_setup_function(uint8_t component) zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(component_line_1[component])); zh_avr_160x_set_cursor(&lcd_handle, 3, 0); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(component_line_2[component])); + zh_avr_pcf8574_write(&led1_handle, 0x0F); + zh_avr_pcf8574_write(&led2_handle, 0x0F); + if ((current_channels & (1 << CHANNEL_1)) == CHANNEL_1) + { + zh_avr_pcf8574_write_gpio(&led1_handle, NUM1_LED_BLUE, LED_ON); + } + if ((current_channels & (1 << CHANNEL_2)) == CHANNEL_2) + { + zh_avr_pcf8574_write_gpio(&led1_handle, NUM2_LED_BLUE, LED_ON); + } + if ((current_channels & (1 << CHANNEL_3)) == CHANNEL_3) + { + zh_avr_pcf8574_write_gpio(&led2_handle, NUM3_LED_BLUE, LED_ON); + } + if ((current_channels & (1 << CHANNEL_4)) == CHANNEL_4) + { + zh_avr_pcf8574_write_gpio(&led2_handle, NUM4_LED_BLUE, LED_ON); + } } \ No newline at end of file diff --git a/src/ate0003.h b/src/ate0003.h index 55ddec7..cb28006 100644 --- a/src/ate0003.h +++ b/src/ate0003.h @@ -48,6 +48,11 @@ #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 CHANNEL_1 0x08 +#define CHANNEL_2 0x04 +#define CHANNEL_3 0x02 +#define CHANNEL_4 0x01 + #ifdef __cplusplus extern "C" {