本文整理汇总了C++中persist_exists函数的典型用法代码示例。如果您正苦于以下问题:C++ persist_exists函数的具体用法?C++ persist_exists怎么用?C++ persist_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了persist_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: settings_load
void settings_load(void) {
if (persist_exists(PERSIST_SETTINGS)) {
if (! persist_exists(PERSIST_SETTINGS_VERSION)) {
DEBUG("Migrating settings from 2.X to 3.X");
OldSettings old_settings;
int res = persist_read_data(PERSIST_SETTINGS, &old_settings, sizeof(old_settings));
if (res >= 0) {
migrate_settings_01(old_settings);
return;
}
}
else if (persist_read_int(PERSIST_SETTINGS_VERSION) == SETTINGS_VERSION_TINY) {
SettingsTiny settings_tiny;
int res = persist_read_data(PERSIST_SETTINGS, &settings_tiny, sizeof(settings_tiny));
if (res >= 0) {
migrate_settings_02(settings_tiny);
return;
}
}
int res = persist_read_data(PERSIST_SETTINGS, &_settings, sizeof(_settings));
if (res < 0) {
LOG("Settings load failed: %d", res);
}
}
}
示例2: show_charge_log
static void show_charge_log()
{
if (!persist_exists(PERSIST_KEY_LOG_COUNT) || !persist_exists(PERSIST_KEY_LOG_INDEX)) {
return;
}
int log_count = persist_read_int(PERSIST_KEY_LOG_COUNT);
int log_index = persist_read_int(PERSIST_KEY_LOG_INDEX);
if (log_count == 0) {
return;
}
time_t now = time(NULL);
for (int i = 0; i < log_count; ++i) {
uint32_t key_log = PERSIST_KEY_LOG_BASE + (log_index + i) % MAX_LOG_COUNT;
ChargeLog charge_log;
persist_read_data(key_log, &charge_log, sizeof(charge_log));
static char buff[] = "999 4294967296 %100";
snprintf(buff, sizeof(buff), "%d %u %d%%", i, (unsigned)difftime(now, charge_log.time), charge_log.charge_state.charge_percent);
APP_LOG(APP_LOG_LEVEL_DEBUG, buff);
}
}
示例3: init
/*
* 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
});
示例4: pause_click_handler
static void pause_click_handler(ClickRecognizerRef recognizer, void *context) {
int calib_stored = persist_exists(CALIB_PKEY) ? persist_read_int(CALIB_PKEY) : CALIB_DEFAULT;
if (calib_stored != 0 && calibrating == 0) {
pause++;
pause = pause % 2;
if (pause == 0) {
end_time = time(NULL);
double elapsed = difftime(end_time, start_time);
result = (int)floor(sum_x/elapsed);
display(text_layer_3, "Score: %d", result);
action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_play);
int calib_stored = persist_exists(CALIB_PKEY) ? persist_read_int(CALIB_PKEY) : CALIB_DEFAULT;
display(text_layer_4, "Calib: %d", calib_stored);
text_layer_set_text(text_layer_2, "");
if (result > 2*calib_stored) {
send(0, 1);
text_layer_set_text(text_layer_1, "YOU'RE DRUNK");
dialog_message_window_push();
}
else {
send(0, 0);
text_layer_set_text(text_layer_1, "YOU'RE FINE");
}
}
else {
sum_x = 0;
text_layer_set_text(text_layer_2, "RUNNING");
text_layer_set_text(text_layer_3, "");
action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_pause);
start_time = time(NULL);
}
}
}
示例5: save_charge_log
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);
}
}
示例6: loadPersistentValues
static void loadPersistentValues() {
backgroundBlack = persist_exists(PERSIST_KEY_BACKGROUND) ? persist_read_int(PERSIST_KEY_BACKGROUND) : DEFAULT_BACKGROUND;
showDay = persist_exists(PERSIST_KEY_SHOW_DAY) ? persist_read_int(PERSIST_KEY_SHOW_DAY) : DEFAULT_SHOWDAY;
APP_LOG(APP_LOG_LEVEL_DEBUG, "Loaded values from storage - background=%d, showDay=%d",
persist_exists(PERSIST_KEY_BACKGROUND) ? backgroundBlack : -1,
persist_exists(PERSIST_KEY_SHOW_DAY)? showDay : -1);
}
示例7: history_load
static void history_load() {
if (persist_exists(MESSAGE_KEY_batches)) {
current_history_batch = persist_read_int(MESSAGE_KEY_batches);
}
if (current_history_batch < 0) {
// APP_LOG(APP_LOG_LEVEL_DEBUG, "No history in persistent storage: %d", current_history_batch);
return;
}
// APP_LOG(APP_LOG_LEVEL_DEBUG, "Reading %d history batches from persistent storage", current_history_batch+1);
int total_bytes_read = 0;
for (int i=0; i<=current_history_batch; i++) {
if (persist_exists(FIRST_HISTORY_BATCH+i)) {
// int result = persist_read_data(FIRST_HISTORY_BATCH+i, &history[i], sizeof(history[i]));
// APP_LOG(APP_LOG_LEVEL_DEBUG, "Loaded history batch %d, %d bytes, %d events, result %d", i, (int) sizeof(history[i]), history[i].last_event+1, result);
persist_read_data(FIRST_HISTORY_BATCH+i, &history[i], sizeof(history[i]));
total_bytes_read += sizeof(history[i]);
}
else {
APP_LOG(APP_LOG_LEVEL_WARNING, "No history batch %d although current_history_batch %d indicates its existence!", i, current_history_batch);
}
}
start_time = (int) history[0].event_time[0];
selected = (Selected) {current_history_batch, history[current_history_batch].last_event};
events = current_history_batch * HISTORY_BATCH_SIZE + history[current_history_batch].last_event + 1;
if (persist_exists(MESSAGE_KEY_avgMood)) {
average_mood = persist_read_int(MESSAGE_KEY_avgMood);
}
APP_LOG(APP_LOG_LEVEL_DEBUG, "Total history: %d batches, %d events, %d bytes", current_history_batch+1, events, total_bytes_read);
}
示例8: main_init
// 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;
}
}
示例9: readConfig
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_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);
}
APP_LOG(APP_LOG_LEVEL_DEBUG, "Stored config (dateorder=%d, weekday=%d, lang=%d, stripedDigits=%d)",
USDate, showWeekday, curLang, stripedDigits);
}
示例10: window_load
static void window_load(Window *window) {
Layer *root_layer = window_get_root_layer(window);
if (persist_exists(PERSIST_KEY_ID_POMODORO)) {
persist_read_data(PERSIST_KEY_ID_POMODORO, &pomodoro, sizeof(pomodoro));
}
if (persist_exists(PERSIST_KEY_ID_POMODORO_CYCLE)) {
persist_read_data(PERSIST_KEY_ID_POMODORO_CYCLE, &pomodoro.cycle, sizeof(pomodoro.cycle));
}
if (persist_exists(PERSIST_KEY_ID_POMODORO_CYCLE_NOW)) {
persist_read_data(PERSIST_KEY_ID_POMODORO_CYCLE_NOW, &pomodoro.timer, sizeof(pomodoro.timer));
if (pomodoro.cycle <= pomodoro.timer) pomodoro.timer = -1;
}
tick_timer_service_subscribe(HOUR_UNIT | MINUTE_UNIT, tick_handler);
// LOAD RESOURCE
uint8_t resource_id = (uint8_t)RESOURCE_ID_HANNA_B;
for (uint8_t i = 0; i < bitmaps_length; ++i) {
bitmaps[i] = gbitmap_create_with_resource((uint8_t)(resource_id + i));
}
load_layers(root_layer);
}
示例11: tick_handler
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);
}
}
示例12: options_init
void options_init() {
if(persist_exists(OPTION_LARGE_FONT))
large_font = persist_read_bool(OPTION_LARGE_FONT);
if(persist_exists(OPTION_TASK_ACTIONS_POSITION))
task_actions_position = persist_read_int(OPTION_TASK_ACTIONS_POSITION);
LOG("lg font? %d", large_font);
LOG("act pos? %d", task_actions_position);
}
示例13: load_config
// Load existing config from persistent storage
void load_config() {
if (persist_exists(MESSAGE_KEY_INVERT)) {
config_invert = persist_read_bool(MESSAGE_KEY_INVERT);
}
if (persist_exists(MESSAGE_KEY_DATE_FORMAT)) {
config_date_format = persist_read_int(MESSAGE_KEY_DATE_FORMAT);
}
}
示例14: read_settings_from_memory
void read_settings_from_memory() {
if (persist_exists(KEY_SCALE_CHOICE))
scale = persist_read_int(KEY_SCALE_CHOICE);
if (persist_exists(KEY_CLOCK_FORMAT))
clock_format = persist_read_int(KEY_CLOCK_FORMAT);
if (persist_exists(KEY_DATE_FORMAT))
date_format = persist_read_int(KEY_DATE_FORMAT);
}
示例15: load_persistent_data
static void load_persistent_data(){
uint32_t data_from = persist_exists(DATE_SAVE) ? (uint32_t)persist_read_int(DATE_SAVE) : get_today();
if (data_from == get_today()){
rounds_done = persist_exists(COMPLETED_COUNT) ? persist_read_int(COMPLETED_COUNT) : 0;
rounds_canceled = persist_exists(CANCELED_COUNT) ? persist_read_int(CANCELED_COUNT) : 0;
}
}