]> sigrok.org Git - libsigrok.git/blobdiff - hardware/demo/demo.c
serial-dmm: Add Digitek DT4000ZC support.
[libsigrok.git] / hardware / demo / demo.c
index 7cde33082f17670e7bf51077749f9826b581e03b..cf8cef6ff9fdcb46e7fb76b6b6cd8395f5256301 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
  * Copyright (C) 2011 Olivier Fauchon <olivier@aixmarseille.com>
+ * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -170,6 +171,7 @@ static GSList *hw_scan(GSList *options)
        int i;
 
        (void)options;
+
        drvc = ddi->priv;
        devices = NULL;
 
@@ -181,7 +183,7 @@ static GSList *hw_scan(GSList *options)
        sdi->driver = ddi;
 
        for (i = 0; probe_names[i]; i++) {
-               if (!(probe = sr_probe_new(i, SR_PROBE_ANALOG, TRUE,
+               if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE,
                                probe_names[i])))
                        return NULL;
                sdi->probes = g_slist_append(sdi->probes, probe);
@@ -204,7 +206,6 @@ static GSList *hw_dev_list(void)
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
 {
-       /* Avoid compiler warnings. */
        (void)sdi;
 
        /* Nothing needed so far. */
@@ -214,7 +215,6 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
 
 static int hw_dev_close(struct sr_dev_inst *sdi)
 {
-       /* Avoid compiler warnings. */
        (void)sdi;
 
        /* Nothing needed so far. */
@@ -231,7 +231,6 @@ static int hw_cleanup(void)
 static int hw_info_get(int info_id, const void **data,
        const struct sr_dev_inst *sdi)
 {
-
        (void)sdi;
 
        switch (info_id) {
@@ -404,7 +403,6 @@ static int receive_data(int fd, int revents, void *cb_data)
        unsigned char c[BUFSIZE];
        gsize z;
 
-       /* Avoid compiler warnings. */
        (void)fd;
        (void)revents;
 
@@ -425,13 +423,8 @@ static int receive_data(int fd, int revents, void *cb_data)
 
        if (!thread_running && z <= 0) {
                /* Make sure we don't receive more packets. */
-               g_io_channel_shutdown(devc->channels[0], FALSE, NULL);
-
-               /* Send last packet. */
-               packet.type = SR_DF_END;
-               sr_session_send(devc->session_dev_id, &packet);
-
-               return FALSE;
+               hw_dev_acquisition_stop(NULL, cb_data);
+               return TRUE;
        }
 
        return TRUE;
@@ -447,6 +440,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        (void)sdi;
 
+       sr_dbg("Starting acquisition.");
+
        /* TODO: 'devc' is never g_free()'d? */
        if (!(devc = g_try_malloc(sizeof(struct dev_context)))) {
                sr_err("%s: devc malloc failed", __func__);
@@ -521,16 +516,23 @@ 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 dev_context *devc;
+       struct sr_datafeed_packet packet;
+
+       (void)sdi;
 
-       /* Avoid compiler warnings. */
-       (void)cb_data;
+       devc = cb_data;
 
-       devc = sdi->priv;
+       sr_dbg("Stopping aquisition.");
 
        /* Stop generate thread. */
        thread_running = 0;
 
        sr_session_source_remove_channel(devc->channels[0]);
+       g_io_channel_shutdown(devc->channels[0], FALSE, NULL);
+
+       /* Send last packet. */
+       packet.type = SR_DF_END;
+       sr_session_send(devc->session_dev_id, &packet);
 
        return SR_OK;
 }