Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Client/CrossPlatformGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,26 @@ void CrossPlatformGUI::_pumpConnectionState()
if (!this->_pollFuture.valid() && ++this->_pollCounter >= DYNAMIC_POLL_FRAMES)
{
this->_pollCounter = 0;
this->_pollFuture.setFromAsync([this]() { this->_headphones.requestAmbientState(); });

// Battery is otherwise read once, in the post-connect phase, and never again: the header keeps
// showing the level from the moment you connected for as long as the app stays open. Refresh it
// on the same worker, on its own slower schedule.
bool withBattery = false;
this->_batteryPollCounter += DYNAMIC_POLL_FRAMES;
if (this->_isV2() && this->_batteryPollCounter >= BATTERY_POLL_FRAMES)
{
this->_batteryPollCounter = 0;
withBattery = true;
}

this->_pollFuture.setFromAsync([this, withBattery]() {
this->_headphones.requestAmbientState();
// Best effort: a device that doesn't answer the battery inquiry must not kill the poll.
if (withBattery)
{
try { this->_headphones.requestBattery(); } catch (const std::exception&) {}
}
});
}
}

Expand Down
4 changes: 4 additions & 0 deletions Client/CrossPlatformGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const auto WINDOW_COLOR = ImVec4(0.09f, 0.09f, 0.11f, 1.00f);

// Physical-button changes (ASM) are polled roughly every two seconds so the app stays in sync.
constexpr auto DYNAMIC_POLL_FRAMES = FPS * 2;
// Battery moves slowly and each read costs a round trip, so it rides along with the ambient poll on a
// much slower schedule instead of getting a request of its own.
constexpr auto BATTERY_POLL_FRAMES = FPS * 30;

class CrossPlatformGUI
{
Expand Down Expand Up @@ -81,6 +84,7 @@ class CrossPlatformGUI
bool _synced = false;
bool _probed = false;
int _pollCounter = 0;
int _batteryPollCounter = 0;

// UI state, synced from the device once after connect; user edits are pushed back to the headphones.
bool _uiAsmOn = false;
Expand Down