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.
This commit is contained in:
Bert Vermeulen 2013-06-12 16:04:23 +02:00
parent bc1143280f
commit 14cf708fef
2 changed files with 21 additions and 4 deletions

View File

@ -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) static void process_byte(const struct sr_dev_inst *sdi, const unsigned char c)
{ {
struct dev_context *devc; struct dev_context *devc;
gint64 cur_time;
int len; int len;
if (!(devc = sdi->priv)) 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 */ /* Device is in hold mode */
devc->cur_mqflags |= SR_MQFLAG_HOLD; devc->cur_mqflags |= SR_MQFLAG_HOLD;
/* TODO: send out the last measurement at the same if (devc->hold_last_sent == 0) {
* rate as it normally gets sent */ /* 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; return;
} }
devc->cur_mqflags &= ~SR_MQFLAG_HOLD; devc->cur_mqflags &= ~SR_MQFLAG_HOLD;
devc->hold_last_sent = 0;
if (devc->state == ST_INIT) { if (devc->state == ST_INIT) {
if (c == 0xa5) { if (c == 0xa5) {

View File

@ -35,6 +35,9 @@
#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args) #define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
#define BUF_SIZE 32 #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 { enum {
TOKEN_WEIGHT_TIME_FAST = 0x02, TOKEN_WEIGHT_TIME_FAST = 0x02,
@ -80,6 +83,7 @@ struct dev_context {
int buf_len; int buf_len;
unsigned char buf[BUF_SIZE]; unsigned char buf[BUF_SIZE];
float last_spl; float last_spl;
gint64 hold_last_sent;
}; };