Example #1
0
    def __init__(self):

        plugin.DaemonPlugin.__init__(self)
        self.plugin_name = 'WIIMOTE'

        self.bdaddr = config.WII_ADDRESS
        self.acc_activate = config.WII_ACC_ACTIVATE
        self.acc_rl_repeat = config.WII_ACC_RL_REPEAT
        self.acc_ud_repeat = config.WII_ACC_UD_REPEAT
        self.acc_button = config.WII_ACC_BUTTON
        self.acc_button_time = config.WII_ACC_BUTTON_TIME
        self.ping_interval = config.WII_PING_INTERVAL

        for mapping in config.WII_CMDS:
            self.KEYMAP[mapping] = config.WII_CMDS.get(mapping, '')

        self.rx = bluetooth.BluetoothSocket(bluetooth.L2CAP)
        self.cx = bluetooth.BluetoothSocket(bluetooth.L2CAP)

        self.cx.settimeout(2)
        self.rx.settimeout(2)

        self.rx_dispatcher = kaa.IOMonitor(self.handle_receive)

        # start immediately for the first time
        self.timer = kaa.Timer(self.onTimer)
        self.timer.start(0.1)

        self.acc_timer = kaa.Timer(self.on_acc_timer)

        self.active = True
Example #2
0
    def __init__(self):
        InputPlugin.__init__(self)

        self.config = freevo.config.input.plugin.joystick

        self.device_name = self.config.device

        blocked = self.get_resources('JOYSTICK')
        if len(blocked) != 0:
            # FIXME maybe different joysticks possible?
            log.error("Joystick is allready used, can't start joystick plugin")
            return

        for mapping in self.config.events:
            self.KEYMAP[mapping.input] = mapping.event
        try:
            self.joyfd = os.open(self.device_name, os.O_RDONLY | os.O_NONBLOCK)
        except OSError:
            #            reason = 'Unable to open %s' % self.device_name
            log.error('Could not open joystick interface (%s)' %
                      self.device_name)
            self.free_resources()
            return

        self.socket_dispatcher = kaa.IOMonitor(self.handle)
        self.socket_dispatcher.register(self.joyfd)
        self.timer = kaa.OneShotTimer(self.axis)
        self.movement = {}
        self.events = {}
Example #3
0
    def resume(self):
        """
        (re-)initialize pylirc, e.g. after calling close()
        """
        logger.log(9, 'Lirc.resume()')
        fd = pylirc.init('freevo', config.LIRCRC)

        self.dispatcher = kaa.IOMonitor(self._handle_lirc_input)
        self.dispatcher.register(fd)
Example #4
0
    def initdev(self, dev):
        """
        init specified device
        """
        e = None

        if os.path.exists(dev):
            try:
                e = evdev.evdev(dev)
                self._devpath[e] = dev
            except:
                print "Problem opening event device '%s'" % dev

        else:
            names = []
            name = dev
            for dev in os.listdir('/dev/input'):
                if not dev.startswith('event'):
                    continue

                try:
                    dev = '/dev/input/' + dev
                    e = evdev.evdev(dev)
                except:
                    continue

                names.append(e.get_name())
                if e.get_name() == name:
                    break
            else:
                e = None
                logger.warning(
                    "Could not find device named '%s', possible are:\n  - %s",
                    name, '\n  - '.join(names))

            if e is not None:
                self._devpath[e] = name

        if e is not None:
            logger.info("Added input device '%s': %s, object: %r", dev,
                        e.get_name(), e)
            m = kaa.IOMonitor(self.__handle_event, e)
            m.register(e._fd)
            self._devs.append(m)

            if config.EVENT_MULTIKEYS == True:
                self._bufkeys[e] = None
                self._lastkey[e] = None

            self._movements[e] = {}
Example #5
0
 def _iterate_handshake(self, handshake):
     """
     Iterate through the TLS handshake for asynchronous calls using
     kaa.IOMonitor and kaa.InProgressCallback.
     """
     try:
         while True:
             n = handshake.next()
             cb = kaa.InProgressCallable()
             disp = kaa.IOMonitor(cb)
             if n == 0:
                 disp.register(self.sock.fileno(), kaa.IO_READ)
             if n == 1:
                 disp.register(self.sock.fileno(), kaa.IO_WRITE)
             yield cb
             disp.unregister()
     except StopIteration:
         pass
Example #6
0
    def __init__(self, rc):
        self.rc = rc

        import struct
        import subprocess
        import sys
        self.pipe = os.pipe()
        self.wire_format = struct.Struct('d30p')

        self.input = subprocess.Popen([
            sys.executable,
            os.path.join(os.environ['FREEVO_HELPERS'], 'inputhelper.py'),
            str(self.pipe[1])
        ],
                                      stdin=subprocess.PIPE)

        self.monitor = kaa.IOMonitor(self._handle_input)
        self.monitor.register(self.pipe[0])
Example #7
0
 def _handle_handshake(self, session):
     self._handshake = True
     # Store current write queue and create a new one
     self._pre_handshake_write_queue = self._write_queue
     self._write_queue = []
     if self._pre_handshake_write_queue:
         # flush pre handshake write data
         yield self._pre_handshake_write_queue[-1][1]
     self._rmon.unregister()
     while True:
         try:
             session.handshake()
             break
         except gnutls.connection.OperationWouldBlock, e:
             cb = kaa.InProgressCallable()
             disp = kaa.IOMonitor(cb)
             disp.register(self.fileno, kaa.IO_READ)
             yield cb
             disp.unregister()
Example #8
0
def init(appname=None, cfg=None):
    """
    Initialize lirc and begin monitoring for events.

    :param appname: the name of the program that corresponds to the *prog*
                    value in the lircrc file (default: kaa)
    :param cfg: the path to the lircrc config file (default: ~/.lircrc).  See
                http://www.lirc.org/html/configure.html for more details.
    :raises: ImportError if pylirc is not installed.
    """
    global _dispatcher

    if _dispatcher:
        # already running
        return False

    # This will raise if pylirc isn't available, however if it is, this will
    # already be imported, so there is no risk of this being imported from a
    # thread.
    import pylirc

    if cfg == None:
        cfg = os.path.expanduser("~/.lircrc")
    if appname == None:
        appname = "kaa"

    try:
        fd = pylirc.init(appname, cfg)
    except IOError:
        # something went wrong
        return False

    if not fd:
        # something went wrong
        return False

    pylirc.blocking(0)
    _dispatcher = kaa.IOMonitor(_handle_lirc_input)
    _dispatcher.register(fd)
    kaa.main.signals["shutdown"].connect(stop)

    return True
Example #9
0
 def __init__(self, size, name, logfile='', fullscreen=False):
     super(Stage, self).__init__()
     self.name = 'candy-backend-%s' % name
     self.logfile = logfile
     self.size = size
     self.scale = None
     self.fullscreen = fullscreen
     self.backend_state = Stage.BACKEND_DOWN
     self.backend_time = 0
     # import cache for restart
     self._candy_restart_import = []
     # create the base widget
     self.layer = [Layer(size=size)]
     # We need the render pipe, the 'step' signal is not enough. It
     # is not triggered between timer and select and a change done
     # in a timer may get lost.
     self._render_pipe = os.pipe()
     fcntl.fcntl(self._render_pipe[0], fcntl.F_SETFL, os.O_NONBLOCK)
     fcntl.fcntl(self._render_pipe[1], fcntl.F_SETFL, os.O_NONBLOCK)
     kaa.IOMonitor(self.__sync).register(self._render_pipe[0])
     os.write(self._render_pipe[1], '1')
     self._start_backend()
Example #10
0
    def connection_thread(self):

        self.tx_dispatcher = kaa.IOMonitor(self.handle_receive)

        self.connection_timer()
Example #11
0
if len(sys.argv) < 2:
    sys.stderr.write('No fd specified!')
    sys.exit(1)

fd = int(sys.argv[1])
logger.debug('Using pipe fd %d', fd)

# Put fd in non-blocking mode
flag = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, flag | os.O_NDELAY)

inputs = []
try:
    inputs.append(Lirc())
except:
    pass

if config.EVENT_DEVS:
    try:
        inputs.append(Evdev())
    except:
        pass

if len(inputs) > 0:
    stdin_dispatcher = kaa.IOMonitor(handle_stdin)
    stdin_dispatcher.register(sys.stdin)

    kaa.main.run()
else:
    sys.stderr.write('No inputs to work, exit!')
Example #12
0

def getch_disable():
    global _tc_orig_settings
    if _tc_orig_settings != None:
        termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, _tc_orig_settings)
    os.system("stty echo")


def _handle_stdin_keypress():
    ch = getch()
    kaa.signals["stdin_key_press"].emit(ch)
    return True


_dispatcher = kaa.IOMonitor(_handle_stdin_keypress)

def _keypress_signal_changed(s, flag):
    if flag == kaa.Signal.CONNECTED and s.count() == 1:
        getch_enable()
        _dispatcher.register(sys.stdin)
    elif flag == kaa.Signal.DISCONNECTED and s.count() == 0:
        getch_disable()
        _dispatcher.unregister()


# init
signal = kaa.Signal(changed_cb = _keypress_signal_changed)
kaa.signals["stdin_key_press"] = signal
# Backward compatibility (TODO: remove in future)
kaa.signals["stdin_key_press_event"] = signal