]> sigrok.org Git - libsigrok.git/blobdiff - hardware/mic-985xx/api.c
mic-985xx: Add support for the MIC 98581.
[libsigrok.git] / hardware / mic-985xx / api.c
index b8983a6dab69aa336baf78edad383d04cfa89af3..4b184e7cbdd6f3b0a43c98980f71d03f71c98c1e 100644 (file)
@@ -35,11 +35,18 @@ static const int hwcaps[] = {
        0,
 };
 
+SR_PRIV struct sr_dev_driver mic_98581_driver_info;
 SR_PRIV struct sr_dev_driver mic_98583_driver_info;
 
 SR_PRIV const struct mic_dev_info mic_devs[] = {
        {
-               "MIC", "98583", "38400/8n2", 32000, TRUE, TRUE,
+               "MIC", "98581", "38400/8n2", 32000, TRUE, FALSE, 6,
+               packet_valid_temp,
+               &mic_98581_driver_info, receive_data_MIC_98581,
+       },
+       {
+               "MIC", "98583", "38400/8n2", 32000, TRUE, TRUE, 10,
+               packet_valid_temp_hum,
                &mic_98583_driver_info, receive_data_MIC_98583,
        },
 };
@@ -122,9 +129,11 @@ static GSList *scan(const char *conn, const char *serialcomm, int idx)
                goto scan_cleanup;
        sdi->probes = g_slist_append(sdi->probes, probe);
 
-       if (!(probe = sr_probe_new(1, SR_PROBE_ANALOG, TRUE, "Humidity")))
-               goto scan_cleanup;
-       sdi->probes = g_slist_append(sdi->probes, probe);
+       if (mic_devs[idx].has_humidity) {
+               if (!(probe = sr_probe_new(1, SR_PROBE_ANALOG, TRUE, "Humidity")))
+                       goto scan_cleanup;
+               sdi->probes = g_slist_append(sdi->probes, probe);
+       }
 
        drvc->instances = g_slist_append(drvc->instances, sdi);
        devices = g_slist_append(devices, sdi);
@@ -169,11 +178,7 @@ static GSList *hw_scan(GSList *options, int idx)
 
 static GSList *hw_dev_list(int idx)
 {
-       struct drv_context *drvc;
-
-       drvc = mic_devs[idx].di->priv;
-
-       return drvc->instances;
+       return ((struct drv_context *)(mic_devs[idx].di->priv))->instances;
 }
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
@@ -260,26 +265,17 @@ static int config_list(int key, const void **data, const struct sr_dev_inst *sdi
 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                                    void *cb_data, int idx)
 {
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_header header;
        struct dev_context *devc;
 
        devc = sdi->priv;
 
        devc->cb_data = cb_data;
 
-       sr_dbg("Starting acquisition.");
-
        devc->num_samples = 0;
        devc->starttime = g_get_monotonic_time();
 
        /* Send header packet to the session bus. */
-       sr_dbg("Sending SR_DF_HEADER.");
-       packet.type = SR_DF_HEADER;
-       packet.payload = (uint8_t *)&header;
-       header.feed_version = 1;
-       gettimeofday(&header.starttime, NULL);
-       sr_session_send(devc->cb_data, &packet);
+       std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
 
        /* Poll every 100ms, or whenever some data comes in. */
        sr_source_add(devc->serial->fd, G_IO_IN, 100,
@@ -290,27 +286,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 
 static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-       struct dev_context *devc;
-
-       if (sdi->status != SR_ST_ACTIVE) {
-               sr_err("Device inactive, can't stop acquisition.");
-               return SR_ERR;
-       }
-
-       devc = sdi->priv;
-
-       sr_dbg("Stopping acquisition.");
-
-       sr_source_remove(devc->serial->fd);
-       hw_dev_close((struct sr_dev_inst *)sdi);
-
-       /* Send end packet to the session bus. */
-       sr_dbg("Sending SR_DF_END.");
-       packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
-
-       return SR_OK;
+       return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close,
+              ((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN);
 }
 
 /* Driver-specific API function wrappers */
@@ -355,4 +332,5 @@ SR_PRIV struct sr_dev_driver ID##_driver_info = { \
        .priv = NULL, \
 };
 
+DRV(mic_98581, MIC_98581, "mic-98581", "MIC 98581")
 DRV(mic_98583, MIC_98583, "mic-98583", "MIC 98583")