Prusa MINI Firmware overview
screen_lan_settings.c File Reference
#include "screen_lan_settings.h"
#include "lwip/dhcp.h"
#include "lwip/netifapi.h"
#include "lwip.h"
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

Macros

#define MAC_ADDR_START   0x1FFF781A
 
#define MAC_ADDR_SIZE   6
 
#define MAX_INI_SIZE   100
 
#define IP4_ADDR_STR_SIZE   16
 

Enumerations

enum  MI_t {
  MI_RETURN, MI_RETURN, MI_WIZARD, MI_Z_OFFSET,
  MI_AUTO_HOME, MI_MESH_BED, MI_SELFTEST, MI_CALIB_FIRST,
  MI_RETURN, MI_LOAD, MI_UNLOAD, MI_CHANGE,
  MI_PURGE, MI_RETURN, MI_ALWAYS, MI_ON_RESTART,
  MI_COUNT, MI_RETURN, MI_SYS_INFO, MI_VERSIONS,
  MI_RETURN, MI_MOVE_X, MI_MOVE_Y, MI_MOVE_Z,
  MI_MOVE_E, MI_RETURN, MI_SYS_RESET, MI_CLR_EEPROM,
  MI_WDG_TEST, MI_PLL, MI_SSCG, MI_SSCG_FREQ,
  MI_SSCG_DEPTH, MI_SPI_PRESC, MI_MESH, MI_BSOD,
  MI_BSOD_HARD_FAULT, MI_COUNT, MI_RETURN, MI_TEMPERATURE,
  MI_MOVE_AXIS, MI_DISABLE_STEP, MI_FACTORY_DEFAULTS, MI_FW_UPDATE,
  MI_FILAMENT_SENSOR, MI_TIMEOUT, MI_LAN_SETTINGS, MI_RETURN,
  MI_NOZZLE, MI_HEATBED, MI_PRINTFAN, MI_COOLDOWN,
  MI_RETURN, MI_NOZZLE, MI_HEAT_PWM_PERIOD, MI_HEATBED,
  MI_FAN_PWM_PERIOD, MI_PRINTFAN, MI_COOLDOWN, MI_COUNT
}
 

Functions

static void _screen_lan_settings_item (window_menu_t *pwindow_menu, uint16_t index, window_menu_item_t **ppitem, void *data)
 
static uint8_t _get_ip4_addrs (void)
 
static void _addrs_to_str (char *param_str, uint8_t flg)
 
static void _parse_MAC_addr (char *mac_addr_str)
 
static void screen_lan_settings_init (screen_t *screen)
 
static int screen_lan_settings_event (screen_t *screen, window_t *window, uint8_t event, void *param)
 
static void screen_lan_settings_draw (screen_t *screen)
 
static void screen_lan_settings_done (screen_t *screen)
 

Variables

static char * plan_str = NULL
 
static networkconfig_t config
 
const menu_item_t _menu_lan_items []
 
screen_t screen_lan_settings
 
screen_t *const pscreen_lan_settings = &screen_lan_settings
 

Macro Definition Documentation

◆ MAC_ADDR_START

#define MAC_ADDR_START   0x1FFF781A

◆ MAC_ADDR_SIZE

#define MAC_ADDR_SIZE   6

◆ MAX_INI_SIZE

#define MAX_INI_SIZE   100

◆ IP4_ADDR_STR_SIZE

#define IP4_ADDR_STR_SIZE   16

Enumeration Type Documentation

◆ MI_t

enum MI_t
Enumerator
MI_RETURN 
MI_RETURN 
MI_WIZARD 
MI_Z_OFFSET 
MI_AUTO_HOME 
MI_MESH_BED 
MI_SELFTEST 
MI_CALIB_FIRST 
MI_RETURN 
MI_LOAD 
MI_UNLOAD 
MI_CHANGE 
MI_PURGE 
MI_RETURN 
MI_ALWAYS 
MI_ON_RESTART 
MI_COUNT 
MI_RETURN 
MI_SYS_INFO 
MI_VERSIONS 
MI_RETURN 
MI_MOVE_X 
MI_MOVE_Y 
MI_MOVE_Z 
MI_MOVE_E 
MI_RETURN 
MI_SYS_RESET 
MI_CLR_EEPROM 
MI_WDG_TEST 
MI_PLL 
MI_SSCG 
MI_SSCG_FREQ 
MI_SSCG_DEPTH 
MI_SPI_PRESC 
MI_MESH 
MI_BSOD 
MI_BSOD_HARD_FAULT 
MI_COUNT 
MI_RETURN 
MI_TEMPERATURE 
MI_MOVE_AXIS 
MI_DISABLE_STEP 
MI_FACTORY_DEFAULTS 
MI_FW_UPDATE 
MI_FILAMENT_SENSOR 
MI_TIMEOUT 
MI_LAN_SETTINGS 
MI_RETURN 
MI_NOZZLE 
MI_HEATBED 
MI_PRINTFAN 
MI_COOLDOWN 
MI_RETURN 
MI_NOZZLE 
MI_HEAT_PWM_PERIOD 
MI_HEATBED 
MI_FAN_PWM_PERIOD 
MI_PRINTFAN 
MI_COOLDOWN 
MI_COUNT 
27  {
28  MI_RETURN,
29 #ifdef STATIC_SAVE_LOAD_CONFIG
30  MI_SAVE,
31  MI_LOAD,
32 #endif //STATIC_SAVE_LOAD_CONFIG
33 } MI_t;

Function Documentation

◆ _screen_lan_settings_item()

static void _screen_lan_settings_item ( window_menu_t pwindow_menu,
uint16_t  index,
window_menu_item_t **  ppitem,
void data 
)
static
50  {
51  screen_t *screen = (screen_t *)data;
52  *ppitem = &(plsd->items[index].item);
53 }
Here is the caller graph for this function:

◆ _get_ip4_addrs()

static uint8_t _get_ip4_addrs ( void  )
static
55  {
56  if (netif_is_up(&eth0)) {
57  if (dhcp_supplied_address(&eth0)) {
58  config.lan_ip4_addr.addr = netif_ip4_addr(&eth0)->addr;
59  config.lan_ip4_msk.addr = netif_ip4_netmask(&eth0)->addr;
60  config.lan_ip4_gw.addr = netif_ip4_gw(&eth0)->addr;
61  } else {
62  return 1;
63  }
64  } else {
65  return 1;
66  }
67  return 0;
68 }
Here is the caller graph for this function:

◆ _addrs_to_str()

static void _addrs_to_str ( char *  param_str,
uint8_t  flg 
)
static
70  {
71  static char ip4_addr_str[IP4_ADDR_STR_SIZE], ip4_msk_str[IP4_ADDR_STR_SIZE], ip4_gw_str[IP4_ADDR_STR_SIZE];
72  strncpy(ip4_addr_str, ip4addr_ntoa(&(config.lan_ip4_addr)), IP4_ADDR_STR_SIZE);
73  strncpy(ip4_msk_str, ip4addr_ntoa(&(config.lan_ip4_msk)), IP4_ADDR_STR_SIZE);
74  strncpy(ip4_gw_str, ip4addr_ntoa(&(config.lan_ip4_gw)), IP4_ADDR_STR_SIZE);
75 
76  if (flg)
77  snprintf(param_str, MAX_INI_SIZE, "[lan_ip4]\naddress=%s\nmask=%s\ngateway=%s", ip4_addr_str, ip4_msk_str, ip4_gw_str);
78  else
79  snprintf(plan_str, 150, "IPv4 Address:\n %s\nIPv4 Netmask:\n %s\nIPv4 Gateway:\n %s\nMAC Address:\n %s",
80  ip4_addr_str, ip4_msk_str, ip4_gw_str, param_str);
81 }
Here is the caller graph for this function:

◆ _parse_MAC_addr()

static void _parse_MAC_addr ( char *  mac_addr_str)
static
83  {
84  volatile uint8_t mac_addr[] = { 0, 0, 0, 0, 0, 0 };
85  for (uint8_t i = 0; i < MAC_ADDR_SIZE; i++)
86  mac_addr[i] = *(volatile uint8_t *)(MAC_ADDR_START + i);
87 
88  sprintf(mac_addr_str, "%x:%x:%x:%x:%x:%x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
89 }
Here is the caller graph for this function:

◆ screen_lan_settings_init()

static void screen_lan_settings_init ( screen_t screen)
static
91  {
92  //============= SCREEN INIT ===============
93 
94  size_t count = sizeof(_menu_lan_items) / sizeof(menu_item_t);
95 
96  plsd->items = (menu_item_t *)malloc(sizeof(menu_item_t) * (count + 1));
97  memset(plsd->items, '\0', sizeof(menu_item_t) * (count + 1));
98 
99  rect_ui16_t menu_rect = rect_ui16(10, 32, 220, 90);
100 
101  int16_t id;
102  int16_t root = window_create_ptr(WINDOW_CLS_FRAME, -1, rect_ui16(0, 0, 0, 0), &(plsd->root));
103  window_disable(root);
104 
105  id = window_create_ptr(WINDOW_CLS_HEADER, root, rect_ui16(0, 0, 240, 31), &(plsd->header));
106  p_window_header_set_text(&(plsd->header), "LAN SETTINGS");
107 
108  id = window_create_ptr(WINDOW_CLS_MENU, root, menu_rect, &(plsd->menu));
109  plsd->menu.padding = padding_ui8(20, 6, 2, 6);
110  plsd->menu.icon_rect = rect_ui16(0, 0, 16, 30);
111  plsd->menu.count = count + 1;
112  plsd->menu.menu_items = _screen_lan_settings_item;
113  plsd->menu.data = (void *)screen;
114 
115  window_set_capture(id); // set capture to list
116  window_set_focus(id);
117 
118  id = window_create_ptr(WINDOW_CLS_TEXT, root, rect_ui16(10, 130, 220, 190), &(plsd->text));
119  plsd->text.font = resource_font(IDR_FNT_SPECIAL);
120 
121  plsd->items[0] = menu_item_return;
122 #ifdef STATIC_SAVE_LOAD_CONFIG
123  memcpy(plsd->items + 1, _menu_lan_items, count * sizeof(menu_item_t));
124 #endif //STATIC_SAVE_LOAD_CONFIG
125  //============== DECLARE VARIABLES ================
126 
127  plan_str = (char *)gui_malloc(150 * sizeof(char));
128 
129  //============= FILL VARIABLES ============
130 
131  _parse_MAC_addr(plsd->mac_addr_str);
132 
133  if (_get_ip4_addrs()) {
134  config.lan_ip4_addr.addr = config.lan_ip4_msk.addr = config.lan_ip4_gw.addr = 0;
135  sprintf(plan_str, "IPv4 Address:\n 0.0.0.0\nIPv4 Netmask:\n 0.0.0.0\nIPv4 Gateway:\n 0.0.0.0\nMAC Address:\n %s",
136  plsd->mac_addr_str);
137  } else {
138  _addrs_to_str(plsd->mac_addr_str, 0); //0 means parsing to screen text
139  }
140 
141  //============= SET TEXT ================
142 
143  plsd->text.text = plan_str;
144 }
Here is the call graph for this function:

◆ screen_lan_settings_event()

static int screen_lan_settings_event ( screen_t screen,
window_t window,
uint8_t  event,
void param 
)
static
214  {
215 
216  window_header_events(&(plsd->header));
217 
218  if (event != WINDOW_EVENT_CLICK) {
219  return 0;
220  }
221 
222  switch ((int)param) {
223  case MI_RETURN:
224  screen_close();
225  return 1;
226 #ifdef STATIC_SAVE_LOAD_CONFIG
227  case MI_SAVE:
228  if (media_is_inserted() == false) {
229  if (gui_msgbox("Please insert USB flash disk and try again.",
231  == MSGBOX_RES_OK) {
232  }
233  } else {
234  if (_save_ini_file()) { // !its possible to save empty configurations!
235  if (gui_msgbox("Settings saved in the \"lan_settings.ini\" file.",
237  == MSGBOX_RES_OK) {
238  }
239  } else {
240  if (gui_msgbox("File \"lan_settings.ini\" did not saved properly.",
242  == MSGBOX_RES_OK) {
243  }
244  }
245  }
246  break;
247  case MI_LOAD:
248  if (media_is_inserted() == false) {
249  if (gui_msgbox("Please insert USB flash disk and try again.",
251  == MSGBOX_RES_OK) {
252  }
253  } else {
254  if (_load_ini_file()) {
255  if (gui_msgbox("Settings successfully loaded", MSGBOX_BTN_OK | MSGBOX_ICO_INFO) == MSGBOX_RES_OK) {
256  }
257  _addrs_to_str(plsd->mac_addr_str, 0);
258  plsd->text.win.flg |= WINDOW_FLG_INVALID;
259 
260  } else {
261  if (gui_msgbox("File \"lan_settings.ini\" not found in the root directory of the USB flash disk.",
263  == MSGBOX_RES_OK) {
264  }
265  }
266  }
267  break;
268 #endif //STATIC_SAVE_LOAD_CONFIG
269  }
270  return 0;
271 }
Here is the call graph for this function:

◆ screen_lan_settings_draw()

static void screen_lan_settings_draw ( screen_t screen)
static
273  {
274 }

◆ screen_lan_settings_done()

static void screen_lan_settings_done ( screen_t screen)
static
276  {
277 
278  if (plan_str)
280  window_destroy(plsd->root.win.id);
281 }
Here is the call graph for this function:

Variable Documentation

◆ plan_str

char* plan_str = NULL
static

◆ config

◆ _menu_lan_items

const menu_item_t _menu_lan_items[]
Initial value:
= {
}

◆ screen_lan_settings

◆ pscreen_lan_settings

screen_t* const pscreen_lan_settings = &screen_lan_settings
_menu_item_t
Definition: screen_menu.h:19
gui_free
void gui_free(void *ptr)
Definition: gui.c:39
_get_ip4_addrs
static uint8_t _get_ip4_addrs(void)
Definition: screen_lan_settings.c:55
plsd
#define plsd
Definition: screen_lan_settings.h:16
window_header_events
#define window_header_events(window)
Definition: window_header.h:72
screen_lan_settings_event
static int screen_lan_settings_event(screen_t *screen, window_t *window, uint8_t event, void *param)
Definition: screen_lan_settings.c:213
rect_ui16
static rect_ui16_t rect_ui16(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
Definition: guitypes.h:159
gui_malloc
void * gui_malloc(unsigned int size)
Definition: gui.c:35
screen_lan_settings_done
static void screen_lan_settings_done(screen_t *screen)
Definition: screen_lan_settings.c:276
data
uint8_t data[8]
Definition: masstorage.h:49
window_destroy
void window_destroy(int16_t id)
Definition: window.c:132
padding_ui8
static padding_ui8_t padding_ui8(uint8_t l, uint8_t t, uint8_t r, uint8_t b)
Definition: guitypes.h:164
i
uint8_t i
Definition: screen_test_graph.c:72
media_is_inserted
bool media_is_inserted()
Definition: Marlin_CardReader.cpp:17
IDR_FNT_SPECIAL
#define IDR_FNT_SPECIAL
Definition: resource.h:13
_menu_lan_items
const menu_item_t _menu_lan_items[]
Definition: screen_lan_settings.c:42
MSGBOX_ICO_INFO
#define MSGBOX_ICO_INFO
Definition: window_msgbox.h:36
MSGBOX_BTN_OK
#define MSGBOX_BTN_OK
Definition: window_msgbox.h:20
screen_close
void screen_close(void)
Definition: screen.c:80
window_disable
void window_disable(int16_t id)
Definition: window.c:523
screen_lan_settings_data_t
Definition: screen_lan_settings.h:19
MI_RETURN
Definition: screen_lan_settings.c:28
WINDOW_CLS_FRAME
#define WINDOW_CLS_FRAME
Definition: window.h:9
MAC_ADDR_SIZE
#define MAC_ADDR_SIZE
Definition: screen_lan_settings.c:23
MI_t
MI_t
Definition: screen_lan_settings.c:27
WINDOW_CLS_MENU
#define WINDOW_CLS_MENU
Definition: window.h:18
window_set_focus
void window_set_focus(int16_t id)
Definition: window.c:480
window_set_capture
void window_set_capture(int16_t id)
Definition: window.c:500
MAX_INI_SIZE
#define MAX_INI_SIZE
Definition: screen_lan_settings.c:24
plan_str
static char * plan_str
Definition: screen_lan_settings.c:35
MAC_ADDR_START
#define MAC_ADDR_START
Definition: screen_lan_settings.c:22
screen_lan_settings_draw
static void screen_lan_settings_draw(screen_t *screen)
Definition: screen_lan_settings.c:273
_rect_ui16_t
Definition: guitypes.h:69
uint8_t
const uint8_t[]
Definition: 404_html.c:3
_screen_t
Definition: screen.h:18
_screen_lan_settings_item
static void _screen_lan_settings_item(window_menu_t *pwindow_menu, uint16_t index, window_menu_item_t **ppitem, void *data)
Definition: screen_lan_settings.c:49
MSGBOX_RES_OK
#define MSGBOX_RES_OK
Definition: window_msgbox.h:46
menu_item_return
const menu_item_t menu_item_return
Definition: screen_menu.c:14
_parse_MAC_addr
static void _parse_MAC_addr(char *mac_addr_str)
Definition: screen_lan_settings.c:83
WINDOW_CLS_TEXT
#define WINDOW_CLS_TEXT
Definition: window.h:10
screen_lan_settings_init
static void screen_lan_settings_init(screen_t *screen)
Definition: screen_lan_settings.c:91
resource_font
font_t * resource_font(uint16_t id)
Definition: guitypes.c:186
WINDOW_EVENT_CLICK
#define WINDOW_EVENT_CLICK
Definition: window.h:46
window_create_ptr
int16_t window_create_ptr(int16_t cls_id, int16_t id_parent, rect_ui16_t rect, void *ptr)
Definition: window.c:102
IP4_ADDR_STR_SIZE
#define IP4_ADDR_STR_SIZE
Definition: screen_lan_settings.c:25
MSGBOX_ICO_ERROR
#define MSGBOX_ICO_ERROR
Definition: window_msgbox.h:33
config_s
Definition: deflate.c:120
WINDOW_CLS_HEADER
int16_t WINDOW_CLS_HEADER
Definition: window_header.c:24
_addrs_to_str
static void _addrs_to_str(char *param_str, uint8_t flg)
Definition: screen_lan_settings.c:70
eth0
struct netif eth0
Definition: lwip.c:72
MI_LOAD
Definition: screen_menu_filament.c:22
WINDOW_FLG_INVALID
#define WINDOW_FLG_INVALID
Definition: window.h:26
p_window_header_set_text
void p_window_header_set_text(window_header_t *window, const char *text)
Definition: window_header.c:152
netif_is_up
#define netif_is_up(netif)
Definition: netif.h:401