Loading...
Searching...
No Matches
Settings

Loads, saves, and syncs a face's settings from its field table. More...

Files

file  src/c/pebble/system/settings/plugin_source.h
 The struct the framework keeps the weather, calendar, and stock source choices in, for a face built with a plugin define, and the checks that decide which of them it keeps.
file  src/c/pebble/system/settings/setting_values.h
 Named values for the multi-choice settings.
file  src/c/pebble/system/settings/settings.c
 The persist API implementation.
file  src/c/pebble/system/settings/settings.h
 The persist API. A per-face SettingField table drives versioned load and save, sanitizing, the typed reads, and the AppMessage round trip, so the shared code never names or hardcodes a single field.
file  src/c/pebble/system/settings/settings_catalog.h
 The shared catalog of known settings. A KNOWN_* macro per setting bakes in its neutral wire key, encoding, bounds, default, and side effects.
file  src/c/pebble/system/settings/settings_chain.h
 The walk over a face's settings schemas, and the checks a launch makes over them.

Data Structures

struct  PluginSourceSettings
 The saved choices, version byte first. More...
struct  SettingField
 Blueprint for a single setting. More...
struct  SettingsSchema
 A face's persistence identity. More...
struct  SettingsInbound
 Carries what an inbound settings message changed, so the caller can react. More...

Macros

#define PLUGIN_SOURCE_KEEPS_WEATHER   0
 1 when the watch keeps the weather source choice, for a face with PLUGIN_WEATHER and WEATHER_PROVIDER
#define PLUGIN_SOURCE_KEEPS_CALENDAR   0
 1 when the watch keeps the calendar source choice, for a face with PLUGIN_CALENDAR and CALENDAR_SOURCE
#define PLUGIN_SOURCE_KEEPS_STOCK   0
 1 when the watch keeps the stock source choice, for a face with PLUGIN_STOCKS and STOCK_PROVIDER
#define PLUGIN_SOURCE_KEEPS_ANY   (PLUGIN_SOURCE_KEEPS_WEATHER || PLUGIN_SOURCE_KEEPS_CALENDAR || PLUGIN_SOURCE_KEEPS_STOCK)
 The watch keeps at least one source choice, so the framework's schema joins the chain.
#define PLUGIN_SOURCE_WEATHER_LEN   12
 The size of the weather source buffer. weatherapi is the longest value the settings page saves, and its 10 characters plus its end leave one byte spare.
#define PLUGIN_SOURCE_CALENDAR_LEN   8
 The size of the calendar source buffer. plugin is the longest value the settings page saves, and its 6 characters plus its end leave one byte spare.
#define PLUGIN_SOURCE_STOCK_LEN   14
 The size of the stock source buffer. alphavantage is the longest value the settings page saves, and its 12 characters plus its end leave one byte spare.
#define PLUGIN_SOURCE_VERSION   2
 The schema's version, raised by one with each appended field.
#define PLUGIN_SOURCE_FIRST_SIZE   21
 The struct's size in its first release, which never changes.
#define PLUGIN_SOURCE_WEATHER_FIELD
 The field the framework keeps the weather source in, with a comma after it, or nothing when the watch keeps no weather choice.
#define PLUGIN_SOURCE_CALENDAR_FIELD
 The field the framework keeps the calendar source in, with a comma after it, or nothing when the watch keeps no calendar choice. It works as the weather one does.
#define PLUGIN_SOURCE_STOCK_FIELD
 The field the framework keeps the stock source in, with a comma after it, or nothing when the watch keeps no stock choice. It works as the weather one does.
#define PLUGIN_SOURCE_FIELDS   PLUGIN_SOURCE_WEATHER_FIELD PLUGIN_SOURCE_CALENDAR_FIELD PLUGIN_SOURCE_STOCK_FIELD
 The framework schema's whole field table, for inside its braces.
#define SETTINGS_PLUGIN_SOURCE_KEY   249
 The persist key the framework keeps the weather, calendar, and stock source choices on, so a face leaves it free.
#define SETTINGS_BLOB_SIZE(blob)
 The size of a settings struct, and a build that stops when the struct is too big to save. SETTINGS_BLOB uses it for a schema's blob_size.
#define SETTINGS_BLOB(settings, first)
 Sets a schema's settings struct, its size, and the size it first shipped at, for a schema's initializer.
#define SETTINGS_FIRST_SIZE_(first, settings)
 The first size for SETTINGS_BLOB, and a build that stops when it is written as more than one token, or is 0 or past the struct's size.
#define SETTINGS_COUNT(key)
 How many choices the settings page offers on a message key, worked out by the build.
#define SETTINGS_COUNT_CHECKED(key, table_count)
 The page's count on a message key, checked against the size of the face's own table.
#define SETTINGS_TEXT_FIELD(blob, member, bytes)
 A text entry's offset and size, with a build stop when the member is not that size.
#define SETTINGS_DEFAULT(key)
 The default the settings page opens with on a message key, worked out by the build.
#define KNOWN_TEMPERATURE_UNIT(off)
 Setting definition for Temperature Unit (Celsius or Fahrenheit).
#define KNOWN_DATE_FORMAT(blob, member)
 Setting definition for Date Format.
#define KNOWN_THEME(off, table_count)
 Setting definition for Theme.
#define KNOWN_STEPS_MODE(off)
 Setting definition for Steps Mode.
#define KNOWN_DISTANCE_UNIT(off)
 Setting definition for Distance Unit.
#define KNOWN_TIME_FORMAT(off)
 Setting definition for Time Format.
#define KNOWN_BLUETOOTH_ICON(off)
 Setting definition for Bluetooth Icon.
#define KNOWN_QUIET_TIME_ICON(off)
 Setting definition for the Quiet Time Icon.
#define KNOWN_BLUETOOTH_VIBE_CONNECT(off)
 Setting definition for Bluetooth Vibe Connect.
#define KNOWN_BLUETOOTH_VIBE_DISCONNECT(off)
 Setting definition for Bluetooth Vibe Disconnect.
#define KNOWN_HOURLY_VIBE(off)
 Setting definition for the Hourly Vibration (a VibeChoice fired at the top of each hour).
#define KNOWN_BATTERY_DISPLAY(off)
 Setting definition for Battery Display (icon + percent / icon / percent).
#define KNOWN_WIND_UNIT(off)
 Setting definition for Wind Unit, the WindUnit a wind speed reads out in.
#define KNOWN_GOAL_STEPS(off)
 Setting definition for the Step Goal, an index into goals_steps.
#define KNOWN_GOAL_DISTANCE(off)
 Setting definition for the Distance Goal, an index into goals_distance_m.
#define KNOWN_GOAL_CALORIES(off)
 Setting definition for the Calorie Goal, an index into goals_calories.
#define KNOWN_GOAL_ACTIVE(off)
 Setting definition for the Activity Goal, an index into goals_active_min.
#define KNOWN_GOAL_SLEEP(off)
 Setting definition for the Sleep Goal, an index into goals_sleep_min.
#define KNOWN_GOAL_HR(off)
 Setting definition for the Heart Rate Limit, an index into goals_hr_limit.
#define KNOWN_GOAL_VIBE(blob, member)
 Setting definition for the Goal Met Vibration, the pick vibe_goal plays.
#define KNOWN_GOAL_VIBE_CUSTOM(blob, member)
 Setting definition for the Custom Vibration Pattern, which vibe_goal plays when the pick is Custom.
#define SETTINGS_CHAIN_EACH(schema, head, tail)
 Walks the face's schemas and then the framework's, for a for loop's header.

Typedefs

typedef struct SettingsSchema SettingsSchema
 A face's persistence identity.

Enumerations

enum  TimeFormat {
  TIME_FORMAT_SYSTEM = 0 , TIME_FORMAT_12H = 1 , TIME_FORMAT_24H = 2 , TIME_FORMAT_BEATS = 3 ,
  TIME_FORMAT_12H_NO_LEAD = 4 , TIME_FORMAT_COUNT
}
 SETTING_TIME_FORMAT choices. More...
enum  StepsMode { STEPS_MODE_STEPS = 0 , STEPS_MODE_MILES = 1 , STEPS_MODE_KM = 2 , STEPS_MODE_COUNT }
 SETTING_STEPS_MODE choices. More...
enum  DistanceUnit { DISTANCE_UNIT_KM = 0 , DISTANCE_UNIT_MILES = 1 , DISTANCE_UNIT_COUNT }
 SETTING_DISTANCE_UNIT choices. A distance readout's own unit, separate from the steps readout's STEPS_MODE. More...
enum  VibeChoice {
  VIBE_NONE = 0 , VIBE_SHORT = 1 , VIBE_LONG = 2 , VIBE_DOUBLE = 3 ,
  VIBE_COUNT
}
 Bluetooth connect/disconnect vibe pattern choices. More...
enum  BatteryDisplay { BATTERY_DISPLAY_BOTH = 0 , BATTERY_DISPLAY_ICON = 1 , BATTERY_DISPLAY_PERCENT = 2 , BATTERY_DISPLAY_COUNT }
 SETTING_BATTERY_DISPLAY choices: what the battery readout shows. More...
enum  SettingId {
  SETTING_TEMPERATURE_UNIT , SETTING_DATE_FORMAT , SETTING_THEME , SETTING_STEPS_MODE ,
  SETTING_DISTANCE_UNIT , SETTING_TIME_FORMAT , SETTING_BLUETOOTH_ICON , SETTING_QUIET_TIME_ICON ,
  SETTING_BLUETOOTH_VIBE_CONNECT , SETTING_BLUETOOTH_VIBE_DISCONNECT , SETTING_HOURLY_VIBE , SETTING_BATTERY_DISPLAY ,
  SETTING_WIND_UNIT , SETTING_GOAL_STEPS , SETTING_GOAL_DISTANCE , SETTING_GOAL_CALORIES ,
  SETTING_GOAL_ACTIVE , SETTING_GOAL_SLEEP , SETTING_GOAL_HR , SETTING_GOAL_VIBE ,
  SETTING_GOAL_VIBE_CUSTOM , SETTING_COUNT
}
 Identity of a known (shared) setting, used for typed reads and indexing. More...
enum  SettingType { SETTING_BOOL , SETTING_ENUM_U8 , SETTING_CSTRING , SETTING_COLOR }
 How a setting encodes on the wire and how the sanitize pass clamps it. More...

Functions

static bool plugin_source_write_needed (const PluginSourceSettings *now, const PluginSourceSettings *on_flash, bool on_flash_known)
 Whether a save has to write the choices to flash.
void settings_init (const SettingsSchema *schema)
 Load a face's settings from their saved blobs, applying defaults first.
bool settings_was_fresh (void)
 Whether the watch booted with no saved settings, because storage was wiped by a fresh install or an update. Lets the phone know it should push its own config back rather than trust the watch's defaults.
void settings_save (void)
 Persist the active face's structs under their keys (the whole chain).
void settings_mark_restored (void)
 Clears settings_was_fresh once a save or restore from the settings page has been saved.
uint8_t settings_u8 (SettingId id)
 Read a known uint8/bool setting by id.
const char * settings_str (SettingId id)
 Read a known string setting by id.
void settings_set_u8 (SettingId id, uint8_t value)
 Write a known uint8 or enum setting by id. In memory only, does not persist.
uint8_t settings_enum_count (SettingId id)
 How many values an enum setting allows (its sanitize ceiling).
uint32_t settings_serialized_size_max (void)
 The most outbox bytes every field of the active face could ever take once written.
bool settings_serialize (DictionaryIterator *iter)
 Write every field of the active face into an outbox iterator.
SettingsInbound settings_apply_inbox (DictionaryIterator *iter)
 Apply any settings present in an inbox message to the active face.
static const SettingsSchema * settings_chain_first (const SettingsSchema *head, const SettingsSchema *tail)
 Where the walk starts.
static const SettingsSchema * settings_chain_next (const SettingsSchema *schema, const SettingsSchema *tail)
 The schema after this one in the walk.
static bool settings_chain_has_field (const SettingsSchema *head, const uint32_t *message_key)
 Whether a schema in the face's own chain has a field on a message key.
static bool settings_chain_has_key (const SettingsSchema *head, uint32_t key)
 Whether a schema in the face's own chain is saved under a persist key.

Detailed Description

Loads, saves, and syncs a face's settings from its field table.

A face hands it a field table, and it handles persist and the phone sync without naming any single setting itself.

Macro Definition Documentation

◆ KNOWN_BATTERY_DISPLAY

#define KNOWN_BATTERY_DISPLAY ( off)
Value:
{ .id = SETTING_BATTERY_DISPLAY, .message_key = &MESSAGE_KEY_BATTERY_DISPLAY, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = BATTERY_DISPLAY_COUNT, \
.default_num = SETTINGS_DEFAULT(BATTERY_DISPLAY) }
#define SETTINGS_DEFAULT(key)
The default the settings page opens with on a message key, worked out by the build.
Definition settings_catalog.h:117
@ SETTING_BATTERY_DISPLAY
What the battery readout shows.
Definition settings.h:36
@ SETTING_ENUM_U8
A choice, taken as an int or as digits and sent back as text holding the number.
Definition settings.h:55
@ BATTERY_DISPLAY_COUNT
How many choices this setting has.
Definition setting_values.h:78

Setting definition for Battery Display (icon + percent / icon / percent).

Parameters
offOffset into the face's settings struct.

◆ KNOWN_BLUETOOTH_ICON

#define KNOWN_BLUETOOTH_ICON ( off)
Value:
{ .id = SETTING_BLUETOOTH_ICON, .message_key = &MESSAGE_KEY_CONNECTION_BLUETOOTH_ICON, \
.type = SETTING_BOOL, .offset = (off), .default_num = SETTINGS_DEFAULT(CONNECTION_BLUETOOTH_ICON) }
@ SETTING_BLUETOOTH_ICON
Whether the bluetooth icon shows.
Definition settings.h:31
@ SETTING_BOOL
0 or 1, taken as an int or as digits and sent back as a byte. default_num holds the default
Definition settings.h:54

Setting definition for Bluetooth Icon.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_BLUETOOTH_VIBE_CONNECT

#define KNOWN_BLUETOOTH_VIBE_CONNECT ( off)
Value:
{ .id = SETTING_BLUETOOTH_VIBE_CONNECT, .message_key = &MESSAGE_KEY_CONNECTION_VIBE_CONNECT, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = VIBE_COUNT, \
.default_num = SETTINGS_DEFAULT(CONNECTION_VIBE_CONNECT) }
@ SETTING_BLUETOOTH_VIBE_CONNECT
Vibe pattern to fire when the phone connects.
Definition settings.h:33
@ VIBE_COUNT
How many choices this setting has.
Definition setting_values.h:67

Setting definition for Bluetooth Vibe Connect.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_BLUETOOTH_VIBE_DISCONNECT

#define KNOWN_BLUETOOTH_VIBE_DISCONNECT ( off)
Value:
{ .id = SETTING_BLUETOOTH_VIBE_DISCONNECT, .message_key = &MESSAGE_KEY_CONNECTION_VIBE_DISCONNECT, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = VIBE_COUNT, \
.default_num = SETTINGS_DEFAULT(CONNECTION_VIBE_DISCONNECT) }
@ SETTING_BLUETOOTH_VIBE_DISCONNECT
Vibe pattern to fire when the phone drops.
Definition settings.h:34

Setting definition for Bluetooth Vibe Disconnect.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_DATE_FORMAT

#define KNOWN_DATE_FORMAT ( blob,
member )
Value:
{ .id = SETTING_DATE_FORMAT, .message_key = &MESSAGE_KEY_CLOCK_DATE_FORMAT, \
.type = SETTING_CSTRING, SETTINGS_TEXT_FIELD(blob, member, 16), \
.default_str = SETTINGS_DEFAULT(CLOCK_DATE_FORMAT), .affects_layout = true }
#define SETTINGS_TEXT_FIELD(blob, member, bytes)
A text entry's offset and size, with a build stop when the member is not that size.
Definition settings_catalog.h:92
@ SETTING_DATE_FORMAT
The date line's format string.
Definition settings.h:26
@ SETTING_CSTRING
Sent as text, copied into a fixed buffer.
Definition settings.h:56

Setting definition for Date Format.

The default is the one the settings page opens with, from SETTINGS_DEFAULT, so a fresh watch shows the date the page says it does. paf build stops on a page default whose UTF-8 does not fit the 16 bytes with its end. It reads the size from KNOWN_FIELDS in tools/pkjs/settings-page.ts, which a spec checks against this file.

It takes the struct and the member rather than an offset, so the build stops on a member that is not exactly 16 bytes. A shorter one would have the date format written past its end.

Parameters
blobThe face's settings struct.
memberThe char[16] member that holds the date format.

◆ KNOWN_DISTANCE_UNIT

#define KNOWN_DISTANCE_UNIT ( off)
Value:
{ .id = SETTING_DISTANCE_UNIT, .message_key = &MESSAGE_KEY_HEALTH_DISTANCE_UNIT, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = DISTANCE_UNIT_COUNT, \
.default_num = SETTINGS_DEFAULT(HEALTH_DISTANCE_UNIT) }
@ DISTANCE_UNIT_COUNT
How many choices this setting has.
Definition setting_values.h:55
@ SETTING_DISTANCE_UNIT
Km or miles on a distance readout, separate from the steps readout's STEPS_MODE.
Definition settings.h:29

Setting definition for Distance Unit.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_GOAL_ACTIVE

#define KNOWN_GOAL_ACTIVE ( off)
Value:
{ .id = SETTING_GOAL_ACTIVE, .message_key = &MESSAGE_KEY_HEALTH_GOAL_ACTIVE, \
.type = SETTING_ENUM_U8, .offset = (off), \
.enum_count = SETTINGS_COUNT_CHECKED(HEALTH_GOAL_ACTIVE, GOALS_ACTIVE_COUNT), \
.default_num = SETTINGS_DEFAULT(HEALTH_GOAL_ACTIVE) }
#define GOALS_ACTIVE_COUNT
How many active minute goals the page offers, from 15 to 90 minutes.
Definition goals.h:27
#define SETTINGS_COUNT_CHECKED(key, table_count)
The page's count on a message key, checked against the size of the face's own table.
Definition settings_catalog.h:73
@ SETTING_GOAL_ACTIVE
The active minutes goal, as an index into goals_active_min.
Definition settings.h:41

Setting definition for the Activity Goal, an index into goals_active_min.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_GOAL_CALORIES

#define KNOWN_GOAL_CALORIES ( off)
Value:
{ .id = SETTING_GOAL_CALORIES, .message_key = &MESSAGE_KEY_HEALTH_GOAL_CALORIES, \
.type = SETTING_ENUM_U8, .offset = (off), \
.enum_count = SETTINGS_COUNT_CHECKED(HEALTH_GOAL_CALORIES, GOALS_CALORIES_COUNT), \
.default_num = SETTINGS_DEFAULT(HEALTH_GOAL_CALORIES) }
#define GOALS_CALORIES_COUNT
How many calorie goals the page offers, from 500 to 3,000 kcal.
Definition goals.h:26
@ SETTING_GOAL_CALORIES
The calorie goal, as an index into goals_calories.
Definition settings.h:40

Setting definition for the Calorie Goal, an index into goals_calories.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_GOAL_DISTANCE

#define KNOWN_GOAL_DISTANCE ( off)
Value:
{ .id = SETTING_GOAL_DISTANCE, .message_key = &MESSAGE_KEY_HEALTH_GOAL_DISTANCE, \
.type = SETTING_ENUM_U8, .offset = (off), \
.enum_count = SETTINGS_COUNT_CHECKED(HEALTH_GOAL_DISTANCE, GOALS_DISTANCE_COUNT), \
.default_num = SETTINGS_DEFAULT(HEALTH_GOAL_DISTANCE) }
#define GOALS_DISTANCE_COUNT
How many distance goals the page offers, from 2 km to 20 km.
Definition goals.h:25
@ SETTING_GOAL_DISTANCE
The distance goal, as an index into goals_distance_m.
Definition settings.h:39

Setting definition for the Distance Goal, an index into goals_distance_m.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_GOAL_HR

#define KNOWN_GOAL_HR ( off)
Value:
{ .id = SETTING_GOAL_HR, .message_key = &MESSAGE_KEY_HEALTH_GOAL_HR, \
.type = SETTING_ENUM_U8, .offset = (off), \
.enum_count = SETTINGS_COUNT_CHECKED(HEALTH_GOAL_HR, GOALS_HR_COUNT), \
.default_num = SETTINGS_DEFAULT(HEALTH_GOAL_HR) }
#define GOALS_HR_COUNT
How many heart rate limits the page offers, from 150 to 200 bpm.
Definition goals.h:29
@ SETTING_GOAL_HR
The heart rate limit, as an index into goals_hr_limit.
Definition settings.h:43

Setting definition for the Heart Rate Limit, an index into goals_hr_limit.

The page only has the Heart Rate Limit row when the face asks for it with heartRate, so a face that places this without the row stops the build with SETTINGS_COUNT_HEALTH_GOAL_HR undeclared.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_GOAL_SLEEP

#define KNOWN_GOAL_SLEEP ( off)
Value:
{ .id = SETTING_GOAL_SLEEP, .message_key = &MESSAGE_KEY_HEALTH_GOAL_SLEEP, \
.type = SETTING_ENUM_U8, .offset = (off), \
.enum_count = SETTINGS_COUNT_CHECKED(HEALTH_GOAL_SLEEP, GOALS_SLEEP_COUNT), \
.default_num = SETTINGS_DEFAULT(HEALTH_GOAL_SLEEP) }
#define GOALS_SLEEP_COUNT
How many sleep goals the page offers, from 6 to 10 hours.
Definition goals.h:28
@ SETTING_GOAL_SLEEP
The sleep goal, as an index into goals_sleep_min.
Definition settings.h:42

Setting definition for the Sleep Goal, an index into goals_sleep_min.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_GOAL_STEPS

#define KNOWN_GOAL_STEPS ( off)
Value:
{ .id = SETTING_GOAL_STEPS, .message_key = &MESSAGE_KEY_HEALTH_GOAL_STEPS, \
.type = SETTING_ENUM_U8, .offset = (off), \
.enum_count = SETTINGS_COUNT_CHECKED(HEALTH_GOAL_STEPS, GOALS_STEPS_COUNT), \
.default_num = SETTINGS_DEFAULT(HEALTH_GOAL_STEPS) }
#define GOALS_STEPS_COUNT
How many step goals the page offers, from 5,000 to 25,000.
Definition goals.h:24
@ SETTING_GOAL_STEPS
The step goal, as an index into goals_steps.
Definition settings.h:38

Setting definition for the Step Goal, an index into goals_steps.

The goal tables are the framework's, in health/goals.h, and the page's rows are the ones goal-rows.ts builds. The count is the page's, from SETTINGS_COUNT, and the build stops when it differs from the table, so a choice the page offers always has a goal behind it. Read it with goals_steps(settings_u8(SETTING_GOAL_STEPS)). The other goal entries work the same way.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_GOAL_VIBE

#define KNOWN_GOAL_VIBE ( blob,
member )
Value:
{ .id = SETTING_GOAL_VIBE, .message_key = &MESSAGE_KEY_HEALTH_GOAL_VIBE, \
.type = SETTING_CSTRING, SETTINGS_TEXT_FIELD(blob, member, 64), \
.default_str = SETTINGS_DEFAULT(HEALTH_GOAL_VIBE) }
@ SETTING_GOAL_VIBE
The Goal Met Vibration pick, which vibe_goal plays.
Definition settings.h:44

Setting definition for the Goal Met Vibration, the pick vibe_goal plays.

The pick is text, empty for None, a letter for a plain pulse or the wearer's own pattern, or a comma list of milliseconds, as goal_vibe_pattern.h reads it. It keeps 64 bytes, room for the longest option the page offers and its end, and goal-rows.spec.ts checks every option fits. A face keeps this and KNOWN_GOAL_VIBE_CUSTOM in a schema of their own when its main struct has no room for them.

It takes the struct and the member rather than an offset, so the build stops on a member that is not exactly 64 bytes. A shorter one would have the pick written past its end.

Parameters
blobThe face's settings struct.
memberThe char[64] member that holds the pick.

◆ KNOWN_GOAL_VIBE_CUSTOM

#define KNOWN_GOAL_VIBE_CUSTOM ( blob,
member )
Value:
{ .id = SETTING_GOAL_VIBE_CUSTOM, .message_key = &MESSAGE_KEY_HEALTH_GOAL_VIBE_CUSTOM, \
.type = SETTING_CSTRING, SETTINGS_TEXT_FIELD(blob, member, 122), \
.default_str = SETTINGS_DEFAULT(HEALTH_GOAL_VIBE_CUSTOM) }
@ SETTING_GOAL_VIBE_CUSTOM
The wearer's own goal pattern, played when the pick is Custom.
Definition settings.h:45

Setting definition for the Custom Vibration Pattern, which vibe_goal plays when the pick is Custom.

It keeps 122 bytes, room for the 120 characters the page's box takes and the end of the text. Only a face that offers Custom, with custom on its goal alert rows, has the box and places this.

Like KNOWN_GOAL_VIBE, it takes the struct and the member, so the build stops on a member that is not exactly 122 bytes.

Parameters
blobThe face's settings struct.
memberThe char[122] member that holds the pattern.

◆ KNOWN_HOURLY_VIBE

#define KNOWN_HOURLY_VIBE ( off)
Value:
{ .id = SETTING_HOURLY_VIBE, .message_key = &MESSAGE_KEY_CLOCK_HOURLY_VIBE, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = VIBE_COUNT, \
.default_num = SETTINGS_DEFAULT(CLOCK_HOURLY_VIBE) }
@ SETTING_HOURLY_VIBE
Vibe pattern to fire on the hour.
Definition settings.h:35

Setting definition for the Hourly Vibration (a VibeChoice fired at the top of each hour).

Parameters
offOffset into the face's settings struct.

◆ KNOWN_QUIET_TIME_ICON

#define KNOWN_QUIET_TIME_ICON ( off)
Value:
{ .id = SETTING_QUIET_TIME_ICON, .message_key = &MESSAGE_KEY_APPEARANCE_QUIET_TIME_ICON, \
.type = SETTING_BOOL, .offset = (off), .default_num = SETTINGS_DEFAULT(APPEARANCE_QUIET_TIME_ICON) }
@ SETTING_QUIET_TIME_ICON
Whether the Quiet Time mark shows.
Definition settings.h:32

Setting definition for the Quiet Time Icon.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_STEPS_MODE

#define KNOWN_STEPS_MODE ( off)
Value:
{ .id = SETTING_STEPS_MODE, .message_key = &MESSAGE_KEY_HEALTH_STEPS_MODE, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = STEPS_MODE_COUNT, \
.default_num = SETTINGS_DEFAULT(HEALTH_STEPS_MODE) }
@ SETTING_STEPS_MODE
Steps, miles, or km on the steps readout.
Definition settings.h:28
@ STEPS_MODE_COUNT
How many choices this setting has.
Definition setting_values.h:44

Setting definition for Steps Mode.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_TEMPERATURE_UNIT

#define KNOWN_TEMPERATURE_UNIT ( off)
Value:
{ .id = SETTING_TEMPERATURE_UNIT, .message_key = &MESSAGE_KEY_WEATHER_TEMPERATURE_UNIT, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = 2, \
.default_num = SETTINGS_DEFAULT(WEATHER_TEMPERATURE_UNIT), .affects_weather = true }
@ SETTING_TEMPERATURE_UNIT
Celsius or Fahrenheit.
Definition settings.h:25

Setting definition for Temperature Unit (Celsius or Fahrenheit).

Every face wires this the same way, so it takes no count. There are two units and there is never going to be a third. Changing it converts the weather already on the watch and asks for fresh weather in the new unit.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_THEME

#define KNOWN_THEME ( off,
table_count )
Value:
{ .id = SETTING_THEME, .message_key = &MESSAGE_KEY_APPEARANCE_THEME, \
.type = SETTING_ENUM_U8, .offset = (off), \
.enum_count = SETTINGS_COUNT_CHECKED(APPEARANCE_THEME, table_count), \
.default_num = SETTINGS_DEFAULT(APPEARANCE_THEME) }
@ SETTING_THEME
Which theme is active.
Definition settings.h:27

Setting definition for Theme.

The count is how many themes the settings page offers, from SETTINGS_COUNT. The face passes how many its own theme table holds, and the build stops when the two differ, so a theme added to the page and not to the C, or to the C and not the page, never reaches a watch.

Parameters
offOffset into the face's settings struct.
table_countHow many themes the face's own table holds, such as its THEME_COUNT.

◆ KNOWN_TIME_FORMAT

#define KNOWN_TIME_FORMAT ( off)
Value:
{ .id = SETTING_TIME_FORMAT, .message_key = &MESSAGE_KEY_CLOCK_TIME_FORMAT, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = TIME_FORMAT_COUNT, \
.default_num = SETTINGS_DEFAULT(CLOCK_TIME_FORMAT), .affects_layout = true }
@ TIME_FORMAT_COUNT
How many choices this setting has.
Definition setting_values.h:33
@ SETTING_TIME_FORMAT
Which TimeFormat the clock uses.
Definition settings.h:30

Setting definition for Time Format.

Parameters
offOffset into the face's settings struct.

◆ KNOWN_WIND_UNIT

#define KNOWN_WIND_UNIT ( off)
Value:
{ .id = SETTING_WIND_UNIT, .message_key = &MESSAGE_KEY_WEATHER_WIND_UNIT, \
.type = SETTING_ENUM_U8, .offset = (off), .enum_count = WIND_UNIT_COUNT, \
.default_num = SETTINGS_DEFAULT(WEATHER_WIND_UNIT) }
@ WIND_UNIT_COUNT
how many units there are, not a unit itself
Definition wind.h:27
@ SETTING_WIND_UNIT
Which WindUnit a wind speed reads out in.
Definition settings.h:37

Setting definition for Wind Unit, the WindUnit a wind speed reads out in.

Kilometres per hour, then miles per hour, knots, and metres per second, the order the settings page's row lists them. The default is the one the page opens with, from SETTINGS_DEFAULT, and kilometres per hour on a page with no wind unit row. Read it with settings_u8(SETTING_WIND_UNIT) and hand it to wind_from_kmh and wind_unit_label.

Parameters
offOffset into the face's settings struct.

◆ PLUGIN_SOURCE_WEATHER_FIELD

#define PLUGIN_SOURCE_WEATHER_FIELD

The field the framework keeps the weather source in, with a comma after it, or nothing when the watch keeps no weather choice.

It is a face-only text field, so it has no typed read. Its default is the one the build wrote from the face's providers list, which is the settings page's own default. So a watch that never got a save sends back the choice the phone would make anyway.

◆ SETTINGS_BLOB

#define SETTINGS_BLOB ( settings,
first )
Value:
.blob = &(settings), \
.blob_size = SETTINGS_BLOB_SIZE(settings), \
.first_size = SETTINGS_FIRST_SIZE_(first, settings)
#define SETTINGS_FIRST_SIZE_(first, settings)
The first size for SETTINGS_BLOB, and a build that stops when it is written as more than one token,...
Definition settings.h:186
#define SETTINGS_BLOB_SIZE(blob)
The size of a settings struct, and a build that stops when the struct is too big to save....
Definition settings.h:132

Sets a schema's settings struct, its size, and the size it first shipped at, for a schema's initializer.

It fills in .blob, .blob_size, and .first_size. The first size is the struct's size in bytes in the first release that saved it, and it never changes after that release. A saved blob smaller than it cannot be this schema's. One from the first size up to today's size reads in, and every field appended since keeps its default. The struct's sizeof rises with each appended field and would turn away every older save, so the first size has to be written as the number itself, or a macro that is one. The build stops on sizeof, SETTINGS_BLOB_SIZE, a sum, brackets, or a cast written in place, and on a first size of 0 or one bigger than the struct. A constant worked out from sizeof somewhere else, such as an enum, still gets through.

static const SettingsSchema s_schema = {
.key = FACE_SETTINGS_KEY,
.version = FACE_SETTINGS_VERSION,
SETTINGS_BLOB(s_settings, 25),
.fields = s_fields,
.field_count = ARRAY_LENGTH(s_fields),
};
#define SETTINGS_BLOB(settings, first)
Sets a schema's settings struct, its size, and the size it first shipped at, for a schema's initializ...
Definition settings.h:166
A face's persistence identity.
Definition settings.h:97
Parameters
settingsThe settings struct itself, not a pointer to it or its type.
firstThe struct's size in bytes in its first release, such as 25.
Returns
The three designated initializers, for inside the schema's braces.

◆ SETTINGS_BLOB_SIZE

#define SETTINGS_BLOB_SIZE ( blob)
Value:
(sizeof(blob) + 0 * sizeof(struct { \
_Static_assert(sizeof(blob) <= PERSIST_DATA_MAX_LENGTH, \
"settings struct is over 256 bytes, so move some fields into a companion schema"); \
char unused; \
}))

The size of a settings struct, and a build that stops when the struct is too big to save. SETTINGS_BLOB uses it for a schema's blob_size.

One persist key holds at most 256 bytes, and the watch saves only the first 256 bytes of a longer write. The fields past that would come back as their defaults on every launch. This stops the build instead, so a face with more than 256 bytes of settings moves some into a companion schema. settings_init logs an error at launch for a schema whose blob_size was filled in without it.

Parameters
blobThe settings struct itself, not a pointer to it.
Returns
The struct's size in bytes.

◆ SETTINGS_CHAIN_EACH

#define SETTINGS_CHAIN_EACH ( schema,
head,
tail )
Value:
for (const SettingsSchema *schema = settings_chain_first((head), (tail)); schema; \
schema = settings_chain_next(schema, (tail)))
static const SettingsSchema * settings_chain_first(const SettingsSchema *head, const SettingsSchema *tail)
Where the walk starts.
Definition settings_chain.h:26
static const SettingsSchema * settings_chain_next(const SettingsSchema *schema, const SettingsSchema *tail)
The schema after this one in the walk.
Definition settings_chain.h:41

Walks the face's schemas and then the framework's, for a for loop's header.

Parameters
schemaThe name the loop's schema goes by.
headThe face's first schema, or NULL for a face with no settings of its own.
tailThe framework's schema, or NULL when it keeps none.

◆ SETTINGS_COUNT

#define SETTINGS_COUNT ( key)
Value:
SETTINGS_COUNT_##key

How many choices the settings page offers on a message key, worked out by the build.

paf build reads the face's settings page and writes a count for every select, radio group, and theme picker whose values are all whole numbers from 0 to 254. The count is the highest value plus one, so a value retired from the middle of a list stays reserved. A key with no such control on the page has no count, and naming it here stops the build with SETTINGS_COUNT_<key> undeclared.

A face's own choice field takes its count the same way, as in .enum_count = SETTINGS_COUNT(APPEARANCE_NIGHT_THEME).

Parameters
keyThe message key without its MESSAGE_KEY_ prefix, such as APPEARANCE_THEME.
Returns
The count, as a number the compiler knows.

◆ SETTINGS_COUNT_CHECKED

#define SETTINGS_COUNT_CHECKED ( key,
table_count )
Value:
(SETTINGS_COUNT(key) + 0 * sizeof(struct { \
_Static_assert(SETTINGS_COUNT(key) == (table_count), \
"the settings page offers " SETTINGS_COUNT_TEXT(SETTINGS_COUNT(key)) " choices on " #key \
", but the table the face passed holds " SETTINGS_COUNT_TEXT(table_count)); \
char unused; \
}))
#define SETTINGS_COUNT(key)
How many choices the settings page offers on a message key, worked out by the build.
Definition settings_catalog.h:50

The page's count on a message key, checked against the size of the face's own table.

The page lists the choices the wearer can pick, and the face's C draws them from a table of its own, such as a theme enum. A choice on the page the table lacks draws nothing, and one in the table the page lacks can never be picked, so the build stops when the two counts differ. The message names the page's count and the table's. The count is the page's, the same as SETTINGS_COUNT.

.enum_count = SETTINGS_COUNT_CHECKED(APPEARANCE_NIGHT_THEME, THEME_COUNT),
Parameters
keyThe message key without its MESSAGE_KEY_ prefix, such as APPEARANCE_THEME.
table_countHow many entries the face's own table holds, such as its THEME_COUNT.
Returns
The page's count, as a number the compiler knows.

◆ SETTINGS_DEFAULT

#define SETTINGS_DEFAULT ( key)
Value:
SETTINGS_DEFAULT_##key

The default the settings page opens with on a message key, worked out by the build.

paf build writes one for every control on the page that opens on a value the watch can hold, as the phone reads it: a toggle as 1 or 0, a choice or a whole number as its number, a colour as 0xRRGGBB, and text as a string. A control with no default of its own gives what Clay opens it on. A key a KNOWN_* entry keeps takes that entry's type, and the build stops on a page default that does not fit it. A key with no default on the page has none, and naming it here stops the build with SETTINGS_DEFAULT_<key> undeclared. The KNOWN_* entries fall back to the framework's own default for a key the page does not show.

A face's own field takes its default the same way, as in .default_num = SETTINGS_DEFAULT(APPEARANCE_NIGHT_THEME) or .default_str = SETTINGS_DEFAULT(LAYOUT).

Parameters
keyThe message key without its MESSAGE_KEY_ prefix, such as CLOCK_DATE_FORMAT.
Returns
The default, as a number or a string the compiler knows.

◆ SETTINGS_FIRST_SIZE_

#define SETTINGS_FIRST_SIZE_ ( first,
settings )
Value:
((first) + 0 * sizeof(struct { \
char settings_first_size_##first##_is_a_number; \
_Static_assert((first) >= 1 && (first) <= sizeof(settings), \
"first size is 0 or bigger than the settings struct, so give the size the struct first shipped with"); \
}))

The first size for SETTINGS_BLOB, and a build that stops when it is written as more than one token, or is 0 or past the struct's size.

SETTINGS_BLOB hands the first size on to this away from any ##, so a macro holding a number has become that number by the time it lands here.

Parameters
firstThe struct's size in bytes in its first release.
settingsThe settings struct itself.
Returns
The first size.

◆ SETTINGS_PLUGIN_SOURCE_KEY

#define SETTINGS_PLUGIN_SOURCE_KEY   249

The persist key the framework keeps the weather, calendar, and stock source choices on, so a face leaves it free.

Only a face built with PLUGIN_WEATHER, PLUGIN_CALENDAR, or PLUGIN_STOCKS that offers the choice writes it. Every face leaves it free anyway, for its settings and its stores, since turning a define on in a later release would otherwise land the choice on top of whatever the face kept there. settings_init catches a settings schema on it but cannot see a store's key.

◆ SETTINGS_TEXT_FIELD

#define SETTINGS_TEXT_FIELD ( blob,
member,
bytes )
Value:
.offset = (offsetof(blob, member) + 0 * sizeof(struct { \
_Static_assert(sizeof(((blob *)0)->member) == (bytes), \
#blob "." #member " has to be " #bytes " bytes, the size its entry writes"); \
char unused; \
})), .size = (bytes)

A text entry's offset and size, with a build stop when the member is not that size.

A text entry writes a fixed number of bytes, so a member any shorter would have the text written over whatever follows it. The size is named once, so the check and the bytes written always agree.

Parameters
blobThe face's settings struct.
memberThe member that holds the text.
bytesHow many bytes the entry writes.
Returns
The .offset and .size for the entry.

Typedef Documentation

◆ SettingsSchema

typedef struct SettingsSchema SettingsSchema

A face's persistence identity.

Its storage key, current schema version, the face struct to load into (its first byte must be the uint8_t version), that struct's size and the size it first shipped at, the field table that drives defaults/sanitize/serialization, and an optional migration hook to rescue pre-versioned data. SETTINGS_BLOB fills in the struct and both sizes.

A face can persist more than one struct by chaining schemas through companion: each schema points to the next and the last one is NULL. settings_init walks the chain so load, save, serialize, and inbox decode all cover every schema. Each link owns its own key, version, and blob, so a domain (e.g. weather or a colour table) can sit in its own key instead of bloating the main one. The typed reads (settings_u8/str) index the whole chain and remember each field's owning schema, so a shared field (id < SETTING_COUNT) can live in any link. A face built with a plugin define also gets the framework's own schema, on SETTINGS_PLUGIN_SOURCE_KEY. It is never linked onto the face's chain. The walk in settings_chain.h visits it after the face's last schema.

Enumeration Type Documentation

◆ BatteryDisplay

SETTING_BATTERY_DISPLAY choices: what the battery readout shows.

Enumerator
BATTERY_DISPLAY_BOTH 

Icon and percent.

BATTERY_DISPLAY_ICON 

Icon only.

BATTERY_DISPLAY_PERCENT 

Percent only.

BATTERY_DISPLAY_COUNT 

How many choices this setting has.

◆ DistanceUnit

SETTING_DISTANCE_UNIT choices. A distance readout's own unit, separate from the steps readout's STEPS_MODE.

Enumerator
DISTANCE_UNIT_KM 

Kilometres.

DISTANCE_UNIT_MILES 

Miles.

DISTANCE_UNIT_COUNT 

How many choices this setting has.

◆ SettingId

enum SettingId

Identity of a known (shared) setting, used for typed reads and indexing.

Face-only settings sit in the same field table but carry an id of SETTING_COUNT or greater, so they are serialized yet never indexed for a shared read.

Enumerator
SETTING_TEMPERATURE_UNIT 

Celsius or Fahrenheit.

SETTING_DATE_FORMAT 

The date line's format string.

SETTING_THEME 

Which theme is active.

SETTING_STEPS_MODE 

Steps, miles, or km on the steps readout.

SETTING_DISTANCE_UNIT 

Km or miles on a distance readout, separate from the steps readout's STEPS_MODE.

SETTING_TIME_FORMAT 

Which TimeFormat the clock uses.

SETTING_BLUETOOTH_ICON 

Whether the bluetooth icon shows.

SETTING_QUIET_TIME_ICON 

Whether the Quiet Time mark shows.

SETTING_BLUETOOTH_VIBE_CONNECT 

Vibe pattern to fire when the phone connects.

SETTING_BLUETOOTH_VIBE_DISCONNECT 

Vibe pattern to fire when the phone drops.

SETTING_HOURLY_VIBE 

Vibe pattern to fire on the hour.

SETTING_BATTERY_DISPLAY 

What the battery readout shows.

SETTING_WIND_UNIT 

Which WindUnit a wind speed reads out in.

SETTING_GOAL_STEPS 

The step goal, as an index into goals_steps.

SETTING_GOAL_DISTANCE 

The distance goal, as an index into goals_distance_m.

SETTING_GOAL_CALORIES 

The calorie goal, as an index into goals_calories.

SETTING_GOAL_ACTIVE 

The active minutes goal, as an index into goals_active_min.

SETTING_GOAL_SLEEP 

The sleep goal, as an index into goals_sleep_min.

SETTING_GOAL_HR 

The heart rate limit, as an index into goals_hr_limit.

SETTING_GOAL_VIBE 

The Goal Met Vibration pick, which vibe_goal plays.

SETTING_GOAL_VIBE_CUSTOM 

The wearer's own goal pattern, played when the pick is Custom.

SETTING_COUNT 

How many known settings there are.

◆ SettingType

How a setting encodes on the wire and how the sanitize pass clamps it.

Enumerator
SETTING_BOOL 

0 or 1, taken as an int or as digits and sent back as a byte. default_num holds the default

SETTING_ENUM_U8 

A choice, taken as an int or as digits and sent back as text holding the number.

SETTING_CSTRING 

Sent as text, copied into a fixed buffer.

SETTING_COLOR 

Sent as a 0xRRGGBB number, stored as one opaque GColor byte.

◆ StepsMode

enum StepsMode

SETTING_STEPS_MODE choices.

Enumerator
STEPS_MODE_STEPS 

Shows the raw step count.

STEPS_MODE_MILES 

Shows the distance walked, in miles.

STEPS_MODE_KM 

Shows the distance walked, in kilometres.

STEPS_MODE_COUNT 

How many choices this setting has.

◆ TimeFormat

enum TimeFormat

SETTING_TIME_FORMAT choices.

Enumerator
TIME_FORMAT_SYSTEM 

Follows the watch's own 12 or 24 hour setting.

TIME_FORMAT_12H 

12 hour with a leading zero like 06:30

TIME_FORMAT_24H 

24 hour clock

TIME_FORMAT_BEATS 

Swatch Internet Time, offered as .beats on the settings page.

TIME_FORMAT_12H_NO_LEAD 

12 hour without a leading zero like 6:30

TIME_FORMAT_COUNT 

How many choices this setting has.

◆ VibeChoice

enum VibeChoice

Bluetooth connect/disconnect vibe pattern choices.

Enumerator
VIBE_NONE 

No vibration.

VIBE_SHORT 

A single short pulse.

VIBE_LONG 

A single long pulse.

VIBE_DOUBLE 

Two short pulses.

VIBE_COUNT 

How many choices this setting has.

Function Documentation

◆ plugin_source_write_needed()

bool plugin_source_write_needed ( const PluginSourceSettings * now,
const PluginSourceSettings * on_flash,
bool on_flash_known )
inlinestatic

Whether a save has to write the choices to flash.

settings_save writes every schema on every save, and the choices only change when the wearer picks another source. So the write is skipped while the choices match what flash holds. With nothing known to be on flash it always writes, even when the choices are still the defaults. Skipping that write would leave the key empty, and the watch would count as fresh on every launch.

Parameters
nowThe choices as they are now.
on_flashThe choices as they were last loaded or written.
on_flash_knownWhether on_flash is really what flash holds. False when the key was empty at launch, or was dropped for a blob the watch could not read.
Returns
True when the save has to write.

◆ settings_apply_inbox()

SettingsInbound settings_apply_inbox ( DictionaryIterator * iter)

Apply any settings present in an inbox message to the active face.

Decodes only. The caller persists and reacts based on the returned flags.

A field already holding what the message carries is left alone and flags nothing. The config page sends the whole page on every save, so the flags say what moved rather than what turned up.

A toggle or a choice is taken whether it came as an int or as text holding only digits, through tuple_number_or. A colour is taken as an int only, since colour text could be hex. Anything else leaves the field as it was.

Parameters
iterThe dictionary iterator to decode from.
Returns
Which categories of setting changed.

◆ settings_chain_first()

const SettingsSchema * settings_chain_first ( const SettingsSchema * head,
const SettingsSchema * tail )
inlinestatic

Where the walk starts.

Parameters
headThe face's first schema, or NULL for a face with no settings of its own.
tailThe framework's schema, or NULL when it keeps none.
Returns
The first schema, or NULL when there is nothing to walk.

◆ settings_chain_has_field()

bool settings_chain_has_field ( const SettingsSchema * head,
const uint32_t * message_key )
inlinestatic

Whether a schema in the face's own chain has a field on a message key.

Only the face's chain is walked, not the framework's schema.

Parameters
headThe face's first schema, or NULL.
message_keyThe MESSAGE_KEY_* to look for, by address.
Returns
True when a face field rides on it.

◆ settings_chain_has_key()

bool settings_chain_has_key ( const SettingsSchema * head,
uint32_t key )
inlinestatic

Whether a schema in the face's own chain is saved under a persist key.

Only the face's chain is walked, not the framework's schema.

Parameters
headThe face's first schema, or NULL.
keyThe persist key to look for.
Returns
True when a face schema uses it.

◆ settings_chain_next()

const SettingsSchema * settings_chain_next ( const SettingsSchema * schema,
const SettingsSchema * tail )
inlinestatic

The schema after this one in the walk.

That is the face's own companion. After the face's last schema it is the framework's, and the walk ends there.

Parameters
schemaThe schema the walk is on.
tailThe framework's schema, or NULL when it keeps none.
Returns
The next schema, or NULL at the end.

◆ settings_enum_count()

uint8_t settings_enum_count ( SettingId id)

How many values an enum setting allows (its sanitize ceiling).

Lets a walk step through every option of an enum (e.g. every theme) without hand-counting.

Parameters
idThe known enum setting.
Returns
The value count, or 0 if the active face didn't subscribe to it.

◆ settings_init()

void settings_init ( const SettingsSchema * schema)

Load a face's settings from their saved blobs, applying defaults first.

Walks the companion chain so every schema in it is loaded. A saved blob is read only when its size and version fit the schema, or when the schema's migrate hook takes it, and every field read back is cleaned. A blob that fits neither is dropped and the schema stays on its defaults. A schema over the 256 bytes one persist key holds is logged as an error, since it can never be saved whole. SETTINGS_BLOB stops the build for one, so the log catches a schema written without it.

A face built with PLUGIN_WEATHER, PLUGIN_CALENDAR, or PLUGIN_STOCKS that declares the kind's select key also gets the framework's schema for the source choice, walked after its own and saved under SETTINGS_PLUGIN_SOURCE_KEY. The choice is only kept once this has run, so a face with no settings of its own still has to call it, as settings_init(NULL), or a reset of the Pebble app drops the wearer's pick. The pick only reaches the phone in the settings reply, so the build adds SETTINGS_REQUEST and SETTINGS_FRESH to such a face's keys. Call it before appmessage_open, which sizes the outbox from the settings reply. Called after, every settings reply goes out empty and a reinstall restores nothing. A face schema on SETTINGS_PLUGIN_SOURCE_KEY is logged as an error and the framework's schema is left out. A face field on a select key the framework keeps is logged too.

Parameters
schemaThe head schema defining the face's settings, or NULL for a face with none.

◆ settings_mark_restored()

void settings_mark_restored ( void )

Clears settings_was_fresh once a save or restore from the settings page has been saved.

Only that message counts. Anything else the phone sends while the watch is fresh stays in memory, so the phone still sees a fresh watch and pushes its whole config back.

◆ settings_save()

void settings_save ( void )

Persist the active face's structs under their keys (the whole chain).

A struct that does not reach flash whole is logged as an error and not tried again.

◆ settings_serialize()

bool settings_serialize ( DictionaryIterator * iter)

Write every field of the active face into an outbox iterator.

Stops at the first field that does not fit. The transport opens its outbox at settings_serialized_size_max, so the whole snapshot fits.

Parameters
iterThe dictionary iterator to encode into.
Returns
True when every field was written, false when the outbox ran out of room partway.

◆ settings_serialized_size_max()

uint32_t settings_serialized_size_max ( void )

The most outbox bytes every field of the active face could ever take once written.

Counts each string as filling its whole buffer, so no later settings change can outgrow it. The transport sizes its outbox from this when it opens.

Returns
The bytes the fields could need, not counting the dictionary's own one byte header.

◆ settings_set_u8()

void settings_set_u8 ( SettingId id,
uint8_t value )

Write a known uint8 or enum setting by id. In memory only, does not persist.

The write-side mirror of settings_u8. Does nothing if the active face isn't subscribed to the id. Used by the dev theme walk to force a theme without touching persistence.

Parameters
idThe known setting to write.
valueThe value to store.

◆ settings_str()

const char * settings_str ( SettingId id)

Read a known string setting by id.

Parameters
idThe known setting to read.
Returns
The stored string, or "" if the active face did not subscribe to it.

◆ settings_u8()

uint8_t settings_u8 ( SettingId id)

Read a known uint8/bool setting by id.

Parameters
idThe known setting to read.
Returns
The stored value, or 0 if the active face did not subscribe to it.

◆ settings_was_fresh()

bool settings_was_fresh ( void )

Whether the watch booted with no saved settings, because storage was wiped by a fresh install or an update. Lets the phone know it should push its own config back rather than trust the watch's defaults.

Returns
true when any schema in the chain had no blob at settings_init, or one was reset for a blob it could not read, and no settings page message has landed since.