b9b620ad2b
Leaving an app was the app's own responsibility, so one that shipped without an exit could only be escaped with a reset. The bar now paints a back button into its leading square and the firmware treats that rect as home, acting on release so a press sliding into the app cancels. The app it returns to is /apps/home, which is what it is to the user. Card grids in home and settings centre left to right as a unit.
322 lines
10 KiB
Lua
322 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.width() end
|
|
|
|
--- Hands the app the whole panel, hiding the status bar, until it is turned off.
|
|
---@param on boolean
|
|
function gui.fullscreen(on) end
|
|
|
|
--- Panel height in pixels, for the current rotation.
|
|
---@return integer
|
|
function gui.height() 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.fontHeight() end
|
|
|
|
--- Width the given text would occupy in pixels.
|
|
---@param text string
|
|
---@return integer
|
|
function gui.textWidth(text) end
|
|
|
|
--- Rotates the frame for this draw only; sys.setRotation persists it.
|
|
---@param rotation integer 0 to 3, in quarter turns.
|
|
function gui.setRotation(rotation) 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.touched() 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 syslib
|
|
sys = {}
|
|
|
|
--- Milliseconds since boot.
|
|
---@return integer
|
|
function sys.millis() 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.appName() 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
|
|
|
|
--- Saved screen rotation in degrees clockwise.
|
|
---@return integer
|
|
function sys.getRotation() end
|
|
|
|
--- Rotates the screen and saves it.
|
|
---@param degrees integer 0, 90, 180 or 270.
|
|
---@return boolean Whether the setting was saved.
|
|
function sys.setRotation(degrees) end
|
|
|
|
--- Name of the active theme in /lib/theme.lua.
|
|
---@return string
|
|
function sys.getTheme() end
|
|
|
|
--- Selects a theme by name and saves it.
|
|
---@param name string
|
|
---@return boolean Whether the setting was saved.
|
|
function sys.setTheme(name) 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 sys.setCalibration(x0, y0, x1, y1) end
|
|
|
|
--- Whether SNTP has answered. Until it has, os.time() is only a build-time floor.
|
|
---@return boolean
|
|
function sys.clockSynced() end
|
|
|
|
--- Active POSIX timezone rule.
|
|
---@return string
|
|
function sys.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 sys.setTimezone(tz) 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.status() 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.localIP() 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
|