Skip to content

Instantly share code, notes, and snippets.

@ukscone ukscone/mixjack.py
Created Mar 3, 2020

Embed
What would you like to do?
hacky mixjuice/micjack "emulator" for raspberry pi/pc
import requests
import serial
from functools import partial
from time import sleep
ser = serial.Serial('/dev/ttyUSB0',115200)
def version():
return "'MixJack (Python) Version 0.0.1\n"
def get(URL):
prog="Not Found"
if(URL[0:6]=="http://"):
pass
else:
URL="http://"+URL
r = requests.get(URL)
if(r.status_code==200):
prog=r.text
return prog
def gets(URL):
prog="Not Found"
if(URL[0:7]=="https://"):
pass
else:
URL="https://"+URL
r = requests.get(URL)
if(r.status_code==200):
prog=r.text
return prog
def load(program):
file = open(program,mode='r')
all_of_it = file.read()
file.close()
return all_of_it
def switch(command,arg):
switcher = {
'VER': version,
'GET': partial(get, arg),
'GETS': partial(gets,arg),
'LOAD': partial(load,arg),
}
func = switcher.get(command, lambda: "'not a command\n")
return func()
print("MixJack (Python) version 0.0.1")
while True:
command_string = ser.read_until().decode('utf-8')
print("command string:"+command_string)
if(command_string[0:2].upper()=="MJ"):
cmd=command_string.split()
if(len(cmd)==2):
result=(switch(cmd[1].upper(),None))
else:
result=(switch(cmd[1].upper(),cmd[2]))
print(result)
for x in range(len(result)):
ser.write(result[x].encode())
sleep(0.02)
ser.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.