Skip to content

Commit

Permalink
System Load settings from File: Provide Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bkerler authored and vorner committed Mar 7, 2024
1 parent b5d58a5 commit acf08f9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/common/str_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ void StringBuilder::append_string(const char *str) {
*current_pos_ = '\0';
}

void StringBuilder::append_string_view(string_view_utf8 str) {

while (true) {
if (is_problem()) {
return;
}

char b = str.getbyte();
if (b == '\0') {
return;
}

append_char(b);
}
}

void StringBuilder::append_printf(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
Expand Down
3 changes: 3 additions & 0 deletions src/common/str_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdint>
#include <algorithm>
#include <assert.h>
#include "../lang/string_view_utf8.hpp"

inline constexpr char CHAR_SPACE = ' ';
inline constexpr char CHAR_NBSP = '\xA0'; /// Non Breaking Space
Expand Down Expand Up @@ -384,6 +385,8 @@ class StringBuilder {

void append_string(const char *str);

void append_string_view(string_view_utf8 str);

/// Appends text to the builder, using vsnprintf under the hood.
void append_printf(const char *fmt, ...);

Expand Down
22 changes: 17 additions & 5 deletions src/gui/MItem_menus.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MItem_menus.hpp"
#include "ScreenHandler.hpp"
#include "str_utils.hpp"
#include <option/buddy_enable_connect.h>
#if BUDDY_ENABLE_CONNECT()
#include <connect/marlin_printer.hpp>
Expand Down Expand Up @@ -403,16 +404,27 @@ MI_LOAD_SETTINGS::MI_LOAD_SETTINGS()
}

void MI_LOAD_SETTINGS::click(IWindowMenu & /*window_menu*/) {
// FIXME: Some error handling/reporting
// TODO: Loading other things than just network
if (netdev_load_ini_to_eeprom()) {
auto build_message = [](StringBuilder &msg_builder, string_view_utf8 name, bool ok) {
msg_builder.append_string_view(name);
msg_builder.append_string(": ");
msg_builder.append_string_view(ok ? _("Ok") : _("Failed"));
msg_builder.append_char('\n');
};
std::array<char, 150> msg;
StringBuilder msg_builder(msg);
msg_builder.append_string_view(_("\nLoading settings finished.\n\n"));

const bool network_settings_loaded = netdev_load_ini_to_eeprom();
if (network_settings_loaded) {
notify_reconfigure();
}
build_message(msg_builder, _("Network"), network_settings_loaded);

// FIXME: Error handling
#if BUDDY_ENABLE_CONNECT()
connect_client::MarlinPrinter::load_cfg_from_ini();
build_message(msg_builder, _("Connect"), connect_client::MarlinPrinter::load_cfg_from_ini());
#endif

MsgBoxInfo(string_view_utf8::MakeRAM((const uint8_t *)msg.data()), Responses_Ok);
}

/**********************************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions src/lang/string_view_utf8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class string_view_utf8 {
, s(0xff) {}
~string_view_utf8() = default;

/// @returns one uint8_t from the input data
uint8_t getbyte() {
return getbyte(attrs);
}

/// @returns one UTF-8 character from the input data
/// and advances internal pointers (in derived classes) to the next one
unichar getUtf8Char() {
Expand Down

0 comments on commit acf08f9

Please sign in to comment.