Loading...
Searching...
No Matches
stock_store.c File Reference

The active stock store: holds the quotes, owns the appmessage stock channel, and asks the phone for more whenever its turn on the face's cadence finds a poll due. More...

Data Structures

struct  [struct].s_state

Macros

#define STOCK_FIRST_POLL_MS   700
 Delay before the first fetch after launch, in ms.

Functions

static void reset_state (void)
 Clear the watchlist back to empty.
static void persist_save (void)
 Stash the whole state so a relaunch can restore it. Only a live face writes.
static void apply_seed (const StockSeed *seed)
 Prefill the store from a seed, for dev builds and screenshots.
static void on_stock_strip (const uint8_t *buf, uint16_t len)
 Stock channel. Takes the watchlist the reader unpacked and puts it away.
static void cadence_poll (void)
 The store's turn on the face's cadence: poll when the deadline has come round.
void stock_store_subscribe (void(*cb)(void))
 Hand it the function to call when a quote changes (the screen redraw).
void stock_store_init (StockConfig cfg, const StockSeed *seed)
 Start the store with its rules. Pass seed = NULL for normal use.
void stock_store_reconfigure (StockConfig cfg)
 Re-apply the rules (e.g. the poll interval changed). Moves the next poll to the new interval, and switching the store off here stops it asking the phone.
const StockStrip * stock_store_strip (void)
 The whole watchlist strip. count is 0 until a reading lands.
const StockSlot * stock_store_slot (uint8_t index)
 One slot by index, or NULL when the index is past what is filled.
int stock_store_age_s (void)
 How many seconds since the last reading turned up, or -1 if we have none.

Variables

static struct  s_state
 The quotes the store holds, laid out as the blob that gets persisted.
static void(*) s_cb (void)
 Called whenever the quotes change, so the face can redraw.
static StoreFetch s_fetch
 The interval, the catch-up fetch, and when the next poll is due.
static uint32_t s_persist_key
 The persist slot the face handed us for the saved strip.
static uint32_t s_saved_sum
 Sum of the reading last written, so a reply that changes nothing is not written again.

Detailed Description

The active stock store: holds the quotes, owns the appmessage stock channel, and asks the phone for more whenever its turn on the face's cadence finds a poll due.

Macro Definition Documentation

◆ STOCK_FIRST_POLL_MS

#define STOCK_FIRST_POLL_MS   700

Delay before the first fetch after launch, in ms.

It fires from the event loop so appmessage is open by then. The recurring poll then runs at the configured interval.

Function Documentation

◆ apply_seed()

void apply_seed ( const StockSeed * seed)
static

Prefill the store from a seed, for dev builds and screenshots.

s_cb is still NULL at the point init calls this, so no redraw fires here.

Parameters
seedThe prefill to apply.

◆ on_stock_strip()

void on_stock_strip ( const uint8_t * buf,
uint16_t len )
static

Stock channel. Takes the watchlist the reader unpacked and puts it away.

A message that does not read clean leaves the last good quotes where they are, so a bad one can never blank the watchlist.

Parameters
bufThe raw wire bytes.
lenHow many bytes there are.