summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-08-28 19:12:12 +0200
committerPeter Wu <lekensteyn@gmail.com>2013-09-02 11:45:34 +0200
commit11801668f75ea70807eff64d71b7fc5d7a671b0e (patch)
treef79f9c2d8824f6352e786bbdea4a71d628a61ebf
parent9bc63112c7c5caa9a86e4e5a09f56eff4286d8e3 (diff)
downloadupower-11801668f75ea70807eff64d71b7fc5d7a671b0e.tar.gz
hidpp: fix K750 battery and luminosity properties
Since commit b1f12feb1fd4535255f04c91bef90ae11ce57311 ("Factor out the Logitech Unifying support to support other devices"), the battery status would always be reported as 1% for the K750 keyboard. Besides that, the luminosity level was removed. This patch fixes the battery level and re-adds the luminosity level. To avoid negativity issues when reading light level into a double type, make the HidppMessage params unsigned. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
-rw-r--r--src/linux/hidpp-device.c37
-rw-r--r--src/linux/hidpp-device.h1
-rw-r--r--src/linux/up-device-unifying.c6
3 files changed, 40 insertions, 4 deletions
diff --git a/src/linux/hidpp-device.c b/src/linux/hidpp-device.c
index d714b46..ea0f3e8 100644
--- a/src/linux/hidpp-device.c
+++ b/src/linux/hidpp-device.c
@@ -129,10 +129,10 @@ typedef struct {
guchar function_idx; /* funcId:software_id */
union {
struct {
- gchar params[3];
+ guchar params[3];
} s; /* short */
struct {
- gchar params[16];
+ guchar params[16];
} l; /* long */
};
} HidppMessage;
@@ -154,6 +154,7 @@ struct HidppDevicePrivate
int fd;
gboolean is_present;
gchar *serial;
+ double lux;
};
typedef struct {
@@ -597,6 +598,17 @@ hidpp_device_is_reachable (HidppDevice *device)
}
/**
+ * hidpp_device_get_luminosity:
+ * Determine the luminosity of the device in lux or negative if unknown.
+ */
+double
+hidpp_device_get_luminosity (HidppDevice *device)
+{
+ g_return_val_if_fail (HIDPP_IS_DEVICE (device), -1);
+ return device->priv->lux;
+}
+
+/**
* hidpp_device_set_hidraw_device:
**/
void
@@ -919,8 +931,24 @@ hidpp_device_refresh (HidppDevice *device,
error);
if (!ret)
goto out;
- priv->batt_percentage = msg.s.params[0];
- priv->batt_status = HIDPP_DEVICE_BATT_STATUS_DISCHARGING;
+
+ /* assume a BattLightMeasureEvent after previous command */
+ ret = hidpp_device_read_resp (device,
+ priv->device_idx,
+ map->idx,
+ HIDPP_FEATURE_SOLAR_DASHBOARD_BE_BATTERY_LEVEL_STATUS,
+ &msg,
+ error);
+ if (!ret)
+ goto out;
+
+ priv->batt_percentage = msg.l.params[0];
+ priv->lux = (msg.l.params[1] << 8) | msg.l.params[2];
+ if (priv->lux > 200) {
+ priv->batt_status = HIDPP_DEVICE_BATT_STATUS_CHARGING;
+ } else {
+ priv->batt_status = HIDPP_DEVICE_BATT_STATUS_DISCHARGING;
+ }
}
/* send a BatteryLevelStatus report */
@@ -1005,6 +1033,7 @@ hidpp_device_init (HidppDevice *device)
device->priv->batt_is_approx = FALSE;
device->priv->kind = HIDPP_DEVICE_KIND_UNKNOWN;
device->priv->serial = NULL;
+ device->priv->lux = -1;
/* add known root */
map = g_new0 (HidppDeviceMap, 1);
diff --git a/src/linux/hidpp-device.h b/src/linux/hidpp-device.h
index fa334f8..1d73a44 100644
--- a/src/linux/hidpp-device.h
+++ b/src/linux/hidpp-device.h
@@ -80,6 +80,7 @@ guint hidpp_device_get_version (HidppDevice *device);
HidppDeviceBattStatus hidpp_device_get_batt_status (HidppDevice *device);
HidppDeviceKind hidpp_device_get_kind (HidppDevice *device);
const gchar *hidpp_device_get_serial (HidppDevice *device);
+double hidpp_device_get_luminosity (HidppDevice *device);
void hidpp_device_set_hidraw_device (HidppDevice *device,
const gchar *hidraw_device);
void hidpp_device_set_index (HidppDevice *device,
diff --git a/src/linux/up-device-unifying.c b/src/linux/up-device-unifying.c
index 830fa32..29f28e9 100644
--- a/src/linux/up-device-unifying.c
+++ b/src/linux/up-device-unifying.c
@@ -56,6 +56,7 @@ up_device_unifying_refresh (UpDevice *device)
UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;
UpDeviceUnifying *unifying = UP_DEVICE_UNIFYING (device);
UpDeviceUnifyingPrivate *priv = unifying->priv;
+ double lux;
/* refresh the battery stats */
refresh_flags = HIDPP_REFRESH_FLAGS_BATTERY;
@@ -98,6 +99,11 @@ up_device_unifying_refresh (UpDevice *device)
}
g_get_current_time (&timeval);
+ lux = hidpp_device_get_luminosity (priv->hidpp_device);
+ if (lux >= 0) {
+ g_object_set (device, "luminosity", lux, NULL);
+ }
+
g_object_set (device,
"is-present", hidpp_device_is_reachable (priv->hidpp_device),
"percentage", (gdouble) hidpp_device_get_batt_percentage (priv->hidpp_device),