d338dfe3e8
crosspoint-reader calls it init() and requires it; this called it setup() and treated it as optional. Same concept, two spellings, so an app could not move between the two firmwares for no reason worth defending. init() wins because it is also the stricter contract: a misspelled entry point is now an error instead of an app that starts, draws nothing, and explains nothing. Requiring it exposed that error screens were unreadable. fail() painted the message and the host relaunched the launcher over it on the very next frame, so every Lua error was serial-only -- which would have made "Missing init()" useless to anyone holding the device rather than a console.
306 lines
9.4 KiB
Lua
306 lines
9.4 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
|
|
|
|
--- 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? Defaults to white.
|
|
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
|
|
|
|
--- Height of the current font in pixels.
|
|
---@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 to the launcher.
|
|
function sys.exit() 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() every TICK_MS, when that global is set
|
|
-- 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
|