Beispiel #1
0
static void in_received_handler(DictionaryIterator *received, void *context) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Received config");
  Tuple *tuple = dict_find(received, MSG_START_TIME);
  if (tuple) {
    start_time = tuple->value->int32;
    persist_write_int(MSG_START_TIME, start_time);
  }
  tuple = dict_find(received, MSG_END_TIME);
  if (tuple) {
    end_time = tuple->value->int32;
    persist_write_int(MSG_END_TIME, end_time);
  }
  tuple = dict_find(received, MSG_TEXT_OTSLUJIL);
  if (tuple) {
    strcpy(text_otslujul, tuple->value->cstring);
    persist_write_string(MSG_TEXT_OTSLUJIL, text_otslujul);
  }
  tuple = dict_find(received, MSG_TEXT_OSTALOS);
  if (tuple) {
    strcpy(text_ostalos, tuple->value->cstring);
    persist_write_string(MSG_TEXT_OSTALOS, text_ostalos);
  }
  tuple = dict_find(received, MSG_TEXT_UJE);
  if (tuple) {
    strcpy(text_uje, tuple->value->cstring);
    persist_write_string(MSG_TEXT_UJE, text_uje);
  }
  time_t now = time(NULL);
  handle_tick(localtime(&now), 0);
}
static void in_recv_handler(DictionaryIterator *iterator, void *context){
  //Get Tuple
  Tuple *t = dict_read_first(iterator);
  if(t)
  {
    switch(t->key)
    {
    case KEY_BG:
      //strcmp compares binary value of two strings, 0 means the two strings are equal
      if(strcmp(t->value->cstring, "dog") == 0){
        bitmap_layer_set_bitmap(s_bitmap_layer, s_dog_bg);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Dog selected");
        persist_write_string(KEY_BG, "dog");
      }
      else if(strcmp(t->value->cstring, "cat") == 0){
        bitmap_layer_set_bitmap(s_bitmap_layer, s_cat_bg);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Cat selected");
        persist_write_string(KEY_BG, "cat");
      }
      else if(strcmp(t->value->cstring, "bird") == 0){
        bitmap_layer_set_bitmap(s_bitmap_layer, s_bird_bg);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Bird selected");
        persist_write_string(KEY_BG, "bird");
      }
      else{
        APP_LOG(APP_LOG_LEVEL_DEBUG, "You shouldn't see this in the app log. Something went wrong.");
      }
    }
  }
}
Beispiel #3
0
static void in_received_handler(DictionaryIterator *iter, void *context) {
	Tuple *server_host_tuple = dict_find(iter, KEY_SERVER_HOST);
	Tuple *server_pass_tuple = dict_find(iter, KEY_SERVER_PASS);
	Tuple *title_tuple = dict_find(iter, KEY_TITLE);
	Tuple *status_tuple = dict_find(iter, KEY_STATUS);
	Tuple *volume_tuple = dict_find(iter, KEY_VOLUME);

	if (server_host_tuple) {
		persist_write_string(KEY_SERVER_HOST, server_host_tuple->value->cstring);
		set_server_host_from_persistent_storage();
	}
	if (server_pass_tuple) {
		persist_write_string(KEY_SERVER_PASS, server_pass_tuple->value->cstring);
		set_server_pass_from_persistent_storage();
	}
	if (title_tuple) {
		strncpy(title, title_tuple->value->cstring, sizeof(title));
		text_layer_set_text(title_layer, title);
	}
	if (status_tuple) {
		strncpy(status, status_tuple->value->cstring, sizeof(status));
		text_layer_set_text(status_layer, status);
		if (strcmp(status, "Playing") == 0) {
			action_bar_layer_set_icon(action_bar, BUTTON_ID_SELECT, action_icon_pause);
		} else {
			action_bar_layer_set_icon(action_bar, BUTTON_ID_SELECT, action_icon_play);
		}
	}
	if (volume_tuple) {
		strncpy(volume, volume_tuple->value->cstring, sizeof(volume));
		text_layer_set_text(volume_layer, volume);
	}
}
Beispiel #4
0
static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) {
    
    
    APP_LOG(APP_LOG_LEVEL_DEBUG, "key: %lu", key);
    
    switch (key) {
               case VALUE_1:
            APP_LOG(APP_LOG_LEVEL_DEBUG, "s_current_session_layer: %s", new_tuple->value->cstring);
            
            persist_write_string(PERSIST_VALUE_1, new_tuple->value->cstring);
            
            text_layer_set_text(s_current_session_layer, new_tuple->value->cstring);
            break;
            
        case VALUE_2:
            // App Sync keeps new_tuple in sync_buffer, so we may use it directly
            
            APP_LOG(APP_LOG_LEVEL_DEBUG, "s_upcoming_session_layer: %s", new_tuple->value->cstring);
            
            persist_write_string(PERSIST_VALUE_2, new_tuple->value->cstring);

            text_layer_set_text(s_upcoming_session_layer, new_tuple->value->cstring);

            
            break;

    }
    
    
}
Beispiel #5
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  APP_LOG(APP_LOG_LEVEL_INFO, "Message received!");
  Tuple *t = dict_read_first(iterator);

  // Process all pairs present
  while(t != NULL) {
    // Process this pair's key
    switch (t->key) {
      case KEY_PHONE:
        persist_write_string(PERSIST_KEY_PHONE_NUMBER, t->value->cstring);
        break;
      case KEY_NAME:
        persist_write_string(PERSIST_KEY_NAME, t->value->cstring);
        break;
      case KEY_TIMER:
        persist_write_int(PERSIST_KEY_INTERVAL_TIME, t->value->int32);
        break;
      case KEY_VIBRATE:
        persist_write_int(PERSIST_KEY_BUZZ_TIME, t->value->int32);
        break;
    }

    // Get next pair, if any
    t = dict_read_next(iterator);
  }
}
Beispiel #6
0
void
write_proj_change_info (void) 
{
    status_t stat;
    int i;
    uint32_t h, m;
    char string[10];

    DictionaryIterator *iterator;

    app_message_outbox_begin(&iterator);

    for (i = 0 ; i < NUM_PROJECTS ; i++) {
	stat = persist_write_int(proj_time_val[i], (uint32_t)proj_time[i]);
	stat = persist_write_int(proj_run_val[i], (uint32_t)proj_running[i]);
	stat = persist_write_int(proj_start_val[i], (uint32_t)proj_start[i]);
	if (proj_name[i] && *proj_name[i]) {
	    stat = persist_write_string(proj_name_val[i], proj_name[i]);
	    dict_write_cstring(iterator, proj_name_val[i], proj_name[i]);
	} else {
	    stat = persist_write_string(proj_name_val[i], "");
	    dict_write_cstring(iterator, proj_name_val[i], proj_name[i]);
	}
	app_log(APP_LOG_LEVEL_WARNING,
		__FILE__,
		__LINE__,
		"Proj %d time info written as %d:%d", i, hours(proj_time[i]), minutes(proj_time[i]));
	h = (uint32_t)hours(proj_time[i]);
	stat = persist_write_int(proj_hour_val[i], h);
	m = (uint32_t)minutes(proj_time[i]);
	stat = persist_write_int(proj_min_val[i], m);

	snprintf(string, sizeof(string), "%u", (uint)h);
	dict_write_cstring(iterator, proj_hour_val[i], string);

	snprintf(string, sizeof(string), "%u", (uint)m);
	dict_write_cstring(iterator, proj_min_val[i], string);
    }

    app_log(APP_LOG_LEVEL_WARNING,
            __FILE__,
            __LINE__,
            "Writing autostop as %d", (int)autostop);
    stat = persist_write_int(AUTOSTOP, (uint32_t)autostop);
    snprintf(string, sizeof(string), "%u", (uint)autostop);
    dict_write_cstring(iterator, AUTOSTOP, string);

    app_message_outbox_send();

    if (bluetooth_connected == true && stat == 4) {
	proj_change_written = true;
    } else {
	app_log(APP_LOG_LEVEL_WARNING,
		__FILE__,
		__LINE__,
		"Proj time info written");
	proj_change_written = false;
    }
}
Beispiel #7
0
void put_entry(char *name, char *value) {
  // Get out the values at the master key
  uint32_t tmp[BUFFER_SIZE/4];
  persist_read_data(MASTER_KEY, tmp, BUFFER_SIZE);

  // Update the store with new stuff
  int key = next_key++;
  persist_write_string(name_key(key), name);
  persist_write_string(value_key(key), value);

  // Write back the master key's new value
  tmp[key] = key;
  persist_write_data(MASTER_KEY, tmp, BUFFER_SIZE);
}
Beispiel #8
0
void Settings_saveToStorage() {
  // ensure that the weather disabled setting is accurate before saving it
  Settings_updateDynamicSettings();

  // save settings to persistent storage
  persist_write_data(SETTING_TIME_COLOR_KEY,            &globalSettings.timeColor,        sizeof(GColor));
  persist_write_data(SETTING_TIME_BG_COLOR_KEY,         &globalSettings.timeBgColor,      sizeof(GColor));
  persist_write_data(SETTING_SIDEBAR_COLOR_KEY,         &globalSettings.sidebarColor,     sizeof(GColor));
  persist_write_data(SETTING_SIDEBAR_TEXT_COLOR_KEY,    &globalSettings.sidebarTextColor, sizeof(GColor));
  persist_write_bool(SETTING_USE_METRIC_KEY,            globalSettings.useMetric);
  persist_write_bool(SETTING_SIDEBAR_LEFT_KEY,          globalSettings.sidebarOnLeft);
  persist_write_bool(SETTING_BT_VIBE_KEY,               globalSettings.btVibe);
  persist_write_int( SETTING_LANGUAGE_ID_KEY,           globalSettings.languageId);
  persist_write_int( SETTING_LEADING_ZERO_KEY,          globalSettings.showLeadingZero);
  persist_write_bool(SETTING_SHOW_BATTERY_PCT_KEY,      globalSettings.showBatteryPct);
  persist_write_bool(SETTING_DISABLE_WEATHER_KEY,       globalSettings.disableWeather);
  persist_write_bool(SETTING_CLOCK_FONT_ID_KEY,         globalSettings.clockFontId);
  persist_write_int( SETTING_HOURLY_VIBE_KEY,           globalSettings.hourlyVibe);
  persist_write_bool(SETTING_BATTERY_ONLY_WHEN_LOW_KEY, globalSettings.onlyShowBatteryWhenLow);
  persist_write_bool(SETTING_USE_LARGE_FONTS_KEY,       globalSettings.useLargeFonts);
  persist_write_int(SETTING_SIDEBAR_WIDGET0_KEY,        globalSettings.widgets[0]);
  persist_write_int(SETTING_SIDEBAR_WIDGET1_KEY,        globalSettings.widgets[1]);
  persist_write_int(SETTING_SIDEBAR_WIDGET2_KEY,        globalSettings.widgets[2]);
  persist_write_string(SETTING_ALTCLOCK_NAME_KEY,       globalSettings.altclockName);
  persist_write_int(SETTING_ALTCLOCK_OFFSET_KEY,        globalSettings.altclockOffset);

  persist_write_int(SETTINGS_VERSION_KEY,               CURRENT_SETTINGS_VERSION);
}
Beispiel #9
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Store incoming information
  static char temperature_buffer[8];
  static char conditions_buffer[32];
  static char weather_layer_buffer[32];
  static char tempscale_buffer[16];

    // Read tuples for data
    Tuple *temp_tuple = dict_find(iterator, KEY_TEMPERATURE);
    Tuple *conditions_tuple = dict_find(iterator, KEY_CONDITIONS);
  
    if (dict_find(iterator, KEY_TEMPSCALE)) {
      Tuple *scale_tuple = dict_find(iterator, KEY_TEMPSCALE);
      snprintf(tempscale_buffer, sizeof(tempscale_buffer), "%s", scale_tuple->value->cstring);
      
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Tempscale = %s", tempscale_buffer);
      persist_write_string(KEY_TEMPSCALE, tempscale_buffer);
    }

    // If all data is available, use it
    if(temp_tuple && conditions_tuple) {
       snprintf(temperature_buffer, sizeof(temperature_buffer), "%dC", (int)temp_tuple->value->int32);
       snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", conditions_tuple->value->cstring);
    }
  
    // Assemble full string and display
    snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
    text_layer_set_text(s_weather_layer, weather_layer_buffer);

}
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  // Almacena la informacion entrante
  static char temperature_buffer[8];
  static char conditions_buffer[32];
  static char weather_layer_buffer[32];
  
  // Lee las tuplas para obtener los datos
  Tuple *temp_tuple = dict_find(iterator, KEY_TEMPERATURE);
  Tuple *conditions_tuple = dict_find(iterator, KEY_CONDITIONS);
  Tuple *freq_update_t = dict_find(iterator, KEY_FREQUENCY_UPDATE_WEATHER);
  
  // Si todos los datos estan disponibles, se usan
  if(temp_tuple && conditions_tuple) {
    snprintf(temperature_buffer, sizeof(temperature_buffer), "%d°", (int)temp_tuple->value->int32);
  }
  
  // Se concatenan las cadenas de caracteres y se muestran
  snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s", temperature_buffer);
  text_layer_set_text(s_weather_layer, weather_layer_buffer);
  persist_write_string(KEY_LAST_WEATHER_BUFFER, weather_layer_buffer);
  
  if(freq_update_t) {
    freq_update_weather = freq_update_t->value->int32;
    persist_write_int(KEY_SAVED_FREQUENCY_UPDATE_WEATHER, freq_update_weather);
  }
  
}
Beispiel #11
0
static void app_message_read_card_payload(DictionaryIterator *dict, int32_t card_index) {
    Tuple *tuple = dict_read_first(dict);
    if (!tuple) {
        APP_LOG(APP_LOG_LEVEL_ERROR, "[CARD %ld] dict_read_first -> NULL", card_index);
        return;
    }

    while (tuple) {
        uint32_t cstr_key = 0;
        uint32_t data_key = 0;
        switch (tuple->key) {
            case KEY_CARD_BALANCE:
                cstr_key = STORAGE_CARD_VALUE(BALANCE, card_index);
                break;
            case KEY_CARD_BARCODE_DATA:
                data_key = STORAGE_CARD_VALUE(BARCODE_DATA, card_index);
                break;
            case KEY_CARD_NAME:
                cstr_key = STORAGE_CARD_VALUE(NAME, card_index);
                break;
        }

        if (cstr_key) {
            persist_write_string(cstr_key, tuple->value->cstring);
        } else if (data_key) {
            persist_write_data(data_key, tuple->value->data, tuple->length);
        }

        tuple = dict_read_next(dict);
    }
}
Beispiel #12
0
static void set_clubcard_number(const char* number)
{
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Setting clubcard account number to '%s'", number);
    strncpy(clubcard_number, number, CLUBCARD_NUMBER_LENGTH);
    persist_write_string(CLUBCARD_NUMBER_KEY, clubcard_number);
    barcode_layer_set_value(barcode_layer, clubcard_number);
}
Beispiel #13
0
/*
 * 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
			});
Beispiel #14
0
void handle_deinit(void) {
  tick_timer_service_unsubscribe();

  persist_write_string(MESSAGE_KEY_DATE_FORMAT_KEY,       PersistDateFormat);
  persist_write_int(MESSAGE_KEY_BT_VIBRATE_KEY,           PersistBTLoss);
  persist_write_int(MESSAGE_KEY_LOW_BATTERY_KEY,          PersistLow_Batt);
  
  battery_state_service_unsubscribe();
  bluetooth_connection_service_unsubscribe();
  app_focus_service_unsubscribe();

  text_layer_destroy(text_time_layer);
  text_layer_destroy(text_date_layer);
  text_layer_destroy(text_dayname_layer);
  text_layer_destroy(text_battery_layer);

  layer_destroy(BatteryLineLayer);
  layer_destroy(BTLayer);

  gbitmap_destroy(image);
  bitmap_layer_destroy(image_layer);

  fonts_unload_custom_font(fontHelvNewLight20);
  fonts_unload_custom_font(fontRobotoBoldSubset40);
  fonts_unload_custom_font(fontRobotoBoldSubset45);


  window_destroy(window);
}
Beispiel #15
0
static void store_timezone() {
    int result;

    result = persist_write_string(1, utc_offset_str);
    if (result < 0) {
        APP_LOG(APP_LOG_LEVEL_WARNING, "Storing timezone failed: %d", result);
    } else {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Stored timezone: %s", utc_offset_str);
    }
}
Beispiel #16
0
// Write back values.
void storage_persist(void) {
    LOG_FUNC();

    persist_write_string(SELECTED_VERSION, storage.selectedVersion);
    persist_write_data(BATTERY_ESTIMATE, (void*)&(storage.battery_estimate), sizeof(battery_estimate_data));
    persist_write_int(LAST_FULL_TIMESTAMP, storage.last_full_timestamp);
    persist_write_int(BATTERY_DISPLAY, storage.battery_display);

    app_log_storage_log(LOG_STORAGE);
}
Beispiel #17
0
static void set_text_from_dict(DictionaryIterator *iter, int key) {
    Tuple *tuple = dict_find(iter, key);
    if (!(tuple && tuple->type == TUPLE_CSTRING)) return;

    char *str = tuple->value->cstring;
    persist_write_string(key, str);

    free_text(key);
    label_text[key] = a2_strdup(str);
    text_layer_set_text(text_layers[key], label_text[key]);
}
Beispiel #18
0
void cache_deinit()
{
   // APP_LOG(APP_LOG_LEVEL_DEBUG, "         cache_deinit()  ");

    persist_write_data(STATE_KEY, state_cache, sizeof(state_cache));
    persist_write_data(TIME_KEY, time_cache, sizeof(time_cache));
    persist_write_data(HEIGHT_KEY, height_cache, sizeof(height_cache));
    persist_write_string(PORTNAME_KEY, portname_cache); 

   // APP_LOG(APP_LOG_LEVEL_DEBUG, "         cache_deinit() - exit ");

}
Beispiel #19
0
void SetThreadScore(struct ThreadData* thread, int index, char* str)
{
#ifdef USE_PERSIST_STRINGS
    persist_write_string(PERSIST_OFFSET_THREAD_SCORE + index, str);
#else
    if(thread->score != NULL)
    {
        nt_Free(thread->score);
    }
    thread->score = (char*)nt_Malloc(sizeof(char) * (strlen(str) + 1));
    strcpy(thread->score, str);
#endif
}
Beispiel #20
0
void workout_save_to_key(Workout *w, bool deep, uint32_t data_key) {
    APP_LOG(APP_LOG_LEVEL_WARNING, "saving workout to slot: %d, deep: %d", (int) data_key, (deep ? 1 : 0));

    workout_serialize(res, w);
    APP_LOG(APP_LOG_LEVEL_WARNING, "workout: %s", res);
    persist_write_string(data_key, res);

    if (deep) {
        Machine *m = w->first_machine;
        while (m != NULL) {
            machine_save_to_key(m, data_key);
            m = m->next;
        }
    }
}
Beispiel #21
0
// inbox received callback - reads and interprets info from companion
//    key 0 -> new timer length
//    key 1 -> new passcode
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  Tuple *t = dict_read_first(iterator);
  while (t != NULL) {
    switch(t -> key) {
      case 0:
        s_timer_len = (t -> value -> uint8)*1000;
        persist_write_int(TIMERLEN_PERSIST_KEY, s_timer_len);
        break;
      case 1:
        snprintf(s_passcode, PASSCODE_LEN + 1, "%s", t -> value -> cstring);
        persist_write_string(PASSCODE_PERSIST_KEY, s_passcode);
        break;
    }
    t = dict_read_next(iterator);
  }
  APP_LOG(APP_LOG_LEVEL_INFO, "Message received!");
}
Beispiel #22
0
void cache_set_refreshed(){
  // get time since epoch and store
  time_t epoch = time(NULL);
  uint16_t epoch_mins = epoch / 60;
  APP_LOG(APP_LOG_LEVEL_WARNING, "         cache_set_refreshed()  epoch_mins= %u", (unsigned int)epoch_mins);
  
  persist_write_int (TIME_INIT_KEY, epoch_mins);
  
  // also store as a 24h hh:mm string - will display when the cache eventually goes stale
  struct tm *tick_time = localtime(&epoch);
  static char buffer[] = "00:00";
  strftime(buffer, sizeof("00:00"), "%H:%M", tick_time);
  persist_write_string(TIME_INIT_KEY_HHMM, buffer);
  
  APP_LOG(APP_LOG_LEVEL_WARNING, "         cache_set_refreshed()  hh_mm= %s", buffer);
  return;
}
Beispiel #23
0
bool checkAndSaveString(char *var, char *val, int key) {
  int ret;

  if (strcmp(var, val) != 0) {
    strcpy(var, val);
    ret = persist_write_string(key, val);
    if (ret < (int)strlen(val)) {
      APP_LOG(APP_LOG_LEVEL_DEBUG, "checkAndSaveString() : persist_write_string(%d, %s) returned %d",
              key, val, ret);
    }
    return true;
  } else {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "checkAndSaveString() : value has not changed (was : %s, is : %s)",
            var, val);
    return false;
  }
}
Beispiel #24
0
static void in_received_handler(DictionaryIterator *iter, void *context) {
	Tuple *index_tuple = dict_find(iter, KEY_MES);
	Tuple *content_tuple = dict_find(iter, KEY_HORARIO);

  
	if (index_tuple && content_tuple) {
		Tipo_horario_recibido horario;
		horario.index = index_tuple->value->int16;
		strncpy(horario.content, content_tuple->value->cstring, sizeof(horario.content) - 1);
		horarios_recibidos[horario.index] = horario;
  
      persist_write_string(horario.index, horario.content);
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Grabado %s en %d", horario.content, horario.index);

	}

}
Beispiel #25
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);
}
Beispiel #26
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
	// Store incoming lecture information
	static char lecture_title_buffer[15];
	static char lecture_location_buffer[15];
	static char lecture_time_buffer[15];
	static char lecture_layer_buffer[50];

	// Read the first item
	Tuple *t = dict_read_first(iterator);
	
	// For each item
	while(t != NULL){
		
		switch(t->key) {
			case KEY_TITLE:
				snprintf(lecture_title_buffer, sizeof(lecture_title_buffer), "%s", t->value->cstring);
				break;
			case KEY_TIME:
				snprintf(lecture_time_buffer, sizeof(lecture_time_buffer), "%s", t->value->cstring);
				break;
			case KEY_LOCATION:
				snprintf(lecture_location_buffer, sizeof(lecture_location_buffer), "%s", t->value->cstring);
				break;
			default:
				APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int) t->key);
				break;
		}
		
		// Get next item
		t = dict_read_next(iterator);
	}
	
	snprintf(lecture_layer_buffer, sizeof(lecture_layer_buffer), "%s\n%s\n%s", lecture_title_buffer, lecture_time_buffer, lecture_location_buffer);
		
	// Compare the buffers and decide whether to write to storage
	if(strcmp(lecture_layer_buffer, current_lecture_layer_buffer) != 0){
		persist_write_string(KEY_DISPLAY_STRING, lecture_layer_buffer);
		strcpy(current_lecture_layer_buffer, lecture_layer_buffer);
	}
	
	text_layer_set_text(s_schedule_layer, lecture_layer_buffer);
}
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
  Tuple *t = dict_read_first(iterator);
  // Process all pairs present
  while (t != NULL) {
    static char s_buffer[64];
    switch (t->key) {
      case NUMBER:
      case NAME:
        snprintf(s_buffer, sizeof(s_buffer), "%s", t->value->cstring);
        // TODO: Save the new number in the pebble storage. Number is locates in s_buffer
        persist_write_string(t->key, t->value->cstring);
        APP_LOG(APP_LOG_LEVEL_ERROR, "Writing a string to persist");
        break;
      case COUNTDOWN_DURATION:
        persist_write_int(t->key, t->value->uint32);
        APP_LOG(APP_LOG_LEVEL_ERROR, "Writing an int to persist");
    }
    // Get next pair, if any
    t = dict_read_next(iterator);
  }
}
Beispiel #28
0
void SetThreadSubreddit(struct ThreadData* thread, int index, char* str)
{
#ifdef USE_PERSIST_STRINGS
    if(str != NULL)
    {
        persist_write_string(PERSIST_OFFSET_THREAD_SUBREDDIT + index, str);
    }
    else
    {
        persist_delete(PERSIST_OFFSET_THREAD_SUBREDDIT + index);
    }
#else
    if(thread->subreddit != NULL)
    {
        nt_Free(thread->subreddit);
    }
    if(str != NULL)
    {
        thread->subreddit = (char*)nt_Malloc(sizeof(char) * (strlen(str) + 1));
        strcpy(thread->subreddit, str);
    }
#endif
}
Beispiel #29
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 #30
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);
}