Files
slate32/stubs/slate32.lua
T
evan b5146b8642 refactor(lua): give the status bar its own dirty tracking and split settings out of sys
The bar repainted itself whole every second. It now compares each field against what
it last painted, adds seconds and a memory percentage, and keys the cache on
gui.getRotation() and ui.themeName so rotation and theme changes still repaint it.
Invalidation lives entirely in Lua; the firmware's push flag and gfx/statusbar.h are gone.

Bindings follow getName/setName/isName, persisted preferences move from sys to a settings
table, and gui.setRotation takes degrees like settings does. A bar that dies mid-run now
keeps its rows reserved rather than silently resizing the running app.
2026-08-02 10:49:01 -04:00

334 lines
10 KiB
Lua

---@meta
-- Generated by scripts/gen_lua_stubs.py. Do not edit.
-- Point your editor's Lua language server at this file to get completion for the
-- firmware API inside sdcard/apps and sdcard/lib.
---@class fslib
fs = {}
--- Reads a whole file from the SD card.
---@param path string Absolute path.
---@return string? Contents truncated to 65536 bytes, or nil when missing.
function fs.readFile(path) end
--- Writes a whole file to the SD card, replacing it if it exists.
---@param path string Absolute path.
---@param content string
---@return boolean
function fs.writeFile(path, content) end
--- Whether a path exists.
---@param path string Absolute path.
---@return boolean
function fs.exists(path) end
--- Names of the files in a directory, excluding dotfiles.
---@param path string Absolute path.
---@return string[]
function fs.listFiles(path) end
--- Names of the subdirectories in a directory, excluding dotfiles.
---@param path string Absolute path.
---@return string[]
function fs.listDirs(path) end
---@class guilib
gui = {}
--- Panel width in pixels, for the current rotation.
---@return integer
function gui.getWidth() end
--- Hands the app the whole panel, hiding the status bar, until it is turned off.
---@param on boolean
function gui.setFullscreen(on) end
--- Panel height in pixels, for the current rotation.
---@return integer
function gui.getHeight() end
--- Fills the whole panel with one color.
---@param color integer? Defaults to white.
function gui.clear(color) end
--- Fills a rectangle.
---@param x integer
---@param y integer
---@param w integer
---@param h integer
---@param color integer
function gui.fillRect(x, y, w, h, color) end
--- Strokes a one pixel rectangle outline.
---@param x integer
---@param y integer
---@param w integer
---@param h integer
---@param color integer
function gui.drawRect(x, y, w, h, color) end
--- Fills an anti-aliased circle, blending its rim against the surface behind it.
---@param x integer Center.
---@param y integer Center.
---@param radius integer
---@param color integer
---@param bg integer? Surface color to blend against, defaults to white.
function gui.fillCircle(x, y, radius, color, bg) end
--- Strokes a line.
---@param x1 integer
---@param y1 integer
---@param x2 integer
---@param y2 integer
---@param color integer
function gui.drawLine(x1, y1, x2, y2, color) end
--- Draws text with an opaque background behind its glyphs.
---@param text string
---@param x integer
---@param y integer
---@param color integer? Defaults to black.
---@param bg integer? Omitted draws transparent glyphs, over whatever is behind them.
function gui.drawText(text, x, y, color, bg) end
--- Draws a rounded rectangle: fill, vertical gradient and border from one
--- distance field, so the edges cannot disagree.
---@param x integer
---@param y integer
---@param w integer
---@param h integer
---@param radius integer Clamped to half the shorter side.
---@param bg integer Surface color the anti-aliased edge blends against.
---@param top integer? Fill color, or the top of the gradient.
---@param bottom integer? Bottom of the gradient, defaults to top.
---@param border integer? Border color; omitted draws no border.
function gui.roundRect(x, y, w, h, radius, bg, top, bottom, border) end
--- Scales the built-in font by a whole number, for this app only.
---@param size integer 1 to 8.
function gui.setTextSize(size) end
--- Height of the current font in pixels, at the current text size.
---@return integer
function gui.getFontHeight() end
--- Width the given text would occupy in pixels.
---@param text string
---@return integer
function gui.getTextWidth(text) end
--- Rotates the frame for this draw only; settings.setRotation persists it.
---@param degrees integer 0, 90, 180 or 270.
function gui.setRotation(degrees) end
--- Rotation of the frame being drawn, which is not always the saved preference.
---@return integer Degrees clockwise.
function gui.getRotation() end
--- Packs 8 bit channels into the panel's RGB565 color format.
---@param r integer
---@param g integer
---@param b integer
---@return integer
function gui.color(r, g, b) end
---@class httplib
http = {}
--- Fetches a URL. Certificates are verified against the embedded root bundle.
---@param url string
---@param headers table? Header name to value.
---@return string? Response body, or nil when the status is not 2xx or the body exceeds 50000 bytes.
---@return integer HTTP status, or -1 when the request could not be sent.
function http.get(url, headers) end
--- Fetches a URL, discarding the body.
---@param url string
---@param headers table? Header name to value.
---@return string? Response body, always empty on success.
---@return integer HTTP status, or -1 when the request could not be sent.
function http.head(url, headers) end
--- Deletes a resource.
---@param url string
---@param headers table? Header name to value.
---@return string? Response body.
---@return integer HTTP status, or -1 when the request could not be sent.
function http.delete(url, headers) end
--- Posts a body to a URL.
---@param url string
---@param body string? Request body, empty when omitted.
---@param headers table? Header name to value.
---@return string? Response body.
---@return integer HTTP status, or -1 when the request could not be sent.
function http.post(url, body, headers) end
--- Patches a resource.
---@param url string
---@param body string? Request body, empty when omitted.
---@param headers table? Header name to value.
---@return string? Response body.
---@return integer HTTP status, or -1 when the request could not be sent.
function http.patch(url, body, headers) end
--- Streams an HTTPS URL to a file, checking size and digest before keeping it.
---@param url string Must be https.
---@param destination string Absolute path that must not already exist.
---@param options table maxBytes is required; expectedSize and sha256 are optional.
---@return integer? Bytes written, or nil on failure.
---@return string? Error message when the download failed.
function http.download(url, destination, options) end
--- Percent-encodes a string, keeping the RFC 3986 unreserved characters.
---@param input string
---@return string
function http.urlencode(input) end
---@class inputlib
input = {}
--- Current touch point, calibrated and rotated.
---@return integer? X, or nil when the panel is not touched.
---@return integer? Y.
function input.getTouch() end
--- Current touch point as raw ADC readings, for calibration.
---@return integer? X, or nil when the panel is not touched.
---@return integer? Y.
function input.getRawTouch() end
--- Whether the panel is being touched.
---@return boolean
function input.isTouched() end
---@class loglib
log = {}
--- Writes a debug line to the serial log.
---@param message string
function log.debug(message) end
--- Writes an info line to the serial log.
---@param message string
function log.info(message) end
--- Writes an error line to the serial log.
---@param message string
function log.error(message) end
---@class settingslib
settings = {}
--- Saved screen rotation in degrees clockwise.
---@return integer
function settings.getRotation() end
--- Rotates the screen and saves it.
---@param degrees integer 0, 90, 180 or 270.
---@return boolean Whether the setting was saved.
function settings.setRotation(degrees) end
--- Name of the active theme in /lib/theme.lua.
---@return string
function settings.getTheme() end
--- Saves the theme name. Apps call ui.setTheme(), which also reloads the palette.
---@param name string
---@return boolean Whether the setting was saved.
function settings.setTheme(name) end
--- Active POSIX timezone rule.
---@return string
function settings.getTimezone() end
--- Sets the timezone from a POSIX TZ rule and saves it.
---@param tz string For example EST5EDT,M3.2.0,M11.1.0.
---@return boolean Whether the setting was saved.
function settings.setTimezone(tz) end
--- Stores touch calibration, in the panel's unrotated frame.
---@param x0 integer Raw reading at the left edge.
---@param y0 integer Raw reading at the top edge.
---@param x1 integer Raw reading at the right edge.
---@param y1 integer Raw reading at the bottom edge.
---@return boolean Whether the setting was saved.
function settings.setCalibration(x0, y0, x1, y1) end
---@class syslib
sys = {}
--- Milliseconds since boot.
---@return integer
function sys.getMillis() end
--- Blocks for the given time.
---@param ms integer
function sys.delay(ms) end
--- Ends this app and returns home.
function sys.exit() end
--- Directory name of the running app, for example "settings".
---@return string
function sys.getAppName() end
--- Sets how often on_tick() runs. Errors when on_tick is not defined.
---@param intervalMs integer 0 stops ticking; anything else is clamped to 33..3600000.
function sys.setTickInterval(intervalMs) end
--- Ends this app and starts another one.
---@param path string Absolute path to the app's main.lua.
function sys.launch(path) end
--- Free and total heap, in bytes.
---@return integer Free bytes.
---@return integer Total bytes.
function sys.getMemory() end
--- Whether SNTP has answered. Until it has, os.time() is only a build-time floor.
---@return boolean
function sys.isClockSynced() end
---@class wifilib
wifi = {}
--- Scans for networks, blocking until the sweep finishes.
---@return table[] Each entry has ssid, rssi and secure.
function wifi.scan() end
--- Saves credentials and starts connecting. Poll status() for the outcome.
---@param ssid string
---@param password string? Omitted for an open network.
---@return boolean Whether the credentials were saved and the attempt started.
function wifi.connect(ssid, password) end
--- Current connection state.
--- connecting, connected, not_found or failed.
---@return table Fields state, ssid, ip and rssi. state is one of disconnected,
function wifi.getStatus() end
--- Whether the station is associated.
---@return boolean
function wifi.isConnected() end
--- Current IPv4 address.
---@return string The address, or 0.0.0.0 when not connected.
function wifi.getLocalIP() end
--- Drops the connection but keeps the saved credentials.
function wifi.disconnect() end
--- Drops the connection and erases the saved credentials.
---@return boolean Whether the settings were saved.
function wifi.forget() end
-- Callbacks an app may define as globals:
-- init() once, before the first draw (required)
-- draw() every 33 ms while the app runs
-- on_tick() at the interval app.setTickInterval() asked for
-- on_touch_down(x, y) finger down
-- on_touch_up(x, y) finger up
-- on_touch(x, y) tap, fired on release like a click