Ejemplo n.º 1
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  static char s_uptime_buffer[32];
  vibes_short_pulse();
  alert_time--;
  if(alert_time <= 0 ){
    //TODO: write notification code
    tick_timer_service_unsubscribe();
    vibes_cancel();
    text_layer_set_text(s_alert_text_layer, "Timout Reached\n:(");
    
    // Prepare dictionary
    DictionaryIterator *iterator;
    app_message_outbox_begin(&iterator);
    
    // Write data
    char buff[100];
    if(persist_exists(PERSIST_KEY_PHONE_NUMBER)){
      persist_read_string(PERSIST_KEY_PHONE_NUMBER, buff, 100);
      dict_write_cstring(iterator, PERSIST_KEY_PHONE_NUMBER, buff);
    }
    if(persist_exists(PERSIST_KEY_NAME)){
      persist_read_string(PERSIST_KEY_NAME, buff, 100);
      dict_write_cstring(iterator, PERSIST_KEY_NAME, buff);
    }
    // Send the data!
    app_message_outbox_send();
    
  } else {
    snprintf(s_uptime_buffer, sizeof(s_uptime_buffer), BANNER_TEXT "\n" CLOCK_FORMAT_STRING, 
             alert_time/60, alert_time%60);
    text_layer_set_text(s_alert_text_layer, s_uptime_buffer);
  }
}
Ejemplo n.º 2
0
void set_server_pass_from_persistent_storage() {
	if (persist_exists(KEY_SERVER_PASS)) {
		persist_read_string(KEY_SERVER_PASS, server_pass, sizeof(server_pass));
	} else {
		strncpy(title, "Set options via Pebble app", sizeof(title));
	}
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: musl/DataFace
/*
 * A place for everything and everything it its place. This is
 * mainly here because main() would be messy otherwise.
 */
static void init() {

	int theme;

	/* 
	 * Read the stored configuration keys or write defaults if they
	 * don't exist so that the config is properly loaded.
	 */

	if(persist_exists(KEY_CONFIG_TEMP_UNIT)) {
		persist_read_string(KEY_CONFIG_TEMP_UNIT, s_temp_unit, sizeof(s_temp_unit));
	} else {
		strncpy(s_temp_unit, DEFAULT_TEMP_UNIT, sizeof(s_temp_unit));    
		persist_write_string(KEY_CONFIG_TEMP_UNIT, s_temp_unit);
	}

	if(persist_exists(KEY_CONFIG_THEME)) {
		theme = persist_read_int(KEY_CONFIG_THEME);
		s_theme = (theme >= 0 && theme < THEME_COUNT) ? theme : DEFAULT_THEME;
	} else {
		s_theme = DEFAULT_THEME;
		persist_write_int(KEY_CONFIG_THEME, s_theme);
	}

	// Build the main window and register callbacks so that the UI gets
	// drawn.
	//
	s_main_window = window_create();
	window_set_window_handlers(s_main_window, (WindowHandlers) {
			.load = load_cb,
			.unload = unload_cb
			});
Ejemplo n.º 4
0
static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) {
  switch (cell_index->section) {
    case 0:
      switch (cell_index->row) {
        case 0:
          menu_cell_basic_draw(ctx, cell_layer, "Calendarios", "Mostrar turnos", NULL);
          break;
        case 1:
          menu_cell_basic_draw(ctx, cell_layer, "FPP", "Calculadora", NULL);
          break;                
      }
      break;
    case 1:
      switch (cell_index->row) {
        case 0:
          if (loading==0) 
            {
              char version[20];
              persist_read_string(80, version, sizeof(version));
              menu_cell_basic_draw(ctx, cell_layer, "Actualizar datos", version, NULL);
            } 
          else
            menu_cell_basic_draw(ctx, cell_layer, "Actualizando...", "Por favor, espera.", NULL);
          break;
      }
  }
}
Ejemplo n.º 5
0
// omain init - registers callback functions, reads persistent data, and requests most recent data from
// companion app. Sets default timer length to 10 seconds.
void main_init(void) {
  s_reset_app(NULL);
    
  // initialize app message
  app_message_register_inbox_received(inbox_received_callback);
  app_message_register_inbox_dropped(inbox_dropped_callback);
  app_message_register_outbox_failed(outbox_failed_callback);
  app_message_register_outbox_sent(outbox_sent_callback);
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
   
  // send request for most recent data
  DictionaryIterator *iter;
  app_message_outbox_begin(&iter);
  dict_write_uint8(iter, 0, 42);
  app_message_outbox_send();
  
  // gather persistent data for timer length and passcode
  if (persist_exists(TIMERLEN_PERSIST_KEY)) {
    s_timer_len = persist_read_int(TIMERLEN_PERSIST_KEY);
  } else {
    s_timer_len = 10*1000;
  }
  if (persist_exists(PASSCODE_PERSIST_KEY)) {
    s_passcode_defined = true;
    persist_read_string(PASSCODE_PERSIST_KEY, s_passcode, PASSCODE_LEN + 1);
  } else {
    s_passcode_defined = false;
  }
}
Ejemplo n.º 6
0
void set_server_host_from_persistent_storage() {
	if (persist_exists(KEY_SERVER_HOST)) {
		persist_read_string(KEY_SERVER_HOST, server_host, sizeof(server_host));
	} else {
		strncpy(title, "Set options via Pebble app", sizeof(title));
	}
}
Ejemplo n.º 7
0
/*
 * Load the saved color settings, or if they don't exist load defaults
 */
void Settings_loadFromStorage() {
  if(persist_exists(SETTING_TIME_COLOR_KEY) && persist_exists(SETTING_TIME_BG_COLOR_KEY) &&
     persist_exists(SETTING_SIDEBAR_COLOR_KEY) && persist_exists(SETTING_SIDEBAR_TEXT_COLOR_KEY)) {

    // if the color data exists, load the colors
    persist_read_data(SETTING_TIME_COLOR_KEY,         &globalSettings.timeColor,        sizeof(GColor));
    persist_read_data(SETTING_TIME_BG_COLOR_KEY,      &globalSettings.timeBgColor,      sizeof(GColor));
    persist_read_data(SETTING_SIDEBAR_COLOR_KEY,      &globalSettings.sidebarColor,     sizeof(GColor));
    persist_read_data(SETTING_SIDEBAR_TEXT_COLOR_KEY, &globalSettings.sidebarTextColor, sizeof(GColor));
  } else {
    // otherwise, load the default colors
    globalSettings.timeBgColor      = GColorBlack;
    globalSettings.sidebarTextColor = GColorBlack;

    #ifdef PBL_COLOR
      globalSettings.timeColor      = GColorOrange;
      globalSettings.sidebarColor   = GColorOrange;
    #else
      globalSettings.timeColor      = GColorWhite;
      globalSettings.sidebarColor   = GColorWhite;
    #endif
  }

  // load widgets
  if(persist_exists(SETTING_SIDEBAR_WIDGET0_KEY)) {
    globalSettings.widgets[0] = persist_read_int(SETTING_SIDEBAR_WIDGET0_KEY);
    globalSettings.widgets[1] = persist_read_int(SETTING_SIDEBAR_WIDGET1_KEY);
    globalSettings.widgets[2] = persist_read_int(SETTING_SIDEBAR_WIDGET2_KEY);
  } else {
    // in the case of a new installation, set the default widgets
    globalSettings.widgets[0] = WEATHER_CURRENT;
    globalSettings.widgets[1] = EMPTY;
    globalSettings.widgets[2] = DATE;
  }

  if(persist_exists(SETTING_ALTCLOCK_NAME_KEY)) {
    persist_read_string(SETTING_ALTCLOCK_NAME_KEY, globalSettings.altclockName, sizeof(globalSettings.altclockName));
  } else {
    strncpy(globalSettings.altclockName, "ALT", sizeof(globalSettings.altclockName));
  }

  // load the rest of the settings, using default settings if none exist
  // all settings except colors automatically return "0" or "false" if
  // they haven't been set yet, so we don't need to check if they exist
  globalSettings.useMetric              = persist_read_bool(SETTING_USE_METRIC_KEY);
  globalSettings.sidebarOnLeft          = persist_read_bool(SETTING_SIDEBAR_LEFT_KEY);
  globalSettings.btVibe                 = persist_read_bool(SETTING_BT_VIBE_KEY);
  globalSettings.languageId             = persist_read_int(SETTING_LANGUAGE_ID_KEY);
  globalSettings.showLeadingZero        = persist_read_int(SETTING_LEADING_ZERO_KEY);
  globalSettings.showBatteryPct         = persist_read_bool(SETTING_SHOW_BATTERY_PCT_KEY);
  globalSettings.disableWeather         = persist_read_bool(SETTING_DISABLE_WEATHER_KEY);
  globalSettings.clockFontId            = persist_read_bool(SETTING_CLOCK_FONT_ID_KEY);
  globalSettings.hourlyVibe             = persist_read_int(SETTING_HOURLY_VIBE_KEY);
  globalSettings.onlyShowBatteryWhenLow = persist_read_bool(SETTING_BATTERY_ONLY_WHEN_LOW_KEY);
  globalSettings.useLargeFonts          = persist_read_bool(SETTING_USE_LARGE_FONTS_KEY);
  globalSettings.altclockOffset         = persist_read_int(SETTING_ALTCLOCK_OFFSET_KEY);

  Settings_updateDynamicSettings();
}
Ejemplo n.º 8
0
void get_contact_number(char *number){
  if (persist_exists(NUMBER)){
    persist_read_string(NUMBER, number, sizeof(number));
  }
  else {
    number = "[Please set up app]";
  }
}
Ejemplo n.º 9
0
static char* get_api_key() {
  static char buffer[33];
  if (persist_exists(KEY_API_KEY)) {
    persist_read_string(KEY_API_KEY, buffer, sizeof(buffer));
    return buffer;
  }
  return "";
}
Ejemplo n.º 10
0
static void update_menu_data(int stringSize) {



  free_all_data();

  if (stringSize == 0) {return;}


  if (stringSize > 0) {
    char *buf= malloc(255);
    int readByteSize = persist_read_string(PERSIST_LIST,buf,255);
    listString = malloc(readByteSize);
    memcpy(listString,buf,readByteSize);
    free(buf);
    buf = NULL;

    listSize = persist_read_int(PERSIST_LIST_SIZE);

    APP_LOG(APP_LOG_LEVEL_DEBUG, "Read list from persistent storage: %s", listString);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Read size (value) from persistent storage: %d", listSize);

  } else {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Processing stringSize: %i",stringSize);
    listSize = stringSize;
    listString = (char*)malloc((strlen(s_buffer)+1)*sizeof(char));
    memcpy(listString, s_buffer, (strlen(s_buffer)+1)*sizeof(char));
    //strcpy(listString,s_buffer);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "strlen(listString): %i",strlen(listString));
  }

  theList = malloc(listSize * sizeof(char*));
  statusList = malloc(listSize * sizeof(char*));

  char * pch = NULL;
  int i;
  i = 0;
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Splitting string \"%s\" into tokens",listString);
  pch = strtok (listString,",");
  APP_LOG(APP_LOG_LEVEL_DEBUG, "strtok'd");

  while (pch != NULL)
  {
    theList[i] = (char*)malloc((strlen(pch)+1) * sizeof(char)); // Add extra for end char
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Malloc'd");
    statusList[i] = "Ready";
    memcpy(theList[i++],pch,(strlen(pch)+1) * sizeof(char));
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Mem copied");
    pch = strtok (NULL, ",");
  }

  for (i=0;i<listSize; ++i) 
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Data[%d]: %s",i, theList[i]);
  pch = NULL;
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Completed free all procedure");

  
}
Ejemplo n.º 11
0
static void load_items(void){
  int i, key;
  for (i=0; i<NUM_FIRST_MENU_ITEMS; i++){
    key = 2*i;
    if (persist_exists(key)) persist_read_string(key, book_list[i].name, sizeof(book_list[i].name));
    key++;
    if (persist_exists(key)) book_list[i].page_number = persist_read_int(key);
  }
}
Ejemplo n.º 12
0
void get_contact_name(char *name){
  if (persist_exists(NAME)){
    persist_read_string(NAME, name, sizeof(name));
  }
  else {
    name = "Serge";
  }
  APP_LOG(APP_LOG_LEVEL_DEBUG, "name = %s", name);
  text_layer_set_text(stl_phone, name);
}
Ejemplo n.º 13
0
static void get_stored_timezone(void) {
    char stored_str[sizeof(utc_offset_str)];

    if (!persist_exists(1)) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "No stored TZ offset.");
        // We don't have it persisted, so give up.
        return;
    }
    persist_read_string(1, stored_str, sizeof(stored_str));
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Looked up UTC offset from local storage: %s", stored_str);
    set_timezone_offset(stored_str);
}
Ejemplo n.º 14
0
char* GetThreadScore(int index)
{
#ifdef USE_PERSIST_STRINGS
    if(persist_index_score != index)
    {
        persist_index_score = index;
        persist_read_string(PERSIST_OFFSET_THREAD_SCORE + index, persist_string_score, PERSIST_STRING_MAX_LENGTH);
    }
    return persist_string_score;
#else
    return threads[index].score;
#endif
}
Ejemplo n.º 15
0
char* GetThreadTitle(int index)
{
#ifdef USE_PERSIST_STRINGS
    if(persist_index_title != index)
    {
        persist_index_title = index;
        persist_read_string(PERSIST_OFFSET_THREAD_TITLE + index, persist_string_title, PERSIST_STRING_MAX_LENGTH);
    }
    return persist_string_title;
#else
    return threads[index].title;
#endif
}
Ejemplo n.º 16
0
static void loadData() {
  if(persist_exists(STORAGE_DAY)) {
    persist_read_string(STORAGE_DAY, g_day, sizeof(g_day));
  }
  if(persist_exists(STORAGE_GOAL_ML)) {
    g_goal = persist_read_int(STORAGE_GOAL_ML);
  }
  if(persist_exists(STORAGE_DRINKS)) {
    persist_read_data(STORAGE_DRINKS, g_drinks, sizeof(g_drinks));
  }
  if(persist_exists(STORAGE_ACTIVE_DRINK_TYPE)) {
    g_activeDrinkType = persist_read_int(STORAGE_ACTIVE_DRINK_TYPE);
  }
}
Ejemplo n.º 17
0
void workout_load_by_data_position(Workout *workout, uint32_t data_position) {
    workout_load_by_data_position_without_machines(workout, data_position);

    Machine *machine = workout->first_machine;

    for (int mi = 0; mi < M__COUNT; mi++) {
        if (machine == NULL) break;

        persist_read_string(data_position + 1 + mi, res, 200);
        read_key_values_unsafe(machine, res, read_machine_data_callback);

        machine = machine->next;
    }
}
Ejemplo n.º 18
0
static void init_config() {
  // display
  if (persist_exists(SHOW_WEATHER))
    s_show_weather = persist_read_bool(SHOW_WEATHER);
  
  if (persist_exists(SHOW_LOCATION))
    s_show_location = persist_read_bool(SHOW_LOCATION);
  
  config_weather_layer(s_show_weather, s_show_location);
  
  // weather & location diaplay
  memset(s_conditions_buffer, 0, sizeof(s_conditions_buffer));
  if (persist_exists(WEATHER_ICON_KEY))
    persist_read_string(WEATHER_ICON_KEY, s_conditions_buffer, sizeof(s_conditions_buffer));
  
  memset(s_temperature_buffer, 0, sizeof(s_temperature_buffer));
  if (persist_exists(WEATHER_TEMPERATURE_KEY))
    persist_read_string(WEATHER_TEMPERATURE_KEY, s_temperature_buffer, sizeof(s_temperature_buffer));
  
  memset(s_city_buffer, 0, sizeof(s_city_buffer));
  if (persist_exists(WEATHER_CITY_KEY))
    persist_read_string(WEATHER_CITY_KEY, s_city_buffer, sizeof(s_city_buffer));
  
  config_weather_buffer(s_conditions_buffer, s_temperature_buffer, s_city_buffer);
  
  // location setting
  memset(s_default_location, 0, sizeof(s_default_location));
  if (persist_exists(DEFAULT_LOCATION))
    persist_read_string(DEFAULT_LOCATION, s_default_location, sizeof(s_default_location));
  
  memset(s_location_opt, 0, sizeof(s_location_opt));
  if (persist_exists(LOCATION_OPT))
    persist_read_string(LOCATION_OPT, s_location_opt, sizeof(s_location_opt));
  
  config_location_setting(s_default_location, s_location_opt);
}
Ejemplo n.º 19
0
static void load_text(int key, bool update_layer) {
    free_text(key);

    if (persist_exists(key)) {
        int size = persist_get_size(key);
        label_text[key] = malloc(size);
        persist_read_string(key, label_text[key], size);
    } else {
        label_text[key] = a2_strdup(label_default_text[key]);
    }

    if (update_layer) {
        text_layer_set_text(text_layers[key], label_text[key]);
    }
}
Ejemplo n.º 20
0
char* GetThreadSubreddit(int index)
{
#ifdef USE_PERSIST_STRINGS
    if(persist_index_subreddit != index)
    {
        persist_index_subreddit = index;
        if(persist_read_string(PERSIST_OFFSET_THREAD_SUBREDDIT + index, persist_string_subreddit, PERSIST_STRING_MAX_LENGTH) == E_DOES_NOT_EXIST)
        {
            return NULL;
        }
    }
    return persist_string_subreddit;
#else
    return threads[index].subreddit;
#endif
}
Ejemplo n.º 21
0
bool load_persistent(Menu *menu) {
    if(menu->id == 0 && persist_exists(0) && persist_read_int(0) > 0) {
        int size = persist_read_int(0);

        menu_allocation(menu, size);

        for(int i = 1; persist_exists(i); i++) {
            persist_read_string(i, menu->row[i-1]->title, 32);
            snprintf(menu->title, 32, "%s", "Favorites");
            snprintf(menu->row[i-1]->subtitle, 32, "%s", "");
            menu->size = size;
        }

        return true;
    }
    return false;
}
Ejemplo n.º 22
0
// Call once from init()/deinit()
void cache_init()
{
    app_log_ts(APP_LOG_LEVEL_DEBUG, "         cache_init()  ");

    if (persist_exists(STATE_KEY)){
      persist_read_data(STATE_KEY, state_cache, sizeof(state_cache));
    }
    if (persist_exists(TIME_KEY)){
      persist_read_data(TIME_KEY, time_cache, sizeof(time_cache));
    }
    if (persist_exists(HEIGHT_KEY)){
      persist_read_data(HEIGHT_KEY, height_cache, sizeof(height_cache));
    }
    if (persist_exists(PORTNAME_KEY)){
      persist_read_string(PORTNAME_KEY, portname_cache, sizeof(portname_cache));
    }
    app_log_ts(APP_LOG_LEVEL_DEBUG, "         cache_init() - exit  ");

}
Ejemplo n.º 23
0
SaveState slots_load_state() {
    persist_read_string(DATA_WORKOUT_SAVE_STATE, res, 200);

    SaveState state = (SaveState) {
            .save1_in_use = false,
            .save2_in_use = false,
            .save3_in_use = false
    };
    read_key_values_unsafe(&state, res, state_read_callback);

    return state;
}

void slots_save_state(SaveState state) {
    snprintf(res, 200, "1=%d;2=%d;3=%d;", state.save1_in_use ? 1 : 0, state.save2_in_use ? 1 : 0, state.save3_in_use ? 1 : 0);

    APP_LOG(APP_LOG_LEVEL_WARNING, "updating state: %s", res);
    persist_write_string(DATA_WORKOUT_SAVE_STATE, res);
}
static void main_window_load(Window *window) {
  //Initialize the backgrounds we can select
  s_dog_bg = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_DOG);
  s_cat_bg = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_CAT);
  s_bird_bg = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_BIRD);
  
  // Create time TextLayer
  s_time_layer = text_layer_create(GRect(0, 0, 144, 32));
  
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, GColorBlack);
  
  // Improve the layout to be more like a watchface
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MULI_24));
  text_layer_set_font(s_time_layer, s_time_font);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  
  //Check for saved background option
  char facebg[20];
  persist_read_string(KEY_BG, facebg, sizeof(facebg));
  
  if(strcmp(facebg,"dog") == 0){
    s_bg_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_DOG);
  }else if(strcmp(facebg,"cat") == 0){
    s_bg_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_CAT);
  }else if(strcmp(facebg,"bird") == 0){
    s_bg_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG_BIRD);
  }
  
  //Declare a bitmap layer
  //static BitmapLayer *s_bitmap_layer;
  
  //Create bitmap layer and set it to show the GBitmap
  s_bitmap_layer = bitmap_layer_create(GRect(0,0,144,168));
  bitmap_layer_set_bitmap(s_bitmap_layer,s_bg_bitmap);
  
  //Add the bitmaplayer as a child layer to the window:
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bitmap_layer));
  
  // Add text layer as a child layer to the Window's root layer
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
}
static void draw_row_callback(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *callback_context) {

    int event_no = get_event_no_from_row_index(cell_index->row);

    if (!persist_exists(event_no * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE))
        return;
    
    char event_title[PERSIST_STRING_MAX_LENGTH];
    persist_read_string(event_no * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE, event_title, PERSIST_STRING_MAX_LENGTH);
    
    char event_subtitle[55];
    char duration_string[10] = "";
    
    if (persist_exists(event_no * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_START_DATE)) {
    
        int start_date = persist_read_int(event_no * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_START_DATE);
    
        if (persist_exists(event_no * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_END_DATE)) {
        
            int end_date = persist_read_int(event_no * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_END_DATE);
        
            int duration = end_date - start_date;
            if (duration / 3600.0 != 24) {
                format_date_time(event_subtitle, 40, (time_t)start_date, 1);
                float_to_string(duration_string, 10, duration / 3600.0);
                strcat(event_subtitle, ", ");
                strcat(event_subtitle, duration_string);
                strcat(event_subtitle, "h");
            } else {
                format_date_time(event_subtitle, 40, (time_t)start_date, 0);
            }
            
        } else {
            format_date_time(event_subtitle, 40, (time_t)start_date, 1);
        }
        
    }
    
    menu_cell_basic_draw(ctx, cell_layer, event_title, event_subtitle, NULL);
    
}
Ejemplo n.º 26
0
static void init(void) {
	//initialize invertTime
	invertTime.offMin = 255;
	invertTime.offHour = 255;
	invertTime.onMin = 255;
	invertTime.onHour = 255;
	invertTime.updateMin = 255;
	invertTime.updateHour = 255;
	invertTime.type = OFF;
	
	// load user settings
	if(persist_exists(KEY_HAND_ORDER)) {
		persist_read_string(KEY_HAND_ORDER, s_hand_order, 4);
	}

	if(persist_exists(KEY_TEXT_TIME)) {
		s_show_text_time = persist_read_bool(KEY_TEXT_TIME);
	}

	if(persist_exists(KEY_INVERT)) {
		s_inverted = persist_read_bool(KEY_INVERT);
	}
	
	if(persist_exists(PS_INVERT_TIME)) {
		persist_read_data(PS_INVERT_TIME, &invertTime, sizeof(invertTime));
	}

	//register service to receive config from phone
	app_message_register_inbox_received((AppMessageInboxReceived)in_recv_handler);
	app_message_register_outbox_failed(outbox_failed_callback);
	app_message_register_outbox_sent(outbox_sent_callback);
	app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

 	// create main window and assign to pointer
	s_main_window = window_create();

	//assign main window handlers
	window_set_window_handlers(s_main_window, (WindowHandlers) {
		.load = main_window_load,
		.unload = main_window_unload
	});
Ejemplo n.º 27
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);
}
Ejemplo n.º 28
0
void readConfig() {
  if (persist_exists(CONFIG_KEY_DATEORDER)) {
    USDate = persist_read_int(CONFIG_KEY_DATEORDER);
  } else {
    USDate = 1;
    persist_write_int(CONFIG_KEY_DATEORDER, USDate);
  }

  if (persist_exists(CONFIG_KEY_WEEKDAY)) {
    showWeekday = persist_read_int(CONFIG_KEY_WEEKDAY);
  } else {
    showWeekday = 0;
    persist_write_int(CONFIG_KEY_WEEKDAY, showWeekday);
  }

  if (persist_exists(CONFIG_KEY_BATTERY)) {
    batteryStatus = persist_read_int(CONFIG_KEY_BATTERY);
  } else {
    batteryStatus = 1;
    persist_write_int(CONFIG_KEY_BATTERY, batteryStatus);
  }

  if (persist_exists(CONFIG_KEY_BLUETOOTH)) {
    bluetoothStatus = persist_read_int(CONFIG_KEY_BLUETOOTH);
  } else {
    bluetoothStatus = 1;
    persist_write_int(CONFIG_KEY_BLUETOOTH, bluetoothStatus);
  }

  if (persist_exists(CONFIG_KEY_INVERT)) {
    invertStatus = persist_read_int(CONFIG_KEY_INVERT);
  } else {
    invertStatus = 0;
    persist_write_int(CONFIG_KEY_INVERT, invertStatus);
  }

  if (persist_exists(CONFIG_KEY_LANG)) {
    curLang = persist_read_int(CONFIG_KEY_LANG);
  } else {
    curLang = LANG_ENGLISH;
    persist_write_int(CONFIG_KEY_LANG, curLang);
  }

  if (persist_exists(CONFIG_KEY_STRIPES)) {
    stripedDigits = persist_read_int(CONFIG_KEY_STRIPES);
  } else {
    stripedDigits = 1;
    persist_write_int(CONFIG_KEY_STRIPES, stripedDigits);
  }

  if (persist_exists(CONFIG_KEY_ROUNDCORNERS)) {
    roundCorners = persist_read_int(CONFIG_KEY_ROUNDCORNERS);
  } else {
    roundCorners = 1;
    persist_write_int(CONFIG_KEY_ROUNDCORNERS, roundCorners);
  }

  if (persist_exists(CONFIG_KEY_FULLDIGITS)) {
    fullDigits = persist_read_int(CONFIG_KEY_FULLDIGITS);
  } else {
    fullDigits = 0;
    persist_write_int(CONFIG_KEY_FULLDIGITS, fullDigits);
  }

  if (persist_exists(CONFIG_KEY_COLORTHEME)) {
    colorTheme = persist_read_int(CONFIG_KEY_COLORTHEME);
  } else {
    colorTheme = 0;
    persist_write_int(CONFIG_KEY_COLORTHEME, colorTheme);
  }

  if (persist_exists(CONFIG_KEY_THEMECODE)) {
    persist_read_string(CONFIG_KEY_THEMECODE, themeCodeText, sizeof(themeCodeText));
  } else {
    strcpy(themeCodeText, "ffffffffffc0");
    persist_write_string(CONFIG_KEY_THEMECODE, themeCodeText);
  }

  decodeThemeCode(themeCodeText);

  APP_LOG(APP_LOG_LEVEL_DEBUG, "Stored config :");
  APP_LOG(APP_LOG_LEVEL_DEBUG, "  dateorder=%d, weekday=%d, battery=%d, BT=%d, invert=%d",
          USDate, showWeekday, batteryStatus, bluetoothStatus, invertStatus);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "  lang=%d, stripedDigits=%d, roundCorners=%d, fullDigits=%d",
          curLang, stripedDigits, roundCorners, fullDigits);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "  colorTheme=%d, themecode=%s", colorTheme, themeCodeText);
}
Ejemplo n.º 29
0
static void init() {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "GlobalTime initialising... build: %s", build_time);
  
  // Create main Window element and assign to pointer
  s_main_window = window_create();
  window_set_background_color(s_main_window, GColorBlack);
  
  // Create popup window
  s_popup_window = window_create();
  window_set_background_color(s_popup_window, GColorBlack);
  popup_window_load(s_popup_window);
  
  ResHandle big_handle = resource_get_handle(RESOURCE_ID_FONT_COMFORTAA_BOLD_33);
  s_big_font = fonts_load_custom_font(big_handle);
  
  ResHandle medium_handle = resource_get_handle(RESOURCE_ID_FONT_COMFORTAA_BOLD_23);
  s_medium_font = fonts_load_custom_font(medium_handle);
  
  ResHandle small_handle = resource_get_handle(RESOURCE_ID_FONT_COMFORTAA_REGULAR_15);
  s_small_font = fonts_load_custom_font(small_handle);
  
  s_bmp_bt = gbitmap_create_with_resource(RESOURCE_ID_BMP_BT);
  s_bmp_nobt = gbitmap_create_with_resource(RESOURCE_ID_BMP_NOBT);
  s_bmp_charge = gbitmap_create_with_resource(RESOURCE_ID_BMP_CHARGE);
  s_bmp_nocharge = gbitmap_create_with_resource(RESOURCE_ID_BMP_NOCHARGE);
  s_bmp_battery[0] = gbitmap_create_with_resource(RESOURCE_ID_BMP_00);
  s_bmp_battery[1] = gbitmap_create_with_resource(RESOURCE_ID_BMP_10);
  s_bmp_battery[2] = gbitmap_create_with_resource(RESOURCE_ID_BMP_20);
  s_bmp_battery[3] = gbitmap_create_with_resource(RESOURCE_ID_BMP_30);
  s_bmp_battery[4] = gbitmap_create_with_resource(RESOURCE_ID_BMP_40);
  s_bmp_battery[5] = gbitmap_create_with_resource(RESOURCE_ID_BMP_50);
  s_bmp_battery[6] = gbitmap_create_with_resource(RESOURCE_ID_BMP_60);
  s_bmp_battery[7] = gbitmap_create_with_resource(RESOURCE_ID_BMP_70);
  s_bmp_battery[8] = gbitmap_create_with_resource(RESOURCE_ID_BMP_80);
  s_bmp_battery[9] = gbitmap_create_with_resource(RESOURCE_ID_BMP_90);
  
  // Read current TZ config
  persist_read_string(KEY_TZ1, s_tz[0], TZ_SIZE);
  persist_read_string(KEY_TZ2, s_tz[1], TZ_SIZE);
  persist_read_string(KEY_TZ3, s_tz[2], TZ_SIZE);
  persist_read_string(KEY_TZ4, s_tz[3], TZ_SIZE);
  persist_read_string(KEY_TZ5, s_tz[4], TZ_SIZE);
  persist_read_string(KEY_TZ6, s_tz[5], TZ_SIZE);
  persist_read_string(KEY_TZ7, s_tz[6], TZ_SIZE);
  persist_read_string(KEY_TZ8, s_tz[7], TZ_SIZE);
  
  s_offset[0] = persist_read_int(KEY_OFFSET1);
  s_offset[1] = persist_read_int(KEY_OFFSET2);
  s_offset[2] = persist_read_int(KEY_OFFSET3);
  s_offset[3] = persist_read_int(KEY_OFFSET4);
  s_offset[4] = persist_read_int(KEY_OFFSET5);
  s_offset[5] = persist_read_int(KEY_OFFSET6);
  s_offset[6] = persist_read_int(KEY_OFFSET7);
  s_offset[7] = persist_read_int(KEY_OFFSET8);
  
  persist_read_string(KEY_LABEL1, s_label[0], LABEL_SIZE);
  persist_read_string(KEY_LABEL2, s_label[1], LABEL_SIZE);
  persist_read_string(KEY_LABEL3, s_label[2], LABEL_SIZE);
  persist_read_string(KEY_LABEL4, s_label[3], LABEL_SIZE);
  persist_read_string(KEY_LABEL5, s_label[4], LABEL_SIZE);
  persist_read_string(KEY_LABEL6, s_label[5], LABEL_SIZE);
  persist_read_string(KEY_LABEL7, s_label[6], LABEL_SIZE);
  persist_read_string(KEY_LABEL8, s_label[7], LABEL_SIZE);

  for (int i = 0; i < CONFIG_SIZE; i++) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Loaded TZ configuration 1: %s - %s (%ld)", s_label[i], s_tz[i], s_offset[i]);
  }
  
  sort_times();
  
  // Register a callback for the UTC offset information
  // TODO register failure callbacks too
  app_message_register_inbox_received(inbox_received_callback);
  
  // Connect to AppMessage stream
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
  
  // Send a request for TZ offsets
  send_tz_request();

  // Set handlers to manage the elements inside the Window
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });
Ejemplo n.º 30
0
static void handle_init(void) {
  time_t rawtime;
  time (&rawtime);
  struct tm * tick_time;
  tick_time = localtime(&rawtime);
  tick_time->tm_year = 2014 - 1900;
  tick_time->tm_mon = 12 - 1;
  tick_time->tm_mday = 9;
  tick_time->tm_hour = 12 - 1;
  tick_time->tm_min = 0;
  tick_time->tm_sec = 0;
  start_time = mktime(tick_time);
  tick_time = localtime(&rawtime);
  tick_time->tm_year = 2015 - 1900;
  tick_time->tm_mon = 12 - 1;
  tick_time->tm_mday = 9;
  tick_time->tm_hour = 12 - 1;
  tick_time->tm_min = 0;
  tick_time->tm_sec = 0;
  end_time = mktime(tick_time);

  strcpy(text_otslujul, "Ты отслужил");
  strcpy(text_ostalos, "До дембеля осталось");
  strcpy(text_uje, "Ты дембель уже");
  
  // Read stored settings
  if (persist_exists(MSG_START_TIME))
    start_time = persist_read_int(MSG_START_TIME);
  if (persist_exists(MSG_END_TIME))
    end_time = persist_read_int(MSG_END_TIME);
  if (persist_exists(MSG_TEXT_OTSLUJIL))
    persist_read_string(MSG_TEXT_OTSLUJIL, text_otslujul, sizeof(text_otslujul));
  if (persist_exists(MSG_TEXT_OSTALOS))
    persist_read_string(MSG_TEXT_OSTALOS, text_ostalos, sizeof(text_ostalos));
  if (persist_exists(MSG_TEXT_UJE))
    persist_read_string(MSG_TEXT_UJE, text_uje, sizeof(text_uje));
    
  // Open communication channel
  app_message_register_inbox_received(in_received_handler);
  app_message_open(256, 256);
  
	// Create a window and text layer
	window = window_create();

  // Current time layer
  time_layer = text_layer_create(GRect(0, 0, 144, 50));	
	// Set the text, font, and text alignment
	text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  text_layer_set_background_color(time_layer, GColorClear);
	text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);	
	// Add the text layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));

  // Left time layer
  left_time_layer = text_layer_create(GRect(0, 47, 144, 80));	
	// Set the text, font, and text alignment
	text_layer_set_font(left_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_background_color(left_time_layer, GColorClear);
	text_layer_set_text_alignment(left_time_layer, GTextAlignmentCenter);	
	// Add the text layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(left_time_layer));

  // Another Left time layer
  left_time_layer2 = text_layer_create(GRect(0, 67, 144, 80));	
	// Set the text, font, and text alignment
	text_layer_set_font(left_time_layer2, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_background_color(left_time_layer2, GColorClear);
	text_layer_set_text_alignment(left_time_layer2, GTextAlignmentCenter);	
	// Add the text layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(left_time_layer2));

  // Percent layer
  percent_layer = text_layer_create(GRect(0, 130, 144, 80));	
	// Set the text, font, and text alignment
	text_layer_set_font(percent_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_background_color(percent_layer, GColorClear);
	text_layer_set_text_alignment(percent_layer, GTextAlignmentCenter);	
	// Add the text layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(percent_layer));

  // Create progress bar
  progress_layer = layer_create(GRect(2, 150, 140, 15));
  layer_set_update_proc(progress_layer, &progress_layer_update_callback);
  layer_add_child(window_get_root_layer(window), progress_layer);
  
  time_t now = time(NULL);
  handle_tick(localtime(&now), 0);
  
	// Push the window
	window_stack_push(window, true);

  // Subscribe to time updates
  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); 
  
  //light_enable(true); // For taking photos only!
}