Commit 13c80fc6 authored by Ivan Tyagov's avatar Ivan Tyagov

Be more verbose and show address of I2C slave.

parent 9210bf74
...@@ -42,14 +42,14 @@ static int setRelayState(int command, int i2c_addr) { ...@@ -42,14 +42,14 @@ static int setRelayState(int command, int i2c_addr) {
file = open(I2C_BLOCK_DEVICE_NAME, O_RDWR); file = open(I2C_BLOCK_DEVICE_NAME, O_RDWR);
if (file < 0) { if (file < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */ /* ERROR HANDLING; you can check errno to see what went wrong */
printf("Error openind i2c device.\n"); printf("Error opening i2c device (0x%x).\n", i2c_addr);
exit(1); exit(1);
} }
// step 2: address the slave by its address // step 2: address the slave by its address
if (ioctl(file, I2C_SLAVE, i2c_addr) < 0) { if (ioctl(file, I2C_SLAVE, i2c_addr) < 0) {
/* ERROR HANDLING; you can check errno to see what went wrong */ /* ERROR HANDLING; you can check errno to see what went wrong */
printf("Error addressing i2c slave.\n"); printf("Error addressing i2c slave (0x%x).\n", i2c_addr);
exit(1); exit(1);
} }
...@@ -62,7 +62,7 @@ static int setRelayState(int command, int i2c_addr) { ...@@ -62,7 +62,7 @@ static int setRelayState(int command, int i2c_addr) {
buf[2] = 0x65; // seems irrelevant the value buf[2] = 0x65; // seems irrelevant the value
if (write(file, buf, 3) != 3) { if (write(file, buf, 3) != 3) {
/* ERROR HANDLING: i2c transaction failed */ /* ERROR HANDLING: i2c transaction failed */
printf("Error writing to i2c slave.\n"); printf("Error writing to i2c slave (0x%x).\n", i2c_addr);
} }
close(file); close(file);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment