X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fatten-pps3xxx%2Fapi.c;h=dc6e5201977d30769956521c1450ffebfd8eb8b4;hb=HEAD;hp=1a783b7a456cd75455918ce5c034d9066d2f986c;hpb=53012da658ae94b245240c8a3e115723eede4c7d;p=libsigrok.git diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 1a783b7a..28b22015 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -113,8 +113,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid) if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; - serial_flush(serial); - /* This is how the vendor software scans for hardware. */ memset(packet, 0, PACKET_SIZE); packet[0] = 0xaa; @@ -159,11 +157,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options, int modelid) for (i = 0; i < MAX_CHANNELS; i++) { snprintf(channel, 10, "CH%d", i + 1); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel); - cg = g_malloc(sizeof(struct sr_channel_group)); - cg->name = g_strdup(channel); + cg = sr_channel_group_new(sdi, channel, NULL); cg->channels = g_slist_append(NULL, ch); - cg->priv = NULL; - sdi->channel_groups = g_slist_append(sdi->channel_groups, cg); } devc = g_malloc0(sizeof(struct dev_context)); @@ -182,8 +177,8 @@ static GSList *scan_3203(struct sr_dev_driver *di, GSList *options) return scan(di, options, PPS_3203T_3S); } -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; @@ -234,56 +229,33 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s return SR_OK; } -static int find_str(const char *str, const char **strings, int array_size) -{ - int idx, i; - - idx = -1; - for (i = 0; i < array_size; i++) { - if (!strcmp(str, strings[i])) { - idx = i; - break; - } - } - - return idx; -} - -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 channel, ret, ival; - const char *sval; + int channel, ival; gboolean bval; - ret = SR_OK; devc = sdi->priv; + if (!cg) { switch (key) { case SR_CONF_CHANNEL_CONFIG: - sval = g_variant_get_string(data, NULL); - if ((ival = find_str(sval, ARRAY_AND_SIZE(channel_modes))) == -1) { - ret = SR_ERR_ARG; - break; - } - if (devc->model->channel_modes && (1 << ival) == 0) { - /* Not supported on this model. */ - ret = SR_ERR_ARG; - } + if ((ival = std_str_idx(data, ARRAY_AND_SIZE(channel_modes))) < 0) + return SR_ERR_ARG; + if (devc->model->channel_modes && (1 << ival) == 0) + return SR_ERR_ARG; /* Not supported on this model. */ if (ival == devc->channel_mode_set) - /* Nothing to do. */ - break; + break; /* Nothing to do. */ devc->channel_mode_set = ival; devc->config_dirty = TRUE; break; case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: bval = g_variant_get_boolean(data); if (bval == devc->over_current_protection_set) - /* Nothing to do. */ - break; + break; /* Nothing to do. */ devc->over_current_protection_set = bval; devc->config_dirty = TRUE; break; @@ -299,35 +271,34 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd case SR_CONF_VOLTAGE_TARGET: dval = g_variant_get_double(data); if (dval < 0 || dval > devc->model->channels[channel].voltage[1]) - ret = SR_ERR_ARG; + return SR_ERR_ARG; devc->config[channel].output_voltage_max = dval; devc->config_dirty = TRUE; break; case SR_CONF_CURRENT_LIMIT: dval = g_variant_get_double(data); if (dval < 0 || dval > devc->model->channels[channel].current[1]) - ret = SR_ERR_ARG; + return SR_ERR_ARG; devc->config[channel].output_current_max = dval; devc->config_dirty = TRUE; break; case SR_CONF_ENABLED: bval = g_variant_get_boolean(data); if (bval == devc->config[channel].output_enabled_set) - /* Nothing to do. */ - break; + break; /* Nothing to do. */ devc->config[channel].output_enabled_set = bval; devc->config_dirty = TRUE; break; default: - ret = SR_ERR_NA; + return SR_ERR_NA; } } - return ret; + 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; @@ -341,6 +312,8 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * 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->channel_modes == CHANMODE_INDEPENDENT) { /* The 1-channel models. */ *data = g_variant_new_strv(channel_modes, 1); @@ -362,9 +335,13 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg)); break; case SR_CONF_VOLTAGE_TARGET: + if (!devc || !devc->model) + return SR_ERR_ARG; *data = std_gvar_min_max_step_array(devc->model->channels[channel].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[channel].current); break; default: