Version 1.4.4

Changed function check_timing: now it takes a struct tm* instead of generating one - now the main function gets the current time after initialising the shutter array.
This commit is contained in:
2021-08-30 21:52:18 +02:00
parent a9950e6c13
commit 9109cc8077
3 changed files with 22 additions and 21 deletions

View File

@@ -73,36 +73,34 @@ void get_timing (shutter *r, FILE *schedule)
while (fscanf (schedule, "%d:%d", &tmp_hour, &tmp_min) != 2)
fscanf (schedule, "%*c");
r->up.tm_hour = (char )tmp_hour;
r->up.tm_min = (char )tmp_min;
r->up.tm_hour = (char) tmp_hour;
r->up.tm_min = (char) tmp_min;
while (fscanf (schedule, "%d:%d", &tmp_hour, &tmp_min) != 2)
fscanf (schedule, "%*c");
r->down.tm_hour = (char )tmp_hour;
r->down.tm_min = (char )tmp_min;
r->down.tm_hour = (char) tmp_hour;
r->down.tm_min = (char) tmp_min;
while (fscanf (schedule, "%d", &tmp_percentage) != 1)
fscanf (schedule, "%*c");
r->percentage = (char )tmp_percentage;
r->percentage = (char) tmp_percentage;
fscanf (schedule, "%*[^\n]s\n");
}
buttons check_timing (shutter *r)
buttons check_timing (shutter *r, struct tm *now)
{
if (r->percentage == 0)
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))
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))
if ((r->up.tm_hour == now->tm_hour) && (r->up.tm_min == (now->tm_min)))
{
return up;
}
return stop;
}