From c49253824a46a45dac86d2a0404b9d5c6e1a92a4 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 19 Dec 2004 18:08:09 +0100 Subject: Replaced time_ms() with a threadsafe and non-overflowing cTimeMs --- lirc.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lirc.c') diff --git a/lirc.c b/lirc.c index ae905fdc..8fe585ab 100644 --- a/lirc.c +++ b/lirc.c @@ -6,7 +6,7 @@ * * LIRC support added by Carsten Koch 2000-06-16. * - * $Id: lirc.c 1.8 2004/12/18 13:25:11 kls Exp $ + * $Id: lirc.c 1.9 2004/12/19 18:05:13 kls Exp $ */ #include "lirc.h" @@ -52,8 +52,8 @@ bool cLircRemote::Ready(void) void cLircRemote::Action(void) { - int FirstTime = 0; - int LastTime = 0; + cTimeMs FirstTime; + cTimeMs LastTime; char buf[LIRC_BUFFER_SIZE]; char LastKeyName[LIRC_KEY_BUF] = ""; bool repeat = false; @@ -75,28 +75,27 @@ void cLircRemote::Action(void) int count; char KeyName[LIRC_KEY_BUF]; sscanf(buf, "%*x %x %29s", &count, KeyName); // '29' in '%29s' is LIRC_KEY_BUF-1! - int Now = time_ms(); if (count == 0) { - if (strcmp(KeyName, LastKeyName) == 0 && Now - FirstTime < KEYPRESSDELAY) + if (strcmp(KeyName, LastKeyName) == 0 && FirstTime.Elapsed() < KEYPRESSDELAY) continue; // skip keys coming in too fast if (repeat) Put(LastKeyName, false, true); strcpy(LastKeyName, KeyName); repeat = false; - FirstTime = Now; + FirstTime.Set(); timeout = -1; } else { - if (Now - FirstTime < REPEATDELAY) + if (FirstTime.Elapsed() < REPEATDELAY) continue; // repeat function kicks in after a short delay repeat = true; timeout = REPEATDELAY; } - LastTime = Now; + LastTime.Set(); Put(KeyName, repeat); } else if (repeat) { // the last one was a repeat, so let's generate a release - if (time_ms() - LastTime >= REPEATDELAY) { + if (LastTime.Elapsed() >= REPEATDELAY) { Put(LastKeyName, false, true); repeat = false; *LastKeyName = 0; -- cgit v1.2.3