return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
}
-static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_get(uint32_t key, GVariant **data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
struct sr_channel *ch;
return SR_OK;
}
-static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_set(uint32_t key, GVariant *data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
struct sr_channel *ch;
gdouble dval;
int ch_idx;
- const char *sval;
gboolean bval;
int idx;
- gboolean found;
devc = sdi->priv;
case SR_CONF_LIMIT_SAMPLES:
return sr_sw_limits_config_set(&devc->limits, key, data);
case SR_CONF_CHANNEL_CONFIG:
- sval = g_variant_get_string(data, NULL);
- found = FALSE;
- for (idx = 0; idx < (int)ARRAY_SIZE(channel_modes); idx++) {
- if (!strcmp(sval, channel_modes[idx])) {
- found = TRUE;
- if (devc->tracking_mode == idx)
- break; /* Nothing to do! */
- devc->tracking_mode = idx;
- if (devc->model->modelid >= LPS_304) /* No use to set anything in the smaller models. */
- return lps_cmd_ok(sdi->conn, "TRACK%1d", devc->tracking_mode);
- }
- if (devc->model->modelid <= LPS_303) /* Only first setting possible for smaller models. */
- break;
- }
- if (!found)
+ if ((idx = std_str_idx(data, ARRAY_AND_SIZE(channel_modes))) < 0)
return SR_ERR_ARG;
+ if (devc->model->modelid <= LPS_303 && idx != 0)
+ break; /* Only first setting possible for smaller models. */
+ if (devc->tracking_mode == idx)
+ break; /* Nothing to do! */
+ devc->tracking_mode = idx;
+ if (devc->model->modelid >= LPS_304) /* No use to set anything in the smaller models. */
+ return lps_cmd_ok(sdi->conn, "TRACK%1d", devc->tracking_mode);
break;
default:
return SR_ERR_NA;
return SR_ERR_NA;
devc->channel_status[ch_idx].output_current_max = dval;
return lps_cmd_ok(sdi->conn, "ISET%d %05.4f", ch_idx+1, dval);
- break;
case SR_CONF_ENABLED:
bval = g_variant_get_boolean(data);
if (bval == devc->channel_status[ch_idx].output_enabled) /* Nothing to do. */
return SR_OK;
}
-static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_list(uint32_t key, GVariant **data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
struct sr_channel *ch;
case SR_CONF_DEVICE_OPTIONS:
return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
case SR_CONF_CHANNEL_CONFIG:
+ if (!devc || !devc->model)
+ return SR_ERR_ARG;
if (devc->model->modelid <= LPS_303) {
/* The 1-channel models. */
*data = g_variant_new_strv(channel_modes, 1);
*data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_ch3));
break;
case SR_CONF_VOLTAGE_TARGET:
+ if (!devc || !devc->model)
+ return SR_ERR_ARG;
*data = std_gvar_min_max_step_array(devc->model->channels[ch_idx].voltage);
break;
case SR_CONF_CURRENT_LIMIT:
+ if (!devc || !devc->model)
+ return SR_ERR_ARG;
*data = std_gvar_min_max_step_array(devc->model->channels[ch_idx].current);
break;
default: