korad-kdxxxxp: Minor cosmetics and consistency changes.

This commit is contained in:
Uwe Hermann 2015-10-29 18:51:09 +01:00
parent c40ed60f27
commit 9e5366df4f
3 changed files with 17 additions and 21 deletions

View File

@ -222,16 +222,13 @@ static int config_get(uint32_t key, GVariant **data,
break; break;
case SR_CONF_REGULATION: case SR_CONF_REGULATION:
/* Dual channel not supported. */ /* Dual channel not supported. */
if (devc->cc_mode[0]) *data = g_variant_new_string((devc->cc_mode[0]) ? "CC" : "CV");
*data = g_variant_new_string("CC");
else
*data = g_variant_new_string("CV");
break; break;
case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
*data = g_variant_new_boolean(devc->OCP_enabled); *data = g_variant_new_boolean(devc->ocp_enabled);
break; break;
case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
*data = g_variant_new_boolean(devc->OVP_enabled); *data = g_variant_new_boolean(devc->ovp_enabled);
break; break;
default: default:
return SR_ERR_NA; return SR_ERR_NA;
@ -293,14 +290,14 @@ static int config_set(uint32_t key, GVariant *data,
break; break;
case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
bval = g_variant_get_boolean(data); bval = g_variant_get_boolean(data);
devc->OCP_enabled = bval; devc->ocp_enabled = bval;
devc->target = KDXXXXP_OCP; devc->target = KDXXXXP_OCP;
if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0) if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0)
return SR_ERR; return SR_ERR;
break; break;
case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
bval = g_variant_get_boolean(data); bval = g_variant_get_boolean(data);
devc->OVP_enabled = bval; devc->ovp_enabled = bval;
devc->target = KDXXXXP_OVP; devc->target = KDXXXXP_OVP;
if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0) if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0)
return SR_ERR; return SR_ERR;

View File

@ -111,11 +111,11 @@ SR_PRIV int korad_kdxxxxp_set_value(struct sr_serial_dev_inst *serial,
break; break;
case KDXXXXP_OCP: case KDXXXXP_OCP:
cmd = "OCP%01.0f"; cmd = "OCP%01.0f";
value = (devc->OCP_enabled) ? 1 : 0; value = (devc->ocp_enabled) ? 1 : 0;
break; break;
case KDXXXXP_OVP: case KDXXXXP_OVP:
cmd = "OVP%01.0f"; cmd = "OVP%01.0f";
value = (devc->OVP_enabled) ? 1 : 0; value = (devc->ovp_enabled) ? 1 : 0;
break; break;
case KDXXXXP_SAVE: case KDXXXXP_SAVE:
cmd = "SAV%01.0f"; cmd = "SAV%01.0f";
@ -249,13 +249,12 @@ SR_PRIV int korad_kdxxxxp_get_reply(struct sr_serial_dev_inst *serial,
devc->reply[count] = 0; devc->reply[count] = 0;
if (target) { if (target) {
/* Handle the strange 'M' */ /* Handle the strange 'M'. */
if (devc->reply[0] == 'M') { if (devc->reply[0] == 'M') {
for (i = 1; i < count; ++i) { for (i = 1; i < count; i++)
devc->reply[i - 1] = devc->reply[i]; devc->reply[i - 1] = devc->reply[i];
} /* Get the last character. */
/* Get the last character */ if ((i = korad_kdxxxxp_read_chars(serial, 1,
if (( i = korad_kdxxxxp_read_chars(serial, 1,
&(devc->reply[count]))) < 0) &(devc->reply[count]))) < 0)
return i; return i;
} }
@ -274,11 +273,11 @@ SR_PRIV int korad_kdxxxxp_get_reply(struct sr_serial_dev_inst *serial,
* 00 independent 01 series 11 parallel * 00 independent 01 series 11 parallel
*/ */
devc->beep_enabled = (1 << 4); devc->beep_enabled = (1 << 4);
devc->OCP_enabled = (status_byte & (1 << 5)); devc->ocp_enabled = (status_byte & (1 << 5));
devc->output_enabled = (status_byte & (1 << 6)); devc->output_enabled = (status_byte & (1 << 6));
/* Velleman LABPS3005 quirk */ /* Velleman LABPS3005 quirk */
if (devc->output_enabled) if (devc->output_enabled)
devc->OVP_enabled = (status_byte & (1 << 7)); devc->ovp_enabled = (status_byte & (1 << 7));
sr_dbg("Status: 0x%02x", status_byte); sr_dbg("Status: 0x%02x", status_byte);
sr_spew("Status: CH1: constant %s CH2: constant %s. " sr_spew("Status: CH1: constant %s CH2: constant %s. "
"Tracking would be %s. Device is " "Tracking would be %s. Device is "
@ -314,7 +313,7 @@ static void next_measurement(struct dev_context *devc)
case KDXXXXP_VOLTAGE_MAX: case KDXXXXP_VOLTAGE_MAX:
devc->target = KDXXXXP_CURRENT; devc->target = KDXXXXP_CURRENT;
break; break;
/* Read back what was set */ /* Read back what was set. */
case KDXXXXP_BEEP: case KDXXXXP_BEEP:
case KDXXXXP_OCP: case KDXXXXP_OCP:
case KDXXXXP_OVP: case KDXXXXP_OVP:

View File

@ -91,11 +91,11 @@ struct dev_context {
gboolean output_enabled; /**< Is the output enabled? */ gboolean output_enabled; /**< Is the output enabled? */
gboolean beep_enabled; /**< Enable beeper. */ gboolean beep_enabled; /**< Enable beeper. */
gboolean OCP_enabled; /**< Output current protection enabled */ gboolean ocp_enabled; /**< Output current protection enabled. */
gboolean OVP_enabled; /**< Output voltage protection enabled */ gboolean ovp_enabled; /**< Output voltage protection enabled. */
/* Temporary state across callbacks */ /* Temporary state across callbacks */
int target; /**< What reply to expect */ int target; /**< What reply to expect. */
int program; /**< Program to store or recall. */ int program; /**< Program to store or recall. */
char reply[6]; char reply[6];
}; };