only match on USB HID devices so we don't try to connect to every USB device on the system at startup

This commit is contained in:
Richard Hughes 2008-08-13 08:08:29 +01:00
parent a104eb5519
commit 3a468e7521
6 changed files with 82 additions and 12 deletions

1
src/.gitignore vendored
View file

@ -6,4 +6,5 @@ devkit-power-daemon
*-marshal.h
*.conf
*.service
.libs

View file

@ -1,4 +1,3 @@
##############################################################################################################
# Logitech Mice with CSR battery readouts
#

View file

@ -0,0 +1,46 @@
##############################################################################################################
# Uninterruptable Power Supplies with USBHID interface
#
SYSFS{idVendor}=="0463", ENV{ID_VENDOR}="MGE Systems"
SYSFS{idVendor}=="051d", ENV{ID_VENDOR}="APC"
SYSFS{idVendor}=="0764", ENV{ID_VENDOR}="CyberPower"
SYSFS{idVendor}=="09ae", ENV{ID_VENDOR}="Tripp Lite"
SYSFS{idVendor}=="050d", ENV{ID_VENDOR}="Belkin"
SYSFS{idVendor}=="06da", ENV{ID_VENDOR}="Liebert"
SYSFS{idVendor}=="0925", ENV{ID_VENDOR}="Kebo"
# MGE UPS SYSTEMS
SYSFS{idVendor}=="0463", SYSFS{idProduct}=="0001", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="0463", SYSFS{idProduct}=="0xffff", ENV{ID_BATTERY_TYPE}="ups"
# APC
SYSFS{idVendor}=="051d", SYSFS{idProduct}=="0002", ENV{ID_BATTERY_TYPE}="ups"
# CyberPower
SYSFS{idVendor}=="0764", SYSFS{idProduct}=="0005", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="0764", SYSFS{idProduct}=="0x0501", ENV{ID_BATTERY_TYPE}="ups"
# Tripp Lite
SYSFS{idVendor}=="09ae", SYSFS{idProduct}=="1003", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="09ae", SYSFS{idProduct}=="0x2005", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="09ae", SYSFS{idProduct}=="0x2007", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="09ae", SYSFS{idProduct}=="0x3012", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="09ae", SYSFS{idProduct}=="0x4002", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="09ae", SYSFS{idProduct}=="0x4003", ENV{ID_BATTERY_TYPE}="ups"
# Belkin
SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0375", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0x0551", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0x0751", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0x0900", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0x0910", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0x0912", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0x0980", ENV{ID_BATTERY_TYPE}="ups"
SYSFS{idVendor}=="050d", SYSFS{idProduct}=="0x1100", ENV{ID_BATTERY_TYPE}="ups"
# Liebert
SYSFS{idVendor}=="06da", SYSFS{idProduct}=="ffff", ENV{ID_BATTERY_TYPE}="ups"
# Kebo
SYSFS{idVendor}=="0925", SYSFS{idProduct}=="1234", ENV{ID_BATTERY_TYPE}="ups"

View file

@ -82,19 +82,21 @@ $(dbusconf_DATA): $(dbusconf_in_files) Makefile
cp $< $@
udevrulesdir = $(sysconfdir)/udev/rules.d
udevrules_DATA = 95-devkit-power.rules
udevrules_DATA = \
95-devkit-power-hid.rules \
95-devkit-power-csr.rules
install-data-hook:
$(mkinstalldirs) $(DESTDIR)$(localstatedir)/lib/DeviceKit-power
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = \
org.freedesktop.DeviceKit.Power.xml \
org.freedesktop.DeviceKit.Power.Device.xml \
dkp-marshal.list \
95-devkit-power.rules \
$(service_in_files) \
EXTRA_DIST = \
org.freedesktop.DeviceKit.Power.xml \
org.freedesktop.DeviceKit.Power.Device.xml \
dkp-marshal.list \
95-devkit-power.rules \
$(service_in_files) \
$(dbusconf_in_files)
clean-local :

View file

@ -277,6 +277,7 @@ dkp_hid_coldplug (DkpDevice *device)
DevkitDevice *d;
gboolean ret = FALSE;
const gchar *device_file;
const gchar *type;
DkpObject *obj = dkp_device_get_obj (device);
/* detect what kind of device we are */
@ -284,6 +285,13 @@ dkp_hid_coldplug (DkpDevice *device)
if (d == NULL)
dkp_error ("could not get device");
/* get the type */
type = devkit_device_get_property (d, "ID_BATTERY_TYPE");
if (type == NULL || strcmp (type, "ups") != 0) {
dkp_debug ("not a UPS device");
goto out;
}
/* get the device file */
device_file = devkit_device_get_device_file (d);
if (device_file == NULL) {
@ -311,11 +319,16 @@ dkp_hid_coldplug (DkpDevice *device)
obj->power_supply = TRUE;
obj->battery_is_present = TRUE;
/* try and get from udev if UPS is being difficult */
if (obj->vendor == NULL)
obj->vendor = g_strdup (devkit_device_get_property (d, "ID_VENDOR"));
/* coldplug everything */
dkp_hid_get_all_data (hid);
/* coldplug */
ret = dkp_hid_refresh (device);
out:
return ret;
}
@ -326,6 +339,7 @@ out:
static gboolean
dkp_hid_refresh (DkpDevice *device)
{
gboolean set = FALSE;
gboolean ret = FALSE;
GTimeVal time;
guint i;
@ -338,14 +352,21 @@ dkp_hid_refresh (DkpDevice *device)
g_get_current_time (&time);
obj->update_time = time.tv_sec;
/* read any data */
/* read any data -- it's okay if there's nothing as we are non-blocking */
rd = read (hid->priv->fd, ev, sizeof (ev));
if (rd < (int) sizeof (ev[0]))
if (rd < (int) sizeof (ev[0])) {
ret = TRUE;
goto out;
}
/* process each event */
for (i=0; i < rd / sizeof (ev[0]); i++)
ret = dkp_hid_set_obj (hid, ev[i].hid, ev[i].value);
for (i=0; i < rd / sizeof (ev[0]); i++) {
set = dkp_hid_set_obj (hid, ev[i].hid, ev[i].value);
/* if only takes one match to make refresh a success */
if (set)
ret = TRUE;
}
out:
return ret;
}

1
tools/.gitignore vendored
View file

@ -5,4 +5,5 @@ devkit-power-on-battery
*.o
*-marshal.c
*-marshal.h
.libs