diff options
author | Gergő J. Miklós | 2020-11-04 02:02:32 +0100 |
---|---|---|
committer | Gergő J. Miklós | 2020-11-04 02:02:32 +0100 |
commit | d5d459a82b8cc0a03fab86f07a4bb68400d64efe (patch) | |
tree | b0e90c94c859232bc5b3f7b7ea5059456e11306e | |
parent | 816738fff33ffe3d0654be755c25626b3f4d2772 (diff) | |
download | i2sensors-d5d459a82b8cc0a03fab86f07a4bb68400d64efe.tar.gz i2sensors-d5d459a82b8cc0a03fab86f07a4bb68400d64efe.zip |
error halndling
-rw-r--r-- | src/main.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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 |