From 89402128bb7e993a375cf54476e3627826dc071c Mon Sep 17 00:00:00 2001 From: Gergő J. Miklós Date: Fri, 16 Oct 2020 23:47:49 +0200 Subject: i2sensors: some errorhandling --- src/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index d9644be..3ba3da3 100644 --- a/src/main.c +++ b/src/main.c @@ -100,11 +100,11 @@ __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, _ #ifdef WITH_I2C_SMBUS } else if ( funcs && I2C_FUNC_SMBUS_WORD_DATA ){ - if(i2c_smbus_write_byte(devicef, buf[0] ) == -1){ //# write one byte to device + if(i2c_smbus_write_byte(devicef, buf[0] ) < 0){ //# write one byte to device fprintf (stderr, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); } usleep(waitlen*1000); //# Wait 10ms for reading - if((data = i2c_smbus_read_word_data(devicef, buf[0])) == -1) { //# read the result + if((data = i2c_smbus_read_word_data(devicef, buf[0])) < 0) { //# read the result fprintf (stderr, "I2C read error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); } else { buf[0] = data & 0x0FF; @@ -166,9 +166,9 @@ int main( int argc, char *argv[] ){ if( argc > 4 ){ //If not get_info was called if(argv[4][0]=='0' && argv[4][1]=='x'){ //# Hexadecimal representetion of device address - addr = (int)strtol(argv[4], NULL, 0); //# strtol() is working with hex-string correctly + addr = (long)strtol(argv[4], NULL, 0); //# strtol() is working with hex-string correctly - if (ioctl(devicef, I2C_SLAVE, addr) < 0){ //# Seeking/Opening the device on the Bus + 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 (stderr, "\n\tCan't open i2c DEVICE! [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__); exit(EXIT_FAILURE); -- cgit v1.2.3