Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
Trill.h
1 #include <I2c.h>
2 #include <stdint.h>
3 
4 class Trill : public I2c
5 {
6  private:
7 
8  enum {
9  kCommandNone = 0,
10  kCommandMode = 1,
11  kCommandScanSettings = 2,
12  kCommandPrescaler = 3,
13  kCommandNoiseThreshold = 4,
14  kCommandIdac = 5,
15  kCommandBaselineUpdate = 6,
16  kCommandMinimumSize = 7,
17  kCommandIdentify = 255
18  };
19 
20  enum {
21  kOffsetCommand = 0,
22  kOffsetData = 4
23  };
24 
25  enum {
26  kNormalLengthDefault = 20,
27  kNormalLength2D = 32,
28  kRawLength = 60
29  };
30 
31  enum {
32  kMaxTouchNum1D = 5,
33  kMaxTouchNum2D = 4
34  };
35 
36  enum {
37  kNumSensorsBar = 26,
38  kNumSensors = 30
39  };
40 
41  bool preparedForDataRead_ = false;
42  uint8_t device_type_; // Which type of device is connected (if any)
43  uint8_t firmware_version_; // Firmware version running on the device
44  uint8_t num_touches_; // Number of touches on last read
45  uint8_t mode_; // Which mode the device is in
46 
47  uint8_t dataBuffer[kRawLength];
48  uint16_t commandSleepTime = 10000;
49 
50  public:
51  int rawData[kNumSensors];
52 
53  enum Modes {
54  NORMAL = 0,
55  RAW = 1,
56  BASELINE = 2,
57  DIFF = 3
58  };
59 
60  enum Devices {
61  NONE = 0,
62  ONED = 1,
63  TWOD = 2
64  };
65 
66  Trill();
67  ~Trill();
68  Trill(int i2c_bus, int i2c_address, int mode);
69  int setup(int i2c_bus = 1, int i2c_address = 0x18, int mode = NORMAL);
70  int setup(int i2c_bus, int i2c_address, int mode, int threshold, int prescaler);
71  void cleanup();
72 
73  bool isReady(){ return preparedForDataRead_; }
74 
75  /* Update the baseline value on the sensor*/
76  int updateBaseLine();
77  int prepareForDataRead();
78  int readI2C(); // This should maybe be renamed readRawData()
79  int readLocations();
80  /* Return the type of the device attached or 0 if none is attached */
81  int deviceType() { return device_type_; }
82  int firmwareVersion() { return firmware_version_; }
83  int getMode() { return mode_; }
84  int identify();
85  void printDetails() {
86  printf("Device type: %d\n", deviceType());
87  printf("Firmware version: %d\n", firmwareVersion());
88  };
89  int numSensors();
90 
91  /* --- Scan configuration settings --- */
92  int setMode(uint8_t mode);
93  int setScanSettings(uint8_t speed, uint8_t num_bits = 12);
94  int setPrescaler(uint8_t prescaler);
95  int setNoiseThreshold(uint8_t threshold);
96  int setIDACValue(uint8_t value);
97  int setMinimumTouchSize(uint16_t size);
98 
99  /* --- Touch-related information --- */
100  int numberOfTouches();
101  int numberOfHorizontalTouches();
102  int touchLocation(uint8_t touch_num);
103  int touchSize(uint8_t touch_num);
104  /* Only for 2D sensors */
105  int touchHorizontalLocation(uint8_t touch_num);
106  int touchHorizontalSize(uint8_t touch_num);
107 
108 };
Definition: I2c.h:23
Definition: Trill.h:4