forked from 400plus/400plus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintercom.c
341 lines (268 loc) · 7.06 KB
/
intercom.c
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
#include <vxworks.h>
#include "firmware.h"
#include "firmware/gui.h"
#include "main.h"
#include "macros.h"
#include "actions.h"
#include "autoiso.h"
#include "af_patterns.h"
#include "button.h"
#include "cmodes.h"
#include "fexp.h"
#include "qexp.h"
#include "languages.h"
#include "menu.h"
#include "menu_main.h"
#include "menu_rename.h"
#include "msm.h"
#include "persist.h"
#include "shortcuts.h"
#include "viewfinder.h"
#include "debug.h"
#include "intercom.h"
// Proxy listeners
int proxy_script_restore (char *message);
int proxy_script_stop (char *message);
int proxy_set_language (char *message);
int proxy_dialog_enter (char *message);
int proxy_dialog_exit (char *message);
int proxy_dialog_afoff (char *message);
int proxy_measuring (char *message);
int proxy_measurement (char *message);
int proxy_shoot_start (char *message);
int proxy_shoot_finish (char *message);
int proxy_settings0 (char *message);
int proxy_settings3 (char *message);
int proxy_button (char *message);
int proxy_wheel (char *message);
int proxy_initialize (char *message);
int proxy_tv (char *message);
int proxy_av (char *message);
int proxy_aeb (char *message);
typedef int (*proxy_t) (char*);
proxy_t listeners_script[0x100] = {
[IC_SHUTDOWN] = proxy_script_restore,
[IC_SHOOT_START] = proxy_shoot_start,
[IC_BUTTON_DP] = proxy_script_stop,
};
proxy_t listeners_menu[0x100] = {
[IC_DIALOGOFF] = proxy_dialog_exit,
[IC_BUTTON_WHEEL] = proxy_wheel,
[IC_BUTTON_DISP] = proxy_button,
[IC_BUTTON_SET] = proxy_button,
[IC_BUTTON_RIGHT] = proxy_button,
[IC_BUTTON_LEFT] = proxy_button,
[IC_BUTTON_DP] = proxy_button,
[IC_BUTTON_AV] = proxy_button,
};
proxy_t listeners_main[0x100] = {
[IC_SET_TV_VAL] = proxy_tv,
[IC_SET_AV_VAL] = proxy_av,
[IC_SET_AE_BKT] = proxy_aeb,
[IC_SET_LANGUAGE] = proxy_set_language,
[IC_DIALOGON] = proxy_dialog_enter,
[IC_MEASURING] = proxy_measuring,
[IC_MEASUREMENT] = proxy_measurement,
[IC_SHOOT_FINISH] = proxy_shoot_finish,
[IC_UNKNOWN_8D] = proxy_initialize,
[IC_SETTINGS_0] = proxy_settings0,
[IC_SETTINGS_3] = proxy_settings3,
[IC_AFPDLGOFF] = proxy_dialog_afoff,
[IC_BUTTON_WHEEL] = proxy_wheel,
[IC_BUTTON_DISP] = proxy_button,
[IC_BUTTON_SET] = proxy_button,
[IC_BUTTON_UP] = proxy_button,
[IC_BUTTON_DOWN] = proxy_button,
[IC_BUTTON_RIGHT] = proxy_button,
[IC_BUTTON_LEFT] = proxy_button,
[IC_BUTTON_DP] = proxy_button,
[IC_BUTTON_AV] = proxy_button,
};
button_t message2button[0x100] = {
[IC_BUTTON_DISP] = BUTTON_DISP,
[IC_BUTTON_SET] = BUTTON_SET,
[IC_BUTTON_UP] = BUTTON_UP,
[IC_BUTTON_DOWN] = BUTTON_DOWN,
[IC_BUTTON_RIGHT] = BUTTON_RIGHT,
[IC_BUTTON_LEFT] = BUTTON_LEFT,
[IC_BUTTON_DP] = BUTTON_DP,
[IC_BUTTON_AV] = BUTTON_AV,
};
void message_logger (char *message);
int send_to_intercom(int message, int parm) {
int result, length = 1;
switch (message) {
case IC_SET_AE:
status.ignore_msg = IC_SETTINGS_0;
break;
case IC_SET_AV_VAL:
case IC_SET_TV_VAL:
status.ignore_msg = message;
break;
case IC_RELEASE:
case IC_SET_REALTIME_ISO_0:
case IC_SET_REALTIME_ISO_1:
length = 0;
break;
case IC_SET_ISO:
case IC_SET_AF_POINT:
case IC_SET_COLOR_TEMP:
length = 2;
break;
}
result = SendToIntercom(message, length, parm);
SleepTask(INTERCOM_WAIT);
return result;
}
void intercom_proxy(const int handler, char *message) {
proxy_t listener;
proxy_t *listeners;
#ifdef ENABLE_DEBUG
message_logger(message);
#endif
if (status.ignore_msg == message [1]) {
status.ignore_msg = FALSE;
} else {
// Fast path for the case of a running script
if (status.script_running)
listeners = listeners_script;
else if (status.menu_running)
listeners = listeners_menu;
else
listeners = listeners_main;
if ((listener = listeners[message[1]]) != NULL)
if (listener(message))
return;
}
IntercomHandler(handler, message);
}
#ifdef ENABLE_DEBUG
void message_logger(char *message) {
int i;
char text[256];
static int id = 0;
for (i = 0; i < message[0]; i++)
sprintf(text + 3 * i, "%02X ", message[i]);
debug_log("MSG%04d-%02X: %s", id++, FLAG_GUI_MODE, text);
}
#endif
int proxy_script_restore(char *message) {
script_restore();
return FALSE;
}
int proxy_script_stop(char *message) {
status.script_stopping = TRUE;
return TRUE;
}
int proxy_set_language(char *message) {
enqueue_action(lang_pack_config);
return FALSE;
}
int proxy_dialog_enter(char *message) {
status.afp_dialog = (message[2] == IC_SET_AF);
shortcut_stop();
return FALSE;
}
int proxy_dialog_exit(char *message) {
enqueue_action(menu_event_finish);
return FALSE;
}
int proxy_dialog_afoff(char *message) {
if (status.afp_dialog) {
// Open Extended AF-Point selection dialog
message[1] = IC_AFPDLGON;
status.afp_dialog = FALSE;
enqueue_action(afp_enter);
}
return FALSE;
}
int proxy_measuring(char *message) {
status.measuring = message[2];
if (! status.measuring)
enqueue_action(viewfinder_end);
return FALSE;
}
int proxy_measurement(char *message) {
if (status.measuring) {
status.measured_tv = message[2];
status.measured_av = message[3];
status.measured_ec = message[4];
switch(status.vf_status) {
case VF_STATUS_QEXP:
enqueue_action(qexp_update);
break;
default:
if (settings.autoiso_enable)
enqueue_action(autoiso);
break;
}
}
return FALSE;
}
int proxy_shoot_start(char *message) {
status.last_shot_tv = message[2];
status.last_shot_av = message[3];
return FALSE;
}
int proxy_shoot_finish(char *message) {
status.last_shot_fl = message[2] | (message[3] << 8);
shortcut_stop();
if (status.msm_active)
enqueue_action(msm_stop);
return FALSE;
}
int proxy_initialize(char *message) {
static int first = TRUE;
if (first) {
first = FALSE;
enqueue_action(start_up);
}
return FALSE;
}
int proxy_settings0(char *message) {
static int first = TRUE;
if (!status.msm_active)
status.main_dial_ae = message[2];
if (first) {
first = FALSE;
} else {
if (status.vf_status == VF_STATUS_FEXP)
fexp_disable();
if (!status.msm_active)
enqueue_action(cmode_apply);
}
shortcut_stop();
return FALSE;
}
int proxy_settings3(char *message) {
// enqueue_action(restore_display);
if (settings.autoiso_enable)
enqueue_action(autoiso_restore);
return FALSE;
}
int proxy_button(char *message) {
return button_handler(message2button[message[1]], message[0] > 3 ? message[2] : TRUE);
}
int proxy_wheel(char *message) {
return button_handler((message[2] & 0x80) ? BUTTON_WHEEL_LEFT : BUTTON_WHEEL_RIGHT, TRUE);
}
int proxy_av(char *message) {
if (status.vf_status == VF_STATUS_FEXP)
enqueue_action(fexp_update_tv);
return FALSE;
}
int proxy_tv(char *message) {
if (settings.autoiso_enable)
enqueue_action(autoiso_restore);
if (status.vf_status == VF_STATUS_FEXP)
enqueue_action(fexp_update_av);
return FALSE;
}
int proxy_aeb(char *message) {
persist.aeb = message[2];
if (persist.aeb)
persist.last_aeb = persist.aeb;
if (!status.shortcut_running)
enqueue_action(persist_write);
return FALSE;
}