hp-3478a: Add get/set/list of digits.
This commit is contained in:
parent
e5137b9343
commit
7812a5c802
|
@ -35,6 +35,7 @@ static const uint32_t devopts[] = {
|
|||
SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
|
||||
SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
|
||||
SR_CONF_RANGE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
|
||||
SR_CONF_DIGITS | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
|
||||
};
|
||||
|
||||
static const struct {
|
||||
|
@ -49,7 +50,6 @@ static const struct {
|
|||
{SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE},
|
||||
};
|
||||
|
||||
|
||||
static const struct {
|
||||
enum sr_mq mq;
|
||||
enum sr_mqflag mqflag;
|
||||
|
@ -97,6 +97,16 @@ static const struct {
|
|||
{SR_MQ_RESISTANCE, SR_MQFLAG_FOUR_WIRE, 7, "30MR"},
|
||||
};
|
||||
|
||||
/** Available digits as strings. */
|
||||
static const char *digits[] = {
|
||||
"3.5", "4.5", "5.5",
|
||||
};
|
||||
|
||||
/** Mapping between devc->spec_digits and digits string. */
|
||||
static const char *digits_map[] = {
|
||||
"", "", "", "", "3.5", "4.5", "5.5",
|
||||
};
|
||||
|
||||
static struct sr_dev_driver hp_3478a_driver_info;
|
||||
|
||||
static int create_front_channel(struct sr_dev_inst *sdi, int chan_idx)
|
||||
|
@ -195,6 +205,12 @@ static int config_get(uint32_t key, GVariant **data,
|
|||
}
|
||||
*data = g_variant_new_string(range_str);
|
||||
break;
|
||||
case SR_CONF_DIGITS:
|
||||
ret = hp_3478a_get_status_bytes(sdi);
|
||||
if (ret != SR_OK)
|
||||
return ret;
|
||||
*data = g_variant_new_string(digits_map[devc->spec_digits]);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
@ -211,6 +227,7 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
GVariant *tuple_child;
|
||||
unsigned int i;
|
||||
const char *range_str;
|
||||
const char *digits_str;
|
||||
|
||||
(void)cg;
|
||||
|
||||
|
@ -237,6 +254,13 @@ static int config_set(uint32_t key, GVariant *data,
|
|||
}
|
||||
}
|
||||
return SR_ERR_NA;
|
||||
case SR_CONF_DIGITS:
|
||||
digits_str = g_variant_get_string(data, NULL);
|
||||
for (i = 0; i < ARRAY_SIZE(rangeopts); i++) {
|
||||
if (g_strcmp0(digits_map[i], digits_str) == 0)
|
||||
return hp_3478a_set_digits(sdi, i);
|
||||
}
|
||||
return SR_ERR_NA;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
@ -286,6 +310,9 @@ static int config_list(uint32_t key, GVariant **data,
|
|||
}
|
||||
*data = g_variant_builder_end(&gvb);
|
||||
break;
|
||||
case SR_CONF_DIGITS:
|
||||
*data = g_variant_new_strv(ARRAY_AND_SIZE(digits));
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
@ -308,7 +335,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
|
|||
* NOTE: For faster readings, there are some things one can do:
|
||||
* - Turn off the display: sr_scpi_send(scpi, "D3SIGROK").
|
||||
* - Set the line frequency to 60Hz via switch (back of the unit).
|
||||
* - Set to 3.5 digits measurement (add config key SR_CONF_DIGITS).
|
||||
* - Set to 3.5 digits measurement.
|
||||
*/
|
||||
|
||||
/* Set to internal trigger. */
|
||||
|
|
|
@ -110,6 +110,24 @@ SR_PRIV int hp_3478a_set_range(const struct sr_dev_inst *sdi, int range_exp)
|
|||
return hp_3478a_get_status_bytes(sdi);
|
||||
}
|
||||
|
||||
SR_PRIV int hp_3478a_set_digits(const struct sr_dev_inst *sdi, uint8_t digits)
|
||||
{
|
||||
int ret;
|
||||
struct sr_scpi_dev_inst *scpi = sdi->conn;
|
||||
struct dev_context *devc = sdi->priv;
|
||||
|
||||
/* No need to send command if we're not changing the range. */
|
||||
if (devc->spec_digits == digits)
|
||||
return SR_OK;
|
||||
|
||||
/* digits are based on devc->spec_digits, so we have to substract 1 */
|
||||
ret = sr_scpi_send(scpi, "N%i", digits-1);
|
||||
if (ret != SR_OK)
|
||||
return ret;
|
||||
|
||||
return hp_3478a_get_status_bytes(sdi);
|
||||
}
|
||||
|
||||
static int parse_range_vdc(struct dev_context *devc, uint8_t range_byte)
|
||||
{
|
||||
if ((range_byte & SB1_RANGE_BLOCK) == RANGE_VDC_30MV) {
|
||||
|
|
|
@ -162,6 +162,7 @@ struct channel_context {
|
|||
SR_PRIV int hp_3478a_set_mq(const struct sr_dev_inst *sdi, enum sr_mq mq,
|
||||
enum sr_mqflag mq_flags);
|
||||
SR_PRIV int hp_3478a_set_range(const struct sr_dev_inst *sdi, int range_exp);
|
||||
SR_PRIV int hp_3478a_set_digits(const struct sr_dev_inst *sdi, uint8_t digits);
|
||||
SR_PRIV int hp_3478a_get_status_bytes(const struct sr_dev_inst *sdi);
|
||||
SR_PRIV int hp_3478a_receive_data(int fd, int revents, void *cb_data);
|
||||
|
||||
|
|
Loading…
Reference in New Issue