initial version
This commit is contained in:
commit
6cdb039c6c
9 changed files with 556 additions and 0 deletions
22
Makefile
Normal file
22
Makefile
Normal file
|
@ -0,0 +1,22 @@
|
|||
all: trawkbd.c twskbd twsmouse twsmux twsmux-kq thotplug
|
||||
|
||||
trawkbd: trawkbd.c /usr/include/dev/wscons/wsconsio.h
|
||||
cc -Wall -g -o trawkbd trawkbd.c
|
||||
|
||||
twskbd: twskbd.c /usr/include/dev/wscons/wsconsio.h
|
||||
cc -Wall -g -o twskbd twskbd.c
|
||||
|
||||
twsmouse: twsmouse.c /usr/include/dev/wscons/wsconsio.h
|
||||
cc -Wall -g -o twsmouse twsmouse.c
|
||||
|
||||
twsmux: twsmux.c /usr/include/dev/wscons/wsconsio.h
|
||||
cc -Wall -g -o twsmux twsmux.c
|
||||
|
||||
# twsmux-kq: twsmux-kq.c /usr/include/dev/wscons/wsconsio.h
|
||||
# cc -Wall -g -o twsmux-kq twsmux-kq.c
|
||||
|
||||
thotplug: thotplug.c
|
||||
cc -Wall -g -o thotplug thotplug.c
|
||||
|
||||
clean:
|
||||
rm -f trawkbd twskbd twsmouse twsmux twsmux-kq thotplug
|
73
thotplug.c
Normal file
73
thotplug.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/hotplug.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
#if 0
|
||||
struct kevent ev;
|
||||
#endif
|
||||
struct hotplug_event he;
|
||||
char *device;
|
||||
int fd, kq, kev;
|
||||
|
||||
if (argc == 2)
|
||||
device = argv[1];
|
||||
else
|
||||
device = "/dev/hotplug";
|
||||
|
||||
fd = open(device, O_RDONLY);
|
||||
if (fd == -1)
|
||||
err(2, "open %s", device);
|
||||
#if 0
|
||||
if ((kq = kqueue()) <= 0)
|
||||
err(2, "kqueue");
|
||||
|
||||
EV_SET(&ev, fd, EVFILT_DEVICE, EV_ADD | EV_ENABLE | EV_CLEAR,
|
||||
NOTE_CHG_DATA, 0, NULL);
|
||||
if (kevent(kq, &ev, 1, NULL, 0, NULL) < 0)
|
||||
err(2, "kevent init");
|
||||
#endif
|
||||
while (1) {
|
||||
#if 0
|
||||
struct pollfd fds;
|
||||
int result;
|
||||
|
||||
fds.fd = kq;
|
||||
fds.events = POLLIN;
|
||||
result = poll(&fds, 1, INFTIM);
|
||||
printf("poll result %d\n", result);
|
||||
#endif
|
||||
int n;
|
||||
n = read(fd, &he, sizeof(he));
|
||||
if (n == -1)
|
||||
err(2, "read");
|
||||
printf("hotplug event %d %d %s\n",
|
||||
he.he_devclass, he.he_type, he.he_devname);
|
||||
if (he.he_devclass != DV_TTY)
|
||||
continue;
|
||||
switch (he.he_type) {
|
||||
case HOTPLUG_DEVAT:
|
||||
printf("wscons attach %s\n", he.he_devname);
|
||||
break;
|
||||
case HOTPLUG_DEVDT:
|
||||
printf("wscons detach %s\n", he.he_devname);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
95
trawkbd.c
Normal file
95
trawkbd.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
#include <dev/wscons/wsdisplay_usl_io.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
volatile int done = 0;
|
||||
|
||||
void
|
||||
sighandler(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct wscons_event ev;
|
||||
struct termios kbdtty, okbdtty;
|
||||
int fd, i, n, option = WSKBD_TRANSLATED;
|
||||
unsigned char buf[256];
|
||||
|
||||
signal(SIGINT, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
|
||||
printf("Signals installed\n");
|
||||
|
||||
if ((fd = open(argv[1] != NULL ? argv[1]:"/dev/wskbd0", O_RDWR))
|
||||
< 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
tcgetattr(fd, &kbdtty);
|
||||
okbdtty = kbdtty;
|
||||
cfmakeraw(&kbdtty);
|
||||
kbdtty.c_cc[VTIME] = 0;
|
||||
kbdtty.c_cc[VMIN] = 1;
|
||||
tcsetattr(fd, TCSANOW, &kbdtty);
|
||||
#endif
|
||||
#if 1
|
||||
if (argv[2] != NULL) {
|
||||
if (argv[2][0] == 'r') {
|
||||
option = WSKBD_RAW;
|
||||
}
|
||||
} else {
|
||||
option = WSKBD_TRANSLATED;
|
||||
}
|
||||
if (ioctl(fd, WSKBDIO_SETMODE, &option) < 0) {
|
||||
perror("SETMODE RAW");
|
||||
return 1;
|
||||
}
|
||||
if (option == WSKBD_RAW) {
|
||||
printf("mode RAW\n");
|
||||
} else {
|
||||
printf("mode TRANSLATED\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
printf("entering loop\n");
|
||||
done = 0;
|
||||
while (!done) {
|
||||
if (option == WSKBD_TRANSLATED) {
|
||||
n = read(fd, &ev, sizeof(ev));
|
||||
printf("-> %d type: %d, value %d\n",
|
||||
n, ev.type, ev.value);
|
||||
} else {
|
||||
struct pollfd pfd[1];
|
||||
pfd[0].fd = fd;
|
||||
pfd[0].events = POLLIN;
|
||||
|
||||
n = poll(pfd, 1, INFTIM);
|
||||
if (n <= 0) {
|
||||
printf("nothing %d\n", n);
|
||||
continue;
|
||||
}
|
||||
n = read(fd, buf, sizeof(buf));
|
||||
printf("-> %d\r\n", n);
|
||||
for (i = 0; i < n; i++) {
|
||||
printf(" 0x%02x\r\n", buf[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
tcsetattr(fd, TCSANOW, &okbdtty);
|
||||
option = WSKBD_TRANSLATED;
|
||||
ioctl(fd, WSKBDIO_SETMODE, &option);
|
||||
exit(0);
|
||||
}
|
38
tvtswitch.c
Normal file
38
tvtswitch.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include <sys/time.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fd, vtnum;
|
||||
struct wsdisplay_addscreendata screendata;
|
||||
struct timeval t0, t1, dt;
|
||||
|
||||
fd = open("/dev/ttyC0", O_RDWR);
|
||||
if (fd < 0)
|
||||
err(2, "open /dev/ttyC0");
|
||||
|
||||
if (argc == 2) {
|
||||
vtnum = atoi(argv[1]);
|
||||
gettimeofday(&t0, NULL);
|
||||
if (ioctl(fd, WSDISPLAYIO_SETSCREEN, &vtnum) < 0)
|
||||
err(2, "SETSCREEN");
|
||||
gettimeofday(&t1, NULL);
|
||||
timersub(&t1, &t0, &dt);
|
||||
printf("vt switch took %lu %ld %lf ms\n",
|
||||
(unsigned long)dt.tv_sec, (long)dt.tv_usec,
|
||||
dt.tv_usec/1000.0);
|
||||
}
|
||||
screendata.idx = -1;
|
||||
if (ioctl(fd, WSDISPLAYIO_GETSCREEN, &screendata) < 0)
|
||||
err(2, "GETSCREEN");
|
||||
printf("Current VT: %d %s %s\n", screendata.idx,
|
||||
screendata.screentype, screendata.emul);
|
||||
exit(0);
|
||||
}
|
115
twskbd.c
Normal file
115
twskbd.c
Normal file
|
@ -0,0 +1,115 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
#include <dev/wscons/wsdisplay_usl_io.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
volatile int done = 0;
|
||||
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
errx(2, "usage: twskbd [-rR] [-v version]");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sighandler(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct wscons_event ev;
|
||||
struct wscons_event_ex evx;
|
||||
struct termios kbdtty, okbdtty;
|
||||
int ch, fd, n, option = 0;
|
||||
char *dev;
|
||||
unsigned int type;
|
||||
unsigned char buf[1];
|
||||
bool raw = false;
|
||||
bool reset = false;
|
||||
int version = 0;
|
||||
|
||||
while ((ch = getopt(argc, argv, "rRv:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'r':
|
||||
raw = true;
|
||||
break;
|
||||
case 'R':
|
||||
reset = true;
|
||||
break;
|
||||
case 'v':
|
||||
version = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
signal(SIGINT, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
|
||||
printf("Signals installed\n");
|
||||
dev = argv[0] != NULL ? argv[0]:"/dev/wskbd";
|
||||
if ((fd = open(dev, O_RDWR)) == -1)
|
||||
err(1, "open '%s'", dev);
|
||||
tcgetattr(fd, &kbdtty);
|
||||
okbdtty = kbdtty;
|
||||
cfmakeraw(&kbdtty);
|
||||
/* kbdtty.c_cc[VTIME] = 0;
|
||||
kbdtty.c_cc[VMIN] = 1; */
|
||||
tcsetattr(fd, TCSANOW, &kbdtty);
|
||||
|
||||
if (version > 0)
|
||||
if (ioctl(fd, WSKBDIO_SETVERSION, &version) == -1)
|
||||
err(1, "SETVERSION %d", version);
|
||||
if (raw)
|
||||
option = WSKBD_RAW;
|
||||
|
||||
if (ioctl(fd, WSKBDIO_SETMODE, &option) == -1)
|
||||
err(1, "SETMODE RAW");
|
||||
|
||||
if (ioctl(fd, WSKBDIO_GTYPE, &type) == -1)
|
||||
err(2, "ioctl WSKBDIO_GTYPE");
|
||||
printf("keyboard type: %ud\n", type);
|
||||
if (reset)
|
||||
exit(0);
|
||||
printf("entering loop\n");
|
||||
done = 0;
|
||||
while (!done) {
|
||||
if (!raw) {
|
||||
if (version == 0) {
|
||||
n = read(fd, &ev, sizeof(ev));
|
||||
printf("%d dev: %#x, type: %#x, value %#x\n", n,
|
||||
/* ev.device */ 0, ev.type, ev.value);
|
||||
} else {
|
||||
n = read(fd, &evx, sizeof(evx));
|
||||
printf("%d dev: %#x, type: %#x, value %#x\n", n,
|
||||
evx.device, evx.type, evx.value);
|
||||
}
|
||||
} else {
|
||||
n = read(fd, buf, sizeof buf);
|
||||
printf("-> %d\n", n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf("0x%02x\n", buf[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
tcsetattr(fd, TCSANOW, &okbdtty);
|
||||
option = WSKBD_TRANSLATED;
|
||||
ioctl(fd, WSKBDIO_SETMODE, &option);
|
||||
exit(0);
|
||||
}
|
71
twsmouse.c
Normal file
71
twsmouse.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/* wsmouse events dump */
|
||||
#include <sys/time.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fd, n;
|
||||
char *dev;
|
||||
struct wscons_event event;
|
||||
|
||||
if (argc == 2) {
|
||||
dev = argv[1];
|
||||
} else {
|
||||
dev = "/dev/wsmouse";
|
||||
}
|
||||
|
||||
fd = open(dev, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
n = read(fd, &event, sizeof(struct wscons_event));
|
||||
if (n <= 0) {
|
||||
perror("read");
|
||||
}
|
||||
// printf("device: %#x: ", event.device);
|
||||
switch (event.type) {
|
||||
case WSCONS_EVENT_MOUSE_UP:
|
||||
printf("MOUSE_UP: 0x%x\n", event.value);
|
||||
break;
|
||||
case WSCONS_EVENT_MOUSE_DOWN:
|
||||
printf("MOUSE_DOWN: 0x%x\n", event.value);
|
||||
break;
|
||||
case WSCONS_EVENT_MOUSE_DELTA_X:
|
||||
printf("MOUSE_DELTA_X: %d\n", event.value);
|
||||
break;
|
||||
case WSCONS_EVENT_MOUSE_DELTA_Y:
|
||||
printf("MOUSE_DELTA_Y: %d\n", event.value);
|
||||
break;
|
||||
#ifdef WSCONS_EVENT_MOUSE_DELTA_Z
|
||||
case WSCONS_EVENT_MOUSE_DELTA_Z:
|
||||
printf("MOUSE_DELTA_Z: %d\n", event.value);
|
||||
break;
|
||||
#endif
|
||||
#ifdef WSCONS_EVENT_MOUSE_ABSOLUTE_Z
|
||||
case WSCONS_EVENT_MOUSE_ABSOLUTE_Z:
|
||||
printf("MOUSE_ABSOLUTE_Z: %d\n", event.value);
|
||||
break;
|
||||
#endif
|
||||
case WSCONS_EVENT_MOUSE_ABSOLUTE_X:
|
||||
printf("MOUSE_ABSOLUTE_X: %d\n", event.value);
|
||||
break;
|
||||
case WSCONS_EVENT_MOUSE_ABSOLUTE_Y:
|
||||
printf("MOUSE_ABSOLUTE_Y: %d\n", event.value);
|
||||
break;
|
||||
case WSCONS_EVENT_SYNC:
|
||||
printf("SYNC\n");
|
||||
break;
|
||||
default:
|
||||
printf("unknown event type 0x%x, value 0x%x\n",
|
||||
event.type, event.value);
|
||||
}
|
||||
}
|
||||
}
|
59
twsmux-kq.c
Normal file
59
twsmux-kq.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/time.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct kevent ev;
|
||||
char *device;
|
||||
int fd, kq, kev;
|
||||
|
||||
if (argc == 2)
|
||||
device = argv[1];
|
||||
else
|
||||
device = "/dev/wskbd";
|
||||
|
||||
fd = open(device, O_RDWR);
|
||||
if (fd == -1)
|
||||
err(2, "open %s", device);
|
||||
|
||||
if ((kq = kqueue()) <= 0)
|
||||
err(2, "kqueue");
|
||||
|
||||
EV_SET(&ev, fd, EVFILT_DEVICE, EV_ADD | EV_ENABLE | EV_CLEAR,
|
||||
NOTE_CHG_DATA, 0, NULL);
|
||||
if (kevent(kq, &ev, 1, NULL, 0, NULL) < 0)
|
||||
err(2, "kevent init");
|
||||
|
||||
while (1) {
|
||||
#if 0
|
||||
struct pollfd fds;
|
||||
int result;
|
||||
|
||||
fds.fd = kq;
|
||||
fds.events = POLLIN;
|
||||
result = poll(&fds, 1, INFTIM);
|
||||
printf("poll result %d\n", result);
|
||||
#endif
|
||||
kev = kevent(kq, NULL, 0, &ev, 1, NULL);
|
||||
printf("kevent -> %d\n", kev);
|
||||
if (kev < 0)
|
||||
err(2, "kevent");
|
||||
if (kev /* && ev.fflags & NOTE_CHG_DATA */) {
|
||||
printf("kevent triggered %lx %hd %hx %x %lld\n",
|
||||
ev.ident, ev.filter, ev.flags, ev.fflags, ev.data);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
35
twsmux.c
Normal file
35
twsmux.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
#include <dev/wscons/wsdisplay_usl_io.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int fd, i;
|
||||
struct wsmux_device_list devs;
|
||||
|
||||
if ((fd = open(argv[1] != NULL ? argv[1]:"/dev/wskbd", O_RDONLY)) < 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
if (ioctl(fd, WSMUXIO_LIST_DEVICES, &devs) < 0) {
|
||||
perror("LIST_DEVICES");
|
||||
return 1;
|
||||
}
|
||||
printf("devices: %d\n", devs.ndevices);
|
||||
for (i = 0; i < devs.ndevices; i++) {
|
||||
printf("device %d type %d idx %d\n", i, devs.devices[i].type,
|
||||
devs.devices[i].idx);
|
||||
}
|
||||
/*
|
||||
while (1) {
|
||||
n = read(fd, &ev, sizeof(ev));
|
||||
printf("type: %d, value %d\n", ev.type, ev.value);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
48
wsmouse_type.c
Normal file
48
wsmouse_type.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
char *device;
|
||||
int fd, wsmouse_type;
|
||||
|
||||
if (argc == 1)
|
||||
device = "/dev/wsmouse0";
|
||||
else
|
||||
device = argv[1];
|
||||
|
||||
fd = open(device, O_RDONLY);
|
||||
if (fd < 0)
|
||||
err(2, "open %s", device);
|
||||
|
||||
if (ioctl(fd, WSMOUSEIO_GTYPE, &wsmouse_type) == -1)
|
||||
err(2,"ioctl get mouse type");
|
||||
|
||||
|
||||
switch (wsmouse_type) {
|
||||
case WSMOUSE_TYPE_SYNAP_SBTN:
|
||||
printf("SYNAP_SBTN\n");
|
||||
break;
|
||||
case WSMOUSE_TYPE_SYNAPTICS:
|
||||
printf("SYNAPTICS\n");
|
||||
break;
|
||||
case WSMOUSE_TYPE_ALPS:
|
||||
printf("ALPS\n");
|
||||
break;
|
||||
case WSMOUSE_TYPE_TOUCHPAD:
|
||||
printf("TOUCHPAD\n");
|
||||
break;
|
||||
case WSMOUSE_TYPE_ELANTECH:
|
||||
printf("ELANTECH\n");
|
||||
break;
|
||||
default:
|
||||
printf("unkonwn type %d\n", wsmouse_type);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue