Files
Shutter/timing.c
Derisis13 6bc23c92fe Version 1.4
Reworked channel changing: now it tracks the current ch. and resets only once. This makes the program to finish faster.
Added rolltime_down and percentage values to shutter structure: now the schedule file needs to contain a percentage column after the timestamp for lowering, and a rolltime needs to be defined for each shutter in the beginning of the program. When lowering shutters, there's a calculation to sleep until the desired percentage is reached, when the shutter is stopped
The way to deactivate shutters has changed: now you need to set the percentage to 0.
2021-08-30 18:47:21 +02:00

102 lines
2.2 KiB
C

//
// Created by lacko on 08/08/2021.
//
#include "idozites.h"
#include <string.h>
//function, which navigates the file, and stops at the label of today.
int find_today (FILE *schedule)
{
time_t t = time (NULL);
struct tm *now = localtime (&t);
char buffer[4] = {0};
while (find_next_day (schedule) == 1)
{
fgets (buffer, 4, schedule);
switch (now->tm_wday)
{
case 0:
if (strcasecmp (buffer, "VAS") == 0)
return 1;
break;
case 1:
if (strcasecmp (buffer, "HET") == 0)
return 1;
break;
case 2:
if (strcasecmp (buffer, "KED") == 0)
return 1;
break;
case 3:
if (strcasecmp (buffer, "SZE") == 0)
return 1;
break;
case 4:
if (strcasecmp (buffer, "CSU") == 0)
return 1;
break;
case 5:
if (strcasecmp (buffer, "PEN") == 0)
return 1;
break;
case 6:
if (strcasecmp (buffer, "SZO") == 0)
return 1;
break;
}
}
return 0;
}
int find_next_day (FILE *f)
{
char c;
while (fscanf (f, "%c", &c) == 1)
{
if (c == '\n' && fgetc (f) == '\n')
return 1;
}
return 0;
}
void get_timing (shutter *r, FILE *schedule)
{
int channel = 0;
while (channel != r->ch)
{
fscanf (schedule, "%*[^\n]s\n");
while (fscanf (schedule, "%d", &channel) != 1)
{
fscanf (schedule, "%*c");
}
}
while (fscanf (schedule, "%d:%d", &r->up.tm_hour, &r->up.tm_min) != 2)
fscanf (schedule, "%*c");
while (fscanf (schedule, "%d:%d", &r->down.tm_hour, &r->down.tm_min) != 2)
fscanf (schedule, "%*c");
fscanf (schedule, "%*[^\n]s\n");
}
buttons check_timing (shutter *r)
{
if ((r->up.tm_hour == r->down.tm_hour) && (r->up.tm_min == r->down.tm_min))
return stop;
time_t t = time (NULL);
struct tm *now = localtime (&t);
if ((r->down.tm_hour == now->tm_hour) && (r->down.tm_min == now->tm_min))
{
return down;
}
if ((r->up.tm_hour == now->tm_hour) && (r->up.tm_min == now->tm_min))
{
return up;
}
return stop;
}