-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCBL2.h
81 lines (71 loc) · 2.24 KB
/
CBL2.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
/*************************************************
* CBL2.h - Library for emulating CBL2 devices *
* or CBL-connected calculators with *
* Arduinos. *
* Created by Christopher Mitchell, *
* 2011-2019, all rights reserved. *
*************************************************/
#ifndef CBL2_H
#define CBL2_H
#include "Arduino.h"
#include "TICL.h"
namespace VarTypes82 { enum VarTypes82 {
VarReal = 0,
VarRList = 1,
VarMatrix = 2,
VarYVar = 3,
VarString = 4,
VarProgram = 5,
VarProtProg = 6,
VarPic = 7,
VarGDB = 8,
VarWindow = 0x0B,
VarComplex = 0x0C,
VarURList = 0x24
}; };
namespace VarTypes84PCSE { enum VarTypes84PCSE {
VarURList = 0x24,
VarReal = 0x58,
VarRMat = 0x5C,
VarRList = 0x5D
}; };
namespace VarTypes85 { enum VarTypes85 {
VarReal = 0,
VarCplx = 1,
VarRVec = 2,
VarCVec = 3,
VarRList = 4,
VarCList = 5,
VarRMat = 6,
VarCMat = 7,
VarRConst = 8,
VarCConst = 9,
VarEqu = 0x0A,
VarString = 0x0C
}; };
typedef uint8_t(*data_callback)(int);
class CBL2: public TICL {
public:
CBL2();
CBL2(int tip, int ring);
// Methods for emulating a calculator, talking to a CBL2
int getFromCBL2(uint8_t type, uint8_t* header, uint8_t* data, int* datalength, int maxlength);
int sendToCBL2(uint8_t type, uint8_t* header, uint8_t* data, int datalength);
// Methods for emulating a CBL2, talking to a calculator
int setupCallbacks(uint8_t* header, uint8_t* data, int maxlength,
int (*get_callback)(uint8_t, enum Endpoint, int),
int (*send_callback)(uint8_t, enum Endpoint, int*, int*, data_callback*));
int eventLoopTick(bool quick_fail = false); // Usually called in loop()
private:
bool verbose_;
bool callback_init;
uint8_t* header_; // Variable header, not msg header, returned to callbacks!
uint8_t* data_; // Variable data returned to callbacks
int datalength_;
int maxlength_;
data_callback data_callback_;
int (*get_callback_)(uint8_t, enum Endpoint, int); // Called when data received from calculator
int (*send_callback_)(uint8_t, enum Endpoint, int*, int*, data_callback*); // Called when calculator wants to get data
void normalizeVariableHeader(const int model);
};
#endif // CBL2_H