Exemple #1
0
def refresh():

    removed = []

    for device_filename in os.listdir(systemmodel.DEV_INPUT):

        if device_filename.startswith('js') and device_filename not in device_names:

            # TODO: We can write to these guys too
            # Open the file, blocking
            time.sleep(0.5)
            f = open("/dev/input/" + device_filename, 'rb')
            
            # Get the device name JSIOCGNAME(len)
            buf = array.array('c', ['\0'] * 64)
            ioctl(f, 0x80006a13 + (0x10000 * len(buf)), buf)
            name = buf.tostring()
            
            logservice.log(logservice.LOG_INFO, 'New game controller: {0}'.format(device_filename))
            displaymodel.alert("New gamepad:", device_filename)            
            
            # Add to the device list
            devices[f.fileno()] = {
                
                "type" : gamepadmodel.DEVICE_TYPE_GAMEPAD,
                "filename" : device_filename,
                "name" : name,
                "file" : f,
                "getevent" : getevent
            }

            device_names.add(device_filename)

    
    return removed
Exemple #2
0
def refresh():

	removed = []

	for device in devices.keys():

		# See if the file is still there
		if not os.path.exists(devices[device]["filename"]):

			# If not, remove it from all the places we track them
			device_names.remove(devices[device]["filename"])
			del devices[device]
			removed.append(device)


	# If the file is gone, we can also remove it from our bad guy list.
	toremove = []

	for filename in device_names_invalid:

		# If not, remove it from all the places we track them
		if not os.path.exists(filename):

			toremove.append(filename)

	for filename in toremove:

		device_names_invalid.remove(filename)

	# Refresh the device list every once in a while
	for device_filename in glob.glob(monomemodel.GRID_DEV_GLOB):

		if (device_filename not in device_names) and (device_filename not in device_names_invalid):

			try:

				# Sleep for a bit just to see if udev needs time
				time.sleep(0.5)

				# Try to create the device
				device = monome.Monome(device_filename)

				# Get the serial number, names, etc.
				devices[device.fileno()] = {

					"type": DEVICE_TYPE_MONOME,
					"filename": device_filename,
					"monome": device,
					"getevent": getevent,
					"message": message
				}

				# TODO - display in window
				logservice.log(logservice.LOG_INFO, 'New monome controller: {0}'.format(device_filename))
				displaymodel.alert("New monome:", device_filename)

				# TODO: Need to remove them too
				device_names.add(device_filename)

				# Set Rotation
				device.rotation = monome.ROTATE_0

				# TODO: Why is this crashing the device?!
				# Clear the device
				# device.led_all(1)
				# time.sleep(0.1)
				# device.led_all(0)
				# time.sleep(0.1)


			except Exception:

				# Add to the invalid list
				device_names_invalid.add(device_filename)

				logservice.log(logservice.LOG_INFO, 'Device {0} was not a monome or there was an error trying.'.format(device_filename))

	# Pass back any that got removed
	return removed