Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linux/input): don't pass unknown battery values #2820

Merged
merged 2 commits into from
Jul 14, 2024

Conversation

cgutman
Copy link
Collaborator

@cgutman cgutman commented Jul 7, 2024

Description

The battery.percentage value is a real percentage (0..100), but it has a special value of LI_BATTERY_PERCENTAGE_UNKNOWN (0xFF) to indicate the percentage is unknown. We shouldn't pass this value or the LI_BATTERY_STATE_UNKNOWN status into inputino.

cc: @ABeltramo

Screenshot

Issues Fixed or Closed

Fixes #2715

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

Branch Updates

LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.

  • I want maintainers to keep my branch updated

Copy link

codecov bot commented Jul 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 9.23%. Comparing base (d57c66f) to head (a006100).

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #2820      +/-   ##
=========================================
- Coverage    9.24%   9.23%   -0.01%     
=========================================
  Files          97      97              
  Lines       17433   17440       +7     
  Branches     8314    8314              
=========================================
  Hits         1611    1611              
- Misses      12939   12946       +7     
  Partials     2883    2883              
Flag Coverage Δ
Linux 6.99% <0.00%> (-0.01%) ⬇️
Windows 4.53% <ø> (ø)
macOS-12 10.32% <ø> (ø)
macOS-13 10.23% <ø> (ø)
macOS-14 10.55% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/platform/linux/input/inputtino_gamepad.cpp 2.54% <0.00%> (-0.12%) ⬇️

@ReenigneArcher ReenigneArcher requested a review from Hazer July 8, 2024 17:09
Comment on lines 264 to 267
case LI_BATTERY_STATE_UNKNOWN:
return;
Copy link
Contributor

@ABeltramo ABeltramo Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-looking at this, we should probably add LI_BATTERY_STATE_NOT_PRESENT and LI_BATTERY_STATE_NOT_CHARGING so that we cover all cases?

case LI_BATTERY_STATE_NOT_CHARGING:
 state = inputtino::PS5Joypad::CHARGHING_ERROR;
 break
case LI_BATTERY_STATE_UNKNOWN:
case LI_BATTERY_STATE_NOT_PRESENT:
  return; // We can't set it, let's return

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LI_BATTERY_STATE_NOT_PRESENT makes sense, but I'm not sure about mapping LI_BATTERY_STATE_NOT_CHARGING to a charging error. We don't really have a specific value in the protocol to indicate that a device is actually broken. "Not charging" could simply indicate the device is holding at 80% or whatever to preserve the life of the battery cells.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, makes sense. To be fair I'm not even sure what the actual meaning for CHARGING_ERROR originally is or how (if?) that will be picked up by clients, but I can see the subtle difference that you mention.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I changed the logic here to just ignore status values that the code doesn't understand and those that don't have good mappings to inputino.

If there was a way to just report a percentage without a battery status, maybe we could support LI_BATTERY_STATE_NOT_CHARGING.

@ReenigneArcher ReenigneArcher enabled auto-merge (squash) July 14, 2024 17:26
@ReenigneArcher ReenigneArcher merged commit 5f715d6 into LizardByte:master Jul 14, 2024
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants