def control_loop(brain, devices, log_file): logging.debug("Starting control loop") while True: inputs = devices.read() log.write(json.dumps(inputs)) actions = brain.process_inputs(inputs) devices.perform(actions)
looping = True quitting = False while looping: busyDevices = list(device for device in inputs if device.busy) # We should only do a blocking read if no device has anything in it's queue. shouldBlock = not (output.busy or busyDevices) # Crude way of cutting down on CPU usage :/ ## This also prevents some events being interpreted (by X11) out of ## sequence, I guess because of small timestamp differentials. if busyDevices: time.sleep(0.01) # Process those events! events = devices.read(blocking=shouldBlock) if options.verbose > 1: for event in events: print 'Incoming event: %s' % repr(event) for device in busyDevices: events = device.process() if options.verbose > 2: for event in events: print 'Outgoing event: %s' % repr(event) # Actually push the events to the uinput device output.process()
looping = True quitting = False while looping: busyDevices = list(device for device in inputs if device.busy) # We should only do a blocking read if no device has anything in it's queue. shouldBlock = not (output.busy or busyDevices) # Crude way of cutting down on CPU usage :/ ## This also prevents some events being interpreted (by X11) out of ## sequence, I guess because of small timestamp differentials. if busyDevices: time.sleep(0.01) # Process those events! events = devices.read(blocking=shouldBlock) if options.verbose > 1: for event in events: print "Incoming event: %s" % repr(event) for device in busyDevices: events = device.process() if options.verbose > 2: for event in events: print "Outgoing event: %s" % repr(event) # Actually push the events to the uinput device output.process()