-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriggerLockoutTimer.c
More file actions
109 lines (97 loc) · 2.28 KB
/
triggerLockoutTimer.c
File metadata and controls
109 lines (97 loc) · 2.28 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
#include "triggerLockoutTimer.h"
#include "globals.h"
#include "stdio.h"
#include "supportFiles/leds.h"
#include "supportFiles/interrupts.h"
#include "supportFiles/buttons.h"
#include "supportFiles/intervalTimer.h"
#include "supportFiles/utils.h"
#define LOCKOUT_DURATION (.5 * GLOBALS_TIMER_FREQUENCY) // .5 s
enum triggerLockoutTimer_states
{wait_st, lockout_st} triggerLockoutTimer_state;
// Standard init function.
void triggerLockoutTimer_init()
{
triggerLockoutTimer_state = wait_st;
}
static bool enabled;
// Calling this starts the timer.
void triggerLockoutTimer_start()
{
enabled = true;
}
static int32_t triggerLockoutTimer;
// Returns true if the timer is running.
bool triggerLockoutTimer_running()
{
return (enabled || (triggerLockoutTimer_state == lockout_st));
}
// Standard tick function.
void triggerLockoutTimer_tick()
{
// Current state actions
switch (triggerLockoutTimer_state)
{
case wait_st:
break;
case lockout_st:
triggerLockoutTimer++;
break;
}
// State transition
switch (triggerLockoutTimer_state)
{
case wait_st:
if(enabled)
{
triggerLockoutTimer_state = lockout_st;
triggerLockoutTimer = 0;
}
break;
case lockout_st:
if(triggerLockoutTimer >= 50000) //LOCKOUT_DURATION)
{
triggerLockoutTimer_state = wait_st;
enabled = false;
}
break;
}
}
// Performs test of the hitLedTimer
void triggerLockoutTimer_runTest()
{
buttons_init();
triggerLockoutTimer_init();
intervalTimer_init(1);
printf("Test triggerLockoutTimer. Press button 1 to exit\r\n");
u32 privateTimerTicksPerSecond = interrupts_getPrivateTimerTicksPerSecond();
leds_init(true);
interrupts_initAll(true);
interrupts_enableTimerGlobalInts();
interrupts_startArmPrivateTimer();
interrupts_enableSysMonGlobalInts();
interrupts_enableArmInts();
bool wasLocked = false;
while (true)
{
triggerLockoutTimer_start();
intervalTimer_reset(1);
intervalTimer_start(1);
int32_t buttonsVal;
while(triggerLockoutTimer_running())
{
buttonsVal = buttons_read();
if(buttonsVal & 0x2)
break;
}
if(buttonsVal & 0x2)
break;
intervalTimer_stop(1);
double seconds;
intervalTimer_getTotalDurationInSeconds(1, &seconds);
printf("Lockout timer ran for %g seconds\r\n", seconds);
utils_msDelay(100);
}
printf("Exited\r\n");
interrupts_disableArmInts();
}