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-06-05 12:55:23 +0300
committerbubnikv <bubnikv@gmail.com>2018-06-19 19:46:37 +0300
commit5414f7379d9ba0592f60a37a0c610a569787456c (patch)
tree4be67d64dd0486c85724fdf53fac0f288fc2fcce /xs/src/avrdude
parent2a07f3a0d58fc5785652bc3deee5e742dac16f05 (diff)
FirmwareDialog: Fix progress display
Diffstat (limited to 'xs/src/avrdude')
-rw-r--r--xs/src/avrdude/avrdude-slic3r.cpp23
-rw-r--r--xs/src/avrdude/avrdude-slic3r.hpp6
-rw-r--r--xs/src/avrdude/ser_posix.c4
3 files changed, 28 insertions, 5 deletions
diff --git a/xs/src/avrdude/avrdude-slic3r.cpp b/xs/src/avrdude/avrdude-slic3r.cpp
index a859200fb..cf4380fdb 100644
--- a/xs/src/avrdude/avrdude-slic3r.cpp
+++ b/xs/src/avrdude/avrdude-slic3r.cpp
@@ -34,6 +34,7 @@ struct AvrDude::priv
{
std::string sys_config;
std::vector<std::string> args;
+ RunFn run_fn;
MessageFn message_fn;
ProgressFn progress_fn;
CompleteFn complete_fn;
@@ -94,6 +95,12 @@ AvrDude& AvrDude::args(std::vector<std::string> args)
return *this;
}
+AvrDude& AvrDude::on_run(RunFn fn)
+{
+ if (p) { p->run_fn = std::move(fn); }
+ return *this;
+}
+
AvrDude& AvrDude::on_message(MessageFn fn)
{
if (p) { p->message_fn = std::move(fn); }
@@ -123,11 +130,17 @@ AvrDude::Ptr AvrDude::run()
if (self->p) {
auto avrdude_thread = std::thread([self]() {
- auto res = self->p->run();
- if (self->p->complete_fn) {
- self->p->complete_fn(res);
- }
- });
+ if (self->p->run_fn) {
+ self->p->run_fn();
+ }
+
+ auto res = self->p->run();
+
+ if (self->p->complete_fn) {
+ self->p->complete_fn(res);
+ }
+ });
+
self->p->avrdude_thread = std::move(avrdude_thread);
}
diff --git a/xs/src/avrdude/avrdude-slic3r.hpp b/xs/src/avrdude/avrdude-slic3r.hpp
index 8d881b094..29d96f72d 100644
--- a/xs/src/avrdude/avrdude-slic3r.hpp
+++ b/xs/src/avrdude/avrdude-slic3r.hpp
@@ -12,6 +12,7 @@ class AvrDude
{
public:
typedef std::shared_ptr<AvrDude> Ptr;
+ typedef std::function<void()> RunFn;
typedef std::function<void(const char * /* msg */, unsigned /* size */)> MessageFn;
typedef std::function<void(const char * /* task */, unsigned /* progress */)> ProgressFn;
typedef std::function<void(int /* exit status */)> CompleteFn;
@@ -29,6 +30,11 @@ public:
// Set avrdude cli arguments
AvrDude& args(std::vector<std::string> args);
+ // Set a callback to be called just after run() before avrdude is ran
+ // This can be used to perform any needed setup tasks from the background thread.
+ // This has no effect when using run_sync().
+ AvrDude& on_run(RunFn fn);
+
// Set message output callback
AvrDude& on_message(MessageFn fn);
diff --git a/xs/src/avrdude/ser_posix.c b/xs/src/avrdude/ser_posix.c
index 91b18e945..cb0fc0385 100644
--- a/xs/src/avrdude/ser_posix.c
+++ b/xs/src/avrdude/ser_posix.c
@@ -376,6 +376,10 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
FD_SET(fd->ifd, &rfds);
nfds = select(fd->ifd + 1, &rfds, NULL, NULL, &to2);
+ // FIXME: The timeout has different behaviour on Linux vs other Unices
+ // On Linux, the timeout is modified by subtracting the time spent,
+ // on OS X (for example), it is not modified.
+ // POSIX recommends re-initializing it before selecting.
if (nfds == 0) {
avrdude_message(MSG_NOTICE2, "%s: ser_recv(): programmer is not responding\n",
progname);