forked from donovan6000/M33-Fio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·12507 lines (9272 loc) · 452 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding=utf-8
from __future__ import absolute_import
# Plugin details
__author__ = "donovan6000 <[email protected]>"
__license__ = "GNU General Public License http://www.gnu.org/licenses/gpl.txt"
__copyright__ = "Copyright (C) 2015-2017 Exploit Kings. All rights reserved."
# Imports
import octoprint.plugin
import octoprint.events
import octoprint.filemanager
import octoprint.printer
import octoprint.settings
import octoprint.slicing
import octoprint.util
import tempfile
import os
import time
import struct
import shutil
import sys
import math
import copy
import flask
import serial
import serial.tools.list_ports
import binascii
import re
import collections
import json
import imp
import glob
import ctypes
import _ctypes
import platform
import subprocess
import psutil
import socket
import threading
import yaml
import logging
import logging.handlers
import urllib
import urllib2
import requests
from .gcode import Gcode
from .vector import Vector
# Check if using Windows, Linux, or FreeBSD
if platform.uname()[0].startswith("Windows") or platform.uname()[0].startswith("Linux") or platform.uname()[0].startswith("FreeBSD") :
# Import webcam libraries
try :
import StringIO
from PIL import Image
import pygame.camera
except :
pass
# Check if using Linux or FreeBSD
if platform.uname()[0].startswith("Linux") or platform.uname()[0].startswith("FreeBSD") :
# Import DBus
try :
import dbus
except :
pass
# Otherwise check if using macOS
elif platform.uname()[0].startswith("Darwin") :
# Import macOS frameworks
try :
import CoreFoundation
import objc
from AppKit import *
from PyObjCTools import AppHelper
from Quartz import *
import QTKit
except :
pass
# Command class
class Command(object) :
# Constructor
def __init__(self, line, origin, skip) :
# Set values
self.line = line
self.origin = origin
self.skip = skip
# Get text
def gettext(text) :
# Return text
return text
# Plugin class
class M33FioPlugin(
octoprint.plugin.StartupPlugin,
octoprint.plugin.ShutdownPlugin,
octoprint.plugin.EventHandlerPlugin,
octoprint.plugin.TemplatePlugin,
octoprint.plugin.SettingsPlugin,
octoprint.plugin.SimpleApiPlugin,
octoprint.plugin.AssetPlugin,
octoprint.printer.PrinterCallback,
octoprint.plugin.BlueprintPlugin
) :
# Constructor
def __init__(self) :
# Set logger
self._m33fio_logger = logging.getLogger("octoprint.plugins.m33fio.debug")
# Initialize data members
self.originalWrite = None
self.originalRead = None
self.invalidPrinter = True
self.processingSlice = False
self.heatbedConnection = None
self.heatbedConnected = False
self.showHeatbedTemperature = False
self.settingHeatbedTemperature = False
self.eeprom = None
self.messageResponse = None
self.invalidBedCenter = False
self.invalidBedPlane = False
self.invalidBedOrientation = False
self.slicerChanges = None
self.sharedLibrary = None
self.lastCommandSent = None
self.lastResponseWasWait = False
self.allSerialPorts = []
self.currentSerialPort = None
self.providedFirmwares = {}
self.printerColor = "Black"
self.lastLineNumberSent = None
self.initializingPrinterConnection = False
self.startingMidPrintFilamentChange = False
self.showMidPrintFilamentChange = False
self.reconnectingToPrinter = False
self.performCancelPrintMovement = False
self.performFinishPrintMovement = False
self.currentFirmwareType = None
self.sharedLibraryIsUsable = False
self.cancelingPrint = False
self.slicerReminder = False
self.sleepReminder = False
self.webcamProcess = None
self.serialPortsList = []
self.serverData = None
self.skipPreprocessing = False
self.waitForDisconnect = False
# Rom decryption and encryption tables
self.romDecryptionTable = [0x26, 0xE2, 0x63, 0xAC, 0x27, 0xDE, 0x0D, 0x94, 0x79, 0xAB, 0x29, 0x87, 0x14, 0x95, 0x1F, 0xAE, 0x5F, 0xED, 0x47, 0xCE, 0x60, 0xBC, 0x11, 0xC3, 0x42, 0xE3, 0x03, 0x8E, 0x6D, 0x9D, 0x6E, 0xF2, 0x4D, 0x84, 0x25, 0xFF, 0x40, 0xC0, 0x44, 0xFD, 0x0F, 0x9B, 0x67, 0x90, 0x16, 0xB4, 0x07, 0x80, 0x39, 0xFB, 0x1D, 0xF9, 0x5A, 0xCA, 0x57, 0xA9, 0x5E, 0xEF, 0x6B, 0xB6, 0x2F, 0x83, 0x65, 0x8A, 0x13, 0xF5, 0x3C, 0xDC, 0x37, 0xD3, 0x0A, 0xF4, 0x77, 0xF3, 0x20, 0xE8, 0x73, 0xDB, 0x7B, 0xBB, 0x0B, 0xFA, 0x64, 0x8F, 0x08, 0xA3, 0x7D, 0xEB, 0x5C, 0x9C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 0xBD, 0xB1, 0xC9, 0x6B, 0xE5, 0x77, 0x35, 0x99, 0xBF, 0x69, 0x13, 0x89, 0x61, 0xDF, 0xA3, 0x45, 0x93, 0xC1, 0x7B, 0xC3, 0xF1, 0xD7, 0xEB, 0x4D, 0x43, 0x9B, 0x05, 0xA1, 0xFF, 0x97, 0x01, 0x19, 0xA7, 0x9D, 0x85, 0x7F, 0x4B, 0xEF, 0x73, 0x57, 0xA9, 0x11, 0x79, 0x39, 0xB7, 0xE7, 0x1F, 0x49, 0x47, 0x41, 0xD9, 0x65, 0x71, 0x33, 0x51, 0x31, 0xD5, 0x27, 0x7D, 0x23]
# EEPROM offsets
self.eepromOffsets = dict(
firmwareVersion = dict(
offset = 0x00,
bytes = 4
),
firmwareCrc = dict(
offset = 0x04,
bytes = 4
),
lastRecordedZValue = dict(
offset = 0x08,
bytes = 4
),
backlashX = dict(
offset = 0x0C,
bytes = 4
),
backlashY = dict(
offset = 0x10,
bytes = 4
),
bedOrientationBackRight = dict(
offset = 0x14,
bytes = 4
),
bedOrientationBackLeft = dict(
offset = 0x18,
bytes = 4
),
bedOrientationFrontLeft = dict(
offset = 0x1C,
bytes = 4
),
bedOrientationFrontRight = dict(
offset = 0x20,
bytes = 4
),
filamentColor = dict(
offset = 0x24,
bytes = 4
),
filamentTypeAndLocation = dict(
offset = 0x28,
bytes = 1
),
filamentTemperature = dict(
offset = 0x29,
bytes = 1
),
filamentAmount = dict(
offset = 0x2A,
bytes = 4
),
backlashExpansionXPlus = dict(
offset = 0x2E,
bytes = 4
),
backlashExpansionYLPlus = dict(
offset = 0x32,
bytes = 4
),
backlashExpansionYRPlus = dict(
offset = 0x36,
bytes = 4
),
backlashExpansionYRMinus = dict(
offset = 0x3A,
bytes = 4
),
backlashExpansionZ = dict(
offset = 0x3E,
bytes = 4
),
backlashExpansionE = dict(
offset = 0x42,
bytes = 4
),
bedOffsetBackLeft = dict(
offset = 0x46,
bytes = 4
),
bedOffsetBackRight = dict(
offset = 0x4A,
bytes = 4
),
bedOffsetFrontRight = dict(
offset = 0x4E,
bytes = 4
),
bedOffsetFrontLeft = dict(
offset = 0x52,
bytes = 4
),
bedHeightOffset = dict(
offset = 0x56,
bytes = 4
),
reserved = dict(
offset = 0x5A,
bytes = 4
),
backlashSpeed = dict(
offset = 0x5E,
bytes = 4
),
bedOrientationVersion = dict(
offset = 0x62,
bytes = 1
),
speedLimitX = dict(
offset = 0x66,
bytes = 4
),
speedLimitY = dict(
offset = 0x6A,
bytes = 4
),
speedLimitZ = dict(
offset = 0x6E,
bytes = 4
),
speedLimitEPositive = dict(
offset = 0x72,
bytes = 4
),
speedLimitENegative = dict(
offset = 0x76,
bytes = 4
),
filamentSize = dict(
offset = 0x82,
bytes = 1
),
filamentUid = dict(
offset = 0x83,
bytes = 4
),
bedOrientationFirstSample = dict(
offset = 0x106,
bytes = 4
),
heatbedTemperature = dict(
offset = 0x28B,
bytes = 1
),
skewX = dict(
offset = 0x28C,
bytes = 4
),
skewY = dict(
offset = 0x290,
bytes = 4
),
expandPrintableRegion = dict(
offset = 0x294,
bytes = 1
),
externalBedHeight = dict(
offset = 0x295,
bytes = 4
),
calibrateZ0Correction = dict(
offset = 0x299,
bytes = 4
),
xJerkSensitivity = dict(
offset = 0x29D,
bytes = 1
),
yJerkSensitivity = dict(
offset = 0x29E,
bytes = 1
),
lastRecordedXValue = dict(
offset = 0x29F,
bytes = 4
),
lastRecordedYValue = dict(
offset = 0x2A3,
bytes = 4
),
lastRecordedXDirection = dict(
offset = 0x2A7,
bytes = 1
),
lastRecordedYDirection = dict(
offset = 0x2A8,
bytes = 1
),
savedXState = dict(
offset = 0x2A9,
bytes = 1
),
savedYState = dict(
offset = 0x2AA,
bytes = 1
),
fanType = dict(
offset = 0x2AB,
bytes = 1
),
fanOffset = dict(
offset = 0x2AC,
bytes = 1
),
fanScale = dict(
offset = 0x2AD,
bytes = 4
),
heaterCalibrationMode = dict(
offset = 0x2B1,
bytes = 1
),
xMotorCurrent = dict(
offset = 0x2B2,
bytes = 2
),
yMotorCurrent = dict(
offset = 0x2B4,
bytes = 2
),
zMotorCurrent = dict(
offset = 0x2B6,
bytes = 2
),
hardwareStatus = dict(
offset = 0x2B8,
bytes = 2
),
heaterTemperatureMeasurementB = dict(
offset = 0x2BA,
bytes = 4
),
hoursCounter = dict(
offset = 0x2C0,
bytes = 4
),
xMotorStepsPerMm = dict(
offset = 0x2D6,
bytes = 4
),
yMotorStepsPerMm = dict(
offset = 0x2DA,
bytes = 4
),
zMotorStepsPerMm = dict(
offset = 0x2DE,
bytes = 4
),
eMotorStepsPerMm = dict(
offset = 0x2E2,
bytes = 4
),
savedZState = dict(
offset = 0x2E6,
bytes = 2
),
eMotorCurrent = dict(
offset = 0x2E8,
bytes = 2
),
heaterResistanceM = dict(
offset = 0x2EA,
bytes = 4
),
serialNumber = dict(
offset = 0x2EF,
bytes = 16
)
)
# Bed dimensions
self.bedLowMaxX = 106.0
self.bedLowMinX = -2.0
self.bedLowMaxY = 105.0
self.bedLowMinY = -2.0
self.bedLowMaxZ = 5.0
self.bedLowMinZ = 0.0
self.bedMediumMaxX = 106.0
self.bedMediumMinX = -2.0
self.bedMediumMaxY = 105.0
self.bedMediumMinY = -9.0
self.bedMediumMaxZ = 73.5
self.bedMediumMinZ = self.bedLowMaxZ
self.bedHighMaxX = 97.0
self.bedHighMinX = 7.0
self.bedHighMaxY = 85.0
self.bedHighMinY = 9.0
self.bedHighMaxZ = 112.0
self.bedHighMinZ = self.bedMediumMaxZ
self.bedWidth = 121.0
self.bedDepth = 121.0
self.bedCenterOffsetX = 8.5005
self.bedCenterOffsetY = 2.0005
# Chip details
self.chipName = "ATxmega32C4"
self.chipPageSize = 0x80
self.chipNumberOfPages = 0x80
self.chipTotalMemory = self.chipNumberOfPages * self.chipPageSize * 2
# Wave bonding pre-processor settings
self.wavePeriod = 5.0
self.wavePeriodQuarter = self.wavePeriod / 4.0
self.waveSize = 0.15
# Bed compensation pre-processor settings
self.segmentLength = 2.0
# Reset print and pre-processor settings
self.resetPreprocessorSettings()
# Reset print settings
def resetPrintSettings(self) :
# General settings
self.printingTestBorder = False
self.printingBacklashCalibration = False
self.sentCommands = {}
self.resetLineNumberCommandSent = False
self.numberWrapCounter = 0
# Reset pre-processor settings
def resetPreprocessorSettings(self) :
# General settings
self.readyToPrint = False
self.currentE = 0
self.currentF = None
self.currentZ = 0
self.layerDetectionRelativeMode = False
self.printedLayers = []
self.onNewPrintedLayer = False
self.tackPointAngle = 0.0
self.tackPointTime = 0.0
self.temperatureStabalizationDelay = 0
self.fanSpeed = 0
self.firstLayerTemperatureChange = 0
# Print settings
self.resetPrintSettings()
# Mid-print filament change pre-processor settings
self.midPrintFilamentChangeLayerCounter = 0
self.midPrintFilamentChangeLayers = []
# Center model pre-processor settings
self.displacementX = 0
self.displacementY = 0
# Preparation pre-processor settings
self.addedIntro = False
self.addedOutro = False
self.preparationLayerCounter = 0
# Wave bonding pre-processor settings
self.waveStep = 0
self.waveBondingRelativeMode = False
self.waveBondingLayerCounter = 0
self.waveBondingChangesPlane = False
self.waveBondingPositionRelativeX = 0
self.waveBondingPositionRelativeY = 0
self.waveBondingPositionRelativeZ = 0
self.waveBondingPositionRelativeE = 0
self.waveBondingPreviousGcode = Gcode()
self.waveBondingRefrenceGcode = Gcode()
self.waveBondingTackPoint = Gcode()
self.waveBondingExtraGcode = Gcode()
# Thermal bonding pre-processor settings
self.thermalBondingRelativeMode = False
self.thermalBondingLayerCounter = 0
self.thermalBondingPreviousGcode = Gcode()
self.thermalBondingRefrenceGcode = Gcode()
self.thermalBondingTackPoint = Gcode()
# Bed compensation pre-processor settings
self.bedCompensationRelativeMode = False
self.bedCompensationChangesPlane = False
self.bedCompensationPositionAbsoluteX = 0
self.bedCompensationPositionAbsoluteY = 0
self.bedCompensationPositionRelativeX = 0
self.bedCompensationPositionRelativeY = 0
self.bedCompensationPositionRelativeZ = 0
self.bedCompensationPositionRelativeE = 0
self.bedCompensationExtraGcode = Gcode()
# Backlash compensation pre-processor settings
self.backlashCompensationRelativeMode = False
self.valueF = "1000"
self.previousDirectionX = "Neither"
self.previousDirectionY = "Neither"
self.compensationX = 0
self.compensationY = 0
self.backlashPositionRelativeX = 0
self.backlashPositionRelativeY = 0
self.backlashPositionRelativeZ = 0
self.backlashPositionRelativeE = 0
self.backlashCompensationExtraGcode = Gcode()
# Skew compensation pre-processor settings
self.skewCompensationRelativeMode = False
self.skewCompensationPositionAbsoluteZ = 0
self.skewCompensationPositionRelativeZ = 0
# Get cpu hardware
def getCpuHardware(self) :
# Check if CPU info exists
if os.path.isfile("/proc/cpuinfo") :
# Read in CPU info
for line in open("/proc/cpuinfo") :
# Check if line contains hardware information
if line.startswith("Hardware") and ":" in line :
# Return CPU hardware
return line[line.index(":") + 2 : -1]
# Return empty string
return ""
# Get printer type
def getPrinterType(self, currentPort) :
# Go through all connected serial ports
for port in list(serial.tools.list_ports.comports()) :
# Check if port is specified
if currentPort == port[0] :
# Check if port contains the correct VID and PID to be a Micro 3D printer
if re.match("^USB VID:PID=0?3EB:2404(?: |$)", port[2], re.IGNORECASE) is not None :
# Return printer type
return "Micro 3D"
# Otherwise check if port contains the correct VID and PID to be an M3D Pro printer
elif re.match("^USB VID:PID=0?483:A21E(?: |$)", port[2], re.IGNORECASE) is not None :
# Return printer type
return "M3D Pro"
# Otherwise check if port contains the correct VID and PID to be a Micro+ printer
elif re.match("^USB VID:PID=0?483:A21F(?: |$)", port[2], re.IGNORECASE) is not None :
# Return printer type
return "Micro+"
# Break
break
# Return none
return None
# Save ports
def savePorts(self, currentPort) :
# Clear saved serial ports
self.allSerialPorts = []
# Go through all connected serial ports
for port in list(serial.tools.list_ports.comports()) :
# Check if port contains the correct VID and PID to be a Micro 3D, M3D Pro, or Micro+ printer
if re.match("^USB VID:PID=0?3EB:2404(?: |$)", port[2], re.IGNORECASE) is not None or re.match("^USB VID:PID=0?483:A21E(?: |$)", port[2], re.IGNORECASE) is not None or re.match("^USB VID:PID=0?483:A21F(?: |$)", port[2], re.IGNORECASE) is not None :
# Save serial port
self.allSerialPorts += [port[0]]
# Save current serial port
self.currentSerialPort = currentPort
# Get port
def getPort(self) :
# Initialize variables
searchForCurrent = True
serialPorts = list(serial.tools.list_ports.comports())
firstUninitializedPrinter = None
firstInitializedPrinter = None
# Loop forever
while True :
# Go through all connected serial ports
for port in serialPorts :
# Check if searching for current port or searching for a new port
if (searchForCurrent and (self.currentSerialPort is None or port[0] == self.currentSerialPort)) or (not searchForCurrent and port[0] not in self.allSerialPorts) :
# Check if port contains the correct VID and PID to be a Micro 3D, M3D Pro, or Micro+ printer
if re.match("^USB VID:PID=0?3EB:2404(?: |$)", port[2], re.IGNORECASE) is not None or re.match("^USB VID:PID=0?483:A21E(?: |$)", port[2], re.IGNORECASE) is not None or re.match("^USB VID:PID=0?483:A21F(?: |$)", port[2], re.IGNORECASE) is not None :
# Check if first time connecting
if searchForCurrent and self.currentSerialPort is None :
# Check if printer is initialized
if " SNR=" in port[2].upper() :
# Save port
firstInitializedPrinter = port[0]
# Otherwise
else :
# Save port
firstUninitializedPrinter = port[0]
# Otherwise
else :
# Return port
return port[0]
# Check if current port has changed
if searchForCurrent :
# Check if an uninitialized printer was found
if firstUninitializedPrinter is not None :
# Return port
return firstUninitializedPrinter
# Check if an initialized printer was found
if firstInitializedPrinter is not None :
# Return port
return firstInitializedPrinter
# Clear search for current
searchForCurrent = False
# Otherwise
else :
# Break
break
# Return none
return None
# Get heatbed port
def getHeatbedPort(self) :
# Check if available serial ports have changed
newestSerialPortsList = list(serial.tools.list_ports.comports())
if cmp(self.serialPortsList, newestSerialPortsList) != 0 :
# Update all serial ports
self.serialPortsList = newestSerialPortsList
# Check if not currently connected to a printer
if self._printer.is_closed_or_error() :
# Update serial ports
self._plugin_manager.send_plugin_message(self._identifier, dict(value = "Update Serial Ports"))
# Check if using a Micro 3D printer
if not self._settings.get_boolean(["NotUsingAMicro3DPrinter"]) :
# Go through all connected serial ports
for port in newestSerialPortsList :
# Check if port contains the correct VID and PID to be a Micro 3D heatbed
if re.match("^USB VID:PID=1A86:7523(?: |$)", port[2], re.IGNORECASE) is not None :
# Return serial port
return port[0]
# Return none
return None
# Keep printer active
def keepPrinterActive(self) :
# Loop forever
while True :
# Check if paused and using a Micro 3D printer
if self._printer.is_paused() and not self._settings.get_boolean(["NotUsingAMicro3DPrinter"]) :
# Send command to keep printer from being inactive for too long
self._printer.commands("G4")
# Delay 5 minutes
time.sleep(5 * 60)
# Monitor heatbed
def monitorHeatbed(self) :
# Initialize variables
previousHeatbedPort = None
# Loop forever
while True :
# Get heatbed port
heatbedPort = self.getHeatbedPort()
# Check if a heatbed has been disconnected
if self.heatbedConnected and heatbedPort is None :
# Clear heatbed connected
self.heatbedConnected = False
# Close heatbed connection
self.heatbedConnection.close()
self.heatbedConnection = None
# Set heated bed to false in printer profile
if self._printer_profile_manager.exists("micro_3d") :
printerProfile = self._printer_profile_manager.get("micro_3d")
printerProfile["heatedBed"] = False
self._printer_profile_manager.save(printerProfile, True, not self._settings.get_boolean(["NotUsingAMicro3DPrinter"]))
# Send message
self._plugin_manager.send_plugin_message(self._identifier, dict(value = "Heatbed Not Detected"))
# Create message
self._plugin_manager.send_plugin_message(self._identifier, dict(value = "Create message", type = "notice", title = gettext("Heatbed removed"), text = gettext("Heatbed has been disconnected")))
# Otherwise check if a heatbed has been connected
elif not self.heatbedConnected and heatbedPort is not None :
# Connect to heatbed
error = False
try :
self.heatbedConnection = serial.Serial(heatbedPort, 115200, timeout = 5)
# check if using macOS, Linux, or FreeBSD and the user lacks read/write access to the heatbed
if (platform.uname()[0].startswith("Darwin") or platform.uname()[0].startswith("Linux") or platform.uname()[0].startswith("FreeBSD")) and not os.access(str(heatbedPort), os.R_OK | os.W_OK) :
# Set error
error = True
# Otherwise
else :
# Set connection timeout
if int(serial.VERSION.split(".", 1)[0]) < 3 :
self.heatbedConnection.writeTimeout = 1
else :
self.heatbedConnection.write_timeout = 1
except :
error = True
# Check if no errors occured
if not error :
# Loop forever
while True :
# Wait for heatbed to initialize
try :
if self.heatbedConnection.read() == "\x1B" :
self.heatbedConnection.timeout = 1
break
except :
error = True
break
# Check if no errors occured
if not error :
# Put heatbed into temperature mode
try :
if int(serial.VERSION.split(".", 1)[0]) < 3 :
self.heatbedConnection.flushInput()
self.heatbedConnection.flushOutput()
else :
self.heatbedConnection.reset_input_buffer()
self.heatbedConnection.reset_output_buffer()
self.heatbedConnection.write("i\r")
time.sleep(0.5)
if int(serial.VERSION.split(".", 1)[0]) < 3 :
self.heatbedConnection.flushInput()
self.heatbedConnection.flushOutput()
else :
self.heatbedConnection.reset_input_buffer()
self.heatbedConnection.reset_output_buffer()
except :
error = True
# Check if no errors occured
if not error :
# Set heated bed to true in printer profile
if self._printer_profile_manager.exists("micro_3d") :
printerProfile = self._printer_profile_manager.get("micro_3d")
printerProfile["heatedBed"] = True
self._printer_profile_manager.save(printerProfile, True, not self._settings.get_boolean(["NotUsingAMicro3DPrinter"]))
# Set heatbed connected
self.heatbedConnected = True
# Send message
self._plugin_manager.send_plugin_message(self._identifier, dict(value = "Heatbed Detected"))
# Create message
self._plugin_manager.send_plugin_message(self._identifier, dict(value = "Create message", type = "success", title = gettext("Heatbed detected"), text = gettext("Heatbed has been connected")))
# Check if an error has occured
if error :
# Check if connection to heatbed was established
if self.heatbedConnection is not None :
# Close connection
self.heatbedConnection.close()
self.heatbedConnection = None
# check if an error occured and it hasn't been show yet
if previousHeatbedPort != heatbedPort :
# Create message
self._plugin_manager.send_plugin_message(self._identifier, dict(value = "Create message", type = "error", title = gettext("Heatbed error"), text = gettext("Failed to connect to heatbed")))
# Set previous heatbed port
previousHeatbedPort = heatbedPort
# Delay
time.sleep(0.5)
# Save printer profile
def savePrinterProfile(self) :
# Create and overwrite Micro 3D printer profile
printerProfile = dict(
id = "micro_3d",
name = "Micro 3D",
model = "Micro 3D",
color = "default",
volume = dict(
width = self.bedLowMaxX - self.bedLowMinX,
depth = self.bedLowMaxY - self.bedLowMinY,
height = self.bedHighMaxZ - self.bedLowMinZ,
formFactor = "rectangular",
origin = "lowerleft",
custom_box = False
),
heatedBed = False,
extruder = dict(
count = 1,
offsets = [
(0, 0)
],
nozzleDiameter = 0.35,
sharedNozzle = False
),
axes = dict(
x = dict(
speed = 4800,
inverted = False
),
y = dict(
speed = 4800,
inverted = False
),
z = dict(
speed = 90,
inverted = False
),
e = dict(
speed = 600,
inverted = False
)
)
)
if self.heatbedConnected :
printerProfile["heatedBed"] = True
printerProfile = octoprint.util.dict_merge(self._printer_profile_manager.get_default(), printerProfile)
self._printer_profile_manager.save(printerProfile, True, not self._settings.get_boolean(["NotUsingAMicro3DPrinter"]))
# Check if using a Micro 3D printer
if not self._settings.get_boolean(["NotUsingAMicro3DPrinter"]) :
# Select Micro 3D printer profile
self._printer_profile_manager.select("micro_3d")
# Add channel
def addChannel(self) :
# Check if M33 Fio channel doesn't exist
if octoprint.settings.settings().get(["server", "firstRun"]) is not None and not octoprint.settings.settings().get(["server", "firstRun"]) and octoprint.settings.settings().get(["plugins", "announcements", "channels", "_m33fio"]) is None :
# Add M33 Fio channel to announcements
octoprint.settings.settings().set(["plugins", "announcements", "channels", "_m33fio"], dict(
name = "M33 Fio Announcements and News",
description = "Announcements and news related to M33 Fio.",
priority = 2,
type = "rss",
url = "https://exploitkings.com/scripts/M33 Fio.xml"), True)
# Enable M33 Fio channel
enabledChannels = octoprint.settings.settings().get(["plugins", "announcements", "enabled_channels"])
if enabledChannels is None :
enabledChannels = []
enabledChannels += ['_m33fio']
octoprint.settings.settings().set(["plugins", "announcements", "enabled_channels"], enabledChannels, True)
# On startup
def on_startup(self, host, port) :
# Setup custom logger
m33fio_logging_handler = logging.handlers.RotatingFileHandler(self._settings.get_plugin_logfile_path(postfix = "debug"), maxBytes = 500 * 1024 * 1024)
m33fio_logging_handler.setFormatter(logging.Formatter("%(asctime)s %(message)s"))
m33fio_logging_handler.setLevel(logging.DEBUG)
self._m33fio_logger.addHandler(m33fio_logging_handler)
self._m33fio_logger.setLevel(logging.DEBUG if self._settings.get_boolean(["UseDebugLogging"]) else logging.CRITICAL)
self._m33fio_logger.propagate = False
# Add channel
self.addChannel()
# Connected to internet
def connectedToInternet(self) :
# Create request
request = urllib2.Request("http://exploitkings.com")