Created
December 28, 2020 06:55
-
-
Save jeffeb3/36b033110bde35162a1575c8c0ae1400 to your computer and use it in GitHub Desktop.
TFT Marlin Simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import serial | |
import time | |
class Screen(object): | |
def __init__(self, port, speed): | |
self.serial = serial.Serial(port, speed, timeout=0.05) | |
print("Opened on port: {}".format(self.serial.name)) | |
self.x = 10.0 | |
self.y = 100.0 | |
self.z = 1.0 | |
self.send(b'ok') | |
def send(self, message): | |
if message != b'ok' and not message.startswith(b'T:24.62') and not message.startswith(b'X:'): | |
print(" "*60 + message.decode("utf-8")) | |
self.serial.write(message + b'\r\n') | |
def parseLine(self, message): | |
#if b'M105' not in message and b'M114' not in message: | |
print(message.decode("utf-8").strip()) | |
if b'M105' in message: | |
screen.send(b'T:24.62 /0.00 B:24.75 /0.00 @:0 B@:0') | |
elif b'M115' in message: | |
screen.send(b'FIRMWARE_NAME:Marlin 2.0.5.3 (GitHub, jeffeb3) SOURCE_CODE_URL:https://github.com/MarlinFirmware/Marlin PROTOCOL_VERSION:1.0 MACHINE_TYPE:3D Printer EXTRUDER_COUNT:1 UUID:cede2a2f-41a2-4748-9b12-c55c62f367ff') | |
screen.send(b'Cap:SERIAL_XON_XOFF:0') | |
screen.send(b'Cap:BINARY_FILE_TRANSFER:0') | |
screen.send(b'Cap:EEPROM:1') | |
screen.send(b'Cap:VOLUMETRIC:1') | |
screen.send(b'Cap:AUTOREPORT_TEMP:1') | |
screen.send(b'Cap:PROGRESS:0') | |
screen.send(b'Cap:PRINT_JOB:1') | |
screen.send(b'Cap:AUTOLEVEL:1') | |
screen.send(b'Cap:Z_PROBE:1') | |
screen.send(b'Cap:LEVELING_DATA:1') | |
screen.send(b'Cap:BUILD_PERCENT:0') | |
screen.send(b'Cap:SOFTWARE_POWER:0') | |
screen.send(b'Cap:TOGGLE_LIGHTS:0') | |
screen.send(b'Cap:CASE_LIGHT_BRIGHTNESS:0') | |
screen.send(b'Cap:EMERGENCY_PARSER:0') | |
screen.send(b'Cap:PROMPT_SUPPORT:0') | |
screen.send(b'Cap:AUTOREPORT_SD_STATUS:0') | |
screen.send(b'Cap:THERMAL_PROTECTION:1') | |
screen.send(b'Cap:MOTION_MODES:0') | |
screen.send(b'Cap:CHAMBER_TEMPERATURE:0') | |
elif b'M119' in message: | |
screen.send(b'Reporting endstop status') | |
screen.send(b'x_min: open') | |
screen.send(b'x2_min: open') | |
screen.send(b'y_min: open') | |
screen.send(b'y2_min: open') | |
screen.send(b'z_min: open') | |
elif b'M503 S0' in message: | |
screen.send(b'G21 ; Units in mm (mm)') | |
screen.send(b'') | |
screen.send(b'M200 D1.75') | |
screen.send(b'M200 D0') | |
screen.send(b'M92 X80.00 Y80.00 Z400.00 E400.00') | |
screen.send(b'M203 X200.00 Y200.00 Z10.00 E50.00') | |
screen.send(b'M201 X3000.00 Y3000.00 Z100.00 E20000.00') | |
screen.send(b'M204 P4500.00 R3000.00 T9000.00') | |
screen.send(b'M205 B20000.00 S0.00 T0.00 X10.00 Y10.00 Z0.40 E5.00') | |
screen.send(b'M206 X0.00 Y0.00 Z0.00') | |
screen.send(b'M420 S1 Z0.00') | |
screen.send(b'M301 P26.15 I2.12 D80.66') | |
screen.send(b'M304 P38.35 I2.40 D408.81') | |
screen.send(b'M851 X30.00 Y0.00 Z-0.52') | |
screen.send(b'M906 X900 Y900 Z900') | |
screen.send(b'M906 T0 E900') | |
screen.send(b'') | |
screen.send(b'M913 X100 Y100 Z20') | |
screen.send(b'M913 T0 E30') | |
screen.send(b'') | |
screen.send(b'M914 X50 Y50') | |
screen.send(b'M569 S1 X Y') | |
screen.send(b'M900 K0.50') | |
elif b'M92' in message: | |
screen.send(b'echo: M92 X80.00 Y80.00 Z400.00 E400.00') | |
elif b'M420 S1' in message: | |
#screen.send(b"echo:Jeffeb3's mad world of TFT sim") | |
screen.send(b"Jeffeb3's mad world of TFT sim") | |
elif b'M114' in message: | |
screen.send('X:{} Y:{} Z:{}'.format(self.x, self.y, self.z).encode('utf-8')) | |
elif message.startswith(b'G1 '): | |
fields = message.split() | |
for field in fields: | |
if field.startswith(b'X'): | |
distance = float(field[1:]) | |
self.x += distance | |
if field.startswith(b'Y'): | |
distance = float(field[1:]) | |
self.y += distance | |
if field.startswith(b'Z'): | |
distance = float(field[1:]) | |
self.z += distance | |
elif message.startswith(b'G4 '): | |
fields = message.split() | |
for field in fields: | |
if field.startswith(b'S'): | |
seconds = float(field[1:]) | |
print('waiting {} seconds'.format(seconds)) | |
time.sleep(seconds) | |
break | |
screen.send(b'ok') | |
screen = Screen("/dev/ttyUSB0", 250000) | |
while True: | |
recv = screen.serial.readline() | |
if (recv): | |
screen.parseLine(recv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure where else to add this info.
I also added,
pip install “pyserial”
Windows users change,
"/dev/ttyUSB0"
to whatever the active COM port is eg"COM2"
Works great!!!!