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))
/* 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) {
#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,
int buf_len;
unsigned char buf[BUF_SIZE];
float last_spl;
+ gint64 hold_last_sent;
};