Kestrel Interface
Loading...
Searching...
No Matches
kest_sequence_view.c
Go to the documentation of this file.
1#include "kest_int.h"
2
3#ifndef PRINTLINES_ALLOWED
4#define PRINTLINES_ALLOWED 0
5#endif
6
7static const char *FNAME = "kest_sequence_view.c";
8
10{
11 if (!sequence)
12 return ERR_NULL_PTR;
13
14 sequence->view_page = kest_alloc(sizeof(kest_ui_page));
15
16 if (!sequence->view_page)
17 return ERR_ALLOC_FAIL;
18
19 init_sequence_view(sequence->view_page);
20 configure_sequence_view(sequence->view_page, sequence);
21
22 return NO_ERROR;
23}
24
26{
27 if (!button)
28 return ERR_NULL_PTR;
29
30 kest_profile *profile = button->data;
31
32 if (!profile)
33 return ERR_BAD_ARGS;
34
35 if (!profile->view_page)
36 {
37 if (!create_profile_view_for(profile))
38 return ERR_ALLOC_FAIL;
39 }
40
41 enter_ui_page_forwards(profile->view_page);
42
43 return NO_ERROR;
44}
45
47{
48 if (!button)
49 return ERR_NULL_PTR;
50
51 kest_profile *profile = (kest_profile*)button->data;
52
53 if (!button->array || !button->array->parent || !button->array->parent->data_struct)
54 return ERR_BAD_ARGS;
55
57
58 kest_sequence *sequence = str->sequence;
59
60 kest_sequence_move_profile(sequence, button->index, button->prev_index);
61
62 return NO_ERROR;
63}
64
66{
67 if (!page)
68 return ERR_NULL_PTR;
69
70 init_ui_page(page);
71
73
75
76 if (!str)
77 return ERR_ALLOC_FAIL;
78
79 str->sequence = NULL;
80
81 str->play = NULL;
82 str->plus = NULL;
83 str->save = NULL;
84
85 page->data_struct = str;
86
89
91
93
96
99
100 str->rep.representee = NULL;
101 str->rep.representer = page;
103
104 return NO_ERROR;
105}
106
107void seq_play_cb(lv_event_t *e)
108{
109 kest_ui_page *page = lv_event_get_user_data(e);
110
111 if (!page)
112 return;
113
115
116 if (!str)
117 return;
118
119 if (!str->sequence)
120 {
121 KEST_PRINTF("ERROR: no sequence\n");
122 return;
123 }
124
125 if (!str->sequence->active)
127
128 return;
129}
130
131void seq_plus_cb(lv_event_t *e)
132{
133 KEST_PRINTF("seq_plus_cb, line %d\n", __LINE__);
134
135 kest_ui_page *page = lv_event_get_user_data(e);
136
137 if (!page) return;
138
139 KEST_PRINTF("seq_plus_cb, line %d\n", __LINE__);
140
142
143 if (!str) return;
144
145 KEST_PRINTF("seq_plus_cb, line %d\n", __LINE__);
146
147 kest_profile *new_profile = create_new_profile();
148
149 if (!new_profile) return;
150
151 KEST_PRINTF("seq_plus_cb, line %d\n", __LINE__);
152
153 new_profile->sequence = str->sequence;
154
155 seq_profile_ll *node = sequence_append_profile_rp(str->sequence, new_profile);
156
157 if (!node) return;
158
159 KEST_PRINTF("seq_plus_cb, line %d\n", __LINE__);
160
162
163
164 KEST_PRINTF("seq_plus_cb, line %d\n", __LINE__);
166
167
168 KEST_PRINTF("seq_plus_cb, line %d\n", __LINE__);
169 if (page->ui_created)
171
172
173 KEST_PRINTF("seq_plus_cb, line %d\n", __LINE__);
174 kest_profile_add_representation(new_profile, &button->rep);
175
176 return;
177}
178
179void seq_save_cb(lv_event_t *e)
180{
181 kest_ui_page *page = lv_event_get_user_data(e);
182
183 if (!page)
184 return;
185
187
188 if (!str)
189 return;
190
191 kest_sequence *sequence = str->sequence;
192
193 if (sequence == &global_cxt.main_sequence)
194 {
196 }
197 else
198 {
199 save_sequence(sequence);
200 }
201
202 return;
203}
204
206{
207 if (!button)
208 return ERR_NULL_PTR;
209
210
211
212 return NO_ERROR;
213}
214
216{
217 if (!button) return ERR_NULL_PTR;
218 if (!button->data) return ERR_BAD_ARGS;
219
220 if (!button->array) return ERR_BAD_ARGS;
221 if (!button->array->parent) return ERR_BAD_ARGS;
222 if (!button->array->parent->data_struct) return ERR_BAD_ARGS;
223
225 kest_sequence *sequence = str->sequence;
226
227 if (!sequence) return ERR_NULL_PTR;
228
229 kest_profile *profile = (kest_profile*)button->data;
230
231 kest_sequence_delete_profile(sequence, profile);
232
233 // no dangling pointers tyvm
234 button->data = NULL;
235
236 return NO_ERROR;
237}
238
239void sequence_view_set_name(lv_event_t *e)
240{
241 kest_ui_page *page = (kest_ui_page*)lv_event_get_user_data(e);
243
244 const char *new_name = lv_textarea_get_text(page->panel->title);
245
246 if (str->sequence->name)
247 kest_free(str->sequence->name);
248
250
251 lv_obj_clear_state(page->panel->title, LV_STATE_FOCUSED);
252 lv_obj_add_state(page->container, LV_STATE_FOCUSED);
253
255
256 str->sequence->unsaved_changes = 1;
258
260
261 return;
262}
263
264void sequence_view_revert_name(lv_event_t *e)
265{
266 kest_ui_page *page = (kest_ui_page*)lv_event_get_user_data(e);
268
269 lv_textarea_set_text(page->panel->title, str->sequence->name);
270
271 lv_obj_clear_state(page->panel->title, LV_STATE_FOCUSED);
272 lv_obj_add_state(page->container, LV_STATE_FOCUSED);
273
275
276 return;
277}
278
280{
281 if (!page)
282 return ERR_NULL_PTR;
283
284 kest_sequence *sequence = (kest_sequence*)data;
285
286 if (!sequence)
287 return ERR_BAD_ARGS;
288
290
291 if (!str)
292 return ERR_ALLOC_FAIL;
293
294 str->sequence = sequence;
295
296 sequence->view_page = page;
297
298 page->panel = new_panel();
299
301
302 str->array->parent = page;
303
304 //str->array->free_cb = seq_view_free_cb;
308
309 str->play = ui_page_add_bottom_button(page, LV_SYMBOL_PLAY, seq_play_cb);
310 str->plus = ui_page_add_bottom_button(page, LV_SYMBOL_PLUS, seq_plus_cb);
311 str->save = ui_page_add_bottom_button(page, LV_SYMBOL_SAVE, seq_save_cb);
312
313 page->panel->text = sequence->name;
314
315 if (sequence != &global_cxt.main_sequence)
317
318 seq_profile_ll *current = sequence->profiles;
319
320 kest_active_button *button;
321
322 while (current)
323 {
324 if (current->data)
325 {
326 button = kest_active_button_array_append_new(str->array, current->data, current->data->name);
327
328 if (!button)
329 {
330 // die
331 return ERR_ALLOC_FAIL;
332 }
333
335
336
337 //button = append_new_glide_button_to_array(str->buttons, current->data, current->data->name);
338 //current->button = button;
339 }
340
341 current = current->next;
342 }
343
344 str->rep.representee = sequence;
345
346 kest_sequence_add_representation(sequence, &str->rep);
347
348 page->configured = 1;
349
350 return NO_ERROR;
351}
352
354{
355 KEST_PRINTF("create_sequence_view_ui\n");
356 if (!page)
357 return ERR_NULL_PTR;
358
360
361 if (!str)
362 return ERR_BAD_ARGS;
363
365
366 #ifndef USE_SDCARD
368 #endif
369
371
372 //create_glide_button_array_ui(str->buttons, page->container);
373
374 page->ui_created = 1;
375
376 KEST_PRINTF("create_sequence_view_ui done\n");
377 return NO_ERROR;
378}
379
381{
382 if (!page)
383 return ERR_NULL_PTR;
384
385
386
387 return NO_ERROR;
388}
389
391{
392 if (!page)
393 return ERR_NULL_PTR;
394
395
396
397 return NO_ERROR;
398}
399
401{
402 if (!page)
403 return ERR_NULL_PTR;
404
405
406
407 return NO_ERROR;
408
409}
410
411void sequence_view_rep_update(void *representer, void *representee)
412{
413 kest_ui_page *page = (kest_ui_page*)representer;
414 kest_sequence *sequence = (kest_sequence*)representee;
415
416 if (!page || !sequence)
417 return;
418
419 ui_page_set_title(page, sequence->name);
420
422
423 if (!str)
424 return;
425
426 if (sequence->active)
427 {
429 }
430 else
431 {
433 }
434
435 #ifdef USE_SDCARD
436 if (sequence->unsaved_changes)
437 {
439 }
440 else
441 {
443 }
444 #endif
445
446 return;
447}
448
449
450void sequence_view_profile_button_rep_update(void *representer, void *representee)
451{
452 KEST_PRINTF("sequence_view_profile_button_rep_update\n");
453 kest_active_button *button = (kest_active_button*)representer;
454 kest_profile *profile = (kest_profile*)representee;
455
456 KEST_PRINTF("button = %p, profile = %s\n", button, profile ? (profile->name ? profile->name : "Unnamed Profile") : "NULL");
457
458 if (!button || !profile)
459 {
460 KEST_PRINTF("sequence_view_profile_button_rep_update bailing...\n");
461 return;
462 }
463
464 kest_active_button_change_label(button, profile->name);
465
466 if (profile->active)
467 {
468 KEST_PRINTF("profile is active; activating active symbol\n");
470 }
471 else
472 {
473 KEST_PRINTF("profile is inactive; disabling active symbol\n");
475 }
476
477 KEST_PRINTF("sequence_view_profile_button_rep_update done\n");
478
479 return;
480}
void kest_free(void *ptr)
Definition kest_alloc.c:32
void * kest_alloc(size_t size)
Definition kest_alloc.c:11
char * kest_strndup(const char *str, size_t n)
Definition kest_alloc.c:73
int kest_button_disable(kest_button *button)
int kest_active_button_create_ui(kest_active_button *button, lv_obj_t *parent)
kest_active_button * kest_active_button_array_append_new(kest_active_button_array *array, void *data, char *label)
int kest_active_button_array_create_ui(kest_active_button_array *array, lv_obj_t *parent)
int kest_button_enable(kest_button *button)
int kest_active_button_array_set_length(kest_active_button_array *array, int n)
int kest_active_button_change_label(kest_active_button *button, char *text)
void kest_active_button_set_representation(kest_active_button *button, void *representer, void *representee, void(*update)(void *, void *))
kest_active_button_array * kest_active_button_array_new()
int kest_active_button_reset_del_button(kest_active_button *button)
int kest_active_button_swap_del_button_for_persistent_unclickable(kest_active_button *button, const char *label)
#define KEST_ACTIVE_BUTTON_ARRAY_FLAG_DELETEABLE
#define KEST_ACTIVE_BUTTON_ARRAY_FLAG_MOVEABLE
int cxt_save_all_profiles(kest_context *cxt)
#define ERR_ALLOC_FAIL
#define ERR_BAD_ARGS
#define NO_ERROR
#define ERR_NULL_PTR
int save_sequence(kest_sequence *sequence)
Definition kest_files.c:921
kest_context global_cxt
Definition kest_int.c:12
#define KEST_PRINTF(...)
Definition kest_printf.h:10
int kest_profile_add_representation(kest_profile *profile, kest_representation *rep)
#define PROFILE_NAME_MAX_LEN
Definition kest_profile.h:4
kest_ui_page * create_profile_view_for(kest_profile *profile)
int kest_sequence_add_representation(kest_sequence *sequence, kest_representation *rep)
int kest_sequence_delete_profile(kest_sequence *sequence, kest_profile *profile)
int kest_sequence_move_profile(kest_sequence *sequence, int pos, int new_pos)
int kest_sequence_update_representations(kest_sequence *sequence)
seq_profile_ll * sequence_append_profile_rp(kest_sequence *sequence, kest_profile *profile)
int kest_sequence_begin(kest_sequence *sequence)
void sequence_view_rep_update(void *representer, void *representee)
int free_sequence_view_ui(kest_ui_page *page)
int sequence_view_free_all(kest_ui_page *page)
void seq_save_cb(lv_event_t *e)
void seq_play_cb(lv_event_t *e)
void sequence_view_revert_name(lv_event_t *e)
int create_sequence_view_for(kest_sequence *sequence)
int seq_view_moved_cb(kest_active_button *button)
void seq_plus_cb(lv_event_t *e)
int create_sequence_view_ui(kest_ui_page *page)
void sequence_view_set_name(lv_event_t *e)
int seq_view_free_cb(kest_active_button *button)
int seq_view_delete_cb(kest_active_button *button)
void sequence_view_profile_button_rep_update(void *representer, void *representee)
int seq_view_clicked_cb(kest_active_button *button)
int configure_sequence_view(kest_ui_page *page, void *data)
int init_sequence_view(kest_ui_page *page)
int refresh_sequence_view(kest_ui_page *page)
kest_ui_page_panel * new_panel()
Definition kest_ui.c:991
int ui_page_set_title_rw(kest_ui_page *page, lv_event_cb_t save_cb, lv_event_cb_t cancel_cb)
Definition kest_ui.c:1335
int enter_ui_page_forwards(kest_ui_page *page)
Definition kest_ui.c:299
int ui_page_add_back_button(kest_ui_page *page)
Definition kest_ui.c:1129
kest_button * ui_page_add_bottom_button(kest_ui_page *page, const char *label, lv_event_cb_t cb)
Definition kest_ui.c:1308
void hide_keyboard()
Definition kest_ui.c:769
int ui_page_set_title(kest_ui_page *page, const char *text)
Definition kest_ui.c:1066
int ui_page_create_base_ui(kest_ui_page *page)
Definition kest_ui.c:1207
int init_ui_page(kest_ui_page *page)
Definition kest_ui.c:152
#define KEST_UI_PAGE_SEQ_VIEW
Definition kest_ui.h:79
int(* moved_cb)(struct kest_active_button *button)
int(* delete_cb)(struct kest_active_button *button)
struct kest_ui_page * parent
int(* clicked_cb)(struct kest_active_button *button)
kest_representation rep
struct kest_active_button_array * array
void(* update)(void *representer, void *representee)
kest_active_button_array * array
kest_representation rep
seq_profile_ll * profiles
lv_obj_t * title
Definition kest_ui.h:51
int ui_created
Definition kest_ui.h:107
kest_ui_page_panel * panel
Definition kest_ui.h:94
int(* create_ui)(struct kest_ui_page *page)
Definition kest_ui.h:97
lv_obj_t * container
Definition kest_ui.h:92
void * data_struct
Definition kest_ui.h:104
int configured
Definition kest_ui.h:106
int(* configure)(struct kest_ui_page *page, void *data)
Definition kest_ui.h:96
kest_profile * data
struct seq_profile_ll * next