class usb_vcp_tmcl_interface(tmcl_module_interface, tmcl_host_interface):

    def __init__(self, port=0, data_rate=None, host_id=2, module_id=1, debug=False):
        del data_rate
        tmcl_module_interface.__init__(self, host_id, module_id, debug)
        tmcl_host_interface.__init__(self, host_id, module_id, debug)

        self.__vcp = USB_VCP(port)
        self.__vcp.init()
        self.__vcp.setinterrupt(-1)

    def __enter__(self):
        return self

    def __exit__(self, exitType, value, traceback):
        del exitType, value, traceback
        self.close()

    def close(self):
        self.__vcp.setinterrupt(3)
        self.__vcp.close()
        return 0

    def data_available(self, hostID, moduleID):
        del hostID, moduleID
        return self.__vcp.any()

    def _send(self, hostID, moduleID, data):
        del hostID, moduleID

        self.__vcp.write(data)

    def _recv(self, hostID, moduleID):
        del hostID, moduleID

        read = bytearray(0)
        while(len(read) < 9):
            read += self.__vcp.read(9)
            if(not(read)):
                read = bytearray(0)

        return read

    def printInfo(self):
        pass

    def enableDebug(self, enable):
        self._debug = enable

    @staticmethod
    def supportsTMCL():
        return True

    @staticmethod
    def supportsCANopen():
        return False

    @staticmethod
    def available_ports():
        return set([0])
Exemple #2
0
    return "".join([chr(char) for char in binary_string])


rtc = pyb.RTC()
usb = USB_VCP()

# Blink blue at start
blink(3)
pyb.delay(500)
blink(3)

# Get time from raspberry

while (True):
    pyb.LED(1).on()
    data = usb.read()
    if data != None:
        if len(data) >= 4:
            # we want to check that starts with date and last element is ")"
            if data[:4] == b'date':
                pyb.LED(1).off()
                # now we parse the time
                time_stamp = data[5:]
                write_binary_time(time_stamp)
                # now decode into string
                time_stamp = decode(time_stamp)
                # and transform to tuple
                tuple_time = parse_date(time_stamp)
                # set the clock!
                rtc.datetime(tuple_time)
                blink(2)
Exemple #3
0
scalez = (127 / (sensor.width() * sensor.height())
          ) * 10  #factor gives fraction of area that will max out integer

yhalf = sensor.width() / 2
buf = 10
scaley_half = 64 / (yhalf - 2 * buf)

mode = 0
debug = 0  # 0 for debug 1 for run

while (True):
    #time.sleep(100)

    if (usb.any()):
        #halfmode = int.from_bytes(usb.read(), 'little')
        mode = int(usb.read())

    if not debug:
        #timeprint(0)

        img = sensor.snapshot()  # Take a picture and return the image.

        #img.difference(bg)

        #stat = img.get_statistics()
        #print(stat.max())

        #img.binary([(30,255)])
        blob = img.find_blobs([(100, 255)], area_threshold=2)

        if (len(blob)):  #Don't do anything if there are no blobs