forked from 400plus/400plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmodes.c
247 lines (184 loc) · 5.21 KB
/
cmodes.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
#include <vxworks.h>
#include <ioLib.h>
#include <stdio.h>
#include "firmware.h"
#include "firmware/fio.h"
#include "main.h"
#include "display.h"
#include "languages.h"
#include "snapshots.h"
#include "utils.h"
#include "debug.h"
#include "cmodes.h"
cmodes_config_t cmodes_default = {
recall_camera : TRUE,
recall_400plus : TRUE,
recall_ordering : FALSE,
recall_settings : FALSE,
recall_image : TRUE,
recall_cfn : TRUE,
};
cmodes_config_t cmodes_config;
int amode_read (AE_MODE ae_mode, snapshot_t *snapshot);
int amode_write (AE_MODE ae_mode);
int amode_delete (AE_MODE ae_mode);
void cmode_recall_apply(int full);
void get_cmode_filenames(char filenames[][FILENAME_LENGTH], int cmode_id);
void get_amode_filenames(char filenames[][FILENAME_LENGTH], AE_MODE ae_mode);
void cmodes_read() {
int id;
int version = 0;
int file = -1;
cmodes_config_t buffer;
for (id = 0; id < CMODES_MAX; id ++) {
sprintf(cmodes_default.names[id], "%s %X", LP_WORD(L_S_CMODE_NAME), id);
cmodes_default.order[id] = id;
}
for (id = 0; id < CMODES_MODES; id ++) {
cmodes_default.assign[id] = CMODE_NONE;
}
cmodes_config = cmodes_default;
if ((file = FIO_OpenFile(MKPATH_NEW(CMODES_CONFIG), O_RDONLY)) == -1)
if ((file = FIO_OpenFile(MKPATH_OLD(CMODES_CONFIG), O_RDONLY)) == -1)
goto end;
if (FIO_ReadFile(file, &version, sizeof(version)) != sizeof(version))
goto end;
if (version != SNAPSHOT_VERSION)
goto end;
if (FIO_ReadFile(file, &buffer, sizeof(buffer)) != sizeof(buffer))
goto end;
cmodes_config = buffer;
end:
if (file != -1)
FIO_CloseFile(file);
}
void cmodes_write() {
const int version = SNAPSHOT_VERSION;
int file = -1;
if ((file = FIO_OpenFile(MKPATH_NEW(CMODES_CONFIG), O_CREAT | O_WRONLY)) == -1)
if (status.folder_exists || (file = FIO_OpenFile(MKPATH_OLD(CMODES_CONFIG), O_CREAT | O_WRONLY)) == -1)
goto end;
FIO_WriteFile(file, (void*)&version, sizeof(version));
FIO_WriteFile(file, (void*)&cmodes_config, sizeof(cmodes_config));
FIO_CloseFile(file);
end:
if (file != -1)
FIO_CloseFile(file);
}
void cmodes_restore() {
cmodes_config = cmodes_default;
cmodes_write();
}
void cmodes_delete() {
int id;
for(id = 0; id < CMODES_MAX; id++)
cmode_delete(id);
}
int cmode_read(int id, snapshot_t *cmode) {
char filenames[2][FILENAME_LENGTH];
get_cmode_filenames(filenames, id);
return snapshot_read(filenames, cmode);
}
int cmode_write(int id) {
char filenames[2][FILENAME_LENGTH];
get_cmode_filenames(filenames, id);
return snapshot_write(filenames);
}
int cmode_delete(int id) {
char filenames[2][FILENAME_LENGTH];
get_cmode_filenames(filenames, id);
return snapshot_delete(filenames);
}
int amode_read(AE_MODE ae_mode, snapshot_t *mode) {
char filenames[2][FILENAME_LENGTH];
get_amode_filenames(filenames, ae_mode);
return snapshot_read(filenames, mode);
}
int amode_write(AE_MODE ae_mode) {
char filenames[2][FILENAME_LENGTH];
get_amode_filenames(filenames, ae_mode);
return snapshot_write(filenames);
}
int amode_delete(AE_MODE ae_mode) {
char filenames[2][FILENAME_LENGTH];
get_amode_filenames(filenames, ae_mode);
return snapshot_delete(filenames);
}
void cmode_recall() {
cmode_recall_apply(FALSE);
}
void cmode_apply() {
cmode_recall_apply(TRUE);
}
void cmode_recall_apply(int full) {
int current_cmode = get_current_cmode();
snapshot_t snapshot;
if(AE_IS_CREATIVE(status.main_dial_ae)) {
// Update current status
status.cmode_active = FALSE;
// Try to find a mode file, and load it
if (amode_read(status.main_dial_ae, &snapshot)) {
amode_delete(status.main_dial_ae);
snapshot_apply(&snapshot);
}
} else {
// Only if a custom mode was loaded, and we can read it back
if (current_cmode != CMODE_NONE && cmode_read(current_cmode, &snapshot)) {
// Update current status
status.cmode_active = TRUE;
// First revert to AE mode
snapshot_recall(&snapshot);
if (full) {
// Save current mode before overwriting other parameters
if (!status.cmode_active)
amode_write(DPData.ae);
// Then apply full custom mode
snapshot_apply(&snapshot);
}
} else {
// Update current status
status.cmode_active = FALSE;
}
}
}
void get_cmode_filenames(char filenames[][FILENAME_LENGTH], int cmode_id) {
sprintf(filenames[0], "%s/%s/" CMODES_FILE, FOLDER_ROOT, FOLDER_NAME, cmode_id);
sprintf(filenames[1], "%s/" CMODES_FILE, FOLDER_ROOT, cmode_id);
}
void get_amode_filenames(char filenames[][FILENAME_LENGTH], AE_MODE ae_mode) {
char id;
switch (ae_mode) {
case AE_MODE_P:
id = 'P';
break;
case AE_MODE_TV:
id = 'T';
break;
case AE_MODE_AV:
id = 'A';
break;
case AE_MODE_M:
id = 'M';
break;
case AE_MODE_ADEP:
id = 'D';
break;
default:
// This should never happen...
id = 'X';
break;
}
sprintf(filenames[0], "%s/%s/" AMODES_FILE, FOLDER_ROOT, FOLDER_NAME, id);
sprintf(filenames[1], "%s/" AMODES_FILE, FOLDER_ROOT, id);
}
int get_current_cmode() {
if (AE_IS_AUTO(status.main_dial_ae))
return cmodes_config.assign[status.main_dial_ae - AE_MODE_AUTO];
else
return CMODE_NONE;
}
void set_current_cmode(int cmode_id) {
status.cmode_active = (cmode_id != CMODE_NONE);
if (AE_IS_AUTO(status.main_dial_ae))
cmodes_config.assign[status.main_dial_ae - AE_MODE_AUTO] = cmode_id;
}