Skip to content

Commit 6d1d4f0

Browse files
Merge PR #386 - add beep demo face
Allows the user manually trigger all 87 buzzer notes. Reviewed-by: Matheus Afonso Martins Moreira <[email protected]> Tested-on-hardware-by: Wesley Black <[email protected]> GitHub-Pull-Request: #386
2 parents 1f61538 + 69f25f1 commit 6d1d4f0

File tree

3 files changed

+311
-0
lines changed

3 files changed

+311
-0
lines changed

movement/movement_faces.h

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
#include "simon_face.h"
115115
#include "simple_calculator_face.h"
116116
#include "alarm_thermometer_face.h"
117+
#include "beeps_face.h"
117118
// New includes go above this line.
118119

119120
#endif // MOVEMENT_FACES_H_
+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2024 Wesley
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#include <stdlib.h>
26+
#include <string.h>
27+
#include "beeps_face.h"
28+
29+
void beeps_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
30+
(void) settings;
31+
(void) watch_face_index;
32+
if (*context_ptr == NULL) {
33+
*context_ptr = malloc(sizeof(beeps_state_t));
34+
memset(*context_ptr, 0, sizeof(beeps_state_t));
35+
// Do any one-time tasks in here; the inside of this conditional happens only at boot.
36+
}
37+
}
38+
39+
void beeps_face_activate(movement_settings_t *settings, void *context) {
40+
(void) settings;
41+
beeps_state_t *state = (beeps_state_t *)context;
42+
}
43+
44+
static void _beep_face_update_lcd(beeps_state_t *state) {
45+
char buf[11];
46+
const char buzzernote[][7] = {" 5500", " 5827", " 6174"," 6541"," 6930"," 7342"," 7778"," 8241"," 8731"," 9250"," 9800"," 10383"," 11000"," 11654"," 12347"," 13081"," 13859"," 14683"," 15556"," 16481"," 17461"," 18500"," 19600"," 20765"," 22000"," 23308"," 24694"," 26163"," 27718"," 29366"," 31113"," 32963"," 34923"," 36999"," 39200"," 41530"," 44000"," 46616"," 49388"," 52325"," 55437"," 58733"," 62225"," 65925"," 69846"," 73999"," 78399"," 83061"," 88000"," 93233"," 98777"," 104650"," 110873"," 117466"," 124451"," 131851"," 139691"," 147998"," 156798"," 166122"," 176000"," 186466"," 197553"," 209300"," 221746"," 234932"," 248902"," 263702"," 279383"," 295996"," 313596"," 332244"," 352000"," 372931"," 395107"," 418601"," 443492"," 469863"," 497803"," 527404"," 558765"," 591991"," 627193"," 664488"," 704000"," 745862"," 790213"};
47+
sprintf(buf, "HZ %s", buzzernote[state->frequency]);
48+
watch_display_string(buf, 0);
49+
}
50+
51+
bool beeps_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
52+
beeps_state_t *state = (beeps_state_t *)context;
53+
54+
switch (event.event_type) {
55+
case EVENT_ACTIVATE:
56+
_beep_face_update_lcd(state);
57+
break;
58+
case EVENT_LIGHT_BUTTON_DOWN:
59+
state->frequency = (state->frequency + 1) % 87;
60+
_beep_face_update_lcd(state);
61+
break;
62+
case EVENT_ALARM_BUTTON_DOWN:
63+
if (state->frequency == 0) {
64+
watch_buzzer_play_note(BUZZER_NOTE_A1, 500);
65+
} else if (state->frequency == 1) {
66+
watch_buzzer_play_note(BUZZER_NOTE_A1SHARP_B1FLAT, 500);
67+
} else if (state->frequency == 2) {
68+
watch_buzzer_play_note(BUZZER_NOTE_B1, 500);
69+
} else if (state->frequency == 3) {
70+
watch_buzzer_play_note(BUZZER_NOTE_C2, 500);
71+
} else if (state->frequency == 4) {
72+
watch_buzzer_play_note(BUZZER_NOTE_C2SHARP_D2FLAT, 500);
73+
} else if (state->frequency == 5) {
74+
watch_buzzer_play_note(BUZZER_NOTE_D2, 500);
75+
} else if (state->frequency == 6) {
76+
watch_buzzer_play_note(BUZZER_NOTE_D2SHARP_E2FLAT, 500);
77+
} else if (state->frequency == 7) {
78+
watch_buzzer_play_note(BUZZER_NOTE_E2, 500);
79+
} else if (state->frequency == 8) {
80+
watch_buzzer_play_note(BUZZER_NOTE_F2, 500);
81+
} else if (state->frequency == 9) {
82+
watch_buzzer_play_note(BUZZER_NOTE_F2SHARP_G2FLAT, 500);
83+
} else if (state->frequency == 10) {
84+
watch_buzzer_play_note(BUZZER_NOTE_G2, 500);
85+
} else if (state->frequency == 11) {
86+
watch_buzzer_play_note(BUZZER_NOTE_G2SHARP_A2FLAT, 500);
87+
} else if (state->frequency == 12) {
88+
watch_buzzer_play_note(BUZZER_NOTE_A2, 500);
89+
} else if (state->frequency == 13) {
90+
watch_buzzer_play_note(BUZZER_NOTE_A2SHARP_B2FLAT, 500);
91+
} else if (state->frequency == 14) {
92+
watch_buzzer_play_note(BUZZER_NOTE_B2, 500);
93+
} else if (state->frequency == 15) {
94+
watch_buzzer_play_note(BUZZER_NOTE_C3, 500);
95+
} else if (state->frequency == 16) {
96+
watch_buzzer_play_note(BUZZER_NOTE_C3SHARP_D3FLAT, 500);
97+
} else if (state->frequency == 17) {
98+
watch_buzzer_play_note(BUZZER_NOTE_D3, 500);
99+
} else if (state->frequency == 18) {
100+
watch_buzzer_play_note(BUZZER_NOTE_D3SHARP_E3FLAT, 500);
101+
} else if (state->frequency == 19) {
102+
watch_buzzer_play_note(BUZZER_NOTE_E3, 500);
103+
} else if (state->frequency == 20) {
104+
watch_buzzer_play_note(BUZZER_NOTE_F3, 500);
105+
} else if (state->frequency == 21) {
106+
watch_buzzer_play_note(BUZZER_NOTE_F3SHARP_G3FLAT, 500);
107+
} else if (state->frequency == 22) {
108+
watch_buzzer_play_note(BUZZER_NOTE_G3, 500);
109+
} else if (state->frequency == 23) {
110+
watch_buzzer_play_note(BUZZER_NOTE_G3SHARP_A3FLAT, 500);
111+
} else if (state->frequency == 24) {
112+
watch_buzzer_play_note(BUZZER_NOTE_A3, 500);
113+
} else if (state->frequency == 25) {
114+
watch_buzzer_play_note(BUZZER_NOTE_A3SHARP_B3FLAT, 500);
115+
} else if (state->frequency == 26) {
116+
watch_buzzer_play_note(BUZZER_NOTE_B3, 500);
117+
} else if (state->frequency == 27) {
118+
watch_buzzer_play_note(BUZZER_NOTE_C4, 500);
119+
} else if (state->frequency == 28) {
120+
watch_buzzer_play_note(BUZZER_NOTE_C4SHARP_D4FLAT, 500);
121+
} else if (state->frequency == 29) {
122+
watch_buzzer_play_note(BUZZER_NOTE_D4, 500);
123+
} else if (state->frequency == 30) {
124+
watch_buzzer_play_note(BUZZER_NOTE_D4SHARP_E4FLAT, 500);
125+
} else if (state->frequency == 31) {
126+
watch_buzzer_play_note(BUZZER_NOTE_E4, 500);
127+
} else if (state->frequency == 32) {
128+
watch_buzzer_play_note(BUZZER_NOTE_F4, 500);
129+
} else if (state->frequency == 33) {
130+
watch_buzzer_play_note(BUZZER_NOTE_F4SHARP_G4FLAT, 500);
131+
} else if (state->frequency == 34) {
132+
watch_buzzer_play_note(BUZZER_NOTE_G4, 500);
133+
} else if (state->frequency == 35) {
134+
watch_buzzer_play_note(BUZZER_NOTE_G4SHARP_A4FLAT, 500);
135+
} else if (state->frequency == 36) {
136+
watch_buzzer_play_note(BUZZER_NOTE_A4, 500);
137+
} else if (state->frequency == 37) {
138+
watch_buzzer_play_note(BUZZER_NOTE_A4SHARP_B4FLAT, 500);
139+
} else if (state->frequency == 38) {
140+
watch_buzzer_play_note(BUZZER_NOTE_B4, 500);
141+
} else if (state->frequency == 39) {
142+
watch_buzzer_play_note(BUZZER_NOTE_C5, 500);
143+
} else if (state->frequency == 40) {
144+
watch_buzzer_play_note(BUZZER_NOTE_C5SHARP_D5FLAT, 500);
145+
} else if (state->frequency == 41) {
146+
watch_buzzer_play_note(BUZZER_NOTE_D5, 500);
147+
} else if (state->frequency == 42) {
148+
watch_buzzer_play_note(BUZZER_NOTE_D5SHARP_E5FLAT, 500);
149+
} else if (state->frequency == 43) {
150+
watch_buzzer_play_note(BUZZER_NOTE_E5, 500);
151+
} else if (state->frequency == 44) {
152+
watch_buzzer_play_note(BUZZER_NOTE_F5, 500);
153+
} else if (state->frequency == 45) {
154+
watch_buzzer_play_note(BUZZER_NOTE_F5SHARP_G5FLAT, 500);
155+
} else if (state->frequency == 46) {
156+
watch_buzzer_play_note(BUZZER_NOTE_G5, 500);
157+
} else if (state->frequency == 47) {
158+
watch_buzzer_play_note(BUZZER_NOTE_G5SHARP_A5FLAT, 500);
159+
} else if (state->frequency == 48) {
160+
watch_buzzer_play_note(BUZZER_NOTE_A5, 500);
161+
} else if (state->frequency == 49) {
162+
watch_buzzer_play_note(BUZZER_NOTE_A5SHARP_B5FLAT, 500);
163+
} else if (state->frequency == 50) {
164+
watch_buzzer_play_note(BUZZER_NOTE_B5, 500);
165+
} else if (state->frequency == 51) {
166+
watch_buzzer_play_note(BUZZER_NOTE_C6, 500);
167+
} else if (state->frequency == 52) {
168+
watch_buzzer_play_note(BUZZER_NOTE_C6SHARP_D6FLAT, 500);
169+
} else if (state->frequency == 53) {
170+
watch_buzzer_play_note(BUZZER_NOTE_D6, 500);
171+
} else if (state->frequency == 54) {
172+
watch_buzzer_play_note(BUZZER_NOTE_D6SHARP_E6FLAT, 500);
173+
} else if (state->frequency == 55) {
174+
watch_buzzer_play_note(BUZZER_NOTE_E6, 500);
175+
} else if (state->frequency == 56) {
176+
watch_buzzer_play_note(BUZZER_NOTE_F6, 500);
177+
} else if (state->frequency == 57) {
178+
watch_buzzer_play_note(BUZZER_NOTE_F6SHARP_G6FLAT, 500);
179+
} else if (state->frequency == 58) {
180+
watch_buzzer_play_note(BUZZER_NOTE_G6, 500);
181+
} else if (state->frequency == 59) {
182+
watch_buzzer_play_note(BUZZER_NOTE_G6SHARP_A6FLAT, 500);
183+
} else if (state->frequency == 60) {
184+
watch_buzzer_play_note(BUZZER_NOTE_A6, 500);
185+
} else if (state->frequency == 61) {
186+
watch_buzzer_play_note(BUZZER_NOTE_A6SHARP_B6FLAT, 500);
187+
} else if (state->frequency == 62) {
188+
watch_buzzer_play_note(BUZZER_NOTE_B6, 500);
189+
} else if (state->frequency == 63) {
190+
watch_buzzer_play_note(BUZZER_NOTE_C7, 500);
191+
} else if (state->frequency == 64) {
192+
watch_buzzer_play_note(BUZZER_NOTE_C7SHARP_D7FLAT, 500);
193+
} else if (state->frequency == 65) {
194+
watch_buzzer_play_note(BUZZER_NOTE_D7, 500);
195+
} else if (state->frequency == 66) {
196+
watch_buzzer_play_note(BUZZER_NOTE_D7SHARP_E7FLAT, 500);
197+
} else if (state->frequency == 67) {
198+
watch_buzzer_play_note(BUZZER_NOTE_E7, 500);
199+
} else if (state->frequency == 68) {
200+
watch_buzzer_play_note(BUZZER_NOTE_F7, 500);
201+
} else if (state->frequency == 69) {
202+
watch_buzzer_play_note(BUZZER_NOTE_F7SHARP_G7FLAT, 500);
203+
} else if (state->frequency == 70) {
204+
watch_buzzer_play_note(BUZZER_NOTE_G7, 500);
205+
} else if (state->frequency == 71) {
206+
watch_buzzer_play_note(BUZZER_NOTE_G7SHARP_A7FLAT, 500);
207+
} else if (state->frequency == 72) {
208+
watch_buzzer_play_note(BUZZER_NOTE_A7, 500);
209+
} else if (state->frequency == 73) {
210+
watch_buzzer_play_note(BUZZER_NOTE_A7SHARP_B7FLAT, 500);
211+
} else if (state->frequency == 74) {
212+
watch_buzzer_play_note(BUZZER_NOTE_B7, 500);
213+
} else if (state->frequency == 75) {
214+
watch_buzzer_play_note(BUZZER_NOTE_C8, 500);
215+
} else if (state->frequency == 76) {
216+
watch_buzzer_play_note(BUZZER_NOTE_C8SHARP_D8FLAT, 500);
217+
} else if (state->frequency == 77) {
218+
watch_buzzer_play_note(BUZZER_NOTE_D8, 500);
219+
} else if (state->frequency == 78) {
220+
watch_buzzer_play_note(BUZZER_NOTE_D8SHARP_E8FLAT, 500);
221+
} else if (state->frequency == 79) {
222+
watch_buzzer_play_note(BUZZER_NOTE_E8, 500);
223+
} else if (state->frequency == 80) {
224+
watch_buzzer_play_note(BUZZER_NOTE_F8, 500);
225+
} else if (state->frequency == 81) {
226+
watch_buzzer_play_note(BUZZER_NOTE_F8SHARP_G8FLAT, 500);
227+
} else if (state->frequency == 82) {
228+
watch_buzzer_play_note(BUZZER_NOTE_G8, 500);
229+
} else if (state->frequency == 83) {
230+
watch_buzzer_play_note(BUZZER_NOTE_G8SHARP_A8FLAT, 500);
231+
} else if (state->frequency == 84) {
232+
watch_buzzer_play_note(BUZZER_NOTE_A8, 500);
233+
} else if (state->frequency == 85) {
234+
watch_buzzer_play_note(BUZZER_NOTE_A8SHARP_B8FLAT, 500);
235+
} else if (state->frequency == 86) {
236+
watch_buzzer_play_note(BUZZER_NOTE_B8, 500);
237+
}
238+
break;
239+
default:
240+
return movement_default_loop_handler(event, settings);
241+
}
242+
return true;
243+
}
244+
245+
void beeps_face_resign(movement_settings_t *settings, void *context) {
246+
(void) settings;
247+
(void) context;
248+
}
249+
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2024 Wesley
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#ifndef BEEPS_FACE_H_
26+
#define BEEPS_FACE_H_
27+
28+
#include "movement.h"
29+
30+
/*
31+
* A simple watch face to test the different Buzzer Notes.
32+
*
33+
* Press the Light button to play a sound.
34+
* Press the Alarm button to change the frequency.
35+
*
36+
* The watch face displays the frequency of the buzzer it will play
37+
* this allows you to reference the watch_buzzer.h file to find the
38+
* corresponding note.
39+
*
40+
* The watch_buzzer.h file is found at watch-library/shared/watch/watch_buzzer.h
41+
*/
42+
43+
typedef struct {
44+
uint8_t frequency;
45+
} beeps_state_t;
46+
47+
void beeps_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
48+
void beeps_face_activate(movement_settings_t *settings, void *context);
49+
bool beeps_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
50+
void beeps_face_resign(movement_settings_t *settings, void *context);
51+
52+
#define beeps_face ((const watch_face_t){ \
53+
beeps_face_setup, \
54+
beeps_face_activate, \
55+
beeps_face_loop, \
56+
beeps_face_resign, \
57+
NULL, \
58+
})
59+
60+
#endif // BEEPS_FACE_H_
61+

0 commit comments

Comments
 (0)