Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

LIRC mode2 support #13

Closed
Closed

Description

@daym

Do you think it would be possible to support mode2 in python-lirc as well?

It's a way of using lirc without lircd, reading just the raw kernel device (try calling "mode2 -r -d /dev/lirc0").

An example is this:

#!/usr/bin/env python

import fcntl
import array
import os
import struct

LIRC_GET_REC_MODE = 0x80046902 # _IOR('i', 0x00000002, __u32)
LIRC_GET_LENGTH = 0x8004690F # _IOR('i', 0x0000000f, __u32)
LIRC_MODE_MODE2 = 0x00000004
PULSE_BIT = 0x01000000
PULSE_MASK = 0x00FFFFFF

result = array.array("I", [0])

lirc_t = "i"

def read(fd):
  rawbuf = os.read(fd, struct.calcsize(lirc_t))
  rawvalue, = struct.unpack(lirc_t, rawbuf)
  pulseflag = rawvalue & PULSE_BIT
  duration = rawvalue & PULSE_MASK
  return (pulseflag != 0, duration)

def main():
  fd = os.open("/dev/lirc0", os.O_RDONLY)
  if fcntl.ioctl(fd, LIRC_GET_REC_MODE, result, True) == -1:
    raise IOError("cannot use {!r} as a raw LIRC device. Is it a
LIRC device?".format(self.device))
  if result[0] != LIRC_MODE_MODE2:
    raise IOError("cannot use {!r} as a raw LIRC device. Is it a
raw (!) LIRC device?".format(self.device))
  print(read(fd))

It would be nice especially to have these strange constants available.

Activity

  1. daym commented on Aug 3, 2016

    @daym
    Author

    See pull request #14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions