Ready to implement GPIO logic to manage relays

This commit is contained in:
2024-09-28 20:02:34 +02:00
parent e574bed96f
commit 274b7089d1
8 changed files with 86 additions and 6 deletions

View File

@ -0,0 +1,28 @@
#include <driver/gpio.h>
#include "esp_log.h"
#include "relays.h"
#include "constants.h"
static const char *TAG = "relays";
/**
* Device relays GPIO ids
*/
static int DEVICE_GPIO_IDS[5] = {2, 4, 12, 14, 15};
void relays_turn_off_all()
{
ESP_LOGI(TAG, "Turning off all relays...");
for (size_t i = 0; i < DEV_MAX_RELAYS; i++)
{
relays_set(i, false);
}
}
void relays_set(int number, bool is_on)
{
size_t gpio_id = DEVICE_GPIO_IDS[number];
ESP_LOGI(TAG, "Set relay %d (gpio %d) to %s", number, gpio_id, is_on ? "on" : "off");
}