Exemplo n.º 1
0
    def run(self):
        '''
        run as thread
        '''
        self._import_requirement_or_import()

        devices = list_connected_devices()  # hack后
        msk_filter = filter(lambda device: isinstance(device, MotionSensorKit),
                            devices)
        msk = next(msk_filter, None)  # Get first Motion Sensor Kit
        self.proximity_loop(msk)
        while self._running:
            time.sleep(1)
Exemplo n.º 2
0
def test_list_connected_devices():
    '''
	Should return only connected devices with Kano's vendor and product ids
	'''
    vDevices = [
        SimpleNamespace(vid=None, pid=None, device="UNKNOWN"),
        SimpleNamespace(vid=9025, pid=33102, device="MSK"),
        SimpleNamespace(vid=1027, pid=24597, device="RPK")
    ]
    with patch('communitysdk.MotionSensorKit.serial_connect'),\
     patch('communitysdk.RetailPixelKitSerial.serial_connect'),\
     patch('serial.tools.list_ports.comports', return_value=vDevices):
        devices = list_connected_devices()
        assert len(devices) == 2
        for d in devices:
            d.close()
Exemplo n.º 3
0
def test_list_connected_devices_instances():
    '''
	Should return connected instances of devices
	'''
    vDevices = [
        SimpleNamespace(vid=9025, pid=33102, device="MSK"),
        SimpleNamespace(vid=1027, pid=24597, device="RPK")
    ]
    with patch('communitysdk.MotionSensorKit.serial_connect'),\
     patch('communitysdk.RetailPixelKitSerial.serial_connect'),\
     patch('serial.tools.list_ports.comports', return_value=vDevices):
        devices = list_connected_devices()
        assert isinstance(devices[0], MotionSensorKit)
        assert isinstance(devices[1], PixelKit)
        assert devices[0].is_connected == True
        assert devices[1].is_connected == True
        for d in devices:
            d.close()
Exemplo n.º 4
0
'''
This example will print the proximity value
'''

from communitysdk import list_connected_devices, MotionSensorKit

devices = list_connected_devices()
msk_filter = filter(lambda device: isinstance(device, MotionSensorKit), devices)
msk = next(msk_filter, None) # Get first Motion Sensor Kit

if msk == None:
	print('No Motion Sensor was found :(')
else:
	def on_proximity(proximityValue):
		# Avoid printing `0` all the time
		if proximityValue > 0:
			print('Proximity value:', proximityValue)
	msk.set_mode('proximity')
	msk.on_proximity = on_proximity
	print('Move your hand above the Motion Sensor:')