diff --git a/libraries/AP_Scripting/docs/docs.lua b/libraries/AP_Scripting/docs/docs.lua index d0118e12ec986..27bdb9f8b5231 100644 --- a/libraries/AP_Scripting/docs/docs.lua +++ b/libraries/AP_Scripting/docs/docs.lua @@ -3140,6 +3140,14 @@ function BattMonitorScript_State_ud:voltage(value) end ---@param value boolean function BattMonitorScript_State_ud:healthy(value) end +-- The temperature library provides access to information about the currently connected temperature sensors on the vehicle. +temperature_sensor = {} + +-- Returns the temperature from this sensor in degrees Celsius +---@param instance integer -- temperature instance +---@return number|nil -- temperature if available +function temperature_sensor:get_temperature(instance) end + -- The battery library provides access to information about the currently connected batteries on the vehicle. battery = {} diff --git a/libraries/AP_Scripting/examples/temperature_sensor.lua b/libraries/AP_Scripting/examples/temperature_sensor.lua new file mode 100644 index 0000000000000..ca3bec775d0a5 --- /dev/null +++ b/libraries/AP_Scripting/examples/temperature_sensor.lua @@ -0,0 +1,18 @@ +--[[ + simple example of reading a temperature sensor +--]] + +local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7} + +--[[ + main update function, called at 1Hz +--]] +function update() + local temperature_C = temperature_sensor:get_temperature(0) + gcs:send_text(MAV_SEVERITY.INFO, string.format("Temperature: %f", temperature_C)) + return update, 1000 +end + +-- start running update loop +return update, 1000 + diff --git a/libraries/AP_Scripting/generator/description/bindings.desc b/libraries/AP_Scripting/generator/description/bindings.desc index f623bead2e50d..a041ea8faa540 100644 --- a/libraries/AP_Scripting/generator/description/bindings.desc +++ b/libraries/AP_Scripting/generator/description/bindings.desc @@ -977,3 +977,9 @@ singleton AP_VisualOdom depends HAL_VISUALODOM_ENABLED singleton AP_VisualOdom rename visual_odom singleton AP_VisualOdom method healthy boolean singleton AP_VisualOdom method quality int8_t + +-- ----AP_TemperatureSensor Library---- +include AP_TemperatureSensor/AP_TemperatureSensor.h +singleton AP_TemperatureSensor depends AP_TEMPERATURE_SENSOR_ENABLED +singleton AP_TemperatureSensor rename temperature_sensor +singleton AP_TemperatureSensor method get_temperature boolean float'Null uint8_t'skip_check