update
This commit is contained in:
@@ -15,9 +15,10 @@ class ComportService:
|
|||||||
if special_port != "":
|
if special_port != "":
|
||||||
self.__working = special_port
|
self.__working = special_port
|
||||||
else:
|
else:
|
||||||
|
print(serial.tools.list_ports.comports())
|
||||||
while self.__working == []:
|
while self.__working == []:
|
||||||
self.__com_name = serial.tools.list_ports.comports()[self.__pos]
|
self.__com_name = serial.tools.list_ports.comports()[self.__pos]
|
||||||
if "USB-Serial Controller" or "Prolific USB-Serial Controller" in self.__com_name:
|
if "NXP ARM mbed" in self.__com_name:
|
||||||
self.__working = self.__comport.pop(self.__pos)
|
self.__working = self.__comport.pop(self.__pos)
|
||||||
else:
|
else:
|
||||||
self.__pos += 1
|
self.__pos += 1
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Com:
|
|||||||
self.str_input = ""
|
self.str_input = ""
|
||||||
self.str_get_input = ""
|
self.str_get_input = ""
|
||||||
self.xs = ""
|
self.xs = ""
|
||||||
self.__comport = '/dev/ttyUSB0'
|
self.__comport = '/dev/ttyACM0'
|
||||||
|
|
||||||
def connect(self, baudrate, special_port):
|
def connect(self, baudrate, special_port):
|
||||||
try:
|
try:
|
||||||
@@ -47,7 +47,7 @@ class Com:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def decode_int(self, value):
|
def decode_int(self, value):
|
||||||
self.i = int(value, base = 16)
|
self.i = int(value, base=16)
|
||||||
return self.i
|
return self.i
|
||||||
|
|
||||||
def decode_float(self, value):
|
def decode_float(self, value):
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
test,,test1,start,stop,stop,start
|
test,test,test,test,test,test,test,test,test2,test,test2,test,test,test,test,test,test,test,test,test,,test1,start,stop,stop,start
|
||||||
|
|||||||
|
@@ -0,0 +1,58 @@
|
|||||||
|
import serial
|
||||||
|
import time
|
||||||
|
import bin.com.lib
|
||||||
|
|
||||||
|
|
||||||
|
lb = bin.com.lib.Com()
|
||||||
|
|
||||||
|
|
||||||
|
class CommandListGenerator:
|
||||||
|
def __init__(self):
|
||||||
|
self.__go = 0
|
||||||
|
self.__received = ""
|
||||||
|
self.__start = 0
|
||||||
|
self.__lfcount = 0
|
||||||
|
self.__total = ""
|
||||||
|
self.__output = []
|
||||||
|
|
||||||
|
def run(self, special_port):
|
||||||
|
# This function asks the micro:bit to send a list of all of the commands the program that runs
|
||||||
|
# on it supports. Sent string: "\ncmdl\n". Please note: if using micropython, use the here included
|
||||||
|
# com module to communicate (you can flash it to the micro:bit through the settings menu and also
|
||||||
|
# add your own modules to the micro:bit.
|
||||||
|
try:
|
||||||
|
lb.connect(19200, special_port)
|
||||||
|
self.__go = 1
|
||||||
|
except serial.SerialException as e:
|
||||||
|
return e
|
||||||
|
if self.__go == 1:
|
||||||
|
self.__start = time.time()
|
||||||
|
lb.send("\ncmdl\n")
|
||||||
|
self.__go = 0
|
||||||
|
while time.time() - self.__start < 5:
|
||||||
|
self.__received = lb.receive(1)
|
||||||
|
if self.__received == "\n":
|
||||||
|
self.__received = lb.receive(1)
|
||||||
|
if self.__received == "c":
|
||||||
|
self.__received = lb.receive(1)
|
||||||
|
if self.__received == "m":
|
||||||
|
self.__received = lb.receive(1)
|
||||||
|
if self.__received == "d":
|
||||||
|
self.__go = 1
|
||||||
|
break
|
||||||
|
if self.__go == 1:
|
||||||
|
self.__total = ""
|
||||||
|
self.__output = []
|
||||||
|
lb.receive(1)
|
||||||
|
while self.__lfcount < 3:
|
||||||
|
self.__received = lb.receive(1)
|
||||||
|
if self.__received == "\n":
|
||||||
|
self.__lfcount += 1
|
||||||
|
else:
|
||||||
|
self.__lfcount = 0
|
||||||
|
if self.__received == " ":
|
||||||
|
self.__output.append(self.__total)
|
||||||
|
self.__total = ""
|
||||||
|
else:
|
||||||
|
self.__total += self.__received
|
||||||
|
return self.__output
|
||||||
|
|||||||
5
bin/micro_bit/micro_bit_soft/common/basic_filtering.py
Normal file
5
bin/micro_bit/micro_bit_soft/common/basic_filtering.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class BasicFiltering:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def standard_lib(self):
|
||||||
@@ -24,6 +24,7 @@ class Encoder:
|
|||||||
'(': '-.--.', ')': '-.--.-', ':': '---...',
|
'(': '-.--.', ')': '-.--.-', ':': '---...',
|
||||||
'!': '-.-.--', ' ': '@'}
|
'!': '-.-.--', ' ': '@'}
|
||||||
self.__input_raw = ""
|
self.__input_raw = ""
|
||||||
|
self.__input = ""
|
||||||
self.__output = []
|
self.__output = []
|
||||||
self.__pos = 0
|
self.__pos = 0
|
||||||
self.check = 0
|
self.check = 0
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
class LogGenerator:
|
|
||||||
def __init__(self):
|
|
||||||
pass
|
|
||||||
@@ -8,4 +8,3 @@ while True:
|
|||||||
else:
|
else:
|
||||||
music.stop()
|
music.stop()
|
||||||
pin1.write_digital(0)
|
pin1.write_digital(0)
|
||||||
|
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
import microbit
|
import microbit
|
||||||
|
|
||||||
microbit.uart.write()
|
|
||||||
|
microbit.uart.init(19200)
|
||||||
|
while True:
|
||||||
|
m = microbit.uart.read(1)
|
||||||
|
if m is not None:
|
||||||
|
microbit.display.scroll(str(m))
|
||||||
|
else:
|
||||||
|
microbit.display.clear()
|
||||||
|
|||||||
42
bin/micro_bit/micro_bit_soft/radio_com/basic.py
Normal file
42
bin/micro_bit/micro_bit_soft/radio_com/basic.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import microbit
|
||||||
|
import radio
|
||||||
|
|
||||||
|
|
||||||
|
class Basic:
|
||||||
|
def __init__(self):
|
||||||
|
self.__rx = ""
|
||||||
|
self.__decode = 0
|
||||||
|
self.__go = 0
|
||||||
|
self.d = 0
|
||||||
|
self.__x = 0
|
||||||
|
self.__y = 0
|
||||||
|
|
||||||
|
def run(self, group):
|
||||||
|
radio.config(group=group)
|
||||||
|
radio.on()
|
||||||
|
while True:
|
||||||
|
self.receive_p()
|
||||||
|
|
||||||
|
def receive_p(self):
|
||||||
|
self.__rx = radio.receive()
|
||||||
|
try:
|
||||||
|
self.__decode = int(self.__rx)
|
||||||
|
self.__go = 1
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if self.__go == 1:
|
||||||
|
for self.i in range(self.__decode):
|
||||||
|
self.d = self.i / 2
|
||||||
|
self.__y = self.d % 4
|
||||||
|
self.__x = self.d // 4
|
||||||
|
if self.__x and self.__y < 4:
|
||||||
|
microbit.display.set_pixel(self.__x, self.__y, 9)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
m = Basic()
|
||||||
|
m.run(11)
|
||||||
30
bin/micro_bit/micro_bit_soft/radio_com/run.py
Normal file
30
bin/micro_bit/micro_bit_soft/radio_com/run.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import microbit
|
||||||
|
import radio
|
||||||
|
import basic_filtering
|
||||||
|
import struct
|
||||||
|
|
||||||
|
|
||||||
|
bf = basic_filtering.BasicFiltering()
|
||||||
|
|
||||||
|
|
||||||
|
class RadioCom:
|
||||||
|
def __init__(self):
|
||||||
|
microbit.uart.init(19200)
|
||||||
|
|
||||||
|
def run(self, group):
|
||||||
|
radio.config(group=group)
|
||||||
|
radio.on()
|
||||||
|
|
||||||
|
def inst(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def sendpc(self, info):
|
||||||
|
microbit.uart.write(info)
|
||||||
|
|
||||||
|
def listen(self):
|
||||||
|
# listens for messages, sends received text to PC if possible
|
||||||
|
# also returns value, None, if no data is being received
|
||||||
|
radio.receive()
|
||||||
|
|
||||||
|
def send(self, message):
|
||||||
|
radio.send(str(message))
|
||||||
@@ -18,9 +18,9 @@ class RunCommand:
|
|||||||
try:
|
try:
|
||||||
com.connect(19200, "")
|
com.connect(19200, "")
|
||||||
com.send(command)
|
com.send(command)
|
||||||
self.__return = "The command executed successfully"
|
self.__return = f"[micro:bit - {command}] The command executed successfully"
|
||||||
except serial.SerialException:
|
except serial.SerialException as e:
|
||||||
self.__return = f"[micro:bit - {command}]: An error occurred running the command. (Maybe disconnected or no permission?)"
|
self.__return = f"[micro:bit - {command}]: An error occurred running the command. (Maybe disconnected or no permission?) {e}"
|
||||||
else:
|
else:
|
||||||
self.__return = "-micro:bit - No such command"
|
self.__return = "-micro:bit - No such command"
|
||||||
return self.__return
|
return self.__return
|
||||||
|
|||||||
9
main.py
9
main.py
@@ -1,10 +1,11 @@
|
|||||||
#########################################################
|
#########################################################
|
||||||
"""@package docstring
|
"""@package docstring
|
||||||
Micro:bit Bluetooth Interface, developed by simplePCBuilding, alpha 1.0
|
Micro:bit USB / BLE Interface, developed by simplePCBuilding, alpha 1.0
|
||||||
|
|
||||||
This App allows you to connect to a micro:bit via the USB cable and as such transmit to
|
This App allows you to connect to a micro:bit via the USB cable (when the micro:bit is
|
||||||
and recieve Data from it. This file here is the control file for the UI and as such
|
running micropython) or via BLE (when the micro:bit is running a C program) and as such
|
||||||
should not be interfaced with. All the api files are located in the bin directory."""
|
transmit to and receive Data from it. This file here is the control file for the UI and
|
||||||
|
as such should not be interfaced with. All the api files are located in the bin directory."""
|
||||||
#########################################################
|
#########################################################
|
||||||
|
|
||||||
# IMPORTS
|
# IMPORTS
|
||||||
|
|||||||
Reference in New Issue
Block a user