This commit is contained in:
2025-09-29 09:12:10 +03:00
parent 751c8ee385
commit d08c591b11
3 changed files with 92 additions and 35 deletions

View File

@@ -8,13 +8,46 @@
// #define DEBUG // #define DEBUG
const component_t component[] = { // const component_t component[] = {
{"ANY", "RED", "GREEN", "BLUE", "WHITE", 0xF}, // {"ANY ", "1:RED 2:GREEN", "3:BLUE 4:WHITE", 0b0001111},
{"334230", "RED", "", "", "", 0x8}, // {"334230", "RED", "", 0x8},
{"334303", "RED", "", "", "", 0x8}, // {"334303", "RED", "", 0x8},
{"334711", "RED", "", "", "", 0x8}, // {"334711", "RED", "", 0x8},
{"334612", "400W", "600W", "", "", 0xC}, // {"334612", "1:400W 2:600W ", " ", 0xC},
}; // };
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_cmm[] = {component_1_cmm, component_2_cmm, component_3_cmm, component_4_cmm, component_5_cmm};
const char component_1_line_1[] PROGMEM = "1:RED 2:GREEN";
const char component_1_line_2[] PROGMEM = "3:BLUE 4:WHITE";
const char component_2_line_1[] PROGMEM = "1:RED 2: ";
const char component_2_line_2[] PROGMEM = "3: 4: ";
const char component_3_line_1[] PROGMEM = "1:RED 2: ";
const char component_3_line_2[] PROGMEM = "3: 4: ";
const char component_4_line_1[] PROGMEM = "1:RED 2: ";
const char component_4_line_2[] PROGMEM = "3: 4: ";
const char component_5_line_1[] PROGMEM = "1:400W 2:600W ";
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 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_loading[] PROGMEM = "Loading:";
const char text_ac_power[] PROGMEM = "AC POWER: ";
const char text_component[] PROGMEM = "COMPONENT: ";
static bool is_initialized = false;
#ifdef DEBUG #ifdef DEBUG
#define BAUD_RATE 9600 #define BAUD_RATE 9600
@@ -32,6 +65,7 @@ FILE uart = FDEV_SETUP_STREAM(usart, NULL, _FDEV_SETUP_WRITE);
#endif #endif
void system_setup_task(void *pvParameters); void system_setup_task(void *pvParameters);
void component_setup_function(uint8_t component);
#ifdef DEBUG #ifdef DEBUG
TaskHandle_t system_setup_task_handle = {0}; TaskHandle_t system_setup_task_handle = {0};
@@ -60,13 +94,14 @@ int main(void)
encoder_init_config.b_gpio_number = PORTC1; encoder_init_config.b_gpio_number = PORTC1;
encoder_init_config.encoder_min_value = 0; encoder_init_config.encoder_min_value = 0;
encoder_init_config.encoder_max_value = 100; encoder_init_config.encoder_max_value = 100;
encoder_init_config.encoder_step = 5;
encoder_init_config.encoder_number = POWER_ENCODER; encoder_init_config.encoder_number = POWER_ENCODER;
zh_avr_encoder_init(&encoder_init_config, &power_encoder_handle); zh_avr_encoder_init(&encoder_init_config, &power_encoder_handle);
zh_avr_encoder_set(&power_encoder_handle, 100); zh_avr_encoder_set(&power_encoder_handle, 100);
encoder_init_config.a_gpio_number = PORTC2; encoder_init_config.a_gpio_number = PORTC2;
encoder_init_config.b_gpio_number = PORTC3; encoder_init_config.b_gpio_number = PORTC3;
encoder_init_config.encoder_min_value = 0; encoder_init_config.encoder_min_value = 0;
encoder_init_config.encoder_max_value = (sizeof(component) / sizeof(component[0])) - 1; encoder_init_config.encoder_max_value = (sizeof(component_cmm) / sizeof(component_cmm[0])) - 1;
encoder_init_config.encoder_number = COMPONENT_ENCODER; encoder_init_config.encoder_number = COMPONENT_ENCODER;
zh_avr_encoder_init(&encoder_init_config, &component_encoder_handle); zh_avr_encoder_init(&encoder_init_config, &component_encoder_handle);
zh_avr_encoder_set(&component_encoder_handle, 0); zh_avr_encoder_set(&component_encoder_handle, 0);
@@ -99,10 +134,10 @@ void system_setup_task(void *pvParameters)
pcf8574_init_config.stack_size = 255; pcf8574_init_config.stack_size = 255;
pcf8574_init_config.i2c_address = LED1_I2C_ADDRESS; pcf8574_init_config.i2c_address = LED1_I2C_ADDRESS;
zh_avr_pcf8574_init(&pcf8574_init_config, &led1_handle); zh_avr_pcf8574_init(&pcf8574_init_config, &led1_handle);
zh_avr_pcf8574_write(&led1_handle, 0xFF); zh_avr_pcf8574_write(&led1_handle, 0xFF); // All LED off.
pcf8574_init_config.i2c_address = LED2_I2C_ADDRESS; pcf8574_init_config.i2c_address = LED2_I2C_ADDRESS;
zh_avr_pcf8574_init(&pcf8574_init_config, &led2_handle); zh_avr_pcf8574_init(&pcf8574_init_config, &led2_handle);
zh_avr_pcf8574_write(&led2_handle, 0x0F); zh_avr_pcf8574_write(&led2_handle, 0xFF); // All LED off.
pcf8574_init_config.i2c_address = RELAY_I2C_ADDRESS; pcf8574_init_config.i2c_address = RELAY_I2C_ADDRESS;
zh_avr_pcf8574_init(&pcf8574_init_config, &relay_handle); zh_avr_pcf8574_init(&pcf8574_init_config, &relay_handle);
pcf8574_init_config.i2c_address = LCD_I2C_ADDRESS; pcf8574_init_config.i2c_address = LCD_I2C_ADDRESS;
@@ -119,13 +154,13 @@ void system_setup_task(void *pvParameters)
zh_avr_pcf8574_init(&pcf8574_init_config, &button_handle); zh_avr_pcf8574_init(&pcf8574_init_config, &button_handle);
zh_avr_160x_init(&lcd_handle, ZH_LCD_16X4); zh_avr_160x_init(&lcd_handle, ZH_LCD_16X4);
zh_avr_160x_set_cursor(&lcd_handle, 0, 0); zh_avr_160x_set_cursor(&lcd_handle, 0, 0);
zh_avr_160x_print_char(&lcd_handle, "LLC AEROTECH"); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_company));
zh_avr_160x_set_cursor(&lcd_handle, 1, 0); zh_avr_160x_set_cursor(&lcd_handle, 1, 0);
zh_avr_160x_print_char(&lcd_handle, "ATE0003.000.000"); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_model));
zh_avr_160x_set_cursor(&lcd_handle, 2, 0); zh_avr_160x_set_cursor(&lcd_handle, 2, 0);
zh_avr_160x_print_char(&lcd_handle, "Firmware v1.0.0"); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_firmware));
zh_avr_160x_set_cursor(&lcd_handle, 3, 0); zh_avr_160x_set_cursor(&lcd_handle, 3, 0);
zh_avr_160x_print_char(&lcd_handle, "Loading: "); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_loading));
for (uint8_t i = 0; i <= 100; ++i) for (uint8_t i = 0; i <= 100; ++i)
{ {
zh_avr_160x_set_cursor(&lcd_handle, 3, 10); zh_avr_160x_set_cursor(&lcd_handle, 3, 10);
@@ -135,9 +170,11 @@ void system_setup_task(void *pvParameters)
} }
zh_avr_160x_lcd_clear(&lcd_handle); zh_avr_160x_lcd_clear(&lcd_handle);
zh_avr_160x_set_cursor(&lcd_handle, 0, 0); zh_avr_160x_set_cursor(&lcd_handle, 0, 0);
zh_avr_160x_print_char(&lcd_handle, "AC POWER: "); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_ac_power));
zh_avr_160x_set_cursor(&lcd_handle, 1, 0); zh_avr_160x_set_cursor(&lcd_handle, 1, 0);
zh_avr_160x_print_char(&lcd_handle, "COMPONENT: "); zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_component));
component_setup_function(0);
is_initialized = true;
vTaskDelete(NULL); vTaskDelete(NULL);
} }
@@ -157,16 +194,16 @@ void zh_avr_pcf8574_event_handler(zh_avr_pcf8574_event_on_isr_t *event)
{ {
if (is_dmm == true) if (is_dmm == true)
{ {
zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_ON);
zh_avr_pcf8574_write_gpio(&led1_handle, DMM_LED_RED, LED_ON); 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(&led1_handle, DMM_LED_GREEN, LED_OFF);
zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_ON);
is_dmm = false; is_dmm = false;
} }
else else
{ {
zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_OFF);
zh_avr_pcf8574_write_gpio(&led1_handle, DMM_LED_RED, LED_OFF); 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(&led1_handle, DMM_LED_GREEN, LED_ON);
zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_OFF);
is_dmm = true; is_dmm = true;
} }
} }
@@ -206,14 +243,13 @@ void zh_avr_encoder_event_handler(zh_avr_encoder_event_on_isr_t *event)
switch (event->encoder_number) switch (event->encoder_number)
{ {
case POWER_ENCODER: case POWER_ENCODER:
zh_avr_ac_dimmer_set(event->encoder_position);
zh_avr_160x_set_cursor(&lcd_handle, 0, 10); zh_avr_160x_set_cursor(&lcd_handle, 0, 10);
zh_avr_160x_print_int(&lcd_handle, (uint8_t)event->encoder_position); zh_avr_160x_print_int(&lcd_handle, (uint8_t)event->encoder_position);
zh_avr_160x_print_char(&lcd_handle, "% "); zh_avr_160x_print_char(&lcd_handle, "% ");
zh_avr_ac_dimmer_set(event->encoder_position);
break; break;
case COMPONENT_ENCODER: case COMPONENT_ENCODER:
zh_avr_160x_set_cursor(&lcd_handle, 1, 10); component_setup_function((uint8_t)event->encoder_position);
// Set system.
break; break;
default: default:
break; break;
@@ -225,6 +261,10 @@ void zh_avr_encoder_event_handler(zh_avr_encoder_event_on_isr_t *event)
ISR(PCINT1_vect) ISR(PCINT1_vect)
{ {
if (is_initialized == false)
{
return;
}
BaseType_t xHigherPriorityTaskWoken = pdFALSE; BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (zh_avr_encoder_isr_handler(&power_encoder_handle) == pdTRUE) if (zh_avr_encoder_isr_handler(&power_encoder_handle) == pdTRUE)
{ {
@@ -245,6 +285,10 @@ ISR(PCINT1_vect)
ISR(PCINT2_vect) ISR(PCINT2_vect)
{ {
if (is_initialized == false)
{
return;
}
BaseType_t xHigherPriorityTaskWoken = pdFALSE; BaseType_t xHigherPriorityTaskWoken = pdFALSE;
zh_avr_ac_dimmer_isr_handler(); zh_avr_ac_dimmer_isr_handler();
if (zh_avr_pcf8574_isr_handler() == pdTRUE) if (zh_avr_pcf8574_isr_handler() == pdTRUE)
@@ -255,4 +299,14 @@ ISR(PCINT2_vect)
{ {
portYIELD(); portYIELD();
} }
}
void component_setup_function(uint8_t component)
{
zh_avr_160x_set_cursor(&lcd_handle, 1, 10);
zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(component_cmm[component]));
zh_avr_160x_set_cursor(&lcd_handle, 2, 0);
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]));
} }

View File

@@ -11,11 +11,11 @@
#define RELAY_OFF LOW #define RELAY_OFF LOW
#define RELAY_ON HIGH #define RELAY_ON HIGH
#define BUTTON_I2C_ADDRESS 0x00 // U5. #define BUTTON_I2C_ADDRESS 0x27 // U5.
#define LED1_I2C_ADDRESS 0x00 // U6. #define LED1_I2C_ADDRESS 0x25 // U6.
#define LED2_I2C_ADDRESS 0x00 // U7. #define LED2_I2C_ADDRESS 0x26 // U7.
#define RELAY_I2C_ADDRESS 0x00 // U8. #define RELAY_I2C_ADDRESS 0x23 // U8.
#define LCD_I2C_ADDRESS 0x00 // U4. #define LCD_I2C_ADDRESS 0x24 // U4.
#define GROUND_RELAY 0x00 // Relay K1. RL1 pin on U8. #define GROUND_RELAY 0x00 // Relay K1. RL1 pin on U8.
#define DMM_RELAY 0x01 // Relay K2. RL2 pin on U8. #define DMM_RELAY 0x01 // Relay K2. RL2 pin on U8.
@@ -53,15 +53,18 @@ extern "C"
{ {
#endif #endif
typedef struct // typedef struct
{ // {
char *cmm; // char *cmm;
char *channel_1; // char *channel_1;
char *channel_2; // char *channel_2;
char *channel_3; // // char *channel_3;
char *channel_4; // // char *channel_4;
uint8_t button; // uint8_t button;
} component_t; // } component_t;
// void system_setup_task(void *pvParameters);
// void component_setup_function(zh_avr_encoder_event_on_isr_t *event);
#ifdef __cplusplus #ifdef __cplusplus
} }