X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fmic-985xx%2Fapi.c;h=14f0c4a8197603c84d6a060531c4b8760d1138e0;hb=204dd31fa1074a78fbe3bf04208776a4a3615a1c;hp=5f9ea71aac88fd26ef0dd25841ee6f22d841f931;hpb=4b1a9d5d8641080bf10e269aa12a3fc17460365f;p=libsigrok.git
diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c
index 5f9ea71a..14f0c4a8 100644
--- a/src/hardware/mic-985xx/api.c
+++ b/src/hardware/mic-985xx/api.c
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
#include
@@ -68,8 +67,6 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
- serial_flush(serial);
-
/* TODO: Query device type. */
// ret = mic_cmd_get_device_info(serial);
@@ -117,61 +114,41 @@ static GSList *scan(GSList *options, int idx)
if (!conn)
return NULL;
- if (serialcomm) {
- /* Use the provided comm specs. */
+ if (serialcomm)
devices = mic_scan(conn, serialcomm, idx);
- } else {
- /* Try the default. */
+ else
devices = mic_scan(conn, mic_devs[idx].conn, idx);
- }
return 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, int idx)
+static int config_list(uint32_t key, GVariant **data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg, int idx)
{
- (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:
- 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;
- }
-
- return SR_OK;
+ /*
+ * We can't use the ternary operator here! The result would contain
+ * sizeof((cond) ? A : B) where A/B are arrays of different type/size.
+ * The ternary operator always returns the "common" type of A and B,
+ * which would be a pointer instead of either the A or B arrays.
+ * Thus, sizeof() would yield the size of a pointer, not the size
+ * of either the A or B array, which is not what we want.
+ */
+ if (mic_devs[idx].has_humidity)
+ return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts_temp_hum, devopts);
+ else
+ return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts_temp, devopts);
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx)
@@ -179,15 +156,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, int idx)
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
devc = sdi->priv;
sr_sw_limits_acquisition_start(&devc->limits);
std_session_send_df_header(sdi);
- /* Poll every 100ms, or whenever some data comes in. */
serial = sdi->conn;
serial_source_add(sdi->session, serial, G_IO_IN, 100,
mic_devs[idx].receive_data, (void *)sdi);
@@ -220,6 +193,7 @@ static struct sr_dev_driver ID##_driver_info = { \
.cleanup = std_cleanup, \
.scan = scan_##ID_UPPER, \
.dev_list = std_dev_list, \
+ .dev_clear = std_dev_clear, \
.config_get = NULL, \
.config_set = config_set, \
.config_list = config_list_##ID_UPPER, \