[PR #135] [MERGED] Switch Pro: report non-charging state and per-slot battery level #222

Closed
opened 2026-10-22 05:07:50 +00:00 by roman · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/safijari/openpuck/pull/135
Author: @Copilot
Created: 7/5/2026
Status: ✅ Merged
Merged: 7/6/2026
Merged by: @safijari

Base: main ← Head: copilot/update-switch-pro-mode


📝 Commits (5)

  • 5d31c8f Update Switch Pro battery and charging flags
  • dcf91fc Finalize Switch Pro battery and charging reporting
  • 9a8e02c Merge branch 'main' into copilot/update-switch-pro-mode
  • 0e64cf5 fmt
  • 75d9ec1 Both slots now work correctly

📊 Changes

4 files changed (+41 additions, -12 deletions)

View changed files

📝 OpenPuck/haptics.cpp (+3 -2)
📝 OpenPuck/mode_switch_pro.cpp (+33 -7)
📝 OpenPuck/puck_hid.cpp (+2 -1)
📝 OpenPuck/serial_console.cpp (+3 -2)

📄 Description

Switch Pro mode was always advertising full + charging (0x91), so the console showed charging and 100% regardless of the actual controller state. This change makes report 0x30/0x21 battery metadata reflect each mapped controller’s real RF battery telemetry while keeping connection semantics intact.

  • Battery byte now reflects real per-slot state

    • Added jcBatteryNibble(bond) to convert g_battery[bond] (0x43 battery %) into Switch’s 4-bit 0..8 battery scale.
    • Uses ceiling mapping so low non-zero percentages do not collapse to 0.
  • Charging is no longer asserted

    • Replaced hardcoded out[1] = 0x91 with computed battery nibble + connection_info=1.
    • Removed forced charging-grip bit from the common button byte, so the emulated pad is not presented as charging.
  • Scope

    • Change is isolated to Switch Pro report prefix construction in mode_switch_pro.cpp; no protocol flow or report cadence changes.
// [7:4]=battery (0..8), [3:0]=connection_info
out[1] = (uint8_t)((jcBatteryNibble(bond) << 4) | 0x01);

static uint8_t jcBatteryNibble(uint8_t bond)
{
	if (bond >= NSLOT || !g_battery[bond])
		return 0;
	uint8_t pct = g_battery[bond];
	return (uint8_t)(((uint16_t)pct * 8u + 99u) / 100u); // ceil to 0..8
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/safijari/openpuck/pull/135 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 7/5/2026 **Status:** ✅ Merged **Merged:** 7/6/2026 **Merged by:** [@safijari](https://github.com/safijari) **Base:** `main` ← **Head:** `copilot/update-switch-pro-mode` --- ### 📝 Commits (5) - [`5d31c8f`](https://github.com/safijari/openpuck/commit/5d31c8f7df9e3c8b3f7c3de9fb90bc3204383db2) Update Switch Pro battery and charging flags - [`dcf91fc`](https://github.com/safijari/openpuck/commit/dcf91fc1aeed0cfe3e78845df24f266ea5aff717) Finalize Switch Pro battery and charging reporting - [`9a8e02c`](https://github.com/safijari/openpuck/commit/9a8e02c03ded7a71a908cf42c0d00f442dd09473) Merge branch 'main' into copilot/update-switch-pro-mode - [`0e64cf5`](https://github.com/safijari/openpuck/commit/0e64cf59b55f6760b280587065c394d495636687) fmt - [`75d9ec1`](https://github.com/safijari/openpuck/commit/75d9ec1eda60d2f87862b04bf4870f41444892b3) Both slots now work correctly ### 📊 Changes **4 files changed** (+41 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `OpenPuck/haptics.cpp` (+3 -2) 📝 `OpenPuck/mode_switch_pro.cpp` (+33 -7) 📝 `OpenPuck/puck_hid.cpp` (+2 -1) 📝 `OpenPuck/serial_console.cpp` (+3 -2) </details> ### 📄 Description Switch Pro mode was always advertising `full + charging` (`0x91`), so the console showed charging and 100% regardless of the actual controller state. This change makes report `0x30/0x21` battery metadata reflect each mapped controller’s real RF battery telemetry while keeping connection semantics intact. - **Battery byte now reflects real per-slot state** - Added `jcBatteryNibble(bond)` to convert `g_battery[bond]` (0x43 battery %) into Switch’s 4-bit 0..8 battery scale. - Uses ceiling mapping so low non-zero percentages do not collapse to 0. - **Charging is no longer asserted** - Replaced hardcoded `out[1] = 0x91` with computed battery nibble + `connection_info=1`. - Removed forced charging-grip bit from the common button byte, so the emulated pad is not presented as charging. - **Scope** - Change is isolated to Switch Pro report prefix construction in `mode_switch_pro.cpp`; no protocol flow or report cadence changes. ```cpp // [7:4]=battery (0..8), [3:0]=connection_info out[1] = (uint8_t)((jcBatteryNibble(bond) << 4) | 0x01); static uint8_t jcBatteryNibble(uint8_t bond) { if (bond >= NSLOT || !g_battery[bond]) return 0; uint8_t pct = g_battery[bond]; return (uint8_t)(((uint16_t)pct * 8u + 99u) / 100u); // ceil to 0..8 } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
roman 2026-10-22 05:07:50 +00:00
Sign in to join this conversation.
No labels
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
safijari/openpuck#222
No description provided.