FirmwareUpdaterMachineAction.qml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.1
  5. import QtQuick.Layouts 1.1
  6. import QtQuick.Window 2.1
  7. import QtQuick.Dialogs // For filedialog
  8. import UM 1.5 as UM
  9. import Cura 1.0 as Cura
  10. Cura.MachineAction
  11. {
  12. anchors.fill: parent
  13. property bool printerConnected: Cura.MachineManager.printerConnected
  14. property var activeOutputDevice: printerConnected ? Cura.MachineManager.printerOutputDevices[0] : null
  15. property bool canUpdateFirmware: activeOutputDevice ? activeOutputDevice.activePrinter.canUpdateFirmware : false
  16. Column
  17. {
  18. id: firmwareUpdaterMachineAction
  19. anchors.fill: parent;
  20. UM.I18nCatalog { id: catalog; name: "cura"}
  21. spacing: UM.Theme.getSize("default_margin").height
  22. UM.Label
  23. {
  24. width: parent.width
  25. text: catalog.i18nc("@title", "Update Firmware")
  26. font.pointSize: 18
  27. }
  28. UM.Label
  29. {
  30. width: parent.width
  31. text: catalog.i18nc("@label", "Firmware is the piece of software running directly on your 3D printer. This firmware controls the step motors, regulates the temperature and ultimately makes your printer work.")
  32. }
  33. UM.Label
  34. {
  35. width: parent.width
  36. text: catalog.i18nc("@label", "The firmware shipping with new printers works, but new versions tend to have more features and improvements.")
  37. }
  38. Row
  39. {
  40. anchors.horizontalCenter: parent.horizontalCenter
  41. width: childrenRect.width
  42. spacing: UM.Theme.getSize("default_margin").width
  43. property string firmwareName: Cura.MachineManager.activeMachine.getDefaultFirmwareName()
  44. Cura.SecondaryButton
  45. {
  46. id: autoUpgradeButton
  47. text: catalog.i18nc("@action:button", "Automatically upgrade Firmware")
  48. enabled: parent.firmwareName != "" && canUpdateFirmware
  49. onClicked:
  50. {
  51. updateProgressDialog.visible = true;
  52. activeOutputDevice.updateFirmware(parent.firmwareName);
  53. }
  54. }
  55. Cura.SecondaryButton
  56. {
  57. id: manualUpgradeButton
  58. text: catalog.i18nc("@action:button", "Upload custom Firmware")
  59. enabled: canUpdateFirmware
  60. onClicked:
  61. {
  62. customFirmwareDialog.open()
  63. }
  64. }
  65. }
  66. UM.Label
  67. {
  68. width: parent.width
  69. visible: !printerConnected && !updateProgressDialog.visible
  70. text: catalog.i18nc("@label", "Firmware can not be updated because there is no connection with the printer.")
  71. }
  72. Label
  73. {
  74. width: parent.width
  75. visible: printerConnected && !canUpdateFirmware
  76. text: catalog.i18nc("@label", "Firmware can not be updated because the connection with the printer does not support upgrading firmware.")
  77. }
  78. }
  79. FileDialog
  80. {
  81. id: customFirmwareDialog
  82. title: catalog.i18nc("@title:window", "Select custom firmware")
  83. nameFilters: "Firmware image files (*.hex)"
  84. onAccepted:
  85. {
  86. updateProgressDialog.visible = true;
  87. activeOutputDevice.updateFirmware(selectedFile);
  88. }
  89. }
  90. UM.Dialog
  91. {
  92. id: updateProgressDialog
  93. width: minimumWidth
  94. minimumWidth: 500 * screenScaleFactor
  95. height: minimumHeight
  96. minimumHeight: 100 * screenScaleFactor
  97. modality: Qt.ApplicationModal
  98. title: catalog.i18nc("@title:window","Firmware Update")
  99. Column
  100. {
  101. anchors.fill: parent
  102. UM.Label
  103. {
  104. anchors
  105. {
  106. left: parent.left
  107. right: parent.right
  108. }
  109. text: {
  110. if(manager.firmwareUpdater == null)
  111. {
  112. return "";
  113. }
  114. switch (manager.firmwareUpdater.firmwareUpdateState)
  115. {
  116. case 0:
  117. return ""; //Not doing anything (eg; idling)
  118. case 1:
  119. return catalog.i18nc("@label","Updating firmware.");
  120. case 2:
  121. return catalog.i18nc("@label","Firmware update completed.");
  122. case 3:
  123. return catalog.i18nc("@label","Firmware update failed due to an unknown error.");
  124. case 4:
  125. return catalog.i18nc("@label","Firmware update failed due to an communication error.");
  126. case 5:
  127. return catalog.i18nc("@label","Firmware update failed due to an input/output error.");
  128. case 6:
  129. return catalog.i18nc("@label","Firmware update failed due to missing firmware.");
  130. }
  131. }
  132. }
  133. UM.ProgressBar
  134. {
  135. id: prog
  136. value: (manager.firmwareUpdater != null) ? manager.firmwareUpdater.firmwareProgress / 100 : 0
  137. indeterminate:
  138. {
  139. if(manager.firmwareUpdater == null)
  140. {
  141. return false;
  142. }
  143. return manager.firmwareUpdater.firmwareProgress < 1 && manager.firmwareUpdater.firmwareProgress > 0;
  144. }
  145. anchors
  146. {
  147. left: parent.left
  148. right: parent.right
  149. }
  150. }
  151. }
  152. rightButtons: [
  153. Cura.SecondaryButton
  154. {
  155. text: catalog.i18nc("@action:button", "Close")
  156. enabled: manager.firmwareUpdater != null ? manager.firmwareUpdater.firmwareUpdateState != 1 : true
  157. onClicked: updateProgressDialog.visible = false
  158. }
  159. ]
  160. }
  161. }