Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1793be8
weather: the model
freethinkel Nov 20, 2026
bb2ffa8
weather: the screens and the loop
freethinkel Nov 20, 2026
23ca2c2
weather: icon, store listing, README row
freethinkel Nov 20, 2026
e99cc83
weather: Cargo.lock
freethinkel Nov 20, 2026
27e62c1
weather: hours and days count from the phone's hour
freethinkel Nov 20, 2026
479371d
weather: no degree sign in text, a ring after the temperature; the no…
freethinkel Nov 20, 2026
a683aeb
weather: the pager came out black on a mixed forecast; screenshots
freethinkel Nov 20, 2026
519d475
weather: room between Today and its icon on the Days page
freethinkel Nov 21, 2026
2c7e3e7
weather: the stock round scroll bar on the hours and the days
freethinkel Nov 21, 2026
83a245b
weather: eight widget icons, in model::Icon order
freethinkel Nov 22, 2026
9672292
weather: the columns card, now and the next three hours
freethinkel Nov 22, 2026
1672719
weather 0.2.0: the widget and its icon-order contract in README and t…
freethinkel Nov 22, 2026
6174f10
weather: night icons for clear and partly cloudy, appended as 8 and 9
freethinkel Nov 22, 2026
4272acc
weather: the card shows night where the hour says so
freethinkel Nov 22, 2026
4df60e4
weather: wrap the widget's store text
freethinkel Nov 22, 2026
1f074ac
weather: check the card in tests with the loader's own accepts
freethinkel Nov 22, 2026
41ccfaa
weather: the card needs stub 10
freethinkel Nov 22, 2026
c519287
weather: test that stub 9 refuses the card and stub 10 takes it
freethinkel Nov 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ An app runs on a watch with the patched firmware and the App Loader, both on the
| [`vela-nav`](apps/vela-nav) | Turn-by-turn directions from the Vela maps app on an Android phone |
| [`calendar`](apps/calendar) | A month with the phone's events as dots, a page next to the face and a widget card (needs FMC Companion) |
| [`reminders`](apps/reminders) | The iPhone's open reminders: overdue, today, later; tick one off with a tap, and a widget card (needs FMC Companion on an iPhone) |
| [`weather`](apps/weather) | Now, the next hours and the week ahead, in stock LVGL parts; a page next to the face and a widget card by the hour (needs FMC Companion) |
| [`ha-remote`](apps/ha-remote) | Up to five Home Assistant light and group toggles with an Android companion |

## Make your own app
Expand Down
9 changes: 9 additions & 0 deletions apps/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions apps/weather/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "weather"
edition.workspace = true
license.workspace = true
version.workspace = true

[dependencies]
cmf-wp2-app.workspace = true
companion-rpc.workspace = true

[dev-dependencies]
wp2-core.workspace = true

[[bin]]
name = "weather"
bench = false
41 changes: 41 additions & 0 deletions apps/weather/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Weather

The store's page is [`store.md`](store.md). This is the contract of the widget card, which the watch
(`src/model.rs`, `Model::columns`) and FMC Companion both write: the same forecast at the same hour gives the same
bytes, so change both sides together.

## The card (stub 10 and its loader)

A v2 `columns` record (the SDK's `docs/widget-push.md`) of at most four columns: now, then the three hours after the
one that contains now. Hours that aren't known give no column. Without the current weather the phone writes nothing
and the watch keeps its text card; so does a watch that answers `-22` to the record.

- Caption: `Now`, then `HH:00` (24 h, zero-padded, `00:00` after `23:00`).
- Hours count from the forecast's own first hour and the phone's clock, never from a stale first entry.
- Value: whole degrees C and `°` (U+00B0), no unit. Now is the current record's 0.1° rounded, halves away from zero,
never `-0`; an hour is its entry's temperature.
- Icon: the index of the condition, from the WMO code of the current record or of that hour. At night index 0 becomes
8 and index 1 becomes 9; the other six have one drawing.
- Night is bit 7 of an hourly entry's precip byte: that entry's for its column, and for Now that of the entry that
contains now, as on the Now page. No such entry means day. Nothing else says what is night (no sunrise of the
phone's or the watch's own), so both write the same bytes.

| Index | `widget-icons/` | `model::Icon` | WMO codes |
|---|---|---|---|
| 0 | `00-clear.svg` | `Clear` | 0 |
| 1 | `01-partly.svg` | `Partly` | 1, 2 |
| 2 | `02-cloud.svg` | `Cloud` | anything not listed here |
| 3 | `03-fog.svg` | `Fog` | 45, 48 |
| 4 | `04-drizzle.svg` | `Drizzle` | 51-57 |
| 5 | `05-rain.svg` | `Rain` | 61-67, 80-82 |
| 6 | `06-snow.svg` | `Snow` | 71-77, 85, 86 |
| 7 | `07-storm.svg` | `Storm` | 95-99 |
| 8 | `08-clear-night.svg` | `Clear` at night | 0 |
| 9 | `09-partly-night.svg` | `Partly` at night | 1, 2 |

The index is the file's place in name order and is stored on watches and sent by phones: append, never reorder.

Test vectors (87 bytes each, `src/model_tests.rs`, `columns_golden_bytes` and `columns_golden_bytes_at_night`):

- `wp2apps.install.columns_record([("Now",6,"-3°"),("23:00",2,"-4°"),("00:00",0,"-5°"),("01:00",7,"0°")])`
- `wp2apps.install.columns_record([("Now",8,"-3°"),("23:00",9,"-4°"),("00:00",2,"-5°"),("01:00",7,"0°")])`
21 changes: 21 additions & 0 deletions apps/weather/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/weather/shots/card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/weather/shots/days.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/weather/shots/hours.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/weather/shots/now.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
193 changes: 193 additions & 0 deletions apps/weather/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
//! weather: now, the next hours and the next days, from FMC Companion (`location` for the place, `weather`).
//!
//! - The menu app is three pages in the stock pager (`screen::pages_view`): now, hours, days. The crown or a
//! swipe pages; the hours and days scroll first. BUTTON exits.
//! - The page next to the watch face (`app_features!(PAGE)`) is the now screen alone (`screen::face_view`).
//! - The card left of the face (`WIDGET`): from stub 10 now and the next three hours in columns with the app's own
//! icons (`widget-icons/`, README.md), before that the place, the temperature with the condition, high and low;
//! written whenever it changes while the app runs, a new hour too.
//!
//! The weather comes from the phone at start and every 15 minutes while shown, and is kept in the app's storage so
//! it opens at once without the phone (`model.rs`).
#![cfg_attr(target_os = "none", no_std, no_main)]

#[cfg_attr(not(target_os = "none"), allow(dead_code))]
mod model;
#[cfg_attr(not(target_os = "none"), allow(dead_code))]
mod screen;

#[cfg(not(target_os = "none"))]
fn main() {}

#[cfg(target_os = "none")]
mod device {
use crate::model::{BLOB_MAX, Card, Got, Model, Widget, wall_min};
use crate::screen::{self, View};
use cmf_wp2_app::lv::{Batch, Lv, ROOT};
use cmf_wp2_app::{Api, BUTTON, MESSAGE, MSG_MAX, PAUSE, RESUME};

cmf_wp2_app::entry!(main);
cmf_wp2_app::app_icon!();
cmf_wp2_app::app_features!(cmf_wp2_app::WIDGET | cmf_wp2_app::PAGE);

/// How often to look at the clock: a new hour moves the hours, the "Updated" line ages.
const TICK_MS: u32 = 60_000;
/// On the page next to the face, coming back asks the phone only when the copy is older than this.
const FRESH_MIN: i32 = 30;

static mut STORE: [u8; BLOB_MAX] = [0; BLOB_MAX];
static mut MODEL: Model = Model::new();

fn wall(api: &Api) -> i32 {
api.time().map_or(0, |t| wall_min(t.year as i32, t.month as u32, t.day as u32, t.hour as u32, t.minute as u32))
}

struct App {
api: &'static Api,
lv: Lv,
b: Batch,
model: &'static mut Model,
view: View,
/// The pager's page, kept over a redraw.
page: usize,
on_page: bool,
/// What the screen shows depends on, besides the data.
shown: (i32, bool, i32),
widget: Widget,
}

impl App {
/// The hour, whether the phone is silent, and the age once it is worth a line.
fn key(&self, w: i32) -> (i32, bool, i32) {
let stale = self.model.stale_min(w);
(w.div_euclid(60), self.model.silent(), if self.model.now.is_some() && stale > 45 { stale / 10 } else { 0 })
}

fn draw(&mut self) {
let (lv, w) = (self.lv, wall(self.api));
let mut flush = |b: &mut Batch| b.submit(&lv);
let r = screen::leave(&mut self.b, self.view.root)
.and_then(|_| {
if self.on_page {
screen::face_view(&mut self.b, &mut flush, self.model, w)
} else {
screen::pages_view(&mut self.b, &mut flush, self.model, w, self.page)
}
})
.and_then(|v| self.b.submit(&lv).map(|_| v));
match r {
Ok(v) => self.view = v,
Err(_) => self.b.clear(), // or the records left in it fail every later draw
}
self.shown = self.key(w);
}

fn save(&mut self) {
let blob = unsafe { &mut *core::ptr::addr_of_mut!(STORE) };
let n = self.model.save(blob);
if n > 0 {
self.api.save(&blob[..n]); // on change: the app can end without notice
}
}

/// The card, when it changes.
fn card(&mut self) {
let api = self.api;
self.widget.update(self.model, wall(api), |card| match card {
Card::Columns((rec, n)) => api.widget_v2(&rec[..*n]),
Card::Text(t, v) => api.widget(t.as_str(), v.as_str()),
});
}

fn poll(&mut self) {
let now = self.api.now();
while let Some(req) = self.model.poll(now) {
if self.api.send(&req) == -11 {
break; // outbox full: the retry timer sends it again
} // -107 with no phone: the retry timer covers it too
}
}

fn message(&mut self, m: &[u8]) {
let got = self.model.reply(m, self.api.now(), wall(self.api));
if got == Got::Saved {
self.save();
}
if got != Got::Nothing {
self.draw();
self.card();
}
}

/// The clock moved, or the phone went silent.
fn tick(&mut self) {
if self.key(wall(self.api)) != self.shown {
self.draw();
self.card();
}
}
}

fn main(api: &'static Api) -> i32 {
let Some(lv) = api.lv() else { return -95 }; // loader older than ABI 1.2
let Some(mut b) = Batch::new() else { return -1 };
if screen::fonts(&mut b).and_then(|_| b.submit(&lv)).is_err() {
return 1;
}
if screen::theme(&mut b).and_then(|_| b.submit(&lv)).is_err() {
return 2;
}
let model = unsafe { &mut *core::ptr::addr_of_mut!(MODEL) };
let blob = unsafe { &mut *core::ptr::addr_of_mut!(STORE) };
let n = api.load(blob);
if n > 0 {
model.load(&blob[..n as usize]);
}
model.ask_now(api.now());
let view = View { root: ROOT, pager: None, bars: [ROOT; 3] };
let mut app =
App { api, lv, b, model, view, page: 0, on_page: api.on_page(), shown: (0, false, 0), widget: Widget::new() };
app.draw();
app.card();
let mut paused = false;
let mut msg = [0u8; MSG_MAX];
loop {
if !paused {
app.poll();
}
let wait = if paused { u32::MAX } else { app.model.wait(api.now()).min(TICK_MS) };
let e = api.event(wait);
if !paused {
app.tick();
}
let Some(e) = e else { continue };
match e.kind {
BUTTON => break,
PAUSE => paused = true,
RESUME => {
paused = false;
if app.model.now.is_none() || app.model.stale_min(wall(api)) > FRESH_MIN {
app.model.ask_now(api.now());
}
app.tick();
}
MESSAGE => {
while let Some(m) = api.recv(&mut msg) {
app.message(m);
}
}
_ if !paused => {
// the pager settled on a page: move its dots
if let Some(p) = app.view.pager.as_mut() {
if let Ok(Some(i)) = p.event(&mut app.b, &e) {
app.page = i;
let _ = app.b.submit(&lv);
}
}
}
_ => {}
}
}
0
}
}
Loading
Loading