Button Press System
The button press system in ASG Client handles physical button interactions on the smart glasses and determines what actions to take.
How It Works
Button Press Flow
- Physical Press: User presses the camera button on the glasses
- MCU Detection: The glasses' microcontroller detects the press
- Command Generation: MCU sends a command to ASG Client:
cs_pho
- Short press (photo)cs_vdo
- Long press (video)
- ASG Client Processing: The service receives and processes the command
- Action Execution: Based on configuration, takes appropriate action
Button Press Modes
The ASG Client supports three configurable modes for handling button presses:
PHOTO Mode (Default)
- Button press triggers local photo/video capture only
- Photos are taken immediately on the device
- No communication with phone/cloud for the button press
// Short press behavior in PHOTO mode
case "cs_pho":
mMediaCaptureService.takePhotoLocally();
break;
APPS Mode
- Button press events are sent to the phone/apps only
- No local photo capture
- Apps can decide what to do with the button press
// Button press sent to phone in APPS mode
sendButtonPressToPhone(isLongPress);
BOTH Mode
- Combines PHOTO and APPS modes
- Takes photo locally AND sends event to apps
- Maximum flexibility for developers
Implementation Details
The button handling is implemented in AsgClientService.java
:
private void handleConfigurableButtonPress(boolean isLongPress) {
AsgSettings.ButtonPressMode mode = asgSettings.getButtonPressMode();
String pressType = isLongPress ? "long" : "short";
switch (mode) {
case PHOTO:
if (isLongPress) {
// Video recording (TODO)
} else {
mMediaCaptureService.takePhotoLocally();
}
break;
case APPS:
sendButtonPressToPhone(isLongPress);
break;
case BOTH:
// Do both actions
break;
}
}
Button Press Message Format
When sending button press to phone (APPS or BOTH mode):
{
"type": "button_press",
"buttonId": "camera",
"pressType": "short", // or "long"
"timestamp": 1234567890
}
Other Button Commands
Besides camera button, the system also handles:
- Swipe gestures:
cs_swst
commands from arm swipes - Battery status:
hm_batv
with battery percentage and voltage - Hotspot control:
hm_htsp
/mh_htsp
for WiFi hotspot
Configuration
Setting Button Mode
The button mode can be configured via:
- Settings in the MentraOS app
- Direct configuration through AsgSettings
- Debug commands during development
Mode Selection Guidelines
- Use PHOTO mode for simple camera glasses functionality
- Use APPS mode when apps need full control over button behavior
- Use BOTH mode for advanced scenarios where both local and remote actions are needed
Photo Capture Process
When a photo is triggered (PHOTO or BOTH mode):
- Capture: CameraNeo takes the photo
- Save: Photo saved to device storage
- Queue: Added to upload queue if online
- Upload: Sent to cloud when connection available
- Cleanup: Local copy managed based on settings
Video Recording
Video recording on long press is currently in development. The infrastructure is in place but the full implementation is pending.
Troubleshooting
Button Press Not Working
- Check logs: Look for
cs_pho
orcs_vdo
in logcat - Verify mode: Ensure correct button mode is set
- Service status: Confirm AsgClientService is running
- Permissions: Check camera and storage permissions
Common Issues
- No MCU commands: Check hardware connection to microcontroller
- Service not responding: May need to restart AsgClientService
- Wrong mode active: Verify configuration in settings
Future Enhancements
- Full video recording implementation
- Custom button mappings
- Gesture combinations
- Multi-button support