Python SDK for interacting with G1 Smart Glasses via Bluetooth LE. Provides a high-level interface for device communication, state management, and feature control.
Requirements:
- Python 3.7+
- Bluetooth LE support
pip install -r requirements.txt
Required packages:
- bleak>=0.21.1: Bluetooth LE communication
- rich>=13.7.0: Enhanced console output
- asyncio>=3.4.3: Asynchronous I/O support
Simple connection example:
from connector import G1Connector
import asyncio
async def main():
# Initialize connector
glasses = G1Connector()
# Connect to glasses (includes automatic retry logic)
if await glasses.connect():
print("Successfully connected to G1 glasses")
# Your code here
else:
print("Failed to connect to glasses")
if __name__ == "__main__":
asyncio.run(main())
- Robust BLE connection handling with configurable retry logic
- Automatic reconnection on disconnect
- Dual glass (left/right) connection support
- Connection state tracking and event notifications
- Physical state monitoring (wearing, charging, cradle)
- Battery level tracking
- Device state updates
- Interaction event processing
- Dashboard mode support
Supports various interaction types:
- Single/Double tap detection
- Long press actions
- Dashboard open/close events
- Silent mode toggles
Text display features:
- Multi-line text support
- Configurable font sizes
- Page-based text display
- Screen status tracking
- Brightness level adjustment
- Auto brightness on/off
Image display capabilities: (TODO)
- 1-bit, 576x136 pixel BMP format
- Packet-based transmission
- CRC verification
- Left/right glass synchronization
Microphone control: (TODO)
- Right-side microphone activation
- LC3 format audio streaming
- 30-second maximum recording duration
- Real-time audio data access
AI feature support: (TODO)
- Start/stop AI recording
- Manual/automatic modes
- Result display handling
- Network status monitoring
Core connection and communication handling:
- base.py: Base class for all connectors
- bluetooth.py: BLE device management and connection handling
- commands.py: Command protocol implementation
- pairing.py: Device pairing and authentication
Individual feature implementations:
- audio.py: Microphone control and audio processing (TODO)
- device.py: Device interactions (TODO)
- display.py: Text and image display management (TODO)
- events.py: Listening and responding to G1 events
- state.py: State tracking and event management
- status.py:
- uart.py: Low-level UART communication
Supporting utilities:
- config.py: Configuration management
- constants.py: Protocol constants and enums
- logger.py: Logging configuration
-
Config Initialization
- utils/config.py: Creates default configuration if none exists
- Default settings loaded from g1_config.json:
{
"reconnect_attempts": 3,
"reconnect_delay": 1.0,
"connection_timeout": 20.0
}
-
Logging Setup
- utils/logger.py: Configures logging handlers
- Creates log directory if not exists
- Initializes both file and console logging
- Log files stored in ./g1_connector.log
-
Bluetooth Discovery
- connector/bluetooth.py: BLEManager.scan_for_glasses()
- Searches for devices matching G1 identifier
- Returns list of discovered G1 glasses with addresses
-
Pairing Process
- connector/pairing.py: Handles initial device pairing
- Establishes secure connection with both left and right glasses
- Validates device authenticity
- Stores pairing information
-
Connection Confirmation
- connector/bluetooth.py: _connect_glass()
- Verifies successful connection to both glasses
- Initializes UART service
- Sets up notification handlers
-
Device ID Storage
- Stores validated glass IDs in config file
- Left glass address: left_address
- Right glass address: right_address
-
Direct Connection
- Reads stored glass IDs from config
- connector/bluetooth.py: Attempts direct connection
- Uses configured retry logic:
for attempt in range(self.connector.config.reconnect_attempts):
# Connection attempt logic
-
Connection Maintenance
- connector/commands.py: Sends periodic heartbeat
- Default heartbeat command: HEARTBEAT_CMD = bytes([0x25, 0x06, 0x00, 0x01, 0x04, 0x01])
- Monitors connection status
- Automatic reconnection on disconnect
-
Event Monitoring
- services/state.py: Manages state tracking
- services/uart.py: Handles UART notifications
- Event types defined in utils/constants.py:
- Physical states (wearing, charging)
- Device states (connected, operational)
- Interactions (taps, gestures)
- Battery status
simple_connect.py
Basic connection demonstration
python -m examples.simple_connect
interactions.py
Monitor and log device interactions
python -m examples.interactions
dashboard.py
Monitor statuses and logs
python -m examples.dashboard
send_text.py
Text display with multi-line support
python -m examples.send_text
PowerPoint Display (In progress)
ppt_teleprompter.py
Send speaker notes from an active PowerPoint presentation to the glasses
python -m examples.ppt_teleprompter
send_image.py (TODO)
Image transmission (1-bit, 576x136 BMP)
python -m examples.send_image
microphone.py (TODO)
Audio recording demonstration
python -m examples.microphone
even_ai.py (TODO)
Even AI integration example
python -m examples.even_ai
- Text display supports configurable font sizes and line counts
- Images must be 1-bit, 576x136 pixel BMP format
- Packet-based transmission with CRC verification
- LC3 format audio streaming
- Right-side microphone activation
- 30-second maximum recording duration
- Physical state tracking (wearing, charging, etc.)
- Battery level monitoring
- Interaction event processing
Default settings can be modified in g1_config.json:
- device_name: Customize the device name for pairing
- device_address: Manually set the device address
- auto_reconnect: Enable or disable automatic reconnection
- log_level: Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
- log_file: Specify a custom log file path
- log_to_console: Enable or disable logging to the console
- log_to_file: Enable or disable logging to a file
Roadmap & Planned Improvements
- clean up the console logs for a new connection, many duplicates and logs with markup
- Implement text sending functionality
- Add comprehensive examples for text display and interaction
- Document text positioning and formatting options
High Priority (Developer Experience)
-
Connection Management
- Implement Windows BLE connection recovery
- Detect and reuse existing connections
- Add configurable retry timing for connection attempts
- Implement force-disconnect on SDK exit
- Add connection state detection and logging
-
Pairing Improvements
- Add robust pairing state detection and management
- Detect proper pairing state vs. just connected state
- Add automatic re-pairing when connection is incomplete avoiding the need to delete the config file
- Add user guidance for connection troubleshooting
-
Documentation Improvements (add more detail to this readme doc)
- Add inline examples in docstrings
- add more detail/quickstarts/examples to this readme doc
- Document error scenarios and solutions
-
Developer Tools
- Create higher-level abstractions for common patterns
- Add more example applications
- Implement helper utilities for content formatting
-
Reliability Enhancements
- Improve connection state recovery
- Add automated reconnection strategies
- Enhance error handling with specific solutions
- Implement better battery and health monitoring (if supported by the device, events are a bit vague)
-
Code Structure
- Split G1Connector into focused components
- Add more type hints and dataclasses
- Implement async context managers
- Add configuration validation
- Structured telemetry collection
- Performance benchmarks
- Circuit breakers for problematic operations
- Formal dependency injection
- Structured logging
- Performance optimization