diff options
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | io-module/mts_io_module.h | 2 | ||||
| -rw-r--r-- | io-module/spi.c | 45 | 
3 files changed, 36 insertions, 13 deletions
| diff --git a/configure.ac b/configure.ac index 7970d9c..b8b04d3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([mts-io], [4.4.5]) +AC_INIT([mts-io], [4.4.6])  AC_CONFIG_SRCDIR([util/mts_util_lora2_reset.c])  AM_INIT_AUTOMAKE  AM_CONFIG_HEADER([config.h]) diff --git a/io-module/mts_io_module.h b/io-module/mts_io_module.h index fde8d60..00e586e 100644 --- a/io-module/mts_io_module.h +++ b/io-module/mts_io_module.h @@ -5,7 +5,7 @@   * MTAC cards.   */ -#define DRIVER_VERSION  "v4.4.5" +#define DRIVER_VERSION  "v4.4.6"  #define DRIVER_AUTHOR   "Multitech Systems"  #define DRIVER_DESC "MTS-IO Controller"  #define DRIVER_NAME "mts-io" diff --git a/io-module/spi.c b/io-module/spi.c index 1244cfc..873caaf 100644 --- a/io-module/spi.c +++ b/io-module/spi.c @@ -348,22 +348,45 @@ static ssize_t mts_attr_show_board_temperature(struct device *dev,  			char *buf)  {  	int tmp; -	u16 temp_raw; +	u16 temp_raw, save[3]; +	int i; int count, diff;  	if (!spi_board_temp_dev) { -		log_notice("spi_board_temp device not present"); -		return -ENODEV; +            log_notice("spi_board_temp device not present"); +            return -ENODEV;  	} -	tmp = spi_readn(spi_board_temp_dev, (u8 *) buf, 2); -	if (tmp) { -		log_error("spi_readn failed %d", tmp); -		return tmp; +	for(count = 3; count > 0; count--) { +            for (i=0;i<3;i++) { +                tmp = spi_readn(spi_board_temp_dev, (u8 *) buf, 2); +                if (tmp) { +                        log_error("spi_readn failed %d", tmp); +                        return tmp; +                } +                temp_raw = ((u8 *) buf)[0] << 8 | ((u8 *) buf)[1]; +                save[i] = temp_raw; +            } +            log_debug("temp: 0x%04X", temp_raw); + +            /* If temp reading is very small, use the last +             * reading, because it could bounce around more. +             */ +            if (save[2] < 50) +                break; +            diff = save[2] - save[1]; +            if (diff < 0) +                diff = -diff; +            if (diff == 0) +                break; +            /* If temperature difference of the last two readings is less +             * than 10%, use the last reading */ +            if ((save[2] / diff) > 10) +                break; +            /* If we have tried 3 times and we still have more than a 10% +             * difference, we give up */  	} -	temp_raw = ((u8 *) buf)[0] << 8 | ((u8 *) buf)[1]; - -	log_debug("temp: 0x%04X", temp_raw); - +	if (count == 0) +            log_info("temp=%d, count=%d, diff=%d, save[0]=%d, save[1]=%d\n", temp_raw,count,diff,save[0],save[1]);  	return sprintf(buf, "%d\n", ADT7302_to_celsius(temp_raw));  } | 
