add: relay/piface support

This commit is contained in:
Tobias Reisinger 2020-04-14 00:50:55 +02:00
parent fa6ceb2bf4
commit db64e4f820
34 changed files with 1259 additions and 313 deletions
models

44
models/period.c Normal file
View file

@ -0,0 +1,44 @@
#include <stdlib.h>
#include <logger.h>
#include <constants.h>
#include <models/period.h>
period_t*
period_create(uint16_t start, uint16_t end)
{
period_t *new_period = malloc(sizeof(period_t));
new_period->start = start;
new_period->end = end;
return new_period;
}
int
period_includes_time(period_t *period, uint16_t timestamp)
{
uint16_t start = period->start;
uint16_t end = period->end;
// "normal" timespan
if(start < end)
{
if(start <= timestamp && end > timestamp)
{
return 1;
}
return 0;
}
// timespan goes through 00:00
if(end < start)
{
if(start >= timestamp && end < timestamp)
{
return 1;
}
return 0;
}
return 0;
}