Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Trill.h
1 #pragma once
2 #include <I2c.h>
3 #include <stdint.h>
4 #include <string>
5 #include <vector>
6 
13 class Trill : public I2c
14 {
15  public:
19  typedef enum {
20  AUTO = -1,
22  CENTROID = 0,
23  RAW = 1,
24  BASELINE = 2,
25  DIFF = 3,
26  } Mode;
27 
31  typedef enum {
32  NONE = -1,
33  UNKNOWN = 0,
34  BAR = 1,
35  SQUARE = 2,
36  CRAFT = 3,
37  RING = 4,
38  HEX = 5,
39  FLEX = 6,
40  } Device;
41  private:
42  Mode mode_; // Which mode the device is in
43  Device device_type_ = NONE; // Which type of device is connected (if any)
44  uint8_t address;
45  uint8_t firmware_version_; // Firmware version running on the device
46  uint8_t num_touches_; // Number of touches on last read
47  std::vector<uint8_t> dataBuffer;
48  uint16_t commandSleepTime = 10000;
49  bool preparedForDataRead_ = false;
50  unsigned int numBits;
51  float posRescale;
52  float posHRescale;
53  float sizeRescale;
54  float rawRescale;
55  int identify();
56  void updateRescale();
57  void parseNewData();
58  bool readErrorOccurred;
59  public:
84  std::vector<float> rawData;
91  static constexpr uint8_t speedValues[4] = {0, 1, 2, 3};
95  static constexpr uint8_t prescalerMax = 8;
96  Trill();
97  ~Trill();
112  Trill(unsigned int i2c_bus, Device device, uint8_t i2c_address = 255);
118  int setup(unsigned int i2c_bus, Device device, uint8_t i2c_address = 255);
119 
126  static Device probe(unsigned int i2c_bus, uint8_t i2c_address);
127 
131  int updateBaseline();
132 
139  int readI2C();
140 
152  void newData(const uint8_t* newData, size_t len);
153 
161  int prepareForDataRead();
165  Device deviceType() { return device_type_; }
169  static const std::string& getNameFromDevice(Device device);
173  static Device getDeviceFromName(const std::string& name);
177  static const std::string& getNameFromMode(Mode mode);
181  static Mode getModeFromName(const std::string& name);
185  int firmwareVersion() { return firmware_version_; }
189  Mode getMode() { return mode_; }
193  uint8_t getAddress() { return address; }
197  void printDetails() ;
201  unsigned int getNumChannels();
202 
219  int setMode(Mode mode);
232  int setScanSettings(uint8_t speed, uint8_t num_bits = 12);
243  int setPrescaler(uint8_t prescaler);
258  int setNoiseThreshold(float threshold);
267  int setIDACValue(uint8_t value);
275  int setMinimumTouchSize(float minSize);
286  int setAutoScanInterval(uint16_t interval); // end of Scan Configuration Settings
288 
326  bool is1D();
334  bool is2D();
338  unsigned int getNumButtons() { return 2 * (getMode() == CENTROID && RING == deviceType());};
345  unsigned int getNumTouches();
357  float touchLocation(uint8_t touch_num);
366  float touchSize(uint8_t touch_num);
373  unsigned int getNumHorizontalTouches();
385  float touchHorizontalLocation(uint8_t touch_num);
394  float touchHorizontalSize(uint8_t touch_num);
401  float compoundTouchLocation();
415  float compoundTouchSize();
425  float getButtonValue(uint8_t button_num);
426  // end of centroid mode
428 };
bool is1D()
Definition: Trill.cpp:532
bool is2D()
Definition: Trill.cpp:547
static Device getDeviceFromName(const std::string &name)
Definition: Trill.cpp:218
int setAutoScanInterval(uint16_t interval)
Definition: Trill.cpp:420
Trill Bar
Definition: Trill.h:34
unsigned int getNumChannels()
Definition: Trill.cpp:673
static Device probe(unsigned int i2c_bus, uint8_t i2c_address)
Definition: Trill.cpp:177
float touchHorizontalLocation(uint8_t touch_num)
Definition: Trill.cpp:616
int setMode(Mode mode)
Definition: Trill.cpp:306
int firmwareVersion()
Definition: Trill.h:185
Definition: Trill.h:22
void printDetails()
Definition: Trill.cpp:299
unsigned int getNumButtons()
Definition: Trill.h:338
float touchHorizontalSize(uint8_t touch_num)
Definition: Trill.cpp:629
Definition: Trill.h:25
int updateBaseline()
Definition: Trill.cpp:435
float touchSize(uint8_t touch_num)
Definition: Trill.cpp:603
Definition: I2c.h:23
Mode getMode()
Definition: Trill.h:189
static const std::string & getNameFromMode(Mode mode)
Definition: Trill.cpp:230
int setup(unsigned int i2c_bus, Device device, uint8_t i2c_address=255)
Definition: Trill.cpp:99
std::vector< float > rawData
Definition: Trill.h:84
Trill Square
Definition: Trill.h:35
Trill Craft
Definition: Trill.h:36
float compoundTouchSize()
Definition: Trill.cpp:665
float compoundTouchLocation()
Definition: Trill.cpp:655
Definition: Trill.h:24
Device
Definition: Trill.h:31
int setIDACValue(uint8_t value)
Definition: Trill.cpp:384
int setPrescaler(uint8_t prescaler)
Definition: Trill.cpp:347
Trill Ring
Definition: Trill.h:37
No device.
Definition: Trill.h:32
float compoundTouchHorizontalLocation()
Definition: Trill.cpp:660
static constexpr uint8_t speedValues[4]
Definition: Trill.h:91
A class to use the Trill family of capacitive sensors. http://bela.io/trill.
Definition: Trill.h:13
int setMinimumTouchSize(float minSize)
Definition: Trill.cpp:399
int prepareForDataRead()
Prepare the device so that successive reads will return data.
Definition: Trill.cpp:450
static constexpr uint8_t prescalerMax
Definition: Trill.h:95
int setNoiseThreshold(float threshold)
Definition: Trill.cpp:362
unsigned int getNumHorizontalTouches()
Definition: Trill.cpp:569
int readI2C()
Read data from the device.
Definition: Trill.cpp:467
Trill Hex
Definition: Trill.h:38
Definition: Trill.h:23
float getButtonValue(uint8_t button_num)
Definition: Trill.cpp:591
Mode
Definition: Trill.h:19
A valid device of unknown type.
Definition: Trill.h:33
Trill Flex
Definition: Trill.h:39
static Mode getModeFromName(const std::string &name)
Definition: Trill.cpp:239
unsigned int getNumTouches()
Definition: Trill.cpp:560
float touchLocation(uint8_t touch_num)
Definition: Trill.cpp:578
static const std::string & getNameFromDevice(Device device)
Definition: Trill.cpp:194
int setScanSettings(uint8_t speed, uint8_t num_bits=12)
Definition: Trill.cpp:324
void newData(const uint8_t *newData, size_t len)
Set data retrieved from the device.
Definition: Trill.cpp:495
Device deviceType()
Definition: Trill.h:165
uint8_t getAddress()
Definition: Trill.h:193
Definition: Trill.h:20