Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVojtech Kral <vojtech@kral.hk>2018-05-04 17:04:43 +0300
committerVojtech Kral <vojtech@kral.hk>2018-05-21 19:58:22 +0300
commitaf360d7097d3c946b712fc62f0af4592d0e8921f (patch)
treef4e50eb759f29c6fad05c2227c0622880f0f6f56 /xs/src/avrdude
parent3d09f2a980af4df03fb8950537d1bcb92f87a94d (diff)
Firmware updater GUI
Diffstat (limited to 'xs/src/avrdude')
-rw-r--r--xs/src/avrdude/avrdude-slic3r.cpp21
-rw-r--r--xs/src/avrdude/avrdude-slic3r.hpp4
2 files changed, 19 insertions, 6 deletions
diff --git a/xs/src/avrdude/avrdude-slic3r.cpp b/xs/src/avrdude/avrdude-slic3r.cpp
index 9f9093aa2..d47469e84 100644
--- a/xs/src/avrdude/avrdude-slic3r.cpp
+++ b/xs/src/avrdude/avrdude-slic3r.cpp
@@ -5,30 +5,39 @@ extern "C" {
#include "avrdude.h"
}
+
namespace Slic3r {
namespace AvrDude {
-static void avrdude_message_handler_ostream(const char *msg, unsigned size, void *user_p)
+
+// Used by our custom code in avrdude to receive messages that avrdude normally outputs on stdout (see avrdude_message())
+static void avrdude_message_handler_closure(const char *msg, unsigned size, void *user_p)
{
- (void)size;
- std::ostream &os = *reinterpret_cast<std::ostream*>(user_p);
- os << msg;
+ auto *message_fn = reinterpret_cast<MessageFn*>(user_p);
+ (*message_fn)(msg, size);
}
-int main(std::vector<std::string> args, std::string sys_config, std::ostream &os)
+int main(std::vector<std::string> args, std::string sys_config, MessageFn message_fn)
{
std::vector<char *> c_args {{ const_cast<char*>(PACKAGE_NAME) }};
for (const auto &arg : args) {
c_args.push_back(const_cast<char*>(arg.data()));
}
- ::avrdude_message_handler_set(avrdude_message_handler_ostream, reinterpret_cast<void*>(&os));
+ ::avrdude_message_handler_set(avrdude_message_handler_closure, reinterpret_cast<void*>(&message_fn));
const auto res = ::avrdude_main(static_cast<int>(c_args.size()), c_args.data(), sys_config.c_str());
::avrdude_message_handler_set(nullptr, nullptr);
return res;
}
+int main(std::vector<std::string> args, std::string sys_config, std::ostream &os)
+{
+ return main(std::move(args), std::move(sys_config), std::move([&os](const char *msg, unsigned /* size */) {
+ os << msg;
+ }));
+}
+
}
diff --git a/xs/src/avrdude/avrdude-slic3r.hpp b/xs/src/avrdude/avrdude-slic3r.hpp
index d26a0edda..b6143b508 100644
--- a/xs/src/avrdude/avrdude-slic3r.hpp
+++ b/xs/src/avrdude/avrdude-slic3r.hpp
@@ -4,10 +4,14 @@
#include <vector>
#include <string>
#include <ostream>
+#include <functional>
namespace Slic3r {
namespace AvrDude {
+ typedef std::function<void(const char * /* msg */, unsigned /* size */)> MessageFn;
+
+ int main(std::vector<std::string> args, std::string sys_config, MessageFn message_fn);
int main(std::vector<std::string> args, std::string sys_config, std::ostream &os);
}