Kestrel Interface
Loading...
Searching...
No Matches
kest_state.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_state.c";
8
9#ifdef KEST_USE_FREERTOS
10SemaphoreHandle_t state_mutex;
11#endif
12
14{
15 int len;
16
17 if (!cxt)
18 return ERR_NULL_PTR;
19
20 if (!state)
21 return ERR_BAD_ARGS;
22
25
26 state->input_gain = cxt->input_gain.value;
27 state->output_gain = cxt->output_gain.value;
28
29 kest_ui_page_create_identifier(cxt->pages.current_page, &state->current_page);
30
31 if (cxt->active_profile && cxt->active_profile->has_fname)
32 {
33 len = strlen(cxt->active_profile->fname);
34 if (len > 31)
35 len = 31;
36
37 memcpy(state->active_profile_fname, cxt->active_profile->fname, len);
38 state->active_profile_fname[len] = 0;
39 }
40 else
41 {
42 state->active_profile_fname[0] = 0;
43 }
44
45 if (cxt->sequence && cxt->sequence->has_fname)
46 {
47 len = strlen(cxt->sequence->fname);
48 if (len > KEST_FILENAME_LEN - 1)
49 len = KEST_FILENAME_LEN - 1;
50
51 memcpy(state->active_sequence_fname, cxt->sequence->fname, len);
52 state->active_sequence_fname[len] = 0;
53 }
54 else
55 {
56 state->active_sequence_fname[0] = 0;
57 }
58
60
61 return NO_ERROR;
62}
63
64
65void kest_state_representation_update(void *representer, void *representee)
66{
67 KEST_PRINTF("kest_state_representation_update\n");
68
69 if (!representee)
70 return;
71
72 kest_context *cxt = (kest_context*)representee;
73 kest_state state;
74
75 memset(&state, 0, sizeof(kest_state));
76
77 int ret_val;
78
79 if ((ret_val = kest_cxt_clone_state(cxt, &state)) != NO_ERROR)
80 {
81 KEST_PRINTF("Failed to clone state; aborting\n");
82 return;
83 }
84
85 KEST_PRINTF("Cloned state\n");
86
87 safe_file_write((int (*)(void*, const char*))save_state_to_file, &state, SETTINGS_FNAME);
88 KEST_PRINTF("kest_state_representation_update done\n");
89
90 return;
91}
92
93
95{
96 KEST_PRINTF("kest_cxt_restore_state\n");
97
98 if (!cxt || !state)
99 return ERR_NULL_PTR;
100
101 kest_profile *profile = NULL;
102 kest_sequence *sequence = NULL;
103 kest_ui_page *page;
104
105 int ret_val = NO_ERROR;
106 int tries = 0;
107
108 profile = cxt_get_profile_by_fname(cxt, state->active_profile_fname);
109
110 if (profile)
112
115
116 KEST_PRINTF("kest_cxt_restore_state done\n");
117 return NO_ERROR;
118}
119
121{
122 if (!cxt || !state)
123 return ERR_NULL_PTR;
124
126
127 int ret_val = enter_ui_page(page);
128
129 return ret_val;
130}
int kest_cxt_set_output_gain(kest_context *cxt, float gain)
int kest_cxt_release_mutex(kest_context *cxt)
int kest_cxt_obtain_mutex(kest_context *cxt)
int set_active_profile_from_sequence(kest_profile *profile)
int kest_cxt_set_input_gain(kest_context *cxt, float gain)
kest_profile * cxt_get_profile_by_fname(kest_context *cxt, const char *fname)
#define ERR_BAD_ARGS
#define NO_ERROR
#define ERR_MUTEX_UNAVAILABLE
#define ERR_NULL_PTR
int safe_file_write(int(*write_func)(void *arg, const char *fname), void *arg, const char *fname)
Definition kest_files.c:738
int save_state_to_file(kest_state *state, const char *fname)
Definition kest_files.c:258
#define SETTINGS_FNAME
Definition kest_files.h:24
#define KEST_FILENAME_LEN
Definition kest_int.h:72
kest_ui_page * kest_page_id_find_page(kest_context *cxt, kest_page_identifier id)
Definition kest_page_id.c:9
int kest_ui_page_create_identifier(kest_ui_page *page, kest_page_identifier *id)
#define KEST_PRINTF(...)
Definition kest_printf.h:10
void kest_state_representation_update(void *representer, void *representee)
Definition kest_state.c:65
int kest_cxt_clone_state(kest_context *cxt, kest_state *state)
Definition kest_state.c:13
int kest_cxt_restore_state(kest_context *cxt, kest_state *state)
Definition kest_state.c:94
int kest_cxt_enter_previous_current_page(kest_context *cxt, kest_state *state)
Definition kest_state.c:120
int enter_ui_page(kest_ui_page *page)
Definition kest_ui.c:244
kest_sequence * sequence
kest_parameter input_gain
kest_parameter output_gain
kest_profile * active_profile
char fname[KEST_FILENAME_LEN]
char fname[KEST_FILENAME_LEN]
float input_gain
Definition kest_state.h:6
kest_page_identifier current_page
Definition kest_state.h:9
float output_gain
Definition kest_state.h:7
char active_profile_fname[32]
Definition kest_state.h:10
char active_sequence_fname[32]
Definition kest_state.h:11