Exemplo n.º 1
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);
}
Exemplo n.º 2
0
int save_settings(){
	version.versionCode = CURRENT_VERSION;

	int total = persist_write_data(KEY_SETTINGS, &settings, sizeof(settings));
	total += persist_write_data(KEY_VERSION, &version, sizeof(version));
	return total;
}
Exemplo n.º 3
0
void timers_save(void) {
  if (timers_count() == 0) {
    persist_delete(PERSIST_TIMER_START);
    return;
  }
  TimerBlock* block = NULL;
  uint8_t block_count = 0;
  for (uint8_t b = 0; b < timers_count(); b += 1) {
    if (NULL == block) {
      block = malloc(sizeof(TimerBlock));
      block->total_timers = timers_count();
      block->save_time = time(NULL);
    }

    uint8_t timer_block_pos = b % TIMER_BLOCK_SIZE;
    block->timers[timer_block_pos] = *timers_get(b);

    bool is_last_timer_in_block = timer_block_pos == (TIMER_BLOCK_SIZE - 1);
    if (is_last_timer_in_block) {
      persist_write_data(PERSIST_TIMER_START + block_count, block, sizeof(TimerBlock));
      block_count += 1;
      free(block);
      block = NULL;
    }
  }
  if (block) {
    persist_write_data(PERSIST_TIMER_START + block_count, block, sizeof(TimerBlock));
  }
  persist_write_int(PERSIST_TIMERS_VERSION, TIMERS_VERSION_CURRENT);
}
Exemplo n.º 4
0
bool SavePersistedData(void)
{
	CharacterData *characterData;

	if(!IsPersistedDataCurrent())
	{
		WARNING_LOG("Persisted data does not match current version, clearing.");
		ClearPersistedData();
	}
	
	if(sizeof(CharacterData) > PERSIST_DATA_MAX_LENGTH )
	{
		ERROR_LOG("CharacterData is too big to save (%d).", sizeof(CharacterData));
		return false;
	}

	if(GetSizeOfItemsOwned() > PERSIST_DATA_MAX_LENGTH )
	{
		ERROR_LOG("Item data is too big to save (%d).", GetSizeOfItemsOwned());
		return false;
	}

	ProfileLogStart("SavePersistedData");
	INFO_LOG("Saving persisted data.");
	DEBUG_VERBOSE_LOG("Saving meta data");
	persist_write_bool(PERSISTED_IS_DATA_SAVED, true);
	persist_write_int(PERSISTED_CURRENT_DATA_VERSION, CURRENT_DATA_VERSION);
	persist_write_int(PERSISTED_MAX_KEY_USED, MAX_PERSISTED_KEY);
	
	DEBUG_VERBOSE_LOG("Saving character");
	characterData = GetCharacter();
	persist_write_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData));
	
	DEBUG_VERBOSE_LOG("Saving floor");
	persist_write_int(PERSISTED_CURRENT_FLOOR, GetCurrentFloor());
	
	DEBUG_VERBOSE_LOG("Saving item data");
	persist_write_data(PERSISTED_ITEM_DATA, GetItemsOwned(), GetSizeOfItemsOwned());
	
	DEBUG_VERBOSE_LOG("Saving stat points");
	persist_write_int(PERSISTED_STAT_POINTS_PURCHASED, GetStatPointsPurchased());

	DEBUG_VERBOSE_LOG("Saving option data");
	persist_write_bool(PERSISTED_VIBRATION, GetVibration());
	persist_write_bool(PERSISTED_FAST_MODE, GetFastMode());
	persist_write_bool(PERSISTED_WORKER_APP, GetWorkerApp());
	persist_write_bool(PERSISTED_WORKER_CAN_LAUNCH, GetWorkerCanLaunch());
	persist_write_bool(PERSISTED_USE_OLD_ASSETS, GetUseOldAssets());

	DEBUG_VERBOSE_LOG("Saving combat data");
	persist_write_bool(PERSISTED_IN_COMBAT, ClosingWhileInBattle());
	persist_write_int(PERSISTED_MONSTER_TYPE, GetMostRecentMonster());
	persist_write_int(PERSISTED_MONSTER_HEALTH, GetCurrentMonsterHealth());
	INFO_LOG("Done saving persisted data.");
	ProfileLogStop("SavePersistedData");
	
	return true;
}
Exemplo n.º 5
0
static void window_unload(Window *window) {
  unload_layers();

  persist_write_data(PERSIST_KEY_ID_POMODORO, &pomodoro.mode, sizeof(pomodoro.mode));
  persist_write_data(PERSIST_KEY_ID_POMODORO_CYCLE, &pomodoro.cycle, sizeof(pomodoro.cycle));
  persist_write_data(PERSIST_KEY_ID_POMODORO_CYCLE_NOW, &pomodoro.timer, sizeof(pomodoro.timer));

  tick_timer_service_unsubscribe();
}
Exemplo n.º 6
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 ");

}
Exemplo n.º 7
0
void save_clock() {
  time_t now = time(NULL);
#ifdef PBL_SDK_2
  struct tm *t = localtime(&now);
#else
  struct tm *t = gmtime(&now);
#endif
  persist_write_data(SW_STORE, &reg, sizeof(reg));
  persist_write_data(SW_LAP, &lap, sizeof(lap));
  persist_write_data(SW_STOP, t, sizeof(reg));
  persist_write_int(SW_BUTT, sw_butt);
}
Exemplo n.º 8
0
bool SavePersistedData(void)
{
	CharacterData *characterData;

	if(!IsPersistedDataCurrent())
	{
		WARNING_LOG("Persisted data does not match current version, clearing.");
		ClearPersistedData();
	}
	
	if(sizeof(CharacterData) > PERSIST_DATA_MAX_LENGTH )
	{
		ERROR_LOG("CharacterData is too big to save (%d).", sizeof(CharacterData));
		return false;
	}

	INFO_LOG("Saving persisted data.");
	persist_write_bool(PERSISTED_IS_DATA_SAVED, true);
	persist_write_int(PERSISTED_CURRENT_DATA_VERSION, CURRENT_DATA_VERSION);
	persist_write_int(PERSISTED_MAX_KEY_USED, MAX_PERSISTED_KEY);
	
	characterData = GetCharacter();
	persist_write_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData));
	
	persist_write_int(PERSISTED_CURRENT_FLOOR, GetCurrentFloor());
	
	uint8_t * itemsOwned = malloc(sizeof(uint8_t) * ITEM_TYPE_COUNT);
	GetItemsOwned(itemsOwned);
	persist_write_data(PERSISTED_ITEM_DATA, itemsOwned, sizeof(itemsOwned));
	free(itemsOwned);
	
	persist_write_int(PERSISTED_STAT_POINTS_PURCHASED, GetStatPointsPurchased());

	persist_write_bool(PERSISTED_VIBRATION, GetVibration());
	persist_write_bool(PERSISTED_FAST_MODE, GetFastMode());
	persist_write_bool(PERSISTED_EASY_MODE, GetEasyMode());

	persist_write_bool(PERSISTED_IN_COMBAT, ClosingWhileInBattle());
	
	persist_write_data(PERSISTED_MONSTER_TYPE, GetCurMonster(), sizeof(MonsterInfo));
	
	CardSave saves[NB_TYPE_CARDS];
	GetCardSaves(saves);
	persist_write_data(PERSISTED_CARD_DECK, saves, sizeof(saves));
	
	persist_write_int(PERSISTED_ENTRIES_SIZE, GetEntriesSize());
	
	return true;
}
Exemplo n.º 9
0
void main_save_data() {
  data_loaded_from_watch = true;
  persist_write_int(STORAGE_KEY_VERSION, CURRENT_STORAGE_VERSION);
  data_timestamp=time(NULL);
  persist_write_int(STORAGE_KEY_TIMESTAMP, data_timestamp);
  if (timer.Active) {
    persist_write_data(STORAGE_KEY_TIMER, &timer, sizeof(Timer));
  } else {
    persist_delete(STORAGE_KEY_TIMER);
  }
  persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(Settings));
  jobs_list_save(STORAGE_KEY_FIRST_JOB); 
  send_settings_to_phone();
  settings_menu_hide();
}
static void menuDestroy() {
    
    persist_write_data(NOTIFICATIONS_KEY, &Notifications, sizeof(Notifications));
    
    basicMenuModelDestroy(s_menuModel);
    s_menuModel = NULL;
}
Exemplo n.º 11
0
void Weather_deinit() {
  // save weather data to persistent storage
  persist_write_data(WEATHERINFO_PERSIST_KEY, &Weather_weatherInfo, sizeof(WeatherInfo));
  
  // free memory
  gdraw_command_image_destroy(Weather_currentWeatherIcon);
}
Exemplo n.º 12
0
static void saveTodayData() {
    int currentDay = getCurrentDayNumber();
    APP_LOG(APP_LOG_LEVEL_INFO, "Current Day: %d", currentDay);
	persist_write_data(currentDay, &today, sizeof(today));
    weekData[0] = today;
	//saveDateDataToStorage(currentDay, &today, sizeof(today));
}
Exemplo n.º 13
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);
    }
}
Exemplo n.º 14
0
static void write_blk_buf_to_persist(){
  /* the persist_read_int(I_BLK_PERSIST_KEY) is NOT a count, it is the current index
  * but 1-indexced, so 1 is the first block and zero is the empty state */

  if(persist_read_int(I_BLK_PERSIST_KEY) < N_BLK_PERSIST){
    // set the index of the current block
    persist_write_int(I_BLK_PERSIST_KEY,persist_read_int(I_BLK_PERSIST_KEY)+1);
    persist_write_data(persist_read_int(I_BLK_PERSIST_KEY),
                       blk_buf,((SIZE_SUMM*N_SUMM_BLK)+SIZE_BLK_HEAD));
  }

  if(bluetooth_connection_service_peek()){
    persist_write_int(WORKER_START_FORE_APP_REASON_PERSIST_KEY,
      WFAWR_PUSH_ALL_DATA_TO_SERVER);
      summ_since_trans_server = 0; // once try to go to server, reset
      worker_launch_app();
  } else if(persist_read_int(I_BLK_PERSIST_KEY) >= (N_BLK_PERSIST-1) ){
    // if the I_BLK_PERSIST_KEY is greater than 90% of storage, then prompt
    // that need to connect the phone
    persist_write_int(WORKER_START_FORE_APP_REASON_PERSIST_KEY,
      WFAWR_MEMORY_LOW_REMINDER);
    worker_launch_app();
  }
  // else if(){
  //   // reset the counter for consecutive summaries
  //   persist_write_int(WORKER_START_FORE_APP_REASON_PERSIST_KEY,
  //     WFAWR_WEAR_REMINDER);
  //   worker_launch_app();
  // }

}
Exemplo n.º 15
0
/*
 * Save the chart data structure
 */
static void save_chart_data() {
  LOG_DEBUG("save_chart_data (%d)", sizeof(chart_data));
  int written = persist_write_data(PERSIST_CHART_KEY, &chart_data, sizeof(chart_data));
  if (written != sizeof(chart_data)) {
    LOG_ERROR("save_chart_data error (%d)", written);
  }
}
Exemplo n.º 16
0
static void message_handler(DictionaryIterator *received, void *context) {
    bool refresh_window = 0;
    Tuple *tuple_show_date         = dict_find(received, MESSAGE_KEY_ShowDate);
    Tuple *tuple_show_battery      = dict_find(received, MESSAGE_KEY_ShowBattery);
    Tuple *tuple_use_bold_font     = dict_find(received, MESSAGE_KEY_UseBoldFont);
    Tuple *tuple_use_larger_font   = dict_find(received, MESSAGE_KEY_UseLargerFont);

    if (tuple_show_date) {
        refresh_window = 1;
        settings.show_date = (bool)tuple_show_date->value->int32;
    }
    if (tuple_show_battery) {
        refresh_window = 1;
        settings.show_battery = (bool)tuple_show_battery->value->int32;
    }
    if (tuple_use_bold_font) {
        refresh_window = 1;
        settings.use_bold_font = (bool)tuple_use_bold_font->value->int32;
    }
    if (tuple_use_larger_font) {
        refresh_window = 1;
        settings.use_larger_font = (bool)tuple_use_larger_font->value->int32;
    }

    persist_write_data(SETTINGS_KEY, &settings, sizeof(settings));

    if (refresh_window) {
        main_window_destroy();
        main_window_create();
    }
}
Exemplo n.º 17
0
void storage_store(){
	APP_LOG(APP_LOG_LEVEL_INFO,"storage_store()");
	APP_LOG(APP_LOG_LEVEL_INFO,"max_cell_size: %d timer_size: %d laps_size: %d clock_size: %d",PERSIST_DATA_MAX_LENGTH,sizeof(Timer),sizeof(Laps),sizeof(Clock));
	
	int result;
	uint8_t c=timers_count();
	
	result=persist_write_int(STORAGE_KEY_VERSION,STORAGE_VERSION);
	if(result<0){
		APP_LOG(APP_LOG_LEVEL_ERROR,"write error count %d in storage %d #%d",c,STORAGE_KEY_COUNT,result);  
		return;
	}
	
	result=persist_write_int(STORAGE_KEY_COUNT,c);
	if(result<0){
		APP_LOG(APP_LOG_LEVEL_ERROR,"write error count %d in storage %d #%d",count_total(count),STORAGE_KEY_COUNT,result); 
		return;
	}
	APP_LOG(APP_LOG_LEVEL_INFO,"timer count %d",count_total(count));
	
	Timer* timer;
	for(uint8_t i=0;i<c;i++){
		timer=timers_get(i);
		result=persist_write_data(STORAGE_KEY_DATA+i,timer,sizeof(Timer));
		if(result<0){
			APP_LOG(APP_LOG_LEVEL_ERROR,"write error timer %d in storage %d #%d",i,STORAGE_KEY_DATA+i,result); 
			continue;
		}
		APP_LOG(APP_LOG_LEVEL_INFO,"stored timer %d",i);
	}
	APP_LOG(APP_LOG_LEVEL_INFO,"stored");
}
Exemplo n.º 18
0
/**
 * Function that saves the presets into persistent storage.
 */
void presets_save(void){
	int block = 0;
	uint8_t num_presets = presets_get_count();
	if (num_presets == 0){
		while (persist_exists(STORAGE_PRESET_START + block)){
			persist_delete(STORAGE_PRESET_START + block);
			block++;
		}
		return;
	}
	for (int i = 0; i < num_presets; i+= PRESET_BLOCK_SIZE){
		PresetBlock *presetBlock = malloc(sizeof(PresetBlock));
		presetBlock->count = num_presets;
		presetBlock->time = time(NULL);
		for (int j = 0; j < PRESET_BLOCK_SIZE; j++){
			if (i+j >= num_presets)
				break;
			presetBlock->presets[j] = *presets_get(i+j);
		}
		persist_write_data(STORAGE_PRESET_START+block, presetBlock, sizeof(PresetBlock));
		free(presetBlock);
		block++;
	}
	return;
}
Exemplo n.º 19
0
/*
 * Save the config data structure
 */
void save_preset_data() {
  LOG_DEBUG("save_preset_data (%d)", sizeof(preset_data));
  int written = persist_write_data(PERSIST_PRESET_KEY, &preset_data, sizeof(preset_data));
  if (written != sizeof(preset_data)) {
    LOG_ERROR("save_preset_data error (%d)", written);
  }
}
Exemplo n.º 20
0
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  // update and save
  slot_options[(s_screen * 2) + s_slot] = (uint8_t) s_item;
  persist_write_data(SLOT_KEY, slot_options, sizeof(slot_options));
  window_stack_remove(s_main_window, true);
  slots_show(s_screen);
}
Exemplo n.º 21
0
void Settings_saveToStorage() {
  // ensure that the weather disabled setting is accurate before saving it
  Settings_updateDynamicSettings();

  // save settings to compressed structure and to persistent storage
  StoredSettings storedSettings;
  // if previous version settings are used than only first part of settings would be overwrited
  // all the other fields will left filled with zeroes
  storedSettings.timeColor = globalSettings.timeColor;
  storedSettings.timeBgColor = globalSettings.timeBgColor;
  storedSettings.sidebarColor = globalSettings.sidebarColor;
  storedSettings.sidebarTextColor = globalSettings.sidebarTextColor;
  storedSettings.languageId = globalSettings.languageId;
  storedSettings.showLeadingZero = globalSettings.showLeadingZero;
  storedSettings.clockFontId = globalSettings.clockFontId;
  storedSettings.btVibe = globalSettings.btVibe;
  storedSettings.hourlyVibe = globalSettings.hourlyVibe;
  storedSettings.widgets[0] = globalSettings.widgets[0];
  storedSettings.widgets[1] = globalSettings.widgets[1];
  storedSettings.widgets[2] = globalSettings.widgets[2];
  storedSettings.sidebarOnLeft = globalSettings.sidebarOnLeft;
  storedSettings.useLargeFonts = globalSettings.useLargeFonts;
  storedSettings.useMetric = globalSettings.useMetric;
  storedSettings.showBatteryPct = globalSettings.showBatteryPct;
  storedSettings.disableAutobattery = globalSettings.disableAutobattery;
  storedSettings.healthUseDistance = globalSettings.healthUseDistance;
  storedSettings.healthUseRestfulSleep = globalSettings.healthUseRestfulSleep;
  storedSettings.decimalSeparator = globalSettings.decimalSeparator;
  memcpy(storedSettings.altclockName, globalSettings.altclockName, 8);
  storedSettings.altclockOffset = globalSettings.altclockOffset;
  storedSettings.activateDisconnectIcon = globalSettings.activateDisconnectIcon;

  persist_write_data(SETTING_VERSION6_AND_HIGHER, &storedSettings, sizeof(StoredSettings));
  persist_write_int(SETTINGS_VERSION_KEY, CURRENT_SETTINGS_VERSION);
}
Exemplo n.º 22
0
void settings_save(void) {
  int res = persist_write_data(PERSIST_SETTINGS, &_settings, sizeof(_settings));
  if (res < 0) {
    LOG("Settings load failed: %d", res);
  }
  persist_write_int(PERSIST_SETTINGS_VERSION, SETTINGS_VERSION_CURRENT);
}
Exemplo n.º 23
0
void save_charge_log(ChargeLog* charge_log)
{
  int32_t log_count = 0;
  int32_t log_index = 0;
  
  if (persist_exists(PERSIST_KEY_LOG_COUNT)) {
    log_count = persist_read_int(PERSIST_KEY_LOG_COUNT);
  }
      
  if (persist_exists(PERSIST_KEY_LOG_INDEX)) {
    log_index = persist_read_int(PERSIST_KEY_LOG_INDEX);
  }
  
  log_count++;
  
  uint32_t key_log = PERSIST_KEY_LOG_BASE + (log_index + log_count - 1) % MAX_LOG_COUNT;
  
  if (log_count > MAX_LOG_COUNT) {
    log_count--;
    log_index++;
  }
  
  persist_write_int(PERSIST_KEY_LOG_COUNT, log_count);
  persist_write_int(PERSIST_KEY_LOG_INDEX, log_index);
  persist_write_data(key_log, charge_log, sizeof(*charge_log));
  
  if (launch_reason() != APP_LAUNCH_WAKEUP) {
    layer_mark_dirty(s_graph_layer);
  }
}
Exemplo n.º 24
0
void sustenance_storage_write_sustenance(struct Sustenance *sustenance) {
	int next_id = (sustenance_first_pkey + sustenance_storage_get_sustenance_count());
	sustenance_storage_update_sustenance_count();

	int bytesWritten = persist_write_data(next_id, sustenance, sizeof(struct Sustenance));
	int expectedBytesWritten = sizeof(struct Sustenance);
	APP_LOG(APP_LOG_LEVEL_DEBUG, "STORAGE. WRITE SUSTENANCE. PKEY: %d. Expected bytes written: %d. Bytes written: %d", next_id, expectedBytesWritten, bytesWritten);
	APP_LOG(APP_LOG_LEVEL_DEBUG, "STORAGE. WRITE SUSTENANCE. Type: %d. Substance: %d. Amount: %d", sustenance->type, sustenance->substance, sustenance->amount);
}
Exemplo n.º 25
0
void jobs_list_save(uint8_t first_key) {
  Job_ptr* job_ptr = first_job_ptr;
  while (job_ptr) {
    persist_write_data(first_key++, job_ptr->Job, sizeof(Job));
    job_ptr=job_ptr->Next_ptr;
  }
  // if we've delete a job then need to delete the saved version or it will come back!
  persist_delete(first_key);
}
Exemplo n.º 26
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);
}
Exemplo n.º 27
0
void bgpicker_updateLocation(LocationInfo loc) {
  bgpicker_location = loc;

  APP_LOG(APP_LOG_LEVEL_DEBUG, "Calculating with location: Lat: %d, Lng: %d, TZ: %d ",
          (int)(loc.lat*100),
          (int)(loc.lng*100),
          (int)(loc.tzOffset*100));

  // determine what day it is, since we'll need this
  time_t rawTime;
  struct tm * timeInfo;
  time(&rawTime);
  timeInfo = localtime(&rawTime);

  // get the sunrise/sunset data
  float sunRiseTime, sunSetTime;
  int sunRiseMin, sunSetMin;


  APP_LOG(APP_LOG_LEVEL_DEBUG, "Params 1: Year: %d, Month: %d, Day: %d, Z: %d",
          (int)timeInfo->tm_year,
          (int)timeInfo->tm_mon,
          (int)timeInfo->tm_mday,
          (int)ZENITH_OFFICIAL);

  sunRiseTime = calcSunRise(timeInfo->tm_year,
                            timeInfo->tm_mon + 1,
                            timeInfo->tm_mday,
                            loc.lat,
                            loc.lng,
                            ZENITH_OFFICIAL);
  sunSetTime  =  calcSunSet(timeInfo->tm_year,
                            timeInfo->tm_mon + 1,
                            timeInfo->tm_mday,
                            loc.lat,
                            loc.lng,
                            ZENITH_OFFICIAL);

  APP_LOG(APP_LOG_LEVEL_DEBUG, "Sunrise Time Initial R: %d, S: %d", (int)(sunRiseTime*100), (int)(sunSetTime*100));

  sunRiseTime = adjustTimezone(sunRiseTime, loc.tzOffset);
  sunSetTime = adjustTimezone(sunSetTime, loc.tzOffset);

  // for some reason, we have to add/subtract 12 hours (720 minutes)
  sunRiseMin = (int)(sunRiseTime * 60) - 720;
  sunSetMin = (int)(sunSetTime * 60) + 720;

  APP_LOG(APP_LOG_LEVEL_DEBUG, "Sunrise Time Initial R: %d, S: %d", (int)(sunRiseTime*100), (int)(sunSetTime*100));

  APP_LOG(APP_LOG_LEVEL_DEBUG, "Sunrise recalculated! R: %d, S: %d", sunRiseMin, sunSetMin);
  bgpicker_setSunriseSunset(sunRiseMin, sunSetMin);

  // save the new location data to persistent storage
  persist_write_data(BGPICKER_LOC_KEY, &loc, sizeof(LocationInfo));
}
Exemplo n.º 28
0
static void history_save() {
  persist_write_int(MESSAGE_KEY_batches, current_history_batch);
  persist_write_int(MESSAGE_KEY_avgMood, average_mood);
  // APP_LOG(APP_LOG_LEVEL_DEBUG, "Writing %d history batches to persistent storage", current_history_batch+1);
  for (int i=0; i<=current_history_batch; i++) {
    // int result = persist_write_data(FIRST_HISTORY_BATCH+i, &history[i], sizeof(history[i]));
    // APP_LOG(APP_LOG_LEVEL_DEBUG, "Persisted history batch %d, %d bytes, result %d", i, (int) sizeof(history[i]), result);
    persist_write_data(FIRST_HISTORY_BATCH+i, &history[i], sizeof(history[i]));
  }
  selected = (Selected) {current_history_batch, history[current_history_batch].last_event};
}
Exemplo n.º 29
0
void sustenance_storage_update_sustenance(int id, struct Sustenance *sustenance) {
	int next_id = sustenance_first_pkey + id;
	if (persist_exists(next_id)) {
		bool existed = persist_delete(next_id);
		APP_LOG(APP_LOG_LEVEL_DEBUG, "STORAGE. UPDATE SUSTENANCE. DELETED EXISTING KEY. EXISTED: %d", existed);
	}

	int bytesWritten = persist_write_data(next_id, sustenance, sizeof(struct Sustenance));
	int expectedBytesWritten = sizeof(struct Sustenance);
	APP_LOG(APP_LOG_LEVEL_DEBUG, "STORAGE. UPDATE SUSTENANCE. PKEY: %d. Expected bytes written: %d. Bytes written: %d", next_id, expectedBytesWritten, bytesWritten);
	APP_LOG(APP_LOG_LEVEL_DEBUG, "STORAGE. UPDATE SUSTENANCE. Type: %d. Substance: %d. Amount: %d", sustenance->type, sustenance->substance, sustenance->amount);
}
Exemplo n.º 30
0
static void select_click_handler(struct MenuLayer *menu_layer, MenuIndex *cell_index, void *context) {
  int n = (int)cell_index->row;

  if (n == SETTINGS_CHECKBOX_NUM_ROWS) {
    persist_write_data(PKEY_SELECTION, MenuSelection, sizeof(MenuSelection));

    const bool animated = true;
    window_stack_pop(animated);
  } else {
    MenuSelection[n] = !MenuSelection[n];
    menu_layer_reload_data(menu_layer);
  }
}