mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 15:17:48 +01:00
1.5 KiB
1.5 KiB
Cardboy Time Sync Companion
This SwiftUI app connects to the Cardboy device over Bluetooth Low Energy and updates its wall clock using the custom time sync service exposed by the firmware. The sources live inside the existing cardboy-companion/cardboy-companion.xcodeproj so you can open and run them directly in Xcode.
Requirements
- Xcode 15 or newer
- iOS 16 or newer deployment target (can be lowered to 15 with minor API tweaks)
- A Cardboy running firmware that includes the BLE time sync service
How it works
- The app scans for peripherals exposing service UUID
00000001-CA7B-4EFD-B5A6-10C3F4D3F230. - Once connected it discovers characteristic
00000002-CA7B-4EFD-B5A6-10C3F4D3F231. - Tapping Sync Now writes a 12‑byte payload containing:
- 8 bytes Unix epoch seconds (little endian)
- 2 bytes time zone offset in minutes from UTC (little endian)
- 1 byte DST flag (
1if daylight saving is active) - 1 reserved byte (
0)
- The firmware applies the timestamp with
settimeofday()and updates the TZ environment variable so the clock app renders local time.
Usage
- Open
cardboy-companion/cardboy-companion.xcodeprojin Xcode. - Enable the
CoreBluetoothcapability for thecardboy-companiontarget (Signing & Capabilities tab). - Build & run on a real device (BLE is not available in the simulator).
- Allow Bluetooth permissions when prompted, then tap Sync Now.
Optionally bundle this code into your existing app—TimeSyncManager is self‑contained and can be reused.