Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linux-dvb] Re: another patch for remote control with rev 2.1



On Sun, Aug 26, 2001 at 08:00:23PM +0200, Christoph Martin wrote:
> I have appended a second patch which adds some of the functions of
> Matthias to my ir code. Mainly I added the buffering and also fixed
> some problems in Matthias' code. In irb_dequeue you forgot to
> spin_unlock when irend == irbeg. Also you said spin_lock at the end of
> this function. I modified the code to return the last command value
> even if the queue is empty. This way the buildin repeat feature of
> lirc is working.

ohhh,uuhh such stupid errors...

>
> I have tested dtv and vdr with this code and it seams to work. The
> repeat mode seams to work to.
>
> Christoph
>

Finally I got lirc to work...

First I changed the buffercode a little bit. Now it buffers until the
buffer is full and then stops instead of overwriting the oldest value
 - I think this is more intuitively. On the other hand I never filled
the buffer completly with my remote-control (highscore: bufferusage 8).

I also changed lastvalue to get initialized with (1<<31) because when i
reloaded the driver and started irw the key 0 got repeated unlimited
times by lirc.

When I played with irw I found that if you press the same key very fast
the pressed events get ?lost? and lirc repeats the key without the highest
bit set although no key is pressed on the remote control until you press
another key.

A more annoying fact is that if you use lirc with vdr and use the repeat
function of lirc (for exaple power-channel-switching) vdr stops after some
channels although the parallel running irw shows no change... I would
suspect vdr lirc handling code. Is that the same with all LIRC-powered
remote controls?

Matthias

Martins second patch with small changes:
----------------------------------cut-------------------------------------------
diff -r -u DVB/driver/dvb.c DVBpatch/driver/dvb.c
--- DVB/driver/dvb.c	Thu Aug 23 20:30:20 2001
+++ DVBpatch/driver/dvb.c	Tue Aug 28 21:06:36 2001
@@ -806,16 +806,57 @@
  ****************************************************************************/

 #ifdef DVB_LIRC
-wait_queue_head_t gpioq;
-static u32 irdata = 0;
+DECLARE_WAIT_QUEUE_HEAD(gpioq);
+#define IR_BUF_LENGTH 20
+#define IR_INC(x) x = (x + 1) % IR_BUF_LENGTH
+#define IRB_USED ((irbeg <= irend)?irend-irbeg:IR_BUF_LENGTH-(irbeg-irend))
+static u32 irbuf[IR_BUF_LENGTH];
+static u8 irbeg, irend;
+static spinlock_t irlock = SPIN_LOCK_UNLOCKED;
+static u32 ircommand;
+
+static inline void irb_enqueue(u32 value) {
+        u8 lookahead;
+        spin_lock(&irlock);
+        lookahead = irend;
+        IR_INC(lookahead);
+        if (lookahead != irbeg) { //if its full don't accept further keys
+                irbuf[irend] = value;
+                irend = lookahead;
+        }
+        spin_unlock(&irlock);
+}
+
+static inline u32 irb_dequeue(void) {
+        u32 value;
+        static u32 lastvalue = (1<<31);
+        spin_lock(&irlock);
+        if (irend == irbeg) {
+                spin_unlock(&irlock);
+                return lastvalue;
+        }
+        value = lastvalue = irbuf[irbeg];
+        IR_INC(irbeg);
+        //printk("dvb: buffer used: %d\n",IRB_USED);
+        spin_unlock(&irlock);
+        return value;
+}
+
+static inline void irb_init(void) {
+        irbeg = irend = 0;
+        spin_lock_init(&irlock);
+}
+
+
 #endif

 void IR_handle(struct dvb_struct *dvb, u32 ircom)
 {
-        printk("dvb: ircommand = %08x\n", ircom);
 #ifdef DVB_LIRC
-        irdata = ircom;
+        irb_enqueue(ircom);
         wake_up_interruptible(&gpioq);
+#else
+        printk("dvb: ircommand = %08x\n", ircom);
 #endif
 }

@@ -833,6 +874,7 @@
 static int
 get_key(void* data, unsigned char *key, int key_no)
 {
+        u32 irdata;
         static unsigned char codes[4];
         int index = code_bytes - key_no - 1;

@@ -846,6 +888,7 @@
                 return SUCCESS;
         }

+        irdata = irb_dequeue();
         memcpy(codes, &irdata, code_bytes);

         *key = codes[index];
@@ -892,6 +935,8 @@
         plugin.code_length = code_length;
         plugin.minor = minor;
         plugin.sample_rate = 10;
+
+	irb_init();

         request_module("lirc_dev");

@@ -906,7 +951,6 @@
                         minor, ret);
                 return ret;
         }
-
         minor = ret;
         printk(LOGHEAD "driver registered\n", minor);

---------------------------------cut--------------------------------------------


-- No attachments (even text) are allowed --
-- Type: TEXT/PLAIN
-- File: dvb2.patch



-- 
Info:
To unsubscribe send a mail to listar@linuxtv.org with "unsubscribe linux-dvb" as subject.


Home | Main Index | Thread Index