Created
March 3, 2020 22:44
-
-
Save ukscone/790013d13d38f52c97c4dbb053508d4c to your computer and use it in GitHub Desktop.
hacky mixjuice/micjack "emulator" for raspberry pi/pc
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
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