talalib.py is a small python module that allows easy interaction with the sensors used on the Tala project, without the need to know GPIO commands, PIL, etc..
- Screen - OLED SSD1306 (128x64)
- Radio Module - HC-12 SI4463
- Keypad - 4x3 Keypad
import talalib
tala = talalib.Tala()
Get the user to select from a list of items. The first parameter of the function is the list of strings to ask the user to select, the output of the function will be one of the items in the list as a string.
tala.menu(["Item 1", "Item 2", "Item 3"])
# -> "Item 1"
This shows a message to the user. The first parameter of the function is the title of the message as a string and the second parameter is the body of the message, if the body is too long to fit on screen, the user can scroll using the up and down keys. The user needs to manually dismiss a message!
tala.message("Example", "This is an example popup!")
Input a title then a body.
This is similar to the above message
method, but does not require user input to
be dismissed (the screen needs to be cleared to remove it). The title parameter
is optional but body is required. After calling this function, you might want
tala.singlebutton()
to get user input.
tala.popup("Popup", "You have mail!")
tala.popup(body="You have mail!")
This uses the above popup
method and combines it with singlebutton
to ask the
user a yes/no question. The question parameter is required and needs to be a
string.
tala.yn("Do you like ice cream")
This waits for a button on the keypad to be pressed, then returns the button as a string (0-9, #, *).
tala.singlebutton()
# -> "1"
This allows the user to type on the keypad by holding a key to cycle through the
letters and unpressing to type the letter that is currently on the screen. The
user can then press the #
button to enter the text. An optional parameter is
wait
which is how fast move onto the next letter in the sequence when the button
is held down in seconds (the default is 0.5
). The function returns the message
as a string.
tala.type()
# -> "Hello World!"
This sends a message via the HC-12 module. The first and only parameter is the message to send as a string, there is no output.
tala.send("Hello World!")
This waits for a message to be received via the HC-12 module. There are no parameters and the output is the message received as a string.
tala.waitForReceive()
# -> "Hello World!"
This receives a message from the HC-12 module. There are no parameters and the
output will be the message as a string. The string may be empty, in which case
no message has been received. waitForReceive()
is the output of this command,
but in a loop.
tala.receive()
# -> "Hello World!"
This cleans up the GPIO pins. This should be run when the program quits.
tala.cleanup()
This clears the screen.
tala.clear()