-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetupHandler.cpp
324 lines (310 loc) · 11.2 KB
/
SetupHandler.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
* SetupHandler.cpp
*
* Created: 4/29/2014 11:35:56 AM
* Author: Ketil Wright
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SetupHandler.h"
#include "LcdImpl.h"
#include <avr/eeprom.h>
extern uint16_t g_savedFocusAmount;
extern uint16_t g_savedNumFrames;
extern uint16_t EEMEM ePromFocusAmount;
extern uint16_t EEMEM ePromFrameDelay;
extern uint16_t EEMEM ePromNumFrames;
extern uint8_t EEMEM ePromRestoreFocus;
extern IMessageHandler *g_pMain;
/*
* A table of available apertures on various lenses, at various zoom values & focal distance/ magnifications
* The intersection of values in this table play a role in which apertures can be applied
* to all lenses generally.
*
* nikkor 16-85
* at 16mm
* 3.5, 4, 4.5, 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22
* at 85 mm
* 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 29, 32, 36,
*
* tamron 180mm macro
*
* 1:1
* 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 29, 32, 36, 40, 45, 51
*
* 1:1.2
* 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 29, 32, 36, 40, 45,
*
* 1:1.5
* 4.8, 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 29, 32, 36, 40, 45
*
* 1:1.75
* 4.5, 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 29, 32, 36, 40,
*
* 1:2.25
* 4, 4.5, 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 29, 32, 36,
*
* 1:3.5
* 3.8, 4, 4.5, 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 29, 32, 36,
*
* 1: 1.6
* 3.5, 4, 4.5, 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22, 25, 29, 32,
*
* tokina 11-16 f2.8
* 2.8, 3.2, 3.5, 4, 4.5, 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22
*
* nikkor 35mm f1.8 dx
* 1.8, 2, 2.2, 2.5, 2.8, 3.2, 3.5, 4, 4.5, 5, 5.6, 6.3, 7.1, 8, 9, 10, 11, 13, 14, 16, 18, 20, 22
*/
// The value expressed to SetDevicePropValue(PTP_DPC_FNumber)
// is a value from the intersection of the available values,
// multiplied by 100
uint16_t SetupHandler::m_apertures[maxApertures] =
{
560, 630, 710, 800, 900, 1000, 1100, 1300, 1400, 1600, 1800, 2000, 2200
};
// Note, to save lcd space, the displayed values are integer divided by 100
// & therefore 05, 06, 07, 08, 09, 10, 11, 13, 14, 16, 18, 20, 22
SetupHandler::SetupHandler(MessagePump *_pump, uint32_t driveAmount, uint32_t frames)
:
IMessageHandler(_pump),
m_driveAmount(driveAmount, 1, 9999, 4),
m_numFrames(frames, 1, 999, 3),
m_frameDelaySeconds(0, 0, 99, 2),
m_lastFStop(16, 5, 22, 2),
m_restoreFocus(false),
m_lastFrameFstopInx(9) // f16
{
menu[0] = "Amt";
menu[1] = "Frm";
menu[2] = "Dl";
menu[3] = "Lf";
menu[4] = "R";
};
SetupHandler::~SetupHandler()
{}
void SetupHandler::advanceCaret(uint8_t dir) // -1 = left, 1 right. All other values ignored
{
unsigned char caretColumn = g_print->getCaretCol();
if(dir == 0xff)
{
// move left
switch(caretColumn)
{
case AmountFieldStartCol: { caretColumn = RestoreFocusFieldStartCol; break;}
case FrameFieldStartCol: { caretColumn = AmountFieldEndCol; break;}
case DelayFieldStartCol: { caretColumn = FrameFieldEndCol; break;}
case LastFstopFieldStartCol: { caretColumn = DelayFieldEndCol; break; }
case RestoreFocusFieldStartCol: { caretColumn = LastFstopFieldStartCol; break;}
default: { --caretColumn; break;}
}
}
else if(dir == 1)
{
// move right
switch(caretColumn)
{
case AmountFieldEndCol: { caretColumn = FrameFieldStartCol; break;}
case FrameFieldEndCol: { caretColumn = DelayFieldStartCol; break;}
case DelayFieldEndCol: { caretColumn = LastFstopFieldStartCol; break;}
// no movement within the last fstop field (up down keys select preset values).
case LastFstopFieldStartCol: { caretColumn = RestoreFocusFieldStartCol; break;}
// no movement within the last fstop field (up down keys select preset values).
case RestoreFocusFieldStartCol: { caretColumn = AmountFieldStartCol; break;}
default: { ++caretColumn; break;}
}
}
g_print->setCursor(caretColumn, 1);
}
MsgResp SetupHandler::processMessage(Msg& msg)
{
MsgResp rsp = eFail;
if(eButtonActionPress != msg.m_type) return rsp;
// the amount up or down some parameter will be changed
unsigned char caretColumn = g_print->getCaretCol();
int change = 0;
// which button?
switch(msg.m_code)
{
case eDown:
{
if((caretColumn <= AmountFieldEndCol) && (msg.m_type == eButtonActionPress))
{
// change amount entry
change = -1000; // todo: consider a power of ten == AmountFieldEnd - AmountFieldStart + 1
while(caretColumn-- != AmountFieldStartCol)
{
change /= 10;
}
m_driveAmount.changeVal(change);
m_driveAmount.display(AmountFieldStartCol, AmountFieldRow);
}
else if((caretColumn >= FrameFieldStartCol) && (caretColumn <= FrameFieldEndCol))
{
change = -100;// todo: consider a power of ten == FrameFieldEnd - FrameFieldStart + 1
while(caretColumn-- != FrameFieldStartCol)
{
change /= 10;
}
m_numFrames.changeVal(change);
m_numFrames.display(FrameFieldStartCol, FrameFieldRow);
}
else if((caretColumn >= DelayFieldStartCol) && (caretColumn <= DelayFieldEndCol))
{
// todo: consider a power of ten == DelayFieldEnd - DelayFieldStart + 1
change = -10;
while(caretColumn-- != DelayFieldStartCol)
{
change /= 10;
}
m_frameDelaySeconds.changeVal(change);
m_frameDelaySeconds.display(DelayFieldStartCol, DelayFieldRow);
}
else if(caretColumn == LastFstopFieldStartCol)
{
// wrap to top at 0
if(m_lastFrameFstopInx == 0) (m_lastFrameFstopInx = maxApertures - 1);
else --m_lastFrameFstopInx;
m_lastFStop.setVal(m_apertures[m_lastFrameFstopInx] / 100);
m_lastFStop.display(LastFstopFieldStartCol,LastFstopFieldRow );
}
else if((caretColumn == RestoreFocusFieldStartCol))
{
updateRestoreFocusUI(-1);
}
break;
}
case eUp:
{
if((caretColumn <= AmountFieldEndCol) && (msg.m_type == eButtonActionPress))
{
// change amount entry
change = 1000; // todo: consider a power of ten == AmountFieldEnd - AmountFieldStart + 1
while(caretColumn-- != AmountFieldStartCol)
{
change /= 10;
}
m_driveAmount.changeVal(change);
m_driveAmount.display(AmountFieldStartCol, AmountFieldRow);
}
else if((caretColumn >= FrameFieldStartCol) && (caretColumn <= FrameFieldEndCol))
{
change = 100;// todo: consider a power of ten == FrameFieldEnd - FrameFieldStart + 1
while(caretColumn-- != FrameFieldStartCol)
{
change /= 10;
}
m_numFrames.changeVal(change);
m_numFrames.display(FrameFieldStartCol, FrameFieldRow);
}
else if((caretColumn >= DelayFieldStartCol) && (caretColumn <= DelayFieldEndCol))
{
// todo: consider a power of ten == DelayFieldEnd - DelayFieldStart + 1
change = 10;
while(caretColumn-- != DelayFieldStartCol)
{
change /= 10;
}
m_frameDelaySeconds.changeVal(change);
m_frameDelaySeconds.display(DelayFieldStartCol, DelayFieldRow);
}
else if(caretColumn == LastFstopFieldStartCol)
{
// wrap to 0 at top
if(m_lastFrameFstopInx < maxApertures - 1)
{
++m_lastFrameFstopInx;
}
else
{
m_lastFrameFstopInx = 0;
}
m_lastFStop.setVal(m_apertures[m_lastFrameFstopInx] / 100);
m_lastFStop.display(LastFstopFieldStartCol,LastFstopFieldRow );
}
else if(caretColumn == RestoreFocusFieldStartCol)
{
updateRestoreFocusUI(1);
}
break;
}
case eLeft:
{
advanceCaret(-1);
break;
}
case eRight:
{
advanceCaret(1);
break;
}
case eSelect:
{
if(eButtonActionPress == msg.m_type)
{
// write any settings that have changed to the eeprom.
uint16_t savedFocusAmt = eeprom_read_word(&ePromFocusAmount);
if(savedFocusAmt != m_driveAmount.getVal())
{
eeprom_write_word(&ePromFocusAmount, m_driveAmount.getVal());
}
uint16_t savedFrameDelay = eeprom_read_word(&ePromFrameDelay);
if(savedFrameDelay != m_frameDelaySeconds.getVal())
{
eeprom_write_word(&ePromFrameDelay, m_frameDelaySeconds.getVal());
}
uint16_t savedNumFrames = eeprom_read_word(&ePromNumFrames);
if(savedNumFrames != m_numFrames.getVal())
{
eeprom_write_word(&ePromNumFrames, m_numFrames.getVal());
}
uint8_t savedRestoreFocus = eeprom_read_byte(&ePromRestoreFocus);
if(savedRestoreFocus != m_restoreFocus)
{
eeprom_write_byte(&ePromRestoreFocus, m_restoreFocus);
}
msg.m_nextHandler = g_pMain;
rsp = eSuccess;
}
break;
} // eSelect handler
default: break;
}
return rsp;
}
void SetupHandler::show()
{
g_print->clear();
printMenuItem(AmountFieldStartCol, 0/*row*/, 0);
printMenuItem(FrameFieldStartCol, 0/*row*/,1);
printMenuItem(DelayFieldStartCol, 0/*row*/,2);
printMenuItem(LastFstopFieldStartCol, 0/*row*/, 3);
printMenuItem(RestoreFocusFieldStartCol, 0/*row*/,4);
m_driveAmount.display(AmountFieldStartCol, AmountFieldRow);
m_numFrames.display(FrameFieldStartCol, FrameFieldRow);
m_frameDelaySeconds.display(DelayFieldStartCol, DelayFieldRow);
m_lastFStop.display(LastFstopFieldStartCol, LastFstopFieldRow);
updateRestoreFocusUI(0);
g_print->setCursor(0, 1);
}
void SetupHandler::updateRestoreFocusUI(int change)
{
g_print->saveCursorLocation();
g_print->setCursor(RestoreFocusFieldStartCol, 1);
//g_print->print(F(" "));
//g_print->setCursor(RestoreFocusFieldStart, 1);
if(0 != change) m_restoreFocus = !m_restoreFocus;
g_print->print( m_restoreFocus ? F("Y") : F("N"));
g_print->restoreCursorLocation();
}