Enable custom signal tones in LE mode.
This makes movement_play_signal synchronous when in LE mode, despite using the underlying asynchronous API. It's a bit of a hack, but it should work well enough for now. This also moves the enabling/disabling of the buzzer into the movement_play_signal function, so that watch faces no longer have to do it.
This commit is contained in:
		
							parent
							
								
									3ee32c6e57
								
							
						
					
					
						commit
						e9fe4aeefe
					
				| @ -294,14 +294,31 @@ void movement_request_wake() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void movement_play_signal(void) { | void movement_play_signal(void) { | ||||||
| #ifdef SIGNAL_TUNE_DEFAULT |     watch_enable_buzzer(); | ||||||
|     watch_buzzer_play_note(BUZZER_NOTE_C8, 75); |     watch_buzzer_play_sequence(signal_tune, watch_disable_buzzer); | ||||||
|     watch_buzzer_play_note(BUZZER_NOTE_REST, 100); |     if (movement_state.le_mode_ticks == -1) { | ||||||
|     watch_buzzer_play_note(BUZZER_NOTE_C8, 100); | 	// This is somewhat of a hack. In order to play a sequence, we need to
 | ||||||
| #else | 	// be awake. We should ideally be able to tell movement that we need to
 | ||||||
|     // Does not work in LE mode.
 | 	// be awake for a given amount of time, but there's no good way to do
 | ||||||
|     watch_buzzer_play_sequence(signal_tune, NULL); | 	// this, so we block instead. This might be bad in the case that a
 | ||||||
| #endif // SIGNAL_TUNE_DEFAULT
 | 	// watch face has housekeeping to do after calling this, since it could
 | ||||||
|  | 	// in theory do that housekeeping concurrently, but alas.
 | ||||||
|  | 	//
 | ||||||
|  | 	// You might wonder, why not just put the instruction to go back to
 | ||||||
|  | 	// sleep in the callback? It's a good idea, but I can't figure out how
 | ||||||
|  | 	// to get it to work - you're basically kicking the can down the road,
 | ||||||
|  | 	// since at some point movement will be done doing what it's doing and
 | ||||||
|  | 	// have to wait. At that point, you're delaying anyways, but it's
 | ||||||
|  | 	// harder to figure out how much time to delay for, since you don't
 | ||||||
|  | 	// know how much time has elapsed since starting the sequence. I'd
 | ||||||
|  | 	// rather this block than have to read from the RTC to figure that
 | ||||||
|  | 	// out.
 | ||||||
|  | 	//
 | ||||||
|  | 	// Don't ask me what the +50ms is doing. The sequence gets cut short
 | ||||||
|  | 	// with the exact time, I have no idea why. 50 extra millisecons seems
 | ||||||
|  | 	// like a safe value.
 | ||||||
|  |         delay_ms(sequence_length(signal_tune) * 1000 / 64 + 50); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void movement_play_alarm(void) { | void movement_play_alarm(void) { | ||||||
|  | |||||||
| @ -49,8 +49,7 @@ const watch_face_t watch_faces[] = { | |||||||
|  */ |  */ | ||||||
| #define MOVEMENT_SECONDARY_FACE_INDEX (MOVEMENT_NUM_FACES - 2) // or (0)
 | #define MOVEMENT_SECONDARY_FACE_INDEX (MOVEMENT_NUM_FACES - 2) // or (0)
 | ||||||
| 
 | 
 | ||||||
| /* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options.
 | /* Custom hourly chime tune. Check movement_custom_signal_tunes.h for options. */ | ||||||
|  * Custom tunes do not currently work in LE mode. */ |  | ||||||
| #define SIGNAL_TUNE_DEFAULT | #define SIGNAL_TUNE_DEFAULT | ||||||
| 
 | 
 | ||||||
| #endif // MOVEMENT_CONFIG_H_
 | #endif // MOVEMENT_CONFIG_H_
 | ||||||
|  | |||||||
| @ -153,17 +153,7 @@ bool repetition_minute_face_loop(movement_event_t event, movement_settings_t *se | |||||||
|         case EVENT_BACKGROUND_TASK: |         case EVENT_BACKGROUND_TASK: | ||||||
|             // uncomment this line to snap back to the clock face when the hour signal sounds:
 |             // uncomment this line to snap back to the clock face when the hour signal sounds:
 | ||||||
|             // movement_move_to_face(state->watch_face_index);
 |             // movement_move_to_face(state->watch_face_index);
 | ||||||
|             if (watch_is_buzzer_or_led_enabled()) { |             movement_play_signal(); | ||||||
|                 // 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; |             break; | ||||||
|         case EVENT_LIGHT_LONG_UP: |         case EVENT_LIGHT_LONG_UP: | ||||||
|             /*
 |             /*
 | ||||||
|  | |||||||
| @ -180,17 +180,7 @@ bool simple_clock_bin_led_face_loop(movement_event_t event, movement_settings_t | |||||||
|         case EVENT_BACKGROUND_TASK: |         case EVENT_BACKGROUND_TASK: | ||||||
|             // uncomment this line to snap back to the clock face when the hour signal sounds:
 |             // uncomment this line to snap back to the clock face when the hour signal sounds:
 | ||||||
|             // movement_move_to_face(state->watch_face_index);
 |             // movement_move_to_face(state->watch_face_index);
 | ||||||
|             if (watch_is_buzzer_or_led_enabled()) { |             movement_play_signal(); | ||||||
|                 // 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; |             break; | ||||||
|         case EVENT_LIGHT_LONG_PRESS: |         case EVENT_LIGHT_LONG_PRESS: | ||||||
|             if (state->flashing_state == 0) { |             if (state->flashing_state == 0) { | ||||||
|  | |||||||
| @ -136,17 +136,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting | |||||||
|         case EVENT_BACKGROUND_TASK: |         case EVENT_BACKGROUND_TASK: | ||||||
|             // uncomment this line to snap back to the clock face when the hour signal sounds:
 |             // uncomment this line to snap back to the clock face when the hour signal sounds:
 | ||||||
|             // movement_move_to_face(state->watch_face_index);
 |             // movement_move_to_face(state->watch_face_index);
 | ||||||
|             if (watch_is_buzzer_or_led_enabled()) { |             movement_play_signal(); | ||||||
|                 // 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; |             break; | ||||||
|         default: |         default: | ||||||
|             return movement_default_loop_handler(event, settings); |             return movement_default_loop_handler(event, settings); | ||||||
|  | |||||||
| @ -130,17 +130,7 @@ bool weeknumber_clock_face_loop(movement_event_t event, movement_settings_t *set | |||||||
|         case EVENT_BACKGROUND_TASK: |         case EVENT_BACKGROUND_TASK: | ||||||
|             // uncomment this line to snap back to the clock face when the hour signal sounds:
 |             // uncomment this line to snap back to the clock face when the hour signal sounds:
 | ||||||
|             // movement_move_to_face(state->watch_face_index);
 |             // movement_move_to_face(state->watch_face_index);
 | ||||||
|             if (watch_is_buzzer_or_led_enabled()) { |             movement_play_signal(); | ||||||
|                 // 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; |             break; | ||||||
|         default: |         default: | ||||||
|             movement_default_loop_handler(event, settings); |             movement_default_loop_handler(event, settings); | ||||||
|  | |||||||
| @ -90,6 +90,15 @@ void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(v | |||||||
|     _tc3_start(); |     _tc3_start(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | uint16_t sequence_length(int8_t *sequence) { | ||||||
|  |     uint16_t result = 0; | ||||||
|  |     int i = 0; | ||||||
|  |     while (sequence[i++]) { | ||||||
|  |         result += sequence[i++]; | ||||||
|  |     } | ||||||
|  |     return result; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void cb_watch_buzzer_seq(void) { | void cb_watch_buzzer_seq(void) { | ||||||
|     // callback for reading the note sequence
 |     // callback for reading the note sequence
 | ||||||
|     if (_tone_ticks == 0) { |     if (_tone_ticks == 0) { | ||||||
|  | |||||||
| @ -175,6 +175,8 @@ extern const uint16_t NotePeriods[108]; | |||||||
|   */ |   */ | ||||||
| void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(void)); | void watch_buzzer_play_sequence(int8_t *note_sequence, void (*callback_on_end)(void)); | ||||||
| 
 | 
 | ||||||
|  | uint16_t sequence_length(int8_t *sequence); | ||||||
|  | 
 | ||||||
| /** @brief Aborts a playing sequence.
 | /** @brief Aborts a playing sequence.
 | ||||||
|   */ |   */ | ||||||
| void watch_buzzer_abort_sequence(void); | void watch_buzzer_abort_sequence(void); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user