]> sigrok.org Git - libsigrok.git/commitdiff
cem-dt-885x: Support for powering off the device
authorBert Vermeulen <redacted>
Mon, 17 Jun 2013 13:46:14 +0000 (15:46 +0200)
committerBert Vermeulen <redacted>
Mon, 17 Jun 2013 14:17:39 +0000 (16:17 +0200)
hardware/cem-dt-885x/api.c
hardware/cem-dt-885x/protocol.c
hardware/cem-dt-885x/protocol.h

index fb309fe2592c55029c10cdfddbc683591a9f8627..3b3082844cc4dad70cd20248f0c49da19f82a7b3 100644 (file)
@@ -32,12 +32,13 @@ static const int32_t hwcaps[] = {
        SR_CONF_SOUNDLEVELMETER,
        SR_CONF_LIMIT_SAMPLES,
        SR_CONF_CONTINUOUS,
-       SR_CONF_DATALOG,
        SR_CONF_SPL_WEIGHT_FREQ,
        SR_CONF_SPL_WEIGHT_TIME,
+       SR_CONF_SPL_MEASUREMENT_RANGE,
+       SR_CONF_DATALOG,
        SR_CONF_HOLD_MAX,
        SR_CONF_HOLD_MIN,
-       SR_CONF_SPL_MEASUREMENT_RANGE,
+       SR_CONF_POWER_OFF,
 };
 
 static const char *weight_freq[] = {
@@ -232,6 +233,9 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi)
                        *data = g_variant_new_tuple(range, 2);
                }
                break;
+       case SR_CONF_POWER_OFF:
+               *data = g_variant_new_boolean(FALSE);
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -305,6 +309,10 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi)
                        }
                }
                break;
+       case SR_CONF_POWER_OFF:
+               if (g_variant_get_boolean(data))
+                       ret = cem_dt_885x_power_off(sdi);
+               break;
        default:
                ret = SR_ERR_NA;
        }
index 3ae43a7042a51f322b115e4db1ecb76e16b34fec..5f2972f68fd3b2fe05307c1a5565f01bd0feac23 100644 (file)
@@ -685,3 +685,36 @@ SR_PRIV int cem_dt_885x_meas_range_set(const struct sr_dev_inst *sdi,
 
        return ret;
 }
+
+SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi)
+{
+       struct sr_serial_dev_inst *serial;
+       char c, cmd;
+
+       serial = sdi->conn;
+
+       /* Reopen the port in non-blocking mode, so we can properly
+        * detect when the device stops communicating. */
+       serial_close(serial);
+       if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
+               return SR_ERR;
+
+       cmd = CMD_TOGGLE_POWER_OFF;
+       while (TRUE) {
+               serial_flush(serial);
+               if (serial_write(serial, (const void *)&cmd, 1) != 1)
+                       return SR_ERR;
+               /* It never takes more than 23ms for the next token to arrive. */
+               g_usleep(25 * 1000);
+               if (serial_read(serial, &c, 1) != 1)
+                       /* Device is no longer responding. Good! */
+                       break;
+       }
+
+       /* In case the user manually turns on the device again, reset
+        * the port back to blocking. */
+       serial_close(serial);
+       serial_open(serial, SERIAL_RDWR);
+
+       return SR_OK;
+}
index 5910608652485949e9b4945e1242395534751f03..28a7cc6ae24eb7e705581d15d6e1e1c974c38dd3 100644 (file)
@@ -72,6 +72,7 @@ enum {
        CMD_TOGGLE_WEIGHT_TIME = 0x77,
        CMD_TOGGLE_HOLD_MAX_MIN = 0x11,
        CMD_TOGGLE_MEAS_RANGE = 0x88,
+       CMD_TOGGLE_POWER_OFF = 0x33,
 };
 
 /** Private, per-device-instance driver context. */
@@ -121,5 +122,6 @@ SR_PRIV int cem_dt_885x_meas_range_get(const struct sr_dev_inst *sdi,
                uint64_t *low, uint64_t *high);
 SR_PRIV int cem_dt_885x_meas_range_set(const struct sr_dev_inst *sdi,
                uint64_t low, uint64_t high);
+SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi);
 
 #endif