Loading...
Searching...
No Matches
settings.h
Go to the documentation of this file.
1
9#pragma once
10#include <pebble.h>
11
16
40
51
55typedef struct
56{
58 const uint32_t *message_key;
60 uint16_t offset;
61 uint16_t size;
62 uint8_t enum_count;
63 uint32_t default_num;
64 const char *default_str;
68
85typedef struct SettingsSchema
86{
87 uint32_t key;
88 uint8_t version;
90 void *blob;
91 uint16_t blob_size;
93 uint8_t field_count;
94 bool (*migrate)(int stored_size);
95 const struct SettingsSchema *companion;
97
110#define SETTINGS_BLOB_SIZE(blob) \
111 (sizeof(blob) + 0 * sizeof(struct { \
112 _Static_assert(sizeof(blob) <= PERSIST_DATA_MAX_LENGTH, \
113 "settings struct is over 256 bytes, so move some fields into a companion schema"); \
114 char unused; \
115 }))
116
120typedef struct
121{
122 bool changed;
126
138void settings_init(const SettingsSchema *schema);
139
148bool settings_was_fresh(void);
149
155void settings_save(void);
156
163void settings_mark_restored(void);
164
171uint8_t settings_u8(SettingId id);
172
179const char *settings_str(SettingId id);
180
190void settings_set_u8(SettingId id, uint8_t value);
191
201
210uint32_t settings_serialized_size_max(void);
211
221bool settings_serialize(DictionaryIterator *iter);
222
234SettingsInbound settings_apply_inbox(DictionaryIterator *iter);
235
SettingsInbound settings_apply_inbox(DictionaryIterator *iter)
Apply any settings present in an inbox message to the active face.
Definition settings.c:525
uint32_t settings_serialized_size_max(void)
The most outbox bytes every field of the active face could ever take once written.
Definition settings.c:461
void settings_mark_restored(void)
Clears settings_was_fresh once a save or restore from the settings page has been saved.
Definition settings.c:383
uint8_t settings_u8(SettingId id)
Read a known uint8/bool setting by id.
Definition settings.c:392
bool settings_was_fresh(void)
Whether the watch booted with no saved settings, because storage was wiped by a fresh install or an u...
Definition settings.c:369
SettingId
Identity of a known (shared) setting, used for typed reads and indexing.
Definition settings.h:24
uint8_t settings_enum_count(SettingId id)
How many values an enum setting allows (its sanitize ceiling).
Definition settings.c:413
bool settings_serialize(DictionaryIterator *iter)
Write every field of the active face into an outbox iterator.
Definition settings.c:477
SettingType
How a setting encodes on the wire and how the sanitize pass clamps it.
Definition settings.h:45
const char * settings_str(SettingId id)
Read a known string setting by id.
Definition settings.c:398
void settings_save(void)
Persist the active face's structs under their keys (the whole chain).
Definition settings.c:374
void settings_init(const SettingsSchema *head)
Load a face's settings from their saved blobs, applying defaults first.
Definition settings.c:339
void settings_set_u8(SettingId id, uint8_t value)
Write a known uint8 or enum setting by id. In memory only, does not persist.
Definition settings.c:404
@ SETTING_TEMPERATURE_UNIT
Celsius or Fahrenheit.
Definition settings.h:25
@ SETTING_HOURLY_VIBE
Vibe pattern to fire on the hour.
Definition settings.h:35
@ SETTING_BLUETOOTH_VIBE_CONNECT
Vibe pattern to fire when the phone connects.
Definition settings.h:33
@ SETTING_COUNT
How many known settings there are.
Definition settings.h:38
@ SETTING_BATTERY_DISPLAY
What the battery readout shows.
Definition settings.h:36
@ SETTING_THEME
Which theme is active.
Definition settings.h:27
@ SETTING_QUIET_TIME_ICON
Whether the Quiet Time mark shows.
Definition settings.h:32
@ SETTING_TIME_FORMAT
Which TimeFormat the clock uses.
Definition settings.h:30
@ SETTING_BLUETOOTH_VIBE_DISCONNECT
Vibe pattern to fire when the phone drops.
Definition settings.h:34
@ SETTING_HEADER_FONT
Which font the panel header labels use, as an index into the face's header font table.
Definition settings.h:37
@ SETTING_BLUETOOTH_ICON
Whether the bluetooth icon shows.
Definition settings.h:31
@ SETTING_DISTANCE_UNIT
Km or miles on the standalone Distance panel.
Definition settings.h:29
@ SETTING_STEPS_MODE
Steps, miles, or km on the steps readout.
Definition settings.h:28
@ SETTING_DATE_FORMAT
The date line's format string.
Definition settings.h:26
@ SETTING_ENUM_U8
Sent as text holding the number, since Clay sends selects as strings.
Definition settings.h:47
@ SETTING_COLOR
Sent as a 0xRRGGBB number, stored as one opaque GColor byte.
Definition settings.h:49
@ SETTING_BOOL
Sent as a byte, 0 or 1. default_num holds the default.
Definition settings.h:46
@ SETTING_CSTRING
Sent as text, copied into a fixed buffer.
Definition settings.h:48
Blueprint for a single setting.
Definition settings.h:56
uint8_t enum_count
How many values are allowed, so the highest is one less, for SETTING_ENUM_U8 only.
Definition settings.h:62
uint16_t offset
Where this field sits in the owning face's struct.
Definition settings.h:60
const char * default_str
Default on a fresh install for CSTRING.
Definition settings.h:64
uint16_t size
Buffer size, for SETTING_CSTRING only.
Definition settings.h:61
bool affects_weather
A change asks for fresh weather, for the temperature unit.
Definition settings.h:66
bool affects_layout
A change re-renders the clock, for the date and time formats.
Definition settings.h:65
uint32_t default_num
Default on a fresh install for BOOL and ENUM_U8, and the 0xRRGGBB colour for COLOR.
Definition settings.h:63
const uint32_t * message_key
The MESSAGE_KEY_* this field rides on, filled in by the SDK at runtime.
Definition settings.h:58
SettingType type
Drives both the wire encoding and the cleanup pass.
Definition settings.h:59
SettingId id
Known id for typed reads. SETTING_COUNT or higher means face-only.
Definition settings.h:57
Carries what an inbound settings message changed, so the caller can react.
Definition settings.h:121
bool layout_changed
A date or time format changed, so re-render the clock.
Definition settings.h:123
bool weather_changed
The temperature unit changed, so ask for fresh weather.
Definition settings.h:124
bool changed
Any field was updated, so save and repaint.
Definition settings.h:122
A face's persistence identity.
Definition settings.h:86
uint8_t field_count
How many entries are in fields.
Definition settings.h:93
const SettingField * fields
The face's field table.
Definition settings.h:92
const struct SettingsSchema * companion
Next schema in the chain, or NULL.
Definition settings.h:95
uint8_t version
This face's current schema version.
Definition settings.h:88
uint16_t min_versioned_size
Smallest versioned blob accepted, the frozen v1 size.
Definition settings.h:89
void * blob
The face's settings struct, version byte first.
Definition settings.h:90
uint16_t blob_size
Size of that struct, best set with SETTINGS_BLOB_SIZE.
Definition settings.h:91
uint32_t key
Storage key for this face's blob.
Definition settings.h:87
bool(*) migrate(int stored_size)
Lifts an old blob from before versioning, true if handled. NULL when none.
Definition settings.h:94