-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathManualHandler.cpp
444 lines (422 loc) · 14.4 KB
/
ManualHandler.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/*
* ModelMenu.cpp
*
* Created: 6/24/2014 8:48:23 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 "ManualHandler.h"
#include "LcdImpl.h"
#include "NikType003.h"
#include "SetupHandler.h"
// amount menu indicator in row 0
#define AmountMenuItemCol 0
#define AmountMenuItemRow 0
// amount field in row 1
#define AmountFieldStartCol 0
#define AmountFieldEndCol 3
#define AmountFieldRow 1
// "Pos"
#define FocusPosMenuItemCol 5
#define FocusPosMenuItemRow 0
// current value of m_pos
#define FocusPosIndicatorCol 9
#define FocusPosIndicatorRow 0
// toggles on/off live view, when
// lv is on up/down keys move focus
#define TestMenuItemCol 5
#define TestMenuItemRow 1
#define DoneMenuItemCol 12
#define DoneMenuItemRow 1
extern IMessageHandler *g_pMain;
extern SetupHandler *g_pSetup;
extern NikType003 nk3;
// default constructor
ManualHandler::ManualHandler(MessagePump *_pump)
:
IMessageHandler(_pump),
//m_pos(0, -2147483648, 2147483647, 7)
m_pos(0, -1000000, 1000000, 7, false) // false -> don't pad zeros
{
menu[0] = "Amt";
menu[1] = "Pos";
menu[2] = "Test";
menu[3] = "Done";
}
MsgResp ManualHandler::processMessage(Msg& msg)
{
if(eButtonActionPress != msg.m_type) return eFail;
MsgResp rsp = eSuccess;
uint8_t col = g_print->getCaretCol();
uint8_t row = g_print->getCaretRow();
switch(msg.m_code)
{
case eLeft:
{
advanceCaret(0xff);
break;
}
case eRight:
{
advanceCaret(1);
break;
}
case eDown:
{
if((TestMenuItemCol == col) && (TestMenuItemRow == row))
{
focus(1); // backward
}
else if((col <= AmountFieldEndCol) && (AmountFieldRow == row))
{
// our amt field is in the same screen pos the setup
// handler, which already knows how to evaluate the
// msg.
rsp = g_pSetup->processMessage(msg);
}
break;
}
case eUp:
{
if((TestMenuItemCol == col) && (TestMenuItemRow == row))
{
focus(2); // forward
}
else if((col <= AmountFieldEndCol) && (AmountFieldRow == row))
{
// our amt field is in the same screen pos the setup
// handler, which already knows how to evaluate the
// msg.
rsp = g_pSetup->processMessage(msg);
}
break;
}
case eSelect:
{
if((TestMenuItemCol == col) && (TestMenuItemRow == row))
{
if(PTP_RC_OK == nk3.waitForReady(100))
{
nk3.enableLiveView(!nk3.isLiveViewEnabled());
}
}
else if((DoneMenuItemCol == col) && (DoneMenuItemRow == row))
{
if(nk3.isLiveViewEnabled())
{
nk3.enableLiveView(false);
}
msg.m_nextHandler = g_pMain;
}
break;
}
default:
{
rsp = eFail;
break;
}
}
return rsp;
}
void ManualHandler::advanceCaret(uint8_t dir)
{
uint8_t col = g_print->getCaretCol();
uint8_t row = g_print->getCaretRow();
if(0xff == dir) // left
{
if((AmountFieldStartCol == col) && (AmountFieldRow == row))
{
// wrap around backwards from beginning of amount field -> Done menu ite,
g_print->setCursor(DoneMenuItemCol, DoneMenuItemRow);
}
else if((col > AmountFieldStartCol) && (col <= AmountFieldEndCol) && (AmountFieldRow == row))
{
// move within the amount field
g_print->setCursor(col - 1, row);
}
else if((TestMenuItemCol == col) && (TestMenuItemRow == row))
{
// move from Test menu to end of amount field
g_print->setCursor(AmountFieldEndCol, AmountFieldRow);
}
else if((DoneMenuItemCol == col) && (DoneMenuItemRow == row))
{
// move from Done item -> Test item
g_print->setCursor(TestMenuItemCol, TestMenuItemRow);
}
}
else if(1 == dir) // right
{
if((col >= AmountFieldStartCol) && (col < AmountFieldEndCol) && (AmountFieldRow == row))
{
// move within the amount field
g_print->setCursor(col + 1, AmountFieldRow);
}
else if((AmountFieldEndCol == col) && (AmountFieldRow == row))
{
// move from end of amount field to done
g_print->setCursor(TestMenuItemCol, TestMenuItemRow);
}
else if((TestMenuItemCol == col) && (TestMenuItemRow == row))
{
// move from test -> done
g_print->setCursor(DoneMenuItemCol, DoneMenuItemRow);
}
else if((DoneMenuItemCol == col) && (DoneMenuItemRow == row))
{
// wrap around from Done -> to start of amount field
g_print->setCursor(AmountFieldStartCol, AmountFieldRow);
}
}
}
void ManualHandler::show()
{
g_print->clear();
printMenuItem(AmountMenuItemCol, AmountMenuItemRow, 0);
printMenuItem(FocusPosMenuItemCol, FocusPosMenuItemRow,1);
printMenuItem(TestMenuItemCol, TestMenuItemRow, 2);
printMenuItem(DoneMenuItemCol, DoneMenuItemRow, 3);
m_pos.setVal(0);
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_pSetup->m_driveAmount.display(AmountFieldStartCol, AmountFieldRow);
g_print->setCursor(AmountFieldStartCol, AmountFieldRow);
nk3.waitForReady(1000);
}
void ManualHandler::focus(uint8_t dir)
{
if(nk3.isLiveViewEnabled())
{
if(PTP_RC_OK == nk3.waitForReady(100))
{
int32_t amount = static_cast<int32_t>(g_pSetup->getDriveAmount());
uint16_t retVal = nk3.moveFocus(dir, amount);
switch(retVal)
{
case PTP_RC_OK:
{
switch(dir)
{
case 1:
{
m_pos.changeVal(-amount);
break;
}
case 2:
{
m_pos.changeVal(amount);
break;
}
}
break;
}
case NK_RC_InvalidStatus:
{
m_pos.setVal(0);
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->saveCursorLocation();
g_print->setCursor(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->print("chk cam");
g_print->restoreCursorLocation();
delay(1000);
break;
}
case NK_RC_MfDriveStepEnd:
{
// TODO: flag this condition & refuse any further
// focus drive in the same direction.
// Note that a subsequent successful
// call to nk3.MoveFocus is returning
// NK_RC_MfDriveStepInsufficiency (you can hear
// the focus motor move).
m_pos.setVal(0);
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->saveCursorLocation();
g_print->setCursor(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->print("end");
g_print->restoreCursorLocation();
break;
}
case NK_RC_MfDriveStepInsufficiency:
{
m_pos.setVal(0);
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->saveCursorLocation();
g_print->setCursor(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->print("isf");
g_print->restoreCursorLocation();
break;
}
}
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
}
}
}
#if 0
void ManualHandler::focus(uint8_t dir)
{
if(nk3.isLiveViewEnabled())
{
if(PTP_RC_OK == nk3.waitForReady(100))
{
int32_t amount = static_cast<int32_t>(g_pSetup->getDriveAmount());
if(PTP_RC_OK == nk3.moveFocus(dir, g_pSetup->getDriveAmount()))
{
//Serial.print("moveFocus: direction: ");
//Serial.print(dir);
//Serial.print(" amount ");
//Serial.println(amount);
//
bool proceed = false;
// bool updateDisplay = false;
uint16_t devReadyResp = PTP_RC_DeviceBusy;
while(!proceed)
{
devReadyResp = nk3.Operation(NK_OC_DeviceReady, 0, NULL);
switch(devReadyResp)
{
case PTP_RC_OK:
{
//Serial.println("PTP_RC_OK");
proceed = true;
// updateDisplay = true;
break;
}
case NK_RC_MfDriveStepEnd:
{
//Serial.println("NK_RC_MfDriveStepEnd");
break;
}
case PTP_RC_DeviceBusy:
{
//Serial.println("PTP_RC_DeviceBusy");
delay(100);
break;
}
case NK_RC_MfDriveStepInsufficiency:
{
//Serial.println("NK_RC_MfDriveStepInsufficiency");
if((nk3.enableLiveView(false) == PTP_RC_OK))
{
if((devReadyResp = nk3.waitForReady(1000)) == PTP_RC_OK)
{
if((devReadyResp = nk3.enableLiveView(true)) == PTP_RC_OK)
{
if((devReadyResp = nk3.waitForReady(1000)) == PTP_RC_OK)
{
m_pos.setVal(0);
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
return;
} //ready
} // moveFocus
} // ready
}
proceed = true;
break;
}
}
}
//Serial.println("MFDrive done");
switch(devReadyResp)
{
case PTP_RC_OK:
{
switch(dir)
{
case 1: // backward
{
m_pos.changeVal(-amount);
break;
}
case 2: // forward
{
m_pos.changeVal(amount);
break;
}
}
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
break;
}
case NK_RC_MfDriveStepInsufficiency:
{
// Indicates that the driving amount is insufficient
m_pos.setVal(0);
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->saveCursorLocation();
g_print->setCursor(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->print("isf");
g_print->restoreCursorLocation();
break;
}
}
//nk3.waitForReady(100);
}
}
}
}
void ManualHandler::focus(uint8_t dir)
{
if(nk3.isLiveViewEnabled())
{
if(PTP_RC_OK == nk3.waitForReady(100))
{
int32_t amount = static_cast<int32_t>(g_pSetup->getDriveAmount());
if(PTP_RC_OK == nk3.moveFocus(dir, g_pSetup->getDriveAmount()))
{
uint16_t retDevReady = nk3.Operation(NK_OC_DeviceReady, 0, NULL);
switch(retDevReady)
{
case PTP_RC_OK:
{
switch(dir)
{
case 1: // backward
{
m_pos.changeVal(-amount);
break;
}
case 2: // forward
{
m_pos.changeVal(amount);
break;
}
}
m_pos.display(FocusPosIndicatorCol, FocusPosIndicatorRow);
break;
}
case NK_RC_MfDriveStepEnd:
{
// Indicates that the MF driving reaches the termination.
g_print->saveCursorLocation();
g_print->setCursor(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->print("end");
g_print->restoreCursorLocation();
break;
}
case NK_RC_MfDriveStepInsufficiency:
{
// Indicates that the driving amount is insufficient
g_print->saveCursorLocation();
g_print->setCursor(FocusPosIndicatorCol, FocusPosIndicatorRow);
g_print->print("insuf");
g_print->restoreCursorLocation();
break;
}
}
//nk3.waitForReady(100);
}
}
}
}
#endif