#include <errno.h>
#include <termios.h>
#include <unistd.h>
+#include <sys/ioctl.h>
#include <bno055_tty.h>
if(tcgetattr(fd,&tty)) return BNO055_ERROR;
if(cfsetspeed(&tty,B115200)) return BNO055_OUT_OF_RANGE;
cfmakeraw(&tty);
+ tty.c_cflag&=~CRTSCTS;
+ tty.c_cflag|=CLOCAL;
if(tcsetattr(fd,TCSANOW,&tty)) return BNO055_ERROR;
+ int status=TIOCM_DTR | TIOCM_RTS;
+ ioctl(fd,TIOCMBIC,&status);
+
bno055->bus_write=BNO055_tty_write;
bno055->bus_read=BNO055_tty_read;
bno055->delay_msec=BNO055_tty_delay_ms;
u8 i=0;
int n=0;
+ tcflush(dev_addr,TCIOFLUSH);
array[0]=BNO055_UART_START;
array[1]=BNO055_UART_WRITE_CMD;
array[2]=reg_addr;
// Add a timeout? KISS approach for now...
n=0;
while(n < 2) if((n+=read(dev_addr,array+n,2-n))==-1) return BNO055_ERROR;
-
if(array[0] != BNO055_UART_ACK ||
array[1] != BNO055_UART_SUCCESS) return BNO055_ERROR;
int n=0;
int length=0;
+ tcflush(dev_addr,TCIOFLUSH);
array[0]=BNO055_UART_START;
array[1]=BNO055_UART_READ_CMD;
array[2]=reg_addr;
array[3]=cnt;
if(write(dev_addr,array,4)==-1) return BNO055_ERROR;
-
+
// Add a timeout? KISS approach for now...
n=0;
while(n < 2) if((n+=read(dev_addr,array+n,2-n))==-1) return BNO055_ERROR;
-
switch(array[0])
{
void usage_help(const char *name)
{
- fprintf(stderr,"Usage: %s [-i i2c_address] [-t tty_device]\n",name);
+ fprintf(stderr,"Usage: %s -i i2c_address | -t tty_device\n",name);
exit(EXIT_FAILURE);
}
case 't':
/* TTY interface */
- if((fd=open(optarg,O_RDWR))==-1)
+ if((fd=open(optarg,O_RDWR | O_NOCTTY))==-1)
{
perror(argv[0]);
return -errno;