-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSnapshot.cpp
283 lines (229 loc) · 5.71 KB
/
Snapshot.cpp
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include "Arduino.h"
#include "Snapshot.h"
Snapshot::Snapshot(Memory *memory)
{
this->memory = memory;
}
void Snapshot::init()
{
uint8_t low_byte;
uint8_t high_byte;
// Load sequence from non-volitile ram
for(int i=0; i<MAX_SEQUENCE_LENGTH; i++)
{
uint16_t memory_address = i * 2;
low_byte = memory->read(memory_address);
high_byte = memory->read(memory_address + 1);
this->sequence[i] = word(high_byte, low_byte);
}
// Load sequence length
low_byte = memory->read(MEM_ADDR_SEQUENCE_LENGTH);
high_byte = memory->read(MEM_ADDR_SEQUENCE_LENGTH + 1);
this->sequence_length = word(high_byte, low_byte);
// Load clock division
low_byte = memory->read(MEM_ADDR_CLOCK_DIVISION);
high_byte = memory->read(MEM_ADDR_CLOCK_DIVISION + 1);
this->clock_division = word(high_byte, low_byte);
// Load slip
this->slip = memory->read(MEM_ADDR_SLIP);
// Load drift percentage
this->drift_percentage = memory->read(MEM_ADDR_DRIFT_PERCENTAGE);
// Load drift amount
low_byte = memory->read(MEM_ADDR_DRIFT_AMOUNT);
high_byte = memory->read(MEM_ADDR_DRIFT_AMOUNT + 1);
this->drift_amount = word(high_byte, low_byte);
// Load hold pattern
this->hold = memory->read(MEM_ADDR_HOLD);
// Load display intensity
this->display_intensity = memory->read(MEM_ADDR_INTENSITY);
// Load scale
this->scale = memory->read(MEM_ADDR_SCALE);
// Load hold
this->hold = memory->read(MEM_ADDR_HOLD);
// Load hold offset
this->hold_offset = memory->read(MEM_ADDR_HOLD_OFFSET);
// Load hold threshold
low_byte = memory->read(MEM_ADDR_HOLD_THRESHOLD);
high_byte = memory->read(MEM_ADDR_HOLD_THRESHOLD + 1);
this->hold_threshold = word(high_byte, low_byte);
// Load song1 and song2
this->song = memory->read(MEM_ADDR_SONG);
this->song2 = memory->read(MEM_ADDR_SONG2);
// Load reset input assignment
this->rst_input_assignment = memory->read(MEM_RST_INPUT_ASSIGNMENT);
// Load press functionality
this->press_functionality = memory->read(MEM_PRESS_FUNCTIONALITY);
}
//
// setValue
//
void Snapshot::setValue(uint16_t step, uint16_t value)
{
if(value != this->sequence[step])
{
// Write the value to the sequence array
this->sequence[step] = value;
// Also store the value in non-volitile memory
uint16_t memory_address = step * 2;
memory->write(memory_address, lowByte(value));
memory->write(memory_address + 1, highByte(value));
}
}
//
// Sequence Length
//
void Snapshot::setSequenceLength(uint16_t sequence_length)
{
if(sequence_length != this->sequence_length)
{
this->sequence_length = sequence_length;
memory->write(MEM_ADDR_SEQUENCE_LENGTH, lowByte(sequence_length));
memory->write(MEM_ADDR_SEQUENCE_LENGTH + 1, highByte(sequence_length));
}
}
//
// Clock Division
//
void Snapshot::setClockDivision(uint16_t clock_division)
{
if(clock_division != this->clock_division)
{
this->clock_division = clock_division;
memory->write(MEM_ADDR_CLOCK_DIVISION, lowByte(clock_division));
memory->write(MEM_ADDR_CLOCK_DIVISION + 1, highByte(clock_division));
}
}
//
// Slip
//
void Snapshot::setSlip(uint8_t slip)
{
if(slip != this->slip)
{
this->slip = slip;
memory->write(MEM_ADDR_SLIP, slip);
}
}
//
// Drift Percentage
//
void Snapshot::setDriftPercentage(uint8_t drift_percentage)
{
if(drift_percentage != this->drift_percentage)
{
this->drift_percentage = drift_percentage;
memory->write(MEM_ADDR_DRIFT_PERCENTAGE, drift_percentage);
}
}
//
// Drift Amount
//
void Snapshot::setDriftAmount(uint16_t drift_amount)
{
if(drift_amount != this->drift_amount)
{
this->drift_amount = drift_amount;
memory->write(MEM_ADDR_DRIFT_AMOUNT, lowByte(drift_amount));
memory->write(MEM_ADDR_DRIFT_AMOUNT + 1, highByte(drift_amount));
}
}
//
// Hold
//
void Snapshot::setHold(uint8_t hold)
{
if(hold != this->hold)
{
this->hold = hold;
memory->write(MEM_ADDR_HOLD, hold);
}
}
//
// Hold Offset
//
void Snapshot::setHoldOffset(uint16_t hold_offset)
{
if(hold_offset != this->hold_offset)
{
this->hold_offset = hold_offset;
memory->write(MEM_ADDR_HOLD_OFFSET, hold_offset);
}
}
//
// Hold Threshold
//
void Snapshot::setHoldThreshold(uint16_t hold_threshold)
{
if(hold_threshold != this->hold_threshold)
{
this->hold_threshold = hold_threshold;
memory->write(MEM_ADDR_HOLD_THRESHOLD, lowByte(hold_threshold));
memory->write(MEM_ADDR_HOLD_THRESHOLD+1, highByte(hold_threshold));
}
}
//
// Display Intensity
//
void Snapshot::setDisplayIntensity(uint8_t display_intensity)
{
if(display_intensity != this->display_intensity)
{
this->display_intensity = display_intensity;
memory->write(MEM_ADDR_INTENSITY, display_intensity);
}
}
//
// Scale
//
void Snapshot::setScale(uint8_t scale)
{
if(scale != this->scale)
{
this->scale = scale;
memory->write(MEM_ADDR_SCALE, scale);
}
}
//
// Song
//
void Snapshot::setSong(uint16_t song)
{
if(song != this->song)
{
this->song = song;
memory->write(MEM_ADDR_SONG, song);
}
}
//
// Song2
//
void Snapshot::setSong2(uint16_t song2)
{
if(song2 != this->song2)
{
this->song2 = song2;
memory->write(MEM_ADDR_SONG2, song2);
}
}
//
// rst_input_assignment
//
void Snapshot::setRstInputAssignment(uint8_t rst_input_assignment)
{
if(rst_input_assignment != this->rst_input_assignment)
{
this->rst_input_assignment = rst_input_assignment;
memory->write(MEM_RST_INPUT_ASSIGNMENT, rst_input_assignment);
}
}
//
// press functionality (course/fine)
//
void Snapshot::setPressFunctionality(uint8_t press_functionality)
{
if(press_functionality != this->press_functionality)
{
this->press_functionality = press_functionality;
memory->write(MEM_PRESS_FUNCTIONALITY, press_functionality);
}
}