FirmwareUpdater: MMU 2.0 / Caterina flashing

This commit is contained in:
Vojtech Kral 2018-07-24 17:42:12 +02:00 committed by bubnikv
parent a7eaf38853
commit a32bd17b75
8 changed files with 496 additions and 109 deletions

View file

@ -36,6 +36,7 @@ struct AvrDude::priv
std::string sys_config;
std::deque<std::vector<std::string>> args;
size_t current_args_set = 0;
bool cancelled = false;
RunFn run_fn;
MessageFn message_fn;
ProgressFn progress_fn;
@ -141,11 +142,16 @@ AvrDude::Ptr AvrDude::run()
if (self->p) {
auto avrdude_thread = std::thread([self]() {
bool cancel = false;
int res = -1;
if (self->p->run_fn) {
self->p->run_fn();
self->p->run_fn(*self);
}
auto res = self->p->run();
if (! self->p->cancelled) {
res = self->p->run();
}
if (self->p->complete_fn) {
self->p->complete_fn(res, self->p->current_args_set);
@ -160,7 +166,10 @@ AvrDude::Ptr AvrDude::run()
void AvrDude::cancel()
{
::avrdude_cancel();
if (p) {
p->cancelled = true;
::avrdude_cancel();
}
}
void AvrDude::join()

View file

@ -12,7 +12,7 @@ class AvrDude
{
public:
typedef std::shared_ptr<AvrDude> Ptr;
typedef std::function<void()> RunFn;
typedef std::function<void(AvrDude&)> 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 */, size_t /* args_id */)> CompleteFn;
@ -31,7 +31,8 @@ public:
AvrDude& push_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 can be used to perform any needed setup tasks from the background thread,
// and, optionally, to cancel by writing true to the `cancel` argument.
// This has no effect when using run_sync().
AvrDude& on_run(RunFn fn);