1 #ifndef LOGICENGINECONTROLLER_H
2 #define LOGICENGINECONTROLLER_H
5 #ifndef LENGINE_DELAY_PIN
6 #if defined(REELTWO_TEENSY)
7 #define LENGINE_DELAY_PIN A1
8 #define LENGINE_FADE_PIN A2
9 #define LENGINE_BRI_PIN A3
10 #define LENGINE_HUE_PIN A6
11 #define LENGINE_PAL_PIN 9
12 #define LENGINE_FJUMP_PIN 0
13 #define LENGINE_RJUMP_PIN 1
14 #elif defined(REELTWO_ZERO)
15 #define LENGINE_DELAY_PIN A0
16 #define LENGINE_FADE_PIN A1
17 #define LENGINE_BRI_PIN A2
18 #define LENGINE_HUE_PIN A3
19 #define LENGINE_PAL_PIN 9
20 #define LENGINE_FJUMP_PIN 2
21 #define LENGINE_RJUMP_PIN 4
22 #elif defined(REELTWO_AVR_MEGA)
23 #define LENGINE_DELAY_PIN A0
24 #define LENGINE_FADE_PIN A1
25 #define LENGINE_BRI_PIN A2
26 #define LENGINE_HUE_PIN A3
27 #define LENGINE_PAL_PIN 9
28 #define LENGINE_FJUMP_PIN 2
29 #define LENGINE_RJUMP_PIN 4
30 #elif defined(REELTWO_AVR)
31 #define LENGINE_DELAY_PIN A0
32 #define LENGINE_FADE_PIN A1
33 #define LENGINE_BRI_PIN A2
34 #define LENGINE_HUE_PIN A3
35 #define LENGINE_PAL_PIN 9
36 #define LENGINE_FJUMP_PIN 2
37 #define LENGINE_RJUMP_PIN 4
57 template <
byte kDelayPin = LENGINE_DELAY_PIN,
byte kFadePin = LENGINE_FADE_PIN,
58 byte kBriPin = LENGINE_BRI_PIN,
byte kHuePin = LENGINE_HUE_PIN,
byte kPalPin = LENGINE_PAL_PIN,
59 byte kFrontJumperPin = LENGINE_FJUMP_PIN,
byte kRearJumperPin = LENGINE_RJUMP_PIN>
74 fFactorySettings[0] = fSettings[0];
75 fFactorySettings[1] = fSettings[1];
76 if (fFLDSettingsStorage.isValid())
78 if (fRLDSettingsStorage.isValid())
82 pinMode(kDelayPin, INPUT);
83 pinMode(kFadePin, INPUT);
84 pinMode(kBriPin, INPUT);
85 pinMode(kHuePin, INPUT);
88 pinMode(kFrontJumperPin, INPUT_PULLUP);
89 pinMode(kRearJumperPin, INPUT_PULLUP);
90 pinMode(kPalPin, INPUT_PULLUP);
105 fFactorySettings[0] = fSettings[0];
106 if (fFLDSettingsStorage.isValid())
109 pinMode(kFrontJumperPin, INPUT_PULLUP);
110 pinMode(kRearJumperPin, INPUT_PULLUP);
111 pinMode(kPalPin, INPUT_PULLUP);
124 compareTrimpots(fAdjMode);
127 int palBut = checkPaletteButton();
139 fFLDSettingsStorage.put(fFactorySettings[i]);
141 fRLDSettingsStorage.put(fFactorySettings[i]);
145 else if (fAdjMode != 0 && palBut >= 3)
148 if (fAdjMode == 1 && fLogic[0] != NULL)
150 else if (fAdjMode == 2 && fLogic[1] != NULL)
157 byte fPrevAdjMode = 0;
158 byte fStartAdjMode = 0;
159 byte fPrevBrightness = 0;
160 byte fPrevPalNum = 0;
161 unsigned fPalPinLoops;
162 bool fPalPinStatus = 1;
163 bool fPrevPalPinStatus = 1;
165 int fStartTrimpots[4];
166 bool fTrimEnabled[4];
167 int fLoopTrimpots[4];
169 byte fAdjThreshold = 5;
184 kMAX_ADJLOOP = 90000,
188 void checkTrimpots(
bool startTrim =
false)
191 int* trimData = (startTrim) ? fStartTrimpots : fLoopTrimpots;
193 trimData[0] = map(analogRead(kDelayPin), 0, 1023, kMIN_DELAY, kMAX_DELAY);
194 trimData[1] = map(analogRead(kFadePin), 0, 1023, 0, kMAX_FADE);
196 trimData[3] = map(analogRead(kHuePin), 0, 1023, 0, 255);
199 void compareTrimpots(
byte adjMode = 0)
201 boolean update =
false;
203 for (
byte x = 0; x < 4; x++)
205 if (x > 1 && fAdjEnabled[x] == 0 &&
206 ((fStartTrimpots[x] - fLoopTrimpots[x] > fAdjThreshold) || (fLoopTrimpots[x] - fStartTrimpots[x] > fAdjThreshold)))
211 else if (fAdjEnabled[x] == 0 && fStartTrimpots[x] != fLoopTrimpots[x])
215 else if (fAdjEnabled[x] == 1)
217 if ((x == 1 && fLoopTrimpots[x] != fStartTrimpots[x]) ||
218 (fLoopTrimpots[x] - fStartTrimpots[x] >= 2 || fStartTrimpots[x] - fLoopTrimpots[x] >= 2))
221 if (fAdjMode == 1 || fAdjMode == 2)
228 settings->
fDelay = fLoopTrimpots[x];
232 settings->
fFade = fLoopTrimpots[x];
236 settings->
fBri = fLoopTrimpots[x];
240 settings->
fHue = fLoopTrimpots[x];
246 fStartTrimpots[x] = fLoopTrimpots[x];
249 if (update && (fAdjMode == 1 || fAdjMode == 2))
261 void checkAdjSwitch()
263 if (digitalRead(kFrontJumperPin) == 0 && fPrevAdjMode != 1 && fStartAdjMode == 0)
270 else if (digitalRead(kRearJumperPin) == 0 && fPrevAdjMode != 2 && fStartAdjMode == 0)
277 else if ((fPrevAdjMode != 0 && digitalRead(kRearJumperPin) == 1 &&
278 digitalRead(kFrontJumperPin) == 1 && fStartAdjMode == 0) || (fAdjLoops > kMAX_ADJLOOP))
280 if (fAdjLoops > kMAX_ADJLOOP)
285 if (fAdjLoops > kMIN_ADJLOOP)
289 fFLDSettingsStorage.put(fSettings[0]);
292 else if (fAdjMode == 2)
294 fRLDSettingsStorage.put(fSettings[1]);
297 if (fAdjLoops > kMAX_ADJLOOP)
299 fStartAdjMode = fAdjMode;
303 for (
byte x = 0; x < 4; x++)
308 else if (digitalRead(kRearJumperPin) == 1 && digitalRead(kFrontJumperPin) == 1 && fStartAdjMode != 0)
314 if (fAdjMode != fPrevAdjMode)
318 fPrevAdjMode = fAdjMode;
321 int checkPaletteButton()
323 if (digitalRead(kPalPin) == 0)
327 if (fPalPinStatus == 1 && fPrevPalPinStatus == 1)
334 else if (digitalRead(kPalPin) == 1 && fPalPinStatus == 0 && fPrevPalPinStatus == 0)
341 fPrevPalPinStatus = fPalPinStatus;
346 #if defined(REELTWO_TEENSY)
349 #elif defined(REELTWO_ZERO)
352 typedef LogicEngineControllerReactorZeroRedPCB LogicEngineControllerReactorZero;
354 #elif defined(REELTWO_AVR_MEGA)
357 #elif defined(REELTWO_AVR)