diff options
author | chatty | 1999-01-12 12:58:18 +0000 |
---|---|---|
committer | chatty | 1999-01-12 12:58:18 +0000 |
commit | 0118246b32fe0ccc5f289cc350f32fb935305959 (patch) | |
tree | 8525f9bc6213b6046d3ce6121398029d76a63bc2 /irbox.c | |
parent | 23abb4b87c7e40ed259dd02f653516f60e55ade4 (diff) | |
download | irbox-0118246b32fe0ccc5f289cc350f32fb935305959.zip irbox-0118246b32fe0ccc5f289cc350f32fb935305959.tar.gz irbox-0118246b32fe0ccc5f289cc350f32fb935305959.tar.bz2 irbox-0118246b32fe0ccc5f289cc350f32fb935305959.tar.xz |
Initial revision
Diffstat (limited to 'irbox.c')
-rw-r--r-- | irbox.c | 128 |
1 files changed, 128 insertions, 0 deletions
@@ -0,0 +1,128 @@ +/* + * + * IRBOX, an Ivy driver for infra-red remote controls + * + * Copyright 1998-1999 + * Centre d'Etudes de la Navigation Aerienne + * + * Main file + * + * $Id$ + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/errno.h> +#include <sys/fcntl.h> +#include <unistd.h> +#include <string.h> + +#include "timer.h" +#include "ivy.h" +#include "ivychannel.h" + +#include "irdev.h" + +#define DEFAULT_DEVICE "/dev/ttyS1" + +typedef struct { + int num; + int state; /* State */ + int period[2]; /* time on, time off */ + TimerId timerid; /* TimerId */ +} Button; + +static const char* app_name; +static IrState *ir; + + +static void +Handle (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 +IrEventCb (IrState *ir, IrEvent event, const char* value) +{ + switch (event) { + case EVENT_BTN_RELEASE: + IvySendMsg ("%s BUTTON %s UP", app_name, value); + break; + + case EVENT_BTN_PRESS_TV_VOL_UP: + IvySendMsg ("%s BUTTON %s DOWN", app_name, "TV:VOL_UP"); + break; + + + default: + IvySendMsg ("%s BUTTON %s DOWN", app_name, value); + break; + } +} + + +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]; + + while ((c = getopt(argc, argv, "s:b:n:")) != 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; + } + + if (!app_name) { + gethostname (app_name_buf, 1024); + strcat (app_name_buf, ".IRBOX"); + app_name = app_name_buf; + } + + ir = IrOpen (dev); + if (!ir) { + fprintf (stderr, "Can't open %s\n", dev); + return -1; + } + + if (!IrInit (ir, IrEventCb, IrTimeout, IrUntimeout)) + return -1; + + IvyInit (app_name, bport, 0, 0, 0, 0, 0); + IvyChannelSetUp (IrGetFd (ir), ir, 0, Handle); + + IvyStart (domains); + IvyMainLoop (0); + + return 0 ; +} |