mirror of
https://github.com/brmlab/ledbar.git
synced 2025-06-09 13:24:01 +02:00
Code reformatting and simple TUI
This commit is contained in:
parent
12fe9e8283
commit
6a241cc06b
2 changed files with 75 additions and 55 deletions
124
mux/mux.c
124
mux/mux.c
|
@ -11,83 +11,103 @@ int main() {
|
||||||
int rainbow, equalizer, serial;
|
int rainbow, equalizer, serial;
|
||||||
fd_set readers;
|
fd_set readers;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int r,s,w;
|
int r, s, w;
|
||||||
int reads_eq=0, reads_ra=0;
|
int reads_eq = 0, reads_ra = 0;
|
||||||
int source;
|
int source;
|
||||||
char buf_eq[65], buf_ra[65];
|
char buf_eq[65], buf_ra[65];
|
||||||
char *srcbuf=buf_eq;
|
char *srcbuf = buf_eq;
|
||||||
|
int c = 'a';
|
||||||
|
int tmp;
|
||||||
|
|
||||||
|
rainbow = open("/tmp/ledbar/rainbow", O_RDWR);
|
||||||
|
equalizer = open("/tmp/ledbar/equalizer", O_RDWR);
|
||||||
|
serial = open("/tmp/ledbar/serial", O_RDWR);
|
||||||
|
|
||||||
rainbow=open("/tmp/ledbar/rainbow", O_RDWR);
|
if(rainbow == -1 || equalizer == -1 || serial == -1) {
|
||||||
equalizer=open("/tmp/ledbar/equalizer", O_RDWR);
|
|
||||||
serial=open("/tmp/ledbar/serial", O_RDWR);
|
|
||||||
|
|
||||||
if(rainbow==-1 || equalizer==-1 || serial==-1) {
|
|
||||||
perror("Open failed");
|
perror("Open failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf( "****************************************\n"
|
||||||
|
"* Usage: press [r] for rainbow mode *\n"
|
||||||
|
"* press [e] for equalizer mode *\n"
|
||||||
|
"* press [a] for automatic mode *\n"
|
||||||
|
"****************************************\n");
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
tv.tv_sec=3;
|
tv.tv_sec = 3;
|
||||||
tv.tv_usec=0;
|
tv.tv_usec = 0;
|
||||||
FD_ZERO(&readers);
|
FD_ZERO(&readers);
|
||||||
FD_SET(rainbow, &readers);
|
FD_SET(rainbow, &readers);
|
||||||
FD_SET(equalizer, &readers);
|
FD_SET(equalizer, &readers);
|
||||||
s=select(equalizer+1, &readers, NULL, NULL, &tv);
|
FD_SET(fileno(stdin), &readers);
|
||||||
if(s==-1) {
|
|
||||||
|
s = select(equalizer+1, &readers, NULL, NULL, &tv);
|
||||||
|
if(s == -1) {
|
||||||
perror("select failed");
|
perror("select failed");
|
||||||
return 2;
|
return 2;
|
||||||
} else if(s) {
|
}
|
||||||
if(FD_ISSET(equalizer, &readers)) {
|
if(!s)
|
||||||
r=read(equalizer, buf_eq, sizeof(buf_eq)-1);
|
continue;
|
||||||
if(r==-1) {
|
|
||||||
perror("eq read");
|
if(FD_ISSET(fileno(stdin), &readers)) {
|
||||||
return 3;
|
tmp = getc(stdin);
|
||||||
}
|
if (tmp != '\r' && tmp != '\n') {
|
||||||
int i;
|
if(tmp != 'a' && tmp != 'r' && tmp != 'e')
|
||||||
for(i=0; i<r; i++) {
|
printf("Invalid command!\n");
|
||||||
if(buf_eq[i]) {
|
else
|
||||||
reads_eq++;
|
c = tmp;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(FD_ISSET(equalizer, &readers)) {
|
||||||
|
r=read(equalizer, buf_eq, sizeof(buf_eq) - 1);
|
||||||
|
if(r == -1) {
|
||||||
|
perror("eq read");
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < r; i++) {
|
||||||
|
if(buf_eq[i]) {
|
||||||
|
reads_eq++;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(FD_ISSET(rainbow, &readers)) {
|
}
|
||||||
r=read(rainbow, buf_ra, sizeof(buf_ra)-1);
|
if(FD_ISSET(rainbow, &readers)) {
|
||||||
if(r==-1) {
|
r=read(rainbow, buf_ra, sizeof(buf_ra) - 1);
|
||||||
perror("ra read");
|
if(r == -1) {
|
||||||
return 3;
|
perror("ra read");
|
||||||
}
|
return 3;
|
||||||
reads_ra++;
|
|
||||||
}
|
}
|
||||||
|
reads_ra++;
|
||||||
|
}
|
||||||
|
|
||||||
// printf("eq: %i ra: %i r: %i\n", reads_eq, reads_ra, r);
|
if (c == 'a') {
|
||||||
|
if(reads_eq > READS_THR) {
|
||||||
if(reads_eq>READS_THR) {
|
reads_eq = 0;
|
||||||
reads_eq=0;
|
reads_ra = 0;
|
||||||
reads_ra=0;
|
srcbuf = buf_eq;
|
||||||
if(srcbuf!=buf_eq)
|
} else if(reads_ra > READS_THR*RAINBOW_DIVISOR) {
|
||||||
printf("switching to equalizer\n");
|
reads_eq = 0;
|
||||||
srcbuf=buf_eq;
|
reads_ra = 0;
|
||||||
} else if(reads_ra>READS_THR*RAINBOW_DIVISOR) {
|
srcbuf = buf_ra;
|
||||||
reads_eq=0;
|
|
||||||
reads_ra=0;
|
|
||||||
if(srcbuf!=buf_ra)
|
|
||||||
printf("switching to rainbow\n");
|
|
||||||
srcbuf=buf_ra;
|
|
||||||
}
|
}
|
||||||
|
} else if (c == 'r') {
|
||||||
|
srcbuf = buf_ra;
|
||||||
|
} else if (c == 'e') {
|
||||||
|
srcbuf = buf_eq;
|
||||||
|
}
|
||||||
|
|
||||||
if(write(serial, srcbuf, r)==-1) {
|
if(write(serial, srcbuf, r) == -1) {
|
||||||
perror("write failed");
|
perror("write failed");
|
||||||
return 4;
|
return 4;
|
||||||
}
|
|
||||||
// usleep(500);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close(serial);
|
close(serial);
|
||||||
close(rainbow);
|
close(rainbow);
|
||||||
close(equalizer);
|
close(equalizer);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue