From 1856a89741061f3ab838f00e415dae1245764a39 Mon Sep 17 00:00:00 2001 From: chatty Date: Mon, 25 Jan 1999 17:48:34 +0000 Subject: 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 --- irbox.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 irbox.c (limited to 'irbox.c') diff --git a/irbox.c b/irbox.c new file mode 100644 index 0000000..0fccdf5 --- /dev/null +++ b/irbox.c @@ -0,0 +1,161 @@ +/* + * + * IRBOX, an Ivy driver for infra-red remote controls + * + * Copyright 1998-1999 + * Centre d'Etudes de la Navigation Aerienne + * + * Main file + * + * Authors: Francois-Regis Colin + * Stephane Chatty + * + * $Id$ + * + * Please refer to file version.h for the + * copyright notice regarding this software + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "timer.h" +#include "ivy.h" +#include "ivychannel.h" + +#include "irdev.h" +#include "irtable.h" + +#ifndef DEFAULT_DEVICE +#define DEFAULT_DEVICE "/dev/ttyS1" +#endif + +#ifndef DEFAULT_IRBOX_DIR +#define DEFAULT_IRBOX_DIR "." +#endif + +static const char* app_name; +static IrState *ir; + + +static void +HandleChannel (Channel channel, int fd, void *data) +{ + IrState *ir = (IrState*) data; + IrIntr (ir); +} + +static void* +IrTimeout (IrTimerCallback cb, long value, void *data ) +{ + return TimerRepeatAfter (1, value, (TimerCb) cb, ir); +} + +static void +IrUntimeout (void *id) +{ + TimerRemove ((TimerId) id); +} + +static void +IrHandleHup (int sig) +{ + IrResetTables (); + IrReadTables ("tables"); /* TO BE UPDATED */ +} + +static void +IrEventCb (IrState *ir, const unsigned char* code) +{ + IrTable* t; + const char* key; + if (IrTableTranslateCode (code, &t, &key)) { + IvySendMsg ("%s Down control=%s button=%s", app_name, t->name, key); + } else { + IvySendMsg ("%s unknown code %.3d %.3d %.3d %.3d %.3d %.3d", app_name, code[0], code[1],code[2],code[3],code[4],code[5]); + fprintf (stderr, "unknown code %.3d %.3d %.3d %.3d %.3d %.3d\n", code[0], code[1],code[2],code[3],code[4],code[5]); + } +} + +static void +IrFailCb (IrState* ir) +{ + fprintf(stderr,"IR box not responding.\n"); + IvySendMsg ("%s Failed", app_name); + IvyStop (); +} + +int +main (int argc, char *argv[]) +{ + unsigned short bport = DEFAULT_BUS; + int c; + 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:p:")) != EOF) + switch (c) { + case 'b': + bport = atoi(optarg) ; + break; + case 's': + dev = optarg; + break; + case 'd': + domains = optarg; + break; + case 'n': + app_name = optarg; + break; + case 'p': + data_dir_name = optarg; + break; + } + + if (!app_name) { + gethostname (app_name_buf, 1024); + strcat (app_name_buf, ".IRBOX"); + 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); + return -1; + } + + if (!IrInit (ir, IrEventCb, IrFailCb, IrTimeout, IrUntimeout)) + return -1; + + /* 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, HandleChannel); + + IvyStart (domains); + IvyMainLoop (0); + + return 0 ; +} -- cgit v1.1