A package for interfacing with TriLightSense by LumenRadio
Project description
lr-tls - TriLightSense API
A package for interfacing with TriLightSense by LumenRadio.
Installation
Using pip
python3 -m pip install lr-tls
Using a requirements.txt file
In your requirements.txt add
lr-tls
Usage
Calibration
Connect the TLS hardware and invoke the command line tool tls calibrate to initiate a calibration of the connected TLS board.
Example code:
$ tls calibrate --device /dev/ttyACM0 --config-file tls.json --channels 0,1,2
Both tls calibrate and tls sample support --format rich (default, human-readable) or --format json for machine-readable output.
Sampling
Use tls sample to take a single color sample on a channel without going through the full calibration flow:
$ tls sample --device /dev/ttyACM0 --channel 0 --duration 0.1
Add --format json for machine-readable output.
Configuration
Use tls config to read or change the board's persistent configuration
(settings are stored on the board and survive power cycles).
Read the current configuration:
$ tls config --device /dev/ttyUSB0
Change one or more settings (only the ones you pass are written):
$ tls config --device /dev/ttyUSB0 --sensitivity 8 --led-state 0
| Option | Values |
|---|---|
--output-format |
0 = 8-bit RGB strings, 1 = 16-bit integer arrays |
--sensitivity |
0 (low) .. 8 (high) |
--led-state |
0 = off, 1 = on |
--measuring-state |
0 = off, 1 = on |
Reset the board to factory defaults with --factory-reset. Add
--format json for machine-readable output.
Pattern matching
lr-tls supports looking for blink patterns with different colors. The colors are specified in the configuration file. Use tls calibrate
to generate such a file.
Example of measuring normalized color:
You may use config_from_string to configure the TriLightSense object with a json string.
example.py
from lr_tls import TriLightSense
tls = TriLightSense()
tls.config_from_string("{\"SAMPLE_RATE\": 150}")
with tls.open("/dev/ttyACM0") as tls:
color = tls.sample(channel = 0, duration_sec = 0.1)
print(f"Color on channel 0 was {color}")
Example of looking for green blink and steady blue indication:
For more complex configuration with colors you can use config_from_file to configure the TriLightSense object.
config.json
{
"SAMPLE_RATE": 150,
"off-0": "000000",
"off-1": "000000",
"green-0": "2D8132",
"blue-1": "111379"
}
example.py
from lr_tls import TriLightSense
tls = TriLightSense()
tls.config_from_file("config.json")
with tls.open("/dev/ttyACM0") as tls:
green_blink = tls.create_pattern("500 off 500 green 500 off", 0)
if tls.expect([green_blink, None, None], timeout_sec=10.0):
print("Got green blink on channel 0!")
blue_indication = tls.create_pattern("100 blue", 1)
if tls.expect([None, blue_indication, None], timeout_sec=10.0):
print("Detected blue light on channel 1!")
NOTE: When looking for a cyclic pattern - Start and end any blink pattern with the same color where the ending is the start of the new cycle.
Considerations
When using this library there are four parameters to consider.
- Interval range - In what ranges are the library and hardware guaranteed to detect a given pattern?
- Detection timeout or
timeout_sec- Given a pattern, how long do I need to look for it to be guaranteed to detect it? - Acception interval - How much can the expected and actual pattern differ and be guaranteed to be accepted?
- Rejection interval - How much can the expected and actual pattern differ and be guaranteed to be rejected?
Interval range
Pattern recognition is guaranteed for patterns with 50% duty cycle and repeat cycle of 600ms to 3000ms.
Detection timeout for a specific frequency
If the blink is slow you'll need a longer timeout. Good rule of thumb is three times the pattern length.
I.e 1500 off red 1500 has a pattern repeat cycle of 3s and therefore require 9s timeout
Guaranteeed Acception Interval
The pattern recognition is guaranteed when the expected and actual pattern differ less than 50ms.
Guaranteed Rejection Interval
Pattern rejection is guaranteed when the expected and actual pattern differs more than 400ms.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lr_tls-0.5.0.tar.gz.
File metadata
- Download URL: lr_tls-0.5.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03c61e7458e3c772b45917b6723bf077e651953d53585af711fea4bcba59ab3a
|
|
| MD5 |
9b283682223ab61630f8ab3dce896d40
|
|
| BLAKE2b-256 |
2cef9cd46297e6e21ae156d4a154bd2efe261f28a64653a4943dd694b99ee9df
|
File details
Details for the file lr_tls-0.5.0-py3-none-any.whl.
File metadata
- Download URL: lr_tls-0.5.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cac2716244653922c8ef8f1bbc841fcd878e8a0316b9ae0689363c284a7db422
|
|
| MD5 |
7e92281df4f15896ef84a8ee8d811676
|
|
| BLAKE2b-256 |
18bd9b780322a97f480ef9a165bac8e3a997ee16ee2281c4e94902740e2cf308
|