diff --git a/bin/com/comport_search.py b/bin/com/comport_search.py index c54b8cf..9b6562e 100644 --- a/bin/com/comport_search.py +++ b/bin/com/comport_search.py @@ -15,9 +15,10 @@ class ComportService: if special_port != "": self.__working = special_port else: + print(serial.tools.list_ports.comports()) while self.__working == []: 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) else: self.__pos += 1 diff --git a/bin/com/lib.py b/bin/com/lib.py index a4c2238..73f77d0 100644 --- a/bin/com/lib.py +++ b/bin/com/lib.py @@ -14,7 +14,7 @@ class Com: self.str_input = "" self.str_get_input = "" self.xs = "" - self.__comport = '/dev/ttyUSB0' + self.__comport = '/dev/ttyACM0' def connect(self, baudrate, special_port): try: @@ -47,7 +47,7 @@ class Com: return 0 def decode_int(self, value): - self.i = int(value, base = 16) + self.i = int(value, base=16) return self.i def decode_float(self, value): diff --git a/bin/data/command_history.csv b/bin/data/command_history.csv index dc62b25..985fc3d 100644 --- a/bin/data/command_history.csv +++ b/bin/data/command_history.csv @@ -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 diff --git a/bin/micro_bit/command_list.py b/bin/micro_bit/command_list.py index e69de29..af44b01 100644 --- a/bin/micro_bit/command_list.py +++ b/bin/micro_bit/command_list.py @@ -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 diff --git a/bin/micro_bit/micro_bit_soft/common/basic_filtering.py b/bin/micro_bit/micro_bit_soft/common/basic_filtering.py new file mode 100644 index 0000000..4bfbfa5 --- /dev/null +++ b/bin/micro_bit/micro_bit_soft/common/basic_filtering.py @@ -0,0 +1,5 @@ +class BasicFiltering: + def __init__(self): + pass + + def standard_lib(self): diff --git a/bin/micro_bit/micro_bit_soft/decoder/encoder.py b/bin/micro_bit/micro_bit_soft/decoder/encoder.py index 373d8da..e0c90ef 100644 --- a/bin/micro_bit/micro_bit_soft/decoder/encoder.py +++ b/bin/micro_bit/micro_bit_soft/decoder/encoder.py @@ -24,6 +24,7 @@ class Encoder: '(': '-.--.', ')': '-.--.-', ':': '---...', '!': '-.-.--', ' ': '@'} self.__input_raw = "" + self.__input = "" self.__output = [] self.__pos = 0 self.check = 0 diff --git a/bin/micro_bit/micro_bit_soft/full_duplex.py b/bin/micro_bit/micro_bit_soft/decoder/full_duplex.py similarity index 100% rename from bin/micro_bit/micro_bit_soft/full_duplex.py rename to bin/micro_bit/micro_bit_soft/decoder/full_duplex.py diff --git a/bin/micro_bit/micro_bit_soft/half_duplex.py b/bin/micro_bit/micro_bit_soft/decoder/half_duplex.py similarity index 100% rename from bin/micro_bit/micro_bit_soft/half_duplex.py rename to bin/micro_bit/micro_bit_soft/decoder/half_duplex.py diff --git a/bin/micro_bit/micro_bit_soft/listen.py b/bin/micro_bit/micro_bit_soft/decoder/listen.py similarity index 100% rename from bin/micro_bit/micro_bit_soft/listen.py rename to bin/micro_bit/micro_bit_soft/decoder/listen.py diff --git a/bin/micro_bit/micro_bit_soft/decoder/log_generator.py b/bin/micro_bit/micro_bit_soft/decoder/log_generator.py deleted file mode 100644 index 2dc16c3..0000000 --- a/bin/micro_bit/micro_bit_soft/decoder/log_generator.py +++ /dev/null @@ -1,3 +0,0 @@ -class LogGenerator: - def __init__(self): - pass \ No newline at end of file diff --git a/bin/micro_bit/micro_bit_soft/sender.py b/bin/micro_bit/micro_bit_soft/decoder/sender.py similarity index 99% rename from bin/micro_bit/micro_bit_soft/sender.py rename to bin/micro_bit/micro_bit_soft/decoder/sender.py index bd3f0bf..ebfa91a 100644 --- a/bin/micro_bit/micro_bit_soft/sender.py +++ b/bin/micro_bit/micro_bit_soft/decoder/sender.py @@ -8,4 +8,3 @@ while True: else: music.stop() pin1.write_digital(0) - diff --git a/bin/micro_bit/micro_bit_soft/micro_bit_soft.py b/bin/micro_bit/micro_bit_soft/micro_bit_soft.py index 0724caa..a4f4395 100644 --- a/bin/micro_bit/micro_bit_soft/micro_bit_soft.py +++ b/bin/micro_bit/micro_bit_soft/micro_bit_soft.py @@ -1,3 +1,10 @@ import microbit -microbit.uart.write() \ No newline at end of file + +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() diff --git a/bin/micro_bit/micro_bit_soft/radio_com/basic.py b/bin/micro_bit/micro_bit_soft/radio_com/basic.py new file mode 100644 index 0000000..5744941 --- /dev/null +++ b/bin/micro_bit/micro_bit_soft/radio_com/basic.py @@ -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) diff --git a/bin/micro_bit/micro_bit_soft/radio_com/run.py b/bin/micro_bit/micro_bit_soft/radio_com/run.py new file mode 100644 index 0000000..7c35632 --- /dev/null +++ b/bin/micro_bit/micro_bit_soft/radio_com/run.py @@ -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)) diff --git a/bin/others/run_command.py b/bin/others/run_command.py index 45c7992..fafd7b0 100644 --- a/bin/others/run_command.py +++ b/bin/others/run_command.py @@ -18,9 +18,9 @@ class RunCommand: try: com.connect(19200, "") com.send(command) - self.__return = "The command executed successfully" - except serial.SerialException: - self.__return = f"[micro:bit - {command}]: An error occurred running the command. (Maybe disconnected or no permission?)" + self.__return = f"[micro:bit - {command}] The command executed successfully" + except serial.SerialException as e: + self.__return = f"[micro:bit - {command}]: An error occurred running the command. (Maybe disconnected or no permission?) {e}" else: self.__return = "-micro:bit - No such command" return self.__return diff --git a/main.py b/main.py index 22f60a4..5154860 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,11 @@ ######################################################### """@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 -and recieve 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.""" +This App allows you to connect to a micro:bit via the USB cable (when the micro:bit is +running micropython) or via BLE (when the micro:bit is running a C program) and as such +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