An open API service indexing awesome lists of open source software.

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.

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.

[![macOS](https://img.shields.io/badge/macOS-13.0+-blue.svg)](https://www.apple.com/macos/)
[![Swift](https://img.shields.io/badge/Swift-5.9+-orange.svg)](https://swift.org/)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Build Status](https://img.shields.io/badge/Build-Passing-brightgreen.svg)]()

## โœจ 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*

[![macOS](https://img.shields.io/badge/macOS-13.0+-blue.svg)](https://www.apple.com/macos/)
[![Swift](https://img.shields.io/badge/Swift-5.9+-orange.svg)](https://swift.org/)
[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Tests](https://img.shields.io/badge/Tests-21%20Passing-brightgreen.svg)]()

*Built with โค๏ธ for the macOS community*