Skip to content

Commit

Permalink
Move elem and quickpages into Model structure
Browse files Browse the repository at this point in the history
  • Loading branch information
howard0su committed Feb 20, 2019
1 parent 6bd4c49 commit 9e11837
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 110 deletions.
20 changes: 10 additions & 10 deletions src/config/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
int max = PAGE_GetNumPages();
for(i = 0; i < max; i++) {
if(mapstrcasecmp(PAGE_GetName(i), value) == 0) {
m->pagecfg2.quickpage[idx] = i;
m->quickpage[idx] = i;
return 1;
}
}
Expand All @@ -423,7 +423,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
};
if (! MATCH_SECTION(SECTION_GUI)) {
if(MATCH_SECTION("gui-320x240")
&& (! ELEM_USED(Model.pagecfg2.elem[0]) || seen_res != HIRES))
&& (! ELEM_USED(Model.elem[0]) || seen_res != HIRES))
{
seen_res = LOWRES;
offset_x = (LCD_WIDTH - 320) / 2;
Expand All @@ -432,7 +432,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
return 1;
} else {
if (seen_res == LOWRES) {
memset(&Model.pagecfg2.elem, 0, sizeof(Model.pagecfg2.elem));
memset(&Model.elem, 0, sizeof(Model.elem));
}
seen_res = HIRES;
}
Expand All @@ -441,7 +441,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
return 1;
#endif
for (idx = 0; idx < NUM_ELEMS; idx++) {
if (Model.pagecfg2.elem[idx].type == ELEM_NONE)
if (Model.elem[idx].type == ELEM_NONE)
break;
}
if (idx == NUM_ELEMS) {
Expand All @@ -468,7 +468,7 @@ static int layout_ini_handler(void* user, const char* section, const char* name,
}

struct elem *cur_elem;
cur_elem = &Model.pagecfg2.elem[idx];
cur_elem = &Model.elem[idx];

memset(cur_elem, 0, sizeof(struct elem));
cur_elem->x = data[0];
Expand Down Expand Up @@ -1384,7 +1384,7 @@ u8 CONFIG_WriteModel(u8 model_num) {
}
fprintf(fh, "[%s]\n", SECTION_GUI);
for(idx = 0; idx < NUM_ELEMS; idx++) {
struct elem *cur_elem = &Model.pagecfg2.elem[idx];
struct elem *cur_elem = &Model.elem[idx];
if (cur_elem->type == ELEM_NONE)
break;
int src = cur_elem->src;
Expand Down Expand Up @@ -1418,8 +1418,8 @@ u8 CONFIG_WriteModel(u8 model_num) {
}
}
for(idx = 0; idx < NUM_QUICKPAGES; idx++) {
if (WRITE_FULL_MODEL || m->pagecfg2.quickpage[idx]) {
u8 val = m->pagecfg2.quickpage[idx];
if (WRITE_FULL_MODEL || m->quickpage[idx]) {
u8 val = m->quickpage[idx];
fprintf(fh, "%s%d=%s\n", GUI_QUICKPAGE, idx+1, PAGE_GetName(val));
}
}
Expand Down Expand Up @@ -1501,7 +1501,7 @@ u8 CONFIG_ReadModel(u8 model_num) {
if (CONFIG_IniParse(file, ini_handler, &Model)) {
printf("Failed to parse Model file: %s\n", file);
}
if (Model.pagecfg2.elem[0].type == ELEM_NONE)
if (Model.elem[0].type == ELEM_NONE)
CONFIG_ReadLayout("layout/default.ini");
if(! PROTOCOL_HasPowerAmp(Model.protocol))
Model.tx_power = TXPOWER_150mW;
Expand Down Expand Up @@ -1628,7 +1628,7 @@ u8 CONFIG_ReadTemplate(const char *filename) {
}

u8 CONFIG_ReadLayout(const char *filename) {
memset(&Model.pagecfg2, 0, sizeof(Model.pagecfg2));
memset(&Model.elem, 0, sizeof(Model.elem));
if (CONFIG_IniParse(filename, layout_ini_handler, &Model)) {
printf("Failed to parse Layout file: %s\n", filename);
return 0;
Expand Down
3 changes: 2 additions & 1 deletion src/config/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ struct Model {
struct Mixer mixers[NUM_MIXERS];
struct Limit limits[NUM_OUT_CHANNELS];
struct Timer timer[NUM_TIMERS];
struct PageCfg2 pagecfg2;
struct elem elem[NUM_ELEMS];
u8 quickpage[NUM_QUICKPAGES];
#if HAS_DATALOG
struct datalog datalog;
#endif
Expand Down
5 changes: 0 additions & 5 deletions src/config/pagecfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ struct elem {
//#define NUM_BAR_ELEMS 8
//#define NUM_TOGGLE_ELEMS 4

struct PageCfg2 {
struct elem elem[NUM_ELEMS];
u8 quickpage[NUM_QUICKPAGES];
u8 padding_1[3];
};

enum {
ELEM_NONE,
Expand Down
15 changes: 7 additions & 8 deletions src/pages/128x64x1/main_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ enum {
};
#endif //OVERRIDE_PLACEMENT
static struct layout_page * const lp = &pagemem.u.layout_page;
static struct PageCfg2 * const pc = &Model.pagecfg2;
static struct mainconfig_obj * const gui = &gui_objs.u.mainconfig;
static u16 current_selected = 0;

Expand Down Expand Up @@ -77,7 +76,7 @@ static const char *cfglabel_cb(guiObject_t *obj, const void *data)
{
(void)obj;
int i = (long)data;
int type = pc->elem[i].type;
int type = Model.elem[i].type;
int idx = elem_abs_to_rel(i);
const char *str;
switch(type) {
Expand Down Expand Up @@ -122,13 +121,13 @@ void newelem_press_cb(guiObject_t *obj, const void *data)
static const char *dlgts1_cb(guiObject_t *obj, int dir, void *data)
{
int idx = (long)data;
if (pc->elem[idx].src == 0 && dir < 0)
pc->elem[idx].src = -1;
if ((s8)pc->elem[idx].src == -1 && dir > 0) {
pc->elem[idx].src = 0;
if (Model.elem[idx].src == 0 && dir < 0)
Model.elem[idx].src = -1;
if ((s8)Model.elem[idx].src == -1 && dir > 0) {
Model.elem[idx].src = 0;
dir = 0;
}
if ((s8)pc->elem[idx].src < 0) {
if ((s8)Model.elem[idx].src < 0) {
GUI_TextSelectEnablePress((guiTextSelect_t *)obj, 1);
//PAGE_MainLayoutExit();
return _tr("Delete");
Expand Down Expand Up @@ -205,7 +204,7 @@ void show_config()
{
long count = 0;
for (count = 0; count < NUM_ELEMS; count++) {
if (pc->elem[count].type == ELEM_NONE)
if (Model.elem[count].type == ELEM_NONE)
break;
}
#if HAS_LAYOUT_EDITOR
Expand Down
1 change: 0 additions & 1 deletion src/pages/128x64x1/main_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#if HAS_LAYOUT_EDITOR

static struct layout_page * const lp = &pagemem.u.layout_page;
static struct PageCfg2 * const pc = &Model.pagecfg2;
static struct mainlayout_obj * const gui = &gui_objs.u.mainlayout;

#define NUMERIC_LABELS
Expand Down
6 changes: 3 additions & 3 deletions src/pages/128x64x1/pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ void PAGE_ChangeQuick(int dir)
{
int quick = 0;
for (int i = 0; i < NUM_QUICKPAGES; i++) {
if(Model.pagecfg2.quickpage[i] && Model.pagecfg2.quickpage[i] == cur_page) {
if(Model.quickpage[i] && Model.quickpage[i] == cur_page) {
quick = i + 1;
break;
}
}
int increment = dir > 0 ? 1 : NUM_QUICKPAGES;
while(1) {
quick = (quick + increment) % 5;
if (quick == 0 || (Model.pagecfg2.quickpage[quick-1] && PAGE_IsValidQuickPage(Model.pagecfg2.quickpage[quick-1])))
if (quick == 0 || (Model.quickpage[quick-1] && PAGE_IsValidQuickPage(Model.quickpage[quick-1])))
break;
}
if (quick == 0) {
PAGE_ChangeByID(PAGEID_MAIN, 0);
} else {
PAGE_ChangeByID(Model.pagecfg2.quickpage[quick-1], 0);
PAGE_ChangeByID(Model.quickpage[quick-1], 0);
}
}
int PAGE_QuickPage(u32 buttons, u8 flags, void *data)
Expand Down
10 changes: 5 additions & 5 deletions src/pages/128x64x1/toggle_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void show_iconsel_page(int SelectedIcon) {
GUI_RemoveAllObjects();
memset(gui, 0, sizeof(*gui));
current_toggleicon = SelectedIcon;
int toggleinput = MIXER_SRC(Model.pagecfg2.elem[tp->tglidx].src);
int toggleinput = MIXER_SRC(Model.elem[tp->tglidx].src);

//Header
PAGE_ShowHeader(INPUT_SourceNameAbbrevSwitch(tempstring, toggleinput));
Expand All @@ -100,9 +100,9 @@ static void show_iconsel_page(int SelectedIcon) {
GUI_CreateLabelBox(&gui->togglelabel[i], LABEL_X, row, LABEL_W, LABEL_H, SelectedIcon == i ? &inverted : &DEFAULT_FONT, NULL, NULL, tglidx[i]);
#ifdef HAS_CHAR_ICONS
GUI_CreateLabelBox(&gui->toggleicon[i], ICON_X, row, ICON_W, LABEL_H, &DEFAULT_FONT, TGLICO_font_cb,
NULL, (void *)(long)Model.pagecfg2.elem[tp->tglidx].extra.ico[i]);
NULL, (void *)(long)Model.elem[tp->tglidx].extra.ico[i]);
#else
struct ImageMap img = TGLICO_GetImage(Model.pagecfg2.elem[tp->tglidx].extra.ico[i]);
struct ImageMap img = TGLICO_GetImage(Model.elem[tp->tglidx].extra.ico[i]);
GUI_CreateImageOffset(&gui->toggleicon[i], ICON_X, row, ICON_W, LABEL_H, img.x_off, img.y_off, img.file,
NULL, //SelectedIcon == 0 ? tglico_reset_cb : tglico_setpos_cb,
(void *)(long)i);
Expand All @@ -121,13 +121,13 @@ static void show_iconsel_page(int SelectedIcon) {
void PAGE_ToggleEditInit(int page)
{
tp->tglidx = page;
memcpy(tp->tglicons, Model.pagecfg2.elem[tp->tglidx].extra.ico, sizeof(tp->tglicons));
memcpy(tp->tglicons, Model.elem[tp->tglidx].extra.ico, sizeof(tp->tglicons));
PAGE_SetActionCB(_action_cb);
show_iconsel_page(0);
}

static void navigate_toggleicons(s8 direction) {
int toggleinput = MIXER_SRC(Model.pagecfg2.elem[tp->tglidx].src);
int toggleinput = MIXER_SRC(Model.elem[tp->tglidx].src);
int num_positions = INPUT_NumSwitchPos(toggleinput);
if(num_positions < 2)
num_positions = 2;
Expand Down
3 changes: 1 addition & 2 deletions src/pages/320x240x16/main_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

static struct mainlayout_obj * const gui = &gui_objs.u.mainlayout;
static struct layout_page * const lp = &pagemem.u.layout_page;
static struct PageCfg2 * const pc = &Model.pagecfg2;

static void draw_elements();
static const char *newelem_cb(guiObject_t *obj, int dir, void *data);
Expand Down Expand Up @@ -319,7 +318,7 @@ void show_config()
FullRedraw = draw_mode;
}
if(lp->selected_for_move >= 0) {
type = pc->elem[lp->selected_for_move].type;
type = Model.elem[lp->selected_for_move].type;
row_idx = elem_abs_to_rel(lp->selected_for_move);
count = elem_get_count(type);
}
Expand Down
8 changes: 4 additions & 4 deletions src/pages/320x240x16/pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void PAGE_ChangeQuick(int dir)
{
int quick = 0;
for (int i = 0; i < NUM_QUICKPAGES; i++) {
if(Model.pagecfg2.quickpage[i] && Model.pagecfg2.quickpage[i] == cur_page) {
if(Model.quickpage[i] && Model.quickpage[i] == cur_page) {
quick = i+1;
break;
}
Expand All @@ -248,15 +248,15 @@ void PAGE_ChangeQuick(int dir)
while(1) {
quick = (quick + increment) % 5;
if (quick == 0
|| (Model.pagecfg2.quickpage[quick-1] && PAGE_IsValidQuickPage(Model.pagecfg2.quickpage[quick-1])))
|| (Model.quickpage[quick-1] && PAGE_IsValidQuickPage(Model.quickpage[quick-1])))
{
break;
}
}
if (quick == 0) {
PAGE_ChangeByID(PAGEID_MAIN, 0);
} else {
PAGE_ChangeByID(Model.pagecfg2.quickpage[quick-1], 0);
PAGE_ChangeByID(Model.quickpage[quick-1], 0);
}
}

Expand All @@ -266,7 +266,7 @@ int PAGE_QuickPage(u32 buttons, u8 flags, void *data)
(void)flags;
int i;
for(i = 0; i < NUM_QUICKPAGES; i++)
if(Model.pagecfg2.quickpage[i])
if(Model.quickpage[i])
break;
if(i == NUM_QUICKPAGES)
return 0;
Expand Down
14 changes: 7 additions & 7 deletions src/pages/320x240x16/toggle_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void show_icons(int SelectedIcon, int idx)
{
int x, y;
struct ImageMap img;
u8 cursel = Model.pagecfg2.elem[tp->tglidx].extra.ico[SelectedIcon];
u8 cursel = Model.elem[tp->tglidx].extra.ico[SelectedIcon];

for(int i = 0; i < NUM_SYMBOL_ELEMS; i++) {
y = 80 + (i / NUM_SYMBOL_COLS) * 40;
Expand Down Expand Up @@ -89,7 +89,7 @@ static const char * revert_str_cb(guiObject_t *obj, const void *data)
static void show_iconsel_page(int SelectedIcon)
{
struct ImageMap img;
int toggleinput = MIXER_SRC(Model.pagecfg2.elem[tp->tglidx].src);
int toggleinput = MIXER_SRC(Model.elem[tp->tglidx].src);
PAGE_RemoveAllObjects();
PAGE_ShowHeader(INPUT_SourceNameAbbrevSwitch(tempstring, toggleinput));
GUI_CreateButton(&gui->revert, LCD_WIDTH-96-8, 4, BUTTON_96, revert_str_cb, revert_cb, NULL);
Expand All @@ -107,24 +107,24 @@ static void show_iconsel_page(int SelectedIcon)
GUI_CreateRect(&gui->toggleframe, 80+80*SelectedIcon, 39, 77, 33, &outline);

GUI_CreateLabelBox(&gui->switchbox, 4, 47, 70, 22, &NORMALBOX_FONT, NULL, NULL,
INPUT_SourceNameAbbrevSwitch(tempstring, Model.pagecfg2.elem[tp->tglidx].src));
INPUT_SourceNameAbbrevSwitch(tempstring, Model.elem[tp->tglidx].src));

int num_positions = INPUT_NumSwitchPos(toggleinput);
if(num_positions < 2)
num_positions = 2;

GUI_CreateLabelBox(&gui->togglelabel[0], 94, 50, 30, 14, &LABEL_FONT, GUI_Localize, NULL, _tr_noop("Pos 0"));
img = TGLICO_GetImage(Model.pagecfg2.elem[tp->tglidx].extra.ico[0]);
img = TGLICO_GetImage(Model.elem[tp->tglidx].extra.ico[0]);
GUI_CreateImageOffset(&gui->toggleicon[0], 124, 40, TOGGLEICON_WIDTH, TOGGLEICON_HEIGHT, img.x_off, img.y_off, img.file,
SelectedIcon == 0 ? tglico_reset_cb : tglico_setpos_cb, (void *)0L);

GUI_CreateLabelBox(&gui->togglelabel[1], 174, 50, 30, 14, &LABEL_FONT, GUI_Localize, NULL, _tr_noop("Pos 1"));
img = TGLICO_GetImage(Model.pagecfg2.elem[tp->tglidx].extra.ico[1]);
img = TGLICO_GetImage(Model.elem[tp->tglidx].extra.ico[1]);
GUI_CreateImageOffset(&gui->toggleicon[1], 204, 40, TOGGLEICON_WIDTH, TOGGLEICON_HEIGHT, img.x_off, img.y_off, img.file,
SelectedIcon == 1 ? tglico_reset_cb : tglico_setpos_cb, (void *)1L);
if (num_positions == 3) {
GUI_CreateLabelBox(&gui->togglelabel[2], 254, 50, 30, 14, &LABEL_FONT, GUI_Localize, NULL, _tr_noop("Pos 2"));
img = TGLICO_GetImage(Model.pagecfg2.elem[tp->tglidx].extra.ico[2]);
img = TGLICO_GetImage(Model.elem[tp->tglidx].extra.ico[2]);
GUI_CreateImageOffset(&gui->toggleicon[2], 284, 40, TOGGLEICON_WIDTH, TOGGLEICON_HEIGHT, img.x_off, img.y_off, img.file,
SelectedIcon == 2 ? tglico_reset_cb : tglico_setpos_cb, (void *)2L);
}
Expand All @@ -137,7 +137,7 @@ static void show_iconsel_page(int SelectedIcon)

void PAGE_ToggleEditInit(int page) {
tp->tglidx = page;
memcpy(tp->tglicons, Model.pagecfg2.elem[tp->tglidx].extra.ico, sizeof(tp->tglicons));
memcpy(tp->tglicons, Model.elem[tp->tglidx].extra.ico, sizeof(tp->tglicons));
show_iconsel_page(0);
}

Expand Down
Loading

0 comments on commit 9e11837

Please sign in to comment.