mirror of
https://github.com/joeycastillo/second-movement.git
synced 2026-02-04 09:15:27 +00:00
Fix faces that relied on watch_buzzer_play_note being blocking
This commit is contained in:
@ -202,9 +202,16 @@ static void _alarm_update_alarm_enabled(alarm_state_t *state) {
|
||||
|
||||
static void _alarm_play_short_beep(uint8_t pitch_idx) {
|
||||
// play a short double beep
|
||||
watch_buzzer_play_note(_buzzer_notes[pitch_idx], 50);
|
||||
watch_buzzer_play_note(BUZZER_NOTE_REST, 50);
|
||||
watch_buzzer_play_note(_buzzer_notes[pitch_idx], 70);
|
||||
static int8_t beep_sequence[] = {
|
||||
0, 4,
|
||||
BUZZER_NOTE_REST, 4,
|
||||
0, 6,
|
||||
0
|
||||
};
|
||||
beep_sequence[0] = _buzzer_notes[pitch_idx];
|
||||
beep_sequence[4] = _buzzer_notes[pitch_idx];
|
||||
|
||||
movement_play_sequence(beep_sequence, 0);
|
||||
}
|
||||
|
||||
static void _alarm_indicate_beep(alarm_state_t *state) {
|
||||
@ -437,14 +444,7 @@ bool advanced_alarm_face_loop(movement_event_t event, void *context) {
|
||||
// play alarm
|
||||
if (state->alarm[state->alarm_playing_idx].beeps == 0) {
|
||||
// short beep
|
||||
if (watch_is_buzzer_or_led_enabled()) {
|
||||
_alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch);
|
||||
} else {
|
||||
// enable, play beep and disable buzzer again
|
||||
watch_enable_buzzer();
|
||||
_alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch);
|
||||
watch_disable_buzzer();
|
||||
}
|
||||
_alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch);
|
||||
} else {
|
||||
// regular alarm beeps
|
||||
movement_play_alarm_beeps((state->alarm[state->alarm_playing_idx].beeps == (ALARM_MAX_BEEP_ROUNDS - 1) ? 20 : state->alarm[state->alarm_playing_idx].beeps),
|
||||
|
||||
@ -82,26 +82,36 @@ static inline int _days_in_month(int16_t month, int16_t year)
|
||||
/* Play beep sound based on type */
|
||||
static inline void _beep(beep_type_t beep_type)
|
||||
{
|
||||
static int8_t beep_sequence[] = {
|
||||
0, 4,
|
||||
0, 6,
|
||||
0, 6,
|
||||
0
|
||||
};
|
||||
|
||||
if (!movement_button_should_sound())
|
||||
return;
|
||||
|
||||
switch (beep_type) {
|
||||
case BEEP_BUTTON:
|
||||
watch_buzzer_play_note_with_volume(BUZZER_NOTE_C7, 50, movement_button_volume());
|
||||
beep_sequence[0] = BUZZER_NOTE_C7;
|
||||
beep_sequence[2] = 0;
|
||||
break;
|
||||
|
||||
case BEEP_ENABLE:
|
||||
watch_buzzer_play_note_with_volume(BUZZER_NOTE_G7, 50, movement_button_volume());
|
||||
watch_buzzer_play_note(BUZZER_NOTE_REST, 75);
|
||||
watch_buzzer_play_note_with_volume(BUZZER_NOTE_C8, 50, movement_button_volume());
|
||||
beep_sequence[0] = BUZZER_NOTE_G7;
|
||||
beep_sequence[2] = BUZZER_NOTE_REST;
|
||||
beep_sequence[4] = BUZZER_NOTE_C8;
|
||||
break;
|
||||
|
||||
case BEEP_DISABLE:
|
||||
watch_buzzer_play_note_with_volume(BUZZER_NOTE_C8, 50, movement_button_volume());
|
||||
watch_buzzer_play_note(BUZZER_NOTE_REST, 75);
|
||||
watch_buzzer_play_note_with_volume(BUZZER_NOTE_G7, 50, movement_button_volume());
|
||||
beep_sequence[0] = BUZZER_NOTE_C8;
|
||||
beep_sequence[2] = BUZZER_NOTE_REST;
|
||||
beep_sequence[4] = BUZZER_NOTE_G7;
|
||||
break;
|
||||
}
|
||||
|
||||
movement_play_sequence(beep_sequence, 0);
|
||||
}
|
||||
|
||||
/* Change tick frequency */
|
||||
|
||||
@ -119,30 +119,22 @@ static void _simon_play_note(SimonNote note, simon_state_t *state, bool skip_res
|
||||
switch (note) {
|
||||
case SIMON_LED_NOTE:
|
||||
if (!state->lightOff) watch_set_led_yellow();
|
||||
if (state->soundOff)
|
||||
delay_ms(_delay_beep);
|
||||
else
|
||||
watch_buzzer_play_note(BUZZER_NOTE_D3, _delay_beep);
|
||||
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_D3, _delay_beep);
|
||||
delay_ms(_delay_beep);
|
||||
break;
|
||||
case SIMON_MODE_NOTE:
|
||||
if (!state->lightOff) watch_set_led_red();
|
||||
if (state->soundOff)
|
||||
delay_ms(_delay_beep);
|
||||
else
|
||||
watch_buzzer_play_note(BUZZER_NOTE_E4, _delay_beep);
|
||||
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_E4, _delay_beep);
|
||||
delay_ms(_delay_beep);
|
||||
break;
|
||||
case SIMON_ALARM_NOTE:
|
||||
if (!state->lightOff) watch_set_led_green();
|
||||
if (state->soundOff)
|
||||
delay_ms(_delay_beep);
|
||||
else
|
||||
watch_buzzer_play_note(BUZZER_NOTE_C3, _delay_beep);
|
||||
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_C3, _delay_beep);
|
||||
delay_ms(_delay_beep);
|
||||
break;
|
||||
case SIMON_WRONG_NOTE:
|
||||
if (state->soundOff)
|
||||
delay_ms(800);
|
||||
else
|
||||
watch_buzzer_play_note(BUZZER_NOTE_A1, 800);
|
||||
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_A1, 800);
|
||||
delay_ms(800);
|
||||
break;
|
||||
}
|
||||
watch_set_led_off();
|
||||
@ -150,7 +142,7 @@ static void _simon_play_note(SimonNote note, simon_state_t *state, bool skip_res
|
||||
if (note != SIMON_WRONG_NOTE) {
|
||||
_simon_clear_display(state);
|
||||
if (!skip_rest) {
|
||||
watch_buzzer_play_note(BUZZER_NOTE_REST, (_delay_beep * 2)/3);
|
||||
delay_ms((_delay_beep * 2)/3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,6 +110,12 @@ static bool tally_face_should_move_back(tally_state_t *state) {
|
||||
bool tally_face_loop(movement_event_t event, void *context) {
|
||||
tally_state_t *state = (tally_state_t *)context;
|
||||
static bool using_led = false;
|
||||
static int8_t beep_sequence[] = {
|
||||
0, 2,
|
||||
BUZZER_NOTE_REST, 3,
|
||||
0, 2,
|
||||
0
|
||||
};
|
||||
|
||||
if (using_led) {
|
||||
if(!HAL_GPIO_BTN_MODE_read() && !HAL_GPIO_BTN_LIGHT_read() && !HAL_GPIO_BTN_ALARM_read())
|
||||
@ -148,9 +154,11 @@ bool tally_face_loop(movement_event_t event, void *context) {
|
||||
state->tally_idx = _tally_default[state->tally_default_idx]; // reset tally index
|
||||
_init_val = true;
|
||||
//play a reset tune
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
|
||||
if (movement_button_should_sound()) {
|
||||
beep_sequence[0] = BUZZER_NOTE_G6;
|
||||
beep_sequence[4] = BUZZER_NOTE_E6;
|
||||
movement_play_sequence(beep_sequence, 0);
|
||||
}
|
||||
print_tally(state, movement_button_should_sound());
|
||||
}
|
||||
break;
|
||||
@ -168,9 +176,11 @@ bool tally_face_loop(movement_event_t event, void *context) {
|
||||
if (TALLY_FACE_PRESETS_SIZE() > 1 && _init_val){
|
||||
state->tally_default_idx = (state->tally_default_idx + 1) % TALLY_FACE_PRESETS_SIZE();
|
||||
state->tally_idx = _tally_default[state->tally_default_idx];
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
|
||||
if (movement_button_should_sound()) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
|
||||
if (movement_button_should_sound()) {
|
||||
beep_sequence[0] = BUZZER_NOTE_E6;
|
||||
beep_sequence[4] = BUZZER_NOTE_G6;
|
||||
movement_play_sequence(beep_sequence, 0);
|
||||
}
|
||||
print_tally(state, movement_button_should_sound());
|
||||
}
|
||||
else{
|
||||
|
||||
Reference in New Issue
Block a user