A class to use the Trill family of capacitive sensors. http://bela.io/trill.
More...
#include <Trill.h>
|
enum | Mode {
AUTO = -1,
CENTROID = 0,
RAW = 1,
BASELINE = 2,
DIFF = 3
} |
|
enum | Device {
NONE = -1,
ANY = 0,
BAR = 1,
SQUARE = 2,
CRAFT = 3,
RING = 4,
HEX = 5,
FLEX = 6,
UNKNOWN = ANY
} |
|
enum | EventMode { kEventModeTouch = 0,
kEventModeChange = 1,
kEventModeAlways = 2
} |
|
enum | ScanTriggerMode { kScanTriggerDisabled = 0x0,
kScanTriggerI2c = 0x1,
kScanTriggerTimer = 0x2,
kScanTriggerI2cOrTimer = 0x3
} |
|
|
| Trill (unsigned int i2c_bus, Device device, uint8_t i2c_address=255) |
|
int | setup (unsigned int i2c_bus, Device device=ANY, uint8_t i2c_address=255) |
|
int | updateBaseline () |
|
int | reset () |
|
int | readI2C (bool shouldReadStatusByte=false) |
| Read data from the device. More...
|
|
void | newData (const uint8_t *newData, size_t len, bool includesStatusByte=false) |
| Set data retrieved from the device. More...
|
|
Device | deviceType () |
|
int | firmwareVersion () |
|
Mode | getMode () |
|
uint8_t | getAddress () |
|
void | printDetails () |
|
void | setVerbose (int verbose) |
|
unsigned int | getNumChannels () const |
|
unsigned int | getDefaultNumChannels () const |
|
ssize_t | readBytes (void *buf, size_t count) |
|
ssize_t | writeBytes (const void *buf, size_t count) |
|
| I2c (I2c &&)=delete |
|
int | initI2C_RW (int bus, int address, int file) |
|
int | closeI2C () |
|
|
When the device is in RAW, BASELINE, or DIFF mode, the readings from the individual sensing channels are accessed through rawData.
|
std::vector< float > | rawData |
|
|
When the device is in CENTROID mode, touches are detected as discrete entities and can be retrieved with the methods in this section.
The location of a touch is a normalised value where 0 and 1 are the extremes of the axis.
The size of a touch is a rescaled value of the total activation measured on the sensing channels that contribute to the touch. The amount of activation for a touch of a given size is dependent (among other things) on the geometry of the device. The values used here have been determined empirically.
A compoundTouch is a single touch represntation obtained by averaging the location and size of the touches on each axis and their size. This is most useful for 2-axes devices, in order to get a single touch.
|
bool | is1D () |
|
bool | is2D () |
|
unsigned int | getBytesToRead (bool includesStatusByte) |
|
unsigned int | getNumButtons () |
|
unsigned int | getNumTouches () |
|
float | touchLocation (uint8_t touch_num) |
|
float | touchSize (uint8_t touch_num) |
|
unsigned int | getNumHorizontalTouches () |
|
float | touchHorizontalLocation (uint8_t touch_num) |
|
float | touchHorizontalSize (uint8_t touch_num) |
|
float | compoundTouchLocation () |
|
float | compoundTouchHorizontalLocation () |
|
float | compoundTouchSize () |
|
float | getButtonValue (uint8_t button_num) |
|
|
int | i2C_bus |
|
int | i2C_address |
|
int | i2C_file |
|
A class to use the Trill family of capacitive sensors. http://bela.io/trill.
- Examples:
- Trill/bar-led/render.cpp, Trill/bar-sound/render.cpp, Trill/bar-visual/render.cpp, Trill/craft-sound/render.cpp, Trill/craft-visual/render.cpp, Trill/custom-slider/render.cpp, Trill/flex-default/render.cpp, Trill/flex-visual/render.cpp, Trill/general-custom-address/render.cpp, Trill/general-print/render.cpp, Trill/general-settings/render.cpp, Trill/general-visual/render.cpp, Trill/hex-sound/render.cpp, Trill/hex-visual/render.cpp, Trill/multiple-devices/render.cpp, Trill/ring-sound/render.cpp, Trill/ring-visual/render.cpp, Trill/square-multitouch/render.cpp, Trill/square-sound/render.cpp, and Trill/square-visual/render.cpp.
The acquisition modes that a device can be set to.
Enumerator |
---|
AUTO |
Auto mode: the mode is set automatically based on the device type
|
CENTROID |
Centroid mode: detect discrete touches
|
RAW |
Raw mode
|
BASELINE |
Baseline mode
|
DIFF |
Differential mode
|
The types of Trill devices
Enumerator |
---|
NONE |
No device.
|
ANY |
A valid device of unknown type.
|
BAR |
Trill Bar
|
SQUARE |
Trill Square
|
CRAFT |
Trill Craft
|
RING |
Trill Ring
|
HEX |
Trill Hex
|
FLEX |
Trill Flex
|
UNKNOWN |
same as ANY, for backwards compatibility
|
Controls when the EVT pin will be set when a new frame is available. In this context, the meaning "activity is detected" depends on the Mode in which the device is:
- in CENTROID mode, activity is detected if one or more touches are detected
- in any other mode, activity is detected if any channel after formatting is non-zero.
Enumerator |
---|
kEventModeTouch |
Only set the EVT pin if activity is detected in the current frame.
|
kEventModeChange |
Only set the EVT pin if activity is detected in the current or past frame.
|
kEventModeAlways |
Set the EVT pin every time a new frame is available.
|
Enumerator |
---|
kScanTriggerDisabled |
Do not scan capacitive channels.
|
kScanTriggerI2c |
Scan capacitive channels after every I2C transaction.
|
kScanTriggerTimer |
Scan capacitive channels every time the timer set by setAutoScanInterval() expires.
|
kScanTriggerI2cOrTimer |
Scan capacitive channels after every I2C transaction or when timer expires, whichever comes first.
|
Trill::Trill |
( |
unsigned int |
i2c_bus, |
|
|
Device |
device, |
|
|
uint8_t |
i2c_address = 255 |
|
) |
| |
Initialise the device.
- Parameters
-
i2c_bus | the bus that the device is connected to. |
device | the device type. |
i2c_address | the address at which the device can be found. |
If device
is ANY then:
- if
i2c_address
is a valid address, then any device detected at that addres will be accepted
- if
i2c_address
is 255
or unspecified, then the range of valid addresses will be scanned, stopping at the first valid device encountered. Use this with caution as it may affect the behaviour of non-Trill devices on the I2C bus.
Otherwise, if i2c_address
is 255
or unspecified, the default address for the specified device type will be used.
int Trill::setup |
( |
unsigned int |
i2c_bus, |
|
|
Device |
device = ANY , |
|
|
uint8_t |
i2c_address = 255 |
|
) |
| |
Initialise the device.
- Parameters
-
i2c_bus | the bus that the device is connected to. |
device | the device type. |
i2c_address | the address at which the device can be found. |
If device
is ANY then:
- if
i2c_address
is a valid address, then any device detected at that addres will be accepted
- if
i2c_address
is 255
or unspecified, then the range of valid addresses will be scanned, stopping at the first valid device encountered. Use this with caution as it may affect the behaviour of non-Trill devices on the I2C bus.
Otherwise, if i2c_address
is 255
or unspecified, the default address for the specified device type will be used.
- Returns
- 0 on success or an error code otherwise.
- Examples:
- Trill/bar-led/render.cpp, Trill/bar-sound/render.cpp, Trill/bar-visual/render.cpp, Trill/craft-sound/render.cpp, Trill/craft-visual/render.cpp, Trill/custom-slider/render.cpp, Trill/flex-default/render.cpp, Trill/flex-visual/render.cpp, Trill/general-custom-address/render.cpp, Trill/general-print/render.cpp, Trill/general-settings/render.cpp, Trill/general-visual/render.cpp, Trill/hex-sound/render.cpp, Trill/hex-visual/render.cpp, Trill/ring-sound/render.cpp, Trill/ring-visual/render.cpp, Trill/square-multitouch/render.cpp, Trill/square-sound/render.cpp, and Trill/square-visual/render.cpp.
Trill::Device Trill::probe |
( |
unsigned int |
i2c_bus, |
|
|
uint8_t |
i2c_address |
|
) |
| |
|
static |
std::vector< std::pair< Trill::Device, uint8_t > > Trill::probeRange |
( |
unsigned int |
i2c_bus, |
|
|
size_t |
maxCount = 0 |
|
) |
| |
|
static |
Probe the bus for a device at any valid address.
- Warning
- Use with caution as it may affect the behaviour of non-Trill devices on the I2C bus.
- Parameters
-
i2c_bus | the I2C bus to scan |
maxCount | stop discovering new devices after this many have been discovered. Use 0 to find all possible devices. |
- Returns
- A vector containing the Device and address pairs identified.
int Trill::updateBaseline |
( |
| ) |
|
int Trill::reset |
( |
void |
| ) |
|
int Trill::readI2C |
( |
bool |
shouldReadStatusByte = false | ) |
|
Read data from the device.
Performs an I2C transaction with the device to retrieve new data and parse them. Users calling this method won't need to call newData().
- Parameters
-
shouldReadStatusByte | whether or not to read the status byte as part of the transaction. If the firmware version is lower than 3, this should be set to false . |
- Returns
- 0 on success or an error code otherwise.
- Examples:
- Trill/bar-led/render.cpp, Trill/bar-sound/render.cpp, Trill/bar-visual/render.cpp, Trill/craft-sound/render.cpp, Trill/craft-visual/render.cpp, Trill/custom-slider/render.cpp, Trill/flex-default/render.cpp, Trill/flex-visual/render.cpp, Trill/general-custom-address/render.cpp, Trill/general-print/render.cpp, Trill/general-settings/render.cpp, Trill/general-visual/render.cpp, Trill/hex-sound/render.cpp, Trill/hex-visual/render.cpp, Trill/multiple-devices/render.cpp, Trill/ring-sound/render.cpp, Trill/ring-visual/render.cpp, Trill/square-multitouch/render.cpp, Trill/square-sound/render.cpp, and Trill/square-visual/render.cpp.
void Trill::newData |
( |
const uint8_t * |
newData, |
|
|
size_t |
len, |
|
|
bool |
includesStatusByte = false |
|
) |
| |
Set data retrieved from the device.
Sets the data retrieved from the device. This can be used to pass to the object data retrieved elsewhere (e.g.: from an I2C DMA callback). Users calling readI2C() won't need to call this method.
- Parameters
-
newData | A pointer to an array containing new data. |
len | The length of the array. For proper operation, this should be the value returned from getBytesToRead(). |
includesStatusByte | whether newData includes the status byte or not. |
const std::string & Trill::getNameFromDevice |
( |
Device |
device | ) |
|
|
static |
Trill::Device Trill::getDeviceFromName |
( |
const std::string & |
name | ) |
|
|
static |
Get the device from the name.
const std::string & Trill::getNameFromMode |
( |
Mode |
mode | ) |
|
|
static |
Get the mode from the name.
Trill::Mode Trill::getModeFromName |
( |
const std::string & |
name | ) |
|
|
static |
Get the mode from the name.
int Trill::firmwareVersion |
( |
| ) |
|
|
inline |
Get the firmware version of the device.
uint8_t Trill::getAddress |
( |
| ) |
|
|
inline |
Get the current address of the device.
void Trill::printDetails |
( |
| ) |
|
Print details about the device to standard output
- Examples:
- Trill/bar-led/render.cpp, Trill/bar-sound/render.cpp, Trill/bar-visual/render.cpp, Trill/craft-sound/render.cpp, Trill/custom-slider/render.cpp, Trill/flex-default/render.cpp, Trill/general-custom-address/render.cpp, Trill/general-print/render.cpp, Trill/general-settings/render.cpp, Trill/general-visual/render.cpp, Trill/hex-sound/render.cpp, Trill/hex-visual/render.cpp, Trill/ring-sound/render.cpp, Trill/ring-visual/render.cpp, Trill/square-multitouch/render.cpp, Trill/square-sound/render.cpp, and Trill/square-visual/render.cpp.
void Trill::setVerbose |
( |
int |
verbose | ) |
|
Print more details about I/O transactions as they happen.
unsigned int Trill::getNumChannels |
( |
| ) |
const |
unsigned int Trill::getDefaultNumChannels |
( |
| ) |
const |
Get the number of capacitive channels available on the device.
int Trill::setMode |
( |
Mode |
mode | ) |
|
int Trill::setScanSettings |
( |
uint8_t |
speed, |
|
|
uint8_t |
num_bits = 12 |
|
) |
| |
Set the speed and bit depth of the capacitive scanning. This triggers a call to CSD_SetScanMode(speed, num_bits)
on the device.
- Parameters
-
speed | The speed of the scanning Valid values of speed are, ordered by decreasing speed, are comprised between 0 (CSD_ULTRA_FAST_SPEED ) and 3 (CSD_SLOW_SPEED ) |
num_bits | The bit depth of the scanning. Valid values are comprised between 9 and 16. |
- Returns
- 0 on success or an error code otherwise.
- Examples:
- Trill/craft-visual/render.cpp, Trill/flex-visual/render.cpp, and Trill/general-settings/render.cpp.
int Trill::setPrescaler |
( |
uint8_t |
prescaler | ) |
|
int Trill::setNoiseThreshold |
( |
float |
threshold | ) |
|
Set the noise threshold for the capacitive channels.
When a channel's scan returns a value smaller than the threshold, its value is set to 0.
- Parameters
-
threshold | the noise threshold level. Valid values are between 0 and 255.0/(1 << numBits) . The value is internally converted to an 8-bit integer by multiplying it times 1 << numBits before being sent to the device. On the device, the received value is used to set the CSD_bNoiseThreshold variable. |
- Returns
- 0 on success, or an error code otherwise.
- Examples:
- Trill/craft-visual/render.cpp, Trill/flex-visual/render.cpp, and Trill/general-settings/render.cpp.
int Trill::setIDACValue |
( |
uint8_t |
value | ) |
|
Sets the IDAC value for the device.
This triggers a call to CSD_SetIdacValue(value)
on the device.
- Parameters
-
value | the IDAC value. Valid values are between 0 and 255. |
- Returns
- 0 on success or an error code otherwise.
int Trill::setMinimumTouchSize |
( |
float |
minSize | ) |
|
Set minimum touch size
Sets the minimum touch size below which a touch is ignored.
- Returns
- 0 on success or an error code otherwise.
- Examples:
- Trill/bar-visual/render.cpp.
Set how the device triggers a new scan of its capacitive channels.
- Parameters
-
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and it will return an error.
- Returns
- 0 on success or an error code otherwise.
- Examples:
- Trill/general-settings/render.cpp.
int Trill::setTimerPeriod |
( |
float |
ms | ) |
|
Set the interval for scanning capacitive channels when the device's scanning is triggered by the timer.
- Parameters
-
ms | the scanning period, measured in milliseconds. The effective minimum scanning period will be limited by the scanning speed, bit depth and any computation happening on the device (such as touch detection). Granularity is 1 ms for values until 255 ms and higher after that. Maximum value is just above 2032 ms. Scanning on timer has to be separately enabled via setScanTrigger(). When ms is not greater than zero, the timer is disabled. |
- Note
- The 32kHz clock often deviates by 10% or more from its nominal frequency, thus affecting the accuracy of the timer.
- Examples:
- Trill/general-settings/render.cpp.
int Trill::setAutoScanInterval |
( |
uint16_t |
interval | ) |
|
Deprecated. Same as setTimerPeriod(), but the interval
is expressed as cycles of a 32kHz clock. On devices with firmware 2, interval
is used directly. On devices with firwmare 3 or above, it is quantised to blocks of at least 1 ms.
Set how the EVT pin behaves.
- Parameters
-
mode | an EventMode denoting the required behaviour. |
- Returns
- 0 on success or an error code otherwise.
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and it will return an error.
- Examples:
- Trill/general-settings/render.cpp.
int Trill::setChannelMask |
( |
uint32_t |
mask | ) |
|
Set a channel mask identifying which scanning channels are enabled.
- Parameters
-
mask | The channel mask. Bits 0 to 31 identify channels 0 to 31 respectively. Bit positions higher than the value returned by getDefaultNumChannels() are ignored. |
- Returns
- 0 on success or an error code otherwise.
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and it will return an error.
- Examples:
- Trill/general-settings/render.cpp.
int Trill::setTransmissionFormat |
( |
uint8_t |
width, |
|
|
uint8_t |
shift |
|
) |
| |
Set the format used for transmission of non-centroid data from the device to the host.
- Parameters
-
width | The data width. If a value would overflow when stored, it is clipped. |
shift | Number of right shift operations applied on the value before being stored in the word. |
- Returns
- 0 on success or an error code otherwise.
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and it will return an error.
- Examples:
- Trill/general-settings/render.cpp.
int Trill::readStatusByte |
( |
| ) |
|
Read the status byte from the device. Alternatively, the status byte can be read as part of reading data by calling readI2C(true).
- Returns
- the status byte, or a negative value in case of error. As a successful call also updates the internal state, the caller is probably better off calling getFrameId(), hasActivity(), hasReset() instead of parsing the status byte directly.
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and its return value is undefined.
Whether the device has reset since a identify command was last written to it.
This relies on a current status byte.
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and it will return an error.
- Examples:
- Trill/general-settings/render.cpp.
bool Trill::hasActivity |
( |
| ) |
|
Whether activity has been detected in the current frame.
This relies on a current status byte.
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and its return value is undefined.
- Examples:
- Trill/general-settings/render.cpp.
uint8_t Trill::getFrameId |
( |
| ) |
|
Get the frameId. This relies on a current status byte.
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and its return value is undefined.
- Examples:
- Trill/general-settings/render.cpp.
uint32_t Trill::getFrameIdUnwrapped |
( |
| ) |
|
Same as above, but it tries to unwrap the 6-bit frameId into a uint32_t counter. This relies on reading several status bytes over time. The counter is guaranteed monotonic, but it can only be regarded as an actual frame counter if the status byte is read at least once every 63 frames.
- Returns
- the counter
- Note
- This feature is only available with devices starting from firmware version 3. On older devices calling this function has no effect and its return value is undefined.
- Examples:
- Trill/general-settings/render.cpp.
Does the device have one axis of position sensing?
- Returns
true
if the device has one axis of position sensing and is set in CENTROID mode, false
otherwise.
unsigned int Trill::getBytesToRead |
( |
bool |
includesStatusByte | ) |
|
Return the number of bytes to read when reading data.
unsigned int Trill::getNumButtons |
( |
| ) |
|
|
inline |
Return the number of "button" channels on the device.
unsigned int Trill::getNumTouches |
( |
| ) |
|
float Trill::touchLocation |
( |
uint8_t |
touch_num | ) |
|
float Trill::touchSize |
( |
uint8_t |
touch_num | ) |
|
unsigned int Trill::getNumHorizontalTouches |
( |
| ) |
|
float Trill::touchHorizontalLocation |
( |
uint8_t |
touch_num | ) |
|
float Trill::touchHorizontalSize |
( |
uint8_t |
touch_num | ) |
|
Get the size of a touch.
- Note
- It is only valid to call this method is2D() returns
true
- Returns
- the size of the touch, if the touch exists, or 0 otherwise.
float Trill::compoundTouchLocation |
( |
| ) |
|
float Trill::compoundTouchHorizontalLocation |
( |
| ) |
|
float Trill::compoundTouchSize |
( |
| ) |
|
float Trill::getButtonValue |
( |
uint8_t |
button_num | ) |
|
Get the value of the capacitive "button" channels on the device
- Parameters
-
button_num | the button number. Valid values are comprised between 0 and getNumButtons() - 1 . |
- Returns
- The differential reading on the button, normalised between 0 and 1.
std::vector<float> Trill::rawData |
constexpr uint8_t Trill::speedValues = {0, 1, 2, 3} |
|
static |
constexpr uint8_t Trill::prescalerMax = 8 |
|
static |
The documentation for this class was generated from the following files:
- libraries/Trill/Trill.h
- libraries/Trill/Trill.cpp