diff options
-rw-r--r-- | irbox.c (renamed from irman.c) | 64 |
1 files changed, 44 insertions, 20 deletions
@@ -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); |