summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-08-06 22:45:30 +0200
committerPeter Wu <lekensteyn@gmail.com>2013-08-22 22:59:27 +0200
commitc3b9d0121dbd9030533382bdb914434d7bb28c16 (patch)
treeed3a564935ae2c203473cea22ab082da8a720f10
parent0cc7c672f995f9414dd9b6ce24512e047a7f5af1 (diff)
downloadupower-c3b9d0121dbd9030533382bdb914434d7bb28c16.tar.gz
hidpp: test only once for d7 register
The d7 battery register does not magically re-appear, therefore skip this register once it is detected that the register is unusable. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
-rw-r--r--src/linux/hidpp-device.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/linux/hidpp-device.c b/src/linux/hidpp-device.c
index 579e88d..78216ca 100644
--- a/src/linux/hidpp-device.c
+++ b/src/linux/hidpp-device.c
@@ -149,6 +149,7 @@ struct HidppDevicePrivate
guint device_idx;
guint version;
HidppDeviceBattStatus batt_status;
+ gboolean batt_is_approx;
HidppDeviceKind kind;
int fd;
};
@@ -782,21 +783,24 @@ hidpp_device_refresh (HidppDevice *device,
/* get battery status */
if ((refresh_flags & HIDPP_REFRESH_FLAGS_BATTERY) > 0) {
if (priv->version == 1) {
- msg.type = HIDPP_MSG_TYPE_SHORT;
- msg.device_idx = priv->device_idx;
- msg.feature_idx = HIDPP_READ_SHORT_REGISTER;
- msg.function_idx = HIDPP_READ_SHORT_REGISTER_BATTERY;
- msg.s.params[0] = 0x00;
- msg.s.params[1] = 0x00;
- msg.s.params[2] = 0x00;
- ret = hidpp_device_cmd (device,
- &msg, &msg,
- error);
- if (!ret && hidpp_is_error(&msg, &error_code) &&
+ if (!priv->batt_is_approx) {
+ msg.type = HIDPP_MSG_TYPE_SHORT;
+ msg.device_idx = priv->device_idx;
+ msg.feature_idx = HIDPP_READ_SHORT_REGISTER;
+ msg.function_idx = HIDPP_READ_SHORT_REGISTER_BATTERY;
+ memset(msg.s.params, 0, sizeof(msg.s.params));
+ ret = hidpp_device_cmd (device,
+ &msg, &msg,
+ error);
+ if (!ret && hidpp_is_error(&msg, &error_code) &&
error_code == HIDPP10_ERROR_CODE_INVALID_ADDRESS) {
- g_error_free(*error);
- *error = NULL;
+ g_error_free(*error);
+ *error = NULL;
+ priv->batt_is_approx = TRUE;
+ }
+ }
+ if (priv->batt_is_approx) {
msg.type = HIDPP_MSG_TYPE_SHORT;
msg.device_idx = priv->device_idx;
msg.feature_idx = HIDPP_READ_SHORT_REGISTER;
@@ -931,6 +935,7 @@ hidpp_device_init (HidppDevice *device)
device->priv->fd = -1;
device->priv->feature_index = g_ptr_array_new_with_free_func (g_free);
device->priv->batt_status = HIDPP_DEVICE_BATT_STATUS_UNKNOWN;
+ device->priv->batt_is_approx = FALSE;
device->priv->kind = HIDPP_DEVICE_KIND_UNKNOWN;
/* add known root */