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/hih61xx.c | 2 +- src/lm75.c | 2 +- src/main.c | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/hih61xx.c b/src/hih61xx.c index cf00c04..92de893 100644 --- a/src/hih61xx.c +++ b/src/hih61xx.c @@ -152,7 +152,7 @@ void hih61xx_read_one(const uchar *opts) break; }else{ if( !isdigit(*(opts+i)) ){ //# Check the register string - printf("The Register address must be an integer!\n"); + fprintf(stderr, "The Register address must be an integer!\n"); print_help(); hih61xx_print_all(); exit (EXIT_FAILURE); diff --git a/src/lm75.c b/src/lm75.c index 2e14738..83e74c3 100644 --- a/src/lm75.c +++ b/src/lm75.c @@ -142,7 +142,7 @@ void lm75_read_one(const uchar *opts){ // Prints the selected r } else { if( !isdigit(*(opts+i)) ){ //# Check the register string - printf("The Register address must be an integer!\n"); + fprintf(stderr, "The Register address must be an integer!\n"); print_help(); lm75_print_all(); exit (EXIT_FAILURE); 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