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 prepareForDataRead();
56  int identify();
57  void updateRescale();
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 
138  int readI2C();
139 
143  Device deviceType() { return device_type_; }
147  static const std::string& getNameFromDevice(Device device);
151  static Device getDeviceFromName(const std::string& name);
155  static const std::string& getNameFromMode(Mode mode);
159  static Mode getModeFromName(const std::string& name);
163  int firmwareVersion() { return firmware_version_; }
167  Mode getMode() { return mode_; }
171  uint8_t getAddress() { return address; }
175  void printDetails() ;
179  unsigned int getNumChannels();
180 
197  int setMode(Mode mode);
210  int setScanSettings(uint8_t speed, uint8_t num_bits = 12);
221  int setPrescaler(uint8_t prescaler);
236  int setNoiseThreshold(float threshold);
245  int setIDACValue(uint8_t value);
253  int setMinimumTouchSize(float minSize);
264  int setAutoScanInterval(uint16_t interval); // end of Scan Configuration Settings
266 
304  bool is1D();
312  bool is2D();
316  unsigned int getNumButtons() { return 2 * (getMode() == CENTROID && RING == deviceType());};
323  unsigned int getNumTouches();
335  float touchLocation(uint8_t touch_num);
344  float touchSize(uint8_t touch_num);
351  unsigned int getNumHorizontalTouches();
363  float touchHorizontalLocation(uint8_t touch_num);
372  float touchHorizontalSize(uint8_t touch_num);
379  float compoundTouchLocation();
393  float compoundTouchSize();
403  float getButtonValue(uint8_t button_num);
404  // end of centroid mode
406 };
bool is1D()
Definition: Trill.cpp:523
bool is2D()
Definition: Trill.cpp:538
static Device getDeviceFromName(const std::string &name)
Definition: Trill.cpp:219
int setAutoScanInterval(uint16_t interval)
Definition: Trill.cpp:420
Trill Bar
Definition: Trill.h:34
unsigned int getNumChannels()
Definition: Trill.cpp:664
static Device probe(unsigned int i2c_bus, uint8_t i2c_address)
Definition: Trill.cpp:178
float touchHorizontalLocation(uint8_t touch_num)
Definition: Trill.cpp:607
int setMode(Mode mode)
Definition: Trill.cpp:306
int firmwareVersion()
Definition: Trill.h:163
Definition: Trill.h:22
void printDetails()
Definition: Trill.cpp:299
unsigned int getNumButtons()
Definition: Trill.h:316
float touchHorizontalSize(uint8_t touch_num)
Definition: Trill.cpp:620
Definition: Trill.h:25
int updateBaseline()
Definition: Trill.cpp:435
float touchSize(uint8_t touch_num)
Definition: Trill.cpp:594
Definition: I2c.h:23
Mode getMode()
Definition: Trill.h:167
static const std::string & getNameFromMode(Mode mode)
Definition: Trill.cpp:231
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:656
float compoundTouchLocation()
Definition: Trill.cpp:646
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:651
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
static constexpr uint8_t prescalerMax
Definition: Trill.h:95
int setNoiseThreshold(float threshold)
Definition: Trill.cpp:362
unsigned int getNumHorizontalTouches()
Definition: Trill.cpp:560
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:582
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:240
unsigned int getNumTouches()
Definition: Trill.cpp:551
float touchLocation(uint8_t touch_num)
Definition: Trill.cpp:569
static const std::string & getNameFromDevice(Device device)
Definition: Trill.cpp:195
int setScanSettings(uint8_t speed, uint8_t num_bits=12)
Definition: Trill.cpp:324
Device deviceType()
Definition: Trill.h:143
uint8_t getAddress()
Definition: Trill.h:171
Definition: Trill.h:20