rename types to be more c-like
This commit is contained in:
		
							parent
							
								
									d5ac4cb71b
								
							
						
					
					
						commit
						d36331ce4e
					
				@ -5,10 +5,10 @@
 | 
			
		||||
#include "movement.h"
 | 
			
		||||
#include "movement_config.h"
 | 
			
		||||
 | 
			
		||||
LauncherState movement_state;
 | 
			
		||||
movement_state_t movement_state;
 | 
			
		||||
void * watch_face_contexts[MOVEMENT_NUM_FACES];
 | 
			
		||||
const int32_t movement_screensaver_deadlines[8] = {INT_MAX, 3600, 7200, 21600, 43200, 86400, 172800, 604800};
 | 
			
		||||
LauncherEvent event;
 | 
			
		||||
movement_event_t event;
 | 
			
		||||
 | 
			
		||||
void cb_mode_btn_interrupt();
 | 
			
		||||
void cb_light_btn_interrupt();
 | 
			
		||||
@ -166,16 +166,16 @@ bool app_loop() {
 | 
			
		||||
    return can_sleep && !movement_state.led_on;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
LauncherEventType _figure_out_button_event(LauncherEventType button_down_event, uint8_t *down_timestamp) {
 | 
			
		||||
movement_event_type_t _figure_out_button_event(movement_event_type_t button_down_event_type, uint8_t *down_timestamp) {
 | 
			
		||||
    watch_date_time date_time = watch_rtc_get_date_time();
 | 
			
		||||
    if (*down_timestamp) {
 | 
			
		||||
        uint8_t diff = ((61 + date_time.unit.second) - *down_timestamp) % 60;
 | 
			
		||||
        *down_timestamp = 0;
 | 
			
		||||
        if (diff > 1) return button_down_event + 2;
 | 
			
		||||
        else return button_down_event + 1;
 | 
			
		||||
        if (diff > 1) return button_down_event_type + 2;
 | 
			
		||||
        else return button_down_event_type + 1;
 | 
			
		||||
    } else {
 | 
			
		||||
        *down_timestamp = date_time.unit.second + 1;
 | 
			
		||||
        return button_down_event;
 | 
			
		||||
        return button_down_event_type;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -19,7 +19,7 @@ typedef union {
 | 
			
		||||
        uint32_t led_green_color : 4;       // for general purpose illumination, the green LED value (0-15)
 | 
			
		||||
    } bit;
 | 
			
		||||
    uint32_t value;
 | 
			
		||||
} LauncherSettings;
 | 
			
		||||
} movement_settings_t;
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
    EVENT_NONE = 0,             // There is no event to report.
 | 
			
		||||
@ -35,28 +35,28 @@ typedef enum {
 | 
			
		||||
    EVENT_ALARM_BUTTON_DOWN,    // The alarm button has been pressed, but not yet released.
 | 
			
		||||
    EVENT_ALARM_BUTTON_UP,      // The alarm button was pressed and released.
 | 
			
		||||
    EVENT_ALARM_LONG_PRESS,     // The alarm button was held for >2 seconds, and released.
 | 
			
		||||
} LauncherEventType;
 | 
			
		||||
} movement_event_type_t;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    uint8_t event_type;
 | 
			
		||||
    uint8_t subsecond;
 | 
			
		||||
} LauncherEvent;
 | 
			
		||||
} movement_event_t;
 | 
			
		||||
 | 
			
		||||
typedef void (*watch_face_setup)(LauncherSettings *settings, void ** context_ptr);
 | 
			
		||||
typedef void (*watch_face_activate)(LauncherSettings *settings, void *context);
 | 
			
		||||
typedef bool (*watch_face_loop)(LauncherEvent event, LauncherSettings *settings, void *context);
 | 
			
		||||
typedef void (*watch_face_resign)(LauncherSettings *settings, void *context);
 | 
			
		||||
typedef void (*watch_face_setup)(movement_settings_t *settings, void ** context_ptr);
 | 
			
		||||
typedef void (*watch_face_activate)(movement_settings_t *settings, void *context);
 | 
			
		||||
typedef bool (*watch_face_loop)(movement_event_t event, movement_settings_t *settings, void *context);
 | 
			
		||||
typedef void (*watch_face_resign)(movement_settings_t *settings, void *context);
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    watch_face_setup setup;
 | 
			
		||||
    watch_face_activate activate;
 | 
			
		||||
    watch_face_loop loop;
 | 
			
		||||
    watch_face_resign resign;
 | 
			
		||||
} WatchFace;
 | 
			
		||||
} watch_face_t;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    // properties stored in BACKUP register
 | 
			
		||||
    LauncherSettings movement_settings;
 | 
			
		||||
    movement_settings_t movement_settings;
 | 
			
		||||
 | 
			
		||||
    // transient properties
 | 
			
		||||
    int16_t current_watch_face;
 | 
			
		||||
@ -79,7 +79,7 @@ typedef struct {
 | 
			
		||||
    uint8_t tick_frequency;
 | 
			
		||||
    uint8_t last_second;
 | 
			
		||||
    uint8_t subsecond;
 | 
			
		||||
} LauncherState;
 | 
			
		||||
} movement_state_t;
 | 
			
		||||
 | 
			
		||||
void movement_move_to_face(uint8_t watch_face_index);
 | 
			
		||||
void movement_move_to_next_face();
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,7 @@
 | 
			
		||||
 | 
			
		||||
#define MOVEMENT_NUM_FACES 3
 | 
			
		||||
 | 
			
		||||
WatchFace watch_faces[MOVEMENT_NUM_FACES] = {
 | 
			
		||||
watch_face_t watch_faces[MOVEMENT_NUM_FACES] = {
 | 
			
		||||
    simple_clock_face,
 | 
			
		||||
    preferences_face,
 | 
			
		||||
    set_time_face,
 | 
			
		||||
 | 
			
		||||
@ -2,13 +2,13 @@
 | 
			
		||||
#include "simple_clock_face.h"
 | 
			
		||||
#include "watch.h"
 | 
			
		||||
 | 
			
		||||
void simple_clock_face_setup(LauncherSettings *settings, void ** context_ptr) {
 | 
			
		||||
void simple_clock_face_setup(movement_settings_t *settings, void ** context_ptr) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    // the only context we need is the timestamp of the previous tick.
 | 
			
		||||
    if (*context_ptr == NULL) *context_ptr = malloc(sizeof(uint32_t));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void simple_clock_face_activate(LauncherSettings *settings, void *context) {
 | 
			
		||||
void simple_clock_face_activate(movement_settings_t *settings, void *context) {
 | 
			
		||||
    if (settings->bit.clock_mode_24h) {
 | 
			
		||||
        watch_set_indicator(WATCH_INDICATOR_24H);
 | 
			
		||||
    }
 | 
			
		||||
@ -17,7 +17,7 @@ void simple_clock_face_activate(LauncherSettings *settings, void *context) {
 | 
			
		||||
    *((uint32_t *)context) = 0xFFFFFFFF;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool simple_clock_face_loop(LauncherEvent event, LauncherSettings *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];
 | 
			
		||||
@ -77,7 +77,7 @@ bool simple_clock_face_loop(LauncherEvent event, LauncherSettings *settings, voi
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void simple_clock_face_resign(LauncherSettings *settings, void *context) {
 | 
			
		||||
void simple_clock_face_resign(movement_settings_t *settings, void *context) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    (void) context;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -3,10 +3,10 @@
 | 
			
		||||
 | 
			
		||||
#include "movement.h"
 | 
			
		||||
 | 
			
		||||
void simple_clock_face_setup(LauncherSettings *settings, void ** context_ptr);
 | 
			
		||||
void simple_clock_face_activate(LauncherSettings *settings, void *context);
 | 
			
		||||
bool simple_clock_face_loop(LauncherEvent event, LauncherSettings *settings, void *context);
 | 
			
		||||
void simple_clock_face_resign(LauncherSettings *settings, void *context);
 | 
			
		||||
void simple_clock_face_setup(movement_settings_t *settings, void ** context_ptr);
 | 
			
		||||
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);
 | 
			
		||||
void simple_clock_face_resign(movement_settings_t *settings, void *context);
 | 
			
		||||
 | 
			
		||||
uint8_t simple_clock_face_get_weekday(uint16_t day, uint16_t month, uint16_t year);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,17 +6,17 @@
 | 
			
		||||
#define PULSOMETER_FACE_FREQUENCY_FACTOR (4ul) // refresh rate will be 2 to this power Hz (0 for 1 Hz, 2 for 4 Hz, etc.)
 | 
			
		||||
#define PULSOMETER_FACE_FREQUENCY (1 << PULSOMETER_FACE_FREQUENCY_FACTOR)
 | 
			
		||||
 | 
			
		||||
void pulseometer_face_setup(LauncherSettings *settings, void ** context_ptr) {
 | 
			
		||||
void pulseometer_face_setup(movement_settings_t *settings, void ** context_ptr) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    if (*context_ptr == NULL) *context_ptr = malloc(sizeof(PulsometerState));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pulseometer_face_activate(LauncherSettings *settings, void *context) {
 | 
			
		||||
void pulseometer_face_activate(movement_settings_t *settings, void *context) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    memset(context, 0, sizeof(PulsometerState));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool pulseometer_face_loop(LauncherEvent event, LauncherSettings *settings, void *context) {
 | 
			
		||||
bool pulseometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
 | 
			
		||||
    printf("pulseometer_face_loop\n");
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    PulsometerState *pulsometer_state = (PulsometerState *)context;
 | 
			
		||||
@ -81,7 +81,7 @@ bool pulseometer_face_loop(LauncherEvent event, LauncherSettings *settings, void
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pulseometer_face_resign(LauncherSettings *settings, void *context) {
 | 
			
		||||
void pulseometer_face_resign(movement_settings_t *settings, void *context) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    (void) context;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -9,10 +9,10 @@ typedef struct {
 | 
			
		||||
    int16_t ticks;
 | 
			
		||||
} PulsometerState;
 | 
			
		||||
 | 
			
		||||
void pulseometer_face_setup(LauncherSettings *settings, void ** context_ptr);
 | 
			
		||||
void pulseometer_face_activate(LauncherSettings *settings, void *context);
 | 
			
		||||
bool pulseometer_face_loop(LauncherEvent event, LauncherSettings *settings, void *context);
 | 
			
		||||
void pulseometer_face_resign(LauncherSettings *settings, void *context);
 | 
			
		||||
void pulseometer_face_setup(movement_settings_t *settings, void ** context_ptr);
 | 
			
		||||
void pulseometer_face_activate(movement_settings_t *settings, void *context);
 | 
			
		||||
bool pulseometer_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
 | 
			
		||||
void pulseometer_face_resign(movement_settings_t *settings, void *context);
 | 
			
		||||
 | 
			
		||||
#define pulseometer_face { \
 | 
			
		||||
    pulseometer_face_setup, \
 | 
			
		||||
 | 
			
		||||
@ -5,18 +5,18 @@
 | 
			
		||||
#define PREFERENCES_FACE_NUM_PREFEFENCES (5)
 | 
			
		||||
const char preferences_face_titles[PREFERENCES_FACE_NUM_PREFEFENCES][11] = {"CL        ", "Bt  Beep  ", "SC        ", "Lt   grn  ", "Lt   red  "};
 | 
			
		||||
 | 
			
		||||
void preferences_face_setup(LauncherSettings *settings, void ** context_ptr) {
 | 
			
		||||
void preferences_face_setup(movement_settings_t *settings, void ** context_ptr) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    if (*context_ptr == NULL) *context_ptr = malloc(sizeof(uint8_t));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void preferences_face_activate(LauncherSettings *settings, void *context) {
 | 
			
		||||
void preferences_face_activate(movement_settings_t *settings, void *context) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    *((uint8_t *)context) = 0;
 | 
			
		||||
    movement_request_tick_frequency(4); // we need to manually blink some pixels
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool preferences_face_loop(LauncherEvent event, LauncherSettings *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) {
 | 
			
		||||
@ -112,7 +112,7 @@ bool preferences_face_loop(LauncherEvent event, LauncherSettings *settings, void
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void preferences_face_resign(LauncherSettings *settings, void *context) {
 | 
			
		||||
void preferences_face_resign(movement_settings_t *settings, void *context) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    (void) context;
 | 
			
		||||
    watch_set_led_off();
 | 
			
		||||
 | 
			
		||||
@ -3,10 +3,10 @@
 | 
			
		||||
 | 
			
		||||
#include "movement.h"
 | 
			
		||||
 | 
			
		||||
void preferences_face_setup(LauncherSettings *settings, void ** context_ptr);
 | 
			
		||||
void preferences_face_activate(LauncherSettings *settings, void *context);
 | 
			
		||||
bool preferences_face_loop(LauncherEvent event, LauncherSettings *settings, void *context);
 | 
			
		||||
void preferences_face_resign(LauncherSettings *settings, void *context);
 | 
			
		||||
void preferences_face_setup(movement_settings_t *settings, void ** context_ptr);
 | 
			
		||||
void preferences_face_activate(movement_settings_t *settings, void *context);
 | 
			
		||||
bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
 | 
			
		||||
void preferences_face_resign(movement_settings_t *settings, void *context);
 | 
			
		||||
 | 
			
		||||
#define preferences_face { \
 | 
			
		||||
    preferences_face_setup, \
 | 
			
		||||
 | 
			
		||||
@ -5,18 +5,18 @@
 | 
			
		||||
#define SET_TIME_FACE_NUM_SETTINGS (6)
 | 
			
		||||
const char set_time_face_titles[SET_TIME_FACE_NUM_SETTINGS][3] = {"HR", "MN", "SE", "YR", "MO", "DA"};
 | 
			
		||||
 | 
			
		||||
void set_time_face_setup(LauncherSettings *settings, void ** context_ptr) {
 | 
			
		||||
void set_time_face_setup(movement_settings_t *settings, void ** context_ptr) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    if (*context_ptr == NULL) *context_ptr = malloc(sizeof(uint8_t));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void set_time_face_activate(LauncherSettings *settings, void *context) {
 | 
			
		||||
void set_time_face_activate(movement_settings_t *settings, void *context) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    *((uint8_t *)context) = 0;
 | 
			
		||||
    movement_request_tick_frequency(4);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool set_time_face_loop(LauncherEvent event, LauncherSettings *settings, void *context) {
 | 
			
		||||
bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
 | 
			
		||||
    uint8_t current_page = *((uint8_t *)context);
 | 
			
		||||
    const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 30, 31, 30, 31, 30, 31};
 | 
			
		||||
    watch_date_time date_time = watch_rtc_get_date_time();
 | 
			
		||||
@ -101,7 +101,7 @@ bool set_time_face_loop(LauncherEvent event, LauncherSettings *settings, void *c
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void set_time_face_resign(LauncherSettings *settings, void *context) {
 | 
			
		||||
void set_time_face_resign(movement_settings_t *settings, void *context) {
 | 
			
		||||
    (void) settings;
 | 
			
		||||
    (void) context;
 | 
			
		||||
    watch_set_led_off();
 | 
			
		||||
 | 
			
		||||
@ -3,10 +3,10 @@
 | 
			
		||||
 | 
			
		||||
#include "movement.h"
 | 
			
		||||
 | 
			
		||||
void set_time_face_setup(LauncherSettings *settings, void ** context_ptr);
 | 
			
		||||
void set_time_face_activate(LauncherSettings *settings, void *context);
 | 
			
		||||
bool set_time_face_loop(LauncherEvent event, LauncherSettings *settings, void *context);
 | 
			
		||||
void set_time_face_resign(LauncherSettings *settings, void *context);
 | 
			
		||||
void set_time_face_setup(movement_settings_t *settings, void ** context_ptr);
 | 
			
		||||
void set_time_face_activate(movement_settings_t *settings, void *context);
 | 
			
		||||
bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
 | 
			
		||||
void set_time_face_resign(movement_settings_t *settings, void *context);
 | 
			
		||||
 | 
			
		||||
#define set_time_face { \
 | 
			
		||||
    set_time_face_setup, \
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user