-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.h
263 lines (201 loc) · 6.54 KB
/
display.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#ifndef SYNTHPI_DISPLAY
#define SYNTHPI_DISPLAY
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include "Thread.h"
namespace SYNTHPI{
class MAX7219 {
public:
MAX7219();
// ~MAX7219();
std::vector<unsigned char> digitBuffer;
int spi_transfer(int fd, unsigned char* tx, int n);
void command(unsigned char reg, unsigned char data);
uint32_t speed = 500000;
uint16_t delay = 0;
int fd;
uint8_t bpw = 8;
unsigned char decodeMode = 0x0;
unsigned char intensity = 0x7;
unsigned char scanLimit = 0x7;
unsigned char shutdown = 0x1;
unsigned char displayTest = 0x0;
unsigned int numDigits = 8;
//SETTERS //
/**
* Sets a value in the \ref digitBuffer.
*
* @param digit Byte address of digit.
* @param value Byte value to assign.
* @param redraw If true, updates all digits at the end of method call.
*/
void setDigit(unsigned int digit, unsigned char value, bool redraw);
/**
* Sets the \ref decodeMode.
* @param value Decode mode byte.
*/
void setDecodeMode(unsigned char value);
/**
* Sets the \ref intensity.
* @param value Intensity value (1-15).
*/
void setIntensity(unsigned char value);
/**
* Sets the \ref scanLimit.
* @param value Scan limit (0-7).
*/
void setScanLimit(unsigned char value);
/**
* Sets the \ref shutdown mode.
* @param value Shutdown mode (1/0).
*/
void setShutdown(unsigned char value);
/**
* Sets the \ref displayTest mode.
* @param value Display test mode (1/0).
*/
void setDisplayTest(unsigned char value);
// GETTERS //
/**
* Gets a value of a digit in the \ref digitBuffer.
* @param digit Byte address of digit.
* @returns Current byte value of digit.
*/
unsigned char getDigit(unsigned char digit);
/**
* Gets the current \ref decodeMode.
* @returns Current \ref decodeMode.
*/
unsigned char getDecodeMode();
/**
* Gets the current \ref intensity.
* @returns Current \ref intensity.
*/
unsigned char getIntensity();
/**
* Gets the current \ref scanLimit.
* @returns Current \ref scanLimit.
*/
unsigned char getScanLimit();
/**
* Gets the current \ref shutdown mode.
* @returns Current \ref shutdown mode.
*/
unsigned char getShutdown();
/**
* Gets the current \ref displayTest mode.
* @returns Current \ref displayTest mode.
*/
unsigned char getDisplayTest();
/**
* Gets the number of digits in the display.
* @returns Number of display digits.
*/
unsigned int getNumDigits();
// HIGH LEVEL METHODS //
/**
* Writes all \ref digitBuffer values to display via SPI bus.
*/
void flush();
/**
* Resets all digits in the \ref digitBuffer to 0.
* @param redraw If true, calls \ref flush to update display.
*/
void clear(bool redraw);
};
class Display: public MAX7219 {
private:
/** Vector to contain corresponding hex values
* for decimal digit representation.
*
* Prevents the need to toggle Code B decode
* for every numerical display.
*/
const std::vector<unsigned char> decHexVals = {
0x7E, // '0'
0x30, // '1'
0x6D, // '2'
0x79, // '3'
0x33, // '4'
0x5B, // '5'
0x5F, // '6'
0x70, // '7'
0x7F, // '8'
0x7B, // '9'
};
const std::vector<std::vector<unsigned char>> params = {
{0x3E,0x1D,0x0E,0x00}, // VOL
{0x1F,0x0E,0x15,0x3D}, // BLND
{0x1F,0x77,0x15,0x4E}, // BANK
{0x77,0x0F,0x77,0x4E}, // ATAC
{0x3D,0x4E,0x77,0x3B}, // DCAY
{0x5B,0x1C,0x5B,0x0F}, // SUST
{0x05,0x4F,0x0E,0x00}, // REL
{0x4E,0x1D,0x47,0x47}, //CoFF
{0x05,0x4F,0x5B,0x1D}, //RESO
{0x5B,0x0E,0x1D,0x67}, //SLOP
};
unsigned int currentParam = 0;
/** Sets a 3 digit decimal value.
* @param value 3 digit value to set.
*/
void setThreeDigit(unsigned int value);
/** Sets a 2 digit decimal value.
* @param value 2 digit value to set.
*/
void setTwoDigit(unsigned int value);
/** Sets a 1 digit decimal value.
* @param value 1 digit value to set.
*/
void setOneDigit(unsigned int value);
public:
Display(); ///Constructor.
/**
* Sets values in \ref digitBuffer
* to display a number up to 999.
*
* @param value Numerical value to display.
* @param redraw If true, updates display.
*/
void setVal(unsigned int value, bool redraw);
/**
* Sets values in \ref digitBuffer
* to display which parameter is being changed by the MIDI keyboard.
*
* @param param Numerical representation of which MIDI parameter is being changed.
* @param redraw If true, updates display.
*/
void setParam(unsigned int param, bool redraw);
/**
* Checks incoming CC values and sends them for processing to display
*
* @param address Numerical representation of which MIDI parameter is being changed.
* @param value Value of MIDI parameter that is being changed.
*/
void ccToDisplay(unsigned int address, unsigned int value);
// ~Display(); ///Destructor.
};
class DisplayThread: public Thread{
protected:
Display* display;
bool isPlaying;
unsigned int currentParam;
public:
DisplayThread(Display* display); // Constructor
~DisplayThread(); //Destructor
virtual void run();
void ccToDisplay(unsigned int address, unsigned int value);
};
} //close namespace
#endif