From 14cf708fef6d1dfd371923c7749f8cecd8a896a2 Mon Sep 17 00:00:00 2001 From: Bert Vermeulen Date: Wed, 12 Jun 2013 16:04:23 +0200 Subject: [PATCH] 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. --- hardware/cem-dt-885x/protocol.c | 21 +++++++++++++++++---- hardware/cem-dt-885x/protocol.h | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) 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; };