27707d4ac9
the output of the CueCat barcode reader under NetBSD.
161 lines
4 KiB
Text
161 lines
4 KiB
Text
$NetBSD: patch-ab,v 1.1.1.1 2001/02/13 13:55:42 wiz Exp $
|
|
|
|
--- read_cuecat.c.orig Wed Sep 20 22:13:46 2000
|
|
+++ read_cuecat.c
|
|
@@ -4,8 +4,8 @@
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
-#include <linux/kd.h>
|
|
-#include <linux/serial.h>
|
|
+#include <sys/time.h>
|
|
+#include <dev/wscons/wsconsio.h>
|
|
#include <sys/ioctl.h>
|
|
#include "cuecat_lib.h"
|
|
#include "cuecat_at2xt.h"
|
|
@@ -24,8 +24,6 @@
|
|
int previous_kbd_mode;
|
|
struct termios old_term_settings;
|
|
struct termios new_term_settings;
|
|
-struct serial_struct old_serinfo;
|
|
-struct serial_struct new_serinfo;
|
|
char serial_dev_filename[FILENAME_MAX]=DEFAULT_SERIAL_DEV_FILE;
|
|
char serial;
|
|
char help;
|
|
@@ -55,6 +53,7 @@
|
|
char barcode_type[CUECAT_BARCODE_TYPE_LEN+1];
|
|
char barcode[256];
|
|
int user_abort=0;
|
|
+ int ioctl_arg;
|
|
|
|
/* Parse the command line parameters */
|
|
if((invalid_parameter=parse_cmdline(argc,argv)))
|
|
@@ -83,7 +82,7 @@
|
|
}
|
|
|
|
/* Get a console or serial port descriptor */
|
|
- fd=getfd();
|
|
+ fd=0;
|
|
|
|
/* Did the user want to use a serial pod ? */
|
|
if(!serial)
|
|
@@ -92,9 +91,9 @@
|
|
printf("Press ESC to end the program ...\n\n");
|
|
|
|
/* Get the current state of the keyboard */
|
|
- if (ioctl(fd, KDGKBMODE, &previous_kbd_mode))
|
|
+ if (ioctl(fd, WSKBDIO_GETMODE, &previous_kbd_mode))
|
|
{
|
|
- perror("KDGKBMODE");
|
|
+ perror("WSKBDIO_GETMODE");
|
|
close(fd);
|
|
exit(1);
|
|
}
|
|
@@ -103,11 +102,9 @@
|
|
printf("The keyboard was in ");
|
|
switch(previous_kbd_mode)
|
|
{
|
|
- case K_RAW: printf("raw") ;break;
|
|
- case K_XLATE: printf("xlate") ;break;
|
|
- case K_MEDIUMRAW: printf("mediumraw");break;
|
|
- case K_UNICODE: printf("unicode") ;break;
|
|
- default: printf("unknown") ;break;
|
|
+ case WSKBD_TRANSLATED: printf("translated"); break;
|
|
+ case WSKBD_RAW: printf("raw"); break;
|
|
+ default: printf("unknown(%d)",previous_kbd_mode); break;
|
|
}
|
|
printf(" state.\n\n");
|
|
|
|
@@ -139,9 +136,10 @@
|
|
close(fd);
|
|
exit(1);
|
|
}
|
|
- if (ioctl(fd,KDSKBMODE,K_RAW))
|
|
+ ioctl_arg = WSKBD_RAW;
|
|
+ if (ioctl(fd,WSKBDIO_SETMODE,&ioctl_arg))
|
|
{
|
|
- perror("KDSKBMODE");
|
|
+ perror("WSKBDIO_SETMODE");
|
|
close(fd);
|
|
exit(1);
|
|
}
|
|
@@ -151,13 +149,6 @@
|
|
/* Give a quick word of advise */
|
|
printf("Press CTRL-C to end the program ...\n\n");
|
|
|
|
- /* Get the current state of the serial port */
|
|
- if(ioctl(fd,TIOCGSERIAL,&old_serinfo))
|
|
- {
|
|
- perror("TIOCGSERIAL");
|
|
- close(fd);
|
|
- exit(1);
|
|
- }
|
|
if(tcgetattr(fd,&old_term_settings)==-1)
|
|
{
|
|
perror("tcgetattr");
|
|
@@ -165,28 +156,12 @@
|
|
exit(1);
|
|
}
|
|
|
|
- new_serinfo=old_serinfo;
|
|
new_term_settings=old_term_settings;
|
|
|
|
/* Setup the signal handler to trap any signal that might kill us before
|
|
we can restore the serial port as it was before */
|
|
setup_signal_handlers();
|
|
|
|
- /* set SPD_CUST and divisor */
|
|
- new_serinfo.flags&=~ASYNC_SPD_MASK;
|
|
- new_serinfo.flags|=ASYNC_SPD_CUST;
|
|
-
|
|
- /* we measured the cuecat's baudrate to be about 8000 the closest we can
|
|
- get to this with a basebaud of 115200 is to use a divisor of 14 */
|
|
- new_serinfo.custom_divisor=14;
|
|
-
|
|
- if (ioctl(fd,TIOCSSERIAL,&new_serinfo))
|
|
- {
|
|
- perror("TIOCSSERIAL");
|
|
- close(fd);
|
|
- exit(1);
|
|
- }
|
|
-
|
|
cfmakeraw(&new_term_settings);
|
|
cfsetospeed(&new_term_settings, B38400);
|
|
|
|
@@ -268,9 +243,9 @@
|
|
/* Restore the keyboard and console as they where when we started */
|
|
void restore_console()
|
|
{
|
|
- if(ioctl(fd,KDSKBMODE,previous_kbd_mode))
|
|
+ if(ioctl(fd,WSKBDIO_SETMODE,&previous_kbd_mode))
|
|
{
|
|
- perror("KDSKBMODE");
|
|
+ perror("WSKBDIO_SETMODE");
|
|
close(fd);
|
|
exit(1);
|
|
}
|
|
@@ -288,12 +263,6 @@
|
|
/* Restore the keyboard and console as they where when we started */
|
|
void restore_serial_port()
|
|
{
|
|
- if(ioctl(fd,TIOCSSERIAL,&old_serinfo)==-1)
|
|
- {
|
|
- perror("TIOCSSERIAL");
|
|
- close(fd);
|
|
- exit(1);
|
|
- }
|
|
close(fd);
|
|
}
|
|
|
|
@@ -361,8 +330,11 @@
|
|
char arg;
|
|
|
|
arg=0;
|
|
+ return 1;
|
|
+#if 0
|
|
return(ioctl(fd,KDGKBTYPE,&arg)==0
|
|
&& ((arg==KB_101) || (arg==KB_84)));
|
|
+#endif
|
|
}
|
|
|
|
|