46 lines
1 KiB
C
46 lines
1 KiB
C
#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];
|
|
if(relay_is_active(relay, time(NULL)))
|
|
{
|
|
LOG_DEBUG("relay %d is active", i);
|
|
if(relay->number >= 2)
|
|
{
|
|
driver_gpio_set(relay, HIGH);
|
|
}
|
|
else
|
|
{
|
|
driver_piface_set(relay, HIGH);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(relay->number >= 2)
|
|
{
|
|
driver_gpio_set(relay, LOW);
|
|
}
|
|
else
|
|
{
|
|
driver_piface_set(relay, LOW);
|
|
}
|
|
}
|
|
}
|
|
}
|