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:
parent
bc1143280f
commit
14cf708fef
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue