#include "main.h"
#include "ctrl_channel_button.h"

#define DUMMY_GPIO_Port B1_GPIO_Port
#define DUMMY_GPIO_Pin B1_Pin

static ButtonKey_t channel_buttons[BTN_CH_MAX];

void CTRL_channelButtonInit(void)
{
    channel_buttons[BTN_CH_1].instance = BTN_CH_1;
    channel_buttons[BTN_CH_1].buttonPressed = CTRL_pushedChanBtnEvent;
    channel_buttons[BTN_CH_1].buttonLongPressed = CTRL_longPushedChanBtnEvent;
    channel_buttons[BTN_CH_1].gpio_port = BTN_CH1_GPIO_Port;
    channel_buttons[BTN_CH_1].gpio_pin = BTN_CH1_Pin;
    channel_buttons[BTN_CH_1].pushed_state = GPIO_PIN_RESET;

    channel_buttons[BTN_CH_2].instance = BTN_CH_2;
    channel_buttons[BTN_CH_2].buttonPressed = CTRL_pushedChanBtnEvent;
    channel_buttons[BTN_CH_2].buttonLongPressed = CTRL_longPushedChanBtnEvent;
    channel_buttons[BTN_CH_2].gpio_port = BTN_CH2_GPIO_Port;
    channel_buttons[BTN_CH_2].gpio_pin = BTN_CH2_Pin;
    channel_buttons[BTN_CH_2].pushed_state = GPIO_PIN_RESET;

    channel_buttons[BTN_CH_3].instance = BTN_CH_3;
    channel_buttons[BTN_CH_3].buttonPressed = CTRL_pushedChanBtnEvent;
    channel_buttons[BTN_CH_3].gpio_port = DUMMY_GPIO_Port;
    channel_buttons[BTN_CH_3].gpio_pin = DUMMY_GPIO_Pin;
    channel_buttons[BTN_CH_3].pushed_state = GPIO_PIN_RESET;

    channel_buttons[BTN_CH_4].instance = BTN_CH_4;
    channel_buttons[BTN_CH_4].buttonPressed = CTRL_pushedChanBtnEvent;
    channel_buttons[BTN_CH_4].gpio_port = DUMMY_GPIO_Port;
    channel_buttons[BTN_CH_4].gpio_pin = DUMMY_GPIO_Pin;
    channel_buttons[BTN_CH_4].pushed_state = GPIO_PIN_RESET;

    channel_buttons[BTN_CH_5].instance = BTN_CH_5;
    channel_buttons[BTN_CH_5].buttonPressed = CTRL_pushedChanBtnEvent;
    channel_buttons[BTN_CH_5].gpio_port = DUMMY_GPIO_Port;
    channel_buttons[BTN_CH_5].gpio_pin = DUMMY_GPIO_Pin;
    channel_buttons[BTN_CH_5].pushed_state = GPIO_PIN_RESET;

    channel_buttons[BTN_CH_6].instance = BTN_CH_6;
    channel_buttons[BTN_CH_6].buttonPressed = CTRL_pushedChanBtnEvent;
    channel_buttons[BTN_CH_6].gpio_port = DUMMY_GPIO_Port;
    channel_buttons[BTN_CH_6].gpio_pin = DUMMY_GPIO_Pin;
    channel_buttons[BTN_CH_6].pushed_state = GPIO_PIN_RESET;

    for (HW_chanBtnName_t btn_key = BTN_CH_1; btn_key < BTN_CH_MAX; btn_key++)
    {
        channel_buttons[btn_key].state = IDLE;
        channel_buttons[btn_key].timer_debounce = BTN_DEFAULT_DEBOUNCE_MS;
        channel_buttons[btn_key].timer_long_pressed = BTN_DEFAULT_LONGPRESSED_MS;
        channel_buttons[btn_key].timer_repeat_delay = BTN_DEFAULT_REPEAT_MS;
    }
}

void CTRL_channelButtonsHandler(void)
{
    for (HW_chanBtnName_t btn_key = BTN_CH_1; btn_key < BTN_CH_MAX; btn_key++)
    {
        buttonHandler(&channel_buttons[btn_key]);
    }
}

__weak void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
{
    UNUSED(key);
}

__weak void CTRL_longPushedChanBtnEvent(ButtonKey_t *key)
{
    UNUSED(key);
}