2 * This file is part of the libsigrok project.
4 * Copyright (C) 2016 Lars-Peter Clausen <lars@metafoo.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <libsigrok/libsigrok.h>
26 #include "libsigrok-internal.h"
28 SR_PRIV void sr_sw_limits_init(struct sr_sw_limits *limits)
30 limits->limit_samples = 0;
31 limits->limit_msec = 0;
34 SR_PRIV int sr_sw_limits_config_get(struct sr_sw_limits *limits, uint32_t key,
38 case SR_CONF_LIMIT_SAMPLES:
39 *data = g_variant_new_uint64(limits->limit_samples);
41 case SR_CONF_LIMIT_MSEC:
42 *data = g_variant_new_uint64(limits->limit_msec / 1000);
51 SR_PRIV int sr_sw_limits_config_set(struct sr_sw_limits *limits, uint32_t key,
55 case SR_CONF_LIMIT_SAMPLES:
56 limits->limit_samples = g_variant_get_uint64(data);
58 case SR_CONF_LIMIT_MSEC:
59 limits->limit_msec = g_variant_get_uint64(data) * 1000;
68 SR_PRIV void sr_sw_limits_acquisition_start(struct sr_sw_limits *limits)
70 limits->samples_read = 0;
71 limits->start_time = g_get_monotonic_time();
74 SR_PRIV gboolean sr_sw_limits_check(struct sr_sw_limits *limits)
76 if (limits->limit_samples) {
77 if (limits->samples_read >= limits->limit_samples)
81 if (limits->limit_msec) {
83 now = g_get_monotonic_time();
84 if (now > limits->start_time &&
85 now - limits->start_time > limits->limit_msec)
92 SR_PRIV void sr_sw_limits_update_samples_read(struct sr_sw_limits *limits,
93 uint64_t samples_read)
95 limits->samples_read += samples_read;