Subversion Repositories svnkaklik

Rev

Rev 364 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 364 Rev 365
Line 49... Line 49...
49
#define I2C_SLAVE_FORCE	0x0706	/* Change slave address			*/
49
#define I2C_SLAVE_FORCE	0x0706	/* Change slave address			*/
50
				/* Attn.: Slave address is 7 or 10 bits */
50
				/* Attn.: Slave address is 7 or 10 bits */
51
				/* This changes the address, even if it */
51
				/* This changes the address, even if it */
52
				/* is already taken!	*/
52
				/* is already taken!	*/
53
 
53
 
54
#define BC_Addr	0x0B
54
#define BC_Addr	    0x0B
55
#define US_Addr	0x70 // 0xE0 in fact
55
#define US_Addr	    0x70 // 0xE0 in fact
-
 
56
#define PIC_Addr	0x50 // 0xA0 in fact
56
 
57
 
57
char vystup[30];
58
char vystup[30];
58
char flag;
-
 
59
pthread_t thread_id;
59
pthread_t thread_id;
60
FILE *pRouraO,*pRouraI;
60
FILE *pRouraO,*pRouraI;
61
unsigned int vzdalenost;
61
unsigned int vzdalenost;
-
 
62
char command,ble;
62
 
63
 
63
void *print_tele(void *unused);
64
void *print_tele(void *unused);
64
 
65
 
65
void DoExit(int ex)
66
void DoExit(int ex)
66
{
67
{
Line 119... Line 120...
119
    Buf[Len] = 0x00;
120
    Buf[Len] = 0x00;
120
    fprintf(stdout, "Board ID is %s.\n", Buf);
121
    fprintf(stdout, "Board ID is %s.\n", Buf);
121
 
122
 
122
//!------ US ---------------------------------------------------------------------------
123
//!------ US ---------------------------------------------------------------------------
123
 
124
 
124
    if (ioctl(file, I2C_SLAVE, US_Addr) == -1)
-
 
125
    {
-
 
126
        fprintf(stderr, "Failed to set address to 0x%02x.\n", US_Addr);
-
 
127
        DoExit(-6);
-
 
128
    }
-
 
129
 
-
 
130
    pthread_create(&thread_id, NULL, print_tele, NULL);
125
    pthread_create(&thread_id, NULL, print_tele, NULL);
131
    flag = 0;
-
 
132
 
126
 
133
    while(true)
127
    while(true)
134
    {
128
    {
-
 
129
        if (ioctl(file, I2C_SLAVE, US_Addr) == -1)
-
 
130
        {
-
 
131
            fprintf(stderr, "Failed to set address to 0x%02x.\n", US_Addr);
-
 
132
            DoExit(-6);
-
 
133
        }
135
        Buf[0]=0x0;
134
        Buf[0]=0x0;
136
        Buf[1]=0x51;
135
        Buf[1]=0x51;
137
        write(file, Buf, 2);
136
        write(file, Buf, 2);
138
        usleep(80000);
137
        usleep(80000);
139
        read(file, Buf, 3);
138
        read(file, Buf, 3);
140
        if (flag==0)
-
 
141
          vzdalenost=(Buf[1]*256+Buf[2]);
139
        vzdalenost=(Buf[1]*256+Buf[2]);
142
//        printf("Vzdalenost: %u cm\n",ble);
140
        usleep(300000);
143
 
141
 
144
 /*
-
 
145
        if (0==flag)
142
        if (ioctl(file, I2C_SLAVE, PIC_Addr) == -1)
146
        {
143
        {
147
            sprintf(vystup,"Vzdalenost: %u cm\n",vzdalenost);
144
            fprintf(stderr, "Failed to set address to 0x%02x.\n", US_Addr);
-
 
145
            DoExit(-6);
148
        };
146
        }
149
*/
147
        Buf[0]=command;
-
 
148
        write(file, Buf, 1);
-
 
149
        read(file, Buf, 1);
150
        usleep(300000);
150
        ble=Buf[0];
151
    };
151
    };
152
	close(file);
152
	close(file);
153
    pthread_join(thread_id, NULL);
153
    pthread_join(thread_id, NULL);
154
    fclose(pRouraO);
154
    fclose(pRouraO);
155
 
155
 
156
	return 0;
156
	return 0;
157
}
157
}
158
 
158
 
159
void *print_tele(void *unused)
159
void *print_tele(void *unused)
160
{
160
{
161
    flag=0;
-
 
162
 
-
 
163
    while(1)
161
    while(1)
164
    {
162
    {
165
        char pom;
-
 
166
 
-
 
167
        pRouraI = fopen("/home/ble/pipe","r");
163
        pRouraI = fopen("/home/ble/pipe","r");
168
        pom=fgetc(pRouraI);
164
        command=fgetc(pRouraI);
169
        fclose(pRouraI);
165
        fclose(pRouraI);
170
        flag=1;
-
 
171
        pRouraO = fopen("/home/ble/pipe","w");
166
        pRouraO = fopen("/home/ble/pipe","w");
172
        fprintf(pRouraO,"Vzdalenost: %u cm\n",vzdalenost);
167
        fprintf(pRouraO,"Vzdalenost: %u cm Command: %x\n",vzdalenost,ble);
173
        fclose(pRouraO);
168
        fclose(pRouraO);
174
        flag=0;
-
 
175
    }
169
    }
176
}
170
}