summaryrefslogtreecommitdiff
path: root/libsigrok4DSLogic/hardware/demo/demo.c
diff options
context:
space:
mode:
Diffstat (limited to 'libsigrok4DSLogic/hardware/demo/demo.c')
-rw-r--r--libsigrok4DSLogic/hardware/demo/demo.c105
1 files changed, 100 insertions, 5 deletions
diff --git a/libsigrok4DSLogic/hardware/demo/demo.c b/libsigrok4DSLogic/hardware/demo/demo.c
index 67df85e..15ef903 100644
--- a/libsigrok4DSLogic/hardware/demo/demo.c
+++ b/libsigrok4DSLogic/hardware/demo/demo.c
@@ -85,6 +85,13 @@ struct dev_context {
void *cb_data;
int64_t starttime;
int stop;
+ gboolean en_ch0;
+ gboolean en_ch1;
+ uint64_t vdiv0;
+ uint64_t vdiv1;
+ uint64_t timebase;
+ gboolean coupling0;
+ gboolean coupling1;
int trigger_stage;
uint16_t trigger_mask;
@@ -192,6 +199,11 @@ static GSList *hw_scan(GSList *options)
devc->limit_samples = 0;
devc->limit_msec = 0;
devc->sample_generator = PATTERN_SINE;
+ devc->vdiv0 = 1000;
+ devc->vdiv1 = 1000;
+ devc->timebase = 100;
+ devc->coupling0 = FALSE;
+ devc->coupling1 = FALSE;
sdi->priv = devc;
@@ -202,6 +214,13 @@ static GSList *hw_scan(GSList *options)
return NULL;
sdi->probes = g_slist_append(sdi->probes, probe);
}
+ } else if (sdi->mode == DSO) {
+ for (i = 0; i < DS_MAX_DSO_PROBES_NUM; i++) {
+ if (!(probe = sr_probe_new(i, SR_PROBE_DSO, TRUE,
+ probe_names[i])))
+ return NULL;
+ sdi->probes = g_slist_append(sdi->probes, probe);
+ }
} else if (sdi->mode == ANALOG) {
for (i = 0; i < DS_MAX_ANALOG_PROBES_NUM; i++) {
if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
@@ -283,6 +302,27 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi)
case SR_CONF_PATTERN_MODE:
*data = g_variant_new_string(pattern_strings[devc->sample_generator]);
break;
+ case SR_CONF_VDIV0:
+ *data = g_variant_new_uint64(devc->vdiv0);
+ break;
+ case SR_CONF_VDIV1:
+ *data = g_variant_new_uint64(devc->vdiv1);
+ break;
+ case SR_CONF_TIMEBASE:
+ *data = g_variant_new_uint64(devc->timebase);
+ break;
+ case SR_CONF_COUPLING0:
+ *data = g_variant_new_uint64(devc->coupling0);
+ break;
+ case SR_CONF_COUPLING1:
+ *data = g_variant_new_uint64(devc->coupling1);
+ break;
+ case SR_CONF_EN_CH0:
+ *data = g_variant_new_uint64(devc->en_ch0);
+ break;
+ case SR_CONF_EN_CH1:
+ *data = g_variant_new_uint64(devc->en_ch1);
+ break;
default:
return SR_ERR_NA;
}
@@ -331,6 +371,16 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi)
else
sdi->probes = g_slist_append(sdi->probes, probe);
}
+ } else if (!strcmp(stropt, mode_strings[DSO])) {
+ sdi->mode = DSO;
+ sr_dev_probes_free(sdi);
+ for (i = 0; i < DS_MAX_DSO_PROBES_NUM; i++) {
+ if (!(probe = sr_probe_new(i, SR_PROBE_DSO, TRUE,
+ probe_names[i])))
+ ret = SR_ERR;
+ else
+ sdi->probes = g_slist_append(sdi->probes, probe);
+ }
} else if (!strcmp(stropt, mode_strings[ANALOG])) {
sdi->mode = ANALOG;
sr_dev_probes_free(sdi);
@@ -363,7 +413,42 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi)
}
sr_dbg("%s: setting pattern to %d",
__func__, devc->sample_generator);
- } else {
+ } else if (id == SR_CONF_EN_CH0) {
+ devc->en_ch0 = g_variant_get_boolean(data);
+ sr_dbg("%s: setting ENABLE of channel 0 to %d", __func__,
+ devc->en_ch0);
+ ret = SR_OK;
+ } else if (id == SR_CONF_EN_CH1) {
+ devc->en_ch1 = g_variant_get_boolean(data);
+ sr_dbg("%s: setting ENABLE of channel 1 to %d", __func__,
+ devc->en_ch1);
+ ret = SR_OK;
+ } else if (id == SR_CONF_VDIV0) {
+ devc->vdiv0 = g_variant_get_uint64(data);
+ sr_dbg("%s: setting VDIV of channel 0 to %" PRIu64, __func__,
+ devc->vdiv0);
+ ret = SR_OK;
+ } else if (id == SR_CONF_VDIV1) {
+ devc->vdiv1 = g_variant_get_uint64(data);
+ sr_dbg("%s: setting VDIV of channel 1 to %" PRIu64, __func__,
+ devc->vdiv1);
+ ret = SR_OK;
+ } else if (id == SR_CONF_TIMEBASE) {
+ devc->timebase = g_variant_get_uint64(data);
+ sr_dbg("%s: setting TIMEBASE to %" PRIu64, __func__,
+ devc->timebase);
+ ret = SR_OK;
+ } else if (id == SR_CONF_COUPLING0) {
+ devc->coupling0 = g_variant_get_boolean(data);
+ sr_dbg("%s: setting AC COUPLING of channel 0 to %d", __func__,
+ devc->coupling0);
+ ret = SR_OK;
+ } else if (id == SR_CONF_COUPLING1) {
+ devc->coupling1 = g_variant_get_boolean(data);
+ sr_dbg("%s: setting AC COUPLING of channel 1 to %d", __func__,
+ devc->coupling1);
+ ret = SR_OK;
+ } else {
ret = SR_ERR_NA;
}
@@ -476,6 +561,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
struct dev_context *devc = sdi->priv;
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
+ struct sr_datafeed_dso dso;
struct sr_datafeed_analog analog;
//uint16_t buf[BUFSIZE];
uint16_t *buf;
@@ -506,7 +592,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
if (sdi->mode == LOGIC)
samples_to_send = MIN(samples_to_send,
devc->limit_samples - devc->samples_counter);
- else if (sdi->mode == ANALOG)
+ else
samples_to_send = MIN(samples_to_send,
devc->limit_samples);
}
@@ -554,7 +640,16 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
logic.length = sending_now * (NUM_PROBES >> 3);
logic.unitsize = (NUM_PROBES >> 3);
logic.data = buf;
- } else if (sdi->mode == ANALOG) {
+ } else if (sdi->mode == DSO) {
+ packet.type = SR_DF_DSO;
+ packet.payload = &dso;
+ dso.probes = sdi->probes;
+ dso.num_samples = sending_now;
+ dso.mq = SR_MQ_VOLTAGE;
+ dso.unit = SR_UNIT_VOLT;
+ dso.mqflags = SR_MQFLAG_AC;
+ dso.data = buf;
+ }else {
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
analog.probes = sdi->probes;
@@ -568,7 +663,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi)
sr_session_send(sdi, &packet);
if (sdi->mode == LOGIC)
devc->samples_counter += sending_now;
- else if (sdi->mode == ANALOG)
+ else
devc->samples_counter = (devc->samples_counter + sending_now) % devc->limit_samples;
} else {
break;
@@ -606,7 +701,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
/*
* trigger setting
*/
- if (!trigger->trigger_en || sdi->mode == ANALOG) {
+ if (!trigger->trigger_en || sdi->mode != LOGIC) {
devc->trigger_stage = 0;
} else {
devc->trigger_mask = ds_trigger_get_mask0(TriggerStages);