1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#include <stdio.h>
#include <stdlib.h>
#include "cube.h"
#include <termios.h>
#include <fcntl.h>
#include <strings.h>
void cube_push (unsigned char data[8][8])
{
int x,y,i;
i= 0;
unsigned char buffer[200];
buffer[i++] = 0xff; // escape
buffer[i++] = 0x00; // reset to 0,0
for (x=0;x<8;x++)
{
for (y=0;y<8;y++)
{
buffer[i++] = data[x][y];
if (data[x][y] == 0xff)
{
buffer[i++] = data[x][y];
}
}
}
write(tty,&buffer,i);
}
int cube_init (const char* tty_path)
{
//FILE *ftty;
//ftty = fopen("/dev/ttyUSB0","a");
struct termios io;
//char *tty_path = "/dev/ttyUSB0";
//char *tty_path = "/dev/ttyUSB1";
//tty = open(tty_path, O_RDWR | O_NOCTTY | O_NDELAY); // <- ORIGINAL
tty = open(tty_path, O_RDWR);
if (tty <0) {perror(tty_path); exit(-1); }
bzero(&io, sizeof(io));
//io.c_cflag = B2400 | CRTSCTS | CS8 | CLOCAL | CREAD;
//io.c_cflag = B2400 | CRTSCTS | PARENB | CS8 | CLOCAL | CREAD;
io.c_cflag = B38400 | PARENB | CS8 | CLOCAL | CREAD;
//io.c_cflag = B19200 | PARENB | CS8 | CLOCAL | CREAD;
io.c_iflag = IGNPAR;
io.c_oflag = 0;
// set input mode (non-canonical, no echo,...)
io.c_lflag &= ~OPOST;
//io.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
io.c_cc[VTIME] = 0; // inter-character timer unused
io.c_cc[VMIN] = 0; // blocking read until 5 chars received
// Flush buffer
tcflush(tty, TCIFLUSH);
//cfsetospeed(&io, B1000000);
//cfsetispeed(&io, B1000000);
// write config to tty
tcsetattr(tty,TCSANOW,&io);
//fcntl(tty, F_SETFL, 0);
return 1;
}
|