projects
/
sball
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
communication seems to work now reliably in canonical mode, with full
[sball]
/
src
/
sball.c
diff --git
a/src/sball.c
b/src/sball.c
index
4b03040
..
3273480
100644
(file)
--- a/
src/sball.c
+++ b/
src/sball.c
@@
-10,6
+10,7
@@
#include <termios.h>
#include <sys/select.h>
#include <sys/time.h>
#include <termios.h>
#include <sys/select.h>
#include <sys/time.h>
+#include <sys/ioctl.h>
#define INP_BUF_SZ 256
#define INP_BUF_SZ 256
@@
-54,7
+55,7
@@
struct sball *sball_open(const char *dev)
char buf[128];
struct sball *sb = 0;
char buf[128];
struct sball *sb = 0;
- if((fd = open(dev, O_RDWR | O_NOCTTY)) == -1) {
+ if((fd = open(dev, O_RDWR | O_NOCTTY | O_NONBLOCK)) == -1) {
fprintf(stderr, "sball_open: failed to open device: %s: %s\n", dev, strerror(errno));
return 0;
}
fprintf(stderr, "sball_open: failed to open device: %s: %s\n", dev, strerror(errno));
return 0;
}
@@
-70,8
+71,9
@@
struct sball *sball_open(const char *dev)
if(stty_sball(fd) == -1) {
goto err;
}
if(stty_sball(fd) == -1) {
goto err;
}
+ write(fd, "\r@RESET\r", 8);
- if((sz = read_timeout(fd, buf, sizeof buf - 1, 2000000)) > 0 && memcmp(buf, "\r@1", 3) == 0) {
+ if((sz = read_timeout(fd, buf, sizeof buf - 1, 2000000)) > 0 && strstr(buf, "\r@1")) {
/* we got a response, so it's a spaceball */
make_printable(buf, sz);
printf("Spaceball detected: %s\n", buf);
/* we got a response, so it's a spaceball */
make_printable(buf, sz);
printf("Spaceball detected: %s\n", buf);
@@
-80,7
+82,7
@@
struct sball *sball_open(const char *dev)
printf("%d buttons\n", sb->nbuttons);
/* set binary mode and enable automatic data packet sending */
printf("%d buttons\n", sb->nbuttons);
/* set binary mode and enable automatic data packet sending */
- write(fd, "\rCB\rMSS\r", 8);
+ write(fd, "\rCB\rMSSV\r", 9);
sb->parse = sball_parsepkt;
return sb;
sb->parse = sball_parsepkt;
return sb;
@@
-161,6
+163,7
@@
int sball_num_buttons(struct sball *sb)
/* Labtec spaceball: 9600 8n1 XON/XOFF */
static int stty_sball(int fd)
{
/* Labtec spaceball: 9600 8n1 XON/XOFF */
static int stty_sball(int fd)
{
+ int status;
struct termios term;
if(tcgetattr(fd, &term) == -1) {
struct termios term;
if(tcgetattr(fd, &term) == -1) {
@@
-169,12
+172,17
@@
static int stty_sball(int fd)
}
term.c_oflag = 0;
}
term.c_oflag = 0;
- term.c_lflag = 0;
+ term.c_lflag = ICANON;
term.c_cc[VMIN] = 0;
term.c_cc[VMIN] = 0;
- term.c_cc[VTIME] = 1;
+ term.c_cc[VTIME] = 0;
+ term.c_cc[VEOF] = 0;
+ term.c_cc[VEOL] = '\r';
+ term.c_cc[VEOL2] = 0;
+ term.c_cc[VERASE] = 0;
+ term.c_cc[VKILL] = 0;
term.c_cflag = CLOCAL | CREAD | CS8 | HUPCL;
term.c_cflag = CLOCAL | CREAD | CS8 | HUPCL;
- term.c_iflag = IGNBRK | IGNPAR | IXON | IXOFF;
+ term.c_iflag = IGNBRK | IGNPAR;
cfsetispeed(&term, B9600);
cfsetospeed(&term, B9600);
cfsetispeed(&term, B9600);
cfsetospeed(&term, B9600);
@@
-184,12
+192,17
@@
static int stty_sball(int fd)
return -1;
}
return -1;
}
+ if(ioctl(fd, TIOCMGET, &status) != -1) {
+ status |= TIOCM_DTR | TIOCM_RTS;
+ ioctl(fd, TIOCMSET, &status);
+ }
return 0;
}
/* Logicad magellan spacemouse: 9600 8n2 CTS/RTS */
static int stty_mag(int fd)
{
return 0;
}
/* Logicad magellan spacemouse: 9600 8n2 CTS/RTS */
static int stty_mag(int fd)
{
+ int status;
struct termios term;
if(tcgetattr(fd, &term) == -1) {
struct termios term;
if(tcgetattr(fd, &term) == -1) {
@@
-198,9
+211,14
@@
static int stty_mag(int fd)
}
term.c_oflag = 0;
}
term.c_oflag = 0;
- term.c_lflag = 0;
+ term.c_lflag = ICANON;
term.c_cc[VMIN] = 0;
term.c_cc[VMIN] = 0;
- term.c_cc[VTIME] = 1;
+ term.c_cc[VTIME] = 0;
+ term.c_cc[VEOF] = 0;
+ term.c_cc[VEOL] = '\r';
+ term.c_cc[VEOL2] = 0;
+ term.c_cc[VERASE] = 0;
+ term.c_cc[VKILL] = 0;
term.c_cflag = CLOCAL | CREAD | CS8 | CSTOPB | HUPCL | CRTSCTS;
term.c_iflag = IGNBRK | IGNPAR;
term.c_cflag = CLOCAL | CREAD | CS8 | CSTOPB | HUPCL | CRTSCTS;
term.c_iflag = IGNBRK | IGNPAR;
@@
-208,11
+226,16
@@
static int stty_mag(int fd)
cfsetispeed(&term, B9600);
cfsetospeed(&term, B9600);
cfsetispeed(&term, B9600);
cfsetospeed(&term, B9600);
- if(tcsetattr(fd, TCSANOW, &term) == -1) {
+ if(tcsetattr(fd, TCSAFLUSH, &term) == -1) {
perror("sball_open: tcsetattr");
return -1;
}
perror("sball_open: tcsetattr");
return -1;
}
+ tcflush(fd, TCIOFLUSH);
+ if(ioctl(fd, TIOCMGET, &status) != -1) {
+ status |= TIOCM_DTR | TIOCM_RTS;
+ ioctl(fd, TIOCMGET, &status);
+ }
return 0;
}
return 0;
}