Exemple #1
0
class BLEHandler(LoggingHandler):
    """Send logging output to the BLE uart port."""

    def __init__(self):
        """Create an instance.

        :param uart: the busio.UART instance to which to write messages

        """
        self._advertising_now = False
        self._uart = UARTServer()
        self._uart.start_advertising()

    def format(self, level, msg):
        """Generate a string to log.

        :param level: The level at which to log
        :param msg: The core message

        """
        return super().format(level, msg) + '\r\n'

    def emit(self, level, msg):
        """Generate the message and write it to the UART.

        :param level: The level at which to log
        :param msg: The core message

        """
        while not self._uart.connected:
            pass
        data = bytes(self.format(level, msg), 'utf-8')
        self._uart.write(data)
Exemple #2
0
                RSTEP_PIN.value = False
                print("slow command")
            elif one_byte == fast_cmd:
                FWD_PIN.value = False
                REV_PIN.value = False
                SLOW_PIN.value = False
                FAST_PIN.value = True
                FSTEP_PIN.value = False
                RSTEP_PIN.value = False
                print("fast command")
            elif one_byte == fstep_cmd:
                FWD_PIN.value = False
                REV_PIN.value = False
                SLOW_PIN.value = False
                FAST_PIN.value = False
                FSTEP_PIN.value = True
                RSTEP_PIN.value = False
                print("fstep command")
            elif one_byte == rstep_cmd:
                FWD_PIN.value = False
                REV_PIN.value = False
                SLOW_PIN.value = False
                FAST_PIN.value = False
                FSTEP_PIN.value = False
                RSTEP_PIN.value = True
                print("rstep command")

            uart.write(one_byte)

    # When disconnected, arrive here. Go back to the top
    # and start advertising again.