• D
    hid-input: add support for HID devices reporting Battery Strength · c5a92aa3
    Daniel Nicoletti 提交于
    I've sent an email earlier asking for help with a GetFeature code, and now I
    have a second patch on top of Jeremy's to provide the battery functionality
    for devices that support reporting it.
    
    If I understood correctly when talking to Jeremy he said his device
    never actually reported the status as an input event (sorry if I didn't
    understand it correctly), and after reading HID specs I believe it's
    really because it was meant to be probed, I have an Apple Keyboard and
    Magic Trackpad both bluetooth batteries operated, so using PacketLogger
    I saw that Mac OSX always ask the battery status using the so called
    GetFeature.
    
    What my patch does is basically:
    - store the report id that matches the battery_strength
    - setup the battery if 0x6.0x20 is found, even if that is reported as a feature
      (as it was meant to be but only the MagicTrackpad does)
    - when upower or someone access /sys/class/power_supply/hid-*/capacity it
      will probe the device and return it's status.
    
    It works great for both devices, but I have two concerns:
    - the report_features function has a duplicated code
    - it would be nice if it was possible for specific drivers to provide their own
      probe as there might be some strange devices... (but maybe it's
    already possible)
    
    I've talked to the upower dev and he fixed it to be able to show the
    right percentage.
    
    Here how the uevent file (in /sys/class/power_supply/hid-*/) looks like:
    POWER_SUPPLY_NAME=hid-00:22:41:D9:18:E7-battery
    POWER_SUPPLY_PRESENT=1
    POWER_SUPPLY_ONLINE=1
    POWER_SUPPLY_CAPACITY=66
    POWER_SUPPLY_MODEL_NAME=MacAdmin’s keyboard
    POWER_SUPPLY_STATUS=Discharging
    
    POWER_SUPPLY_NAME=hid-70:CD:60:F5:FF:3F-battery
    POWER_SUPPLY_PRESENT=1
    POWER_SUPPLY_ONLINE=1
    POWER_SUPPLY_CAPACITY=62
    POWER_SUPPLY_MODEL_NAME=nexx’s Trackpad
    POWER_SUPPLY_STATUS=Discharging
    Signed-off-by: NDaniel Nicoletti <dantti12@gmail.com>
    c5a92aa3
hid-input.c 35.0 KB