Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::FirmwareDialog::priv Struct Reference
+ Collaboration diagram for Slic3r::FirmwareDialog::priv:

Public Types

enum  AvrDudeComplete { AC_NONE , AC_SUCCESS , AC_FAILURE , AC_USER_CANCELLED }
 

Public Member Functions

 priv (FirmwareDialog *q)
 
void find_serial_ports ()
 
void fit_no_shrink ()
 
void set_txt_status (const wxString &label)
 
void flashing_start (unsigned tasks)
 
void flashing_done (AvrDudeComplete complete)
 
void set_autodetect (bool autodetect)
 
void update_flash_enabled ()
 
void load_hex_file (const wxString &path)
 
void queue_event (AvrdudeEvent aevt, wxString message)
 
bool ask_model_id_mismatch (const std::string &printer_model)
 
bool check_model_id ()
 
void avr109_wait_for_bootloader (Avr109Pid usb_pid, unsigned retries)
 
void avr109_reboot (const SerialPortInfo &port)
 
void avr109_lookup_port (Avr109Pid usb_pid)
 
void prepare_common ()
 
void prepare_mk2 ()
 
void prepare_mk3 ()
 
void prepare_avr109 (Avr109Pid usb_pid)
 
bool get_serial_port ()
 
void perform_upload ()
 
void user_cancel ()
 
void on_avrdude (const wxCommandEvent &evt)
 
void on_async_dialog (const wxCommandEvent &evt)
 
void ensure_joined ()
 
void queue_status (wxString message)
 
template<class ... Args>
void queue_message (const wxString &format, Args... args)
 
template<class ... Args>
void queue_error (const wxString &format, Args... args)
 

Static Public Member Functions

static const char * avr109_dev_name (Avr109Pid usb_pid)
 

Public Attributes

FirmwareDialogq
 
wxComboBox * port_picker
 
wxStaticText * txt_port_autodetect
 
wxFilePickerCtrl * hex_picker
 
wxStaticText * txt_status
 
wxGauge * progressbar
 
wxCollapsiblePane * spoiler
 
wxTextCtrl * txt_stdout
 
wxButton * btn_rescan
 
wxButton * btn_close
 
wxButton * btn_flash
 
wxString btn_flash_label_ready
 
wxString btn_flash_label_flashing
 
wxString label_status_flashing
 
wxTimer timer_pulse
 
int min_width
 
int min_height
 
int min_height_expanded
 
std::mutex mutex
 
int modal_response
 
std::condition_variable response_cv
 
std::vector< SerialPortInfoports
 
optional< SerialPortInfoport
 
bool port_autodetect
 
HexFile hex_file
 
AvrDude::Ptr avrdude
 
unsigned progress_tasks_done
 
unsigned progress_tasks_bar
 
bool user_cancelled
 
const bool extra_verbose
 

Detailed Description

Member Enumeration Documentation

◆ AvrDudeComplete

Enumerator
AC_NONE 
AC_SUCCESS 
AC_FAILURE 
AC_USER_CANCELLED 
101 {
102 AC_NONE,
106 };
@ AC_SUCCESS
Definition FirmwareDialog.cpp:103
@ AC_NONE
Definition FirmwareDialog.cpp:102
@ AC_USER_CANCELLED
Definition FirmwareDialog.cpp:105
@ AC_FAILURE
Definition FirmwareDialog.cpp:104

Constructor & Destructor Documentation

◆ priv()

Slic3r::FirmwareDialog::priv::priv ( FirmwareDialog q)
inline
150 :
151 q(q),
152 btn_flash_label_ready(_(L("Flash!"))),
153 btn_flash_label_flashing(_(L("Cancel"))),
154 label_status_flashing(_(L("Flashing in progress. Please do not disconnect the printer!"))),
155 timer_pulse(q),
156 port_autodetect(false),
159 user_cancelled(false),
160 extra_verbose(false)
161 {}
#define _(msgid)
Definition getopt.c:87
#define L(s)
Definition I18N.hpp:18
unsigned progress_tasks_bar
Definition FirmwareDialog.cpp:146
wxTimer timer_pulse
Definition FirmwareDialog.cpp:125
const bool extra_verbose
Definition FirmwareDialog.cpp:148
bool port_autodetect
Definition FirmwareDialog.cpp:139
wxString label_status_flashing
Definition FirmwareDialog.cpp:123
bool user_cancelled
Definition FirmwareDialog.cpp:147
FirmwareDialog * q
Definition FirmwareDialog.cpp:108
unsigned progress_tasks_done
Definition FirmwareDialog.cpp:145
wxString btn_flash_label_flashing
Definition FirmwareDialog.cpp:122
wxString btn_flash_label_ready
Definition FirmwareDialog.cpp:121

Member Function Documentation

◆ ask_model_id_mismatch()

bool Slic3r::FirmwareDialog::priv::ask_model_id_mismatch ( const std::string &  printer_model)
325{
326 // model_id in the hex file doesn't match what the printer repoted.
327 // Ask the user if it should be flashed anyway.
328
329 std::unique_lock<std::mutex> lock(mutex);
330
331 auto evt = new wxCommandEvent(EVT_ASYNC_DIALOG, this->q->GetId());
332 evt->SetString(wxString::Format(_(L(
333 "This firmware hex file does not match the printer model.\n"
334 "The hex file is intended for: %s\n"
335 "Printer reported: %s\n\n"
336 "Do you want to continue and flash this hex file anyway?\n"
337 "Please only continue if you are sure this is the right thing to do.")),
338 hex_file.model_id, printer_model
339 ));
340 wxQueueEvent(this->q, evt);
341
342 response_cv.wait(lock, [this]() { return this->modal_response != wxID_NONE; });
343
344 if (modal_response == wxID_YES) {
345 return true;
346 } else {
347 user_cancel();
348 return false;
349 }
350}
void user_cancel()
Definition FirmwareDialog.cpp:694
int modal_response
Definition FirmwareDialog.cpp:133
std::condition_variable response_cv
Definition FirmwareDialog.cpp:134
HexFile hex_file
Definition FirmwareDialog.cpp:140
std::mutex mutex
Definition FirmwareDialog.cpp:132
std::string model_id
Definition HexFile.hpp:25

References _, and L.

◆ avr109_dev_name()

const char * Slic3r::FirmwareDialog::priv::avr109_dev_name ( Avr109Pid  usb_pid)
static
771 {
772 switch (usb_pid.boot) {
773 case USB_PID_MMU_BOOT:
774 return "Original Prusa MMU 2.0 Control";
775 case USB_PID_CW1_BOOT:
776 return "Original Prusa CW1";
778 return "Original Prusa CW1S";
779 default: throw Slic3r::RuntimeError((boost::format("Invalid avr109 device USB PID: %1%") % usb_pid.boot).str());
780 }
781}
@ USB_PID_CW1S_BOOT
Definition FirmwareDialog.cpp:68
@ USB_PID_CW1_BOOT
Definition FirmwareDialog.cpp:66
@ USB_PID_MMU_BOOT
Definition FirmwareDialog.cpp:64

References Slic3r::Avr109Pid::boot, Slic3r::USB_PID_CW1_BOOT, Slic3r::USB_PID_CW1S_BOOT, and Slic3r::USB_PID_MMU_BOOT.

◆ avr109_lookup_port()

void Slic3r::FirmwareDialog::priv::avr109_lookup_port ( Avr109Pid  usb_pid)
434{
435 const char *dev_name = avr109_dev_name(usb_pid);
436 const wxString msg_not_found = wxString::Format(
437 _(L("The %s device was not found.\n"
438 "If the device is connected, please press the Reset button next to the USB connector ...")),
439 dev_name);
440
441 queue_message("Flashing %s, looking for VID/PID 0x2c99/%u or 0x2c99/%u ...", dev_name, usb_pid.boot, usb_pid.app);
442
444 ports.erase(std::remove_if(ports.begin(), ports.end(), [=](const SerialPortInfo &port ) {
445 return port.id_vendor != USB_VID_PRUSA ||
446 (port.id_product != usb_pid.boot && port.id_product != usb_pid.app);
447 }), ports.end());
448
449 if (ports.size() == 0) {
450 queue_message("The %s device was not found.", dev_name);
451 queue_status(msg_not_found);
452 avr109_wait_for_bootloader(usb_pid, 30);
453 } else if (ports.size() > 1) {
454 queue_message("Several VID/PID 0x2c99/%u devices found", usb_pid.boot);
455 queue_error(_(L("Multiple %s devices found. Please only connect one at a time for flashing.")), dev_name);
456 } else {
457 if (ports[0].id_product == usb_pid.app) {
458 // The device needs to be rebooted into the bootloader mode
459 queue_message("Found VID/PID 0x2c99/%u at `%s`, rebooting the device ...", usb_pid.app, ports[0].port);
461 avr109_wait_for_bootloader(usb_pid, 10);
462
463 if (! port) {
464 // The device in bootloader mode was not found, inform the user and wait some more...
465 queue_message("%s device not found after reboot", dev_name);
466 queue_status(msg_not_found);
467 avr109_wait_for_bootloader(usb_pid, 30);
468 }
469 } else {
470 port = ports[0];
471 }
472 }
473}
std::vector< SerialPortInfo > scan_serial_ports_extended()
Definition Serial.cpp:107
void avr109_reboot(const SerialPortInfo &port)
Definition FirmwareDialog.cpp:426
optional< SerialPortInfo > port
Definition FirmwareDialog.cpp:138
std::vector< SerialPortInfo > ports
Definition FirmwareDialog.cpp:137
void avr109_wait_for_bootloader(Avr109Pid usb_pid, unsigned retries)
Definition FirmwareDialog.cpp:401
void queue_message(const wxString &format, Args... args)
Definition FirmwareDialog.cpp:192
static const char * avr109_dev_name(Avr109Pid usb_pid)
Definition FirmwareDialog.cpp:771
void queue_error(const wxString &format, Args... args)
Definition FirmwareDialog.cpp:199
void queue_status(wxString message)
Definition FirmwareDialog.cpp:190

References _, Slic3r::Avr109Pid::app, Slic3r::Avr109Pid::boot, L, and Slic3r::Utils::scan_serial_ports_extended().

+ Here is the call graph for this function:

◆ avr109_reboot()

void Slic3r::FirmwareDialog::priv::avr109_reboot ( const SerialPortInfo port)
427{
428 asio::io_service io;
429 Serial serial(io, port.port, 1200);
430 std::this_thread::sleep_for(std::chrono::milliseconds(50));
431}

References Slic3r::Utils::SerialPortInfo::port.

◆ avr109_wait_for_bootloader()

void Slic3r::FirmwareDialog::priv::avr109_wait_for_bootloader ( Avr109Pid  usb_pid,
unsigned  retries 
)
402{
403 enum {
404 SLEEP_MS = 500,
405 };
406
407 for (unsigned i = 0; i < retries && !user_cancelled; i++) {
408 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MS));
409
411 ports.erase(std::remove_if(ports.begin(), ports.end(), [=](const SerialPortInfo &port ) {
412 return port.id_vendor != USB_VID_PRUSA || port.id_product != usb_pid.boot;
413 }), ports.end());
414
415 if (ports.size() == 1) {
416 port = ports[0];
417 return;
418 } else if (ports.size() > 1) {
419 queue_message("Several VID/PID 0x2c99/%u devices found", usb_pid.boot);
420 queue_error(_(L("Multiple %s devices found. Please only connect one at a time for flashing.")), avr109_dev_name(usb_pid));
421 return;
422 }
423 }
424}

References _, Slic3r::Avr109Pid::boot, L, and Slic3r::Utils::scan_serial_ports_extended().

+ Here is the call graph for this function:

◆ check_model_id()

bool Slic3r::FirmwareDialog::priv::check_model_id ( )
353{
354 // XXX: The implementation in Serial doesn't currently work reliably enough to be used.
355 // Therefore, regretably, so far the check cannot be used and we just return true here.
356 // TODO: Rewrite Serial using more platform-native code.
357 return true;
358
359 // if (hex_file.model_id.empty()) {
360 // // No data to check against, assume it's ok
361 // return true;
362 // }
363
364 // asio::io_service io;
365 // Serial serial(io, port->port, 115200);
366 // serial.printer_setup();
367
368 // enum {
369 // TIMEOUT = 2000,
370 // RETREIES = 5,
371 // };
372
373 // if (! serial.printer_ready_wait(RETREIES, TIMEOUT)) {
374 // queue_error(wxString::Format(_(L("Could not connect to the printer at %s")), port->port));
375 // return false;
376 // }
377
378 // std::string line;
379 // error_code ec;
380 // serial.printer_write_line("PRUSA Rev");
381 // while (serial.read_line(TIMEOUT, line, ec)) {
382 // if (ec) {
383 // queue_error(wxString::Format(_(L("Could not connect to the printer at %s")), port->port));
384 // return false;
385 // }
386
387 // if (line == "ok") { continue; }
388
389 // if (line == hex_file.model_id) {
390 // return true;
391 // } else {
392 // return ask_model_id_mismatch(line);
393 // }
394
395 // line.clear();
396 // }
397
398 // return false;
399}

◆ ensure_joined()

void Slic3r::FirmwareDialog::priv::ensure_joined ( )
765{
766 // Make sure the background thread is collected and the AvrDude object reset
767 if (avrdude) { avrdude->join(); }
768 avrdude.reset();
769}
AvrDude::Ptr avrdude
Definition FirmwareDialog.cpp:144

◆ find_serial_ports()

void Slic3r::FirmwareDialog::priv::find_serial_ports ( )
209{
210 auto new_ports = Utils::scan_serial_ports_extended();
211 if (new_ports != this->ports) {
212 this->ports = new_ports;
213 port_picker->Clear();
214 for (const auto &port : this->ports)
215 port_picker->Append(wxString::FromUTF8(port.friendly_name.data()));
216 if (ports.size() > 0) {
217 int idx = port_picker->GetValue().IsEmpty() ? 0 : -1;
218 for (int i = 0; i < (int)this->ports.size(); ++ i)
219 if (this->ports[i].is_printer) {
220 idx = i;
221 break;
222 }
223 if (idx != -1) {
224 port_picker->SetSelection(idx);
226 }
227 }
228 }
229}
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195
void update_flash_enabled()
Definition FirmwareDialog.cpp:301
wxComboBox * port_picker
Definition FirmwareDialog.cpp:111

References port, port_picker, ports, Slic3r::Utils::scan_serial_ports_extended(), and update_flash_enabled().

+ Here is the call graph for this function:

◆ fit_no_shrink()

void Slic3r::FirmwareDialog::priv::fit_no_shrink ( )
232{
233 // Ensure content fits into window and window is not shrinked
234 const auto old_size = q->GetSize();
235 q->Layout();
236 q->Fit();
237 const auto new_size = q->GetSize();
238 const auto new_width = std::max(old_size.GetWidth(), new_size.GetWidth());
239 const auto new_height = std::max(old_size.GetHeight(), new_size.GetHeight());
240 q->SetSize(new_width, new_height);
241}

◆ flashing_done()

void Slic3r::FirmwareDialog::priv::flashing_done ( AvrDudeComplete  complete)
272{
273 port_picker->Enable();
274 btn_rescan->Enable();
275 hex_picker->Enable();
276 btn_close->Enable();
278 txt_status->SetForegroundColour(GUI::wxGetApp().get_label_clr_default());
279 timer_pulse.Stop();
280 progressbar->SetValue(progressbar->GetRange());
281
282 switch (complete) {
283 case AC_SUCCESS: set_txt_status(_(L("Flashing succeeded!"))); break;
284 case AC_FAILURE: set_txt_status(_(L("Flashing failed. Please see the avrdude log below."))); break;
285 case AC_USER_CANCELLED: set_txt_status(_(L("Flashing cancelled."))); break;
286 default: break;
287 }
288}
wxGauge * progressbar
Definition FirmwareDialog.cpp:115
wxButton * btn_flash
Definition FirmwareDialog.cpp:120
wxFilePickerCtrl * hex_picker
Definition FirmwareDialog.cpp:113
wxButton * btn_close
Definition FirmwareDialog.cpp:119
wxButton * btn_rescan
Definition FirmwareDialog.cpp:118
void set_txt_status(const wxString &label)
Definition FirmwareDialog.cpp:243
wxStaticText * txt_status
Definition FirmwareDialog.cpp:114

References _, and L.

◆ flashing_start()

void Slic3r::FirmwareDialog::priv::flashing_start ( unsigned  tasks)
253{
254 modal_response = wxID_NONE;
255 txt_stdout->Clear();
257 txt_status->SetForegroundColour(GUI::wxGetApp().get_label_clr_modified());
258 port_picker->Disable();
259 btn_rescan->Disable();
260 hex_picker->Disable();
261 btn_close->Disable();
263 progressbar->SetRange(200 * tasks); // See progress callback below
264 progressbar->SetValue(0);
267 user_cancelled = false;
268 timer_pulse.Start(50);
269}
wxTextCtrl * txt_stdout
Definition FirmwareDialog.cpp:117

◆ get_serial_port()

bool Slic3r::FirmwareDialog::priv::get_serial_port ( )
576{
577 const int selection = port_picker->GetSelection();
578 if (selection != wxNOT_FOUND) {
579 port = this->ports[selection];
580 } else {
581 // User has supplied a custom filename
582
583 std::string path_u8 = GUI::into_u8(port_picker->GetValue());
584#ifdef _WIN32
585 static const std::regex com_pattern("COM[0-9]+", std::regex::icase);
586 std::smatch matches;
587 if (std::regex_match(path_u8, matches, com_pattern)) {
588#else
589 if (fs::is_other(fs::path(path_u8))) {
590#endif
591 port = SerialPortInfo(std::move(path_u8));
592 } else {
593 port = boost::none;
594 }
595 }
596
597 return !!port;
598}
std::string into_u8(const wxString &str)
Definition GUI.cpp:442

References Slic3r::GUI::into_u8().

+ Here is the call graph for this function:

◆ load_hex_file()

void Slic3r::FirmwareDialog::priv::load_hex_file ( const wxString &  path)
310{
311 hex_file = HexFile(path.wx_str());
313 set_autodetect(autodetect);
314}
void set_autodetect(bool autodetect)
Definition FirmwareDialog.cpp:290
@ DEV_CW1S
Definition HexFile.hpp:20
@ DEV_CW1
Definition HexFile.hpp:19
@ DEV_MM_CONTROL
Definition HexFile.hpp:18
DeviceKind device
Definition HexFile.hpp:24

References Slic3r::Utils::HexFile::DEV_CW1, Slic3r::Utils::HexFile::DEV_CW1S, and Slic3r::Utils::HexFile::DEV_MM_CONTROL.

◆ on_async_dialog()

void Slic3r::FirmwareDialog::priv::on_async_dialog ( const wxCommandEvent &  evt)
754{
755 //wxMessageDialog dlg(this->q, evt.GetString(), wxMessageBoxCaptionStr, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
756 GUI::MessageDialog dlg(this->q, evt.GetString(), wxMessageBoxCaptionStr, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
757 {
758 std::lock_guard<std::mutex> lock(mutex);
759 modal_response = dlg.ShowModal();
760 }
761 response_cv.notify_all();
762}

◆ on_avrdude()

void Slic3r::FirmwareDialog::priv::on_avrdude ( const wxCommandEvent &  evt)
703{
704 AvrDudeComplete complete_kind;
705
706 switch (evt.GetExtraLong()) {
707 case AE_MESSAGE:
708 txt_stdout->AppendText(evt.GetString());
709 break;
710
711 case AE_PROGRESS:
712 // We try to track overall progress here.
713 // Avrdude performs 3 tasks per one memory operation ("-U" arg),
714 // first of which is reading of status data (very short).
715 // We use the timer_pulse during the very first task to indicate intialization
716 // and then display overall progress during the latter tasks.
717
718 if (progress_tasks_done > 0) {
719 progressbar->SetValue(progress_tasks_bar + evt.GetInt());
720 }
721
722 if (evt.GetInt() == 100) {
723 timer_pulse.Stop();
724 if (progress_tasks_done % 3 != 0) {
725 progress_tasks_bar += 100;
726 }
728 }
729
730 break;
731
732 case AE_EXIT:
733 BOOST_LOG_TRIVIAL(info) << "avrdude exit code: " << evt.GetInt();
734
735 // Figure out the exit state
736 if (user_cancelled) { complete_kind = AC_USER_CANCELLED; }
737 else if (avrdude->cancelled()) { complete_kind = AC_NONE; } // Ie. cancelled programatically
738 else { complete_kind = evt.GetInt() == 0 ? AC_SUCCESS : AC_FAILURE; }
739
740 flashing_done(complete_kind);
742 break;
743
744 case AE_STATUS:
745 set_txt_status(evt.GetString());
746 break;
747
748 default:
749 break;
750 }
751}
@ AE_MESSAGE
Definition FirmwareDialog.cpp:76
@ AE_EXIT
Definition FirmwareDialog.cpp:79
@ AE_STATUS
Definition FirmwareDialog.cpp:78
@ AE_PROGRESS
Definition FirmwareDialog.cpp:77
void flashing_done(AvrDudeComplete complete)
Definition FirmwareDialog.cpp:271
AvrDudeComplete
Definition FirmwareDialog.cpp:101
void ensure_joined()
Definition FirmwareDialog.cpp:764

References Slic3r::AE_EXIT, Slic3r::AE_MESSAGE, Slic3r::AE_PROGRESS, and Slic3r::AE_STATUS.

◆ perform_upload()

void Slic3r::FirmwareDialog::priv::perform_upload ( )
601{
602 auto filename = hex_picker->GetPath();
603 if (filename.IsEmpty()) { return; }
604
605 load_hex_file(filename); // Might already be loaded, but we want to make sure it's fresh
606
607 if (!port_autodetect && !get_serial_port()) {
608 return;
609 }
610
611 const bool extra_verbose = false; // For debugging
612
614
615 // Init the avrdude object
616 AvrDude avrdude;
617
618 // It is ok here to use the q-pointer to the FirmwareDialog
619 // because the dialog ensures it doesn't exit before the background thread is done.
620 auto q = this->q;
621
622 avrdude
623 .on_run([this](AvrDude::Ptr avrdude) {
624 this->avrdude = std::move(avrdude);
625
626 try {
627 switch (this->hex_file.device) {
628 case HexFile::DEV_MK3:
629 this->prepare_mk3();
630 break;
631
634 break;
635
636 case HexFile::DEV_CW1:
638 break;
639
642 break;
643
644 default:
645 this->prepare_mk2();
646 break;
647 }
648 } catch (const std::exception &ex) {
649 if (port) {
650 queue_error(_(L("Error accessing port at %s: %s")), port->port, ex.what());
651 } else {
652 queue_error(_(L("Error: %s")), ex.what());
653 }
654 }
655 })
656 .on_message([
657#if !defined(__APPLE__) && !defined(__clang__)
658 // clang complains when capturing constants.
660#endif // __APPLE__
661 q](const char* msg, unsigned /* size */) {
662 if (extra_verbose) {
663 BOOST_LOG_TRIVIAL(debug) << "avrdude: " << msg;
664 }
665
666 auto evt = new wxCommandEvent(EVT_AVRDUDE, q->GetId());
667 auto wxmsg = wxString::FromUTF8(msg);
668#ifdef WIN32
669 // The string might be in local encoding
670 if (wxmsg.IsEmpty() && *msg != '\0') {
671 wxmsg = wxString(msg);
672 }
673#endif
674
675 evt->SetExtraLong(AE_MESSAGE);
676 evt->SetString(std::move(wxmsg));
677 wxQueueEvent(q, evt);
678 })
679 .on_progress([q](const char * /* task */, unsigned progress) {
680 auto evt = new wxCommandEvent(EVT_AVRDUDE, q->GetId());
681 evt->SetExtraLong(AE_PROGRESS);
682 evt->SetInt(progress);
683 wxQueueEvent(q, evt);
684 })
685 .on_complete([this]() {
686 auto evt = new wxCommandEvent(EVT_AVRDUDE, this->q->GetId());
687 evt->SetExtraLong(AE_EXIT);
688 evt->SetInt(this->avrdude->exit_code());
689 wxQueueEvent(this->q, evt);
690 })
691 .run();
692}
std::shared_ptr< AvrDude > Ptr
Definition avrdude-slic3r.hpp:19
static void run(wxWindow *parent)
Definition FirmwareDialog.cpp:950
@ USB_PID_CW1S_APP
Definition FirmwareDialog.cpp:69
@ USB_PID_CW1_APP
Definition FirmwareDialog.cpp:67
@ USB_PID_MMU_APP
Definition FirmwareDialog.cpp:65
void prepare_avr109(Avr109Pid usb_pid)
Definition FirmwareDialog.cpp:544
void prepare_mk3()
Definition FirmwareDialog.cpp:510
void flashing_start(unsigned tasks)
Definition FirmwareDialog.cpp:252
bool get_serial_port()
Definition FirmwareDialog.cpp:575
void prepare_mk2()
Definition FirmwareDialog.cpp:498
void load_hex_file(const wxString &path)
Definition FirmwareDialog.cpp:309
@ DEV_MK3
Definition HexFile.hpp:17

References _, Slic3r::AE_EXIT, Slic3r::AE_MESSAGE, Slic3r::AE_PROGRESS, Slic3r::Utils::HexFile::DEV_CW1, Slic3r::Utils::HexFile::DEV_CW1S, Slic3r::Utils::HexFile::DEV_MK3, Slic3r::Utils::HexFile::DEV_MM_CONTROL, L, Slic3r::AvrDude::on_run(), Slic3r::FirmwareDialog::run(), Slic3r::USB_PID_CW1_APP, Slic3r::USB_PID_CW1_BOOT, Slic3r::USB_PID_CW1S_APP, Slic3r::USB_PID_CW1S_BOOT, Slic3r::USB_PID_MMU_APP, and Slic3r::USB_PID_MMU_BOOT.

+ Here is the call graph for this function:

◆ prepare_avr109()

void Slic3r::FirmwareDialog::priv::prepare_avr109 ( Avr109Pid  usb_pid)
545{
546 port = boost::none;
547 avr109_lookup_port(usb_pid);
548 if (! port) {
549 queue_error(_(L("The %s device could not have been found")), avr109_dev_name(usb_pid));
550 return;
551 }
552
553 queue_message("Found VID/PID 0x2c99/%u at `%s`, flashing ...", usb_pid.boot, port->port);
555
556 std::vector<std::string> args {{
557 extra_verbose ? "-vvvvv" : "-v",
558 "-p", "atmega32u4",
559 "-c", "avr109",
560 "-P", port->port,
561 "-b", "57600",
562 "-D",
563 "-U", (boost::format("flash:w:0:%1%:i") % hex_file.path.string()).str(),
564 }};
565
566 BOOST_LOG_TRIVIAL(info) << "Preparing avrdude arguments: "
567 << std::accumulate(std::next(args.begin()), args.end(), args[0], [](std::string a, const std::string &b) {
568 return a + ' ' + b;
569 });
570
571 avrdude->push_args(std::move(args));
572}
void avr109_lookup_port(Avr109Pid usb_pid)
Definition FirmwareDialog.cpp:433
boost::filesystem::path path
Definition HexFile.hpp:23

References _, Slic3r::Avr109Pid::boot, and L.

◆ prepare_common()

void Slic3r::FirmwareDialog::priv::prepare_common ( )
476{
477 std::vector<std::string> args {{
478 extra_verbose ? "-vvvvv" : "-v",
479 "-p", "atmega2560",
480 // Using the "Wiring" mode to program Rambo or Einsy, using the STK500v2 protocol (not the STK500).
481 // The Prusa's avrdude is patched to never send semicolons inside the data packets, as the USB to serial chip
482 // is flashed with a buggy firmware.
483 "-c", "wiring",
484 "-P", port->port,
485 "-b", "115200", // TODO: Allow other rates? Ditto elsewhere.
486 "-D",
487 "-U", (boost::format("flash:w:0:%1%:i") % hex_file.path.string()).str(),
488 }};
489
490 BOOST_LOG_TRIVIAL(info) << "Preparing arguments avrdude: "
491 << std::accumulate(std::next(args.begin()), args.end(), args[0], [](std::string a, const std::string &b) {
492 return a + ' ' + b;
493 });
494
495 avrdude->push_args(std::move(args));
496}

◆ prepare_mk2()

void Slic3r::FirmwareDialog::priv::prepare_mk2 ( )
499{
500 if (! port) { return; }
501
502 if (! check_model_id()) {
503 avrdude->cancel();
504 return;
505 }
506
508}
void prepare_common()
Definition FirmwareDialog.cpp:475
bool check_model_id()
Definition FirmwareDialog.cpp:352

◆ prepare_mk3()

void Slic3r::FirmwareDialog::priv::prepare_mk3 ( )
511{
512 if (! port) { return; }
513
514 if (! check_model_id()) {
515 avrdude->cancel();
516 return;
517 }
518
520
521 // The hex file also contains another section with l10n data to be flashed into the external flash on MK3 (Einsy)
522 // This is done via another avrdude invocation, here we build arg list for that:
523 std::vector<std::string> args {{
524 extra_verbose ? "-vvvvv" : "-v",
525 "-p", "atmega2560",
526 // Using the "Arduino" mode to program Einsy's external flash with languages, using the STK500 protocol (not the STK500v2).
527 // The Prusa's avrdude is patched again to never send semicolons inside the data packets.
528 "-c", "arduino",
529 "-P", port->port,
530 "-b", "115200",
531 "-D",
532 "-u", // disable safe mode
533 "-U", (boost::format("flash:w:1:%1%:i") % hex_file.path.string()).str(),
534 }};
535
536 BOOST_LOG_TRIVIAL(info) << "Preparing avrdude arguments for external flash flashing: "
537 << std::accumulate(std::next(args.begin()), args.end(), args[0], [](std::string a, const std::string &b) {
538 return a + ' ' + b;
539 });
540
541 avrdude->push_args(std::move(args));
542}

◆ queue_error()

template<class ... Args>
void Slic3r::FirmwareDialog::priv::queue_error ( const wxString &  format,
Args...  args 
)
inline
199 {
200 queue_message(format, args...);
201 queue_event(AE_STATUS, _(L("Flashing failed")) +": "+ wxString::Format(format, args...));
202 avrdude->cancel();
203 }
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:44
void queue_event(AvrdudeEvent aevt, wxString message)
Definition FirmwareDialog.cpp:316

References _, Slic3r::AE_STATUS, avrdude, Slic3r::format(), L, queue_event(), and queue_message().

+ Here is the call graph for this function:

◆ queue_event()

void Slic3r::FirmwareDialog::priv::queue_event ( AvrdudeEvent  aevt,
wxString  message 
)
317{
318 auto evt = new wxCommandEvent(EVT_AVRDUDE, this->q->GetId());
319 evt->SetExtraLong(aevt);
320 evt->SetString(std::move(message));
321 wxQueueEvent(this->q, evt);
322}

Referenced by queue_error(), queue_message(), and queue_status().

+ Here is the caller graph for this function:

◆ queue_message()

template<class ... Args>
void Slic3r::FirmwareDialog::priv::queue_message ( const wxString &  format,
Args...  args 
)
inline
192 {
193 auto message = wxString::Format(format, args...);
194 BOOST_LOG_TRIVIAL(info) << message;
195 message.Append('\n');
196 queue_event(AE_MESSAGE, std::move(message));
197 }

References Slic3r::AE_MESSAGE, Slic3r::format(), and queue_event().

Referenced by queue_error().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ queue_status()

void Slic3r::FirmwareDialog::priv::queue_status ( wxString  message)
inline
190{ queue_event(AE_STATUS, std::move(message)); }

References Slic3r::AE_STATUS, and queue_event().

+ Here is the call graph for this function:

◆ set_autodetect()

void Slic3r::FirmwareDialog::priv::set_autodetect ( bool  autodetect)
291{
292 port_autodetect = autodetect;
293
294 port_picker->Show(!autodetect);
295 btn_rescan->Show(!autodetect);
296 txt_port_autodetect->Show(autodetect);
297 q->Layout();
299}
void fit_no_shrink()
Definition FirmwareDialog.cpp:231
wxStaticText * txt_port_autodetect
Definition FirmwareDialog.cpp:112

◆ set_txt_status()

void Slic3r::FirmwareDialog::priv::set_txt_status ( const wxString &  label)
244{
245 const auto width = txt_status->GetSize().GetWidth();
246 txt_status->SetLabel(label);
247 txt_status->Wrap(width);
248
250}
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:539

◆ update_flash_enabled()

void Slic3r::FirmwareDialog::priv::update_flash_enabled ( )
302{
303 const bool hex_exists = wxFileExists(hex_picker->GetPath());
304 const bool port_valid = port_autodetect || get_serial_port();
305
306 btn_flash->Enable(hex_exists && port_valid);
307}

Referenced by find_serial_ports().

+ Here is the caller graph for this function:

◆ user_cancel()

void Slic3r::FirmwareDialog::priv::user_cancel ( )
695{
696 if (avrdude) {
697 user_cancelled = true;
698 avrdude->cancel();
699 }
700}

Member Data Documentation

◆ avrdude

AvrDude::Ptr Slic3r::FirmwareDialog::priv::avrdude

Referenced by queue_error().

◆ btn_close

wxButton* Slic3r::FirmwareDialog::priv::btn_close

◆ btn_flash

wxButton* Slic3r::FirmwareDialog::priv::btn_flash

◆ btn_flash_label_flashing

wxString Slic3r::FirmwareDialog::priv::btn_flash_label_flashing

◆ btn_flash_label_ready

wxString Slic3r::FirmwareDialog::priv::btn_flash_label_ready

◆ btn_rescan

wxButton* Slic3r::FirmwareDialog::priv::btn_rescan

◆ extra_verbose

const bool Slic3r::FirmwareDialog::priv::extra_verbose

◆ hex_file

HexFile Slic3r::FirmwareDialog::priv::hex_file

◆ hex_picker

wxFilePickerCtrl* Slic3r::FirmwareDialog::priv::hex_picker

◆ label_status_flashing

wxString Slic3r::FirmwareDialog::priv::label_status_flashing

◆ min_height

int Slic3r::FirmwareDialog::priv::min_height

◆ min_height_expanded

int Slic3r::FirmwareDialog::priv::min_height_expanded

◆ min_width

int Slic3r::FirmwareDialog::priv::min_width

◆ modal_response

int Slic3r::FirmwareDialog::priv::modal_response

◆ mutex

std::mutex Slic3r::FirmwareDialog::priv::mutex

◆ port

optional<SerialPortInfo> Slic3r::FirmwareDialog::priv::port

Referenced by find_serial_ports().

◆ port_autodetect

bool Slic3r::FirmwareDialog::priv::port_autodetect

◆ port_picker

wxComboBox* Slic3r::FirmwareDialog::priv::port_picker

Referenced by find_serial_ports().

◆ ports

std::vector<SerialPortInfo> Slic3r::FirmwareDialog::priv::ports

Referenced by find_serial_ports().

◆ progress_tasks_bar

unsigned Slic3r::FirmwareDialog::priv::progress_tasks_bar

◆ progress_tasks_done

unsigned Slic3r::FirmwareDialog::priv::progress_tasks_done

◆ progressbar

wxGauge* Slic3r::FirmwareDialog::priv::progressbar

◆ q

FirmwareDialog* Slic3r::FirmwareDialog::priv::q

◆ response_cv

std::condition_variable Slic3r::FirmwareDialog::priv::response_cv

◆ spoiler

wxCollapsiblePane* Slic3r::FirmwareDialog::priv::spoiler

◆ timer_pulse

wxTimer Slic3r::FirmwareDialog::priv::timer_pulse

◆ txt_port_autodetect

wxStaticText* Slic3r::FirmwareDialog::priv::txt_port_autodetect

◆ txt_status

wxStaticText* Slic3r::FirmwareDialog::priv::txt_status

◆ txt_stdout

wxTextCtrl* Slic3r::FirmwareDialog::priv::txt_stdout

◆ user_cancelled

bool Slic3r::FirmwareDialog::priv::user_cancelled

The documentation for this struct was generated from the following file: