X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fkern-scale%2Fapi.c;h=e369a44cf5e585722dbec8acf544b8a90b8119e8;hb=755793e991c4d429f99254f23008bfddb89d8e00;hp=167bf1bc9958c8180b83908c2c47f95c5f27ae17;hpb=2ea1fdf12113311cbe1a4316e9e2efe4d8ac40f0;p=libsigrok.git diff --git a/src/hardware/kern-scale/api.c b/src/hardware/kern-scale/api.c index 167bf1bc..e369a44c 100644 --- a/src/hardware/kern-scale/api.c +++ b/src/hardware/kern-scale/api.c @@ -28,8 +28,11 @@ static const uint32_t scanopts[] = { SR_CONF_SERIALCOMM, }; -static const uint32_t devopts[] = { +static const uint32_t drvopts[] = { SR_CONF_SCALE, +}; + +static const uint32_t devopts[] = { SR_CONF_CONTINUOUS, SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, SR_CONF_LIMIT_MSEC | SR_CONF_SET, @@ -79,7 +82,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) serial_flush(serial); sr_spew("Set O1 mode (continuous values, stable and unstable ones)."); - if (serial_write_nonblocking(serial, "O1\r\n", 4) != 4) + if (serial_write_blocking(serial, "O1\r\n", 4, 0) < 0) goto scan_cleanup; /* Device replies with "A00\r\n" (OK) or "E01\r\n" (Error). Ignore. */ @@ -110,41 +113,22 @@ scan_cleanup: return std_scan_complete(di, devices); } -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; (void)cg; - if (sdi->status != SR_ST_ACTIVE) - return SR_ERR_DEV_CLOSED; - devc = sdi->priv; return sr_sw_limits_config_set(&devc->limits, key, data); } -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) { - (void)sdi; - (void)cg; - - 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, - devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); - break; - default: - return SR_ERR_NA; - } - - return SR_OK; + return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts); } static int dev_acquisition_start(const struct sr_dev_inst *sdi) @@ -152,21 +136,17 @@ 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; serial = sdi->conn; sr_spew("Set O1 mode (continuous values, stable and unstable ones)."); - if (serial_write_nonblocking(serial, "O1\r\n", 4) != 4) + if (serial_write_blocking(serial, "O1\r\n", 4, 0) < 0) return SR_ERR; /* Device replies with "A00\r\n" (OK) or "E01\r\n" (Error). Ignore. */ sr_sw_limits_acquisition_start(&devc->limits); std_session_send_df_header(sdi); - /* Poll every 50ms, or whenever some data comes in. */ serial_source_add(sdi->session, serial, G_IO_IN, 50, kern_scale_receive_data, (void *)sdi); @@ -184,6 +164,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) .cleanup = std_cleanup, \ .scan = scan, \ .dev_list = std_dev_list, \ + .dev_clear = std_dev_clear, \ .config_get = NULL, \ .config_set = config_set, \ .config_list = config_list, \