-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm.c
68 lines (55 loc) · 1.38 KB
/
alarm.c
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
/*
* alarm.c
*
* Created on: 17 gen 2017
* Author: Alessandro Trifoglio
*/
#include "inc/alarm.h"
#include "inc/interface/WidgetConfig.h"
#define MAXBEATS 30
unsigned int toReset = 0;
unsigned int i = 0;
/*
* LEDs are switched on-off according to these time intervals. Values are comprised between 0 (no wait time before switching a LED)
* and 100*(MAXCOUNT-1) (maximum wait time before toggling LED) and are expressed in milliseconds
*/
unsigned int beats[MAXBEATS] = {
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100
};
void stopAlarm (void) {
if (toReset==1) {
GPIO_ResetBits(GPIOD, GPIO_Pin_12);
toReset = 0;
}
i = 0;
}
boolean launchAlarm (unsigned int* counter) {
static unsigned int lastCounter;
if (i==0) {
GPIO_SetBits(GPIOD, GPIO_Pin_12);
lastCounter = *counter;
toReset = (toReset-1)%2;
i++;
return 1;
} else if (i<=MAXBEATS) {
while ((*counter-lastCounter)%MAXCOUNT<(beats[i-1]/100));
switch (toReset) {
case (1):
GPIO_ResetBits(GPIOD, GPIO_Pin_12);
break;
case (0):
GPIO_SetBits(GPIOD, GPIO_Pin_12);
break;
default:
break;
}
lastCounter = *counter;
toReset = (toReset-1)%2;
i++;
return true;
} else {
stopAlarm();
return false;
}
}