From 2f4119a6d723fc1e0e7b148aed73101cb89c5369 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 2 Feb 2021 13:21:16 +0200 Subject: [PATCH 1/2] M552 - Printer IP address --- Firmware/Marlin.h | 2 ++ Firmware/Marlin_main.cpp | 19 +++++++++++++++++++ Firmware/ultralcd.cpp | 31 +++++++++++++++++++------------ Firmware/util.cpp | 7 +++++++ Firmware/util.h | 3 +++ 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 307b8c91..17fce271 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -501,4 +501,6 @@ void raise_z_above(float target, bool plan=true); extern "C" void softReset(); +extern uint32_t IP_address; + #endif diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 9deb5105..61e5a33c 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -321,6 +321,8 @@ uint16_t print_time_remaining_normal = PRINT_TIME_REMAINING_INIT; //estimated re uint8_t print_percent_done_silent = PRINT_PERCENT_DONE_INIT; uint16_t print_time_remaining_silent = PRINT_TIME_REMAINING_INIT; //estimated remaining print time in minutes +uint32_t IP_address = 0; + //=========================================================================== //=============================Private Variables============================= //=========================================================================== @@ -8003,6 +8005,23 @@ Sigma_Exit: break; } #endif // CUSTOM_M_CODE_SET_Z_PROBE_OFFSET + case 552: + { + if (code_seen('P')) + { + uint8_t valCnt = 0; + IP_address = 0; + do + { + *strchr_pointer = '*'; + ((uint8_t*)&IP_address)[valCnt] = code_value_short(); + valCnt++; + } while ((valCnt < 4) && code_seen('.')); + + if (valCnt != 4) + IP_address = 0; + } + } break; #ifdef FILAMENTCHANGEENABLE diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index d7976d27..0f6bc1fa 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2057,8 +2057,8 @@ static void lcd_support_menu() { // 22bytes total int8_t status; // 1byte bool is_flash_air; // 1byte - uint8_t ip[4]; // 4bytes - char ip_str[3*4+3+1]; // 16bytes + uint32_t ip; // 4bytes + char ip_str[IP4_STR_SIZE]; // 16bytes } _menu_data_t; static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data"); _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]); @@ -2069,17 +2069,10 @@ static void lcd_support_menu() _md->status = 1; _md->is_flash_air = card.ToshibaFlashAir_isEnabled(); if (_md->is_flash_air) { - card.ToshibaFlashAir_GetIP(_md->ip); // ip[4] filled with 0 if it failed - // Prepare IP string from ip[4] - sprintf_P(_md->ip_str, PSTR("%d.%d.%d.%d"), - _md->ip[0], _md->ip[1], - _md->ip[2], _md->ip[3]); + card.ToshibaFlashAir_GetIP((uint8_t*)(&_md->ip)); // ip == 0 if it failed } - } else if (_md->is_flash_air && - _md->ip[0] == 0 && _md->ip[1] == 0 && - _md->ip[2] == 0 && _md->ip[3] == 0 && - ++ _md->status == 16) - { + } else if (_md->is_flash_air && _md->ip == 0 && ++ _md->status == 16) + { // Waiting for the FlashAir card to get an IP address from a router. Force an update. _md->status = 0; } @@ -2143,6 +2136,20 @@ static void lcd_support_menu() MENU_ITEM_BACK_P(PSTR(" ")); if (((menu_item - 1) == menu_line) && lcd_draw_update) { lcd_set_cursor(2, menu_row); + ip4_to_str(_md->ip_str, (uint8_t*)(&_md->ip)); + lcd_printf_P(PSTR("%s"), _md->ip_str); + } + } + + // Show the printer IP address, if it is available. + if (IP_address) { + + MENU_ITEM_BACK_P(STR_SEPARATOR); + MENU_ITEM_BACK_P(PSTR("Printer IP Addr:")); //c=18 r=1 + MENU_ITEM_BACK_P(PSTR(" ")); + if (((menu_item - 1) == menu_line) && lcd_draw_update) { + lcd_set_cursor(2, menu_row); + ip4_to_str(_md->ip_str, (uint8_t*)(&IP_address)); lcd_printf_P(PSTR("%s"), _md->ip_str); } } diff --git a/Firmware/util.cpp b/Firmware/util.cpp index e335793a..a25efd35 100644 --- a/Firmware/util.cpp +++ b/Firmware/util.cpp @@ -4,6 +4,7 @@ #include "sound.h" #include "language.h" #include "util.h" +#include // Allocate the version string in the program memory. Otherwise the string lands either on the stack or in the global RAM. const char FW_VERSION_STR[] PROGMEM = FW_VERSION; @@ -604,3 +605,9 @@ else { sPrinterName=_sPrinterName; } } + + +void ip4_to_str(char* dest, uint8_t* IP) +{ + sprintf_P(dest, PSTR("%u.%u.%u.%u"), IP[0], IP[1], IP[2], IP[3]); +} diff --git a/Firmware/util.h b/Firmware/util.h index f25749de..6d34aa08 100644 --- a/Firmware/util.h +++ b/Firmware/util.h @@ -110,4 +110,7 @@ void gcode_level_check(uint16_t nGcodeLevel); void fSetMmuMode(bool bMMu); +#define IP4_STR_SIZE 16 +extern void ip4_to_str(char* dest, uint8_t* IP); + #endif /* UTIL_H */ From 647cde0caeb3365e66d65cf1d558168c2ae2dc29 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 2 Feb 2021 13:38:20 +0200 Subject: [PATCH 2/2] Add documentation --- Firmware/Marlin_main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 61e5a33c..777a05ff 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3734,6 +3734,7 @@ extern uint8_t st_backlash_y; //!@n M503 - print the current settings (from memory not from EEPROM) //!@n M509 - force language selection on next restart //!@n M540 - Use S[0|1] to enable or disable the stop SD card print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) +//!@n M552 - Set IP address //!@n M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] //!@n M605 - Set dual x-carriage movement mode: S [ X R ] //!@n M860 - Wait for PINDA thermistor to reach target temperature. @@ -8005,6 +8006,19 @@ Sigma_Exit: break; } #endif // CUSTOM_M_CODE_SET_Z_PROBE_OFFSET + + /*! + ### M552 - Set IP address M552: Set IP address, enable/disable network interface" + Sets the printer IP address that is shown in the support menu. Designed to be used with the help of host software. + If P is not specified nothing happens. + If the structure of the IP address is invalid, 0.0.0.0 is assumed and nothing is shown on the screen in the Support menu. + #### Usage + + M552 [ P ] + + #### Parameters + - `P` - The IP address in xxx.xxx.xxx.xxx format. Eg: P192.168.1.14 + */ case 552: { if (code_seen('P'))