mirror of
https://github.com/firewalkwithm3/Sensor-Watch.git
synced 2024-11-22 19:20:30 +08:00
Merge branch 'main' into default-handler
This commit is contained in:
commit
3142fccea3
|
@ -136,7 +136,17 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
|
|||
case EVENT_BACKGROUND_TASK:
|
||||
// uncomment this line to snap back to the clock face when the hour signal sounds:
|
||||
// movement_move_to_face(state->watch_face_index);
|
||||
movement_play_signal();
|
||||
if (watch_is_buzzer_or_led_enabled()) {
|
||||
// if we are in the foreground, we can just beep.
|
||||
movement_play_signal();
|
||||
} else {
|
||||
// if we were in the background, we need to enable the buzzer peripheral first,
|
||||
watch_enable_buzzer();
|
||||
// beep quickly (this call blocks for 275 ms),
|
||||
movement_play_signal();
|
||||
// and then turn the buzzer peripheral off again.
|
||||
watch_disable_buzzer();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return movement_default_loop_handler(event, settings);
|
||||
|
|
|
@ -136,7 +136,17 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set
|
|||
case EVENT_BACKGROUND_TASK:
|
||||
// uncomment this line to snap back to the clock face when the hour signal sounds:
|
||||
// movement_move_to_face(state->watch_face_index);
|
||||
movement_play_signal();
|
||||
if (watch_is_buzzer_or_led_enabled()) {
|
||||
// if we are in the foreground, we can just beep.
|
||||
movement_play_signal();
|
||||
} else {
|
||||
// if we were in the background, we need to enable the buzzer peripheral first,
|
||||
watch_enable_buzzer();
|
||||
// beep quickly (this call blocks for 275 ms),
|
||||
movement_play_signal();
|
||||
// and then turn the buzzer peripheral off again.
|
||||
watch_disable_buzzer();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -417,7 +417,15 @@ bool alarm_face_loop(movement_event_t event, movement_settings_t *settings, void
|
|||
case EVENT_BACKGROUND_TASK:
|
||||
// play alarm
|
||||
if (state->alarm[state->alarm_playing_idx].beeps == 0) {
|
||||
_alarm_play_short_beep(state->alarm[state->alarm_playing_idx].pitch);
|
||||
// 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();
|
||||
}
|
||||
} 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),
|
||||
|
|
|
@ -79,7 +79,7 @@ static void next_op(rpn_calculator_state_t *state) {
|
|||
// FIXME: this converts the number to string and back, there might
|
||||
// be better ways to do this
|
||||
static float inc_digit(float num, uint8_t position) {
|
||||
char buf[7];
|
||||
char buf[8];
|
||||
if (position > 5) {
|
||||
return 0.0;
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ static void run_op(rpn_calculator_state_t *state) {
|
|||
state->mode = rpn_calculator_err;
|
||||
}
|
||||
|
||||
static void draw(rpn_calculator_state_t *state, uint8_t subsecond, movement_settings_t *settings) {
|
||||
static void draw(rpn_calculator_state_t *state, uint8_t subsecond) {
|
||||
char buf[16];
|
||||
switch (state->mode) {
|
||||
case rpn_calculator_err:
|
||||
|
@ -234,6 +234,7 @@ static void draw(rpn_calculator_state_t *state, uint8_t subsecond, movement_sett
|
|||
|
||||
void rpn_calculator_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) settings;
|
||||
(void) watch_face_index;
|
||||
if (*context_ptr == NULL) {
|
||||
*context_ptr = malloc(sizeof(rpn_calculator_state_t));
|
||||
memset(*context_ptr, 0, sizeof(rpn_calculator_state_t));
|
||||
|
@ -246,29 +247,30 @@ void rpn_calculator_face_setup(movement_settings_t *settings, uint8_t watch_face
|
|||
|
||||
void rpn_calculator_face_activate(movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
rpn_calculator_state_t *state = (rpn_calculator_state_t *)context;
|
||||
(void) state;
|
||||
(void) context;
|
||||
|
||||
// Handle any tasks related to your watch face coming on screen.
|
||||
}
|
||||
|
||||
bool rpn_calculator_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
|
||||
rpn_calculator_state_t *state = (rpn_calculator_state_t *)context;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
break;
|
||||
case EVENT_TICK:
|
||||
if (state->mode == rpn_calculator_number) {
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
}
|
||||
break;
|
||||
case EVENT_MODE_BUTTON_UP:
|
||||
switch (state->mode) {
|
||||
case rpn_calculator_number:
|
||||
state->mode = rpn_calculator_waiting;
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
movement_request_tick_frequency(1);
|
||||
break;
|
||||
default:
|
||||
|
@ -282,15 +284,15 @@ bool rpn_calculator_face_loop(movement_event_t event, movement_settings_t *setti
|
|||
switch (state->mode) {
|
||||
case rpn_calculator_waiting:
|
||||
state->mode = rpn_calculator_op;
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
break;
|
||||
case rpn_calculator_number:
|
||||
state->selection = (state->selection + 1) % 6;
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
break;
|
||||
case rpn_calculator_op:
|
||||
next_op(state);
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
break;
|
||||
default:
|
||||
movement_illuminate_led();
|
||||
|
@ -303,21 +305,21 @@ bool rpn_calculator_face_loop(movement_event_t event, movement_settings_t *setti
|
|||
state->mode = rpn_calculator_number;
|
||||
state->selection = 2;
|
||||
stack_push(state, 0);
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
movement_request_tick_frequency(4);
|
||||
break;
|
||||
case rpn_calculator_number:
|
||||
state->stack[state->top] = inc_digit(state->stack[state->top], state->selection);
|
||||
printf_stack(state);
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
break;
|
||||
case rpn_calculator_err:
|
||||
state->mode = rpn_calculator_waiting;
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
break;
|
||||
case rpn_calculator_op:
|
||||
run_op(state);
|
||||
draw(state, event.subsecond, settings);
|
||||
draw(state, event.subsecond);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -147,7 +147,6 @@ inline void watch_enable_buzzer(void) {
|
|||
if (!hri_tcc_get_CTRLA_reg(TCC0, TCC_CTRLA_ENABLE)) {
|
||||
_watch_enable_tcc();
|
||||
}
|
||||
gpio_set_pin_direction(BUZZER, GPIO_DIRECTION_OUT);
|
||||
}
|
||||
|
||||
inline void watch_set_buzzer_period(uint32_t period) {
|
||||
|
@ -157,7 +156,6 @@ inline void watch_set_buzzer_period(uint32_t period) {
|
|||
|
||||
void watch_disable_buzzer(void) {
|
||||
_watch_disable_tcc();
|
||||
watch_set_buzzer_off();
|
||||
}
|
||||
|
||||
inline void watch_set_buzzer_on(void) {
|
||||
|
@ -166,8 +164,8 @@ inline void watch_set_buzzer_on(void) {
|
|||
}
|
||||
|
||||
inline void watch_set_buzzer_off(void) {
|
||||
gpio_set_pin_direction(BUZZER, GPIO_DIRECTION_OFF);
|
||||
gpio_set_pin_function(BUZZER, GPIO_PIN_FUNCTION_OFF);
|
||||
gpio_set_pin_level(BUZZER, true);
|
||||
}
|
||||
|
||||
void watch_buzzer_play_note(BuzzerNote note, uint16_t duration_ms) {
|
||||
|
|
Loading…
Reference in a new issue