wip:
This commit is contained in:
		@@ -6,6 +6,9 @@
 | 
			
		||||
#include "zh_avr_ac_dimmer.h"
 | 
			
		||||
#include "ate0003.h"
 | 
			
		||||
 | 
			
		||||
// #define configMINIMAL_STACK_SIZE                                        70
 | 
			
		||||
// #define configCHECK_FOR_STACK_OVERFLOW                                  1
 | 
			
		||||
 | 
			
		||||
#define DEBUG
 | 
			
		||||
 | 
			
		||||
const char *component_cmm[] = {component_1_cmm, component_2_cmm, component_3_cmm, component_4_cmm, component_5_cmm};
 | 
			
		||||
@@ -54,6 +57,7 @@ int main(void)
 | 
			
		||||
{
 | 
			
		||||
    //** Encoders init **/
 | 
			
		||||
    zh_avr_encoder_init_config_t encoder_init_config = ZH_AVR_ENCODER_INIT_CONFIG_DEFAULT();
 | 
			
		||||
    encoder_init_config.stack_size = 150;
 | 
			
		||||
    encoder_init_config.gpio_port = AVR_PORTC;
 | 
			
		||||
    encoder_init_config.a_gpio_number = PORTC0;
 | 
			
		||||
    encoder_init_config.b_gpio_number = PORTC1;
 | 
			
		||||
@@ -67,6 +71,7 @@ int main(void)
 | 
			
		||||
    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);
 | 
			
		||||
@@ -84,7 +89,7 @@ int main(void)
 | 
			
		||||
    UCSR0B = (1 << RXEN0) | (1 << TXEN0);
 | 
			
		||||
    UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
 | 
			
		||||
    stdout = &uart;
 | 
			
		||||
    xTaskCreate(system_setup_task, "system_setup", 150, NULL, tskIDLE_PRIORITY, &system_setup_task_handle);
 | 
			
		||||
    xTaskCreate(system_setup_task, "system_setup", 120, NULL, 4, &system_setup_task_handle);
 | 
			
		||||
#else
 | 
			
		||||
    xTaskCreate(system_setup_task, NULL, 150, NULL, tskIDLE_PRIORITY, NULL);
 | 
			
		||||
#endif
 | 
			
		||||
@@ -94,9 +99,10 @@ int main(void)
 | 
			
		||||
 | 
			
		||||
void system_setup_task(void *pvParameters)
 | 
			
		||||
{
 | 
			
		||||
    char text_buffer[17];
 | 
			
		||||
    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;
 | 
			
		||||
    pcf8574_init_config.stack_size = 150;
 | 
			
		||||
    //** 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);
 | 
			
		||||
@@ -126,16 +132,21 @@ void system_setup_task(void *pvParameters)
 | 
			
		||||
    zh_avr_pcf8574_init(&pcf8574_init_config, &button_handle);
 | 
			
		||||
    //** Loading. Just for fun. **/
 | 
			
		||||
    zh_avr_160x_set_cursor(&lcd_handle, 0, 0);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_company));
 | 
			
		||||
    strcpy_P(text_buffer, text_company);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, text_buffer);
 | 
			
		||||
    zh_avr_160x_set_cursor(&lcd_handle, 1, 0);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_model));
 | 
			
		||||
    strcpy_P(text_buffer, text_model);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, text_buffer);
 | 
			
		||||
    zh_avr_160x_set_cursor(&lcd_handle, 2, 0);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_firmware));
 | 
			
		||||
    strcpy_P(text_buffer, text_firmware);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, text_buffer);
 | 
			
		||||
    vTaskDelay(1000 / portTICK_PERIOD_MS);
 | 
			
		||||
    zh_avr_160x_set_cursor(&lcd_handle, 3, 0);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_loading));
 | 
			
		||||
    strcpy_P(text_buffer, text_loading);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, text_buffer);
 | 
			
		||||
    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, 9);
 | 
			
		||||
        zh_avr_160x_print_int(&lcd_handle, i);
 | 
			
		||||
        zh_avr_160x_print_char(&lcd_handle, "%");
 | 
			
		||||
        vTaskDelay(50 / portTICK_PERIOD_MS);
 | 
			
		||||
@@ -143,12 +154,14 @@ void system_setup_task(void *pvParameters)
 | 
			
		||||
    //** LCD default text print. **/
 | 
			
		||||
    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);
 | 
			
		||||
    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);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(text_component));
 | 
			
		||||
    strcpy_P(text_buffer, text_component);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, text_buffer);
 | 
			
		||||
    //**"ANY" component setup after loading **/
 | 
			
		||||
    used_channels = component_channel[0];
 | 
			
		||||
    component_setup_function(0);
 | 
			
		||||
@@ -165,6 +178,7 @@ void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
 | 
			
		||||
 | 
			
		||||
void zh_avr_pcf8574_event_handler(zh_avr_pcf8574_event_on_isr_t *event)
 | 
			
		||||
{
 | 
			
		||||
    // portENTER_CRITICAL();
 | 
			
		||||
    switch (event->gpio_number)
 | 
			
		||||
    {
 | 
			
		||||
    case DMM_BUTTON:
 | 
			
		||||
@@ -174,14 +188,16 @@ void zh_avr_pcf8574_event_handler(zh_avr_pcf8574_event_on_isr_t *event)
 | 
			
		||||
            {
 | 
			
		||||
                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);
 | 
			
		||||
                // zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_ON);
 | 
			
		||||
                // zh_avr_pcf8574_write(&relay_handle, 0xFF);
 | 
			
		||||
                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);
 | 
			
		||||
                // zh_avr_pcf8574_write_gpio(&relay_handle, DMM_RELAY, RELAY_OFF);
 | 
			
		||||
                // zh_avr_pcf8574_write(&relay_handle, 0x00);
 | 
			
		||||
                is_dmm = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -276,16 +292,18 @@ void zh_avr_pcf8574_event_handler(zh_avr_pcf8574_event_on_isr_t *event)
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
    printf("Interrupt happened on device address 0x%02X on GPIO number %d at level %d.\n", event->i2c_address, event->gpio_number, event->gpio_level);
 | 
			
		||||
    // printf("Interrupt happened on device address 0x%02X on GPIO number %d at level %d.\n", event->i2c_address, event->gpio_number, event->gpio_level);
 | 
			
		||||
#endif
 | 
			
		||||
    // portEXIT_CRITICAL();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void zh_avr_encoder_event_handler(zh_avr_encoder_event_on_isr_t *event)
 | 
			
		||||
{
 | 
			
		||||
    // portENTER_CRITICAL();
 | 
			
		||||
    switch (event->encoder_number)
 | 
			
		||||
    {
 | 
			
		||||
    case POWER_ENCODER:
 | 
			
		||||
        zh_avr_160x_set_cursor(&lcd_handle, 0, 10);
 | 
			
		||||
        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);
 | 
			
		||||
@@ -297,8 +315,9 @@ void zh_avr_encoder_event_handler(zh_avr_encoder_event_on_isr_t *event)
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
    printf("Encoder number %d position %0.2f.\n", event->encoder_number, event->encoder_position);
 | 
			
		||||
    // printf("Encoder number %d position %d.\n", event->encoder_number, (uint8_t)event->encoder_position);
 | 
			
		||||
#endif
 | 
			
		||||
    // portEXIT_CRITICAL();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ISR(PCINT1_vect)
 | 
			
		||||
@@ -345,14 +364,18 @@ ISR(PCINT2_vect)
 | 
			
		||||
 | 
			
		||||
void component_setup_function(uint8_t component)
 | 
			
		||||
{
 | 
			
		||||
    char text_buffer[17];
 | 
			
		||||
    zh_avr_160x_set_cursor(&lcd_handle, 1, 10);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(component_cmm[component]));
 | 
			
		||||
    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);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, pgm_read_ptr(component_line_1[component]));
 | 
			
		||||
    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);
 | 
			
		||||
    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);
 | 
			
		||||
    strcpy_P(text_buffer, component_line_2[component]);
 | 
			
		||||
    zh_avr_160x_print_char(&lcd_handle, text_buffer);
 | 
			
		||||
    // zh_avr_pcf8574_write(&led1_handle, 0xF0);
 | 
			
		||||
    // zh_avr_pcf8574_write(&led2_handle, 0x0F);
 | 
			
		||||
    if ((used_channels & (1 << CHANNEL1)) == CHANNEL1)
 | 
			
		||||
    {
 | 
			
		||||
        zh_avr_pcf8574_write_gpio(&led1_handle, NUM1_LED_BLUE, LED_ON);
 | 
			
		||||
 
 | 
			
		||||
@@ -62,25 +62,25 @@ extern "C"
 | 
			
		||||
    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_ac_power[] PROGMEM = "A/C POWER: ";
 | 
			
		||||
    const char text_component[] PROGMEM = "COMPONENT: ";
 | 
			
		||||
 | 
			
		||||
    const char component_1_cmm[] PROGMEM = "ANY   ";
 | 
			
		||||
    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:BLUE 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:RUNW 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  ";
 | 
			
		||||
    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: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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user