Initial commit

This commit is contained in:
2026-06-13 13:37:44 +02:00
commit 1b93e0cf91
14 changed files with 383 additions and 0 deletions

43
main/buttons/buttons.c Normal file
View File

@@ -0,0 +1,43 @@
#include "buttons.h"
#include "iot_button.h"
#include "button_gpio.h"
#include "esp_log.h"
#include "esp_err.h"
#include "esp_check.h"
static const char* TAG = "TrainThing/buttons";
const action actions[] = {
{.btnAcc = FRONT_LIGHT_INCREASE, .name = "FRONT_LIGHT_INCREASE", .pin = 1, .shortcut = 'a'},
{.btnAcc = FRONT_LIGHT_DECREASE, .name = "FRONT_LIGHT_DECREASE", .pin = 2, .shortcut = 'b'},
{.btnAcc = BACK_LIGHT_INCREASE, .name = "BACK_LIGHT_INCREASE", .pin = 3, .shortcut = 'c'},
{.btnAcc = BACK_LIGHT_DECREASE, .name = "BACK_LIGHT_DECREASE", .pin = 4, .shortcut = 'd'},
{.btnAcc = CAB_LIGHT, .name = "CAB_LIGHT", .pin = 5, .shortcut = 'e'},
{.btnAcc = WIPPERS, .name = "WIPPERS", .pin = 6, .shortcut = 'f'},
{.btnAcc = SANDER, .name = "SANDER", .pin = 7, .shortcut = 'g'},
{.btnAcc = STARTER, .name = "STARTER", .pin = 8, .shortcut = 'h'},
{.btnAcc = CUT, .name = "CUT", .pin = 9, .shortcut = 'i'},
{.btnAcc = HORN, .name = "HORN", .pin = 10, .shortcut = 'j'},
};
void button_event_cb(void *arg, void *data)
{
action *a = (action*)data;
button_event_t event = iot_button_get_event(arg);
ESP_LOGI(TAG, "%s pin:%d name:%s shortcut:%c", iot_button_get_event_str(event), (int)a->pin, (char*)a->name, (char)a->shortcut);
}
void initialize_buttons(){
const button_config_t btn_cfg = {0};
button_handle_t btns[5];
for (size_t i = 0; i < sizeof(actions) / sizeof(actions[0]); i++)
{
const button_gpio_config_t btn_gpio_cfg = {
.gpio_num = actions[i].pin,
.active_level = 0,
};
ESP_RETURN_VOID_ON_ERROR(iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &btns[i]), TAG, "");
iot_button_register_cb(btns[i], BUTTON_PRESS_DOWN, NULL, button_event_cb, (void *) &actions[i]);
}
}

30
main/buttons/buttons.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef BUTTONS_H
#define BUTTONS_H
typedef enum {
FRONT_LIGHT_INCREASE,
FRONT_LIGHT_DECREASE,
BACK_LIGHT_INCREASE,
BACK_LIGHT_DECREASE,
CAB_LIGHT,
WIPPERS,
SANDER,
STARTER,
CUT,
HORN,
}buttonAction;
typedef struct
{
buttonAction btnAcc;
const char* name;
char shortcut;
int pin;
}action;
void button_event_cb(void *arg, void *data);
void initialize_buttons();
#endif // BUTTONS_H