mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-06 04:28:28 +02:00
battery-technology should be an enumerated type
This commit is contained in:
parent
2da987f9bc
commit
ec658f5d29
4 changed files with 80 additions and 7 deletions
|
|
@ -78,3 +78,65 @@ devkit_power_convert_state_to_text (DevkitPowerState state_enum)
|
|||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
const char *
|
||||
devkit_power_convert_technology_to_text (DevkitPowerTechnology technology_enum)
|
||||
{
|
||||
const char *technology = NULL;
|
||||
switch (technology_enum) {
|
||||
case DEVKIT_POWER_TECHNOLGY_LITHIUM_ION:
|
||||
technology = "lithium-ion";
|
||||
break;
|
||||
case DEVKIT_POWER_TECHNOLGY_LITHIUM_POLYMER:
|
||||
technology = "lithium-polymer";
|
||||
break;
|
||||
case DEVKIT_POWER_TECHNOLGY_LITHIUM_IRON_PHOSPHATE:
|
||||
technology = "lithium-iron-phosphate";
|
||||
break;
|
||||
case DEVKIT_POWER_TECHNOLGY_LEAD_ACID:
|
||||
technology = "lead-acid";
|
||||
break;
|
||||
case DEVKIT_POWER_TECHNOLGY_NICKEL_CADMIUM:
|
||||
technology = "nickel-cadmium";
|
||||
break;
|
||||
case DEVKIT_POWER_TECHNOLGY_NICKEL_METAL_HYDRIDE:
|
||||
technology = "nickel-metal-hydride";
|
||||
break;
|
||||
case DEVKIT_POWER_TECHNOLGY_UNKNOWN:
|
||||
technology = "unknown";
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
return technology;
|
||||
}
|
||||
|
||||
DevkitPowerTechnology
|
||||
devkit_power_convert_acpi_technology_to_enum (const char *type)
|
||||
{
|
||||
if (type == NULL) {
|
||||
return DEVKIT_POWER_TECHNOLGY_UNKNOWN;
|
||||
}
|
||||
/* every case combination of Li-Ion is commonly used.. */
|
||||
if (strcasecmp (type, "li-ion") == 0 ||
|
||||
strcasecmp (type, "lion") == 0) {
|
||||
return DEVKIT_POWER_TECHNOLGY_LITHIUM_ION;
|
||||
}
|
||||
if (strcasecmp (type, "pb") == 0 ||
|
||||
strcasecmp (type, "pbac") == 0) {
|
||||
return DEVKIT_POWER_TECHNOLGY_LEAD_ACID;
|
||||
}
|
||||
if (strcasecmp (type, "lip") == 0 ||
|
||||
strcasecmp (type, "lipo") == 0) {
|
||||
return DEVKIT_POWER_TECHNOLGY_LITHIUM_POLYMER;
|
||||
}
|
||||
if (strcasecmp (type, "nimh") == 0) {
|
||||
return DEVKIT_POWER_TECHNOLGY_NICKEL_METAL_HYDRIDE;
|
||||
}
|
||||
if (strcasecmp (type, "lifo") == 0) {
|
||||
return DEVKIT_POWER_TECHNOLGY_LITHIUM_IRON_PHOSPHATE;
|
||||
}
|
||||
return DEVKIT_POWER_TECHNOLGY_UNKNOWN;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,20 @@ typedef enum {
|
|||
DEVKIT_POWER_STATE_UNKNOWN
|
||||
} DevkitPowerState;
|
||||
|
||||
typedef enum {
|
||||
DEVKIT_POWER_TECHNOLGY_LITHIUM_ION,
|
||||
DEVKIT_POWER_TECHNOLGY_LITHIUM_POLYMER,
|
||||
DEVKIT_POWER_TECHNOLGY_LITHIUM_IRON_PHOSPHATE,
|
||||
DEVKIT_POWER_TECHNOLGY_LEAD_ACID,
|
||||
DEVKIT_POWER_TECHNOLGY_NICKEL_CADMIUM,
|
||||
DEVKIT_POWER_TECHNOLGY_NICKEL_METAL_HYDRIDE,
|
||||
DEVKIT_POWER_TECHNOLGY_UNKNOWN
|
||||
} DevkitPowerTechnology;
|
||||
|
||||
const char *devkit_power_convert_type_to_text (DevkitPowerType type_enum);
|
||||
const char *devkit_power_convert_state_to_text (DevkitPowerState state_enum);
|
||||
const char *devkit_power_convert_technology_to_text (DevkitPowerTechnology technology_enum);
|
||||
DevkitPowerTechnology devkit_power_convert_acpi_technology_to_enum (const char *type);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ struct DevkitPowerSourcePrivate
|
|||
|
||||
gboolean line_power_online;
|
||||
DevkitPowerState battery_state;
|
||||
DevkitPowerTechnology battery_technology;
|
||||
|
||||
double battery_energy;
|
||||
double battery_energy_empty;
|
||||
|
|
@ -73,7 +74,6 @@ struct DevkitPowerSourcePrivate
|
|||
gint64 battery_time_to_empty;
|
||||
gint64 battery_time_to_full;
|
||||
double battery_percentage;
|
||||
char *battery_technology;
|
||||
};
|
||||
|
||||
static void devkit_power_source_class_init (DevkitPowerSourceClass *klass);
|
||||
|
|
@ -181,7 +181,7 @@ get_property (GObject *object,
|
|||
break;
|
||||
|
||||
case PROP_BATTERY_TECHNOLOGY:
|
||||
g_value_set_string (value, source->priv->battery_technology);
|
||||
g_value_set_string (value, devkit_power_convert_technology_to_text (source->priv->battery_technology));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -553,10 +553,8 @@ update (DevkitPowerSource *source)
|
|||
char *s;
|
||||
|
||||
s = g_strstrip (sysfs_get_string (source->priv->native_path, "technology"));
|
||||
if (strcmp (s, "Unknown") != 0)
|
||||
source->priv->battery_technology = s;
|
||||
else
|
||||
g_free (s);
|
||||
source->priv->battery_technology = devkit_power_convert_acpi_technology_to_enum (s);
|
||||
g_free (s);
|
||||
|
||||
source->priv->vendor = g_strstrip (sysfs_get_string (source->priv->native_path, "manufacturer"));
|
||||
source->priv->model = g_strstrip (sysfs_get_string (source->priv->native_path, "model_name"));
|
||||
|
|
|
|||
|
|
@ -216,7 +216,8 @@
|
|||
|
||||
<property name="battery-technology" type="s" access="read">
|
||||
<doc:doc><doc:description><doc:para>
|
||||
Technology used in the battery; known values are "Li-ion".
|
||||
Technology used in the battery; known values are "lithium-ion", "lead-acid",
|
||||
"lithium-polymer", "nickel-metal-hydride", "lithium-iron-phosphate" or "unknown".
|
||||
</doc:para><doc:para>
|
||||
This property is only valid if the property
|
||||
<doc:ref type="property" to="Source:type">type</doc:ref>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue