---@meta

-- GENERATED FILE — do not hand-edit.
-- Regenerated by `tools/docs_pipeline.py build` (see docs-system/README.md).
-- To fix API facts: edit the upstream EdgeTX /*luadoc*/ comment, then
-- re-extract and rebuild. To add narrative content: edit
-- docs-system/overlays/<doc_id>.md, then rebuild.

--- LCD line pattern selector such as SOLID or DOTTED.
---@alias pen_type integer
--- Text rendering flags used by legacy LCD number APIs.
---@alias text_flags integer
--- Packed 16-bit RGB color value for color LCD APIs.
---@alias lcd_color_RGB565 integer
--- Font size selector such as XXLSIZE, DBLSIZE, MIDSIZE, or SMLSIZE.
---@alias lcd_font_size integer
--- Bitmask of LCD text rendering flags such as INVERS, BLINK, and SHADOWED.
---@alias lcd_text_flags integer
--- Combined LCD text formatting bitmask covering font size and text flags.
---@alias lcd_text_format integer
--- Signed EdgeTX source value in the normalized range from -1024 to 1024.
---@alias source_range_1024 integer
--- Global timer selector such as all, total, session, throttle, or throttlepct.
---@alias timer_type string
--- Telemetry unit identifier from the EdgeTX unit list.
---@alias unit_type integer
--- Telemetry precision selector controlling decimal places.
---@alias prec_type integer

--- Returns gray value which can be used in LCD functions
--- @since 2.0.13
---@return integer
function GREY() end

--- This functions allows for sending SPORT / ACCESS telemetry data toward the receiver,
and more generally, to anything connected SPORT bus on the receiver or transmitter.
--- @since 2.3
---@param module integer module index (0 = internal, 1 = external)
---@param rxuid integer receiver index
---@param sensorid unknown physical sensor ID
---@param frameid unknown frame ID
---@param dataid unknown data ID
---@param value unknown value
---@return boolean
function accessTelemetryPush(module, rxuid, sensorid, frameid, dataid, value) end

--- Apply RGB led colors previously defined by setRGBLedColor
--- @since 2.10
function applyRGBLedColors() end

--- Change the working directory
--- @since 2.3.0
---@param directory string New working directory
function chdir(directory) end

--- Pops a received Crossfire Telemetry packet from the queue.
--- @since 2.2.0
---@return nil
---@return integer command
---@return table packet
function crossfireTelemetryPop() end

--- This functions allows for sending telemetry data toward the TBS Crossfire link.
--- @since 2.2.0
---@param command unknown command
---@param data table table of data bytes
---@return boolean
---@return nil
function crossfireTelemetryPush(command, data) end

--- Get channel assigned to stick. See Default Channel Order in General Settings
--- @since 2.0.0
---@param stick integer stick number (from 0 to 3)
---@return integer
---@return nil
function defaultChannel(stick) end

--- Get stick that is assigned to a channel. See Default Channel Order in General Settings.
--- @since 2.0.0
---@param channel integer channel number (0 means CH1)
---@return integer
function defaultStick(channel) end

--- Returns FRESULT (e.g. 0=OK, 4=File not found, 5=Path not found, 6=Path invalid)
--- @since 2.9.0
function del() end

--- Return an iterator listing all the files and directories name in a directory
--- @since 2.5.0
---@param directory string Working directory
function dir(directory) end

--- flushes audio queue
--- @since unknown
function flushAudio() end

--- Checks the existence of file or directory.
 If not exist, return nil.
 If exist, return the object information.
--- @since 2.5.0
---@param path string path to the object
---@return table
function fstat(path) end

--- Get available memory remaining in the Heap for Lua.
--- @since unknown
---@return integer usage
function getAvailableMemory() end

--- Return current system date and time that is kept by the RTC unit
--- @since unknown
---@return table
function getDateTime() end

--- Return detailed information about field (source)
--- @since 2.0.8
---@param source string can be an index (number) (which was obtained by getFieldInfo or getSourceIndex) or a name (string) of the source.
---@return table
---@return nil
function getFieldInfo(source) end

--- Return flight mode data.
--- @since 2.1.7
---@param mode integer flight mode number to return (0 - 8). If mode parameter is not specified (or contains invalid value), then the current flight mode data is returned.
---@return integer current_flight_mode_number_0_8
---@return string current_flight_mode_name
function getFlightMode(mode) end

--- Returns (some of) the general radio settings
--- @since 2.0.6
---@return table
function getGeneralSettings() end

--- Returns radio timers
--- @since unknown
---@return table
function getGlobalTimer() end

--- 
--- @since 2.6
---@param id integer identifying the logical switch (zero for LS1 etc.).
---@return true/false value
function getLogicalSwitchValue(id) end

--- 
--- @since 2.8.0
---@param outputindex integer identifying the output channel number 0 for CH1, up to MAX_OUTPUT_CHANNELS - 1.
---@return integer
function getOutputValue(outputindex) end

--- Return the RAS value or nil if no valid hardware found
--- @since 2.2.0
---@return integer
function getRAS() end

--- Get RSSI value as well as low and critical RSSI alarm levels (in dB)
--- @since 2.2.0
---@return unknown rssi
---@return unknown alarm_low
---@return unknown alarm_crit
function getRSSI() end

--- Return rotary encoder mode
--- @since 2.8.0
---@return integer
function getRotEncMode() end

--- Return rotary encoder current speed
--- @since 2.3.10
---@return integer
function getRotEncSpeed() end

--- Return current RTC system date as unix timstamp (in seconds since 1. Jan 1970)
--- @since unknown
---@return integer
function getRtcTime() end

--- 
--- @since 2.6
---@param id integer between 1 and 16 identifying the shared memory variable.
---@return integer value
function getShmVar(id) end

--- 
--- @since 2.6
---@param sourcename string naming a value source as it is shown on radio menus where you can select it. Notice that many names have special characters in them.
---@return integer sourceindex
function getSourceIndex(sourcename) end

--- 
--- @since 2.6
---@param sourceindex integer identifying a value source as returned by getSourceIndex(sourceName) or the id field in the table returned by getFieldInfo.
---@return string sourcename
function getSourceName(sourceindex) end

--- Returns the value of a source. Superseeds getValue.
--- @since 2.0.0
---@param source string can be an index (number) (which was obtained by getFieldInfo or getSourceIndex) or a name (string) of the source.
---@return integer
---@return unknown iscurrent
---@return unknown isfresh
function getSourceValue(source) end

--- 
--- @since 3.0
---@return integer
function getStickMode() end

--- 
--- @since 2.6
---@param positionname string naming a switch position as it is shown on radio menus where you can select a switch. Notice that many names have special characters in them like arrow up/down etc.
---@return integer value
function getSwitchIndex(positionname) end

--- 
--- @since 2.12
---@param sourceindex integer identifying a value source as returned by getSourceIndex(sourceName) or the id field in the table returned by getFieldInfo.
---@return table
function getSwitchInfo(sourceindex) end

--- 
--- @since 2.6
---@param switchindex integer identifying a switch as returned by getSwitchIndex(positionName) or fields in the table returned by model.getLogicalSwitch(switch) identifying switches.
---@return string value
function getSwitchName(switchindex) end

--- 
--- @since 2.6
---@param switchindex integer identifying a switch as returned by getSwitchIndex(positionName) or fields in the table returned by model.getLogicalSwitch(switch) identifying switches.
---@return integer value
function getSwitchValue(switchindex) end

--- Return the time since the radio was started in multiple of 10ms
--- @since 2.0.0
---@return integer
function getTime() end

--- 
--- @since 2.9.0
---@return integer
function getTrainerStatus() end

--- Return the internal GPS position or nil if no valid hardware found
--- @since 2.2.2
---@return table
function getTxGPS() end

--- Get percent of already used Lua instructions in current script execution cycle.
--- @since 2.2.1
---@return integer usage
function getUsage() end

--- Returns the value of a source.
--- @since 2.0.0
---@param source string can be an index (number) (which was obtained by getFieldInfo or getSourceIndex) or a name (string) of the source.
---@return integer
---@return table
---@return table
---@return table
function getValue(source) end

--- Return OpenTX version
--- @since 2.0.0
---@return string
---@return string opentx_version_ie_2
---@return string radio_type_x12s_x10_x9e_x9d_x9d_or_x7
---@return integer major_version_ie_2_if_version_2
---@return integer minor_version_ie_1_if_version_2
---@return integer revision_number_ie_5_if_version_2
---@return string os_name_i
function getVersion() end

--- Pops a received Ghost Telemetry packet from the queue.
--- @since 2.7.0
---@return nil
---@return integer type
---@return table packet
function ghostTelemetryPop() end

--- This functions allows for sending telemetry data toward the Ghost link.
--- @since 2.7.0
---@param command unknown command
---@param data table table of data bytes
---@return boolean
---@return nil
function ghostTelemetryPush(command, data) end

--- Stops key state machine. See [Key Events](../key_events.md) for the detailed description.
--- @since 2.0.0
---@param key integer key to be killed, can also include event type (only the key part is used)
function killEvents(key) end

--- Load a Lua script file. This is similar to Lua's own [loadfile()](https://www.lua.org/manual/5.2/manual.html#pdf-loadfile)
API method, but it uses OpenTx's optional pre-compilation feature to save memory and time during load.
--- @since 2.2.0
---@param file string Full path and file name of script. The file extension is optional and ignored (see mode param to control which extension will be used). However, if an extension is specified, it should be ".lua" (or ".luac"), otherwise it is treated as part of the file name and the .lua/.luac will be appended to that.
---@param mode? string (optional) Controls whether to force loading the text (.lua) or pre-compiled binary (.luac) version of the script. By default ETX will load the newest version and compile a new binary if necessary (overwriting any existing .luac version of the same script, and stripping some debug info like line numbers). You can use mode to control the loading behavior more specifically. Possible values are: * b only binary. * t only text. * T (default on simulator) prefer text but load binary if that is the only version available. * bt (default on radio) either binary or text, whichever is newer (binary preferred when timestamps are equal). * Add x to avoid automatic compilation of source file to .luac version. Eg: "tx", "bx", or "btx". * Add c to force compilation of source file to .luac version (even if existing version is newer than source file). Eg: "tc" or "btc" (forces "t", overrides "x"). * Add d to keep extra debug info in the compiled binary. Eg: "td", "btd", or "tcd" (no effect with just "b" or with "x").
---@param env? integer See documentation for Lua function loadfile().
---@return function|nil
---@return string|nil
function loadScript(file, mode, env) end

--- Create a directory
--- @since 2.11.0
---@param directory string Directory to create
function mkdir(directory) end

--- This function reads/writes the Multi protocol buffer to interact with a protocol.
--- @since 2.3.2
---@param address unknown to read/write in the buffer @param (optional): value to write in the buffer
---@return integer
function multiBuffer(address) end

--- Play a time value (text to speech)
--- @since 2.1.0
---@param duration integer number of seconds to play. Only integral part is used.
---@param hourformat? integer * 0 or not present play format: minutes and seconds. * != 0 play format: hours, minutes and seconds. * @param volume (number): - (1..5) override radio settings Wav volume for the duration of file - omitting the parameter uses radio settings Wav volume
---@return unknown none
function playDuration(duration, hourformat) end

--- Play a file from the SD card
--- @since 2.0.0
---@param filename string full path to wav file (i.e. "/SOUNDS/en/system/tada.wav") Introduced in 2.1.0: If you use a relative path, the current language is appended to the path (example: for English language: /SOUNDS/en is appended)
---@param volume? integer - (1..5) override radio settings Wav volume for the duration of file - omitting the parameter uses radio settings Wav volume
---@return unknown none
function playFile(filename, volume) end

--- Generate haptic feedback
--- @since 2.2.0
---@param duration integer length of the haptic feedback in milliseconds
---@param pause integer length of the silence after haptic feedback in milliseconds
---@param flags? integer * 0 or not present play with normal priority * PLAY_NOW play immediately
function playHaptic(duration, pause, flags) end

--- Play a numerical value (text to speech)
--- @since 2.0.0
---@param value integer number to play. Value is interpreted as integer.
---@param unit integer unit identifier, see the Units reference for the full list
---@param attributes? integer possible values: * 0 or not present plays integral part of the number (for a number 123 it plays 123) * PREC1 plays a number with one decimal place (for a number 123 it plays 12.3) * PREC2 plays a number with two decimal places (for a number 123 it plays 1.23)
---@param volume? integer - (1..5) override radio settings Wav volume for the duration of file - omitting the parameter uses radio settings Wav volume
---@return unknown none
function playNumber(value, unit, attributes, volume) end

--- Play a tone
--- @since 2.1.0
---@param frequency integer tone frequency in Hz (from 150 to 15000)
---@param duration integer length of the tone in milliseconds
---@param pause integer length of the silence after the tone in milliseconds
---@param flags? integer * 0 or not present play with normal priority. * PLAY_BACKGROUND play in background (built in vario function uses this context) * PLAY_NOW play immediately
---@param freqincr? integer positive number increases the tone pitch (frequency with time), negative number decreases it. The frequency changes every 10 milliseconds, the change is freqIncr * 10Hz. The valid range is from -127 to 127.
---@param volume? integer - (1..5) override radio settings Beep volume for the duration of file - omitting the parameter uses radio settings Beep volume
---@return unknown none
function playTone(frequency, duration, pause, flags, freqincr, volume) end

--- Raises a pop-up on screen that asks for confirmation
--- @since 2.2.0
---@param title string title to display
---@param message string text to display
---@param event integer the event variable that is passed in from the Run function (key pressed)
---@return unknown cancel
function popupConfirmation(title, message, event) end

--- Raises a pop-up on screen that allows uses input
--- @since 2.0.0
---@param title string text to display
---@param event integer the event variable that is passed in from the Run function (key pressed)
---@param input integer value that can be adjusted by the +/- keys
---@param min integer min value that input can reach (by pressing the - key)
---@param max integer max value that input can reach
---@return integer
---@return unknown ok
---@return unknown cancel
function popupInput(title, event, input, min, max) end

--- Raises a pop-up on screen that shows a warning
--- @since 2.2.0
---@param title string text to display
---@param event integer the event variable that is passed in from the Run function (key pressed)
---@return unknown cancel
function popupWarning(title, event) end

--- Rename a file or directory
  If the file or directory is being moved to a new parent directory, then the new parent
  directory must already exist.
--- @since 2.11.0
---@param from_path string Current path to rename @param to_path (string) Path to rename to
function rename(from_path) end

--- Resets the radio global timer to 0.
--- @since 2.2.2
---@param type? unknown : if set to 'all', throttle ,throttle percent and session timers are reset too if set to 'session', radio session timer is reset too if set to 'ttimer', radio throttle timer is reset too if set to 'tptimer', radio throttle percent timer is reset too
function resetGlobalTimer(type) end

--- Takes a screenshot, which is saved to the SCREENSHOTS folder on the radio SD card.
--- @since 2.11
---@return unknown none
function screenshot() end

--- 
--- @since 2.9.0
---@param port_nr valid values are only 0 and 1 on radios that have SWSERIALPOWER defined 0 - first serial port, e.g. on TX16S AUX1 1 - second serial port, e.g. on TX16S AUX2
---@return true value
---@return nil
function serialGetPower(port_nr) end

--- 
--- @since 2.3.8
---@param num? integer maximum number of bytes to read. If non-zero, serialRead will read up to num characters from the buffer. If 0 or left out, serialRead will read up to and including the first newline character or the end of the buffer. Note that the returned string may not end in a newline if this character is not present in the buffer.
---@return unknown str
function serialRead(num) end

--- 
--- @since 2.9.0
---@param port_nr valid values are only 0 and 1 on radios that have SWSERIALPOWER defined 0 - first serial port, e.g. on TX16S AUX1 1 - second serial port, e.g. on TX16S AUX2
---@param value 0 - disable power 1 - enable power
---@return true/false success
function serialSetPower(port_nr, value) end

--- 
--- @since 2.3.10
---@param str string String to be written to the serial port.
function serialWrite(str) end

--- Overrides the LED color for a custom function switch
--- @since 3.0.0
---@param id string identifying a custom function switch name
---@param rvalue integer value of red channel
---@param bvalue integer value of green channel
---@param cvalue integer value of blue channel
function setCFSLedColor(id, rvalue, bvalue, cvalue) end

--- 
--- @since 3.0
---@param offset integer offset in angular degree. -1 to offset to current X position
---@param range integer range in angular degree. 180° max.90 means min/max value will be reached at 45° from offset position
function setIMU_X(offset, range) end

--- 
--- @since 3.0
---@param offset integer offset in angular degree. -1 to offset to current Y position
---@param range integer range in angular degree, 180° max. 90 means min/max value will be reached at 45° from offset position
function setIMU_Y(offset, range) end

--- 
--- @since 2.10
---@param id integer identifying a led in the led chain
---@param rvalue integer value of red channel
---@param bvalue integer value of green channel
---@param cvalue integer value of blue channel
function setRGBLedColor(id, rvalue, bvalue, cvalue) end

--- 
--- @since 2.3.12
---@param baudrate unknown Desired baurate
function setSerialBaudrate(baudrate) end

--- 
--- @since 2.6
---@param id integer between 1 and 16 identifying the shared memory variable.
---@param value integer . The value of the shared memory variable.
function setShmVar(id, value) end

--- 
--- @since 2.6
---@param id integer identifying the sticky logical switch (zero for LS1 etc.).
---@param value integer . The new value of the sticky logical switch.
---@return true/false bufferfull
function setStickySwitch(id, value) end

--- 
--- @since 2.2.0
---@param id unknown Id of the sensor, valid range is from 0 to 0xFFFF
---@param subid unknown subID of the sensor, usually 0, valid range is from 0 to 7
---@param instance unknown instance of the sensor (SensorID), valid range is from 0 to 0xFF
---@param value unknown fed to the sensor
---@param unit? unknown unit of the sensor, see the Units reference for the full list
---@param precision? unknown the precision of the sensor * 0 or not present no decimal precision. * != 0 value is divided by 10^precision, e.g. value=1000, prec=2 => 10.00.
---@param name? string Name of the sensor if it does not yet exist (4 chars). * not present Name defaults to the Id. * present Sensor takes name of the argument. Argument must have name surrounded by quotes: e.g., "Name"
---@return unknown true
function setTelemetryValue(id, subid, instance, value, unit, precision, name) end

--- 
--- @since 2.6
---@param first? integer first source index. If nil or omitted, the first available source is used.
---@param last? integer last soure index. If nil or omitted, the last available source is used.
function sources(first, last) end

--- Pops a received SPORT packet from the queue. Please note that only packets using a data ID within 0x5000 to 0x50FF
(frame ID == 0x10), as well as packets with a frame ID equal 0x32 (regardless of the data ID) will be passed to
the LUA telemetry receive queue.
--- @since 2.2.0
---@return nil
---@return integer sensor_id
---@return integer frame_id
---@return integer data_id
---@return integer value
function sportTelemetryPop() end

--- This functions allows for sending SPORT telemetry data toward the receiver,
and more generally, to anything connected SPORT bus on the receiver or transmitter.
--- @since 2.2.0
---@param sensorid unknown physical sensor ID
---@param frameid unknown frame ID
---@param dataid unknown data ID
---@param value unknown value
---@return boolean
---@return nil
function sportTelemetryPush(sensorid, frameid, dataid, value) end

--- 
--- @since 2.6
---@param first? integer first switch index. If nil or omitted, the first available switch is used.
---@param last? integer last switch index. If nil or omitted, the last available switch is used.
function switches(first, last) end
