-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiming.c
More file actions
119 lines (108 loc) · 3.14 KB
/
timing.c
File metadata and controls
119 lines (108 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of Shutter.
*
* Shutter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Shutter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Shutter. If not, see <https://www.gnu.org/licenses/>.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "timing.h"
#include <string.h>
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 (strcmp (buffer, "SUN") == 0)
return 1;
break;
case 1:
if (strcmp (buffer, "MON") == 0)
return 1;
break;
case 2:
if (strcmp (buffer, "TUE") == 0)
return 1;
break;
case 3:
if (strcmp (buffer, "WED") == 0)
return 1;
break;
case 4:
if (strcmp (buffer, "THU") == 0)
return 1;
break;
case 5:
if (strcmp (buffer, "FRI") == 0)
return 1;
break;
case 6:
if (strcmp (buffer, "SAT") == 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 tmp_min = 0, tmp_hour = 0, channel = 0, tmp_percentage = 0;
while (channel != r->ch)
{
fscanf (schedule, "%*[^\n]s\n");
while (fscanf (schedule, "%d", &channel) != 1)
{
fscanf (schedule, "%*c");
}
}
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;
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;
while (fscanf (schedule, "%d", &tmp_percentage) != 1)
fscanf (schedule, "%*c");
r->percentage = (char) tmp_percentage;
fscanf (schedule, "%*[^\n]s\n");
}
buttons check_timing (shutter *r, struct tm *now)
{
if (r->percentage == 0)
return stop;
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;
}