Skip to content

Commit

Permalink
Tally face sound now uses the preference's beep so decrementing fast …
Browse files Browse the repository at this point in the history
…can happen immedietly
  • Loading branch information
voloved committed Sep 8, 2024
1 parent 002f5bc commit a5a4dd1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
57 changes: 24 additions & 33 deletions movement/watch_faces/complication/tally_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ void tally_face_setup(movement_settings_t *settings, uint8_t watch_face_index, v
memset(*context_ptr, 0, sizeof(tally_state_t));
tally_state_t *state = (tally_state_t *)*context_ptr;
state->tally_default_idx = 0;
state->soundOff = true;
state->tally_idx = _tally_default[state->tally_default_idx];
_init_val = true;
}
Expand All @@ -65,34 +64,33 @@ static void stop_quick_cyc(void){
movement_request_tick_frequency(1);
}

static void tally_face_increment(tally_state_t *state) {
bool soundOn = !_quick_ticks_running && !state->soundOff;
static void tally_face_increment(tally_state_t *state, bool sound_on) {
bool soundOn = !_quick_ticks_running && sound_on;
_init_val = false;
if (state->tally_idx >= TALLY_FACE_MAX){
if (soundOn) watch_buzzer_play_note(BUZZER_NOTE_E7, 30);
}
else {
state->tally_idx++;
print_tally(state);
print_tally(state, sound_on);
if (soundOn) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
}
}

static void tally_face_decrement(tally_state_t *state) {
bool soundOn = !_quick_ticks_running && !state->soundOff;
static void tally_face_decrement(tally_state_t *state, bool sound_on) {
bool soundOn = !_quick_ticks_running && sound_on;
_init_val = false;
if (state->tally_idx <= TALLY_FACE_MIN){
if (soundOn) watch_buzzer_play_note(BUZZER_NOTE_C5SHARP_D5FLAT, 30);
}
else {
state->tally_idx--;
print_tally(state);
print_tally(state, sound_on);
if (soundOn) watch_buzzer_play_note(BUZZER_NOTE_C6SHARP_D6FLAT, 30);
}
}

bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
(void) settings;
tally_state_t *state = (tally_state_t *)context;
static bool using_led = false;

Expand All @@ -112,24 +110,17 @@ bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void
bool light_pressed = watch_get_pin_level(BTN_LIGHT);
bool alarm_pressed = watch_get_pin_level(BTN_ALARM);
if (light_pressed && alarm_pressed) stop_quick_cyc();
else if (light_pressed) tally_face_increment(state);
else if (alarm_pressed) tally_face_decrement(state);
else if (light_pressed) tally_face_increment(state, settings->bit.button_should_sound);
else if (alarm_pressed) tally_face_decrement(state, settings->bit.button_should_sound);
else stop_quick_cyc();
}
break;
case EVENT_ALARM_BUTTON_UP:
tally_face_decrement(state);
tally_face_decrement(state, settings->bit.button_should_sound);
break;
case EVENT_ALARM_LONG_PRESS:
if (_init_val) {
state->soundOff = !state->soundOff;
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
print_tally(state);
}
else{
tally_face_decrement(state);
start_quick_cyc();
}
tally_face_decrement(state, settings->bit.button_should_sound);
start_quick_cyc();
break;
case EVENT_MODE_LONG_PRESS:
if (state->tally_idx == _tally_default[state->tally_default_idx]) {
Expand All @@ -140,14 +131,14 @@ bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void
state->tally_idx = _tally_default[state->tally_default_idx]; // reset tally index
_init_val = true;
//play a reset tune
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
print_tally(state);
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
print_tally(state, settings->bit.button_should_sound);
}
break;
case EVENT_LIGHT_BUTTON_UP:
tally_face_increment(state);
tally_face_increment(state, settings->bit.button_should_sound);
break;
case EVENT_LIGHT_BUTTON_DOWN:
case EVENT_ALARM_BUTTON_DOWN:
Expand All @@ -160,18 +151,18 @@ bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void
if (_init_val){
state->tally_default_idx = (state->tally_default_idx + 1) % _tally_default_size;
state->tally_idx = _tally_default[state->tally_default_idx];
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
if (!state->soundOff) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
print_tally(state);
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_E6, 30);
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_REST, 30);
if (settings->bit.button_should_sound) watch_buzzer_play_note(BUZZER_NOTE_G6, 30);
print_tally(state, settings->bit.button_should_sound);
}
else{
tally_face_increment(state);
tally_face_increment(state, settings->bit.button_should_sound);
start_quick_cyc();
}
break;
case EVENT_ACTIVATE:
print_tally(state);
print_tally(state, settings->bit.button_should_sound);
break;
case EVENT_TIMEOUT:
// ignore timeout
Expand All @@ -185,9 +176,9 @@ bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void
}

// print tally index at the center of display.
void print_tally(tally_state_t *state) {
void print_tally(tally_state_t *state, bool sound_on) {
char buf[14];
if (!state->soundOff)
if (sound_on)
watch_set_indicator(WATCH_INDICATOR_BELL);
else
watch_clear_indicator(WATCH_INDICATOR_BELL);
Expand Down
5 changes: 2 additions & 3 deletions movement/watch_faces/complication/tally_face.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@

typedef struct {
int16_t tally_idx;
uint8_t tally_default_idx : 7;
bool soundOff;
uint8_t tally_default_idx;
} tally_state_t;


Expand All @@ -60,7 +59,7 @@ void tally_face_activate(movement_settings_t *settings, void *context);
bool tally_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void tally_face_resign(movement_settings_t *settings, void *context);

void print_tally(tally_state_t *state);
void print_tally(tally_state_t *state, bool sound_on);

#define tally_face ((const watch_face_t){ \
tally_face_setup, \
Expand Down

0 comments on commit a5a4dd1

Please sign in to comment.