]> sigrok.org Git - libsigrok.git/blobdiff - hardware/demo/demo.c
Rename SR_HWOPT_* and SR_HWCAP_* to SR_CONF_*
[libsigrok.git] / hardware / demo / demo.c
index ff7ba06b7ce39ea3d1f7274f9690a260cf2345cf..850cf8a8ef533b53a686951d9fe09ef773b32c6f 100644 (file)
@@ -84,13 +84,13 @@ struct dev_context {
 };
 
 static const int hwcaps[] = {
-       SR_HWCAP_LOGIC_ANALYZER,
-       SR_HWCAP_DEMO_DEV,
-       SR_HWCAP_SAMPLERATE,
-       SR_HWCAP_PATTERN_MODE,
-       SR_HWCAP_LIMIT_SAMPLES,
-       SR_HWCAP_LIMIT_MSEC,
-       SR_HWCAP_CONTINUOUS,
+       SR_CONF_LOGIC_ANALYZER,
+       SR_CONF_DEMO_DEV,
+       SR_CONF_SAMPLERATE,
+       SR_CONF_PATTERN_MODE,
+       SR_CONF_LIMIT_SAMPLES,
+       SR_CONF_LIMIT_MSEC,
+       SR_CONF_CONTINUOUS,
 };
 
 static const struct sr_samplerates samplerates = {
@@ -111,14 +111,7 @@ static const char *pattern_strings[] = {
 
 /* We name the probes 0-7 on our demo driver. */
 static const char *probe_names[NUM_PROBES + 1] = {
-       "0",
-       "1",
-       "2",
-       "3",
-       "4",
-       "5",
-       "6",
-       "7",
+       "0", "1", "2", "3", "4", "5", "6", "7",
        NULL,
 };
 
@@ -138,7 +131,7 @@ static uint8_t pattern_sigrok[] = {
 
 /* List of struct sr_dev_inst, maintained by dev_open()/dev_close(). */
 SR_PRIV struct sr_dev_driver demo_driver_info;
-static struct sr_dev_driver *ddi = &demo_driver_info;
+static struct sr_dev_driver *di = &demo_driver_info;
 static uint64_t cur_samplerate = SR_KHZ(200);
 static uint64_t limit_samples = 0;
 static uint64_t limit_msec = 0;
@@ -161,7 +154,8 @@ static int hw_init(struct sr_context *sr_ctx)
                sr_err("Driver context malloc failed.");
                return SR_ERR_MALLOC;
        }
-       ddi->priv = drvc;
+       drvc->sr_ctx = sr_ctx;
+       di->priv = drvc;
 
        return SR_OK;
 }
@@ -176,7 +170,7 @@ static GSList *hw_scan(GSList *options)
 
        (void)options;
 
-       drvc = ddi->priv;
+       drvc = di->priv;
        devices = NULL;
 
        sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, DEMONAME, NULL, NULL);
@@ -184,7 +178,7 @@ static GSList *hw_scan(GSList *options)
                sr_err("%s: sr_dev_inst_new failed", __func__);
                return 0;
        }
-       sdi->driver = ddi;
+       sdi->driver = di;
 
        for (i = 0; probe_names[i]; i++) {
                if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
@@ -203,7 +197,7 @@ static GSList *hw_dev_list(void)
 {
        struct drv_context *drvc;
 
-       drvc = ddi->priv;
+       drvc = di->priv;
 
        return drvc->instances;
 }
@@ -241,12 +235,6 @@ static int hw_info_get(int info_id, const void **data,
        case SR_DI_HWCAPS:
                *data = hwcaps;
                break;
-       case SR_DI_NUM_PROBES:
-               *data = GINT_TO_POINTER(NUM_PROBES);
-               break;
-       case SR_DI_PROBE_NAMES:
-               *data = probe_names;
-               break;
        case SR_DI_SAMPLERATES:
                *data = &samplerates;
                break;
@@ -271,24 +259,24 @@ static int hw_dev_config_set(const struct sr_dev_inst *sdi, int hwcap,
 
        (void)sdi;
 
-       if (hwcap == SR_HWCAP_SAMPLERATE) {
+       if (hwcap == SR_CONF_SAMPLERATE) {
                cur_samplerate = *(const uint64_t *)value;
                sr_dbg("%s: setting samplerate to %" PRIu64, __func__,
                       cur_samplerate);
                ret = SR_OK;
-       } else if (hwcap == SR_HWCAP_LIMIT_SAMPLES) {
+       } else if (hwcap == SR_CONF_LIMIT_SAMPLES) {
                limit_msec = 0;
                limit_samples = *(const uint64_t *)value;
                sr_dbg("%s: setting limit_samples to %" PRIu64, __func__,
                       limit_samples);
                ret = SR_OK;
-       } else if (hwcap == SR_HWCAP_LIMIT_MSEC) {
+       } else if (hwcap == SR_CONF_LIMIT_MSEC) {
                limit_msec = *(const uint64_t *)value;
                limit_samples = 0;
                sr_dbg("%s: setting limit_msec to %" PRIu64, __func__,
                       limit_msec);
                ret = SR_OK;
-       } else if (hwcap == SR_HWCAP_PATTERN_MODE) {
+       } else if (hwcap == SR_CONF_PATTERN_MODE) {
                stropt = value;
                ret = SR_OK;
                if (!strcmp(stropt, "sigrok")) {
@@ -388,11 +376,8 @@ static int receive_data(int fd, int revents, void *cb_data)
                devc->samples_counter += sending_now;
        }
 
-
-       if (devc->samples_counter >= limit_samples) {
-               sr_spew("We sent a total of %" PRIu64 " samples.",
-                       devc->samples_counter);
-               /* Make sure we don't receive more packets. */
+       if (limit_samples && devc->samples_counter >= limit_samples) {
+               sr_info("Requested number of samples reached.");
                hw_dev_acquisition_stop(NULL, cb_data);
                return TRUE;
        }
@@ -405,7 +390,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 {
        struct sr_datafeed_packet *packet;
        struct sr_datafeed_header *header;
-       struct sr_datafeed_meta_logic meta;
        struct dev_context *devc;
 
        (void)sdi;
@@ -467,13 +451,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
        gettimeofday(&header->starttime, NULL);
        sr_session_send(devc->session_dev_id, packet);
 
-       /* Send metadata about the SR_DF_LOGIC packets to come. */
-       packet->type = SR_DF_META_LOGIC;
-       packet->payload = &meta;
-       meta.samplerate = cur_samplerate;
-       meta.num_probes = NUM_PROBES;
-       sr_session_send(devc->session_dev_id, packet);
-
        /* We use this timestamp to decide how many more samples to send. */
        devc->starttime = g_get_monotonic_time();