Files
espresso_frame/firmware/main/frame_client.h
T
tfaour d324bc4a57
Build and push server image / build-and-push (push) Successful in 40s
Read battery once, after the picture is pushed, not at boot
battery_read_percent() was called once at the very start of boot, before
WiFi even connects, and that value was reused both for the manage-menu
overlay and the server report. Taken right after a reset (e.g. the OTA
reboot that immediately precedes it), the rail may still be settling --
plausible source of noisy jumps in reported battery level.

Now there's a single read, in frame_client_run() right before
report_battery(), after the photo (and manage overlay, if shown) is
already on the panel -- the fetch/display work already done this cycle
is the settle time, no delay to guess. The manage overlay no longer
needs an early local reading at all: it shows the server's last-known
value instead, added to the /frame/photo-info response it already
fetches.
2026-07-22 10:32:20 -04:00

49 lines
1.9 KiB
C

#pragma once
#include <stdbool.h>
#include "esp_err.h"
#include "wifi_provisioning.h"
/**
* Which photo-fetch behavior this wake cycle should use -- normally the
* idempotent GET /frame/image (the server decides on its own whether to
* advance, based on its configured refresh interval, so a plain
* wake/reboot never skips a photo just by asking), or POST
* /frame/advance / POST /frame/back to force a move in either direction
* (the next-photo / back-photo buttons).
*/
typedef enum {
FETCH_NORMAL,
FETCH_ADVANCE,
FETCH_BACK,
} fetch_action_t;
/**
* Connects to the home WiFi network described by cfg, retrying up to
* CONFIG_FRAME_STA_CONNECT_MAX_RETRIES times with a per-attempt timeout of
* CONFIG_FRAME_STA_CONNECT_TIMEOUT_MS. Returns ESP_OK once an IP address
* has been obtained, ESP_FAIL if all retries are exhausted.
*/
esp_err_t frame_wifi_connect_sta(const frame_config_t *cfg);
/**
* Runs the frame's normal-operation cycle: fetch the current image from
* cfg->toolsserver per `action` (see fetch_action_t), display it, and
* deep-sleep until the next refresh.
*
* If show_management_qr is true (the manage button was held), the
* displayed photo gets a small "scan to manage" QR overlay in the
* top-right corner linking to the server's config page, held for 30
* seconds (the device stays awake), then reverted back to the plain
* photo before proceeding to the normal sleep-interval logic. Its
* battery indicator shows the server's last-known reading, not a fresh
* one -- see fetch_photo_info() in frame_client.c.
*
* Reads the battery (see battery_read_percent()) itself, once, after the
* photo is already on the panel, and reports it to the server on a
* successful fetch; a -1 reading ("no reading" -- on mains, disabled, or
* implausible) skips the report.
*/
void frame_client_run(const frame_config_t *cfg, fetch_action_t action, bool show_management_qr);