1 /* $Id: smode2.c,v 5.12 2003/03/30 12:26:44 lirc Exp $ */
3 /****************************************************************************
4 ** smode2.c ****************************************************************
5 ****************************************************************************
7 * smode2 - shows the ir waveform of an IR signal
9 * Copyright (C) 1998.11.18 Sinkovics Zoltan <sinko@szarvas.hu>
11 * This program is based on the mode2.c file which is a part of the
12 * LIRC distribution. The main purpose of this program is to check
13 * operation of LIRC receiver hardware, and to see the IR waveform of
14 * the remote controller without an expensive oscilloscope. The time
15 * division is variable from 1 ms/div to extremely high values (integer
16 * type) but there is no point increasing this value above 20 ms/div,
17 * because one pulse is about 1 ms. I think this kind of presentation
18 * is much more exciting than the simple pulse&space output showed by
21 * Usage: smode2 [-t (ms/div)] , default division is 5 ms/div
34 #include <sys/types.h>
36 #include <sys/ioctl.h>
40 #include "drivers/lirc.h"
42 GraphicsContext
*screen
;
43 GraphicsContext
*physicalscreen
;
44 GraphicsContext
*backscreen
;
52 vgamode
= G640x480x16
;
54 if (!vga_hasmode(vgamode
)) {
55 printf("Mode not available.\n");
60 /* Create virtual screen. */
61 gl_setcontextvgavirtual(vgamode
);
62 backscreen
= gl_allocatecontext();
63 gl_getcontext(backscreen
);
65 /* Physical screen context. */
67 gl_setcontextvga(vgamode
);
68 physicalscreen
= gl_allocatecontext();
69 gl_getcontext(physicalscreen
);
71 gl_setcontext(backscreen
);
72 /*drawgraypalette();*/
76 // gl_setcontextvga(vgamode);
78 gl_setclippingwindow(0,0,639,479);
79 gl_setwritemode(WRITEMODE_OVERWRITE
| FONT_COMPRESSED
);
80 gl_setfont(8, 8, gl_font8x8
);
81 gl_setfontcolors(0, 1) ;
84 void closescreen(void)
89 int main(int argc
, char **argv
)
99 char *device
=LIRC_DRIVER_DEVICE
;
107 static struct option long_options
[] =
109 {"help",no_argument
,NULL
,'h'},
110 {"version",no_argument
,NULL
,'v'},
111 {"device",required_argument
,NULL
,'d'},
112 {"timediv",required_argument
,NULL
,'t'},
115 c
= getopt_long(argc
,argv
,"hvd:t:",long_options
,NULL
);
121 printf("Usage: %s [options]\n",progname
);
122 printf("\t -h --help\t\tdisplay usage summary\n");
123 printf("\t -v --version\t\tdisplay version\n");
124 printf("\t -d --device=device\tread from given device\n");
125 printf("\t -t --timediv=value\tms per unit\n");
126 return(EXIT_SUCCESS
);
128 printf("%s %s\n",progname
, VERSION
);
129 return(EXIT_SUCCESS
);
133 case 't': /* timediv */
134 div
= strtol(optarg
,NULL
,10);
137 printf("Usage: %s [options]\n",progname
);
138 return(EXIT_FAILURE
);
143 fprintf(stderr
,"%s: too many arguments\n",progname
);
144 return(EXIT_FAILURE
);
147 fd
=open(device
,O_RDONLY
);
150 fprintf(stderr
,"%s: error opening %s\n",progname
,device
);
153 if ( (fstat(fd
,&s
)!=-1) && (S_ISFIFO(s
.st_mode
)) )
155 /* can't do ioctls on a pipe */
157 else if(ioctl(fd
,LIRC_GET_REC_MODE
,&mode
)==-1 || mode
!=LIRC_MODE_MODE2
)
159 printf("This program is only intended for receivers "
160 "supporting the pulse/space layer.\n");
161 printf("Note that this is no error, but this program simply "
162 "makes no sense for your\nreceiver.\n");
163 printf("In order to test your setup run lircd with the "
164 "--nodaemon option and \n"
165 "then check if the remote works with the irw tool.\n");
174 for (y2
=0;y2
<640;y2
+=20) gl_line(y2
,0,y2
,480,1);
175 sprintf(textbuffer
,"%d ms/unit",div
);
176 gl_write(500,10,textbuffer
);
177 gl_copyscreen(physicalscreen
);
181 result
=read(fd
,&data
,sizeof(data
));
182 if (result
==sizeof(data
))
184 // printf("%.8lx\t",(unsigned long) data);
185 x2
=(data
&PULSE_MASK
)/(div
*50);
190 gl_copyscreen(physicalscreen
);
196 gl_line(x1
, ((data
&PULSE_BIT
)?y1
:y1
+10), x1
+x2
, ((data
&PULSE_BIT
)?y1
:y1
+10), c
) ;
198 gl_line(x1
, ((data
&PULSE_BIT
)?y1
:y1
+10), x1
, ((data
&PULSE_BIT
)?y1
+10:y1
), c
) ;
205 for (y2
=0;y2
<640;y2
+=10) gl_line(y2
,0,y2
,480,1);
206 gl_write(500,10,textbuffer
);
209 // gl_copyscreen(physicalscreen);