]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/pce-322a/api.c
dev_clear(): Consistently name callback 'clear_helper()'.
[libsigrok.git] / src / hardware / pce-322a / api.c
index 202e3122a26cbb4ec7be226bf6e9759aee7ca70d..14534e2ad9991f4af384483c295018bb30a55d8b 100644 (file)
@@ -2,6 +2,7 @@
  * This file is part of the libsigrok project.
  *
  * Copyright (C) 2016 George Hopkins <george-hopkins@null.net>
+ * Copyright (C) 2016 Matthieu Guillaumin <matthieu@guillaum.in>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -38,6 +39,7 @@ static const uint32_t devopts[] = {
        SR_CONF_SPL_WEIGHT_TIME | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_SPL_MEASUREMENT_RANGE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
 };
 
 static const char *weight_freq[] = {
@@ -57,6 +59,11 @@ static const uint64_t meas_ranges[][2] = {
        { 80, 130 },
 };
 
+static const char *data_sources[] = {
+       "Live",
+       "Memory",
+};
+
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
 {
        struct dev_context *devc;
@@ -96,11 +103,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
        return std_scan_complete(di, g_slist_append(NULL, sdi));
 }
 
-static int dev_clear(const struct sr_dev_driver *di)
-{
-       return std_dev_clear(di, NULL);
-}
-
 static int config_get(uint32_t key, GVariant **data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
@@ -149,6 +151,12 @@ static int config_get(uint32_t key, GVariant **data,
        case SR_CONF_POWER_OFF:
                *data = g_variant_new_boolean(FALSE);
                break;
+       case SR_CONF_DATA_SOURCE:
+               if (devc->cur_data_source == DATA_SOURCE_LIVE)
+                       *data = g_variant_new_string("Live");
+               else
+                       *data = g_variant_new_string("Memory");
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -167,9 +175,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 
        (void)cg;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
 
        ret = SR_OK;
@@ -215,6 +220,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
                if (g_variant_get_boolean(data))
                        ret = pce_322a_power_off(sdi);
                break;
+       case SR_CONF_DATA_SOURCE:
+               tmp_str = g_variant_get_string(data, NULL);
+               if (!strcmp(tmp_str, "Live"))
+                       devc->cur_data_source = DATA_SOURCE_LIVE;
+               else if (!strcmp(tmp_str, "Memory"))
+                       devc->cur_data_source = DATA_SOURCE_MEMORY;
+               else
+                       return SR_ERR;
+               break;
        default:
                ret = SR_ERR_NA;
        }
@@ -268,6 +282,9 @@ static int config_list(uint32_t key, GVariant **data,
                        }
                        *data = g_variant_builder_end(&gvb);
                        break;
+               case SR_CONF_DATA_SOURCE:
+                       *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
+                       break;
                default:
                        return SR_ERR_NA;
                }
@@ -303,11 +320,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
        devc->buffer_len = 0;
+       devc->memory_state = MEM_STATE_REQUEST_MEMORY_USAGE;
 
        std_session_send_df_header(sdi);
 
@@ -327,7 +342,7 @@ static struct sr_dev_driver pce_322a_driver_info = {
        .cleanup = std_cleanup,
        .scan = scan,
        .dev_list = std_dev_list,
-       .dev_clear = dev_clear,
+       .dev_clear = std_dev_clear,
        .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,