From 47bda328c70858c3b61cddf8e1398ce7ab0ff700 Mon Sep 17 00:00:00 2001 From: Gergő J. Miklós Date: Fri, 6 Nov 2020 22:05:49 +0100 Subject: errors to stderr --- src/main.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index a87a82d..af37eb3 100644 --- a/src/main.c +++ b/src/main.c @@ -21,8 +21,8 @@ #include "lm75.h" #include "hih61xx.h" #include "hmc5883.h" - -#define VERSION 1.31 + +#define VERSION 1.032 #ifndef _BUILD_TIME_ #define _BUILD_TIME_ __DATE__" "__TIME__ #endif @@ -78,7 +78,7 @@ void print_help(void) { " i2sensors read_all 1 lm75 0x4f \n" " i2sensors read_one 1 lm75 0x4f 00,-1.35\n" "\n" ); - printf ("Version: v%1.2f, build: [%s] (gcc %s) \n\n",VERSION,_BUILD_TIME_,__VERSION__); + printf ("Version: v%1.3f, build: [%s] (gcc %s) \n\n",VERSION,_BUILD_TIME_,__VERSION__); } @@ -91,11 +91,11 @@ __uint8_t *xchg_data (__uint8_t *buf, __uint16_t wrlen, __uint16_t waitlen, _ if( funcs & I2C_FUNC_I2C ){ #endif if(write(devicef, buf, 1) != 1){ //# write one byte to device - fprintf (stdout, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); + 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(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__); + fprintf (stderr, "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); } @@ -103,11 +103,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] ) < 0){ //# write one byte to device - fprintf (stdout, "I2C write error: [NO: %d, MSG: %s] at %s, line %d. (function: %s)\n", errno, strerror(errno), __FILE__, __LINE__, __func__); + 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])) < 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__); + fprintf (stderr, "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 { @@ -157,12 +157,12 @@ int main( int argc, char *argv[] ){ snprintf(filename, 256, "/dev/i2c-%s", argv[2]); devicef = open(filename, O_RDWR); //# Open the i2c bus if (devicef < 0){ - printf("\n\tCan't open \"%s\" BUS. (Have you any permission?)\n\n", filename); + fprintf(stderr, "\n\tCan't open \"%s\" BUS. (Have you any permission?)\n\n", filename); exit(EXIT_FAILURE); } 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__); + fprintf (stderr, "\n\tAdapter function error [ERR: %d, MSG: %s] at %s, line %d. \n", errno, strerror(errno), __FILE__, __LINE__); close(devicef); exit(EXIT_FAILURE); } @@ -175,12 +175,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__); + fprintf (stderr, "\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"); + fprintf(stderr, "\n\tThe DEVICE address must be a hexadecimal number\n\n"); close(devicef); exit(EXIT_FAILURE); } -- cgit v1.2.3