add: version.h
fix: refactor
This commit is contained in:
parent
532750da74
commit
f5f9be803c
36 changed files with 27 additions and 34 deletions
src/handlers
46
src/handlers/loop.c
Normal file
46
src/handlers/loop.c
Normal file
|
@ -0,0 +1,46 @@
|
|||
#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)
|
||||
{
|
||||
time_t timestamp = time(NULL);
|
||||
struct tm *time_struct = localtime(×tamp);
|
||||
LOG_DEBUG("===== IDLE LOOP START =====\n");
|
||||
for(uint_fast8_t i = 0; i < controller->relay_count; ++i)
|
||||
{
|
||||
relay_t *relay = controller->relays[i];
|
||||
int is_active = 0;
|
||||
if(relay_is_active(relay, time_struct))
|
||||
{
|
||||
LOG_DEBUG("relay %d is active\n", i);
|
||||
is_active = 1;
|
||||
}
|
||||
if(global_config.relay_configs[i].inverted)
|
||||
{
|
||||
is_active = !is_active;
|
||||
}
|
||||
switch(global_config.relay_configs[i].driver)
|
||||
{
|
||||
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\n", i);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue