Suunto EON Steel: do the proper enum lookup for a few more cases
Instead of hardcoding the enum values for setpoint type and gas type, use "lookup_enum()" to actually parse the enum data and use that. I don't think this matters right now, since the numeric translations haven't changed, but it is the RigthThing(tm) to do. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
cba786df2f
commit
d11d30999b
@ -776,21 +776,24 @@ static void sample_event_alarm_value(const struct type_desc *desc, struct sample
|
|||||||
static void sample_setpoint_type(const struct type_desc *desc, struct sample_data *info, unsigned char value)
|
static void sample_setpoint_type(const struct type_desc *desc, struct sample_data *info, unsigned char value)
|
||||||
{
|
{
|
||||||
dc_sample_value_t sample = {0};
|
dc_sample_value_t sample = {0};
|
||||||
|
const char *type = lookup_enum(desc, value);
|
||||||
|
|
||||||
switch (value) {
|
if (!type) {
|
||||||
case 0:
|
DEBUG(info->eon->base.context, "sample_setpoint_type(%u) did not match anything in %s", value, desc->format);
|
||||||
sample.ppo2 = info->eon->cache.lowsetpoint;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
sample.ppo2 = info->eon->cache.highsetpoint;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
sample.ppo2 = info->eon->cache.customsetpoint;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
DEBUG(info->eon->base.context, "sample_setpoint_type(%u)", value);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcasecmp(type, "Low"))
|
||||||
|
sample.ppo2 = info->eon->cache.lowsetpoint;
|
||||||
|
else if (!strcasecmp(type, "High"))
|
||||||
|
sample.ppo2 = info->eon->cache.highsetpoint;
|
||||||
|
else if (!strcasecmp(type, "Custom"))
|
||||||
|
sample.ppo2 = info->eon->cache.customsetpoint;
|
||||||
|
else {
|
||||||
|
DEBUG(info->eon->base.context, "sample_setpoint_type(%u) unknown type '%s'", value, type);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (info->callback) info->callback(DC_SAMPLE_SETPOINT, sample, info->userdata);
|
if (info->callback) info->callback(DC_SAMPLE_SETPOINT, sample, info->userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1110,24 +1113,24 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d
|
|||||||
{
|
{
|
||||||
int idx = eon->cache.ngases;
|
int idx = eon->cache.ngases;
|
||||||
dc_tankinfo_t tankinfo = DC_TANKINFO_METRIC;
|
dc_tankinfo_t tankinfo = DC_TANKINFO_METRIC;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
if (idx >= MAXGASES)
|
if (idx >= MAXGASES)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
eon->cache.ngases = idx+1;
|
eon->cache.ngases = idx+1;
|
||||||
switch (type) {
|
name = lookup_enum(desc, type);
|
||||||
case 0:
|
if (!name)
|
||||||
tankinfo = 0;
|
DEBUG(eon->base.context, "Unable to look up gas type %u in %s", type, desc->format);
|
||||||
break;
|
else if (!strcasecmp(name, "Diluent"))
|
||||||
case 3:
|
|
||||||
tankinfo |= DC_TANKINFO_CC_DILUENT;
|
tankinfo |= DC_TANKINFO_CC_DILUENT;
|
||||||
break;
|
else if (!strcasecmp(name, "Oxygen"))
|
||||||
case 4:
|
|
||||||
tankinfo |= DC_TANKINFO_CC_O2;
|
tankinfo |= DC_TANKINFO_CC_O2;
|
||||||
break;
|
else if (!strcasecmp(name, "None"))
|
||||||
default:
|
tankinfo = 0;
|
||||||
break;
|
else if (strcasecmp(name, "Primary"))
|
||||||
}
|
DEBUG(eon->base.context, "Unknown gas type %u (%s)", type, name);
|
||||||
|
|
||||||
eon->cache.tankinfo[idx] = tankinfo;
|
eon->cache.tankinfo[idx] = tankinfo;
|
||||||
|
|
||||||
eon->cache.initialized |= 1 << DC_FIELD_GASMIX_COUNT;
|
eon->cache.initialized |= 1 << DC_FIELD_GASMIX_COUNT;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user