-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_input.pde
439 lines (322 loc) · 9.1 KB
/
user_input.pde
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
/*
-- user input functions
LightRails 1.0
A dynamic external exposure control system with
integrated intervalometer for time-lapse
photography
Copyright (c) 2008-2009 C. A. Church drone< a_t >dronecolony.com
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.
*/
void check_input() {
// this function determines if any button has been hit,
// and what to do about it
// up and down do not require a HIGH (unpressed) reading
// so that you can hold them down and quickly cycle through
// values (about 3 changes per second)
if( digitalRead(B_UP) == LOW && millis() - button_hit > 300) {
button_hit = millis();
take_button_action(0);
return;
}
if( digitalRead(B_DN) == LOW && millis() - button_hit > 300 ) {
//pre_dn = true;
take_button_action(1);
button_hit = millis();
return;
}
if( digitalRead(B_LT) == LOW) {
if(buttons & B00100000 && millis() - button_hit > 300) {
buttons &= B11011111;
take_button_action(2);
button_hit = millis();
return;
}
buttons &= B11011111;
}
else {
buttons |= B00100000;
}
if( digitalRead(B_RT) == LOW ) {
if( buttons & B00010000 && millis() - button_hit > 300) {
buttons &= B11101111;
take_button_action(3);
button_hit = millis();
return;
}
buttons &= B11101111;
}
else {
buttons |= B00010000;
}
if( digitalRead(B_CT) == LOW ) {
if( buttons & B00001000 && millis() - button_hit > 300) {
buttons &= B11110111;
take_button_action(4);
button_hit = millis();
return;
}
buttons &= B11110111;
}
else {
buttons |= B00001000;
}
}
void take_button_action( byte button ) {
// this function operates whatever action is desired when
// a button is pressed. called by check_input()
switch(button) {
case 0:
// up hit
if( status & B00010000 ) {
// we're in a setup screen...
// increasing value at current cursor position
change_setup_value(setup_step, 1);
// update flag to show change in display value
status |= B00000001;
return;
}
else {
// on main screen - up turns intervalometer on
// if intervalometer on already, do nothing
if( status & B10000000 )
return;
// turn on intervalometer
status |= B10000000;
// save current exposure reading for latch
pre_exp_tm = exp_tm;
}
break;
case 1:
// down hit
if( status & B00010000 ) {
// we're in a setup screen
// decreasing value at current cursor position
change_setup_value(setup_step, -1);
status |= B00000001;
return;
}
else {
// main menu - turn off intervalometer
// re-set latch matched (if set)
status &= B01110111;
shots_fired = 0;
}
break;
case 2:
// left button was hit
// do nothing if in setup menu
if( status & B00010000 )
return;
// main display, cycle through display values
if( disp_enable & B10000000 ) {
// we were already left, move to the furthest right
// value
disp_enable = B00000001;
// set screen to update
status |= B00000001;
}
else {
// shift current display value left
disp_enable = disp_enable << 1;
status |= B00000001;
}
break;
case 3:
// right button was hit
// do nothing if in setup menu
if( status & B00010000 )
return;
// main display, cycle through display values
if( disp_enable & B00000001 ) {
// we were already at furthest right value,
// need to move to furthest left value
disp_enable = B10000000;
// set screen to update
status |= B00000001;
}
else {
// shift current display right
disp_enable = disp_enable >> 1;
// set screen to update
status |= B00000001;
}
break;
case 4:
// center button hit
if( status & B00010000 ) {
// in setup mode - we're going to change which
// setup value we're displaying
// set display to update
status |= B00000001;
if( setup_step == MAX_SETUP_STEPS - 1 ) {
// no more steps to go, exit menu
setup_step = 0;
// set that we're no longer in setup
status &= B11101111;
return;
}
setup_step++;
return;
}
else {
// not in setup or input -
// go into setup mode, tell display
// to refresh
status |= B00010001;
return;
}
break;
}
}
void change_setup_value( byte which, int what ) {
switch( which ) {
case 0:
{
// change iso value, convert to logarithmic
// scale first, then add or subtract one step
// and convert back to arithmetic scale
float foo = log(iso_rating) / log(10);
int din = ( 10 * foo ) + 1;
din += what;
if( din < 1 )
din = 1;
float bar = pow(10, (float) ( (float) din - 1) / (float) 10 );
if( bar > int(bar) ) {
iso_rating = int(bar) + 1;
}
else {
iso_rating = int(bar);
}
}
break;
case 1:
{
// move f_stop value - move one third step
// either direction
float steps = log( f_stop ) / log( sqrt(2) );
if( what > 0 ) {
steps += 0.3333;
}
else {
steps -= 0.3333;
}
if( steps < 0 )
steps = 0;
f_stop = pow( sqrt(2), steps );
}
break;
case 2:
// ev adjust moes in 1/4 EV increments
ev_adjust += (float) what * 0.25;
break;
case 3:
// ev steps determines how many divisions of an EV
// there are when calculating automatic exposure
// values. more steps = better granularity in exposure
// timing.
ev_steps += what;
if( ev_steps < 0 )
ev_steps = 0;
break;
case 4:
camera_delay += what;
if( camera_delay < 1 )
camera_delay = 1;
// ms delay time
real_camera_delay = camera_delay * 1000;
break;
case 5:
// cycle between latch settings
if( status & B01000000 ) {
status &= B10111111;
status |= B00100000;
}
else if( status & B00100000 ) {
status &= B10011111;
}
else {
status |= B01000000;
}
break;
case 6:
min_exp_tm += what;
// don't allow min time to be less than 0
if( min_exp_tm <= 0 )
min_exp_tm = 0;
break;
case 7:
max_exp_tm += what;
// don't allow max time to be less than 0
if( max_exp_tm <= 0 )
max_exp_tm = 0;
break;
case 8:
// change scaling:
// scaling value can be 2, 10, or 100
// allow wrap around from highest to lowest
// and vice-versa
freq_mult += what;
// we only get to 11 by going up from 10 and
// we only 1 by going down from 2 - next step
// either way is 100
if( freq_mult == 11 || freq_mult == 1 ) {
tsl_set_scaling(100);
}
else if( freq_mult == 9 || freq_mult == 101 ) {
// if we're moving down from 10, or up from 100
// move to lowest setting
tsl_set_scaling(2);
}
else {
// if neither of the above cases is true, then our only
// destination is 10
tsl_set_scaling(10);
}
break;
case 9:
{
// move ttl_stop value - move one third step
// either direction
float steps = log( ttl_stop ) / log(sqrt(2));
if( steps < 0 )
steps = 0;
if( what > 0 ) {
steps += 0.3333;
}
else {
steps -= 0.3333;
}
// for ttl stop, we want to get to zero, if possible
// for non-ttl readings. We go ahead and skip every stop below
// 1.0 for the heck of it. (Very few lenses go below 1.0)
if( steps < 0 ) {
ttl_stop = 0.0;
}
else {
ttl_stop = pow( sqrt(2), steps );
// handle rounding for higher f-stops
if( ttl_stop > 7.1 )
ttl_stop = int(ttl_stop);
}
}
break;
case 10:
light_type = light_type == 1 ? 0 : 1;
break;
case 11:
ev_diff_ceiling += what;
break;
default:
break;
}
return;
}