X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmic-985xx%2Fapi.c;h=d2ce842b07d39b9f88e984ba9e62e0f4207bb15a;hb=f3ba3c119c3918dfa9cbde74afe21bd4c5609b44;hp=3917314598b845f0d8feeae25304d2b3993db88f;hpb=e6284bf09fa80a611b84fdc2f370fb10e1df7207;p=libsigrok.git diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index 39173145..d2ce842b 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -20,17 +20,24 @@ #include "protocol.h" -static const int32_t hwopts[] = { +static const uint32_t scanopts[] = { SR_CONF_CONN, SR_CONF_SERIALCOMM, }; -static const int32_t hwcaps[] = { +static const uint32_t drvopts_temp[] = { + SR_CONF_THERMOMETER, +}; + +static const uint32_t drvopts_temp_hum[] = { SR_CONF_THERMOMETER, SR_CONF_HYGROMETER, - SR_CONF_LIMIT_SAMPLES, - SR_CONF_LIMIT_MSEC, - SR_CONF_CONTINUOUS, +}; + +static const uint32_t devopts[] = { + SR_CONF_CONTINUOUS | SR_CONF_SET, + SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, + SR_CONF_LIMIT_MSEC | SR_CONF_SET, }; SR_PRIV struct sr_dev_driver mic_98581_driver_info; @@ -71,7 +78,7 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) return NULL; - if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) + if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; drvc = mic_devs[idx].di->priv; @@ -84,9 +91,10 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) sr_info("Found device on port %s.", conn); /* TODO: Fill in version from protocol response. */ - if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, mic_devs[idx].vendor, - mic_devs[idx].device, NULL))) - goto scan_cleanup; + sdi = sr_dev_inst_new(); + sdi->status = SR_ST_INACTIVE; + sdi->vendor = g_strdup(mic_devs[idx].vendor); + sdi->model = g_strdup(mic_devs[idx].device); if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); @@ -160,7 +168,7 @@ static int cleanup(int idx) return dev_clear(idx); } -static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, +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; @@ -172,7 +180,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, devc = sdi->priv; - switch (id) { + switch (key) { case SR_CONF_LIMIT_SAMPLES: devc->limit_samples = g_variant_get_uint64(data); sr_dbg("Setting sample limit to %" PRIu64 ".", @@ -190,20 +198,29 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, return SR_OK; } -static int config_list(int 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, int idx) { - (void)sdi; (void)cg; switch (key) { case SR_CONF_SCAN_OPTIONS: - *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, - hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); + *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_INT32, - hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); + if (!sdi && !mic_devs[idx].has_humidity) { + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + drvopts_temp, ARRAY_SIZE(drvopts_temp), + sizeof(uint32_t)); + } else if (!sdi && mic_devs[idx].has_humidity) { + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + drvopts_temp_hum, ARRAY_SIZE(drvopts_temp_hum), + sizeof(uint32_t)); + } else { + *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, + devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); + } break; default: return SR_ERR_NA; @@ -254,6 +271,10 @@ static GSList *scan_##X(GSList *options) { return scan(options, X); } static GSList *dev_list_##X(void) { return dev_list(X); } #define HW_DEV_CLEAR(X) \ static int dev_clear_##X(void) { return dev_clear(X); } +#define HW_CONFIG_LIST(X) \ +static int config_list_##X(uint32_t key, GVariant **data, \ +const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { \ +return config_list(key, data, sdi, cg, X); } #define HW_DEV_ACQUISITION_START(X) \ static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); } @@ -265,6 +286,7 @@ HW_CLEANUP(ID_UPPER) \ HW_SCAN(ID_UPPER) \ HW_DEV_LIST(ID_UPPER) \ HW_DEV_CLEAR(ID_UPPER) \ +HW_CONFIG_LIST(ID_UPPER) \ HW_DEV_ACQUISITION_START(ID_UPPER) \ SR_PRIV struct sr_dev_driver ID##_driver_info = { \ .name = NAME, \ @@ -277,7 +299,7 @@ SR_PRIV struct sr_dev_driver ID##_driver_info = { \ .dev_clear = dev_clear_##ID_UPPER, \ .config_get = NULL, \ .config_set = config_set, \ - .config_list = config_list, \ + .config_list = config_list_##ID_UPPER, \ .dev_open = std_serial_dev_open, \ .dev_close = std_serial_dev_close, \ .dev_acquisition_start = dev_acquisition_start_##ID_UPPER, \