Чтение и запись постоянных данных на Pebble

Я делаю очень простое приложение для отслеживания оценки поля стрельбы из лука для Pebble, и у меня возникают проблемы с хранением и получением целочисленных значений между сессиями. Процесс сохранения и извлечения работает нормально, но по какой-то странной причине извлекается только 1 значение, а затем заносится во вторую переменную, чтобы они оба были одинаковыми.

Вставка моего полного кода, включая запись в журнал отладки при попытке выяснить это. Все значения верны даже при выгрузке окна, но при получении значений при следующей загрузке окна, кажется, просто получается 1...?

/*  TODO
    - Show time bar along top of screen
*/

#include <pebble.h>

uint32_t keyTotal,keyTargets;
static Window *window;
static TextLayer *text_layer_SCORE,*text_layer_TARGETS,*text_layer_TOTAL,*text_layer_TITLE;
int score,targets,total;
char targetText[]="Targets: ";
char scoreText[]="Score: ";
char totalText[]="TOTAL: ";
char currentScore[]="Score: xxxx";
char currentTotal[]="TOTAL: xxxx";
char currentTargets[]="Targets: xxx";

static void logValues(char *string) {
  APP_LOG(APP_LOG_LEVEL_INFO, string);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "----- SCORE: %i", score);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "----- TOTAL: %i", total);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "----- TARGETS: %i", targets);
}

static void updateScore() {
  snprintf(currentScore,sizeof(currentScore),"%s %d",scoreText,score);
  text_layer_set_text(text_layer_SCORE, currentScore);

  logValues("----- AFTER UPDATE SCORE");
}

static void updateTotal() {
  snprintf(currentTotal,sizeof(currentTotal),"%s %d",totalText,total);
  text_layer_set_text(text_layer_TOTAL, currentTotal);

  logValues("----- UPDATE TOTAL");
}

static void updateTargets() {
  snprintf(currentTargets,sizeof(currentTargets),"%s %d",targetText,targets);
  text_layer_set_text(text_layer_TARGETS, currentTargets);

  logValues("----- AFTER UPDATE TARGETS");
}

static void updateAll() {
  updateTotal();
  updateTargets();
  updateScore();

  logValues("----- AFTER UPDATE ALL");
}

static void persistValues() {
  persist_write_int(keyTotal, total);
  persist_write_int(keyTargets, targets);

  logValues("----- AFTER PERSIST VALUES");
}

static void resetValues() {
  score = 0;
  total = 0;
  targets = 0;
  persist_write_int(keyTargets, 0);
  persist_write_int(keyTotal, 0);

  logValues("----- AFTER RESET VALUES");
}

static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  total = total + score;
  ++targets;
  updateAll();

  logValues("----- AFTER SELECT PRESSED");
}

static void up_click_handler(ClickRecognizerRef recognizer, void *context) {
  // text_layer_set_text(text_layer, "Up");
  score++;
  updateScore();

  logValues("----- AFTER UP PRESSED");
}

static void down_click_handler(ClickRecognizerRef recognizer, void *context) {
  // text_layer_set_text(text_layer, "Down");
  score--;
  updateScore();

  logValues("----- AFTER DOWN PRESSED");
}

static void up_long_click_handler(ClickRecognizerRef recognizer, void *context) {
  //Window *window = (Window *)context;
}

static void up_long_click_release_handler(ClickRecognizerRef recognizer, void *context) {
  //Window *window = (Window *)
  resetValues();
  updateAll();
}

static void click_config_provider(void *context) {
  window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
  window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
  window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
  window_long_click_subscribe(BUTTON_ID_UP, 3000, up_long_click_handler, up_long_click_release_handler);
}

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

  logValues("----- START OF WINDOW LOAD");

  score = 0;

  // Get previous total (if it exists)
  if(persist_exists(keyTotal)) {
    total = persist_read_int(keyTotal);
  } else {
    total = 0;
    //persist_write_int(keyTotal, total);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "----- PERSIST TOTAL NOT FOUND, SETTING: %i", total);
  }

  // Get previous targets (if it exists)
  if(persist_exists(keyTargets)) {
    targets = persist_read_int(keyTargets);
  } else {
    targets = 0;
    //persist_write_int(keyTargets, targets);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "----- PERSIST TARGETS NOT FOUND, SETTING: %i", targets);
  }

  APP_LOG(APP_LOG_LEVEL_DEBUG, "----- PERSIST END, TOTAL IS CURRENTLY: %i", total);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "----- PERSIST END, TOTAL IS CURRENTLY: %i", total);

  window_set_click_config_provider(window, (ClickConfigProvider) click_config_provider);

  text_layer_TITLE = text_layer_create(GRect(0, 0, bounds.size.w, bounds.size.h));
  text_layer_SCORE = text_layer_create(GRect(0, 40, bounds.size.w, 35));
  text_layer_TARGETS = text_layer_create(GRect(0, 80, bounds.size.w, 35));
  text_layer_TOTAL = text_layer_create(GRect(0,120, bounds.size.w, 50));

  text_layer_set_text(text_layer_TITLE, "ScoreTracker");

  text_layer_set_text(text_layer_SCORE, currentScore);
  text_layer_set_text(text_layer_TARGETS, currentTargets);
  text_layer_set_text(text_layer_TOTAL, currentTotal);

  updateAll();

  text_layer_set_text_color(text_layer_TOTAL, GColorWhite);
  text_layer_set_text_color(text_layer_TARGETS, GColorWhite);
  text_layer_set_text_color(text_layer_SCORE, GColorBlack);
  text_layer_set_background_color(text_layer_TITLE, GColorGreen);
  text_layer_set_background_color(text_layer_TOTAL, GColorBlack);
  text_layer_set_background_color(text_layer_SCORE, GColorLightGray);
  text_layer_set_background_color(text_layer_TARGETS, GColorBlue);
  text_layer_set_text_alignment(text_layer_TITLE, GTextAlignmentCenter);
  text_layer_set_text_alignment(text_layer_SCORE, GTextAlignmentLeft);
  text_layer_set_text_alignment(text_layer_TARGETS, GTextAlignmentLeft);
  text_layer_set_text_alignment(text_layer_TOTAL, GTextAlignmentCenter);

  // Fonts
  text_layer_set_font(text_layer_TITLE, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_font(text_layer_SCORE, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_font(text_layer_TARGETS, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_font(text_layer_TOTAL, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));

  layer_add_child(window_layer, text_layer_get_layer(text_layer_TITLE));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_SCORE));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_TARGETS));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_TOTAL));

  logValues("----- END OF WINDOW LOAD");
}

static void window_unload(Window *window) {
  text_layer_destroy(text_layer_SCORE);
  text_layer_destroy(text_layer_TARGETS);
  text_layer_destroy(text_layer_TOTAL);
  text_layer_destroy(text_layer_TITLE);
  persistValues();

  logValues("----- END OF WINDOW UNLOAD");
}

static void init(void) {
  window = window_create();
  window_set_click_config_provider(window, click_config_provider);

  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
  const bool animated = true;
  window_stack_push(window, animated);

  logValues("----- END OF INIT");
}

static void deinit(void) {
  window_destroy(window);
}

int main(void) {
  init();

  APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", window);

  app_event_loop();
  deinit();
}

Здесь выводится лог запуска кода выше, внесения некоторых изменений, выхода и перезагрузки приложения.

[INFO] ocess_manager.c:419: Heap Usage for App <ScoreTrack: Total Size <62480B> Used <628B> Still allocated <0B>
[INFO] button_click.c:19: ----- START OF WINDOW LOAD
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[DEBUG] button_click.c:126: ----- PERSIST TOTAL NOT FOUND, SETTING: 0
[DEBUG] button_click.c:135: ----- PERSIST TARGETS NOT FOUND, SETTING: 0
[DEBUG] button_click.c:138: ----- PERSIST END, TOTAL IS CURRENTLY: 0
[DEBUG] button_click.c:139: ----- PERSIST END, TARGETS IS CURRENTLY: 0
[INFO] button_click.c:19: ----- UPDATE TOTAL
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UPDATE TARGETS
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UPDATE ALL
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- END OF WINDOW LOAD
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- END OF INIT
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[DEBUG] button_click.c:213: Done initializing, pushed window: 0x20020c0c
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 1
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UP PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 1
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 2
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UP PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 2
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 3
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UP PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 3
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- AFTER UP PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[INFO] button_click.c:19: ----- UPDATE TOTAL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 4
[DEBUG] button_click.c:22: ----- TARGETS: 1
[INFO] button_click.c:19: ----- AFTER UPDATE TARGETS
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 4
[DEBUG] button_click.c:22: ----- TARGETS: 1
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 4
[DEBUG] button_click.c:22: ----- TARGETS: 1
[INFO] button_click.c:19: ----- AFTER UPDATE ALL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 4
[DEBUG] button_click.c:22: ----- TARGETS: 1
[INFO] button_click.c:19: ----- AFTER SELECT PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 4
[DEBUG] button_click.c:22: ----- TARGETS: 1
[INFO] button_click.c:19: ----- UPDATE TOTAL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 8
[DEBUG] button_click.c:22: ----- TARGETS: 2
[INFO] button_click.c:19: ----- AFTER UPDATE TARGETS
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 8
[DEBUG] button_click.c:22: ----- TARGETS: 2
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 8
[DEBUG] button_click.c:22: ----- TARGETS: 2
[INFO] button_click.c:19: ----- AFTER UPDATE ALL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 8
[DEBUG] button_click.c:22: ----- TARGETS: 2
[INFO] button_click.c:19: ----- AFTER SELECT PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 8
[DEBUG] button_click.c:22: ----- TARGETS: 2
[INFO] button_click.c:19: ----- UPDATE TOTAL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 12
[DEBUG] button_click.c:22: ----- TARGETS: 3
[INFO] button_click.c:19: ----- AFTER UPDATE TARGETS
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 12
[DEBUG] button_click.c:22: ----- TARGETS: 3
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 12
[DEBUG] button_click.c:22: ----- TARGETS: 3
[INFO] button_click.c:19: ----- AFTER UPDATE ALL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 12
[DEBUG] button_click.c:22: ----- TARGETS: 3
[INFO] button_click.c:19: ----- AFTER SELECT PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 12
[DEBUG] button_click.c:22: ----- TARGETS: 3
[INFO] button_click.c:19: ----- UPDATE TOTAL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 16
[DEBUG] button_click.c:22: ----- TARGETS: 4
[INFO] button_click.c:19: ----- AFTER UPDATE TARGETS
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 16
[DEBUG] button_click.c:22: ----- TARGETS: 4
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 16
[DEBUG] button_click.c:22: ----- TARGETS: 4
[INFO] button_click.c:19: ----- AFTER UPDATE ALL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 16
[DEBUG] button_click.c:22: ----- TARGETS: 4
[INFO] button_click.c:19: ----- AFTER SELECT PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 16
[DEBUG] button_click.c:22: ----- TARGETS: 4
[INFO] button_click.c:19: ----- UPDATE TOTAL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 20
[DEBUG] button_click.c:22: ----- TARGETS: 5
[INFO] button_click.c:19: ----- AFTER UPDATE TARGETS
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 20
[DEBUG] button_click.c:22: ----- TARGETS: 5
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 20
[DEBUG] button_click.c:22: ----- TARGETS: 5
[INFO] button_click.c:19: ----- AFTER UPDATE ALL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 20
[DEBUG] button_click.c:22: ----- TARGETS: 5
[INFO] button_click.c:19: ----- AFTER SELECT PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 20
[DEBUG] button_click.c:22: ----- TARGETS: 5
[INFO] button_click.c:19: ----- UPDATE TOTAL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 24
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- AFTER UPDATE TARGETS
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 24
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 24
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- AFTER UPDATE ALL
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 24
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- AFTER SELECT PRESSED
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 24
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- AFTER PERSIST VALUES
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 24
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- END OF WINDOW UNLOAD
[DEBUG] button_click.c:20: ----- SCORE: 4
[DEBUG] button_click.c:21: ----- TOTAL: 24
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] ocess_manager.c:419: Heap Usage for App <ScoreTrack: Total Size <62480B> Used <628B> Still allocated <0B>
[INFO] button_click.c:19: ----- START OF WINDOW LOAD
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 0
[DEBUG] button_click.c:22: ----- TARGETS: 0
[DEBUG] button_click.c:138: ----- PERSIST END, TOTAL IS CURRENTLY: 6
[DEBUG] button_click.c:139: ----- PERSIST END, TARGETS IS CURRENTLY: 6
[INFO] button_click.c:19: ----- UPDATE TOTAL
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 6
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- AFTER UPDATE TARGETS
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 6
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- AFTER UPDATE SCORE
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 6
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- AFTER UPDATE ALL
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 6
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- END OF WINDOW LOAD
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 6
[DEBUG] button_click.c:22: ----- TARGETS: 6
[INFO] button_click.c:19: ----- END OF INIT
[DEBUG] button_click.c:20: ----- SCORE: 0
[DEBUG] button_click.c:21: ----- TOTAL: 6
[DEBUG] button_click.c:22: ----- TARGETS: 6
[DEBUG] button_click.c:213: Done initializing, pushed window: 0x20020c0c

Вместо этого я пытался использовать структуры данных для сохранения и извлечения этих значений, но пока не могу понять, как это делается. Пример на сайте разработчиков Pebble недостаточно продуман, чтобы я мог заполнить пробелы. Все еще только хобби-программист для подобных вещей, так что, вероятно, есть целая куча основ, которые мне здесь просто не хватает. Любая помощь очень ценится!

1 ответ

Решение

Догадаться. Я неверно истолковал значение ключа как целое число, которое вы хотите сохранить в хранилище, а не как фактическое значение ключа для места, где оно хранится. Поэтому каждый раз, когда я сохранял и извлекал значения, которые он сохранял и извлекал из разных мест, в зависимости от того, какое значение было в то время.

Глядя на пример кода Persist Counter на следующей странице, мне помог https://developer.pebble.com/examples/

Соответствующий код сейчас

#define NUM_TOTAL_DEFAULT 0
#define NUM_TARGETS_DEFAULT 0
#define NUM_TOTAL_PKEY 1
#define NUM_TARGETS_PKEY 2

...

static void persistValues() {
  persist_write_int(NUM_TARGETS_PKEY, targets);
  persist_write_int(NUM_TOTAL_PKEY, total);
}

... 

static void init(void) {
  // SET PERSISTENT VALUES IF EXISTS
  total = persist_exists(NUM_TOTAL_PKEY) ? persist_read_int(NUM_TOTAL_PKEY) : NUM_TOTAL_DEFAULT;
  targets = persist_exists(NUM_TARGETS_PKEY) ? persist_read_int(NUM_TARGETS_PKEY) : NUM_TARGETS_DEFAULT;

...

}

static void deinit(void) {
  // SAVE VALUES IN TO PERSISTENT STORAGE
  persistValues();

  window_destroy(window);
}
Другие вопросы по тегам