Dateien nach "devkit" hochladen
parent
d2eb94b781
commit
f9b5051b6c
|
@ -0,0 +1,218 @@
|
|||
import serial.tools.list_ports
|
||||
import serial
|
||||
import sys
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
from tkinter import messagebox
|
||||
import easygui
|
||||
import select
|
||||
import threading
|
||||
import os
|
||||
import time
|
||||
import modules
|
||||
import ast
|
||||
|
||||
print("ports: ")
|
||||
for info in serial.tools.list_ports.comports():
|
||||
print(info)
|
||||
port = input("enter port (Normal: /dev/ttyACM0): ")
|
||||
|
||||
print("listening...")
|
||||
|
||||
while True:
|
||||
try:
|
||||
s = serial.Serial(port, 115200)
|
||||
break
|
||||
except Exception as e:
|
||||
#print(e)
|
||||
pass
|
||||
|
||||
print("connected.")
|
||||
|
||||
returns = []
|
||||
|
||||
def getreturn():
|
||||
global s
|
||||
global logincmd
|
||||
global returns
|
||||
while True:
|
||||
line = s.readline()
|
||||
if line:
|
||||
line = line.decode()
|
||||
returns.append(line)
|
||||
logincmd(line, "")
|
||||
|
||||
def WURI(length):
|
||||
while len(returns) < length:
|
||||
pass
|
||||
time.sleep(0.1)
|
||||
|
||||
def WUMF(marker):
|
||||
while not returns[-1].startswith(marker):
|
||||
pass
|
||||
|
||||
threading.Thread(target=getreturn).start()
|
||||
|
||||
cmd = tk.Tk()
|
||||
cmd.title("cmd")
|
||||
allowcmd = True
|
||||
cmdtext = tk.Text(cmd, bg="black", fg="white")
|
||||
cmdtext.tag_config('CMDOUT', background="black", foreground="light green")
|
||||
cmdtext.tag_config('error', background="red", foreground="light green")
|
||||
cmdtext.tag_config('warning', background="yellow", foreground="light green")
|
||||
cmdtext.config(state="disabled")
|
||||
commandentry = tk.Entry(cmd, bg="black", fg="light green")
|
||||
execcmdbut = tk.Button(cmd, command=lambda: execcmd(commandentry, globals(), locals()), text="execute")
|
||||
cmdtext.grid()
|
||||
commandentry.grid()
|
||||
execcmdbut.grid()
|
||||
|
||||
def logincmd(text, end="\n"):
|
||||
text = str(text)
|
||||
cmdtext.config(state="normal")
|
||||
cmdtext.insert(tk.END, "--->"+text+end)
|
||||
cmdtext.see("end")
|
||||
cmdtext.config(state="disabled")
|
||||
cmd.update()
|
||||
|
||||
def execcmdlog(text):
|
||||
text = str(text)
|
||||
cmdtext.config(state="normal")
|
||||
cmdtext.insert(tk.END, "<---"+text+"\n", "CMDOUT")
|
||||
cmdtext.see("end")
|
||||
cmdtext.config(state="disabled")
|
||||
cmd.update()
|
||||
|
||||
def error(text):
|
||||
text = str(text)
|
||||
cmdtext.config(state="normal")
|
||||
cmdtext.insert(tk.END, ">"+text+"\n", "error")
|
||||
cmdtext.see("end")
|
||||
cmdtext.config(state="disabled")
|
||||
cmd.update()
|
||||
|
||||
def warning(text):
|
||||
text = str(text)
|
||||
cmdtext.config(state="normal")
|
||||
cmdtext.insert(tk.END, ">"+text+"\n", "warning")
|
||||
cmdtext.see("end")
|
||||
cmdtext.config(state="disabled")
|
||||
cmd.update()
|
||||
|
||||
def execcmd(command, global2, local):
|
||||
global allowcmd
|
||||
global commandentry
|
||||
if allowcmd == True:
|
||||
command = command.get()
|
||||
sendcommand(command)
|
||||
commandentry.delete(0, tk.END)
|
||||
else:
|
||||
error("CMD command cannot be executed because allowcmd is False")
|
||||
|
||||
def sendcommand(command):
|
||||
global s
|
||||
execcmdlog(command)
|
||||
time.sleep(0.3)
|
||||
command = command.replace("\n", "<NL>")
|
||||
s.write(str(command).encode())
|
||||
s.write(b"\r\n")
|
||||
s.flush()
|
||||
|
||||
def setcmd(state):
|
||||
global allowcmd
|
||||
warning("CMD STATE set to {}".format(state))
|
||||
allowcmd = state
|
||||
|
||||
def recursiveupload(target, target2):
|
||||
sendcommand("import os")
|
||||
sendcommand("os.mkdir('{}')".format(target2))
|
||||
for i in os.listdir(target):
|
||||
if os.path.isdir(target+"/"+i):
|
||||
recursiveupload(target+"/"+i, target2+"/"+i)
|
||||
else:
|
||||
file = open(target+"/"+i, 'r')
|
||||
file = file.read()
|
||||
sendcommand(modules.WF.check().format(target2+"/"+i, file))
|
||||
|
||||
def uploadgame(game):
|
||||
if not os.path.exists(game+"/"+"info.txt") and not os.path.exists(game+"/"+"main.py"):
|
||||
messagebox.showerror("ERROR", "Invalid game dir!")
|
||||
return
|
||||
command = modules.exists.check().format(os.path.basename(game))
|
||||
temp = len(returns)
|
||||
sendcommand(command)
|
||||
WURI(temp+1)
|
||||
if returns[-1] == "1\r\n":
|
||||
if not messagebox.askyesno("wirklich?", "Spiel existiert bereits auf der JUFSBOX, überschreiben?"):
|
||||
return
|
||||
elif returns[-1] != "0\r\n":
|
||||
messagebox.showerror("ERROR", "Unexpected answer {}, see CMD for more!".format(repr(returns[-1])))
|
||||
recursiveupload(game, "games/"+os.path.basename(game))
|
||||
|
||||
def rungame(name):
|
||||
sendcommand(modules.rungame.check().format(name))
|
||||
|
||||
def rungamesel():
|
||||
temp = len(returns)
|
||||
sendcommand(modules.initcom.check())
|
||||
WURI(temp+1)
|
||||
sendcommand(modules.getgames.check())
|
||||
WUMF("{")
|
||||
games = ast.literal_eval(returns[-1])
|
||||
temp = []
|
||||
for i in games:
|
||||
temp.append(i)
|
||||
selected = easygui.choicebox("Select game to start.", "selection", temp)
|
||||
rungame(selected)
|
||||
|
||||
def uploadgamesel():
|
||||
game = filedialog.askdirectory()
|
||||
uploadgame(game)
|
||||
|
||||
def RUsel():
|
||||
game = filedialog.askdirectory()
|
||||
uploadgame(game)
|
||||
temp = len(returns)
|
||||
sendcommand(modules.initcom.check())
|
||||
WURI(temp+1)
|
||||
rungame(os.path.basename(game))
|
||||
|
||||
s.write(b"BLMBOOT\n")
|
||||
|
||||
menubar = tk.Menu()
|
||||
tools_menu = tk.Menu(menubar, tearoff=False)
|
||||
tools_menu.add_command(
|
||||
label="Upload game",
|
||||
accelerator="Ctrl+U",
|
||||
command=lambda: threading.Thread(target=uploadgamesel).start()
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="Run game",
|
||||
accelerator="Ctrl+R",
|
||||
command=lambda: threading.Thread(target=rungamesel).start()
|
||||
)
|
||||
tools_menu.add_command(
|
||||
label="Upload and Run game",
|
||||
accelerator="Ctrl+T",
|
||||
command=lambda: threading.Thread(target=RUsel).start()
|
||||
)
|
||||
control = tk.Menu(menubar, tearoff=False)
|
||||
control.add_command(
|
||||
label="Interrupt",
|
||||
accelerator="Ctrl+I",
|
||||
command=lambda: sendcommand("\x03")
|
||||
)
|
||||
|
||||
menubar.add_cascade(menu=tools_menu, label="Tools")
|
||||
menubar.add_cascade(menu=control, label="Controls")
|
||||
cmd.config(menu=menubar)
|
||||
cmd.bind_all("<Control-R>", lambda Event=None: threading.Thread(target=rungamesel).start())
|
||||
cmd.bind_all("<Control-r>", lambda Event=None: threading.Thread(target=rungamesel).start())
|
||||
cmd.bind_all("<Control-U>", lambda Event=None: threading.Thread(target=uploadgamesel).start())
|
||||
cmd.bind_all("<Control-u>", lambda Event=None: threading.Thread(target=uploadgamesel).start())
|
||||
cmd.bind_all("<Control-T>", lambda Event=None: threading.Thread(target=RUsel).start())
|
||||
cmd.bind_all("<Control-t>", lambda Event=None: threading.Thread(target=RUsel).start())
|
||||
cmd.bind_all("<Control-I>", lambda Event=None: sendcommand("\x03"))
|
||||
cmd.bind_all("<Control-i>", lambda Event=None: sendcommand("\x03"))
|
||||
|
||||
cmd.mainloop()
|
Loading…
Reference in New Issue