Subversion Repositories HomeAutomation

Rev

Rev 337 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 337 Rev 338
Line 3... Line 3...
3
#include <fcntl.h>
3
#include <fcntl.h>
4
#include <termios.h>
4
#include <termios.h>
5
#include <unistd.h>
5
#include <unistd.h>
6
#include <stdio.h>
6
#include <stdio.h>
7
 
7
 
-
 
8
#define DEVICE "/dev/midi1"
-
 
9
#define BAUDRATE B115200
-
 
10
#define TRIG_LEVEL 128
-
 
11
#define SAMPLE_FREQ 1000
-
 
12
 
8
#define SAMPLES_PER_PLOT 200
13
#define SAMPLES_PER_PLOT 200
-
 
14
 
-
 
15
struct termios oldtio,newtio;
9
 
16
 
10
int main(int argc, char* argv[]) {
17
int main(int argc, char* argv[]) {
11
    int input;
18
    int input;
12
    FILE* gnuplot;
19
    FILE* gnuplot;
13
    int i;
20
    int i;
14
    float out_data;
21
    float out_data;
15
    unsigned char buf[SAMPLES_PER_PLOT];
22
    unsigned char buf[SAMPLES_PER_PLOT];
16
    unsigned char trig = 128;
23
    unsigned char trig = TRIG_LEVEL;
17
    unsigned freq = 1000;
24
    unsigned freq = SAMPLE_FREQ;
18
   
25
   
19
    input = open("/dev/midi1", O_RDONLY);
26
    input = open(DEVICE, O_RDONLY | O_NOCTTY);
-
 
27
    if (input <0) {perror(DEVICE); return -1; }
20
    gnuplot = popen("gnuplot", "w");
28
    gnuplot = popen("gnuplot", "w");
-
 
29
   
-
 
30
    tcgetattr(input,&oldtio); /* save current port settings */
-
 
31
   
-
 
32
    // bzero not defined? moving newtio outside main to zero it. 
-
 
33
    //bzero(&newtio, sizeof(newtio));
-
 
34
    newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
-
 
35
    newtio.c_iflag = IGNPAR;
-
 
36
    newtio.c_oflag = 0;
-
 
37
   
-
 
38
    /* set input mode (non-canonical, no echo,...) */
-
 
39
    newtio.c_lflag = 0;
-
 
40
   
-
 
41
    newtio.c_cc[VTIME]    = 0;   /* inter-character timer unused */
-
 
42
    newtio.c_cc[VMIN]     = SAMPLES_PER_PLOT;   /* blocking read until all samples received */
-
 
43
   
-
 
44
    tcflush(input, TCIFLUSH);
-
 
45
    tcsetattr(input,TCSANOW,&newtio);
21
   
46
   
22
    fprintf(gnuplot, "set yrange [-0.1:5.1]\n");
47
    fprintf(gnuplot, "set yrange [-0.1:5.1]\n");
23
    while(1) {
48
    while(1) {
24
        // Wait for trig
49
        // Wait for trig
25
        do {
50
        do {
Line 43... Line 68...
43
        }
68
        }
44
        fprintf(gnuplot, "e\n"); // Display output
69
        fprintf(gnuplot, "e\n"); // Display output
45
        fflush(gnuplot);
70
        fflush(gnuplot);
46
    }
71
    }
47
   
72
   
-
 
73
    tcsetattr(input,TCSANOW,&oldtio);
48
    close(input);
74
    close(input);
49
    pclose(gnuplot);
75
    pclose(gnuplot);
50
    printf("\n");
76
    printf("\n");
51
    return 0;
77
    return 0;
52
}
78
}