summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchatty1999-01-25 17:48:34 +0000
committerchatty1999-01-25 17:48:34 +0000
commit1856a89741061f3ab838f00e415dae1245764a39 (patch)
treefc49a5b0024a29a4f920a7ef71294a70a393d9ea
parentfb242b482a81baa20d5cb4b8a563880b16aebdee (diff)
downloadirbox-1856a89741061f3ab838f00e415dae1245764a39.zip
irbox-1856a89741061f3ab838f00e415dae1245764a39.tar.gz
irbox-1856a89741061f3ab838f00e415dae1245764a39.tar.bz2
irbox-1856a89741061f3ab838f00e415dae1245764a39.tar.xz
Prepared for version 1.0:
- headers updated - renamed irman.c into irbox.c - added options at launch - added functions to read tables from a directory and its index - created a utility for creating tables - created files for launch at boot time
-rw-r--r--irbox.c (renamed from irman.c)64
1 files changed, 44 insertions, 20 deletions
diff --git a/irman.c b/irbox.c
index 9f70163..0fccdf5 100644
--- a/irman.c
+++ b/irbox.c
@@ -1,14 +1,19 @@
/*
*
- * IRBOX, an Ivy driver for infra-red remote controls
+ * IRBOX, an Ivy driver for infra-red remote controls
*
- * Copyright 1998-1999
- * Centre d'Etudes de la Navigation Aerienne
+ * Copyright 1998-1999
+ * Centre d'Etudes de la Navigation Aerienne
*
- * Main file
+ * Main file
*
- * $Id$
+ * Authors: Francois-Regis Colin <fcolin@cenatoulouse.dgac.fr>
+ * Stephane Chatty <chatty@cenatoulouse.dgac.fr>
*
+ * $Id$
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
*/
#include <stdio.h>
@@ -19,6 +24,7 @@
#include <sys/fcntl.h>
#include <unistd.h>
#include <string.h>
+#include <signal.h>
#include "timer.h"
#include "ivy.h"
@@ -27,21 +33,20 @@
#include "irdev.h"
#include "irtable.h"
+#ifndef DEFAULT_DEVICE
#define DEFAULT_DEVICE "/dev/ttyS1"
+#endif
-typedef struct {
- int num;
- int state; /* State */
- int period[2]; /* time on, time off */
- TimerId timerid; /* TimerId */
-} Button;
+#ifndef DEFAULT_IRBOX_DIR
+#define DEFAULT_IRBOX_DIR "."
+#endif
static const char* app_name;
static IrState *ir;
static void
-Handle (Channel channel, int fd, void *data)
+HandleChannel (Channel channel, int fd, void *data)
{
IrState *ir = (IrState*) data;
IrIntr (ir);
@@ -60,6 +65,13 @@ IrUntimeout (void *id)
}
static void
+IrHandleHup (int sig)
+{
+ IrResetTables ();
+ IrReadTables ("tables"); /* TO BE UPDATED */
+}
+
+static void
IrEventCb (IrState *ir, const unsigned char* code)
{
IrTable* t;
@@ -88,8 +100,10 @@ main (int argc, char *argv[])
const char* dev = DEFAULT_DEVICE;
const char* domains = 0;
static char app_name_buf [1024];
+ const char* data_dir_name = 0;
+ struct sigaction act;
- while ((c = getopt(argc, argv, "s:b:n:")) != EOF)
+ while ((c = getopt(argc, argv, "s:b:n:p:")) != EOF)
switch (c) {
case 'b':
bport = atoi(optarg) ;
@@ -103,6 +117,9 @@ main (int argc, char *argv[])
case 'n':
app_name = optarg;
break;
+ case 'p':
+ data_dir_name = optarg;
+ break;
}
if (!app_name) {
@@ -111,6 +128,12 @@ main (int argc, char *argv[])
app_name = app_name_buf;
}
+ /* data directory */
+ if (!data_dir_name)
+ data_dir_name = getenv ("IRBOX_DIR");
+ if (!data_dir_name)
+ data_dir_name = DEFAULT_IRBOX_DIR;
+
ir = IrOpen (dev);
if (!ir) {
fprintf (stderr, "Can't open %s\n", dev);
@@ -120,15 +143,16 @@ main (int argc, char *argv[])
if (!IrInit (ir, IrEventCb, IrFailCb, IrTimeout, IrUntimeout))
return -1;
- IrTableReadFile ("tables/akaiVCR1.ir");
- IrTableReadFile ("tables/akaiVCR2.ir");
- IrTableReadFile ("tables/rcaTV1.ir");
- IrTableReadFile ("tables/rcaVCR1.ir");
- IrTableReadFile ("tables/sonyTV.ir");
- IrTableReadFile ("tables/sonyVCR1.ir");
+ /* Let's read tables and provide for their re-reading on SIGHUP */
+ IrReadTables ("tables");
+ act.sa_handler = IrHandleHup;
+ sigemptyset (&act.sa_mask);
+ act.sa_flags = 0;
+ sigaction (1, &act, 0);
+
IvyInit (app_name, bport, 0, 0, 0, 0, 0);
- IvyChannelSetUp (IrGetFd (ir), ir, 0, Handle);
+ IvyChannelSetUp (IrGetFd (ir), ir, 0, HandleChannel);
IvyStart (domains);
IvyMainLoop (0);