-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeaker.c
More file actions
65 lines (50 loc) · 1.1 KB
/
speaker.c
File metadata and controls
65 lines (50 loc) · 1.1 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
#include "main.h"
#include "config.h"
#include "speaker.h"
void init_speaker()
{
speakerstat.alarm_in_progress = 0;
speakerstat.alarm_snooze_in_progress = 0;
speakerstat.alarm_snooze_minutes = 8;
speakerstat.sound_in_progress = 0;
}
void speaker_initiate_alarm()
{
speakerstat.alarm_in_progress = 1;
speakerstat.alarm_snoozed = 0;
speaker_start_alarm_tone();
}
void speaker_start_alarm_tone()
{
speaker_on();
speakerstat.sound_data = ALARM_TONE;
speakerstat.sound_idx = 0;
speakerstat.sound_idx_max = ALARM_TONE_NUM_ELEMENTS;
speakerstat.sound_in_progress = 1;
}
void speaker_play_space()
{
speaker_on();
speakerstat.sound_data = SPACE;
speakerstat.sound_idx = 0;
speakerstat.sound_idx_max = SPACE_NUM_ELEMENTS;
speakerstat.sound_in_progress = 1;
}
void speaker_stop_playing()
{
speaker_off();
speakerstat.sound_in_progress = 0;
}
void speaker_on()
{
T4CONbits.TMR4ON = 1;
T2CONbits.TMR2ON = 1;
CCPR1L = 0;
TMR4IE = 1;
}
void speaker_off()
{
T4CONbits.TMR4ON = 0;
T2CONbits.TMR2ON = 0;
CCPR1L = 0;
}