controller-legacy/handlers/loop.c

45 lines
1.2 KiB
C
Raw Normal View History

2020-04-16 19:19:56 +00:00
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <logger.h>
#include <models/controller.h>
#include <handlers.h>
#include <drivers.h>
#include <enums.h>
#include <helpers.h>
#include <wiringPi.h>
#include <wiring_debug.h>
void
handler_loop(controller_t *controller)
{
LOG_DEBUG("===== IDLE LOOP START =====");
for(uint_fast8_t i = 0; i < controller->relay_count; ++i)
{
relay_t *relay = controller->relays[i];
2020-04-16 23:38:25 +00:00
int is_active = 0;
2020-04-16 19:19:56 +00:00
if(relay_is_active(relay, time(NULL)))
{
LOG_DEBUG("relay %d is active", i);
2020-04-16 23:38:25 +00:00
is_active = 1;
2020-04-16 19:19:56 +00:00
}
2020-04-18 00:09:50 +00:00
if(global_config.relay_configs[i].inverted)
{
is_active = !is_active;
}
2020-04-16 23:38:25 +00:00
switch(global_config.relay_configs[i].driver)
2020-04-16 19:19:56 +00:00
{
2020-04-16 23:38:25 +00:00
case RELAY_DRIVER_GPIO:
driver_gpio_set(global_config.relay_configs[i].pin, is_active);
break;
case RELAY_DRIVER_PIFACE:
driver_piface_set(global_config.relay_configs[i].pin, is_active);
break;
default:
LOG_WARN("relay %d is not using a driver", i);
2020-04-16 19:19:56 +00:00
}
}
}