Ready to implement GPIO logic to manage relays
This commit is contained in:
28
esp32_device/main/relays.c
Normal file
28
esp32_device/main/relays.c
Normal 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");
|
||||
}
|
Reference in New Issue
Block a user