53,12 → 53,13 |
|
#define BC_Addr 0x0B |
#define US_Addr 0x70 // 0xE0 in fact |
#define PIC_Addr 0x50 // 0xA0 in fact |
|
char vystup[30]; |
char flag; |
pthread_t thread_id; |
FILE *pRouraO,*pRouraI; |
unsigned int vzdalenost; |
char command,ble; |
|
void *print_tele(void *unused); |
|
121,34 → 122,33 |
|
//!------ US --------------------------------------------------------------------------- |
|
pthread_create(&thread_id, NULL, print_tele, NULL); |
|
while(true) |
{ |
if (ioctl(file, I2C_SLAVE, US_Addr) == -1) |
{ |
fprintf(stderr, "Failed to set address to 0x%02x.\n", US_Addr); |
DoExit(-6); |
} |
|
pthread_create(&thread_id, NULL, print_tele, NULL); |
flag = 0; |
|
while(true) |
{ |
Buf[0]=0x0; |
Buf[1]=0x51; |
write(file, Buf, 2); |
usleep(80000); |
read(file, Buf, 3); |
if (flag==0) |
vzdalenost=(Buf[1]*256+Buf[2]); |
// printf("Vzdalenost: %u cm\n",ble); |
usleep(300000); |
|
/* |
if (0==flag) |
if (ioctl(file, I2C_SLAVE, PIC_Addr) == -1) |
{ |
sprintf(vystup,"Vzdalenost: %u cm\n",vzdalenost); |
fprintf(stderr, "Failed to set address to 0x%02x.\n", US_Addr); |
DoExit(-6); |
} |
Buf[0]=command; |
write(file, Buf, 1); |
read(file, Buf, 1); |
ble=Buf[0]; |
}; |
*/ |
usleep(300000); |
}; |
close(file); |
pthread_join(thread_id, NULL); |
fclose(pRouraO); |
158,19 → 158,13 |
|
void *print_tele(void *unused) |
{ |
flag=0; |
|
while(1) |
{ |
char pom; |
|
pRouraI = fopen("/home/ble/pipe","r"); |
pom=fgetc(pRouraI); |
command=fgetc(pRouraI); |
fclose(pRouraI); |
flag=1; |
pRouraO = fopen("/home/ble/pipe","w"); |
fprintf(pRouraO,"Vzdalenost: %u cm\n",vzdalenost); |
fprintf(pRouraO,"Vzdalenost: %u cm Command: %x\n",vzdalenost,ble); |
fclose(pRouraO); |
flag=0; |
} |
} |