mirror of
https://github.com/He4eT/dice.git
synced 2026-05-04 17:37:25 +00:00
c: cleanup
This commit is contained in:
parent
0de95471e0
commit
312288facd
1 changed files with 35 additions and 38 deletions
|
|
@ -1,45 +1,15 @@
|
||||||
#include <pebble.h>
|
#include <pebble.h>
|
||||||
|
|
||||||
|
#define SETTINGS_KEY 1
|
||||||
|
typedef struct ClaySettings {
|
||||||
|
int upper_bound;
|
||||||
|
} ClaySettings;
|
||||||
|
static ClaySettings settings;
|
||||||
|
|
||||||
/* State */
|
/* State */
|
||||||
|
|
||||||
static int current_number = 1;
|
static int current_number = 1;
|
||||||
|
|
||||||
/* Settings */
|
|
||||||
|
|
||||||
static void prv_update_ui();
|
|
||||||
|
|
||||||
#define SETTINGS_KEY 1
|
|
||||||
|
|
||||||
typedef struct ClaySettings {
|
|
||||||
int UPPER_BOUND;
|
|
||||||
} ClaySettings;
|
|
||||||
static ClaySettings settings;
|
|
||||||
|
|
||||||
static void prv_default_settings() {
|
|
||||||
settings.UPPER_BOUND = 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void prv_load_settings() {
|
|
||||||
prv_default_settings();
|
|
||||||
persist_read_data(SETTINGS_KEY, &settings, sizeof(settings));
|
|
||||||
current_number = settings.UPPER_BOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void prv_save_settings() {
|
|
||||||
persist_write_data(SETTINGS_KEY, &settings, sizeof(settings));
|
|
||||||
current_number = settings.UPPER_BOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void prv_inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|
||||||
Tuple *upper_bound_t = dict_find(iter, MESSAGE_KEY_UPPER_BOUND);
|
|
||||||
if (upper_bound_t) {
|
|
||||||
settings.UPPER_BOUND = upper_bound_t->value->int32;
|
|
||||||
}
|
|
||||||
|
|
||||||
prv_save_settings();
|
|
||||||
prv_update_ui();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* UI */
|
/* UI */
|
||||||
|
|
||||||
static Window *s_window;
|
static Window *s_window;
|
||||||
|
|
@ -47,7 +17,7 @@ static TextLayer *s_text_layer;
|
||||||
|
|
||||||
static void prv_update_ui() {
|
static void prv_update_ui() {
|
||||||
static char string_buffer[7];
|
static char string_buffer[7];
|
||||||
snprintf(string_buffer, sizeof(string_buffer), "%u", current_number);
|
snprintf(string_buffer, sizeof(string_buffer), "%d", current_number);
|
||||||
text_layer_set_text(s_text_layer, string_buffer);
|
text_layer_set_text(s_text_layer, string_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +47,7 @@ static void prv_window_unload(Window *window) {
|
||||||
/* Input */
|
/* Input */
|
||||||
|
|
||||||
static void prv_click_handler(ClickRecognizerRef recognizer, void *context) {
|
static void prv_click_handler(ClickRecognizerRef recognizer, void *context) {
|
||||||
current_number = 1 + rand() % settings.UPPER_BOUND;
|
current_number = 1 + rand() % settings.upper_bound;
|
||||||
prv_update_ui();
|
prv_update_ui();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,6 +57,36 @@ static void prv_click_config_provider(void *context) {
|
||||||
window_single_click_subscribe(BUTTON_ID_SELECT, prv_click_handler);
|
window_single_click_subscribe(BUTTON_ID_SELECT, prv_click_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Settings */
|
||||||
|
|
||||||
|
static void prv_default_settings() {
|
||||||
|
settings.upper_bound = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prv_load_settings() {
|
||||||
|
if (persist_exists(SETTINGS_KEY)) {
|
||||||
|
persist_read_data(SETTINGS_KEY, &settings, sizeof(settings));
|
||||||
|
} else {
|
||||||
|
prv_default_settings();
|
||||||
|
}
|
||||||
|
current_number = settings.upper_bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prv_save_settings() {
|
||||||
|
persist_write_data(SETTINGS_KEY, &settings, sizeof(settings));
|
||||||
|
current_number = settings.upper_bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prv_inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||||
|
Tuple *upper_bound_t = dict_find(iter, MESSAGE_KEY_UPPER_BOUND);
|
||||||
|
if (upper_bound_t) {
|
||||||
|
settings.upper_bound = upper_bound_t->value->int32;
|
||||||
|
}
|
||||||
|
|
||||||
|
prv_save_settings();
|
||||||
|
prv_update_ui();
|
||||||
|
}
|
||||||
|
|
||||||
/* Lifecycle */
|
/* Lifecycle */
|
||||||
|
|
||||||
static void prv_init(void) {
|
static void prv_init(void) {
|
||||||
|
|
@ -113,9 +113,6 @@ static void prv_deinit(void) {
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
prv_init();
|
prv_init();
|
||||||
|
|
||||||
APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", s_window);
|
|
||||||
|
|
||||||
app_event_loop();
|
app_event_loop();
|
||||||
prv_deinit();
|
prv_deinit();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue