aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index b9eb4d0..4c7e13c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -22,7 +22,7 @@
#include "hih61xx.h"
#include "hmc5883.h"
-#define VERSION 1.28
+#define VERSION 1.30
#ifndef _BUILD_TIME_
#define _BUILD_TIME_ __DATE__" "__TIME__
#endif
@@ -96,6 +96,7 @@ __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, _
usleep(waitlen*1000); //# Wait 10ms for reading
if(read(devicef, buf, rdlen) != rdlen) { //# read the result
fprintf (stdout, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
+ close(devicef);
exit(EXIT_FAILURE);
}
@@ -107,6 +108,7 @@ __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, _
usleep(waitlen*1000); //# Wait 10ms for reading
if((data = i2c_smbus_read_word_data(devicef, buf[0])) < 0) { //# read the result
fprintf (stdout, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__);
+ close(devicef);
exit(EXIT_FAILURE);
} else {
buf[0] = data & 0x0FF;
@@ -161,7 +163,8 @@ int main( int argc, char *argv[] ){
if (ioctl(devicef, I2C_FUNCS, &funcs) < 0) { //Get i2c device features
fprintf (stdout, "\n\tAdapter function error [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__);
- exit(EXIT_FAILURE);
+ close(devicef);
+ exit(EXIT_FAILURE);
}
@@ -173,10 +176,12 @@ int main( int argc, char *argv[] ){
if (ioctl(devicef, I2C_SLAVE_FORCE, addr) < 0){ //# Seeking/Opening the device on the Bus
//printf("\n\tCan't open i2c DEVICE, errno: %d\n\n",errno);
fprintf (stdout, "\n\tCan't open i2c DEVICE! [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__);
+ close(devicef);
exit(EXIT_FAILURE);
}
} else {
printf("\n\tThe DEVICE address must be a hexadecimal number\n\n");
+ close(devicef);
exit(EXIT_FAILURE);
}
preinit((char *)argv[3]); //Initialization of subcommands