Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 364 → Rev 365

/roboti/Robotour/SW/board/main.cpp
51,14 → 51,15
/* This changes the address, even if it */
/* is already taken! */
 
#define BC_Addr 0x0B
#define US_Addr 0x70 // 0xE0 in fact
#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,33 → 122,32
 
//!------ US ---------------------------------------------------------------------------
 
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)
{
if (ioctl(file, I2C_SLAVE, US_Addr) == -1)
{
fprintf(stderr, "Failed to set address to 0x%02x.\n", US_Addr);
DoExit(-6);
}
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);
vzdalenost=(Buf[1]*256+Buf[2]);
usleep(300000);
 
/*
if (0==flag)
if (ioctl(file, I2C_SLAVE, PIC_Addr) == -1)
{
sprintf(vystup,"Vzdalenost: %u cm\n",vzdalenost);
};
*/
usleep(300000);
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];
};
close(file);
pthread_join(thread_id, NULL);
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;
}
}