From: Bert Vermeulen Date: Wed, 12 Jun 2013 14:04:23 +0000 (+0200) Subject: cem-dt-885x: Send last measurement at normal rate in hold mode X-Git-Tag: libsigrok-0.2.1~62 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=14cf708fef6d1dfd371923c7749f8cecd8a896a2;p=libsigrok.git cem-dt-885x: Send last measurement at normal rate in hold mode The device only sends the "hold" token otherwise, which clashes somewhat with other devices. This makes the device more predictable for frontends. --- diff --git a/hardware/cem-dt-885x/protocol.c b/hardware/cem-dt-885x/protocol.c index b727ada9..c9d0c89e 100644 --- a/hardware/cem-dt-885x/protocol.c +++ b/hardware/cem-dt-885x/protocol.c @@ -169,6 +169,7 @@ static void process_mset(const struct sr_dev_inst *sdi) static void process_byte(const struct sr_dev_inst *sdi, const unsigned char c) { struct dev_context *devc; + gint64 cur_time; int len; if (!(devc = sdi->priv)) @@ -178,14 +179,26 @@ static void process_byte(const struct sr_dev_inst *sdi, const unsigned char c) /* Device is in hold mode */ devc->cur_mqflags |= SR_MQFLAG_HOLD; - /* TODO: send out the last measurement at the same - * rate as it normally gets sent */ + if (devc->hold_last_sent == 0) { + /* First hold notification. */ + devc->hold_last_sent = g_get_monotonic_time(); + /* When the device leaves hold mode, it starts from scratch. */ + devc->state = ST_INIT; + } else { + cur_time = g_get_monotonic_time(); + if (cur_time - devc->hold_last_sent > HOLD_REPEAT_INTERVAL) { + /* Force the last measurement out again. */ + devc->cmd = 0xa5; + devc->token = TOKEN_MEAS_WAS_READOUT; + process_mset(sdi); + devc->hold_last_sent = cur_time; + } + } - /* When the device leaves hold mode, it starts from scratch. */ - devc->state = ST_INIT; return; } devc->cur_mqflags &= ~SR_MQFLAG_HOLD; + devc->hold_last_sent = 0; if (devc->state == ST_INIT) { if (c == 0xa5) { diff --git a/hardware/cem-dt-885x/protocol.h b/hardware/cem-dt-885x/protocol.h index f3809fc2..fa96d163 100644 --- a/hardware/cem-dt-885x/protocol.h +++ b/hardware/cem-dt-885x/protocol.h @@ -35,6 +35,9 @@ #define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args) #define BUF_SIZE 32 +/* When in hold mode, force the last measurement out at this interval. + * We're using 50ms, which duplicates the non-hold 20Hz update rate. */ +#define HOLD_REPEAT_INTERVAL 50 * 1000 enum { TOKEN_WEIGHT_TIME_FAST = 0x02, @@ -80,6 +83,7 @@ struct dev_context { int buf_len; unsigned char buf[BUF_SIZE]; float last_spl; + gint64 hold_last_sent; };