basic launcher switching between two widgets
This commit is contained in:
		
							parent
							
								
									399caa2582
								
							
						
					
					
						commit
						95ea714d61
					
				| @ -7,6 +7,11 @@ | |||||||
| LauncherState launcher_state; | LauncherState launcher_state; | ||||||
| void * widget_contexts[LAUNCHER_NUM_WIDGETS]; | void * widget_contexts[LAUNCHER_NUM_WIDGETS]; | ||||||
| 
 | 
 | ||||||
|  | void cb_mode_pressed(); | ||||||
|  | void cb_light_pressed(); | ||||||
|  | void cb_alarm_pressed(); | ||||||
|  | void cb_tick(); | ||||||
|  | 
 | ||||||
| void launcher_request_tick_frequency(uint8_t freq) { | void launcher_request_tick_frequency(uint8_t freq) { | ||||||
|     watch_rtc_disable_all_periodic_callbacks(); |     watch_rtc_disable_all_periodic_callbacks(); | ||||||
|     watch_rtc_register_periodic_callback(cb_tick, freq); |     watch_rtc_register_periodic_callback(cb_tick, freq); | ||||||
| @ -16,10 +21,26 @@ void launcher_illuminate_led() { | |||||||
|     launcher_state.light_ticks = 3; |     launcher_state.light_ticks = 3; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void launcher_move_to_next_widget() { | ||||||
|  |     launcher_state.widget_changed = true; | ||||||
|  |     widgets[launcher_state.current_widget].resign(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); | ||||||
|  |     launcher_state.current_widget = (launcher_state.current_widget + 1) % LAUNCHER_NUM_WIDGETS; | ||||||
|  |     widgets[launcher_state.current_widget].activate(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); | ||||||
|  |     watch_display_string(widgets[launcher_state.current_widget].widget_name, 0); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void launcher_move_to_first_widget() { | ||||||
|  |     launcher_state.widget_changed = true; | ||||||
|  |     widgets[launcher_state.current_widget].resign(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); | ||||||
|  |     launcher_state.current_widget = 0; | ||||||
|  |     widgets[0].activate(&launcher_state.launcher_settings, widget_contexts[0]); | ||||||
|  |     watch_display_string(widgets[launcher_state.current_widget].widget_name, 0); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| void app_init() { | void app_init() { | ||||||
|     memset(&launcher_state, 0, sizeof(launcher_state)); |     memset(&launcher_state, 0, sizeof(launcher_state)); | ||||||
|     launcher_state.launcher_settings.bit.led_green_color = 0xF; |     launcher_state.launcher_settings.bit.led_green_color = 0xF; | ||||||
|  |     launcher_state.launcher_settings.bit.led_red_color = 0x0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void app_wake_from_deep_sleep() { | void app_wake_from_deep_sleep() { | ||||||
| @ -41,6 +62,8 @@ void app_setup() { | |||||||
|     for(uint8_t i = 0; i < LAUNCHER_NUM_WIDGETS; i++) { |     for(uint8_t i = 0; i < LAUNCHER_NUM_WIDGETS; i++) { | ||||||
|         widgets[i].setup(&launcher_state.launcher_settings, widget_contexts[i]); |         widgets[i].setup(&launcher_state.launcher_settings, widget_contexts[i]); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     launcher_move_to_first_widget(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void app_prepare_for_sleep() { | void app_prepare_for_sleep() { | ||||||
| @ -61,8 +84,10 @@ bool app_loop() { | |||||||
| 
 | 
 | ||||||
|     // If the LED is off and should be on, turn it on
 |     // If the LED is off and should be on, turn it on
 | ||||||
|     if (launcher_state.light_ticks > 0 && !launcher_state.led_on) { |     if (launcher_state.light_ticks > 0 && !launcher_state.led_on) { | ||||||
|         watch_set_led_color(launcher_state.launcher_settings.bit.led_red_color, launcher_state.launcher_settings.bit.led_green_color); |         watch_set_led_color(launcher_state.launcher_settings.bit.led_red_color ? (0xF | launcher_state.launcher_settings.bit.led_red_color << 4) : 0, | ||||||
|  |                             launcher_state.launcher_settings.bit.led_green_color ? (0xF | launcher_state.launcher_settings.bit.led_green_color << 4) : 0); | ||||||
|         launcher_state.led_on = true; |         launcher_state.led_on = true; | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // if the LED is on and should be off, turn it off
 |     // if the LED is on and should be off, turn it off
 | ||||||
| @ -77,71 +102,42 @@ bool app_loop() { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (event) { |     if (event) { | ||||||
|         event = 0; |  | ||||||
|         widgets[launcher_state.current_widget].loop(event, &launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); |         widgets[launcher_state.current_widget].loop(event, &launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); | ||||||
|  |         event = 0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|     if (launcher_state.led_on) return false; |     if (launcher_state.led_on) return false; | ||||||
| 
 | 
 | ||||||
|     return true; |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void move_to_next_widget() { | LauncherEvent _figure_out_button_event(LauncherEvent button_down_event, uint8_t *down_timestamp) { | ||||||
|     launcher_state.widget_changed = true; |     watch_date_time date_time = watch_rtc_get_date_time(); | ||||||
|     widgets[launcher_state.current_widget].resign(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); |     if (*down_timestamp) { | ||||||
|     launcher_state.current_widget = (launcher_state.current_widget + 1) % LAUNCHER_NUM_WIDGETS; |         uint8_t diff = ((61 + date_time.unit.second) - *down_timestamp) % 60; | ||||||
|     widgets[launcher_state.current_widget].activate(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); |         *down_timestamp = 0; | ||||||
| } |         if (diff > 1) return button_down_event + 2; | ||||||
| 
 |         else return button_down_event + 1; | ||||||
| void move_to_first_widget() { |     } else { | ||||||
|     launcher_state.widget_changed = true; |         *down_timestamp = date_time.unit.second + 1; | ||||||
|     widgets[launcher_state.current_widget].resign(&launcher_state.launcher_settings, widget_contexts[launcher_state.current_widget]); |         return button_down_event; | ||||||
|     launcher_state.current_widget = 0; |     } | ||||||
|     widgets[0].activate(&launcher_state.launcher_settings, widget_contexts[0]); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void cb_light_pressed() { | void cb_light_pressed() { | ||||||
|     struct calendar_date_time date_time; |     event = _figure_out_button_event(EVENT_LIGHT_BUTTON_DOWN, &launcher_state.light_down_timestamp); | ||||||
|     watch_get_date_time(&date_time); |  | ||||||
|     if (launcher_state.light_down_timestamp) { |  | ||||||
|         uint8_t diff = (61 + date_time.time.sec) - launcher_state.light_down_timestamp; |  | ||||||
|         if (diff > 1) event = EVENT_LIGHT_LONG_PRESS; |  | ||||||
|         else event = EVENT_LIGHT_BUTTON_UP; |  | ||||||
|         launcher_state.light_down_timestamp = 0; |  | ||||||
|     } else { |  | ||||||
|         launcher_state.light_down_timestamp = date_time.time.sec + 1; |  | ||||||
|         event = EVENT_LIGHT_BUTTON_DOWN; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void cb_mode_pressed() { | void cb_mode_pressed() { | ||||||
|     struct calendar_date_time date_time; |     event = _figure_out_button_event(EVENT_MODE_BUTTON_DOWN, &launcher_state.mode_down_timestamp); | ||||||
|     watch_get_date_time(&date_time); |  | ||||||
|     if (launcher_state.mode_down_timestamp) { |  | ||||||
|         uint8_t diff = (61 + date_time.time.sec) - launcher_state.mode_down_timestamp; |  | ||||||
|         if (diff > 1) event = EVENT_MODE_LONG_PRESS; |  | ||||||
|         else event = EVENT_MODE_BUTTON_UP; |  | ||||||
|         launcher_state.mode_down_timestamp = 0; |  | ||||||
|     } else { |  | ||||||
|         launcher_state.mode_down_timestamp = date_time.time.sec + 1; |  | ||||||
|         event = EVENT_MODE_BUTTON_DOWN; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void cb_alarm_pressed() { | void cb_alarm_pressed() { | ||||||
|     struct calendar_date_time date_time; |     event = _figure_out_button_event(EVENT_ALARM_BUTTON_DOWN, &launcher_state.alarm_down_timestamp); | ||||||
|     watch_get_date_time(&date_time); |  | ||||||
|     if (launcher_state.alarm_down_timestamp) { |  | ||||||
|         uint8_t diff = (61 + date_time.time.sec) - launcher_state.alarm_down_timestamp; |  | ||||||
|         if (diff > 1) event = EVENT_ALARM_LONG_PRESS; |  | ||||||
|         else event = EVENT_ALARM_BUTTON_UP; |  | ||||||
|         launcher_state.alarm_down_timestamp = 0; |  | ||||||
|     } else { |  | ||||||
|         launcher_state.alarm_down_timestamp = date_time.time.sec + 1; |  | ||||||
|         event = EVENT_ALARM_BUTTON_DOWN; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void cb_tick() { | void cb_tick() { | ||||||
|     event = EVENT_TICK; |     event = EVENT_TICK; | ||||||
|  |     if (launcher_state.light_ticks) launcher_state.light_ticks--; | ||||||
| } | } | ||||||
|  | |||||||
| @ -42,7 +42,6 @@ typedef void (*launcher_widget_resign)(LauncherSettings *settings, void *context | |||||||
| 
 | 
 | ||||||
| typedef struct WatchWidget { | typedef struct WatchWidget { | ||||||
|     char widget_name[11]; |     char widget_name[11]; | ||||||
|     bool snapback_enabled; |  | ||||||
|     launcher_widget_setup setup; |     launcher_widget_setup setup; | ||||||
|     launcher_widget_activate activate; |     launcher_widget_activate activate; | ||||||
|     launcher_widget_loop loop; |     launcher_widget_loop loop; | ||||||
| @ -67,9 +66,8 @@ typedef struct LauncherState { | |||||||
|     uint8_t alarm_down_timestamp; |     uint8_t alarm_down_timestamp; | ||||||
| } LauncherState; | } LauncherState; | ||||||
| 
 | 
 | ||||||
| void cb_mode_pressed(); | void launcher_move_to_next_widget(); | ||||||
| void cb_light_pressed(); | void launcher_move_to_first_widget(); | ||||||
| void cb_alarm_pressed(); | void launcher_illuminate_led(); | ||||||
| void cb_tick(); |  | ||||||
| 
 | 
 | ||||||
| #endif // LAUNCHER_H_
 | #endif // LAUNCHER_H_
 | ||||||
|  | |||||||
| @ -1,12 +1,14 @@ | |||||||
| #ifndef LAUNCHER_CONFIG_H_ | #ifndef LAUNCHER_CONFIG_H_ | ||||||
| #define LAUNCHER_CONFIG_H_ | #define LAUNCHER_CONFIG_H_ | ||||||
| 
 | 
 | ||||||
| #include "fake_widget.h" | #include "fake_widget_1.h" | ||||||
|  | #include "fake_widget_2.h" | ||||||
| 
 | 
 | ||||||
| #define LAUNCHER_NUM_WIDGETS 1 | #define LAUNCHER_NUM_WIDGETS 2 | ||||||
| 
 | 
 | ||||||
| WatchWidget widgets[LAUNCHER_NUM_WIDGETS] = { | WatchWidget widgets[LAUNCHER_NUM_WIDGETS] = { | ||||||
|     fake_widget |     fake_widget_1, | ||||||
|  |     fake_widget_2, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -20,7 +20,8 @@ INCLUDES += \ | |||||||
| #   ../utils/temperature.c
 | #   ../utils/temperature.c
 | ||||||
| SRCS += \
 | SRCS += \
 | ||||||
|   ../launcher.c \
 |   ../launcher.c \
 | ||||||
|   ../widgets/fake_widget.c \
 |   ../widgets/fake_widget_1.c \
 | ||||||
|  |   ../widgets/fake_widget_2.c \
 | ||||||
| 
 | 
 | ||||||
| # Leave this line at the bottom of the file; it has all the targets for making your project.
 | # Leave this line at the bottom of the file; it has all the targets for making your project.
 | ||||||
| include $(TOP)/rules.mk | include $(TOP)/rules.mk | ||||||
|  | |||||||
| @ -1,24 +0,0 @@ | |||||||
| #include "fake_widget.h" |  | ||||||
| 
 |  | ||||||
| void fake_widget_setup(LauncherSettings *settings, void ** context_ptr) { |  | ||||||
|     (void) settings; |  | ||||||
|     *context_ptr = NULL; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void fake_widget_activate(LauncherSettings *settings, void *context) { |  | ||||||
|     (void) settings; |  | ||||||
|     (void) context; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void fake_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context) { |  | ||||||
|     (void) event; |  | ||||||
|     (void) settings; |  | ||||||
|     (void) context; |  | ||||||
| 
 |  | ||||||
|     return true; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void fake_widget_resign(LauncherSettings *settings, void *context) { |  | ||||||
|     (void) settings; |  | ||||||
|     (void) context; |  | ||||||
| } |  | ||||||
| @ -1,20 +0,0 @@ | |||||||
| #ifndef FAKE_WIDGET_H_ |  | ||||||
| #define FAKE_WIDGET_H_ |  | ||||||
| 
 |  | ||||||
| #include "launcher.h" |  | ||||||
| 
 |  | ||||||
| void fake_widget_setup(LauncherSettings *settings, void ** context_ptr); |  | ||||||
| void fake_widget_activate(LauncherSettings *settings, void *context); |  | ||||||
| void fake_widget_loop(LauncherEvent event, LauncherSettings *settings, void *context); |  | ||||||
| void fake_widget_resign(LauncherSettings *settings, void *context); |  | ||||||
| 
 |  | ||||||
| #define fake_widget { \ |  | ||||||
|     "WI dGIt01", \ |  | ||||||
|     true, \ |  | ||||||
|     fake_widget_setup, \ |  | ||||||
|     fake_widget_activate, \ |  | ||||||
|     fake_widget_loop, \ |  | ||||||
|     fake_widget_resign, \ |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #endif // FAKE_WIDGET_H_
 |  | ||||||
							
								
								
									
										32
									
								
								launcher/widgets/fake_widget_1.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								launcher/widgets/fake_widget_1.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | |||||||
|  | #include "fake_widget_1.h" | ||||||
|  | 
 | ||||||
|  | void fake_widget_1_setup(LauncherSettings *settings, void ** context_ptr) { | ||||||
|  |     (void) settings; | ||||||
|  |     // *context_ptr = NULL;
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void fake_widget_1_activate(LauncherSettings *settings, void *context) { | ||||||
|  |     (void) settings; | ||||||
|  |     (void) context; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void fake_widget_1_loop(LauncherEvent event, LauncherSettings *settings, void *context) { | ||||||
|  |     (void) settings; | ||||||
|  |     (void) context; | ||||||
|  | 
 | ||||||
|  |     switch (event) { | ||||||
|  |         case EVENT_MODE_BUTTON_UP: | ||||||
|  |             launcher_move_to_next_widget(); | ||||||
|  |             break; | ||||||
|  |         case EVENT_LIGHT_BUTTON_UP: | ||||||
|  |             launcher_illuminate_led(); | ||||||
|  |             break; | ||||||
|  |         default: | ||||||
|  |             break; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void fake_widget_1_resign(LauncherSettings *settings, void *context) { | ||||||
|  |     (void) settings; | ||||||
|  |     (void) context; | ||||||
|  | } | ||||||
							
								
								
									
										19
									
								
								launcher/widgets/fake_widget_1.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								launcher/widgets/fake_widget_1.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | |||||||
|  | #ifndef FAKE_WIDGET_1_H_ | ||||||
|  | #define FAKE_WIDGET_1_H_ | ||||||
|  | 
 | ||||||
|  | #include "launcher.h" | ||||||
|  | 
 | ||||||
|  | void fake_widget_1_setup(LauncherSettings *settings, void ** context_ptr); | ||||||
|  | void fake_widget_1_activate(LauncherSettings *settings, void *context); | ||||||
|  | void fake_widget_1_loop(LauncherEvent event, LauncherSettings *settings, void *context); | ||||||
|  | void fake_widget_1_resign(LauncherSettings *settings, void *context); | ||||||
|  | 
 | ||||||
|  | #define fake_widget_1 { \ | ||||||
|  |     "W1 d get01", \ | ||||||
|  |     fake_widget_1_setup, \ | ||||||
|  |     fake_widget_1_activate, \ | ||||||
|  |     fake_widget_1_loop, \ | ||||||
|  |     fake_widget_1_resign, \ | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif // FAKE_WIDGET_1_H_
 | ||||||
							
								
								
									
										32
									
								
								launcher/widgets/fake_widget_2.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								launcher/widgets/fake_widget_2.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | |||||||
|  | #include "fake_widget_2.h" | ||||||
|  | 
 | ||||||
|  | void fake_widget_2_setup(LauncherSettings *settings, void ** context_ptr) { | ||||||
|  |     (void) settings; | ||||||
|  |     *context_ptr = NULL; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void fake_widget_2_activate(LauncherSettings *settings, void *context) { | ||||||
|  |     (void) settings; | ||||||
|  |     (void) context; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void fake_widget_2_loop(LauncherEvent event, LauncherSettings *settings, void *context) { | ||||||
|  |     (void) settings; | ||||||
|  |     (void) context; | ||||||
|  | 
 | ||||||
|  |     switch (event) { | ||||||
|  |         case EVENT_MODE_BUTTON_UP: | ||||||
|  |             launcher_move_to_next_widget(); | ||||||
|  |             break; | ||||||
|  |         case EVENT_LIGHT_BUTTON_UP: | ||||||
|  |             launcher_illuminate_led(); | ||||||
|  |             break; | ||||||
|  |         default: | ||||||
|  |             break; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void fake_widget_2_resign(LauncherSettings *settings, void *context) { | ||||||
|  |     (void) settings; | ||||||
|  |     (void) context; | ||||||
|  | } | ||||||
							
								
								
									
										19
									
								
								launcher/widgets/fake_widget_2.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								launcher/widgets/fake_widget_2.h
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | |||||||
|  | #ifndef FAKE_WIDGET_2_H_ | ||||||
|  | #define FAKE_WIDGET_2_H_ | ||||||
|  | 
 | ||||||
|  | #include "launcher.h" | ||||||
|  | 
 | ||||||
|  | void fake_widget_2_setup(LauncherSettings *settings, void ** context_ptr); | ||||||
|  | void fake_widget_2_activate(LauncherSettings *settings, void *context); | ||||||
|  | void fake_widget_2_loop(LauncherEvent event, LauncherSettings *settings, void *context); | ||||||
|  | void fake_widget_2_resign(LauncherSettings *settings, void *context); | ||||||
|  | 
 | ||||||
|  | #define fake_widget_2 { \ | ||||||
|  |     "W1 d get02", \ | ||||||
|  |     fake_widget_2_setup, \ | ||||||
|  |     fake_widget_2_activate, \ | ||||||
|  |     fake_widget_2_loop, \ | ||||||
|  |     fake_widget_2_resign, \ | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #endif // FAKE_WIDGET_2_H_
 | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user