]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/cem-dt-885x/api.c
drivers: Factor out std_gvar_tuple_{array,rational}().
[libsigrok.git] / src / hardware / cem-dt-885x / api.c
index 7ad8e610a83940b4c42adaeb87e45be3e523685e..1c456ce0585b5edff014994c1ddc54ec9070a7fc 100644 (file)
@@ -208,9 +208,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;
@@ -287,58 +284,27 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
                const struct sr_channel_group *cg)
 {
-       GVariant *tuple, *range[2];
-       GVariantBuilder gvb;
-       unsigned int i;
-       int ret;
-
-       (void)cg;
-
-       ret = SR_OK;
-       if (!sdi) {
-               switch (key) {
-               case SR_CONF_SCAN_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
-                       break;
-               case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
-                       break;
-               default:
-                       return SR_ERR_NA;
-               }
-       } else {
-               switch (key) {
-               case SR_CONF_DEVICE_OPTIONS:
-                       *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
-                                       devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
-                       break;
-               case SR_CONF_SPL_WEIGHT_FREQ:
-                       *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
-                       break;
-               case SR_CONF_SPL_WEIGHT_TIME:
-                       *data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
-                       break;
-               case SR_CONF_SPL_MEASUREMENT_RANGE:
-                       g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
-                       for (i = 0; i < ARRAY_SIZE(meas_ranges); i++) {
-                               range[0] = g_variant_new_uint64(meas_ranges[i][0]);
-                               range[1] = g_variant_new_uint64(meas_ranges[i][1]);
-                               tuple = g_variant_new_tuple(range, 2);
-                               g_variant_builder_add_value(&gvb, tuple);
-                       }
-                       *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;
-               }
+       switch (key) {
+       case SR_CONF_SCAN_OPTIONS:
+       case SR_CONF_DEVICE_OPTIONS:
+               return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
+       case SR_CONF_SPL_WEIGHT_FREQ:
+               *data = g_variant_new_strv(weight_freq, ARRAY_SIZE(weight_freq));
+               break;
+       case SR_CONF_SPL_WEIGHT_TIME:
+               *data = g_variant_new_strv(weight_time, ARRAY_SIZE(weight_time));
+               break;
+       case SR_CONF_SPL_MEASUREMENT_RANGE:
+               *data = std_gvar_tuple_array(&meas_ranges, ARRAY_SIZE(meas_ranges));
+               break;
+       case SR_CONF_DATA_SOURCE:
+               *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources));
+               break;
+       default:
+               return SR_ERR_NA;
        }
 
-       return ret;
+       return SR_OK;
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
@@ -353,7 +319,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 
        std_session_send_df_header(sdi);
 
-       /* Poll every 100ms, or whenever some data comes in. */
        serial = sdi->conn;
        serial_source_add(sdi->session, serial, G_IO_IN, 150,
                        cem_dt_885x_receive_data, (void *)sdi);
@@ -369,7 +334,7 @@ static struct sr_dev_driver cem_dt_885x_driver_info = {
        .cleanup = std_cleanup,
        .scan = scan,
        .dev_list = std_dev_list,
-       .dev_clear = NULL,
+       .dev_clear = std_dev_clear,
        .config_get = config_get,
        .config_set = config_set,
        .config_list = config_list,