X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmanson-hcs-3xxx%2Fapi.c;h=765d9abc78682a905cde53a680cab51ae7fd0414;hb=f6ce25ec05e8707ee3783b111ea13779f237c3b3;hp=a2f1feca229152993322b4502f3cd71cccb09079;hpb=55fb76b34826a287240bebeeda688e4c465b4751;p=libsigrok.git diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index a2f1feca..765d9abc 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -18,14 +18,6 @@ * along with this program; if not, see . */ -/** - * @file - * - * Manson HCS-3xxx series power supply driver - * - * @internal - */ - #include #include "protocol.h" @@ -35,18 +27,13 @@ static const uint32_t scanopts[] = { }; static const uint32_t drvopts[] = { - /* Device class */ SR_CONF_POWER_SUPPLY, }; static const uint32_t devopts[] = { - /* Device class */ - SR_CONF_POWER_SUPPLY, - /* Acquisition modes. */ SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, - /* Device configuration */ SR_CONF_VOLTAGE | SR_CONF_GET, SR_CONF_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_CURRENT | SR_CONF_GET, @@ -66,6 +53,7 @@ static const struct hcs_model models[] = { { MANSON_HCS_3300, "HCS-3300-USB", "3300", { 1, 16, 0.1 }, { 0, 30, 0.10 } }, { MANSON_HCS_3302, "HCS-3302-USB", "3302", { 1, 32, 0.1 }, { 0, 15, 0.10 } }, { MANSON_HCS_3304, "HCS-3304-USB", "3304", { 1, 60, 0.1 }, { 0, 8, 0.10 } }, + { MANSON_HCS_3304, "HCS-3304-USB", "HCS-3304", { 1, 60, 0.1 }, { 0, 8, 0.10 } }, { MANSON_HCS_3400, "HCS-3400-USB", "3400", { 1, 16, 0.1 }, { 0, 40, 0.10 } }, { MANSON_HCS_3402, "HCS-3402-USB", "3402", { 1, 32, 0.1 }, { 0, 20, 0.10 } }, { MANSON_HCS_3404, "HCS-3404-USB", "3404", { 1, 60, 0.1 }, { 0, 10, 0.10 } }, @@ -138,7 +126,6 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) } g_strfreev(tokens); - /* Init device instance, etc. */ sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->status = SR_ST_INACTIVE; sdi->vendor = g_strdup("Manson"); @@ -186,8 +173,8 @@ exit_err: return NULL; } -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; @@ -224,8 +211,8 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s 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; gboolean bval; @@ -263,11 +250,15 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd break; case SR_CONF_ENABLED: bval = g_variant_get_boolean(data); - if (bval == devc->output_enabled) /* Nothing to do. */ - break; - if ((hcs_send_cmd(sdi->conn, "SOUT%1d\r", !bval) < 0) || - (hcs_read_reply(sdi->conn, 1, devc->buf, sizeof(devc->buf)) < 0)) + + if (hcs_send_cmd(sdi->conn, "SOUT%1d\r", !bval) < 0) { + sr_err("Could not send SR_CONF_ENABLED command."); return SR_ERR; + } + if (hcs_read_reply(sdi->conn, 1, devc->buf, sizeof(devc->buf)) < 0) { + sr_err("Could not read SR_CONF_ENABLED reply."); + return SR_ERR; + } devc->output_enabled = bval; break; default: @@ -277,14 +268,11 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd 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) { + const double *a; struct dev_context *devc; - GVariant *gvar; - GVariantBuilder gvb; - double dval; - int idx; devc = (sdi) ? sdi->priv : NULL; @@ -293,30 +281,16 @@ 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_VOLTAGE_TARGET: - g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); - /* Min, max, step. */ - for (idx = 0; idx < 3; idx++) { - if (idx == 1) - dval = devc->voltage_max_device; - else - dval = devc->model->voltage[idx]; - gvar = g_variant_new_double(dval); - g_variant_builder_add_value(&gvb, gvar); - } - *data = g_variant_builder_end(&gvb); + if (!devc || !devc->model) + return SR_ERR_ARG; + a = devc->model->voltage; + *data = std_gvar_min_max_step(a[0], devc->voltage_max_device, a[2]); break; case SR_CONF_CURRENT_LIMIT: - g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); - /* Min, max, step. */ - for (idx = 0; idx < 3; idx++) { - if (idx == 1) - dval = devc->current_max_device; - else - dval = devc->model->current[idx]; - gvar = g_variant_new_double(dval); - g_variant_builder_add_value(&gvb, gvar); - } - *data = g_variant_builder_end(&gvb); + if (!devc || !devc->model) + return SR_ERR_ARG; + a = devc->model->current; + *data = std_gvar_min_max_step(a[0], devc->current_max_device, a[2]); break; default: return SR_ERR_NA; @@ -338,7 +312,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc->reply_pending = FALSE; devc->req_sent_at = 0; - /* Poll every 10ms, or whenever some data comes in. */ serial = sdi->conn; serial_source_add(sdi->session, serial, G_IO_IN, 10, hcs_receive_data, (void *)sdi);