X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fdmm%2Ffs9721.c;h=b775380f751b2ef87e232bd76e06a810969449ee;hb=7ab89f4827d516313cafc9b7b9670ee99dc9c584;hp=fca6a5a43c5cab81b54fd53a3be63d1f2e6923d1;hpb=8c1adf3738b68912ab8cf4308341b82dbc83056a;p=libsigrok.git diff --git a/hardware/common/dmm/fs9721.c b/hardware/common/dmm/fs9721.c index fca6a5a4..b775380f 100644 --- a/hardware/common/dmm/fs9721.c +++ b/hardware/common/dmm/fs9721.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2012 Uwe Hermann * Copyright (C) 2012 Alexandru Gagniuc @@ -38,14 +38,14 @@ #include "libsigrok.h" #include "libsigrok-internal.h" -/* Message logging helpers with driver-specific prefix string. */ -#define DRIVER_LOG_DOMAIN "fs9721: " -#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args) -#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args) -#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args) -#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args) -#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args) -#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args) +/* Message logging helpers with subsystem-specific prefix string. */ +#define LOG_PREFIX "fs9721: " +#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args) +#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args) +#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args) +#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args) +#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args) +#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args) static int parse_digit(uint8_t b) { @@ -326,11 +326,6 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, sr_spew("User-defined LCD symbol 3 is active."); } -SR_PRIV gboolean sr_fs9721_is_packet_start(uint8_t b) -{ - return (((b >> 4) & 0x0f) == 0x01); -} - SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf) { struct fs9721_info info; @@ -343,30 +338,91 @@ SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf) /** * Parse a protocol packet. * - * @param buf Buffer containing the 14-byte protocol packet. + * @param buf Buffer containing the 14-byte protocol packet. Must not be NULL. * @param floatval Pointer to a float variable. That variable will contain the - * result value upon parsing success. + * result value upon parsing success. Mut not be NULL. * @param analog Pointer to a struct sr_datafeed_analog. The struct will be * filled with data according to the protocol packet. + * Must not be NULL. * @param info Pointer to a struct fs9721_info. The struct will be filled - * with data according to the protocol packet. + * with data according to the protocol packet. Must not be NULL. * * @return SR_OK upon success, SR_ERR upon failure. Upon errors, the * 'analog' variable contents are undefined and should not be used. */ SR_PRIV int sr_fs9721_parse(const uint8_t *buf, float *floatval, - struct sr_datafeed_analog *analog, - struct fs9721_info *info) + struct sr_datafeed_analog *analog, void *info) { int ret; + struct fs9721_info *info_local; + + info_local = (struct fs9721_info *)info; if ((ret = parse_value(buf, floatval)) != SR_OK) { sr_err("Error parsing value: %d.", ret); return ret; } - parse_flags(buf, info); - handle_flags(analog, floatval, info); + parse_flags(buf, info_local); + handle_flags(analog, floatval, info_local); return SR_OK; } + +SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog *analog, void *info) +{ + struct fs9721_info *info_local; + + info_local = (struct fs9721_info *)info; + + /* User-defined FS9721_LP3 flag 'c2c1_00' means temperature (C). */ + if (info_local->is_c2c1_00) { + analog->mq = SR_MQ_TEMPERATURE; + analog->unit = SR_UNIT_CELSIUS; + } +} + +SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog *analog, void *info) +{ + struct fs9721_info *info_local; + + info_local = (struct fs9721_info *)info; + + /* User-defined FS9721_LP3 flag 'c2c1_01' means temperature (C). */ + if (info_local->is_c2c1_01) { + analog->mq = SR_MQ_TEMPERATURE; + analog->unit = SR_UNIT_CELSIUS; + } +} + +SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog *analog, void *info) +{ + struct fs9721_info *info_local; + + info_local = (struct fs9721_info *)info; + + /* User-defined FS9721_LP3 flag 'c2c1_10' means temperature (C). */ + if (info_local->is_c2c1_10) { + analog->mq = SR_MQ_TEMPERATURE; + analog->unit = SR_UNIT_CELSIUS; + } +} + +SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog *analog, void *info) +{ + struct fs9721_info *info_local; + + info_local = (struct fs9721_info *)info; + + /* User-defined FS9721_LP3 flag 'c2c1_01' means temperature (F). */ + if (info_local->is_c2c1_01) { + analog->mq = SR_MQ_TEMPERATURE; + analog->unit = SR_UNIT_FAHRENHEIT; + } + + /* User-defined FS9721_LP3 flag 'c2c1_10' means temperature (C). */ + if (info_local->is_c2c1_10) { + analog->mq = SR_MQ_TEMPERATURE; + analog->unit = SR_UNIT_CELSIUS; + } +}