static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  s_text_layer = text_layer_create(GRect(0, 55, bounds.size.w, 100));
  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_LECO_38_BOLD_NUMBERS));
  text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter);
  text_layer_set_background_color(s_text_layer, GColorClear);

  if (persist_read_int(KEY_BACKGROUND_COLOR)) {
    int background_color = persist_read_int(KEY_BACKGROUND_COLOR);
    set_background_and_text_color(background_color);
  }

  if (persist_read_bool(KEY_TWENTY_FOUR_HOUR_FORMAT)) {
    twenty_four_hour_format = persist_read_bool(KEY_TWENTY_FOUR_HOUR_FORMAT);
  }

  layer_add_child(window_layer, text_layer_get_layer(s_text_layer));

  update_time();
}
static void game_start() {
	srand(time(NULL));
	
	game_wins = 0;
	if (game_is_first && persist_exists(0)) {
		game_wins = persist_read_int(0);
	}
	game_is_first = false;
	round_start();
	
	game_timer = app_timer_register(WAIT_RESTING, game_update, NULL);
	layer_mark_dirty(game_layer);
}
void init_settings() {
    int font_id = 0;
    if(persist_exists(KEY_STORAGE_OK) && persist_read_int(KEY_STORAGE_OK) == KEY_STORAGE_OK) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Reading from storage");
        storage_ok = true; //else storage empty or corrupt
        font_id = persist_read_int(KEY_FONT);
    } else {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "No stored settings");
    }
    settings = (Settings) {
        .bg = persist_read_colour(KEY_BG, DEF_BG),
        .fg = persist_read_colour(KEY_FG, DEF_FG),
        //Settings
        .disco_vibrate = persist_read_bool_def(KEY_DISCO_VIBRATE, true),
        .disco_desaturate = persist_read_bool_def(KEY_DESATURATE, true),
        .show_weather = persist_read_bool_def(KEY_WEATHER, true),
        .show_date = persist_read_bool_def(KEY_DATE, true),
        .fahrenheit = persist_read_bool_def(KEY_TEMP_UNITS_F, false),
        //Fonts
        .font_main_big = fonts_load_custom_font(resource_get_handle(custom_fonts[font_id])),
        .font_big_y_offset = font_offset(font_id),
        .font_date = fonts_get_system_font(persist_read_bool_def(KEY_SIZE_DATE, false) ?
                                           FONT_KEY_GOTHIC_14 : FONT_KEY_GOTHIC_24_BOLD),
        .font_temp = fonts_get_system_font(persist_read_bool_def(KEY_SIZE_WEATHER, false) ?
                                           FONT_KEY_GOTHIC_24_BOLD : FONT_KEY_GOTHIC_14),
        .num_colours = persist_read_int_def(KEY_N_COLOURS, DEF_N_COLOURS, 3, 5)
    };
    //Ribbon Colours
    settings.colours[0] = persist_read_colour(KEY_C1, DEF_C1);
    settings.colours[1] = persist_read_colour(KEY_C2, DEF_C2);
    settings.colours[2] = persist_read_colour(KEY_C3, DEF_C3);
    settings.colours[3] = persist_read_colour(KEY_C4, DEF_C4);
    settings.colours[4] = persist_read_colour(KEY_C5, DEF_C5);
}

void destroy_settings() {
    fonts_unload_custom_font(settings.font_main_big);
}
Beispiel #4
0
void stats_print_status()
{
  APP_LOG(APP_LOG_LEVEL_DEBUG, "HAPPINESS:%d", (int)persist_read_int(HAPPINESS_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "HUNGER:%d", (int)persist_read_int(HUNGER_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "ENERGY:%d", (int)persist_read_int(ENERGY_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "ACTIVE:%d", (int)persist_read_int(ACTIVE_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "HYGIENE:%d", (int)persist_read_int(HYGIENE_LEVEL_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "SICK:%s", persist_read_bool(SICK_STATUS_KEY) ? "true" : "false");
  APP_LOG(APP_LOG_LEVEL_DEBUG, "SLEEP:%s", persist_read_bool(SLEEP_STATUS_KEY) ? "true" : "false");
  APP_LOG(APP_LOG_LEVEL_DEBUG, "TOTAL STATS:%d", (int)persist_read_int(TOTAL_STATS_KEY));
  APP_LOG(APP_LOG_LEVEL_DEBUG, "TOTAL TICS:%d", (int)persist_read_int(TOTAL_TICS_KEY));
}
static int get_event_no_from_row_index(int index) {
    int i = 0;
    int past_events = 0;
    time_t now = time(0);
    while ((i - past_events) <= index && persist_exists(i*PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE)) {
        if (persist_exists(i*PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_END_DATE)) {
            int end_date = persist_read_int(i * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_END_DATE);
            if (end_date < now)
                past_events++;
        }
        i++;
    }
    return i - 1;
}
Beispiel #6
0
// pebble event handlers
static void on_window_load(Window *window) {
  init_stroke_datas(window);
  action_bar_init(window);

  b_stroke_selected = false;
  i_current_stroke = persist_read_int(CURRENT_STROKE);

  if(b_stroke_selected) {
    init_stroke_layers();
    change_stroke(i_current_stroke);
  } else {
    init_intro_layers();
  }
}
static uint16_t get_events_count_callback(struct MenuLayer *menu_layer, uint16_t section_index, void *callback_context) {
    int i = 0;
    int past_events = 0;
    time_t now = time(0);
    while (persist_exists(i*PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE)) {
        if (persist_exists(i*PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_END_DATE)) {
            int end_date = persist_read_int(i * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_END_DATE);
            if (end_date < now)
                past_events++;
        }
        i++;
    }
    return i - past_events;
}
Beispiel #8
0
bool DoNotDisturb(int Hour, int Minutes, int DNDStart_KEY, int DNDEnd_KEY){
	//Define the variables
	bool blnNextDay = 0;

	//Read the Hourly Vibe Quiet Hours setup
	int intDNDStart = persist_read_int(DNDStart_KEY);
	int intDNDEnd = persist_read_int(DNDEnd_KEY);
	
	//Determine if the DND End is the next day
	if(intDNDStart>intDNDEnd){blnNextDay = 1;}
	
	if (blnNextDay){
	//if the DND End is next day, DND period is when the Current Hour is greater than Start Hour
		if ((Hour>=intDNDStart)||(Hour<intDNDEnd)){return true; } //DND period
		else {return false;} //Not DND period
	}
	else{
	//if the DND End is the same day, DND period is when the Current Hour is between Start and End Hours
		if ((Hour>=intDNDStart)&&(Hour<intDNDEnd)){return true;} //DND period
		else {return false;} //Not DND period
	}
	
}
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect window_bounds = layer_get_bounds(window_layer);

  // status layer
  status_layer = text_layer_create(GRect(0, window_bounds.size.h / 2 - (42 / 2) - 28 - 5, window_bounds.size.w, 42));
  text_layer_set_font(status_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_background_color(status_layer, GColorClear);
  text_layer_set_text_alignment(status_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(status_layer));
  
  // output layer
  output_layer = text_layer_create(GRect(0, window_bounds.size.h / 2 - (42 / 2) - 5, window_bounds.size.w, 42));
  text_layer_set_font(output_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  text_layer_set_background_color(output_layer, GColorClear);
  text_layer_set_text_color(output_layer, GColorWhite);
  text_layer_set_text_alignment(output_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(output_layer));
  
  // bpm layer
  bpm_layer = text_layer_create(GRect(0, window_bounds.size.h / 2 + (42 / 2) - 5, window_bounds.size.w, 42));
  text_layer_set_font(bpm_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_background_color(bpm_layer, GColorClear);
  text_layer_set_text_color(bpm_layer, GColorWhite);
  text_layer_set_text_alignment(bpm_layer, GTextAlignmentCenter);
  text_layer_set_text(bpm_layer, "BPM");
  layer_add_child(window_layer, text_layer_get_layer(bpm_layer));

  // read stuff
  vibe_duration = (persist_exists(KEY_VIBE_DURATION) ? persist_read_int(KEY_VIBE_DURATION) : INITIAL_VIBE_DURATION);
  set_vibe(vibe_duration);
  set_tempo(persist_exists(KEY_TEMPO) ? persist_read_int(KEY_TEMPO) : INITIAL_TEMPO);
  
  color = get_color();
  set_state(true);
  metronome_loop();
}
Beispiel #10
0
void storage_load(){
	APP_LOG(APP_LOG_LEVEL_INFO,"storage_load()");
	
	if(!persist_exists(STORAGE_KEY_VERSION)){ 
		APP_LOG(APP_LOG_LEVEL_WARNING,"no version"); 
		return;
	}
	if(persist_read_int(STORAGE_KEY_VERSION)!=STORAGE_VERSION){
		APP_LOG(APP_LOG_LEVEL_WARNING,"wrong version");
		return;
	}
	if(!persist_exists(STORAGE_KEY_COUNT)){ 
		APP_LOG(APP_LOG_LEVEL_ERROR,"no count"); 
		return;
	}
	uint8_t storage_count=(uint8_t)persist_read_int(STORAGE_KEY_COUNT);
 	APP_LOG(APP_LOG_LEVEL_INFO,"storage count: %d",storage_count);
	Timer* timer;
	int result;
	for(uint8_t i=0;i<storage_count;i++){
		if(!persist_exists(STORAGE_KEY_DATA+i)){ 
			APP_LOG(APP_LOG_LEVEL_ERROR,"missing timer %d in storage %d",i,STORAGE_KEY_DATA+i); 
			continue;
		}
		timer=timer_create();
		result=persist_read_data(STORAGE_KEY_DATA+i,timer,sizeof(Timer));
		if(result<0){
			APP_LOG(APP_LOG_LEVEL_ERROR,"read error timer %d in storage %d",i,STORAGE_KEY_DATA+i);
			timer_destroy(timer);
			continue;
		}
		timers_add(timer);
		APP_LOG(APP_LOG_LEVEL_INFO,"loaded timer %d",i);
	}
		
	APP_LOG(APP_LOG_LEVEL_INFO,"loaded");
}
Beispiel #11
0
void ClearPersistedData(void)
{
	ProfileLogStart("ClearPersistedData");
	if(persist_exists(PERSISTED_IS_DATA_SAVED))
	{
		DEBUG_LOG("Clearing persisted data.");
		int maxKey = persist_read_int(PERSISTED_MAX_KEY_USED);
		int i;
		for(i = 0; i <= maxKey; ++i)
		{
			persist_delete(i);
		}
	}
	ProfileLogStop("ClearPersistedData");
}
Beispiel #12
0
// Makes sure storage is populated (by checking and, on absence, writing
// defaults) and then reading values.
void storage_init(void) {
    LOG_FUNC();

    // THIS MUST NEVER BE ENABLED */for (unsigned int i = 0; i <= MAXIMUM_EVER_USED; i++) {
    // THIS MUST NEVER BE ENABLED */    if ((i % 10000) == 0) {
    // THIS MUST NEVER BE ENABLED */        LOG_EXT(LOG_STORAGE, "storage_init(): working key %d", i);
    // THIS MUST NEVER BE ENABLED */    }
    // THIS MUST NEVER BE ENABLED */    if (persist_exists(i)) {
    // THIS MUST NEVER BE ENABLED */        LOG_EXT(LOG_STORAGE, "storage_init(): deleting key %d", i);
    // THIS MUST NEVER BE ENABLED */        persist_delete(i);
    // THIS MUST NEVER BE ENABLED */    }
    // THIS MUST NEVER BE ENABLED */}

    if (!persist_exists(SELECTED_VERSION)) {
        persist_write_string(SELECTED_VERSION, "Regular");
        LOG_EXT(LOG_STORAGE, "storage_init(): init %d with data %s", SELECTED_VERSION, "Regular");
    }
    persist_read_string(SELECTED_VERSION, storage.selectedVersion, 64);
    if (!persist_exists(BATTERY_ESTIMATE)) {
        persist_write_data(BATTERY_ESTIMATE, (void*)&battery_estimate_data_init, sizeof(battery_estimate_data));
        LOG_EXT(LOG_STORAGE, "storage_init(): init %d", BATTERY_ESTIMATE);
    }
    persist_read_data(BATTERY_ESTIMATE, (void*)&(storage.battery_estimate), sizeof(battery_estimate_data));
    if (!persist_exists(LAST_FULL_TIMESTAMP)) {
        persist_write_int(LAST_FULL_TIMESTAMP, (time_t)-1);
        LOG_EXT(LOG_STORAGE, "storage_init(): init %d with data %ld", LAST_FULL_TIMESTAMP, (time_t)-1);
    }
    storage.last_full_timestamp = persist_read_int(LAST_FULL_TIMESTAMP);
    if (!persist_exists(BATTERY_DISPLAY)) {
        persist_write_int(BATTERY_DISPLAY, 7);
        LOG_EXT(LOG_STORAGE, "storage_init(): init %d with data %d", BATTERY_DISPLAY, 1);
    }
    storage.battery_display = persist_read_int(BATTERY_DISPLAY);

    app_log_storage_log(LOG_STORAGE_SU);
}
Beispiel #13
0
void readConfig() {
	if (persist_exists(CONFIG_KEY_DATEORDER)) {
		USDate = persist_read_int(CONFIG_KEY_DATEORDER);
	} else {
		APP_LOG(APP_LOG_LEVEL_DEBUG, "persist_exists(CONFIG_KEY_DATEORDER) returned false");
		USDate = 1;
	}

	if (persist_exists(CONFIG_KEY_LANG)) {
		curLang = persist_read_int(CONFIG_KEY_LANG);
	} else {
		APP_LOG(APP_LOG_LEVEL_DEBUG, "persist_exists(CONFIG_KEY_LANG) returned false");
		curLang = LANG_ENGLISH;
	}
	
	if (persist_exists(CONFIG_KEY_BACKLIGHT)) {
		backlight = persist_read_int(CONFIG_KEY_BACKLIGHT);
	} else {
		APP_LOG(APP_LOG_LEVEL_DEBUG, "persist_exists(CONFIG_KEY_BACKLIGHT) returned false");
		backlight = 0;
	}
	
	logVariables("readConfig");
}
Beispiel #14
0
static void init() {
    if (!persist_exists(BACKGROUND_COLOR_KEY)) {
        persist_write_int(BACKGROUND_COLOR_KEY, pcb_background.argb);
        persist_write_int(SILKSCREEN_COLOR_KEY, pcb_silkscreen.argb);
    }
    else {
        pcb_background.argb = persist_read_int(BACKGROUND_COLOR_KEY);
        pcb_silkscreen.argb = persist_read_int(SILKSCREEN_COLOR_KEY);
    }

    time_t t = time(NULL);
    struct tm *time_now = localtime(&t);
    tick_handler(time_now, MINUTE_UNIT);

    s_ocra_font = fonts_load_custom_font(
        resource_get_handle(RESOURCE_ID_FONT_OCR_A_20));
    
    s_resistor_img = gbitmap_create_with_resource(RESOURCE_ID_RESISTOR_IMG);
    
    s_main_window = window_create();
    window_set_window_handlers(s_main_window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
    });
Beispiel #15
0
static void set_score() {
	int highScore = persist_read_int(HIGH_SCORE_KEY);

	if (state.score > highScore) {
		// Save persistent data
		persist_write_int(HIGH_SCORE_KEY, state.score);	
		highScore = state.score;
	}
	
	// Display high score
	static char buf[32];
	snprintf(buf, 32, "High Score: %u", highScore);
	text_layer_set_text(high_score_label, buf);
	
	layer_set_hidden((Layer*) high_score_label, false);
}
Beispiel #16
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time();
  // Get weather update every n minutes
  int fetch = persist_read_int(MESSAGE_KEY_Weather_Fetch);
  if(tick_time->tm_min % fetch == 0) {
    // Begin dictionary
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
  
    // Add a key-value pair
    dict_write_uint8(iter, 0, 0);
  
    // Send the message!
    app_message_outbox_send();
  }
}
Beispiel #17
0
static void set_time_display() {
	// Check if our time display property exists
	if (persist_exists(KEY_TIME_DISPLAY)) {
		// If so, read it in to a variable
		TIME_DISPLAY = persist_read_int(KEY_TIME_DISPLAY);
	}
	
	// If time display == 0, hide the display, otherwise show
	bool hide = TIME_DISPLAY == 0 ? true : false;
	
	// Hide or show the layer
	layer_set_hidden(text_layer_get_layer(label_layer_time), hide);
	
	// Output log message for testing
	APP_LOG(APP_LOG_LEVEL_INFO, "SELECTED TIME DISPLAY: %d", TIME_DISPLAY);
}
Beispiel #18
0
//
//  Ageing logic
//
int cache_stale(){
  // get mins since epoch 
  time_t epoch = time(NULL);
  uint16_t now_mins = epoch / 60;
  
  // retrieve time cache was initialised 
  uint16_t cache_init = persist_read_int (TIME_INIT_KEY);
  
  uint16_t cache_age = now_mins-cache_init; 
  
  if (cache_age > CACHE_MAX_MINS) {
//     APP_LOG(APP_LOG_LEVEL_INFO, "         cache_stale() = 1   now= %u, cache_init = %u", (unsigned int)now_mins, (unsigned int) cache_init);
    return 1;
  }
//   APP_LOG(APP_LOG_LEVEL_INFO, "         cache_stale() = 0   now= %u, cache_init = %u", (unsigned int)now_mins, (unsigned int) cache_init);
  return 0;
}
Beispiel #19
0
void Settings_init() {
  // first, check if we have any saved settings
  int settingsVersion = persist_read_int(SETTINGS_VERSION_KEY);

  // load all settings
  Settings_loadFromStorage();

  // for BW watches, reset colors to defaults
  #ifndef PBL_COLOR
    if(settingsVersion < CURRENT_SETTINGS_VERSION) {
      globalSettings.timeColor      = GColorWhite;
      globalSettings.sidebarColor   = GColorWhite;
      globalSettings.timeBgColor      = GColorBlack;
      globalSettings.sidebarTextColor = GColorBlack;
    }
  #endif
}
Beispiel #20
0
void stats_decrease_stat_value(uint32_t key)
{
  int cur_val = persist_read_int(key);
  cur_val--;
  if(persist_read_bool(SICK_STATUS_KEY))
  {
    cur_val--;
  }
  if(cur_val <= STAT_FIELD_MIN)
  {
    persist_write_int(key, STAT_FIELD_MIN);
  }
  else
  {
    persist_write_int(key, cur_val);
  }
}
Beispiel #21
0
void stats_increase_stat_value(uint32_t key)
{
  int cur_val = persist_read_int(key);
  cur_val++;
  if(cur_val > STAT_FIELD_MAX)
  {
    if(key != ENERGY_LEVEL_KEY && key != HAPPINESS_LEVEL_KEY)
    {
      stats_decrease_stat_value(HAPPINESS_LEVEL_KEY);
    }
    persist_write_int(key, STAT_FIELD_MAX);
  }
  else
  {
    persist_write_int(key, cur_val);
  }
}
Beispiel #22
0
void timers_restore(void) {

  if (! persist_exists(PERSIST_TIMERS_VERSION)) {
    timers_migrate_1();
    return;
  }

  if (TIMERS_VERSION_TINY == persist_read_int(PERSIST_TIMERS_VERSION)) {
    timers_migrate_2();
    return;
  }

  timers_clear();

  time_t now = time(NULL);
  uint16_t seconds_elapsed = 0;

  TimerBlock* block = NULL;
  if (persist_exists(PERSIST_TIMER_START)) {
    block = malloc(sizeof(TimerBlock));
    persist_read_data(PERSIST_TIMER_START, block, sizeof(TimerBlock));
    uint8_t num_timers = block->total_timers;
    uint8_t block_offset = 0;
    seconds_elapsed = now - block->save_time;

    for (uint8_t t = 0; t < num_timers; t += 1) {
      if (! block) {
        block = malloc(sizeof(TimerBlock));
        persist_read_data(PERSIST_TIMER_START + block_offset, block, sizeof(TimerBlock));
      }
      Timer* timer = timer_clone(&block->timers[t % TIMER_BLOCK_SIZE]);
      timers_add(timer);
      timer_restore(timer, seconds_elapsed);
      if (t % TIMER_BLOCK_SIZE == (TIMER_BLOCK_SIZE - 1)) {
        free(block);
        block = NULL;
        block_offset += 1;
      }
    }
    if (block) {
      free(block);
      block = NULL;
    }
  }
}
Beispiel #23
0
void window_load(Window *window)
{
  Layer *window_layer = window_get_root_layer(window);

  text_layer_1 = text_layer_create(GRect(0, 0, 104, 30));
  text_layer_set_text_color(text_layer_1, GColorBlack);
  text_layer_set_background_color(text_layer_1, GColorWhite);
  text_layer_set_font(text_layer_1, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_1));

  s_action_bar = action_bar_layer_create();
  action_bar_layer_add_to_window(s_action_bar, window);
  action_bar_layer_set_click_config_provider(s_action_bar, click_config_provider);
  action_bar_layer_set_icon(s_action_bar, BUTTON_ID_DOWN, s_icon_reset);
  action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_play);
  action_bar_layer_set_icon(s_action_bar, BUTTON_ID_UP, s_icon_calib);
  
  text_layer_2 = text_layer_create(GRect(0, 30, 104, 40));
  text_layer_set_font(text_layer_2, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_2));
  
  text_layer_3 = text_layer_create(GRect(0, 70, 104, 20));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_3));
  text_layer_set_overflow_mode(text_layer_3, GTextOverflowModeWordWrap);
  
  text_layer_4 = text_layer_create(GRect(0, 90, 104, 20));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_4));
  int calib_stored = persist_exists(CALIB_PKEY) ? persist_read_int(CALIB_PKEY) : CALIB_DEFAULT;
  if (calib_stored != 0) {
    text_layer_set_text(text_layer_1, "HELLO,");
    text_layer_set_text(text_layer_2, "DRINK SAFE");
    text_layer_set_text(text_layer_4, "Flick to start");
    display(text_layer_3,"Calib: %d", calib_stored);
  }
  else {
    text_layer_set_text(text_layer_1, "PLEASE");
    text_layer_set_text(text_layer_2, "CALIBRATE");
    text_layer_set_text(text_layer_3, "Press UP button");
    text_layer_set_text(text_layer_4, "to calibrate.");
  }
  accel_data_service_subscribe(1, accel_handler);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);

  accel_tap_service_subscribe(accel_tap_handler);
}
Beispiel #24
0
void load_face_fonts() {
    int selected_font = persist_exists(KEY_FONTTYPE) ? persist_read_int(KEY_FONTTYPE) : BLOCKO_FONT;

    if (selected_font == SYSTEM_FONT) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Loading system fonts. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
        time_font = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49);
        medium_font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);
        base_font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
        loaded_font = SYSTEM_FONT;
    } else if (selected_font == ARCHIVO_FONT) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Loading Archivo font. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
        time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARCHIVO_56));
        medium_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARCHIVO_28));
        base_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARCHIVO_18));
        loaded_font = ARCHIVO_FONT;
    } else if (selected_font == DIN_FONT) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Loading DIN font. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
        time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIN_58));
        medium_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIN_26));
        base_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIN_20));
        loaded_font = DIN_FONT;
    } else if (selected_font == PROTOTYPE_FONT) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Loading Prototype font. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
        time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PROTOTYPE_48));
        medium_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PROTOTYPE_22));
        base_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PROTOTYPE_16));
        loaded_font = PROTOTYPE_FONT;
    } else if (selected_font == BLOCKO_BIG_FONT) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Loading Blocko font (big). %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
        time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCKO_64));
        medium_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCKO_32));
        base_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCKO_19));
        loaded_font = BLOCKO_BIG_FONT;
    } else {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Loading Blocko font. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
        time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCKO_56));
        medium_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCKO_24));
        base_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCKO_16));
        loaded_font = BLOCKO_FONT;
    }

    weather_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_WEATHER_24));
    custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ICONS_20));
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Fonts loaded. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
}
Beispiel #25
0
static void select_click_handler(ClickRecognizerRef recognizer, void *context) 
{
  if (mode_clock)  // was clock - now get and display text
  {
    mode_clock = 0;  // toggle to text
    options[TEXT_SELECTED] = persist_read_int(TEXT_SELECTED);
    text_select = options[TEXT_SELECTED]; // get stored mode
    swap_to_oclock();
  }
  else  // was displaying text - save choice then display clock
  {
    mode_clock = 1;  // toggle back to clock 
    
    options[TEXT_SELECTED] = text_select; // set stored mode
    persist_write_int(TEXT_SELECTED, options[TEXT_SELECTED]);
    time_t now = time(NULL);
    struct tm *current_time = localtime(&now);
    handle_minute_tick(current_time, SECOND_UNIT);
  }
}
Beispiel #26
0
void show_adjust_time(const char *destination, const char *dayofweek, const char * station, uint32_t key)
{
  strncpy(s_Destination, destination,sizeof(s_Destination));
  strncpy(s_Station, station,sizeof(s_Station));
  strncpy(s_DayOfWeek, dayofweek,sizeof(s_DayOfWeek));
  s_key = key;
  char work[6];
  snprintf(work,sizeof(work), "%3.3d",(int)persist_read_int(s_key));
  s_time[0] = work[0];
  s_time[1] = ':';
  s_time[2] = work[1];
  s_time[3] = work[2];
  s_time[4] = '\0';
  
  s_grDigits[0] = GRect(4, 0, 24, 39);
  s_grDigits[2] = GRect(46, 0, 24, 39);
  s_grDigits[3] = GRect(74, 0, 24, 39);
  
  initialise_ui();
  window_set_window_handlers(s_window, (WindowHandlers) {
    .unload = handle_window_unload,
  });
Beispiel #27
0
void migrate_legacy_data() {
  // load legacy checklist information from storage
  s_checklist_length = persist_read_int(PERSIST_KEY_CHECKLIST_LENGTH);
  s_checklist_num_checked = 0;

  // load the legacy checklist data from storage
  for(int i = 0; i < MAX_CHECKLIST_ITEMS; i++) {
    persist_read_data(PERSIST_KEY_CHECKLIST_ITEM_FIRST + i, &s_checklist_items[i], sizeof(ChecklistItem));

    if(s_checklist_items[i].is_checked) {
      s_checklist_num_checked++;
    }
  }

  // now write the data in the new format
  save_data_to_storage();

  // delete the old data
  for(int i = 0; i < MAX_CHECKLIST_ITEMS; i++) {
    persist_delete(PERSIST_KEY_CHECKLIST_ITEM_FIRST + i);
  }
}
struct texto_paradas texto_favoritos_separado(int key)
  {
    struct texto_paradas item;

    int unsigned valor = persist_exists(key) ? persist_read_int(key) : NUM_DEFAULT;
    int unsigned v1 = valor/10000;
    int unsigned v2 = (valor % 10000) /1000;
    int unsigned v3 = (valor % 1000) /100;
    int unsigned v4 = (valor % 100);
    int t_parada = (v1*100)+(v2*10)+v3;
    //char t_linea = devuelve_linea(t_parada, v4);
    snprintf(buffer1, sizeof(buffer1), "%d", v1);
    snprintf(buffer2, sizeof(buffer2), "%d", v2);
    snprintf(buffer3, sizeof(buffer3), "%d", v3);
   
  /*
  if (t_linea=='1')
      snprintf(buffer4, sizeof(buffer4), "%s", "R");
    else if (t_linea=='2')
      snprintf(buffer4, sizeof(buffer4), "%s", "R2");
    else if (t_linea=='3')
      snprintf(buffer4, sizeof(buffer4), "%s", "R");
    else
      */
      snprintf(buffer4, sizeof(buffer4), "%s", devuelve_linea(t_parada, v4));


  
  
    strcpy(item.texto, "Parada: ");
    strcat(item.texto,buffer1);
    strcat(item.texto, buffer2);
    strcat(item.texto, buffer3);
    strcat(item.texto, " ");
    strcat(item.texto, buffer4);
    item.parada = t_parada;

    return item;
}
Beispiel #29
0
void init(){
	mins = 0;
	if(persist_exists(KEY_MINUTES)){
		mins = persist_read_int(KEY_MINUTES);
	}
	
	center = false;
	if(persist_exists(CENTER)){
		center = persist_read_bool(CENTER);
	}
	
	show_date = true;
	if(persist_exists(SHOW_DATE)){
		show_date = persist_read_bool(SHOW_DATE);
	}
	
	window = window_create();
	
	window_set_window_handlers(window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });
Beispiel #30
0
void Weather_SaveData()
{
   
   #ifdef DEBUG_WEATHER
      printf("[WEATHER][Weather_SaveData] Saving weather data (time: %d)",m_i_Weather_LastRefresh);
   #endif
   
   int i_LastSaveTime = 0;
   if (persist_exists(MESSAGE_KEY_WEATHER_DATA_TIME))
      i_LastSaveTime = persist_read_int(MESSAGE_KEY_WEATHER_DATA_TIME);
   
   if (i_LastSaveTime != m_i_Weather_LastRefresh)
   {
      WriteInt(MESSAGE_KEY_WEATHER_DATA_TIME, m_i_Weather_LastRefresh);
      WriteInt(MESSAGE_KEY_WEATHER_DATA_TEMP, m_i_Weather_Temperature);
      WriteInt(MESSAGE_KEY_WEATHER_DATA_IMAGE, m_i_Weather_WeatherImage);
      WriteInt(MESSAGE_KEY_WEATHER_DATA_TEMPMIN, m_i_Weather_Temperature_Min);
      WriteInt(MESSAGE_KEY_WEATHER_DATA_TEMPMAX, m_i_Weather_Temperature_Max);
      WriteString(MESSAGE_KEY_WEATHER_DATA_COND, m_s_Weather_ConditionBuffer);
      WriteString(MESSAGE_KEY_WEATHER_DATA_LOCATION, m_s_Weather_LocationBuffer);
   }
}