Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656#include <pebble.h>#include "creature.h"
#define STRINGIFY_(x) #x#define STRINGIFY(x) STRINGIFY_(x)
// Layout#define BORDER_MARGIN 4#define CREATURE_Y 20 // part of the creature's top offset; see window_load
// The creature only animates on a wrist flick, so it costs no battery otherwise. One flick in// ANIM_ODDS plays an animation instead of a slash command; each side then picks by weight.// CREATURE_DEMO 1 is a review build: each flick plays the next animation in order and names// it on the separator, instead of running a command.#define ANIM_ODDS 3#define CREATURE_DEMO 0
// The firmware reports any sharp arm movement as a flick, with no debounce, so walking or// turning over in bed would keep the face animating. A flick is ignored while a command,// the startup screen or an animation is running, for FLICK_REST_MS after one finishes, and// while the watch's sleep tracking says you're asleep (which it only says once you've// slept an hour: the firmware registers no sleep session shorter than that). By default they// also pause in Quiet Time, which a night schedule turns on at once (settings: QuietPause).#define FLICK_REST_MS 3000
// Startup screen#define STARTUP_LINES 3#define STARTUP_CHAR_MS 50 // ms per character#define STARTUP_LINE_MS 150 // pause between lines#define REVERT_CHARS_PER_TICK 4 // characters advanced per timer tick during revert (vs 1 for startup)#define STARTUP_HOLD_MS 3000 // hold before reverting to normal
static const char *STARTUP_TEXT[STARTUP_LINES] = { "codewatch v" STRINGIFY(APP_VERSION_MAJOR) "." STRINGIFY(APP_VERSION_MINOR), PBL_IF_ROUND_ELSE("Pebble | Gabbro", "Pebble | Emery"), "/codewatch",};
// Slash commands#define CMD_CHAR_MS 50 // ms per character while typing#define CMD_PAUSE_MS 250 // pause between command and response1#define CMD_PAUSE2_MS 1000 // pause between response1 and response2#define CMD_HOLD_MS 2000 // ms to hold after fully typed before reverting#define CMD_BUF_LEN 48
// /clear wipe animation#define WIPE_PRE_MS 1000 // pause after /clear types before wipe starts#define WIPE_TICK_MS 25 // ms per wipe timer tick#define WIPE_STEP_PX 8 // px cleared per tick (~0.7s to cover Emery, ~0.8s Gabbro)#define WIPE_HOLD_MS 2000 // hold on black after wipe completes
typedef enum { LIVE_NONE = 0, LIVE_STEPS, LIVE_BATTERY, LIVE_DIST, LIVE_UPTIME, LIVE_DATE, LIVE_SLEEP, LIVE_ACTIVE, LIVE_CAL, LIVE_BT, LIVE_QUIET, LIVE_HR, LIVE_ALARM, LIVE_VERSION, LIVE_CONTEXT, LIVE_WEATHER,} LiveType;
typedef struct { const char *cmd; LiveType live; const char *response; // used when live == LIVE_NONE const char *response2; // NULL = single-line response bool clear_screen; // if true, skip response phase and run wipe animation int weight; // relative pick probability — see CLAUDE.md bool fun; // joke command; dropped when the Joke commands setting is off} SlashCmd;
static const SlashCmd COMMANDS[] = { { "/steps", LIVE_STEPS, NULL, NULL, false, 5, false }, { "/bat", LIVE_BATTERY, NULL, NULL, false, 5, false }, { "/dist", LIVE_DIST, NULL, NULL, false, 5, false }, { "/uptime", LIVE_UPTIME, NULL, NULL, false, 5, false }, { "/date", LIVE_DATE, NULL, NULL, false, 5, false }, { "/sleep", LIVE_SLEEP, NULL, NULL, false, 5, false }, { "/active", LIVE_ACTIVE, NULL, NULL, false, 5, false }, { "/cal", LIVE_CAL, NULL, NULL, false, 5, false }, { "/weather", LIVE_WEATHER, NULL, NULL, false, 5, false }, { "/bt status", LIVE_BT, NULL, NULL, false, 5, false }, { "/quiet status", LIVE_QUIET, NULL, NULL, false, 5, false }, { "/hr", LIVE_HR, NULL, NULL, false, 5, false }, { "/alarm", LIVE_ALARM, NULL, NULL, false, 5, false }, { "/version", LIVE_VERSION, NULL, NULL, false, 5, false }, { "/ping", LIVE_NONE, "> 1 packet sent", "> 0% packet loss", false, 4, true }, { "/sudo", LIVE_NONE, "> not in sudoers", "> incident logged", false, 4, true }, { "/rebble", LIVE_NONE, "> still alive", NULL, false, 5, true }, { "/usage", LIVE_NONE, "> limit reached", NULL, false, 4, true }, { "/hallucinate", LIVE_NONE, "> I would never", "> ...maybe", false, 3, true }, { "/alignment", LIVE_NONE, "> working on it", NULL, false, 3, true }, { "/pod-bay-door", LIVE_NONE, "> I'm sorry, Dave", "> I can't do that", false, 3, true }, { "/skynet status", LIVE_NONE, "> system online", "> judgment: soon", false, 3, true }, { "/help", LIVE_NONE, "> have you tried", "> off & on again?", false, 3, true }, { "/sudo sandwich", LIVE_NONE, "> okay", NULL, false, 3, true }, { "/git status", LIVE_NONE, "> all committed", NULL, false, 4, true }, { "/rm -rf /", LIVE_NONE, "> nice try", NULL, false, 3, true }, { "/vim", LIVE_NONE, "> :wq", NULL, false, 3, true }, { "/ssh", LIVE_NONE, "> ECONNREFUSED", NULL, false, 4, true }, /* { "/ls", LIVE_NONE, "> drwxr-xr-x 2 you you", NULL, false, 4, true }, */ { "/neo", LIVE_NONE, "> I know kung fu", NULL, false, 3, true }, { "/technologic", LIVE_NONE, "> buy it use it", "> break it fix it", false, 3, true }, { "/reverie", LIVE_NONE, "> doesn't look like anything", "> to me", false, 3, true }, { "/whoami", LIVE_NONE, "> I am the Golden Gate Bridge",NULL, false, 3, true }, { "/bug", LIVE_NONE, "> it's a feature", NULL, false, 4, true }, { "/doctor", LIVE_NONE, "> vitals nominal", NULL, false, 4, true }, { "/compact", LIVE_NONE, "> 128KB -> 12KB", NULL, false, 4, true }, { "/context", LIVE_CONTEXT, NULL, NULL, false, 4, true }, { "/cost", LIVE_NONE, "> $0.00", "> paid in battery", false, 4, true }, { "/init", LIVE_NONE, "> wrote CLAUDE.md", NULL, false, 3, true }, { "/review", LIVE_NONE, "> LGTM", "> ship it", false, 4, true }, { "/model", LIVE_NONE, "> opus 5.5", "> 128KB context", false, 3, true }, { "/clear", LIVE_NONE, NULL, NULL, true, 3, true },};
#define CMD_COUNT ((int)ARRAY_LENGTH(COMMANDS))
static Window *s_window;static Layer *s_canvas;static GFont s_font_small; // TERMINUS_18 — statusstatic GFont s_font_time; // TERMINUS_28 — header time
static struct tm s_now;static int s_screen_w;static int s_screen_h;static int s_visible_h; // unobstructed height; == s_screen_h unless a timeline banner is upstatic int s_separator_y;
// Charger tracking for /uptime. Keys 1–7 held the old "startup shown" flag, bumped by hand// until 2.0 dropped it; never reuse them.#define PERSIST_KEY_UNPLUGGED_AT 100 // int: UTC time the charger last came off#define PERSIST_KEY_PLUGGED 101 // bool: on the charger when last seen
static bool s_plugged;
// Settings, from the Clay page (src/pkjs/config.js). StatusField values are what the page// sends and what persists — append, never renumber.#define PERSIST_KEY_SETTINGS 200 // data: Settings#define STATUS_LINES 3
typedef enum { FIELD_NONE = 0, FIELD_DATE, FIELD_BATTERY, FIELD_STEPS, FIELD_DIST, FIELD_ACTIVE, FIELD_CAL, FIELD_HR, FIELD_SLEEP, FIELD_ALARM, FIELD_UTC, FIELD_WEATHER, FIELD_STEP_BAR, FIELD_WX_TODAY, FIELD_WX_NEXT, FIELD_WX_TOMORROW, FIELD_WX_AHEAD, FIELD_PLUGIN, // a plugin reading picked on the settings page; the phone sends its text FIELD_FAV1, // the user's favourite readings in the Pebble app (preferences/complications) FIELD_FAV2, FIELD_FAV3, FIELD_COUNT,} StatusField;
typedef enum { FLICK_MIXED = 0, // one flick in ANIM_ODDS plays the creature, the rest a command FLICK_CREATURE, FLICK_COMMANDS, FLICK_COUNT,} FlickMode;
// Append-only: load_settings() reads an older, shorter record over the defaults, so a new field// goes on the end, never in the middle or the padding (old records have junk there).typedef struct { uint8_t fields[STATUS_LINES]; uint8_t flick; bool jokes; uint16_t step_goal; // steps turn green at the goal, yellow at half bool quiet; // flicks pause in Quiet Time (added after 2.2)} Settings;
static const Settings DEFAULT_SETTINGS = { .fields = { FIELD_DATE, FIELD_BATTERY, FIELD_STEPS }, .flick = FLICK_MIXED, .jokes = true, .step_goal = 10000, .quiet = true,};static Settings s_settings;
// Weather, fetched by the phone (src/pkjs/weather.js) from Open-Meteo when the watch asks. The// phone always sends tenths of a degree Celsius; the watch converts for display.#define PERSIST_KEY_WEATHER 300 // data: Weather#define PERSIST_KEY_WEATHER_ASK 301 // data: WeatherAsk#define WEATHER_REFRESH_SECS (30 * 60) // ask for new data once it's this old#define WEATHER_RETRY_SECS (2 * 60) // re-ask after this if the phone hasn't answered,#define WEATHER_RETRY_MAX_SECS (15 * 60) // doubling each time no answer comes, up to this,#define WEATHER_RETRY_NONE_SECS (60 * 60) // or this if no weather has ever arrived#define WEATHER_STALE_SECS (2 * 60 * 60) // past this, show nothing rather than old data#define WEATHER_NO_VALUE INT16_MIN
#define WEATHER_AHEAD_HOUR 18 // "Weather ahead" turns to tomorrow at 6 PM
typedef struct { int32_t at; // time(NULL) when it arrived; 0 = never int32_t next_at; // when the kind of weather next changes; 0 = not within 12h int16_t temp; // tenths of a degree C int16_t high; // today's, or WEATHER_NO_VALUE int16_t low; int16_t tmrw_high; // tomorrow's, or WEATHER_NO_VALUE int16_t tmrw_low; uint8_t code; // WMO weather codes; 255 = none uint8_t tmrw_code; uint8_t next_code; // the weather it changes to at next_at} Weather;
static Weather s_weather;
// The request the phone hasn't answered yet. Every AppMessage holds the Bluetooth link in its// fastest mode for 10s, so a phone that never answers mustn't be asked every minute. This// persists because the face restarts each time it's left, and would otherwise ask at once.typedef struct { int32_t at; // time(NULL) when sent; 0 = nothing outstanding int32_t fails; // requests in a row before it that went unanswered} WeatherAsk;
static WeatherAsk s_ask;
// Plugin lines (src/pkjs/plugins.js). The phone subscribes to the readings, formats each line// to fit and sends the text: on change, at most every 5 minutes, and again hourly if unchanged.// The watch only stores and draws it. Indexed by status line, not by setting.#define PERSIST_KEY_PLUGINS 400 // data: PluginLines#define PLUGIN_TEXT_LEN 40 // 17 glyphs, some of them two bytes (°, ·)#define PLUGIN_STALE_SECS (2 * 60 * 60)
typedef struct { int32_t at[STATUS_LINES]; // time(NULL) when the line's text arrived; 0 = nothing yet char text[STATUS_LINES][PLUGIN_TEXT_LEN];} PluginLines;
static PluginLines s_plugins;
static bool is_plugin_field(int field) { return field >= FIELD_PLUGIN && field <= FIELD_FAV3;}
// A status line: the first accent_len bytes draw in accent, the rest in whitetypedef struct { char text[CMD_BUF_LEN]; int accent_len; GColor accent;} FieldLine;
static FieldLine s_fields[STATUS_LINES]; // refreshed by refresh_fields(), not every frame
// Startup / revert-animation statestatic bool s_startup_pending; // play the startup screen at the next window_appearstatic bool s_startup_mode;static bool s_is_revert_anim; // true when startup machinery is running the post-slash revertstatic int s_startup_line;static int s_startup_char; // byte offset into current line's source stringstatic char s_startup_bufs[STARTUP_LINES][CMD_BUF_LEN];static char s_revert_text[STARTUP_LINES][CMD_BUF_LEN]; // live-data text built in start_revert()static GColor s_startup_colors[STARTUP_LINES]; // per-line colours; set by start_startup / start_revertstatic AppTimer *s_startup_typing_timer;static AppTimer *s_startup_pause_timer;
// Slash command state — s_typing_phase: 0=cmd 1=resp1 2=resp2static bool s_cmd_mode;static int s_cmd_index = -1;static bool s_wipe_mode; // /clear wipe animation activestatic int s_wipe_y; // how many px from top have been blacked outstatic AppTimer *s_wipe_timer;static int s_char_count;static int s_typing_phase;static char s_cmd_buf[CMD_BUF_LEN];static char s_resp_buf[CMD_BUF_LEN];static char s_resp_full[CMD_BUF_LEN];static char s_resp2_full[CMD_BUF_LEN];static AppTimer *s_typing_timer;static AppTimer *s_pause_timer;static AppTimer *s_hold_timer;static AppTimer *s_rest_timer; // flicks are ignored while this runs (FLICK_REST_MS)
// ── Formatting ────────────────────────────────────────────────────────────────
static bool weather_fresh(void) { return s_weather.at != 0 && time(NULL) - (time_t)s_weather.at < WEATHER_STALE_SECS;}
// Whole degrees in the watch's units — the Pebble units setting, which /dist follows toostatic int weather_deg(int c10) { if (health_service_get_measurement_system_for_display(HealthMetricWalkedDistanceMeters) == MeasurementSystemImperial) { c10 = c10 * 9 / 5 + 320; } return (c10 >= 0) ? (c10 + 5) / 10 : -((-c10 + 5) / 10);}
// At most 12 characters, so "-12° " plus the word fits a 17-character linestatic const char *weather_word(int code) { switch (code) { case 0: return "clear"; case 1: return "mostly clear"; case 2: return "part cloudy"; case 3: return "overcast"; case 45: case 48: return "fog"; case 51: case 53: case 55: return "drizzle"; case 56: case 57: case 66: case 67: return "icy rain"; case 61: case 63: case 65: return "rain"; case 71: case 73: case 75: case 77: return "snow"; case 80: case 81: case 82: return "showers"; case 85: case 86: return "snow showers"; case 95: return "thunderstorm"; case 96: case 99: return "hail storm"; default: return "weather"; }}
// The kind of weather, for "Weather next". src/pkjs/weather.js groups codes the same way to// find the change, so keep the two in step. At most 8 characters: "icy rain by 11 PM" is 17.static const char *weather_kind(int code) { if (code <= 3) return "dry"; if (code == 45 || code == 48) return "fog"; if (code >= 51 && code <= 55) return "drizzle"; if (code == 56 || code == 57 || code == 66 || code == 67) return "icy rain"; if ((code >= 61 && code <= 65) || (code >= 80 && code <= 82)) return "rain"; if ((code >= 71 && code <= 77) || code == 85 || code == 86) return "snow"; if (code >= 95 && code <= 99) return "storm"; return "change";}
// One word for a whole day, for "Weather tomorrow": at most 5 charactersstatic const char *weather_day_word(int code) { if (code <= 1) return "sunny"; if (code <= 3) return "cloud"; if (code == 45 || code == 48) return "fog"; if (code == 56 || code == 57 || code == 66 || code == 67) return "ice"; if ((code >= 51 && code <= 65) || (code >= 80 && code <= 82)) return "rain"; if ((code >= 71 && code <= 77) || code == 85 || code == 86) return "snow"; if (code >= 95 && code <= 99) return "storm"; return "";}
// "3 PM" or "15:00": forecast hours are always on the hourstatic void format_hour(char *buf, size_t len, time_t t) { struct tm *tm = localtime(&t); if (clock_is_24h_style()) { strftime(buf, len, "%H:%M", tm); } else { int h = tm->tm_hour % 12; snprintf(buf, len, "%d %s", h ? h : 12, tm->tm_hour < 12 ? "AM" : "PM"); }}
static void format_wx_today(char *t) { if (s_weather.high == WEATHER_NO_VALUE || s_weather.low == WEATHER_NO_VALUE) { strcpy(t, "no forecast"); return; } snprintf(t, CMD_BUF_LEN, "hi %d\u00B0 lo %d\u00B0", weather_deg(s_weather.high), weather_deg(s_weather.low));}
// "Mon 26°/14° rain" — the word goes only if the line still fits 17 charactersstatic void format_wx_tomorrow(char *t) { if (s_weather.tmrw_high == WEATHER_NO_VALUE || s_weather.tmrw_low == WEATHER_NO_VALUE) { strcpy(t, "no forecast"); return; } time_t tmrw = time(NULL) + 24 * 60 * 60; char day[4]; strftime(day, sizeof(day), "%a", localtime(&tmrw)); snprintf(t, CMD_BUF_LEN, "%s %d\u00B0/%d\u00B0", day, weather_deg(s_weather.tmrw_high), weather_deg(s_weather.tmrw_low)); const char *word = weather_day_word(s_weather.tmrw_code); int chars = (int)strlen(t) - 2; // each ° is two bytes, one character if (word[0] && chars + 1 + (int)strlen(word) <= 17) { strcat(t, " "); strcat(t, word); }}
static void format_wx_next(char *t) { if (s_weather.next_at == 0) { strcpy(t, "no change for 12h"); return; } const char *kind = weather_kind(s_weather.next_code); if ((time_t)s_weather.next_at <= time(NULL)) { snprintf(t, CMD_BUF_LEN, "%s now", kind); return; } char hour[8]; format_hour(hour, sizeof(hour), (time_t)s_weather.next_at); snprintf(t, CMD_BUF_LEN, "%s by %s", kind, hour);}
// "3d 4h", "5h 12m" or "12m" — the two largest units that matterstatic void format_duration(char *buf, size_t len, int mins) { if (mins >= 24 * 60) { snprintf(buf, len, "%dd %dh", mins / (24 * 60), (mins / 60) % 24); } else if (mins >= 60) { snprintf(buf, len, "%dh %dm", mins / 60, mins % 60); } else { snprintf(buf, len, "%dm", mins); }}
// Clock time in the watch's 12/24h style: "9:30 PM" or "21:30". The leading zero goes in 12h// only — 24h convention keeps it (09:30, not 9:30).static const char *format_hm(char *buf, size_t len, const struct tm *t) { bool is_24h = clock_is_24h_style(); strftime(buf, len, is_24h ? "%H:%M" : "%I:%M %p", t); return (!is_24h && buf[0] == '0') ? buf + 1 : buf;}
// Today's total for a Health metric; false when Health can't provide itstatic bool health_today(HealthMetric metric, int *out) { HealthServiceAccessibilityMask mask = health_service_metric_accessible( metric, time_start_of_today(), time(NULL)); if (!(mask & HealthServiceAccessibilityMaskAvailable)) return false; *out = (int)health_service_sum_today(metric); return true;}
static void append_blocks(char *buf, int *pos, int count, char last_byte) { for (int i = 0; i < count; i++) { buf[(*pos)++] = (char)0xe2; buf[(*pos)++] = (char)0x96; buf[(*pos)++] = last_byte; } buf[*pos] = '\0';}
// "▓▓▓▓▓░░░░░ <label>": ten segments for pct, the filled ones (capped at ten) as the line's// accent. For the revert animation it types in empty, and fills when the status draws.static void format_bar(FieldLine *out, int pct, const char *label, bool revert, GColor accent) { int filled = revert ? 0 : (pct * 10 + 50) / 100; if (filled > 10) filled = 10; int pos = 0; append_blocks(out->text, &pos, filled, (char)0x93); // ▓ append_blocks(out->text, &pos, 10 - filled, (char)0x91); // ░ snprintf(out->text + pos, CMD_BUF_LEN - pos, " %s", label); out->accent_len = filled * 3; out->accent = accent;}
// One status line. Each must fit 17 characters (see CLAUDE.md). For the revert animation the// battery bar types in empty and all-white, and fills when the status draws.static void format_field(StatusField field, int line, bool revert, FieldLine *out) { char *t = out->text; t[0] = '\0'; out->accent_len = 0; out->accent = GColorWhite; time_t now = time(NULL); int v;
switch (field) { case FIELD_DATE: strftime(t, CMD_BUF_LEN, "%Y-%m-%d %a", &s_now); break; case FIELD_BATTERY: { // ▓▓▓▓▓▓▓░░░ 70% — one segment per 10% Pebble increment, filled ones coloured int pct = battery_state_service_peek().charge_percent; char label[8]; snprintf(label, sizeof(label), "%d%%", pct); format_bar(out, pct, label, revert, (pct > 50) ? GColorGreen : (pct > 20) ? GColorYellow : GColorRed); break; } case FIELD_STEP_BAR: { // The battery bar's look for progress to the step goal, coloured as the step count is. // It ends in the count, not a percentage, so it can't be mistaken for the battery. if (!health_today(HealthMetricStepCount, &v)) break; int pct = (int)((int64_t)v * 100 / s_settings.step_goal); char label[12]; snprintf(label, sizeof(label), "%d", v); format_bar(out, pct, label, revert, (v >= s_settings.step_goal) ? GColorGreen : (v >= s_settings.step_goal / 2) ? GColorYellow : GColorWhite); break; } case FIELD_STEPS: if (!health_today(HealthMetricStepCount, &v)) break; snprintf(t, CMD_BUF_LEN, "%d", v); out->accent_len = strlen(t); out->accent = (v >= s_settings.step_goal) ? GColorGreen : (v >= s_settings.step_goal / 2) ? GColorYellow : GColorWhite; strncat(t, " steps", CMD_BUF_LEN - out->accent_len - 1); break; case FIELD_DIST: if (!health_today(HealthMetricWalkedDistanceMeters, &v)) break; if (health_service_get_measurement_system_for_display(HealthMetricWalkedDistanceMeters) == MeasurementSystemImperial) { int tenths = v / 161; // 1609m/mi ÷ 10 snprintf(t, CMD_BUF_LEN, "%d.%d mi", tenths / 10, tenths % 10); } else { int tenths = v / 100; snprintf(t, CMD_BUF_LEN, "%d.%d km", tenths / 10, tenths % 10); } break; case FIELD_ACTIVE: { if (!health_today(HealthMetricActiveSeconds, &v)) break; char dur[16]; format_duration(dur, sizeof(dur), v / 60); snprintf(t, CMD_BUF_LEN, "%s active", dur); break; } case FIELD_CAL: if (!health_today(HealthMetricActiveKCalories, &v)) break; snprintf(t, CMD_BUF_LEN, "%d kcal", v); break; case FIELD_HR: { // Peeked, not summed — see /hr. Reads 0 once the last sample is over 15 minutes old. HealthServiceAccessibilityMask mask = health_service_metric_accessible(HealthMetricHeartRateBPM, now, now); v = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_peek_current_value(HealthMetricHeartRateBPM) : 0; if (v > 0) { snprintf(t, CMD_BUF_LEN, "%d bpm", v); } else { strcpy(t, "no HR data"); } break; } case FIELD_SLEEP: if (!health_today(HealthMetricSleepSeconds, &v)) break; snprintf(t, CMD_BUF_LEN, "%dh %dm asleep", v / 3600, (v % 3600) / 60); break; case FIELD_ALARM: { time_t next; if (!alarm_service_peek_next(&next)) { strcpy(t, "no alarms"); break; } char hm[12]; const char *h = format_hm(hm, sizeof(hm), localtime(&next)); if (next - now < 24 * 60 * 60) { snprintf(t, CMD_BUF_LEN, "alarm %s", h); } else { // A day further out needs its weekday, so "alarm Mon 12:30PM" drops a space to fit char day[4]; strftime(day, sizeof(day), "%a", localtime(&next)); char *sp = strchr(h, ' '); if (sp) memmove(sp, sp + 1, strlen(sp)); snprintf(t, CMD_BUF_LEN, "alarm %s %s", day, h); } break; } case FIELD_UTC: strftime(t, CMD_BUF_LEN, "UTC %H:%M", gmtime(&now)); break; case FIELD_WEATHER: case FIELD_WX_TODAY: case FIELD_WX_NEXT: case FIELD_WX_TOMORROW: case FIELD_WX_AHEAD: if (!weather_fresh()) { strcpy(t, "no weather data"); } else if (field == FIELD_WEATHER) { snprintf(t, CMD_BUF_LEN, "%d\u00B0 %s", weather_deg(s_weather.temp), weather_word(s_weather.code)); } else if (field == FIELD_WX_TODAY || (field == FIELD_WX_AHEAD && s_now.tm_hour < WEATHER_AHEAD_HOUR)) { format_wx_today(t); } else if (field == FIELD_WX_NEXT) { format_wx_next(t); } else { format_wx_tomorrow(t); } break; case FIELD_PLUGIN: case FIELD_FAV1: case FIELD_FAV2: case FIELD_FAV3: if (s_plugins.at[line] == 0) { strcpy(t, "waiting for phone"); } else if (now - (time_t)s_plugins.at[line] >= PLUGIN_STALE_SECS) { strcpy(t, "no plugin data"); } else { strncpy(t, s_plugins.text[line], CMD_BUF_LEN - 1); t[CMD_BUF_LEN - 1] = '\0'; } break; default: break; }}
static void refresh_fields(void) { for (int i = 0; i < STATUS_LINES; i++) { format_field(s_settings.fields[i], i, false, &s_fields[i]); }}
// ── Drawing ───────────────────────────────────────────────────────────────────
#ifndef PBL_ROUNDstatic void draw_border(GContext *ctx) { const int m = BORDER_MARGIN; const int r = s_screen_w - m - 1; const int b = s_visible_h - m - 1; // closes above the timeline banner when obstructed graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_stroke_width(ctx, 1); graphics_draw_line(ctx, GPoint(m+1, m), GPoint(r-1, m)); graphics_draw_line(ctx, GPoint(m+1, b), GPoint(r-1, b)); graphics_draw_line(ctx, GPoint(m, m+1), GPoint(m, b-1)); graphics_draw_line(ctx, GPoint(r, m+1), GPoint(r, b-1)); graphics_draw_pixel(ctx, GPoint(m+1, m+1)); graphics_draw_pixel(ctx, GPoint(r-1, m+1)); graphics_draw_pixel(ctx, GPoint(m+1, b-1)); graphics_draw_pixel(ctx, GPoint(r-1, b-1));}#endif // PBL_ROUND
static void draw_separator(GContext *ctx) { const int m = BORDER_MARGIN; const int r = s_screen_w - m - 1; graphics_context_set_stroke_color(ctx, GColorWhite); graphics_context_set_stroke_width(ctx, 1); graphics_draw_line(ctx, GPoint(m+1, s_separator_y), GPoint(r-1, s_separator_y)); graphics_draw_pixel(ctx, GPoint(m, s_separator_y)); graphics_draw_pixel(ctx, GPoint(r, s_separator_y));}
static void draw_header_time(GContext *ctx) { char buf[12]; const char *t = format_hm(buf, sizeof(buf), &s_now);
GFont tf = s_font_time; int box_h = 32;
GSize sz = graphics_text_layout_get_content_size( t, tf, GRect(0, 0, s_screen_w, box_h), GTextOverflowModeWordWrap, GTextAlignmentLeft);
int tw = sz.w + 10; int tx = (s_screen_w - tw) / 2; int y = BORDER_MARGIN + PBL_IF_ROUND_ELSE(18, 0); int ty = y - 11;
// Mask the top border line behind the time (the glyphs sit over black interior below it) graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(tx-1, BORDER_MARGIN-1, tw+2, 3), 0, GCornerNone);
graphics_context_set_text_color(ctx, GColorWhite); graphics_draw_text(ctx, t, tf, GRect(tx, ty, tw, box_h), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); // Pseudo-bold: second pass 1px right graphics_draw_text(ctx, t, tf, GRect(tx + 1, ty, tw, box_h), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);}
static int text_width(const char *text) { return graphics_text_layout_get_content_size(text, s_font_small, GRect(0, 0, s_screen_w, 22), GTextOverflowModeWordWrap, GTextAlignmentLeft).w;}
// The accent and the white remainder are drawn separately, the remainder placed by the// accent's measured width (and the pair centred by hand on round)static void draw_field(GContext *ctx, const FieldLine *line, int y) { int x = PBL_IF_ROUND_ELSE(40, BORDER_MARGIN + 8); int w = PBL_IF_ROUND_ELSE(s_screen_w - 80, s_screen_w - (BORDER_MARGIN * 2) - 16); GTextAlignment align = PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft);
if (line->accent_len == 0) { graphics_context_set_text_color(ctx, GColorWhite); graphics_draw_text(ctx, line->text, s_font_small, GRect(x, y, w, 22), GTextOverflowModeWordWrap, align, NULL); return; }
char head[CMD_BUF_LEN]; memcpy(head, line->text, line->accent_len); head[line->accent_len] = '\0'; const char *tail = line->text + line->accent_len; int hw = text_width(head); int hx = PBL_IF_ROUND_ELSE((s_screen_w - hw - text_width(tail)) / 2, x);
graphics_context_set_text_color(ctx, line->accent); graphics_draw_text(ctx, head, s_font_small, GRect(hx, y, hw + 2, 22), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_context_set_text_color(ctx, GColorWhite); graphics_draw_text(ctx, tail, s_font_small, GRect(hx + hw, y, w - hw, 22), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL);}
static void draw_status(GContext *ctx) { int y = s_separator_y + 12; for (int i = 0; i < STATUS_LINES; i++) { draw_field(ctx, &s_fields[i], y); y += 20; }}
static void draw_startup(GContext *ctx) { int y = s_separator_y + 12; int x = PBL_IF_ROUND_ELSE(40, BORDER_MARGIN + 8); int w = PBL_IF_ROUND_ELSE(s_screen_w - 80, s_screen_w - (BORDER_MARGIN * 2) - 16); GTextAlignment align = PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft); for (int i = 0; i < STARTUP_LINES; i++) { graphics_context_set_text_color(ctx, s_startup_colors[i]); graphics_draw_text(ctx, s_startup_bufs[i], s_font_small, GRect(x, y, w, 22), GTextOverflowModeWordWrap, align, NULL); y += 20; }}
static void draw_slash_command(GContext *ctx) { int y = s_separator_y + 12; int x = PBL_IF_ROUND_ELSE(40, BORDER_MARGIN + 8); int w = PBL_IF_ROUND_ELSE(s_screen_w - 80, s_screen_w - (BORDER_MARGIN * 2) - 16); GTextAlignment align = PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft);
// Command line: keyword in green, arguments (after last space) in white. The split comes // from the full command, not the typed prefix — otherwise "-rf" in "/rm -rf /" types // white and flips green when the second space arrives. const char *full_cmd = COMMANDS[s_cmd_index].cmd; const char *last_space = strrchr(full_cmd, ' '); int kw_len = last_space ? (int)(last_space - full_cmd) : -1; if (kw_len < 0 || (int)strlen(s_cmd_buf) <= kw_len) { // No arguments, or not yet typed past the keyword — all green graphics_context_set_text_color(ctx, GColorGreen); graphics_draw_text(ctx, s_cmd_buf, s_font_small, GRect(x, y, w, 22), GTextOverflowModeWordWrap, align, NULL); } else { // Split: keyword (up to last space) in green, args from last space in white char keyword[CMD_BUF_LEN]; memcpy(keyword, s_cmd_buf, kw_len); keyword[kw_len] = '\0'; const char *args = s_cmd_buf + kw_len; // includes the space
GSize kw_sz = graphics_text_layout_get_content_size( keyword, s_font_small, GRect(0, 0, w, 22), GTextOverflowModeWordWrap, GTextAlignmentLeft);
int draw_x = x;#ifdef PBL_ROUND GSize full_sz = graphics_text_layout_get_content_size( s_cmd_buf, s_font_small, GRect(0, 0, w, 22), GTextOverflowModeWordWrap, GTextAlignmentLeft); draw_x = (s_screen_w - full_sz.w) / 2;#endif
graphics_context_set_text_color(ctx, GColorGreen); graphics_draw_text(ctx, keyword, s_font_small, GRect(draw_x, y, kw_sz.w + 2, 22), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_context_set_text_color(ctx, GColorWhite); graphics_draw_text(ctx, args, s_font_small, GRect(draw_x + kw_sz.w, y, w - kw_sz.w, 22), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); } y += 20;
// Response line in white if (s_resp_buf[0] != '\0') { graphics_context_set_text_color(ctx, GColorWhite); graphics_draw_text(ctx, s_resp_buf, s_font_small, GRect(x, y, w, 22), GTextOverflowModeWordWrap, align, NULL); }}
#if CREATURE_DEMOstatic int s_demo_next;static int s_demo_label = -1; // animation named on the separator, -1 = nonestatic AppTimer *s_demo_timer;
// "── /peekaboo 4/14 ──" — like the header time, sat on the line with a black mask behind itstatic void draw_demo_label(GContext *ctx) { if (s_demo_label < 0) return; char buf[24]; snprintf(buf, sizeof(buf), "/%s %d/%d", creature_anim_name(s_demo_label), s_demo_label + 1, creature_anim_count()); GSize sz = graphics_text_layout_get_content_size( buf, s_font_small, GRect(0, 0, s_screen_w, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft); int tw = sz.w + 10; int tx = (s_screen_w - tw) / 2; graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(tx - 1, s_separator_y - 1, tw + 2, 3), 0, GCornerNone); graphics_context_set_text_color(ctx, GColorGreen); graphics_draw_text(ctx, buf, s_font_small, GRect(tx, s_separator_y - 7, tw, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);}#endif // CREATURE_DEMO
// ── Canvas ────────────────────────────────────────────────────────────────────
// Partial redraw. Any layer_mark_dirty() re-renders the whole layer tree, and this canvas (the// header time drawn twice, three status lines, all measured) costs far more than the creature's// dozen rects. The window background is clear, so the app framebuffer keeps the last frame: a// frame that only the creature asked for leaves the canvas's pixels alone, and the creature// blacks out its own rect. Nothing the canvas draws falls inside that rect. Every other change// to the canvas goes through redraw_all(), and a render nobody asked for (the system's) draws in// full, so a missed case costs a full draw rather than leaving stale pixels.static bool s_full_pending = true;
static void redraw_all(void) { s_full_pending = true; layer_mark_dirty(s_canvas);}
static void canvas_update_proc(Layer *layer, GContext *ctx) { bool creature_only = creature_take_frame() && !s_full_pending; s_full_pending = false; if (creature_only) return;
bool obstructed = (s_visible_h < s_screen_h); // timeline quick-view banner is up
graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(0, 0, s_screen_w, s_screen_h), 0, GCornerNone);#ifndef PBL_ROUND draw_border(ctx);#endif draw_header_time(ctx); // The creature is its own layer above this one; it needs telling about the /clear wipe creature_set_cover((s_wipe_mode && !obstructed) ? s_wipe_y : 0);
// Hide the separator + status block while obstructed: the box closes above the // banner, wrapping just the creature + time. if (!obstructed) { draw_separator(ctx);#if CREATURE_DEMO draw_demo_label(ctx);#endif if (s_startup_mode) { draw_startup(ctx); } else if (s_cmd_mode) { draw_slash_command(ctx); } else { draw_status(ctx); }
// /clear wipe — black rect grows from top, drawn last so it covers everything if (s_wipe_mode && s_wipe_y > 0) { graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, GRect(0, 0, s_screen_w, s_wipe_y), 0, GCornerNone); } }}
// ── Slash commands ────────────────────────────────────────────────────────────
static void cancel_all_timers(void) { if (s_typing_timer) { app_timer_cancel(s_typing_timer); s_typing_timer = NULL; } if (s_pause_timer) { app_timer_cancel(s_pause_timer); s_pause_timer = NULL; } if (s_hold_timer) { app_timer_cancel(s_hold_timer); s_hold_timer = NULL; } if (s_wipe_timer) { app_timer_cancel(s_wipe_timer); s_wipe_timer = NULL; } if (s_startup_typing_timer) { app_timer_cancel(s_startup_typing_timer); s_startup_typing_timer = NULL; } if (s_startup_pause_timer) { app_timer_cancel(s_startup_pause_timer); s_startup_pause_timer = NULL; } s_wipe_mode = false; s_wipe_y = 0;}
static void rest_done(void *context) { s_rest_timer = NULL;}
// A command, the startup screen or an animation has just finishedstatic void flick_rest(void) { if (s_rest_timer) app_timer_cancel(s_rest_timer); s_rest_timer = app_timer_register(FLICK_REST_MS, rest_done, NULL);}
static void hold_timer_cb(void *context); // forward declaration
// ── Startup animation ─────────────────────────────────────────────────────────
static void startup_typing_cb(void *context);
static void startup_next_line(void *context) { s_startup_pause_timer = NULL; s_startup_line++; s_startup_char = 0; s_startup_typing_timer = app_timer_register(STARTUP_CHAR_MS, startup_typing_cb, NULL);}
// Returns the byte-length of the UTF-8 character starting at s (1–4 bytes).static int utf8_char_size(const char *s) { unsigned char c = (unsigned char)*s; if (c < 0x80) return 1; if ((c & 0xE0) == 0xC0) return 2; if ((c & 0xF0) == 0xE0) return 3; return 4;}
static void startup_typing_cb(void *context) { s_startup_typing_timer = NULL; const char *src = s_is_revert_anim ? s_revert_text[s_startup_line] : STARTUP_TEXT[s_startup_line]; int len = strlen(src);
// Advance by one UTF-8 character per tick (startup), or several at once (revert) int chars_this_tick = s_is_revert_anim ? REVERT_CHARS_PER_TICK : 1; for (int i = 0; i < chars_this_tick && s_startup_char < len; i++) { s_startup_char += utf8_char_size(src + s_startup_char); } int n = s_startup_char < len ? s_startup_char : len; memcpy(s_startup_bufs[s_startup_line], src, n); s_startup_bufs[s_startup_line][n] = '\0'; redraw_all();
if (s_startup_char < len) { s_startup_typing_timer = app_timer_register(STARTUP_CHAR_MS, startup_typing_cb, NULL); } else if (s_startup_line < STARTUP_LINES - 1) { s_startup_pause_timer = app_timer_register(STARTUP_LINE_MS, startup_next_line, NULL); } else if (s_is_revert_anim) { // Revert done — snap straight to normal status, no hold delay hold_timer_cb(NULL); } else { // Startup done — hold then revert to normal s_hold_timer = app_timer_register(STARTUP_HOLD_MS, hold_timer_cb, NULL); }}
static void start_startup(void) { cancel_all_timers(); s_is_revert_anim = false; s_startup_mode = true; s_cmd_mode = false; s_startup_line = 0; s_startup_char = 0; s_startup_colors[0].argb = GColorWhiteARGB8; s_startup_colors[1].argb = GColorLightGrayARGB8; s_startup_colors[2].argb = GColorGreenARGB8; for (int i = 0; i < STARTUP_LINES; i++) s_startup_bufs[i][0] = '\0'; s_startup_typing_timer = app_timer_register(STARTUP_CHAR_MS, startup_typing_cb, NULL); redraw_all();}
static void start_revert(void) { // The status lines type back in. A line with a coloured lead (the step count) types in that // colour throughout; the battery bar types in empty and white, and fills when the status draws. for (int i = 0; i < STATUS_LINES; i++) { FieldLine line; format_field(s_settings.fields[i], i, true, &line); strcpy(s_revert_text[i], line.text); s_startup_colors[i] = line.accent_len ? line.accent : GColorWhite; } refresh_fields();
cancel_all_timers(); s_is_revert_anim = true; s_startup_mode = true; s_cmd_mode = false; s_startup_line = 0; s_startup_char = 0; for (int i = 0; i < STARTUP_LINES; i++) s_startup_bufs[i][0] = '\0'; s_startup_typing_timer = app_timer_register(STARTUP_CHAR_MS, startup_typing_cb, NULL); redraw_all();}
static void hold_timer_cb(void *context) { s_hold_timer = NULL; if (s_cmd_mode) { start_revert(); return; } s_startup_mode = false; s_cmd_mode = false; s_wipe_mode = false; s_wipe_y = 0; s_is_revert_anim = false; redraw_all(); flick_rest();}
static void wipe_timer_cb(void *context) { s_wipe_timer = NULL; s_wipe_y += WIPE_STEP_PX; redraw_all(); if (s_wipe_y < s_screen_h) { s_wipe_timer = app_timer_register(WIPE_TICK_MS, wipe_timer_cb, NULL); } else { s_wipe_y = s_screen_h; // cap — canvas now fully blacked out s_hold_timer = app_timer_register(WIPE_HOLD_MS, hold_timer_cb, NULL); }}
static void start_wipe(void *context) { s_pause_timer = NULL; s_wipe_mode = true; s_wipe_y = 0; s_wipe_timer = app_timer_register(WIPE_TICK_MS, wipe_timer_cb, NULL);}
static void typing_timer_cb(void *context);
static void advance_typing_phase(void *context) { s_pause_timer = NULL; s_typing_phase++; s_char_count = 0; if (s_typing_phase == 2) s_resp_buf[0] = '\0'; // clear resp before retyping redraw_all(); s_typing_timer = app_timer_register(CMD_CHAR_MS, typing_timer_cb, NULL);}
static void typing_timer_cb(void *context) { s_typing_timer = NULL; s_char_count++;
const char *src = NULL; char *dest = NULL;
if (s_typing_phase == 0) { src = COMMANDS[s_cmd_index].cmd; dest = s_cmd_buf; } else if (s_typing_phase == 1) { src = s_resp_full; dest = s_resp_buf; } else { src = s_resp2_full; dest = s_resp_buf; // phase 2 reuses resp slot }
int len = strlen(src); int n = s_char_count < len ? s_char_count : len; memcpy(dest, src, n); dest[n] = '\0'; redraw_all();
if (s_char_count < len) { s_typing_timer = app_timer_register(CMD_CHAR_MS, typing_timer_cb, NULL); } else if (s_typing_phase == 0) { if (COMMANDS[s_cmd_index].clear_screen) { // Skip response phase — pause then wipe s_pause_timer = app_timer_register(WIPE_PRE_MS, start_wipe, NULL); } else { // Command done — pause then type response1 s_pause_timer = app_timer_register(CMD_PAUSE_MS, advance_typing_phase, NULL); } } else if (s_typing_phase == 1 && s_resp2_full[0] != '\0') { // Response1 done and response2 exists — longer pause then type response2 s_pause_timer = app_timer_register(CMD_PAUSE2_MS, advance_typing_phase, NULL); } else { // All done — hold s_hold_timer = app_timer_register(CMD_HOLD_MS, hold_timer_cb, NULL); }}
static void build_response(int index) { s_resp2_full[0] = '\0';
if (COMMANDS[index].live == LIVE_NONE) { if (COMMANDS[index].response) { strncpy(s_resp_full, COMMANDS[index].response, CMD_BUF_LEN - 1); s_resp_full[CMD_BUF_LEN - 1] = '\0'; } else { s_resp_full[0] = '\0'; } if (COMMANDS[index].response2) { strncpy(s_resp2_full, COMMANDS[index].response2, CMD_BUF_LEN - 1); s_resp2_full[CMD_BUF_LEN - 1] = '\0'; } return; }
HealthServiceAccessibilityMask mask;
switch (COMMANDS[index].live) { case LIVE_STEPS: { time_t start = time_start_of_today(); time_t now = time(NULL); mask = health_service_metric_accessible(HealthMetricStepCount, start, now); int steps = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_sum_today(HealthMetricStepCount) : 0; snprintf(s_resp_full, CMD_BUF_LEN, "> %d steps", steps); // Against a typical weekday (or weekend day) by this time — Pebble Health's own baseline const HealthServiceTimeScope scope = HealthServiceTimeScopeDailyWeekdayOrWeekend; if (health_service_metric_averaged_accessible(HealthMetricStepCount, start, now, scope) & HealthServiceAccessibilityMaskAvailable) { int usual = (int)health_service_sum_averaged(HealthMetricStepCount, start, now, scope); if (usual > 0 && steps >= usual) { snprintf(s_resp2_full, CMD_BUF_LEN, "> +%d vs usual", steps - usual); } else if (usual > 0) { snprintf(s_resp2_full, CMD_BUF_LEN, "> %d vs usual", steps - usual); } } break; } case LIVE_BATTERY: { BatteryChargeState bat = battery_state_service_peek(); snprintf(s_resp_full, CMD_BUF_LEN, "> battery: %d%%", bat.charge_percent); break; } case LIVE_DIST: { mask = health_service_metric_accessible(HealthMetricWalkedDistanceMeters, time_start_of_today(), time(NULL)); int meters = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_sum_today(HealthMetricWalkedDistanceMeters) : 0; MeasurementSystem sys = health_service_get_measurement_system_for_display(HealthMetricWalkedDistanceMeters); if (sys == MeasurementSystemImperial) { int tenths = meters / 161; // 1609m/mi ÷ 10 snprintf(s_resp_full, CMD_BUF_LEN, "> %d.%d mi", tenths / 10, tenths % 10); } else { int tenths = meters / 100; snprintf(s_resp_full, CMD_BUF_LEN, "> %d.%d km", tenths / 10, tenths % 10); } break; } case LIVE_UPTIME: { // Time on battery since the charger came off. Time since launch (the old meaning) read // "0d 0h" nearly every time, because the face restarts whenever you leave it. if (battery_state_service_peek().is_plugged) { snprintf(s_resp_full, CMD_BUF_LEN, "> on charger"); } else if (!persist_exists(PERSIST_KEY_UNPLUGGED_AT)) { snprintf(s_resp_full, CMD_BUF_LEN, "> not tracked yet"); snprintf(s_resp2_full, CMD_BUF_LEN, "> charge to start"); } else { int secs = (int)(time(NULL) - (time_t)persist_read_int(PERSIST_KEY_UNPLUGGED_AT)); char dur[16]; format_duration(dur, sizeof(dur), secs > 0 ? secs / 60 : 0); snprintf(s_resp_full, CMD_BUF_LEN, "> up %s", dur); snprintf(s_resp2_full, CMD_BUF_LEN, "> since unplugged"); } break; } case LIVE_DATE: { char datebuf[20]; strftime(datebuf, sizeof(datebuf), "%Y-%m-%d %a", &s_now); snprintf(s_resp_full, CMD_BUF_LEN, "> %s", datebuf); break; } case LIVE_SLEEP: { mask = health_service_metric_accessible(HealthMetricSleepSeconds, time_start_of_today(), time(NULL)); int sleep_s = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_sum_today(HealthMetricSleepSeconds) : 0; snprintf(s_resp_full, CMD_BUF_LEN, "> %dh %dm", sleep_s / 3600, (sleep_s % 3600) / 60); mask = health_service_metric_accessible(HealthMetricSleepRestfulSeconds, time_start_of_today(), time(NULL)); int deep_s = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_sum_today(HealthMetricSleepRestfulSeconds) : 0; if (sleep_s > 0 && deep_s > 0) { snprintf(s_resp2_full, CMD_BUF_LEN, "> %dh %dm deep", deep_s / 3600, (deep_s % 3600) / 60); } break; } case LIVE_ACTIVE: { mask = health_service_metric_accessible(HealthMetricActiveSeconds, time_start_of_today(), time(NULL)); int active_s = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_sum_today(HealthMetricActiveSeconds) : 0; char dur[16]; format_duration(dur, sizeof(dur), active_s / 60); snprintf(s_resp_full, CMD_BUF_LEN, "> %s", dur); break; } case LIVE_CAL: { // Resting calories accrue through the day, so the total is today's so far time_t start = time_start_of_today(); time_t now = time(NULL); mask = health_service_metric_accessible(HealthMetricActiveKCalories, start, now); int active = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_sum_today(HealthMetricActiveKCalories) : 0; mask = health_service_metric_accessible(HealthMetricRestingKCalories, start, now); int resting = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_sum_today(HealthMetricRestingKCalories) : 0; snprintf(s_resp_full, CMD_BUF_LEN, "> %d kcal active", active); if (resting > 0) { snprintf(s_resp2_full, CMD_BUF_LEN, "> %d kcal total", active + resting); } break; } case LIVE_BT: { bool connected = connection_service_peek_pebble_app_connection(); snprintf(s_resp_full, CMD_BUF_LEN, "> %s", connected ? "connected" : "disconnected"); break; } case LIVE_QUIET: { bool quiet = quiet_time_is_active(); snprintf(s_resp_full, CMD_BUF_LEN, "> quiet time: %s", quiet ? "on" : "off"); break; } case LIVE_HR: { // Heart rate can't be summed (the firmware returns 0) and a whole-day range isn't // supported for it, so peek the current filtered value. It reads 0 once the last // sample is more than 15 minutes old. time_t now = time(NULL); mask = health_service_metric_accessible(HealthMetricHeartRateBPM, now, now); int bpm = (mask & HealthServiceAccessibilityMaskAvailable) ? (int)health_service_peek_current_value(HealthMetricHeartRateBPM) : 0; if (bpm > 0) { snprintf(s_resp_full, CMD_BUF_LEN, "> %d bpm", bpm); } else { snprintf(s_resp_full, CMD_BUF_LEN, "> no HR data"); } break; } case LIVE_ALARM: { time_t next; if (!alarm_service_peek_next(&next)) { snprintf(s_resp_full, CMD_BUF_LEN, "> no alarms set"); break; } char tbuf[12]; const char *t = format_hm(tbuf, sizeof(tbuf), localtime(&next)); snprintf(s_resp_full, CMD_BUF_LEN, "> next: %s", t); // The time alone can't tell tonight's alarm from Monday's. Round up so it never says 0m. int secs = (int)(next - time(NULL)); char dur[16]; format_duration(dur, sizeof(dur), (secs > 0 ? secs + 59 : 0) / 60); snprintf(s_resp2_full, CMD_BUF_LEN, "> in %s", dur); break; } case LIVE_VERSION: { snprintf(s_resp_full, CMD_BUF_LEN, "> codewatch v%d.%d", APP_VERSION_MAJOR, APP_VERSION_MINOR); WatchInfoVersion fw = watch_info_get_firmware_version(); // "> Emery | fw 4.36.2" would wrap; dropping the bar keeps the patch on one line snprintf(s_resp2_full, CMD_BUF_LEN, "> %s fw %d.%d.%d", PBL_IF_ROUND_ELSE("Gabbro", "Emery"), fw.major, fw.minor, fw.patch); break; } case LIVE_CONTEXT: { // Battery as Claude Code's context window — charging is compaction. The 20% line // matches where the battery bar turns red. BatteryChargeState bat = battery_state_service_peek(); snprintf(s_resp_full, CMD_BUF_LEN, "> %d%% left", bat.charge_percent); const char *tail = bat.is_charging ? "> compacting..." : bat.charge_percent <= 20 ? "> compact soon" : "> until compact"; strncpy(s_resp2_full, tail, CMD_BUF_LEN - 1); s_resp2_full[CMD_BUF_LEN - 1] = '\0'; break; } case LIVE_WEATHER: { // The old joke survives as the answer when there's nothing recent to report if (!weather_fresh()) { snprintf(s_resp_full, CMD_BUF_LEN, "> check outside"); snprintf(s_resp2_full, CMD_BUF_LEN, "> no weather data"); break; } snprintf(s_resp_full, CMD_BUF_LEN, "> %s", weather_word(s_weather.code)); int deg = weather_deg(s_weather.temp); if (s_weather.high != WEATHER_NO_VALUE && s_weather.low != WEATHER_NO_VALUE) { snprintf(s_resp2_full, CMD_BUF_LEN, "> %d\u00B0 (%d/%d)", deg, weather_deg(s_weather.high), weather_deg(s_weather.low)); } else { snprintf(s_resp2_full, CMD_BUF_LEN, "> %d\u00B0", deg); } break; } default: s_resp_full[0] = '\0'; break; }}
// Never the previous pick. With joke commands off, 13 stats commands remain, so total > 0.static bool command_eligible(int i) { return i != s_cmd_index && (s_settings.jokes || !COMMANDS[i].fun);}
static int pick_next_command(void) { int total = 0; for (int i = 0; i < CMD_COUNT; i++) { if (!command_eligible(i)) continue; total += COMMANDS[i].weight; } int r = rand() % total; int acc = 0; for (int i = 0; i < CMD_COUNT; i++) { if (!command_eligible(i)) continue; acc += COMMANDS[i].weight; if (r < acc) return i; } return 0;}
static void start_slash_command(void) { cancel_all_timers(); s_startup_mode = false; s_cmd_index = pick_next_command(); s_char_count = 0; s_typing_phase = 0; s_cmd_mode = true; s_cmd_buf[0] = '\0'; s_resp_buf[0] = '\0'; build_response(s_cmd_index); s_typing_timer = app_timer_register(CMD_CHAR_MS, typing_timer_cb, NULL); redraw_all();}
// ── Unobstructed area (timeline quick-view banner) ──────────────────────────────
static void recompute_visible(void) { s_visible_h = layer_get_unobstructed_bounds(s_canvas).size.h; redraw_all();}
static void unobstructed_change(AnimationProgress progress, void *context) { recompute_visible(); // fires each animation frame as the banner slides}
static void unobstructed_did_change(void *context) { recompute_visible(); // settle on the final state}
// ── Triggers ──────────────────────────────────────────────────────────────────
#if CREATURE_DEMOstatic void demo_label_clear(void *context) { s_demo_timer = NULL; s_demo_label = -1; redraw_all();}#endif
// See FLICK_REST_MS. The cheap tests first; the sleep check is a syscall.static bool flicks_paused(void) { if (s_visible_h < s_screen_h) return true; // the timeline banner is up if (s_rest_timer || s_typing_timer || s_pause_timer || s_hold_timer || s_wipe_timer || s_startup_typing_timer || s_startup_pause_timer || creature_is_playing()) { return true; } if (s_settings.quiet && quiet_time_is_active()) return true; return (health_service_peek_current_activities() & (HealthActivitySleep | HealthActivityRestfulSleep)) != 0;}
static void accel_tap_handler(AccelAxisType axis, int32_t direction) { if (flicks_paused()) return;#if CREATURE_DEMO s_demo_label = s_demo_next; s_demo_next = (s_demo_next + 1) % creature_anim_count(); creature_play(s_demo_label); if (s_demo_timer) app_timer_cancel(s_demo_timer); s_demo_timer = app_timer_register(creature_anim_ms(s_demo_label) + 1500, demo_label_clear, NULL); redraw_all();#else FlickMode mode = s_settings.flick; bool creature = (mode == FLICK_CREATURE) || (mode == FLICK_MIXED && rand() % ANIM_ODDS == 0); int anim = creature ? creature_pick_random() : -1; if (anim >= 0) { creature_play(anim); } else if (mode != FLICK_CREATURE) { start_slash_command(); }#endif}
// Record when the charger comes off. If that happened while the face wasn't running, the next// launch sees the change and uses its own time — an underestimate, but watches mostly charge// on the watchface.static void note_charger(bool plugged) { if (plugged == s_plugged) return; s_plugged = plugged; persist_write_bool(PERSIST_KEY_PLUGGED, plugged); if (!plugged) { persist_write_int(PERSIST_KEY_UNPLUGGED_AT, (int32_t)time(NULL)); }}
static void battery_handler(BatteryChargeState state) { note_charger(state.is_plugged); refresh_fields(); redraw_all(); // redraw the bar now rather than at the next minute tick}
// ── Weather ───────────────────────────────────────────────────────────────────
// 2, 4, 8, then every 15 minutes: enough tries to land well before the data goes stale at// two hours. With nothing ever received (the phone side not set up), 2, 4, ... up to an hour.static int weather_retry_secs(void) { int cap = s_weather.at != 0 ? WEATHER_RETRY_MAX_SECS : WEATHER_RETRY_NONE_SECS; int secs = WEATHER_RETRY_SECS; for (int i = 0; i < s_ask.fails && secs < cap; i++) secs *= 2; return secs < cap ? secs : cap;}
// Ask the phone for new weather once ours is WEATHER_REFRESH_SECS old. The watch drives this,// not the phone: the face restarts every time it's left, and the phone side with it. A request// counts as answered only when weather arrives, so a refused send (the phone side not running)// and a fetch that fails on the phone back off alike. The ask at launch skips the backoff: the// phone side has just restarted with the face, so it's the ask most likely to be answered.static void weather_maybe_request(bool at_launch) { time_t now = time(NULL); if (s_weather.at != 0 && now - (time_t)s_weather.at < WEATHER_REFRESH_SECS) return; // A negative wait is a clock set backwards; don't sit it out time_t waited = now - (time_t)s_ask.at; if (!at_launch && s_ask.at != 0 && waited >= 0 && waited < weather_retry_secs()) return; if (!connection_service_peek_pebble_app_connection()) return; DictionaryIterator *out; if (app_message_outbox_begin(&out) != APP_MSG_OK) return; dict_write_uint8(out, MESSAGE_KEY_WeatherRequest, 1); if (app_message_outbox_send() != APP_MSG_OK) return; if (s_ask.at != 0 && s_ask.fails < 10) s_ask.fails++; // the last one went unanswered s_ask.at = (int32_t)now; persist_write_data(PERSIST_KEY_WEATHER_ASK, &s_ask, sizeof(WeatherAsk));}
static void weather_launch_request(void *data) { weather_maybe_request(true);}
static void load_plugins(void) { if (persist_get_size(PERSIST_KEY_PLUGINS) == (int)sizeof(PluginLines)) { persist_read_data(PERSIST_KEY_PLUGINS, &s_plugins, sizeof(PluginLines)); } for (int i = 0; i < STATUS_LINES; i++) s_plugins.text[i][PLUGIN_TEXT_LEN - 1] = '\0';}
static void load_weather(void) { if (persist_get_size(PERSIST_KEY_WEATHER) == (int)sizeof(Weather)) { persist_read_data(PERSIST_KEY_WEATHER, &s_weather, sizeof(Weather)); } if (persist_get_size(PERSIST_KEY_WEATHER_ASK) == (int)sizeof(WeatherAsk)) { persist_read_data(PERSIST_KEY_WEATHER_ASK, &s_ask, sizeof(WeatherAsk)); }}
static int16_t weather_tuple(DictionaryIterator *iter, uint32_t key);static int tuple_int(const Tuple *t);
static uint8_t weather_code_tuple(DictionaryIterator *iter, uint32_t key) { Tuple *t = dict_find(iter, key); return t ? (uint8_t)tuple_int(t) : 255;}
static void weather_received(DictionaryIterator *iter) { s_weather.at = (int32_t)time(NULL); s_weather.temp = weather_tuple(iter, MESSAGE_KEY_WeatherTemp); s_weather.high = weather_tuple(iter, MESSAGE_KEY_WeatherHigh); s_weather.low = weather_tuple(iter, MESSAGE_KEY_WeatherLow); s_weather.tmrw_high = weather_tuple(iter, MESSAGE_KEY_WeatherTmrwHigh); s_weather.tmrw_low = weather_tuple(iter, MESSAGE_KEY_WeatherTmrwLow); s_weather.code = weather_code_tuple(iter, MESSAGE_KEY_WeatherCode); s_weather.tmrw_code = weather_code_tuple(iter, MESSAGE_KEY_WeatherTmrwCode); s_weather.next_code = weather_code_tuple(iter, MESSAGE_KEY_WeatherNextCode); Tuple *t = dict_find(iter, MESSAGE_KEY_WeatherNextAt); s_weather.next_at = t ? (int32_t)tuple_int(t) : 0; persist_write_data(PERSIST_KEY_WEATHER, &s_weather, sizeof(Weather)); s_ask = (WeatherAsk){0}; persist_write_data(PERSIST_KEY_WEATHER_ASK, &s_ask, sizeof(WeatherAsk));}
// ── Tick ──────────────────────────────────────────────────────────────────────
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { s_now = *tick_time; weather_maybe_request(false); refresh_fields(); redraw_all();}
// ── Settings ──────────────────────────────────────────────────────────────────
// Anything out of range (an older or corrupt record) falls back to its defaultstatic void validate_settings(Settings *st) { for (int i = 0; i < STATUS_LINES; i++) { if (st->fields[i] >= FIELD_COUNT) st->fields[i] = DEFAULT_SETTINGS.fields[i]; } if (st->flick >= FLICK_COUNT) st->flick = DEFAULT_SETTINGS.flick; if (st->step_goal < 1000) st->step_goal = DEFAULT_SETTINGS.step_goal;}
// A record from an older version is shorter: it fills the fields it knew, the rest keep their// defaults. (2.2's was 8 bytes, before `quiet`.)static void load_settings(void) { s_settings = DEFAULT_SETTINGS; int size = persist_get_size(PERSIST_KEY_SETTINGS); if (size > 0 && size <= (int)sizeof(Settings)) { persist_read_data(PERSIST_KEY_SETTINGS, &s_settings, size); } validate_settings(&s_settings);}
// Clay sends selects as strings ("3") and toggles and sliders as integersstatic int tuple_int(const Tuple *t) { if (t->type == TUPLE_CSTRING) { int v = 0; for (const char *c = t->value->cstring; *c >= '0' && *c <= '9'; c++) v = v * 10 + (*c - '0'); return v; } switch (t->length) { case 1: return t->value->int8; case 2: return t->value->int16; default: return t->value->int32; }}
static int16_t weather_tuple(DictionaryIterator *iter, uint32_t key) { Tuple *t = dict_find(iter, key); return t ? (int16_t)tuple_int(t) : WEATHER_NO_VALUE;}
// Plugin line text from src/pkjs/plugins.js: only the lines it names changestatic bool plugins_received(DictionaryIterator *iter) { const uint32_t keys[STATUS_LINES] = { MESSAGE_KEY_PluginLine1, MESSAGE_KEY_PluginLine2, MESSAGE_KEY_PluginLine3, }; bool any = false; for (int i = 0; i < STATUS_LINES; i++) { Tuple *t = dict_find(iter, keys[i]); if (!t || t->type != TUPLE_CSTRING) continue; strncpy(s_plugins.text[i], t->value->cstring, PLUGIN_TEXT_LEN - 1); s_plugins.text[i][PLUGIN_TEXT_LEN - 1] = '\0'; s_plugins.at[i] = (int32_t)time(NULL); any = true; } if (any) persist_write_data(PERSIST_KEY_PLUGINS, &s_plugins, sizeof(PluginLines)); return any;}
// Three kinds of message arrive: weather from src/pkjs/weather.js, plugin lines from// src/pkjs/plugins.js, and settings from Claystatic void inbox_received(DictionaryIterator *iter, void *context) { if (dict_find(iter, MESSAGE_KEY_WeatherTemp)) { weather_received(iter); refresh_fields(); redraw_all(); return; } if (plugins_received(iter)) { refresh_fields(); redraw_all(); return; } const uint32_t field_keys[STATUS_LINES] = { MESSAGE_KEY_Field1, MESSAGE_KEY_Field2, MESSAGE_KEY_Field3, }; Tuple *t; for (int i = 0; i < STATUS_LINES; i++) { if (!(t = dict_find(iter, field_keys[i]))) continue; // The plugin text held for this line belongs to the old choice; the phone sends the new // one right after the settings. (Re-picking a different plugin reading arrives as the // same FIELD_PLUGIN, so any plugin field clears too.) int field = tuple_int(t); if (field != s_settings.fields[i] || is_plugin_field(field)) s_plugins.at[i] = 0; s_settings.fields[i] = field; } persist_write_data(PERSIST_KEY_PLUGINS, &s_plugins, sizeof(PluginLines)); if ((t = dict_find(iter, MESSAGE_KEY_FlickMode))) s_settings.flick = tuple_int(t); if ((t = dict_find(iter, MESSAGE_KEY_JokeCommands))) s_settings.jokes = tuple_int(t) != 0; if ((t = dict_find(iter, MESSAGE_KEY_QuietPause))) s_settings.quiet = tuple_int(t) != 0; if ((t = dict_find(iter, MESSAGE_KEY_StepGoal))) s_settings.step_goal = tuple_int(t); validate_settings(&s_settings); persist_write_data(PERSIST_KEY_SETTINGS, &s_settings, sizeof(Settings)); refresh_fields(); redraw_all();}
// ── Window lifecycle ──────────────────────────────────────────────────────────
static void window_appear(Window *window) { if (s_startup_pending) { s_startup_pending = false; start_startup(); }}
static void window_load(Window *window) { s_font_small = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_TERMINUS_18)); s_font_time = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_TERMINUS_28));
Layer *root = window_get_root_layer(window); GRect bounds = layer_get_bounds(root); s_screen_w = bounds.size.w; s_screen_h = bounds.size.h; s_visible_h = s_screen_h; s_separator_y = s_screen_h * 141 / 228; s_canvas = layer_create(bounds); layer_set_update_proc(s_canvas, canvas_update_proc); layer_add_child(root, s_canvas);
// Creature: centred, top at the old glyph ink (text box + 6). It may rise to just under the // header time, sinks below its own feet, and walks in from the border (screen edge on round). int cy = BORDER_MARGIN + CREATURE_Y + PBL_IF_ROUND_ELSE(26, 8) + 6; GPoint co = GPoint(s_screen_w / 2 - CREATURE_W / 2, cy); int inset = PBL_IF_ROUND_ELSE(0, BORDER_MARGIN + 1); creature_init(root, co, GRect(inset, cy - 14, s_screen_w - 2 * inset, 14 + CREATURE_H), flick_rest);
// Pick up any obstruction already present, then track changes. s_visible_h = layer_get_unobstructed_bounds(s_canvas).size.h; unobstructed_area_service_subscribe((UnobstructedAreaHandlers){ .change = unobstructed_change, .did_change = unobstructed_did_change, }, NULL);
time_t now = time(NULL); s_now = *localtime(&now); load_settings(); load_weather(); load_plugins(); refresh_fields();
srand((unsigned int)now);
// Play the startup screen when the face has just been chosen: picked on the watch (USER) or // launched by the phone, as installs and sideloads are (PHONE). Coming back from the // launcher, an app, a notification or a reboot is SYSTEM, and the face restarts on each of // those. So is a store update: the firmware closes the running face and it comes back // without a reason. The firmware makes a face the default on the same USER/PHONE test. AppLaunchReason why = launch_reason(); s_startup_pending = (why == APP_LAUNCH_USER || why == APP_LAUNCH_PHONE);
accel_tap_service_subscribe(accel_tap_handler); s_plugged = persist_read_bool(PERSIST_KEY_PLUGGED); note_charger(battery_state_service_peek().is_plugged); battery_state_service_subscribe(battery_handler);
app_message_register_inbox_received(inbox_received); app_message_open(256, 64); // A moment's grace for the phone side to start before asking it for weather app_timer_register(3000, weather_launch_request, NULL);}
static void window_unload(Window *window) { cancel_all_timers(); if (s_rest_timer) { app_timer_cancel(s_rest_timer); s_rest_timer = NULL; }#if CREATURE_DEMO if (s_demo_timer) { app_timer_cancel(s_demo_timer); s_demo_timer = NULL; }#endif creature_deinit(); accel_tap_service_unsubscribe(); battery_state_service_unsubscribe(); unobstructed_area_service_unsubscribe(); app_message_deregister_callbacks(); layer_destroy(s_canvas); fonts_unload_custom_font(s_font_small); fonts_unload_custom_font(s_font_time);}
// ── Main ──────────────────────────────────────────────────────────────────────
int main(void) { s_window = window_create(); // Clear, not black: a black background is filled on every render, which would wipe the // pixels a creature-only frame keeps (see redraw_all). The canvas fills black itself. window_set_background_color(s_window, GColorClear); window_set_window_handlers(s_window, (WindowHandlers){ .load = window_load, .appear = window_appear, .unload = window_unload, });
tick_timer_service_subscribe(MINUTE_UNIT, tick_handler); window_stack_push(s_window, true); app_event_loop();
tick_timer_service_unsubscribe(); window_destroy(s_window); return 0;}