How ironmanfpv/fitness-odometer-for-monocle works
Project type and purpose
• This is a single-page, front-end proof-of-concept web application (“Fitness Odometer for Monocle”) that runs entirely in the browser.
• It uses the Web Geolocation API to collect latitude/longitude points, computes distance traveled, renders a route overlay in the UI, and (optionally) streams distance updates over Bluetooth Low Energy (BLE) to a Monocle device.
File structure
• Top-level:
• index.html – entry point and skeleton of the UI
• css/ – style sheets (button.css, overlay.css, tracker.css)
• js/ – JavaScript modules:
– config.js (BLE service/characteristic UUIDs, config constants)
– connect.js (BLE device discovery & connection logic)
– distance.js (haversine or similar distance‐calculation functions)
– overlay.js (canvas or SVG route‐drawing code)
– tracker.js (geolocation polling, start/stop controls, event orchestration)
– senddist.js (packaging & transmitting distance over BLE)
• No backend code or server-side components. All logic executes locally in the browser.
Key insights from README
• Relies on Mozilla Web Geolocation API and Web Bluetooth API.
• UI consists of a “Slide to start/stop” button, a map or route overlay, and a “Connect”/“Transmit” button for Monocle.
• No data is sent to any web server; all location and distance processing is client-side.
Main components
a. Browser UI Layer
• Presentation controls: Start/Stop slider, Connect!, Transmit button
• Overlay canvas or map container
b. Geolocation Service
• Browser’s navigator.geolocation API
• Managed by tracker.js
c. Data Processing Layer
• distance.js calculates incremental and cumulative distance
• overlay.js renders path segments onto the map/canvas
d. BLE Service Layer
• .js handles device scan, connect, and characteristic discovery
• senddist.js formats distance data and writes to BLE characteristic
e. External Device
• Monocle BLE device (with custom UUIDs defined in config.js)
Relationships and interactions
1. User clicks “Slide to start” → tracker.js subscribes to geolocation.watchPosition
2. Geolocation Service returns lat/lon → distance.js computes delta distance
3. distance.js emits new distance → overlay.js draws the new segment on UI
4. User clicks “Connect!” → connect.js invokes navigator.bluetooth.requestDevice
5. After BLE connection, user clicks “Transmit” → senddist.js writes current distance to Monocle over BLE
6. User clicks “Slide to stop” → tracker.js clears watchPosition and stops updates
Architectural patterns and design principles
• Modular JavaScript with Single Responsibility modules
• Event-driven flow: modules emit and consume custom events (e.g., “positionUpdate”, “distanceComputed”)
• Separation of concerns: UI controls vs. data services vs. external device integration