Skip to content

Commit

Permalink
Merge pull request #333 from RadekVana/RemoveDynamBicMacAloc405
Browse files Browse the repository at this point in the history
Remove dynam Big Mac alloc 4.0.5
  • Loading branch information
RadekVana authored Mar 31, 2020
2 parents 38c94dc + 267e274 commit 78f2cfe
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 70 deletions.
34 changes: 14 additions & 20 deletions src/gui/screen_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "screen_menu.h"
#include "config.h"
#include "stdlib.h"
#include "resource.h"

void window_set_capture(int16_t id);

Expand All @@ -22,9 +23,10 @@ void screen_menu_item(window_menu_t *pwindow_menu, uint16_t index,
*ppitem = &(psmd->items[index].item);
}

void screen_menu_init(screen_t *screen,
const char *label, int count, uint8_t footer, uint8_t help) {
psmd->items = (menu_item_t *)malloc(sizeof(menu_item_t) * count);
void screen_menu_init(screen_t *screen, const char *label,
menu_item_t *p_items, size_t count, uint8_t footer, uint8_t help) {

psmd->items = p_items;
memset(psmd->items, '\0', sizeof(menu_item_t) * count);

rect_ui16_t menu_rect = rect_ui16(10, 32, 220, 278);
Expand Down Expand Up @@ -58,41 +60,33 @@ void screen_menu_init(screen_t *screen,
window_set_focus(id);

if (help) {
psmd->phelp = (window_text_t *)gui_malloc(sizeof(window_text_t));
psmd->flags.has_help = 1;
id = window_create_ptr(WINDOW_CLS_TEXT, root,
(footer) ? rect_ui16(10, 154, 220, 115) : rect_ui16(10, 195, 220, 115),
psmd->phelp);
psmd->phelp->font = resource_font(IDR_FNT_SPECIAL);
&psmd->help);
psmd->help.font = resource_font(IDR_FNT_SPECIAL);
} else {
psmd->phelp = NULL;
psmd->flags.has_help = 0;
}

if (footer) {
psmd->pfooter = (status_footer_t *)gui_malloc(sizeof(status_footer_t));
status_footer_init(psmd->pfooter, root);
psmd->flags.has_footer = 1;
status_footer_init(&psmd->footer, root);
} else {
psmd->pfooter = NULL;
psmd->flags.has_footer = 0;
}
}

void screen_menu_done(screen_t *screen) {
window_destroy(psmd->root.win.id);
if (psmd->phelp) {
free(psmd->phelp);
}

if (psmd->pfooter) {
free(psmd->pfooter);
}
free(psmd->items);
}

void screen_menu_draw(screen_t *screen) {}

int screen_menu_event(screen_t *screen, window_t *window,
uint8_t event, void *param) {
if (psmd->pfooter) {
status_footer_event(psmd->pfooter, window, event, param);
if (psmd->flags.has_footer) {
status_footer_event(&psmd->footer, window, event, param);
}

window_header_events(&(psmd->header));
Expand Down
14 changes: 10 additions & 4 deletions src/gui/screen_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#pragma pack(push)
#pragma pack(1)

typedef struct {
uint8_t has_footer : 1;
uint8_t has_help : 1;
} menu_flags_t;

typedef struct _menu_item_t {
window_menu_item_t item;
screen_t *screen;
Expand All @@ -28,8 +33,9 @@ typedef struct
window_menu_t menu;
menu_item_t *items;

window_text_t *phelp;
status_footer_t *pfooter;
menu_flags_t flags;
window_text_t help;
status_footer_t footer;

} screen_menu_data_t;

Expand All @@ -45,8 +51,8 @@ extern "C" {

extern const menu_item_t menu_item_return;

void screen_menu_init(screen_t *screen,
const char *label, int count, uint8_t footer, uint8_t help);
void screen_menu_init(screen_t *screen, const char *label,
menu_item_t *p_items, size_t count, uint8_t footer, uint8_t help);

void screen_menu_done(screen_t *screen);

Expand Down
21 changes: 17 additions & 4 deletions src/gui/screen_menu_calibration.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef enum {
#endif
// MI_CALIB_XY,
MI_CALIB_FIRST,
MI_COUNT
} MI_t;

const menu_item_t _menu_calibration_items[] = {
Expand All @@ -38,12 +39,24 @@ const menu_item_t _menu_calibration_items[] = {
{ { "First Layer Cal.", 0, WI_LABEL }, SCREEN_MENU_NO_SCREEN },
};

//"C inheritance" of screen_menu_data_t with data items
#pragma pack(push)
#pragma pack(1)

typedef struct
{
screen_menu_data_t base;
menu_item_t items[MI_COUNT];

} this_screen_data_t;

#pragma pack(pop)

void screen_menu_calibration_init(screen_t *screen) {
marlin_vars_t *vars;
int count = sizeof(_menu_calibration_items) / sizeof(menu_item_t);
screen_menu_init(screen, "CALIBRATION", count + 1, 0, 0);
screen_menu_init(screen, "CALIBRATION", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 0, 0);
psmd->items[MI_RETURN] = menu_item_return;
memcpy(psmd->items + 1, _menu_calibration_items, count * sizeof(menu_item_t));
memcpy(psmd->items + 1, _menu_calibration_items, (MI_COUNT - 1) * sizeof(menu_item_t));

vars = marlin_update_vars(MARLIN_VAR_MSK(MARLIN_VAR_Z_OFFSET));
psmd->items[MI_Z_OFFSET].item.wi_spin_fl.value = vars->z_offset;
Expand Down Expand Up @@ -95,7 +108,7 @@ screen_t screen_menu_calibration = {
screen_menu_done,
screen_menu_draw,
screen_menu_calibration_event,
sizeof(screen_menu_data_t), //data_size
sizeof(this_screen_data_t), //data_size
0, //pdata
};

Expand Down
21 changes: 17 additions & 4 deletions src/gui/screen_menu_filament.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef enum {
MI_UNLOAD,
MI_CHANGE,
MI_PURGE,
MI_COUNT
} MI_t;

const menu_item_t _menu_filament_items[] = {
Expand Down Expand Up @@ -69,12 +70,24 @@ static void _deactivate_item(screen_t *screen) {
}
}

//"C inheritance" of screen_menu_data_t with data items
#pragma pack(push)
#pragma pack(1)

typedef struct
{
screen_menu_data_t base;
menu_item_t items[MI_COUNT];

} this_screen_data_t;

#pragma pack(pop)

void screen_menu_filament_init(screen_t *screen) {
//filament_not_loaded = -1;
int count = sizeof(_menu_filament_items) / sizeof(menu_item_t);
screen_menu_init(screen, "FILAMENT", count + 1, 1, 0);
screen_menu_init(screen, "FILAMENT", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0);
psmd->items[0] = menu_item_return;
memcpy(psmd->items + 1, _menu_filament_items, count * sizeof(menu_item_t));
memcpy(psmd->items + 1, _menu_filament_items, (MI_COUNT - 1) * sizeof(menu_item_t));
_deactivate_item(screen);
}

Expand Down Expand Up @@ -115,7 +128,7 @@ screen_t screen_menu_filament = {
screen_menu_done,
screen_menu_draw,
screen_menu_filament_event,
sizeof(screen_menu_data_t), //data_size
sizeof(this_screen_data_t), //data_size
0, //pdata
};

Expand Down
21 changes: 17 additions & 4 deletions src/gui/screen_menu_fw_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ typedef enum {
MI_COUNT,
} MI_t;

//"C inheritance" of screen_menu_data_t with data items
#pragma pack(push)
#pragma pack(1)

typedef struct
{
screen_menu_data_t base;
menu_item_t items[MI_COUNT];

} this_screen_data_t;

#pragma pack(pop)

void screen_menu_fw_update_init(screen_t *screen) {
screen_menu_init(screen, "FW UPDATE", MI_COUNT, 1, 1);
screen_menu_init(screen, "FW UPDATE", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 1);
psmd->items[MI_RETURN] = menu_item_return;
psmd->items[MI_ALWAYS] = (menu_item_t) { { "Always", 0, WI_SWITCH, .wi_switch_select = { 0, opt_on_off } }, SCREEN_MENU_NO_SCREEN };
psmd->items[MI_ON_RESTART] = (menu_item_t) { { "On restart", 0, WI_SWITCH, .wi_switch_select = { 0, opt_on_off } }, SCREEN_MENU_NO_SCREEN };
Expand All @@ -30,8 +43,8 @@ void screen_menu_fw_update_init(screen_t *screen) {
psmd->items[MI_ALWAYS].item.wi_switch_select.index = 1;
psmd->items[MI_ON_RESTART].item.wi_switch_select.index = sys_fw_update_on_restart_is_enabled() ? 0 : 1;
}
psmd->phelp[0].font = resource_font(IDR_FNT_SPECIAL);
window_set_text(psmd->phelp[0].win.id, "Select when you want\nto automatically flash\nupdated firmware\nfrom USB flash disk.");
psmd->help.font = resource_font(IDR_FNT_SPECIAL);
window_set_text(psmd->help.win.id, "Select when you want\nto automatically flash\nupdated firmware\nfrom USB flash disk.");
}

int screen_menu_fw_update_event(screen_t *screen, window_t *window, uint8_t event, void *param) {
Expand Down Expand Up @@ -68,7 +81,7 @@ screen_t screen_menu_fw_update = {
screen_menu_done,
screen_menu_draw,
screen_menu_fw_update_event,
sizeof(screen_menu_data_t), //data_size
sizeof(this_screen_data_t), //data_size
0, //pdata
};

Expand Down
23 changes: 18 additions & 5 deletions src/gui/screen_menu_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ typedef enum {
MI_FAIL_STAT,
MI_SUPPORT,
#endif //_DEBUG
MI_VERSIONS
MI_VERSIONS,
MI_COUNT
} MI_t;

const menu_item_t _menu_info_items[] = {
Expand Down Expand Up @@ -47,11 +48,23 @@ const menu_item_t _menu_info_items[] = {
#endif //_DEBUG
};

//"C inheritance" of screen_menu_data_t with data items
#pragma pack(push)
#pragma pack(1)

typedef struct
{
screen_menu_data_t base;
menu_item_t items[MI_COUNT];

} this_screen_data_t;

#pragma pack(pop)

void screen_menu_info_init(screen_t *screen) {
int count = sizeof(_menu_info_items) / sizeof(menu_item_t);
screen_menu_init(screen, "INFO", count + 1, 1, 0);
screen_menu_init(screen, "INFO", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0);
psmd->items[MI_RETURN] = menu_item_return;
memcpy(psmd->items + 1, _menu_info_items, count * sizeof(menu_item_t));
memcpy(psmd->items + 1, _menu_info_items, (MI_COUNT - 1) * sizeof(menu_item_t));
}

int screen_menu_info_event(screen_t *screen, window_t *window, uint8_t event, void *param) {
Expand All @@ -65,7 +78,7 @@ screen_t screen_menu_info = {
screen_menu_done,
screen_menu_draw,
screen_menu_info_event,
sizeof(screen_menu_data_t), //data_size
sizeof(this_screen_data_t), //data_size
0, //pdata
};

Expand Down
21 changes: 17 additions & 4 deletions src/gui/screen_menu_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef enum {
MI_MOVE_Y,
MI_MOVE_Z,
MI_MOVE_E,
MI_COUNT
} MI_t;

const menu_item_t _menu_move_items[] = {
Expand All @@ -21,12 +22,24 @@ const menu_item_t _menu_move_items[] = {
{ { "Extruder", 0, WI_SPIN, .wi_spin = { 0, move_e } }, SCREEN_MENU_NO_SCREEN },
};

//"C inheritance" of screen_menu_data_t with data items
#pragma pack(push)
#pragma pack(1)

typedef struct
{
screen_menu_data_t base;
menu_item_t items[MI_COUNT];

} this_screen_data_t;

#pragma pack(pop)

void screen_menu_move_init(screen_t *screen) {
marlin_vars_t *vars;
int count = sizeof(_menu_move_items) / sizeof(menu_item_t);
screen_menu_init(screen, "MOVE AXIS", count + 1, 1, 0);
screen_menu_init(screen, "MOVE AXIS", ((this_screen_data_t *)screen->pdata)->items, MI_COUNT, 1, 0);
psmd->items[0] = menu_item_return;
memcpy(psmd->items + 1, _menu_move_items, count * sizeof(menu_item_t));
memcpy(psmd->items + 1, _menu_move_items, (MI_COUNT - 1) * sizeof(menu_item_t));

vars = marlin_update_vars(MARLIN_VAR_MSK_POS_XYZE | MARLIN_VAR_MSK(MARLIN_VAR_TEMP_NOZ));
psmd->items[MI_MOVE_X].item.wi_spin.value = (int32_t)(vars->pos[0] * 1000);
Expand Down Expand Up @@ -78,7 +91,7 @@ screen_t screen_menu_move = {
screen_menu_done,
0,
screen_menu_move_event,
sizeof(screen_menu_data_t), //data_size
sizeof(this_screen_data_t), //data_size
0, //pdata
};

Expand Down
21 changes: 17 additions & 4 deletions src/gui/screen_menu_preheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,27 @@

uint8_t menu_preheat_type = 0; // 0 - preheat, 1 - load filament, 2 - unload filament

//"C inheritance" of screen_menu_data_t with data items
#pragma pack(push)
#pragma pack(1)

typedef struct
{
screen_menu_data_t base;
menu_item_t items[FILAMENTS_END + 1];

} this_screen_data_t;

#pragma pack(pop)

void screen_menu_preheat_init(screen_t *screen) {
switch (menu_preheat_type) {
case 0:
screen_menu_init(screen, "PREHEAT", FILAMENTS_END + 1, 1, 0);
screen_menu_init(screen, "PREHEAT", ((this_screen_data_t *)screen->pdata)->items, FILAMENTS_END + 1, 1, 0);
break;
case 1:
screen_menu_init(screen, "LOAD FILAMENT", FILAMENTS_END, 1, 1);
window_set_text(psmd->phelp->win.id,
screen_menu_init(screen, "LOAD FILAMENT", ((this_screen_data_t *)screen->pdata)->items, FILAMENTS_END, 1, 1);
window_set_text(psmd->help.win.id,
"The nozzle must be\npreheated before\ninserting the filament.\n"
"Please, select the type\nof material");
break;
Expand Down Expand Up @@ -86,7 +99,7 @@ screen_t screen_menu_preheat = {
screen_menu_preheat_done,
screen_menu_draw,
screen_menu_preheat_event,
sizeof(screen_menu_data_t), //data_size
sizeof(this_screen_data_t), //data_size
0, //pdata
};

Expand Down
Loading

0 comments on commit 78f2cfe

Please sign in to comment.