add timeout event to give faces a chance to resign
This commit is contained in:
		
							parent
							
								
									8dbbe92a9b
								
							
						
					
					
						commit
						93624f0b69
					
				@ -7,7 +7,8 @@
 | 
			
		||||
 | 
			
		||||
movement_state_t movement_state;
 | 
			
		||||
void * watch_face_contexts[MOVEMENT_NUM_FACES];
 | 
			
		||||
const int32_t movement_inactivity_deadlines[8] = {INT_MAX, 3600, 7200, 21600, 43200, 86400, 172800, 604800};
 | 
			
		||||
const int32_t movement_le_inactivity_deadlines[8] = {INT_MAX, 3600, 7200, 21600, 43200, 86400, 172800, 604800};
 | 
			
		||||
const int32_t movement_timeout_inactivity_deadlines[4] = {60, 120, 300, 1800};
 | 
			
		||||
movement_event_t event;
 | 
			
		||||
 | 
			
		||||
void cb_mode_btn_interrupt();
 | 
			
		||||
@ -18,8 +19,10 @@ void cb_alarm_fired();
 | 
			
		||||
void cb_tick();
 | 
			
		||||
 | 
			
		||||
static inline void _movement_reset_inactivity_countdown() {
 | 
			
		||||
    // for testing, make the timeout happen 60x faster.
 | 
			
		||||
    movement_state.le_mode_ticks = movement_inactivity_deadlines[movement_state.settings.bit.le_inactivity_interval] / 60;
 | 
			
		||||
    // for testing, make the low energy timeout happen 60x faster.
 | 
			
		||||
    movement_state.le_mode_ticks = movement_le_inactivity_deadlines[movement_state.settings.bit.le_inactivity_interval] / 60;
 | 
			
		||||
    // for testing, make the inactivity timeout happen 4x faster.
 | 
			
		||||
    movement_state.timeout_ticks = movement_timeout_inactivity_deadlines[movement_state.settings.bit.to_inactivity_interval] / 4;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void movement_request_tick_frequency(uint8_t freq) {
 | 
			
		||||
@ -130,6 +133,11 @@ bool app_loop() {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // if we have timed out of our timeout countdown, give the app a hint that they can resign.
 | 
			
		||||
    if (movement_state.timeout_ticks == 0) {
 | 
			
		||||
        event.event_type = EVENT_TIMEOUT;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // if we have timed out of our low energy mode countdown, enter low energy mode.
 | 
			
		||||
    if (movement_state.le_mode_ticks == 0) {
 | 
			
		||||
        movement_state.le_mode_ticks = -1;
 | 
			
		||||
@ -210,6 +218,7 @@ void cb_tick() {
 | 
			
		||||
    if (date_time.unit.second != movement_state.last_second) {
 | 
			
		||||
        if (movement_state.light_ticks) movement_state.light_ticks--;
 | 
			
		||||
        if (movement_state.settings.bit.le_inactivity_interval && movement_state.le_mode_ticks > 0) movement_state.le_mode_ticks--;
 | 
			
		||||
        if (movement_state.timeout_ticks > 0) movement_state.timeout_ticks--;
 | 
			
		||||
 | 
			
		||||
        movement_state.last_second = date_time.unit.second;
 | 
			
		||||
        movement_state.subsecond = 0;
 | 
			
		||||
 | 
			
		||||
@ -6,9 +6,10 @@
 | 
			
		||||
// TODO: none of this is implemented
 | 
			
		||||
typedef union {
 | 
			
		||||
    struct {
 | 
			
		||||
        uint32_t reserved : 16;
 | 
			
		||||
        uint32_t reserved : 14;
 | 
			
		||||
        uint32_t clock_mode_24h : 1;        // determines whether clock should use 12 or 24 hour mode.
 | 
			
		||||
        uint32_t button_should_sound : 1;   // if true, pressing a button emits a sound.
 | 
			
		||||
        uint32_t to_inactivity_interval : 2;// an inactivity interval for asking the active face to resign.
 | 
			
		||||
        uint32_t le_inactivity_interval : 3;// 0 to disable low energy mode, or an inactivity interval for going into low energy mode.
 | 
			
		||||
        uint32_t led_duration : 3;          // how many seconds to shine the LED for, or 0 to disable it.
 | 
			
		||||
        uint32_t led_red_color : 4;         // for general purpose illumination, the red LED value (0-15)
 | 
			
		||||
@ -23,6 +24,7 @@ typedef enum {
 | 
			
		||||
    EVENT_TICK,                 // Most common event type. Your watch face is being called from the tick callback.
 | 
			
		||||
    EVENT_LOW_ENERGY_UPDATE,    // If the watch is in low energy mode and you are in the foreground, you will get a chance to update the display once per minute.
 | 
			
		||||
    EVENT_BACKGROUND_TASK,      // Your watch face is being invoked to perform a background task. Don't update the display here; you may not be in the foreground.
 | 
			
		||||
    EVENT_TIMEOUT,              // Your watch face has been inactive for a while. You may want to resign, depending on your watch face's intended use case.
 | 
			
		||||
    EVENT_LIGHT_BUTTON_DOWN,    // The light button has been pressed, but not yet released.
 | 
			
		||||
    EVENT_LIGHT_BUTTON_UP,      // The light button was pressed and released.
 | 
			
		||||
    EVENT_LIGHT_LONG_PRESS,     // The light button was held for >2 seconds, and released.
 | 
			
		||||
@ -162,6 +164,9 @@ typedef struct {
 | 
			
		||||
    // low energy mode countdown
 | 
			
		||||
    int32_t le_mode_ticks;
 | 
			
		||||
 | 
			
		||||
    // app resignation countdown (TODO: consolidate with LE countdown?)
 | 
			
		||||
    int16_t timeout_ticks;
 | 
			
		||||
 | 
			
		||||
    // stuff for subsecond tracking
 | 
			
		||||
    uint8_t tick_frequency;
 | 
			
		||||
    uint8_t last_second;
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,6 @@ void simple_clock_face_activate(movement_settings_t *settings, void *context) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool simple_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
 | 
			
		||||
    printf("simple_clock_face_loop\n");
 | 
			
		||||
    const char weekdays[7][3] = {"SA", "SU", "MO", "TU", "WE", "TH", "FR"};
 | 
			
		||||
    char buf[11];
 | 
			
		||||
    uint8_t pos;
 | 
			
		||||
@ -28,6 +27,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
 | 
			
		||||
    switch (event.event_type) {
 | 
			
		||||
        case EVENT_ACTIVATE:
 | 
			
		||||
        case EVENT_TICK:
 | 
			
		||||
        case EVENT_TIMEOUT:
 | 
			
		||||
        case EVENT_LOW_ENERGY_UPDATE:
 | 
			
		||||
            date_time = watch_rtc_get_date_time();
 | 
			
		||||
            previous_date_time = *((uint32_t *)context);
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,6 @@ void pulsometer_face_activate(movement_settings_t *settings, void *context) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
 | 
			
		||||
    printf("pulsometer_face_loop\n");
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    pulsometer_state_t *pulsometer_state = (pulsometer_state_t *)context;
 | 
			
		||||
    char buf[14];
 | 
			
		||||
@ -74,6 +73,9 @@ bool pulsometer_face_loop(movement_event_t event, movement_settings_t *settings,
 | 
			
		||||
            pulsometer_state->measuring = false;
 | 
			
		||||
            movement_request_tick_frequency(1);
 | 
			
		||||
            break;
 | 
			
		||||
        case EVENT_TIMEOUT:
 | 
			
		||||
            movement_move_to_face(0);
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,6 @@ void preferences_face_activate(movement_settings_t *settings, void *context) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
 | 
			
		||||
    printf("preferences_face_loop\n");
 | 
			
		||||
    uint8_t current_page = *((uint8_t *)context);
 | 
			
		||||
    switch (event.event_type) {
 | 
			
		||||
        case EVENT_MODE_BUTTON_UP:
 | 
			
		||||
@ -47,6 +46,9 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case EVENT_TIMEOUT:
 | 
			
		||||
            movement_move_to_face(0);
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -58,6 +58,9 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
 | 
			
		||||
            }
 | 
			
		||||
            watch_rtc_set_date_time(date_time);
 | 
			
		||||
            break;
 | 
			
		||||
        case EVENT_TIMEOUT:
 | 
			
		||||
            movement_move_to_face(0);
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user