https://github.com/ambicuity/trackpad-weight
Turn your MacBook trackpad into a digital weighing scale using Force Touch pressure data.
https://github.com/ambicuity/trackpad-weight
force-touch macos multi swift touch trackpad weighing-scale weighing-scales
Last synced: 5 months ago
JSON representation
Turn your MacBook trackpad into a digital weighing scale using Force Touch pressure data.
- Host: GitHub
- URL: https://github.com/ambicuity/trackpad-weight
- Owner: ambicuity
- License: mit
- Created: 2025-07-25T19:34:06.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-08-04T04:54:51.000Z (11 months ago)
- Last Synced: 2025-08-04T05:04:29.099Z (11 months ago)
- Topics: force-touch, macos, multi, swift, touch, trackpad, weighing-scale, weighing-scales
- Language: Swift
- Homepage: https://github.com/ambicuity/trackpad-weight
- Size: 115 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TrackPad Weight Scale
A powerful macOS application that transforms your Force Touch trackpad into a precision digital weighing scale using advanced multitouch pressure sensing technology.
[](https://www.apple.com/macos/)
[](https://swift.org/)
[](LICENSE)
[]()
## โจ Key Features
### ๐ฏ **Precision Measurement**
- **Multi-layered Pressure Detection**: Primary multitouch support with Force Touch fallback
- **High Accuracy**: ยฑ0.1-0.5g precision depending on MacBook model
- **Real-time Updates**: Live weight display with sub-second response time
- **Smart Calibration**: Advanced zero-point calibration with drift compensation
### ๐ฅ๏ธ **Native macOS Integration**
- **Menu Bar Integration**: Always-accessible weight display in your menu bar
- **Native UI Components**: Built with SwiftUI/Cocoa for seamless macOS experience
- **Multiple Display Options**: Main window, compact widget, and menu bar views
- **Accessibility Support**: Full VoiceOver compatibility and keyboard navigation
### ๐ **Advanced Features**
- **Auto-Tare System**: Automatically zero the scale for new measurement sessions
- **Comparison Mode**: Compare weights against reference items with tolerance checking
- **Data Logging**: Comprehensive weight logging with CSV/JSON export
- **API Integration**: Built-in REST API server with webhook support
- **Theme Customization**: Multiple themes and font sizes for personalization
### ๐ง **Professional Tools**
- **Session Management**: Organized measurement sessions with detailed statistics
- **Export Capabilities**: Multiple export formats for data analysis
- **Remote Control**: API endpoints for programmatic control and monitoring
- **Compact Widget**: Always-on-top floating weight display
## ๐ง How It Works
### Advanced Pressure Detection System
TrackWeight employs a sophisticated multi-layered approach to trackpad pressure sensing:
#### **Primary Method: Open Multi-Touch Support**
- Utilizes enhanced Open Multi-Touch Support library integration
- Direct access to private macOS multitouch APIs
- Captures detailed pressure data from multiple touch points simultaneously
- Provides the highest accuracy and sensitivity
#### **Fallback Method: Force Touch Events**
- NSEvent-based Force Touch monitoring for compatibility
- Ensures functionality across all supported MacBook models
- Automatic fallback when multitouch access is unavailable
#### **Smart Pressure Processing**
- **Capacitance Detection**: Pressure readings only available with finger contact on trackpad
- **Multi-point Aggregation**: Combines pressure from multiple simultaneous touches
- **Real-time Calibration**: Continuous drift compensation and environmental adjustment
- **Noise Filtering**: Advanced algorithms to eliminate measurement noise
### Weight Calculation Algorithm
```
Raw Pressure โ Calibration Offset โ Environmental Compensation โ Weight (grams)
```
Our extensive testing reveals that **MultitouchSupport pressure data is pre-calibrated in grams**, providing exceptional accuracy without complex conversion algorithms.
## ๐ Requirements & Compatibility
### โ
**Fully Supported Models**
| Model | Years | Weight Limit | Accuracy | Status |
|-------|-------|--------------|----------|---------|
| **MacBook Pro** | 2015+ (13", 14", 15", 16") | 300-400g | ยฑ0.1-0.2g | โ
Excellent |
| **MacBook Air** | 2018+ (13", 15") | 280-320g | ยฑ0.1-0.15g | โ
Excellent |
| **MacBook** | 2016-2017 (12") | 250g | ยฑ0.2g | โ
Good |
### โ **Not Compatible**
- MacBook Pro (2014 and earlier)
- MacBook Air (2017 and earlier)
- iMac, Mac Mini, Mac Pro (no Force Touch trackpad)
### ๐ป **System Requirements**
- **OS**: macOS 13.0 (Ventura) or later
- **Hardware**: MacBook with Force Touch trackpad
- **Memory**: 50MB RAM minimum
- **Storage**: 10MB disk space
- **Development**: Swift 5.9+, Xcode 16.0+ (for building from source)
> **๐ Quick Compatibility Check**: System Preferences โ Trackpad โ "Force Click and haptic feedback" should be available
### โ ๏ธ **Important Safety Limits**
**Never exceed these weight limits to avoid trackpad damage:**
| Model Category | Recommended Max | Absolute Max | Risk Level |
|----------------|-----------------|--------------|------------|
| MacBook Pro 13" | 300g | 500g | โ ๏ธ Medium |
| MacBook Pro 15-16" | 350-400g | 600-700g | โ ๏ธ Medium |
| MacBook Air | 280-320g | 450-500g | โ ๏ธ Medium |
| MacBook 12" | 250g | 400g | ๐ด High |
> **โ ๏ธ Warranty Warning**: Exceeding absolute maximums may void your warranty and cause permanent trackpad damage.
## ๐ Quick Start Guide
### Method 1: One-Command Install (Recommended)
```bash
# Clone and run in one step
git clone https://github.com/ambicuity/trackpad-weight.git && cd trackpad-weight && swift run TrackpadWeight
```
### Method 2: Production Build
```bash
# Build optimized version
git clone https://github.com/ambicuity/trackpad-weight.git
cd trackpad-weight
swift build -c release
# Run the optimized build
./.build/release/TrackpadWeight
```
### Method 3: App Bundle
```bash
# Create proper macOS app (see INSTALLATION.md for details)
git clone https://github.com/ambicuity/trackpad-weight.git
cd trackpad-weight
# Follow detailed app bundle creation steps in INSTALLATION.md
```
> **๐ Need detailed instructions?** See our comprehensive [Installation Guide](INSTALLATION.md) with troubleshooting, permissions setup, and advanced configuration options.
## ๐ Usage Guide
### Basic Operation
1. **๐ Launch**: Application appears in menu bar with scale icon (โ๏ธ)
2. **โ๏ธ Calibrate**: Click menu bar โ "Calibrate" (essential for accuracy)
3. **๐ฑ View**: Click menu bar โ "Show Weight Scale" for main window
4. **๐ Measure**: Place items on trackpad while maintaining finger contact
### Essential Tips for Accurate Measurements
#### โ
**Best Practices**
```
โ Calibrate before each session
โ Maintain consistent finger contact
โ Place items gently in trackpad center
โ Use clean, dry trackpad surface
โ Ensure stable, vibration-free surface
```
#### โ **Avoid These**
```
โ Exceeding weight limits
โ Sharp or pointed objects
โ Wet or dirty items
โ Sudden movements during measurement
โ Multiple items without proper spacing
```
### Real-World Examples
#### ๐ฎ **Mail & Shipping**
- Standard letter (up to 28g): ยฑ0.2g accuracy
- Large letter (up to 100g): ยฑ0.3g accuracy
- Small packet (up to 500g): Use with caution
#### ๐ **Jewelry & Precious Items**
- Rings, earrings (1-10g): ยฑ0.1g accuracy
- Chains, bracelets (5-25g): ยฑ0.2g accuracy
- Small coins for calibration reference
#### ๐ฌ **Educational & Hobby**
- Electronic components: Excellent precision
- Model building materials: Good for balancing
- Kitchen ingredients: Approximate portions
> **๐ Want detailed examples?** Check our [Examples & Use Cases Guide](EXAMPLES.md) with real-world scenarios and step-by-step instructions.
## ๐ง Advanced Features
### ๐ค **Auto-Tare System**
Automatically zeroes the scale when starting new measurement sessions.
```bash
Menu Bar โ "Auto-Tare" โ Enable
Configure: Menu Bar โ "Auto-Tare Settings"
```
### ๐ **Comparison Mode**
Compare current measurements against reference weights with tolerance checking.
```bash
Enable: Menu Bar โ "Comparison Mode"
Set Reference: Menu Bar โ "Comparison Tools" โ "Set Reference Weight"
```
### ๐ **Data Logging & Export**
Comprehensive measurement logging with multiple export formats.
```bash
Enable: Menu Bar โ "Enable Logging"
Export: Menu Bar โ "Export Weight Log (CSV/JSON)"
Location: ~/Documents/TrackpadWeight/
```
### ๐ฅ๏ธ **Compact Widget**
Always-on-top floating weight display for continuous monitoring.
```bash
Show: Menu Bar โ "Show Compact Widget"
Configure: Menu Bar โ "Widget Options" โ Position/Size
```
### ๐ **REST API Server**
Built-in HTTP API for programmatic access and integration.
```bash
Enable: Menu Bar โ "API Server"
Access: http://localhost:8080/api
Docs: http://localhost:8080/docs
```
### ๐จ **Customization Options**
- **Themes**: System, Light, Dark, High Contrast
- **Font Sizes**: Small, Medium, Large, Extra Large
- **Accessibility**: Full VoiceOver support
- **Positioning**: Customizable widget placement
> **๐ง Need API integration?** See our complete [API Documentation](API.md) with endpoints, examples, and client libraries.
## โ ๏ธ Safety & Risk Assessment
### ๐จ **Critical Safety Guidelines**
#### **Physical Risks to Avoid**
- **๐ด High Risk**: Exceeding weight limits, sharp objects, liquids, hot items
- **๐ก Medium Risk**: Metal objects, static-sensitive items, magnetic materials
- **๐ข Low Risk**: Paper, coins, small electronics, dry food items
#### **Weight Limits by Model**
| MacBook Model | Safe Limit | Damage Risk |
|---------------|------------|-------------|
| Pro 13" (2015+) | 300g | >500g |
| Pro 15-16" (2015+) | 350-400g | >600-700g |
| Air 13-15" (2018+) | 280-320g | >450-500g |
| 12" (2016-2017) | 250g | >400g |
#### **Placement Guidelines**
```
โ
DO: Gentle placement, center positioning, finger contact
โ DON'T: Sharp edges, excessive force, liquid contact
```
### ๐ **Accuracy Specifications**
#### **Expected Precision by Weight Range**
| Weight Range | Typical Accuracy | Best Use Cases |
|-------------|------------------|----------------|
| 0.1-1.0g | ยฑ0.05-0.1g | Electronics, small jewelry |
| 1-10g | ยฑ0.1-0.2g | Coins, medium jewelry |
| 10-50g | ยฑ0.2-0.5g | Documents, food portions |
| 50-200g | ยฑ0.5-1.0g | Packages, containers |
| 200g+ | ยฑ1.0-2.0g | Large items (approach limits) |
#### **Environmental Factors**
- **Temperature**: ยฑ5ยฐC from calibration affects accuracy
- **Humidity**: Extreme conditions impact sensor performance
- **Vibration**: Stable surface required for precise measurements
### ๐ซ **Important Limitations**
#### **Not Suitable For**
- Legal/commercial trade measurements
- Medical dosing or pharmaceutical use
- Precious metals trading
- Scientific research requiring high precision
- Safety-critical applications
#### **Recommended For**
- Educational demonstrations and learning
- Hobby projects and crafting
- Approximate measurements and estimations
- Quick weight checks and comparisons
> **โ ๏ธ Legal Disclaimer**: This application is for demonstration and educational purposes only. Not certified for commercial use. Use at your own risk. See [COMPATIBILITY.md](COMPATIBILITY.md) for detailed risk assessment.
## ๐๏ธ Technical Architecture
### ๐ง **Core Components**
```
๐ฑ SwiftUI/Cocoa Interface
โ
๐ Combine Reactive Framework
โ
๐ TrackpadMonitor (Pressure Detection)
โ
๐ฏ MultitouchSupport Integration โ ๐ โ NSEvent Force Touch (Fallback)
โ
โ๏ธ Weight Calculation Engine
```
### ๐ **Project Structure**
```
Sources/TrackpadWeight/
โโโ ๐ main.swift # Application entry point & menu bar
โโโ ๐ฏ MultitouchSupport.swift # Open Multi-Touch Support integration
โโโ ๐ TrackpadMonitor.swift # Enhanced pressure sensing logic
โโโ ๐ฅ๏ธ WeightDisplayView.swift # Native UI components
โโโ ๐ WeightLogger.swift # Data logging & export system
โโโ ๐ค AutoTareManager.swift # Automatic tare functionality
โโโ ๐ ComparisonManager.swift # Weight comparison features
โโโ ๐จ ThemeManager.swift # UI themes & accessibility
โโโ ๐ฑ CompactWeightWidget.swift # Floating widget display
โโโ ๐ APIServer.swift # REST API & webhook server
Tests/TrackpadWeightTests/
โโโ โ
TrackpadWeightTests.swift # Comprehensive unit tests (21 tests)
```
### ๐ง **Enhanced Architecture Features**
#### **Multi-layered Pressure Detection**
- **Primary**: Open Multi-Touch Support library integration
- **Fallback**: NSEvent Force Touch monitoring
- **Smart Switching**: Automatic method selection based on availability
#### **Real-time Processing Pipeline**
```
Raw Sensor Data โ Noise Filtering โ Calibration โ Environmental Compensation โ Weight Output
```
#### **Data Flow Architecture**
- **Reactive**: Combine framework for real-time updates
- **Thread-safe**: Concurrent pressure processing
- **Memory efficient**: Optimized for continuous operation
### ๐งช **Validation & Testing**
#### **Calibration Methodology**
Our weight calculations are validated through rigorous testing:
1. **Reference Scale Comparison**: MacBook placed on certified digital scale
2. **Known Weight Testing**: Verified using certified calibration weights
3. **Cross-model Validation**: Testing across multiple MacBook models
4. **Environmental Testing**: Various temperature and humidity conditions
#### **Test Coverage**
- โ
**21 Unit Tests**: Core functionality validation
- โ
**Edge Case Testing**: Boundary conditions and error scenarios
- โ
**Performance Testing**: Memory usage and CPU optimization
- โ
**Accuracy Validation**: Real-world measurement verification
> **๐ฌ Key Discovery**: MultitouchSupport pressure data is pre-calibrated in grams, providing exceptional accuracy without complex conversion algorithms.
## ๐ Documentation
### ๐ **Complete Guide Collection**
| Document | Description | Key Contents |
|----------|-------------|--------------|
| **[๐ Examples & Use Cases](EXAMPLES.md)** | Detailed real-world examples | API integration, troubleshooting, performance benchmarks |
| **[๐ง Installation Guide](INSTALLATION.md)** | Complete setup instructions | Multiple install methods, permissions, troubleshooting |
| **[๐ฑ Compatibility Guide](COMPATIBILITY.md)** | Model compatibility & risk assessment | Weight limits, safety guidelines, accuracy specs |
| **[๐ API Documentation](API.md)** | REST API & webhook integration | Endpoints, client libraries, webhook system |
### ๐ **Quick Links**
- **โก Quick Start**: [Installation Guide - Method 1](INSTALLATION.md#method-1-quick-install-recommended)
- **๐ Weight Limits**: [Compatibility Guide - Weight Limits](COMPATIBILITY.md#weight-limits-by-model)
- **๐ป API Examples**: [API Documentation - Examples](API.md#examples)
- **๐ ๏ธ Troubleshooting**: [Examples Guide - Troubleshooting](EXAMPLES.md#troubleshooting-common-issues)
### ๐งช **Development & Building**
```bash
# ๐๏ธ Development Setup
git clone https://github.com/ambicuity/trackpad-weight.git
cd trackpad-weight
# ๐จ Build & Test
swift build # Development build
swift test # Run all tests (21 tests)
swift build -c release # Optimized build
# ๐ฑ Xcode Development
swift package generate-xcodeproj
open TrackpadWeight.xcodeproj
```
### ๐ **Acknowledgments**
This project builds upon the excellent [Open Multi-Touch Support library](https://github.com/Kyome22/OpenMultitouchSupport) by Takuto Nakamura (@Kyome22), which provides:
- ๐ฏ Direct access to global multitouch events
- ๐ Detailed touch data (position, pressure, angle, density)
- ๐ Thread-safe async/await touch event streams
- ๐ Comprehensive sensor data and touch state tracking
## ๐ค Contributing
We welcome contributions! Here's how to get started:
### ๐ ๏ธ **Development Process**
1. **๐ด Fork** the repository
2. **๐ Create** a feature branch (`git checkout -b feature/amazing-feature`)
3. **โจ Make** your changes with comprehensive tests
4. **โ
Test** thoroughly (`swift test` should pass all 21+ tests)
5. **๐ Document** new features and update relevant guides
6. **๐ Submit** a pull request with detailed description
### ๐ **Contribution Guidelines**
- **๐ง Code Style**: Follow Swift conventions and existing patterns
- **๐งช Testing**: Add tests for new functionality (maintain >90% coverage)
- **๐ Documentation**: Update relevant `.md` files for new features
- **โก Performance**: Ensure changes don't impact measurement accuracy
- **๐ Security**: Consider security implications for trackpad access
### ๐ **Bug Reports & Feature Requests**
- **๐ Issues**: [Report bugs](https://github.com/ambicuity/trackpad-weight/issues) with reproduction steps
- **๐ก Features**: [Request features](https://github.com/ambicuity/trackpad-weight/issues) with use case details
- **๐ฌ Discussions**: [Community support](https://github.com/ambicuity/trackpad-weight/discussions)
## ๐ License
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
```
Copyright (c) 2025 TrackPad Weight Scale Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files...
```
## โ ๏ธ Legal Disclaimer
**Important**: This application is provided for **demonstration and educational purposes only**.
### ๐ซ **Not Suitable For**
- โ Commercial trade or legal measurements
- โ Medical dosing or pharmaceutical applications
- โ Precious metals trading or valuation
- โ Scientific research requiring certified accuracy
- โ Safety-critical applications
### โ
**Recommended Uses**
- โ
Educational demonstrations and learning
- โ
Hobby projects and maker activities
- โ
Approximate measurements and estimations
- โ
Quick weight checks and comparisons
### ๐ **Liability & Warranty**
- **No Warranty**: Software provided "as-is" without warranties
- **Use at Risk**: Users assume all risks for trackpad damage
- **No Liability**: Authors not responsible for decisions based on readings
- **Educational Only**: Not certified for commercial or professional use
---
**โ๏ธ TrackPad Weight Scale** - *Transform your MacBook trackpad into a precision digital scale*
[](https://www.apple.com/macos/)
[](https://swift.org/)
[](LICENSE)
[]()
*Built with โค๏ธ for the macOS community*