-
Notifications
You must be signed in to change notification settings - Fork 5
Lua Scripting API
print(text)
Shows text in the console.
sleep(seconds)
Pauses the script for a number of seconds, floating point numbers can be used.
delay(microseconds)
Pauses the script for a number of microseconds.
seconds()
Returns the number of seconds since 1-Jan-1970. Can be used for timing or animations.
millis()
Returns the number of milliseconds since 1-Jan-1970. Can be used for timing or animations.
min(a, b)
Returns the smaller of 2 numbers.
max(a, b)
Returns the bigger of 2 numbers.
abs(a)
Returns the absolute value of a.
constrain(x, min, max)
Returns x if x is between min and max. If x is smaller than min, min is returned. If x is larger than max, max is returned.
map(x, in_min, in_max, out_min, out_max)
Maps a number from an input range [in_min; in_max] to an output range [out_min, out_max]. Useful for interpolation.
rising_edge(identifier, value)
Helper function to detect a rising edge of a signal (e.g. button, key, capacitive touch pad, etc). Identifier is an arbitrary string that is used to distinguish between different signals. Internally, it's used as a key for the dictionary that keeps track of different signals.
Usage:
if rising_edge("mybutton", UI:is_key_pressed("up")) then
-- Do something
end
falling_edge(identifier, value)
Helper function to detect a falling edge of a signal (e.g. button, key, capacitive touch pad, etc). Identifier is an arbitrary string that is used to distinguish between different signals. Internally, it's used as a key for the dictionary that keeps track of different signals.
Usage:
if falling_edge("mybutton", UI:is_key_pressed("up")) then
-- Do something
end
UI:init()
Starts the UI library on the client
UI:add_button(name, caption, icon, toggle=false)
Adds a new button. Name is a unique identifier for the button. Caption is the text that's shown on the button. Icon lets you define a font-awesome icon. If toggle is true, the button can be clicked once to activate it, and then click it again to deactivate it.
UI:add_key(key)
Tells the UI to listen for certain key presses. Possible values: "up", "down", "left", "right", "space", "a", "b", ... "z".
UI:is_button_pressed(name)
Returns true if the button is pressed.
UI:is_key_pressed(key)
Returns true if the key is pressed.
Sound:say_tts(text, generate_only=False)
Takes a string of text, converts it using the PicoTTS engine, and plays it. Wave files are buffered in /tmp/OnoTTS/.wav. First call blocks while PicoTTS generates the .wav, this may take about a second. Subsequent calls of the same text return immediately. If you wish to avoid this, sound files can be generated on beforehand by using generate_only=True.
Sound:play_file(filename)
Plays a sound file. Files can be added using the Sounds app.
Hardware:spi_command(cmd, params=None, returned=0, delay=0)
Send a command over the SPI bus to the ATmega328. Optionally reads the result buffer and returns those bytes.
Hardware:ping()
Returns True if OnoHAT rev3 is connected.
Hardware:reset()
Resets the ATmega328, MPR121 and PCA9685.
Hardware:led_on()
Turns status LED on.
Hardware:led_off()
Turns status LED off.
Hardware:i2c_detect(addr)
Returns True if an I2C device is found at a particular address.
Hardware:i2c_read8(addr, reg)
Read a byte from an I2C device.
Hardware:i2c_write8(addr, reg, data)
Write a byte to an I2C device.
Hardware:i2c_read16(addr, reg)
Read 2 bytes from an I2C device.
Hardware:i2c_write16(addr, reg, data)
Write 2 bytes to an I2C device.
Hardware:servo_init()
Set up the PCA9685 for driving servos.
Hardware:servo_enable()
Turns on the servo power MOSFET, enabling all servos.
Hardware:servo_disable()
Turns off the servo power MOSFET, disabling all servos.
Hardware:servo_neutral()
Set all servos to 1500us.
Hardware:servo_set(channel, pos)
Set the position of one servo.
Pos in us, 500 to 2500
Hardware:servo_set_all(pos_list)
Set position of all 16 servos using a list.
Hardware:cap_init(electrodes)
Initialize the MPR121 capacitive touch sensor. Electrodes defines the number of electrodes that will be read. Electrodes=5 means that E0 to E4 will be read.
Hardware:cap_set_threshold(channel, touch, release)
Set an electrode's touch and release threshold.
Hardware:cap_get_filtered_data()
Get list of electrode filtered data (10 bits per electrode).
Hardware:cap_get_baseline_data()
Get list of electrode baseline data. Result is 10 bits, but the 2 least significant bits are set to 0.
Hardware:cap_get_touched()
Returns the values of the touch registers, each bit corresponds to one electrode.
Hardware:neo_init(num_leds)
Initialize the NeoPixel library.
Hardware:neo_set_brightness(brightness)
Set the NeoPixel's global brightness, 0-255.
Hardware:neo_show()
Sends the pixel data from the ATmega328 to the NeoPixels.
Hardware:neo_set_pixel(pixel, r, g, b)
Set the color of a single pixel.
Hardware:neo_set_range(start, end, r, g, b)
Set the color of a range of pixels.
Hardware:neo_set_all(r, g, b)
Set the color of the entire strip.
Hardware:neo_set_pixel_hsv(pixel, h, s, v)
Set the HSV color of a single pixel.
Hardware:neo_set_range_hsv(start, end, h, s, v)
Set the HSV color of a range of pixels.
Hardware:neo_set_all_hsv(h, s, v)
Set the HSV color of the entire strip.
Hardware:ana_read_channel(channel)
Reads the value of a single analog channel.
Hardware:ana_read_all_channels()
Reads all analog channels and returns them as a list.
Expression:set_emotion_val_ar(valence, arousal, anim_time=0)
Sets the emotion using valence (-1 to +1) and arousal (-1 to +1). Anim_time is the time (in seconds) it should take to animate the facial expression.
Expression:set_emotion_r_phi(r, phi, degrees=False, anim_time=0)
Sets the emotion using r (0.0 to 1.0) and phi. If degrees=true, phi is interpeted in degrees, otherwise, it is interpreted as radians. Anim_time is the time (in seconds) it should take to animate the facial expression.
Expression:update()
Calculates the new DOF positions and sends them to the hardware.
Expression:empty_config()
Clear the configuration of the Expression system.
Expression:load_config()
Reload the configuration from the config files.
Expression.servos[].pin
Expression.servos[].dofname
Expression.servos[].min_range
Expression.servos[].mid_pos
Expression.servos[].max_range
Expression.dofs[].overlays:append(fn)
Expression.dofs[]:calc(phi, r)
anim = Animate:new(times, values)
Class to facilitate the tweening of values in time. The animation starts when the object is created. Once ended, the call method will return the last item in values.
times: A list of timestamps in seconds, in increasing order. Timestamp 0 is the moment the Animate object was created.
values: A list of numerical values associated with timestamps. First element should be 0.
anim()
Calculates and returns the current value of the animation.
anim:has_ended()
Returns true if the animation has ended.
anim_p = AnimatePeriodic(times, values)
Class to facilitate the tweening of values in time. The animation starts when the object is created. This class is a variant of the Animate class that does not end, but instead repeats its pattern indefinitely.
times: A list of timestamps in seconds, in increasing order. timestamp 0 is the moment the Animate object was created.
values: A list of numerical values associated with timestamps. First element should be 0.
anim_p()
Calculates and returns the current value of the periodic animation.