Subversion Repositories svnkaklik

Rev

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

Rev 374 Rev 376
Line 105... Line 105...
105
 
105
 
106
	fprintf(stdout, "\n **** Change I2C Address **** \n \r");
106
	fprintf(stdout, "\n **** Change I2C Address **** \n \r");
107
 
107
 
108
    if (argc<2)
108
    if (argc<2)
109
    {
109
    {
110
        printf("Use:\n%s OldAddress NewAddress - for change address\nOR\n%s Address - for echo\n\r",argv[0],argv[0]);
110
        printf("Use:\n%s OldAddress NewAddress - for change address\nOR\n%s Address - for echo\n\n\r",argv[0],argv[0]);
111
        return 0;
111
        return 0;
112
    }
112
    }
113
 
113
 
114
    i2c_init();
114
    i2c_init();
115
 
115
 
116
    sscanf(argv[1],"%x",&OldAddress);
116
    sscanf(argv[1],"%x",&OldAddress);
117
 
117
 
118
    if (argc==2)
118
    if (argc==2)
119
    {
119
    {
120
        echo(OldAddress);
-
 
121
        printf("Vzdalenost: %d\n", echo(NewAddress));
120
        printf("Vzdalenost: %d\n", echo(OldAddress>>1));
122
        close(file);
121
        close(file);
123
        return 0;
122
        return 0;
124
    }
123
    }
125
 
124
 
126
    sscanf(argv[2],"%x",&NewAddress);
125
    sscanf(argv[2],"%x",&NewAddress);
127
 
126
 
128
    printf("Old: %x New: %x\n", OldAddress, NewAddress);
127
    printf("Old: %x New: %x\n", OldAddress, NewAddress);
129
 
128
 
130
    echo(OldAddress);
-
 
131
    printf("Vzdalenost: %d\n", echo(NewAddress));
129
    printf("Vzdalenost: %d\n", echo(OldAddress>>1));
132
 
130
 
133
    I2C_addr(OldAddress);
131
    I2C_addr(OldAddress>>1);
134
    Buf[0]=0x0;
132
    Buf[0]=0x0;
135
    Buf[1]=0xA0;
133
    Buf[1]=0xA0;
-
 
134
    write(file, Buf, 2);
-
 
135
    I2C_addr(OldAddress>>1);
-
 
136
    Buf[0]=0x0;
136
    Buf[2]=0xAA;
137
    Buf[1]=0xAA;
-
 
138
    write(file, Buf, 2);
-
 
139
    I2C_addr(OldAddress>>1);
-
 
140
    Buf[0]=0x0;
137
    Buf[3]=0xA5;
141
    Buf[1]=0xA5;
-
 
142
    write(file, Buf, 2);
-
 
143
    I2C_addr(OldAddress>>1);
-
 
144
    Buf[0]=0x0;
138
    Buf[4]=(unsigned char)NewAddress;
145
    Buf[1]=NewAddress;
139
    write(file, Buf, 5);
146
    write(file, Buf, 2);
-
 
147
 
140
 
148
 
141
    usleep(100000);
149
    usleep(100000);
142
 
150
 
143
    echo(NewAddress);
-
 
144
    printf("Vzdalenost: %d\n", echo(NewAddress));
151
    printf("Vzdalenost: %d\n", echo(NewAddress>>1));
145
 
152
 
146
	close(file);
153
	close(file);
147
	return 0;
154
	return 0;
148
}
155
}