summaryrefslogtreecommitdiff
path: root/src/lua/stubs
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-11-15 10:22:01 +1100
committerjacqueline <me@jacqueline.id.au>2023-11-15 10:22:01 +1100
commit51d1cee3d70bac68e7bc735569e92bc584267f73 (patch)
treeb78090c8c85b672e5e5ad9cb84dcf1e7f01cba46 /src/lua/stubs
parent0cae95a71ee88aafe0a9fffe9ee310b708029146 (diff)
downloadtangara-fw-51d1cee3d70bac68e7bc735569e92bc584267f73.tar.gz
Set up ldoc and lua-language-server, write some module stubs
Diffstat (limited to 'src/lua/stubs')
-rw-r--r--src/lua/stubs/bluetooth.lua14
-rw-r--r--src/lua/stubs/playback.lua11
-rw-r--r--src/lua/stubs/power.lua18
-rw-r--r--src/lua/stubs/types.lua27
4 files changed, 70 insertions, 0 deletions
diff --git a/src/lua/stubs/bluetooth.lua b/src/lua/stubs/bluetooth.lua
new file mode 100644
index 00000000..f819c2f1
--- /dev/null
+++ b/src/lua/stubs/bluetooth.lua
@@ -0,0 +1,14 @@
+--- Properties and functions for handling Bluetooth connectivity
+-- @module bluetooth
+
+local bluetooth = {}
+
+-- Whether or not the Bluetooth stack is currently enabled. This property is writeable, and can be used to enable or disable Bluetooth.
+-- @treturn types.Property a boolean property
+function bluetooth.enabled() end
+
+--- Whether or not there is an active connection to another Bluetooth device.
+-- @treturn types.Property a boolean property
+function bluetooth.connected() end
+
+return bluetooth
diff --git a/src/lua/stubs/playback.lua b/src/lua/stubs/playback.lua
new file mode 100644
index 00000000..d32febae
--- /dev/null
+++ b/src/lua/stubs/playback.lua
@@ -0,0 +1,11 @@
+--- Properties for interacting with the audio playback system
+-- @module playback
+
+local playback = {}
+
+--- Whether or not any audio is *allowed* to be played. If there is a current track, then this is essentially an indicator of whether playback is paused or unpaused.
+--- This value isn't meaningful if there is no current track.
+-- @treturn types.Property a boolean property
+function playback.playing() end
+
+return playback
diff --git a/src/lua/stubs/power.lua b/src/lua/stubs/power.lua
new file mode 100644
index 00000000..30fe7520
--- /dev/null
+++ b/src/lua/stubs/power.lua
@@ -0,0 +1,18 @@
+--- Properties and functions that deal with the device's battery and power state
+-- @module power
+
+local power = {}
+
+--- battery_pct returns the battery's current charge as a percentage
+-- @treturn types.Property an integer property, from 0 to 100
+function power.battery_pct() end
+
+--- battery_millivolts returns the battery's current voltage in millivolts
+-- @treturn types.Property an integer property, typically from about 3000 to about 4200.
+function power.battery_millivolts() end
+
+--- plugged_in returns whether or not the device is currently receiving external power
+-- @treturn types.Property a boolean property
+function power.plugged_in() end
+
+return power \ No newline at end of file
diff --git a/src/lua/stubs/types.lua b/src/lua/stubs/types.lua
new file mode 100644
index 00000000..1f6970bd
--- /dev/null
+++ b/src/lua/stubs/types.lua
@@ -0,0 +1,27 @@
+--- Userdata-based types used throughout the rest of the API. These types are
+--- not generally constructable within Lua code.
+-- @module types
+
+--- A value sourced from the C++ firmware.
+-- @type Property
+local Property = {}
+
+--- Gets the current value
+-- @return The property's current value.
+function Property:get() end
+
+--- Sets a new value. Not all properties may be set from within Lua code. For
+--- example, it makes little sense to attempt to override the current battery
+--- level.
+-- @param val The new value. This should generally be of the same type as the existing value.
+-- @return true if the new value was applied, or false if the backing C++ code rejected the new value (e.g. if it was out of range, or the wrong type).
+function Property:set(val) end
+
+--- Invokes the given function once immediately with the current value, and then again whenever the value changes.
+--- The function is invoked for *all* changes; both from the underlying C++ data, and from calls to `set` (if this is a Lua-writeable property).
+--- The binding will be active **only** so long as the given function remains in scope.
+-- @param fn callback function to apply property values. Must accept one argument; the updated value.
+-- @return fn, for more ergonmic use with anonymous closures.
+function Property:bind(fn) end
+
+return Property