diff --git a/src/gui/MItem_lan.cpp b/src/gui/MItem_lan.cpp index 8f89d2f8aa..0e131e232e 100644 --- a/src/gui/MItem_lan.cpp +++ b/src/gui/MItem_lan.cpp @@ -83,3 +83,17 @@ MI_IP4_GWAY::MI_IP4_GWAY() MI_MAC_ADDR::MI_MAC_ADDR() : WiInfo(_(label), nullptr, is_enabled_t::yes, is_hidden_t::no) { } + +MI_NTP_IP4_ADDR::MI_NTP_IP4_ADDR() + : WiInfo(_(label), nullptr, is_enabled_t::yes, is_hidden_t::no) { +} + +/*****************************************************************************/ +// MI_NTP_VIA_DHCP +MI_NTP_VIA_DHCP::MI_NTP_VIA_DHCP() + : WI_ICON_SWITCH_OFF_ON_t(bool(config_store().lan_ntp_via_dhcp.get()), _(label), nullptr, is_enabled_t::yes, is_hidden_t::no) {} + +void MI_NTP_VIA_DHCP::OnChange(size_t /*old_index*/) { + bool enabled = config_store().lan_ntp_via_dhcp.get(); + config_store().lan_ntp_via_dhcp.set(!enabled); +} diff --git a/src/gui/MItem_lan.hpp b/src/gui/MItem_lan.hpp index 08509c220a..530884ddcf 100644 --- a/src/gui/MItem_lan.hpp +++ b/src/gui/MItem_lan.hpp @@ -117,3 +117,18 @@ class MI_MAC_ADDR : public WiInfo { public: MI_MAC_ADDR(); }; + +class MI_NTP_IP4_ADDR : public WiInfo { + static constexpr const char *const label = GuiDefaults::ScreenWidth > 240 ? N_("NTP IPv4 Address") : N_("NTP IP"); + +public: + MI_NTP_IP4_ADDR(); +}; + +class MI_NTP_VIA_DHCP : public WI_ICON_SWITCH_OFF_ON_t { + constexpr static const char *const label = N_("NTP via DHCP"); + +public: + MI_NTP_VIA_DHCP(); + virtual void OnChange(size_t old_index) override; +}; diff --git a/src/gui/screen_menu_network.cpp b/src/gui/screen_menu_network.cpp index bed6d0fb69..2724cb034e 100644 --- a/src/gui/screen_menu_network.cpp +++ b/src/gui/screen_menu_network.cpp @@ -8,6 +8,7 @@ #include "netdev.h" #include "network_gui_tools.hpp" #include +#include ScreenMenuNetwork::ScreenMenuNetwork() : ScreenMenuNetwork__(_(label)) { @@ -27,8 +28,11 @@ void ScreenMenuNetwork::refresh_address() { netdev_get_ipv4_addresses(active_netdev, ðconfig); stringify_address_for_screen(str, sizeof(str), ethconfig, ETHVAR_MSK(ETHVAR_LAN_ADDR_IP4)); Item().ChangeInformation(str); + const ip_addr_t *ntp_server = sntp_getserver(0); + Item().ChangeInformation(ipaddr_ntoa(ntp_server)); } else { Item().ChangeInformation(UNKNOWN_ADDR); + Item().ChangeInformation(UNKNOWN_ADDR); } } diff --git a/src/gui/screen_menu_network.hpp b/src/gui/screen_menu_network.hpp index d4f23cbfe1..aa925ab292 100644 --- a/src/gui/screen_menu_network.hpp +++ b/src/gui/screen_menu_network.hpp @@ -15,7 +15,7 @@ using ScreenMenuNetwork__ = ScreenMenu; + MI_NET_INTERFACE_t, MI_IP4_ADDR, MI_MAC_ADDR, MI_NTP_VIA_DHCP, MI_NTP_IP4_ADDR, MI_METRICS_SETTINGS, MI_ETH_SETTINGS, MI_WIFI_SETTINGS>; class ScreenMenuNetwork : public ScreenMenuNetwork__ { public: diff --git a/src/marlin_stubs/CMakeLists.txt b/src/marlin_stubs/CMakeLists.txt index 3d157cc070..d25b50234f 100644 --- a/src/marlin_stubs/CMakeLists.txt +++ b/src/marlin_stubs/CMakeLists.txt @@ -4,6 +4,7 @@ target_sources( G64.cpp gcode.cpp M123.cpp + M1702.cpp M300.cpp M330.cpp M340.cpp diff --git a/src/marlin_stubs/M1702.cpp b/src/marlin_stubs/M1702.cpp new file mode 100644 index 0000000000..6c6ae88bbc --- /dev/null +++ b/src/marlin_stubs/M1702.cpp @@ -0,0 +1,35 @@ +/** + * @file + */ +#include "../../lib/Marlin/Marlin/src/gcode/gcode.h" +#include "../../lib/Marlin/Marlin/src/gcode/queue.h" +#include "PrusaGcodeSuite.hpp" +#include "selftest_esp.hpp" +#include +/** + * Set ntp server ip + * + * Used for setting the ntp server ip manually + * + * ## Parameters + * + * - `I` - Set ntp ip address, for example: `I "192.168.0.1"` + */ +void PrusaGcodeSuite::M1702() { + char ip_address[config_store_ns::lan_hostname_max_len + 1] = { 0 }; + if (parser.seen('I')) { + const char *ip_str = nullptr; + if ((ip_str = strstr(parser.string_arg, "\"")) != nullptr) { + ++ip_str; + strncpy(ip_address, ip_str, sizeof(ip_address)); + for (char *fn = ip_address; *fn; ++fn) { + if (*fn == '"') { + *fn = '\0'; + break; + } + } + config_store().lan_ntp_server.set(ip_address); + sntp_client_static_init(ip_address); + } + } +} diff --git a/src/marlin_stubs/PrusaGcodeSuite.hpp b/src/marlin_stubs/PrusaGcodeSuite.hpp index 955f6f1aac..b6cb94b8d2 100644 --- a/src/marlin_stubs/PrusaGcodeSuite.hpp +++ b/src/marlin_stubs/PrusaGcodeSuite.hpp @@ -88,6 +88,7 @@ void M1600(); ///< Menu change filament. Prusa STM32 platform specific void M1601(); ///< Filament stuck detected, Prusa STM32 platform specific void M1700(); ///< Preheat. Prusa STM32 platform specific void M1701(); ///< Autoload. Prusa STM32 platform specific +void M1702(); ///< Set ntp server ip #if HAS_TOOLCHANGER() void P0(); ///< Tool park diff --git a/src/marlin_stubs/gcode.cpp b/src/marlin_stubs/gcode.cpp index d53e296d1a..a8d3491937 100644 --- a/src/marlin_stubs/gcode.cpp +++ b/src/marlin_stubs/gcode.cpp @@ -176,6 +176,9 @@ bool GcodeSuite::process_parsed_command_custom(bool no_ok) { case 1701: PrusaGcodeSuite::M1701(); break; + case 1702: + PrusaGcodeSuite::M1702(); + break; default: processed = false; break; @@ -243,6 +246,7 @@ void __attribute__((weak)) PrusaGcodeSuite::M1600() { log_error(PRUSA_GCODE, "M1 void __attribute__((weak)) PrusaGcodeSuite::M1601() { log_error(PRUSA_GCODE, "M1601 unsupported"); } void __attribute__((weak)) PrusaGcodeSuite::M1700() { log_error(PRUSA_GCODE, "M1700 unsupported"); } void __attribute__((weak)) PrusaGcodeSuite::M1701() { log_error(PRUSA_GCODE, "M1701 unsupported"); } +void __attribute__((weak)) PrusaGcodeSuite::M1702() { log_error(PRUSA_GCODE, "M1702 unsupported"); } void __attribute__((weak)) PrusaGcodeSuite::G64() { log_error(PRUSA_GCODE, "G64 unsupported"); } void __attribute__((weak)) PrusaGcodeSuite::G162() { log_error(PRUSA_GCODE, "G162 unsupported"); } void __attribute__((weak)) PrusaGcodeSuite::G163() { log_error(PRUSA_GCODE, "G163 unsupported"); } diff --git a/src/persistent_stores/store_instances/config_store/defaults.hpp b/src/persistent_stores/store_instances/config_store/defaults.hpp index 2c9ecf4814..cd9b673f1e 100644 --- a/src/persistent_stores/store_instances/config_store/defaults.hpp +++ b/src/persistent_stores/store_instances/config_store/defaults.hpp @@ -78,6 +78,9 @@ namespace defaults { inline constexpr std::array wifi_ap_ssid { "" }; inline constexpr std::array wifi_ap_password { "" }; + // default ntp server: ip of Czech CESNET NTP server tak.cesnet.cz, until user changable + inline constexpr std::array ntp_server { "195.113.144.238" }; + inline constexpr eSOUND_MODE sound_mode { eSOUND_MODE::_undef }; inline constexpr uint8_t sound_volume { 5 }; inline constexpr uint16_t language { 0xffff }; diff --git a/src/persistent_stores/store_instances/config_store/store_definition.hpp b/src/persistent_stores/store_instances/config_store/store_definition.hpp index bc35d13d4f..8238b0317c 100644 --- a/src/persistent_stores/store_instances/config_store/store_definition.hpp +++ b/src/persistent_stores/store_instances/config_store/store_definition.hpp @@ -62,6 +62,9 @@ struct CurrentStore : public journal::CurrentStoreConfig timezone; // hour difference from UTC + StoreItem, defaults::ntp_server, journal::hash("NTP Server")> lan_ntp_server; // ntp server hostname + StoreItem lan_ntp_via_dhcp; // use dhcp server for ntp + // WIFI settings // wifi_flag & 1 -> On = 0/off = 1, lan_flag & 2 -> dhcp = 0/static = 1, wifi_flag & 0b1100 -> reserved, previously ap_sec_t security StoreItem wifi_flag;