Commit Graph

1245 Commits

Author SHA1 Message Date
Jonas Bark
02c8da29f6 Use the shared advertised-address policy in the OBC mDNS emulator
Replaces the copy-pasted "first non-loopback IPv4" interface selection
with prop's AdvertisedAddressPicker (prefers the real LAN interface over
VPN tunnels, virtualization bridges and link-local adapters) and bumps
the prop submodule with the DirCon TCP/mDNS hardening: reconnect
supersede, socket onError handling, port-bind fallback with
actually-bound-port advertising, dual-stack listener.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 20:09:23 +02:00
Jonas Bark
e9e7425c29 Integration tests: controller connections + virtual shifting through fake platform seams
Add test/integration with platform fakes installed at the plugin seams
(UniversalBle.setInstance, NsdPlatformInterface.instance); everything
above them — Connection, device classification, protocol parsers, press
state machine, keymaps, ProxyDevice — is the real code:

- controller_connection_test: scan→classification (Zwift Click/Ride via
  manufacturer data, Di2 via service UUID, FTMS trainer→ProxyDevice,
  ignored names/devices), connect lifecycle (device-info reads, battery,
  RideOn handshake, subscriptions), drops, dedupe, forget list.
- controller_button_chain_test: byte-accurate BLE notifications through
  the full reaction chain — single/double/long press, trigger remapping,
  duplicate-frame dedupe, unmapped-button error surfacing, multi-button
  Ride presses.
- virtual_shifting_connection_logic_test: retrofit-mode defaults (WiFi /
  BT-wins / proxy for power meters), auto-connect consent gating,
  in-place "No connection" disconnect + in-place reconnect, WiFi trainer
  discovery rules (found/lost/connected-survives-flap, self-exclusion),
  and an end-to-end Click-press → real action pipeline → gear shift.

Protocol-level coverage (DirCon over real TCP, BLE peripheral) lives in
the prop submodule's own tests — no prop internals in this repo.

Bug fix found by these tests: Connection.disconnect(keepInList: true)
was defeated — UniversalBle.disconnect resolves only after the platform
disconnect event, so the still-attached connectionStream listener
re-entered disconnect() without keepInList and dropped the device,
orphaning the object the open details page holds (the exact bug
0db8cf0c addressed). Guarded via _inPlaceDisconnects.

Also update stale tests to current behavior: sim-mode shifts return
Ignored since e0e4494d (handled by the bridge, not forwarded, logged
neutrally), ControllerButton.initials direction arrows, and skip the
third BC2 state-machine test consistently with its siblings.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 18:59:14 +02:00
Jonas Bark
736d0d515e Route ProxyDevice detach errors through recordError
The _detachLogged teardown helper now reports failures via the app's
recordError (console in debug + crash persistence), matching the
convention used elsewhere (e.g. ZwiftClickV2.detach), instead of a bare
debugPrint.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 15:27:44 +02:00
Jonas Bark
120f80b9bb cleanup 2026-06-10 15:19:35 +02:00
Jonas Bark
0d612ce032 Re-attach connection listeners on in-place reconnect
After an in-place "No connection" disconnect, selecting Virtual Shifting
again reconnected the BLE upstream but the connect never completed:
device.isConnected stayed false and the card hung on "connecting".

The listener that flips isConnected (and drives the handshake to
completion) is created only in _connect(), which runs once via the
auto-connect queue at app start. The first manual connect reuses that
listener; disconnect cancels it (so a BLE drop doesn't fire
auto-reconnect); the second manual connect via startProxy() had no
listener and never re-ran _connect.

Route the in-place reconnect through a new Connection.connectDevice()
wrapper over _connect, re-attaching the action / connection-state
listeners — the same path the working auto-connect uses — instead of
calling ProxyDevice.startProxy() directly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 14:39:10 +02:00
Jonas Bark
0db8cf0c31 Keep the device registered on in-place "No connection" disconnect
The "No connection" picker entry disconnects without leaving the details
page, but Connection.disconnect(forget: false) removed the ProxyDevice
from the registry (isResetting is false). The open page kept the now
orphaned object: rediscovery built a *new* ProxyDevice while the page
still pointed at the old one, so selecting Virtual Shifting again
reconnected a device absent from bluetoothDevices — its BLE notifications
were rejected ("Device not found") and the connection was force-dropped.

Add a keepInList flag to disconnect; the in-place "No connection" path
passes it so the same device object stays registered (and its scan
result is retained to avoid a churned duplicate) and remains
reconnectable on the same card. The Disconnect buttons, which pop the
page, keep the default removing behaviour.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 14:14:48 +02:00
Jonas Bark
60817dabee Smart Trainer card: stable keys, reconnect rebinding, awaited mDNS stop, No-connection UX
- ConnectionCard: "No connection" shows "Not connected" instead of the
  bridge connect instruction; switching modes keeps the bridge accordion
  mounted with inline progress (drops the "Connecting in ... mode"
  placeholder card).
- proxy_device_details: stable keys on ConnectionCard / LiveMetricsSection
  / MiniWorkoutCard. On (dis)connect, conditional siblings toggle both
  above (FTMS warning) and below (gear/settings/VS-notice) these widgets,
  trapping the unkeyed ones in Flutter's reconciliation middle and
  remounting them — which collapsed the accordion and rebuilt the page.
- ProxyDevice: re-establish the emulator-state bindings on every
  (re)connect (_rebindEmulatorState in startProxy). The in-place
  "No connection" disconnect detaches them on a reused ProxyDevice, so
  reconnecting Virtual Shifting left the UI stuck on "connecting" while
  the emulator was actually connected.
- ProxyDevice.disconnect/switchRetrofitMode/handleServices: await the
  emulator stops so mDNS/TCP is torn down before reporting disconnected,
  and log the previously swallowed detach errors.
- connection.dart: log the discovered device name instead of its runtime
  type.
- Bump prop for the awaited mDNS teardown.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 14:06:12 +02:00
Jonas Bark
f8b9e6db62 fix 2026-06-10 11:15:45 +02:00
Jonas Bark
df18e4ff2f advertisement fix 2026-06-10 11:09:35 +02:00
Jonas Bark
a60a1384e3 Merge origin/universal-ble-2-peripheral: universal_ble 2.0.0 peripheral mode
Brings the BLE peripheral-mode migration to universal_ble 2.0.0 into the
WiFi DirCon trainer-discovery branch and bumps universal_ble to the latest
fork commit (ref: changes, 2.0.0).

Conflict resolutions:
- prop submodule: merged the universal_ble 2.0 transporter migration with
  the WiFi DirCon TrainerTransport refactor; kept the '0x' short-UUID
  normalisation on startAdvertising. Updated BleCharacteristic call sites
  to the new 3-arg (uuid, properties, descriptors) constructor.
- obc_ble_emulator.dart: took the PeripheralServer / universal_ble 2.0
  write-handler migration; kept the richer Error(button:) context on
  sendAction (using _currentDeviceId, the migrated connection tracker).
- unlock.dart: kept the main.dart import.
- pubspec.yaml: kept version 6.0.0+135; took ref: changes for universal_ble.

Pre-existing prop test failures (composite/dircon/fitness serviceUUIDs) are
unchanged by this merge — they fail identically on the pre-merge branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 09:19:58 +02:00
Jonas Bark
e79edf4809 UI adjustments 2026-06-10 08:53:30 +02:00
Jonas Bark
1ce9ab43c0 fix scanner 2026-06-10 07:23:36 +02:00
Jonas Bark
95c717e58d feat: surface mDNS-discovered DirCon trainers in Connection.proxyDevices
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 07:10:40 +02:00
Jonas Bark
51747eb4f4 feat: ProxyDevice.wifi — bridge DirCon trainers through TrainerTransport seams
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 07:10:40 +02:00
Jonas Bark
d7aef3ff04 feat: add WifiTrainerScanner with mDNS browsing and self-exclusion
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 07:10:40 +02:00
Jonas Bark
4e2a922760 feat: use shared BikeControl mDNS marker constants; register obc advertisement
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 07:10:40 +02:00
Jonas Bark
365893256d UX 2026-06-07 08:32:14 +02:00
Jonas Bark
e3985611cf fix bluetooth parsing - fixes https://github.com/OpenBikeControl/bikecontrol/issues/366 2026-06-06 21:59:13 +02:00
Jonas Bark
6ca4852491 fix mobile UI 2026-06-06 21:33:01 +02:00
Jonas Bark
8310e881dc Fix UX, translation 2026-06-06 20:21:13 +02:00
Jonas Bark
27919882b4 Fix UX, translation 2026-06-06 20:20:29 +02:00
Jonas Bark
8f221245cc new unlock method 2026-06-06 19:54:00 +02:00
Jonas Bark
f35ff80b1e fix #3 2026-06-03 16:10:55 +02:00
Jonas Bark
e9772a34a8 add missing Zwift Play button placements 2026-06-03 11:39:13 +02:00
Jonas Bark
ce19e629c2 add missing Zwift Play button placements 2026-06-03 11:35:44 +02:00
Jonas Bark
a68b68a1b4 fix button mapping popup 2026-06-01 11:53:55 +02:00
Jonas Bark
bd7cb80014 feat: reload emulator advertisement when trainer app changes
- Settings.trainerAppListenable fires from setTrainerApp.
- Connection.initialize listens and restarts ftmsEmulator + each
  ProxyDevice's _proxyEmulator so the new advertisement name (e.g.
  "Zwift Hub" for Rouvy) appears on the wire without reconnect.
- ProxyDevice.restartProxyEmulator no-ops in VS mode (ftmsEmulator
  handles itself).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-31 18:33:33 +02:00
Jonas Bark
0bfd483ba1 Merge branch '5.5.0' into draft
# Conflicts:
#	prop
2026-05-31 10:26:25 +02:00
Jonas Bark
461fe8a420 Zwift Play Firmware 2.0.1 support 2026-05-25 21:14:49 +02:00
Jonas Bark
60ba3121c6 animations 2026-05-25 20:13:08 +02:00
Jonas Bark
218a7e2e98 zwift adjustments 2026-05-21 22:01:14 +02:00
Jonas Bark
51f2455166 rouvy mode 2026-05-21 20:34:51 +02:00
Jonas Bark
c360ef17a7 document findings 2026-05-21 12:42:02 +02:00
Jonas Bark
cfadaff94e adjustments 2026-05-21 12:27:37 +02:00
Jonas Bark
82519b8497 refactor: delegate advertisementName back to DirconEmulator
ProxyDevice sets trainerApp / isTrial / deviceName callbacks on the
emulator instead of computing the name itself. ProxyDevice.advertisementName
now reads through emulator.advertisementName. startServer no longer
takes the name as a parameter.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 00:16:31 +02:00
Jonas Bark
0a76de870a refactor: ProxyDevice owns trainer identity and def construction
handleServices builds both ProxyBikeDefinition and
FitnessBikeDefinition up front and attaches to the right emulator
based on retrofit mode. ProxyDevice provides advertisementName +
mdnsTxt to ftmsEmulator/_proxyEmulator via the new startServer
parameters. Drops DirconEmulator state mirroring that's no longer
needed. ZwiftClickV2 no longer calls startServer (click-alone
path removed per prop strip). UI consumers route through
ProxyDevice.advertisementName and device.retrofitMode.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 00:08:33 +02:00
Jonas Bark
823a323218 fix(proxy): respect saved retrofit mode at connect time
handleServices was always driving _proxyEmulator.startServer, even
when the saved mode for the trainer was wifi or bluetooth. The
per-instance proxy emulator now only starts in proxy mode; for VS
modes the FBD attaches to the shared ftmsEmulator, mirroring what
switchRetrofitMode does for mid-session swaps.
2026-05-20 23:37:40 +02:00
Jonas Bark
cb2fbe7db0 refactor: move unlock state from emulator to ZwiftClickV2
isUnlocked / alreadyUnlocked / waiting notifiers + the vendor message
capture move to ZwiftClickV2. ftmsEmulator.setScanResult and
handleServices are no longer called from the click flow. The unlock
page binds to widget.device's notifiers. The prefs-based unlock check
is renamed isPersistedUnlocked to avoid shadowing the new live notifier.
2026-05-20 23:16:14 +02:00
Jonas Bark
9fb8d63f9a refactor: collapse to a single shared DirconEmulator for VS mode
ftmsEmulator is now the single emulator for Virtual Shifting traffic
across all trainers and the Click V2. ProxyDevice keeps a per-instance
emulator only for proxy mode (each proxy trainer advertises its own
mDNS identity). ZwiftClickV2 attaches its def to ftmsEmulator directly.

ProxyDevice exposes its own state ValueListenables (isStartedListenable,
isConnectedListenable, retrofitMode, localAddress) that mirror the active
emulator, so UI bindings survive mode swaps. setRetrofitMode and
switchRetrofitMode live on ProxyDevice and migrate the FBD between
proxy/shared emulators.

Removes companionProvider, refreshCompanions, and the click-def
internal seeding in DirconEmulator.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:05:40 +02:00
Jonas Bark
822c929b09 refactor: drop EmulatorRegistry, use DirconEmulator.companionProvider
ZwiftClickV2 no longer tracks which emulator hosts its definition or
listens for trainer arrival/departure. Instead:

- ProxyDevice installs an emulator.companionProvider that returns click
  defs for any connected ZwiftClickV2 at start time.
- ZwiftClickV2.handleServices builds the def, asks running trainer
  emulators to refreshCompanions, or starts the standalone if no
  trainer is running.
- ProxyDevice.disconnect migrates the click def back to the standalone
  so the Click stays usable after a trainer goes away.

Removes EmulatorRegistry singleton, the rebind handler, and the
sharedTrainerEmulator listener.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 22:36:54 +02:00
Jonas Bark
cd6626c507 feat: always advertise Click service while a Click V2 is connected
ZwiftClickDefinition is now attached to the resolved DirconEmulator at
Click-connect time, regardless of whether the unlock page is open:
- No trainer → ZwiftClickV2.handleServices starts the standalone so
  Zwift / Rouvy see BikeControl-as-Click as soon as the user plugs the
  Click in.
- Trainer present → click def attaches to the trainer's emulator; the
  trainer's existing peripheral advertises both services via the
  composite, so Zwift auto-subscribes to the Click service when it
  pairs with the trainer.

unlock.dart no longer drives the standalone's lifecycle; it just
listens to the shared unlock notifiers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 22:08:57 +02:00
Jonas Bark
feba139ada fix: harden unlock page and route attach/detach errors through recordError
- unlock.dart now seeds ftmsEmulator.scanResult before calling
  startServer, so the unlock page works when the Click is bound to the
  trainer's emulator (and never told the standalone about itself).
  Also guards the startServer call behind isStarted.value to avoid
  double-starting.
- ZwiftClickV2 attach/detach call sites now wrap their futures in
  catchError(recordError, context: '...') per the project's
  feedback_record_error rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 18:27:28 +02:00
Jonas Bark
ea8fbc51ef fix(zwift_clickv2): don't overwrite trainer emulator's scanResult/services
ZwiftClickV2.handleServices / _onSharedTrainerChanged were calling
setScanResult and handleServices on whichever DirconEmulator the
registry resolved to — corrupting the trainer's mDNS advertisement
(which reads scanResult.deviceId + scanResult.services for its TXT
record) and breaking subsequent _createDefinitionAndTransporter
rebuilds whenever a trainer was the resolve target.

The Click's hardware identity already lives inside the
ZwiftClickDefinition (services / device constructor args). Only the
standalone ftmsEmulator should learn the Click as its primary device.
2026-05-20 18:15:43 +02:00
Jonas Bark
1eb96c7d39 feat: route ZwiftClickV2 through EmulatorRegistry + attachDefinition
When a smart trainer is connected, the Click V2's ZwiftClickDefinition
attaches to the trainer's emulator so Zwift/Rouvy pair once and see
both services. When no trainer is connected, falls back to the
standalone ftmsEmulator (existing unlock path). Trainer arrival /
departure while the Click is connected rebinds the definition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 18:11:05 +02:00
Jonas Bark
9c272f698b feat: ProxyDevice registers its emulator in EmulatorRegistry
Lets companion devices (Zwift Click V2) attach their definitions to
the trainer's emulator instead of using a separate one. The registry
slot is reclaimed by ProxyDevice's emulator on construction and
released on teardown.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 18:06:50 +02:00
Jonas Bark
6fd18d9c03 feat: add EmulatorRegistry for companion-device emulator resolution
ZwiftClickV2 uses this to find the trainer's DirconEmulator at connect
time and attach its ZwiftClickDefinition there, falling back to the
standalone emulator only when no trainer is connected.
2026-05-20 18:04:22 +02:00
Jonas Bark
a795b3c681 refactor: route FBD-specific callers through emulator.fitnessBike
activeDefinition now returns the CompositeBleDefinition; consumers
that need the FitnessBikeDefinition specifically use the fitnessBike
convenience getter. Bumps prop submodule to pick up the composite
machinery.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 17:55:53 +02:00
Jonas Bark
db3cb986cc deactivate script on invalid format detected 2026-05-19 22:12:12 +02:00
Jonas Bark
29741e520f migrate peripheral mode to universal_ble 2.0.0
Drop bluetooth_low_energy. Move OBC BLE emulator, Zwift emulator, and
the remote mouse / keyboard pairing flows onto a new PeripheralServer
wrapper around UniversalBlePeripheral that routes per-characteristic
read/write handlers, so multiple peripheral instances coexist without
clobbering universal_ble's process-wide handlers.

Also: onValueChange callback gains a timestamp param (v1.0.0 breaking
change), PeripheralManager().showAppSettings() → openAppSettings(),
UUID.short(0x12) → literal UUID, and prop submodule bumped to the
matching universal_ble peripheral rewrite.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 09:28:39 +02:00
Jonas Bark
618aa01204 IPV6 is not the cause of the issues 2026-05-14 18:11:53 +02:00