-
Notifications
You must be signed in to change notification settings - Fork 12
/
TICL.h
97 lines (84 loc) · 2.18 KB
/
TICL.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*************************************************
* TICL.h - Core of ArTICL library for linking *
* TI calculators and Arduinos. *
* Created by Christopher Mitchell, *
* 2011-2019, all rights reserved. *
*************************************************/
#ifndef TICL_H
#define TICL_H
#include "Arduino.h"
#include "HardwareSerial.h"
#define TIMEOUT 100000l // microseconds (100ms)
#define GET_ENTER_TIMEOUT 1000000l // microseconds (1s)
#if defined(__MSP432P401R__) // MSP432 target
#define DEFAULT_TIP 17 // Tip = red wire (GPIO 5.7)
#define DEFAULT_RING 37 // Ring = white wire (GPIO 5.6)
#else // Arduino target
#define DEFAULT_TIP 2 // Tip = red wire
#define DEFAULT_RING 3 // Ring = white wire
#endif
enum TICLErrors {
ERR_READ_TIMEOUT = -1,
ERR_WRITE_TIMEOUT = -2,
ERR_BAD_CHECKSUM = -3,
ERR_BUFFER_OVERFLOW = -4,
ERR_INVALID = -5,
ERR_READ_ENTER_TIMEOUT = -6
};
enum Endpoint {
COMP82 = 0x02,
COMP83 = 0x03,
COMP85 = 0x05,
COMP86 = 0x06,
COMP89 = 0x09,
COMP92 = 0x09,
CBL82 = 0x12,
CBL85 = 0x15,
CBL89 = 0x19,
CBL92 = 0x19,
COMP83P = 0x23,
CALC83P = 0x73,
CALC82 = 0x82,
CALC83 = 0x83,
CALC85a = 0x85,
CALC89 = 0x89,
CALC92 = 0x89,
CALC85b = 0x95,
};
enum CommandID {
VAR = 0x06,
CTS = 0x09,
DATA = 0x15,
VER = 0x2D,
SKIP = 0x36,
EXIT = 0x36,
ACK = 0x56,
ERR = 0x5A,
RDY = 0x68,
SCR = 0x6D,
KEY = 0x87,
DEL = 0x88,
EOT = 0x92,
REQ = 0xA2,
RTS = 0xC9,
};
class TICL {
public:
TICL();
TICL(int tip, int ring);
void begin();
void setLines(int tip, int ring);
void setVerbosity(bool verbose, HardwareSerial* serial = NULL);
int send(uint8_t* header, uint8_t* data, int datalength, uint8_t(*data_callback)(int) = NULL);
int get(uint8_t* header, uint8_t* data, int* datalength, int maxlength, int timeout = GET_ENTER_TIMEOUT);
void resetLines();
protected:
HardwareSerial* serial_;
private:
int sendByte(uint8_t byte);
int getByte(uint8_t* byte, int timeout = GET_ENTER_TIMEOUT);
int digitalSafeRead(int pin);
int tip_;
int ring_;
};
#endif // TICL_H