import React, { useEffect, useRef, useState } from 'react'; import { ActivityIndicator, Switch, View, Text, ScrollView, Pressable, StyleSheet, Modal, TextInput, } from 'react-native'; import { LinearGradient } from 'expo-linear-gradient'; import Svg, { Circle, Line, Path, Polyline, Rect } from 'react-native-svg'; import { Header } from '../components/Header'; import { useScrollBottomPadding } from '../components/keyboardLayout'; import { OfflineNotice } from '../components/OfflineNotice'; import { colors } from '../components/theme'; import { connectedWifiStatus, galleryHotspotPasswordLabel, galleryHotspotSsidLabel, galleryServerUrl, hotspotLabel, isGlassesConnected, wifiLabel, wifiSubLabel, } from '../sdkFormat'; import { RGB_LED_COLORS, durationText, type LedColor, type LedMode, type BluetoothSdkExampleModel, type SdkConsoleEvent } from '../useBluetoothSdkExample'; import {TOUCH_GESTURES} from '../touchGestureDefaults'; import {isMentraLiveRuntime} from '../useBluetoothSdkExample'; const WIFI_COLLAPSED_NETWORK_LIMIT = 3; export function SystemScreen({ sdk }: { sdk: BluetoothSdkExampleModel }) { const scrollBottomPadding = useScrollBottomPadding(); const connected = isGlassesConnected(sdk.glasses); const currentWifi = connectedWifiStatus(sdk.glasses); const networks = (sdk.phone.wifiScanResults ?? []).filter( (network) => !connected || !currentWifi || network.ssid !== currentWifi.ssid, ); const galleryUrl = galleryServerUrl(sdk.glasses, sdk.hotspotEnabled); const galleryHotspotPassword = galleryUrl ? galleryHotspotPasswordLabel(sdk.glasses) : null; const inputChips = recentInputChips(sdk.events); const [pendingWifi, setPendingWifi] = useState<{ssid: string; requiresPassword: boolean} | null>(null); const [pendingWifiPassword, setPendingWifiPassword] = useState(''); const [showWifiPassword, setShowWifiPassword] = useState(false); const [wifiExpanded, setWifiExpanded] = useState(false); const didAutoScanWifi = useRef(false); const visibleNetworks = wifiExpanded ? networks : networks.slice(0, WIFI_COLLAPSED_NETWORK_LIMIT); const hiddenNetworkCount = Math.max(0, networks.length - visibleNetworks.length); const canToggleWifiList = networks.length > WIFI_COLLAPSED_NETWORK_LIMIT; const micStatus = sdk.micRecording ? recordingMicStatus(sdk) : sdk.micPlaying ? 'playing last recording' : sdk.lastMicDurationSeconds !== null && sdk.lastMicBytes > 0 ? `last ${durationText(sdk.lastMicDurationSeconds)} · ${formatPcmBytes(sdk.lastMicBytes)}` : connected ? 'record PCM from glasses' : 'connect glasses to record'; useEffect(() => { if (!connected) { didAutoScanWifi.current = false; return; } if (didAutoScanWifi.current) { return; } didAutoScanWifi.current = true; void sdk.requestWifiScan(); }, [connected, sdk]); return (
{!connected && } {/* Wi-Fi card */} Wi-Fi {networks.length} networks nearby Scan {currentWifi ? ( ) : null} {visibleNetworks.map((network, index) => { const connectingThis = sdk.wifiConnectingSsid === network.ssid; const joinNetwork = () => { if (network.requiresPassword) { setPendingWifi({ssid: network.ssid, requiresPassword: true}); setPendingWifiPassword(''); setShowWifiPassword(false); } else { void sdk.sendWifiCredentials(network.ssid, '', false); } }; return ( ); })} {sdk.wifiConnectError ? ( {sdk.wifiConnectError} ) : null} {canToggleWifiList ? ( setWifiExpanded((expanded) => !expanded)}> {wifiExpanded ? 'Show fewer networks' : `Show ${hiddenNetworkCount} more network${hiddenNetworkCount === 1 ? '' : 's'}`} ) : null} {/* Hotspot */} Hotspot {connected ? hotspotLabel(sdk.glasses, sdk.hotspotEnabled) : 'connect glasses to toggle'} Gallery server {galleryUrl ?? 'Enable hotspot to expose local gallery access'} {galleryHotspotPassword ? ( Join {galleryHotspotSsidLabel(sdk.glasses)} · password {galleryHotspotPassword} ) : null} {sdk.galleryServerStatus} {/* Wi-Fi ADB (Mentra Live debug) */} Wi-Fi ADB {connected ? sdk.wifiAdbEnabled ? 'Wireless debugging enabled (Mentra Live)' : 'Wireless debugging off (default)' : 'connect glasses first'} { void sdk.setWifiAdbState(true); }} /> { void sdk.setWifiAdbState(false); }} /> Mentra Live only · watch Console for TX/LIVE lines if nothing changes {/* Microphone */} {sdk.micRecording ? : } {sdk.micPlaying ? : } sdk.setVoiceActivityDetectionEnabled(!sdk.voiceActivityDetectionEnabled)} /> Microphone {micStatus} {sdk.micAudioRouteStatus} Audio setup {sdk.micPlaybackHint ? {sdk.micPlaybackHint} : null} {/* Inputs */} Inputs button · touch · swipe {connected ? 'LIVE' : 'OFF'} {inputChips.map((item) => ( ))} Save in gallery mode {sdk.galleryModeEnabled ? 'On: the glasses button saves photos/videos locally.' : 'Off: button and touch events are reported to the phone.'} sdk.setGalleryModeEnabled(true)} /> sdk.setGalleryModeEnabled(false)} /> Touchpad default actions Enable the glasses’ built-in action for each gesture. Touch events still reach the app. Settings reset after disconnect or reboot. Requires Mentra Live with supported firmware. {TOUCH_GESTURES.map(({gesture, label}) => ( {label} void sdk.setTouchGestureDefaultBehaviorEnabled(gesture, enabled)} trackColor={{true: colors.greenAccent}} /> ))} {/* RGB LED */} RGB LED color & pattern {sdk.ledMode !== 'Off' && ( )} {sdk.ledMode === 'Off' ? 'off' : 'on'} sdk.selectLedMode('Off')} icon={} label="Off" /> sdk.selectLedMode('Solid')} icon={} label="Solid" /> sdk.selectLedMode('Pulse')} icon={} label="Pulse" /> sdk.selectLedMode('Blink')} icon={} label="Blink" /> {RGB_LED_COLORS.map((color) => ( sdk.selectLedColor(color)} /> ))} Mentra Live RGB controls demonstrate LED color and timing patterns. setPendingWifi(null)} transparent visible={pendingWifi !== null}> Join Wi-Fi {pendingWifi?.ssid} setShowWifiPassword((visible) => !visible)} style={styles.modalInputEye}> {showWifiPassword ? ( <> ) : ( <> )} setPendingWifi(null)}> Cancel { if (pendingWifi) { void sdk.sendWifiCredentials(pendingWifi.ssid, pendingWifiPassword, pendingWifi.requiresPassword); } setPendingWifi(null); setPendingWifiPassword(''); }}> Connect ); } function NetworkRow({ actionColor = colors.ink, actionLabel, busy, check, disabled, faint, last, locked, name, onActionPress, onPress, rssi, sub, subColor, }: { actionColor?: string; actionLabel?: string; busy?: boolean; check?: boolean; disabled?: boolean; faint?: boolean; last?: boolean; locked?: boolean; name: string; onActionPress?: () => void; onPress?: () => void; rssi?: string; sub: string; subColor: string; }) { return ( {name} {sub} {rssi && ( {rssi} {check && } )} {locked && ( )} {busy ? ( ) : actionLabel ? ( {actionLabel} ) : null} ); } function GalleryModeChip({ active, disabled, label, onPress }: { active: boolean; disabled: boolean; label: string; onPress: () => void }) { return ( {label} ); } function HotspotActionChip({ enabled, label, onPress }: { enabled: boolean; label: string; onPress: () => void }) { return ( {label} ); } function InputChip({ prefix, label }: { prefix: string; label: string }) { return ( {prefix} {label} ); } function recordingMicStatus(sdk: BluetoothSdkExampleModel) { if (sdk.pcmBytes <= 0) { return 'recording · listening for speech'; } return `recording · ${formatPcmBytes(sdk.pcmBytes)} captured`; } function formatPcmBytes(bytes: number) { if (bytes < 1024) { return `${bytes} B PCM`; } const kib = bytes / 1024; if (kib < 1024) { return `${kib >= 10 ? kib.toFixed(0) : kib.toFixed(1)} KB PCM`; } const mib = kib / 1024; return `${mib >= 10 ? mib.toFixed(0) : mib.toFixed(1)} MB PCM`; } function recentInputChips(events: SdkConsoleEvent[]) { const labels = events.map((item) => inputLabel(item.text)).filter((label): label is string => Boolean(label)).slice(0, 3); if (labels.length === 0) { return [{ age: '--', label: 'waiting' }]; } return labels.map((label, index) => ({ age: `${index + 1}s`, label })); } function inputLabel(text: string) { const normalized = normalizeInputText(text); const [prefix, ...payloadParts] = normalized.split(' '); if (!inputEventPrefixes.has(prefix)) { return null; } const label = beautifyInputPayload(payloadParts.join(' ')); return label || prefix; } const inputEventPrefixes = new Set(['button', 'touch', 'swipe']); const inputLabelReplacements: Array<[string, string]> = [ ['forward swipe', 'swipe →'], ['right swipe', 'swipe →'], ['backward swipe', 'swipe ←'], ['backwards swipe', 'swipe ←'], ['left swipe', 'swipe ←'], ['up swipe', 'swipe ↑'], ['down swipe', 'swipe ↓'], ['single tap', 'tap'], ['long press', 'long'], ]; function normalizeInputText(text: string) { return text .trim() .toLowerCase() .replace(/->/g, ' forward swipe ') .replace(/[_:]+/g, ' ') .replace(/\s+/g, ' ') .trim(); } function beautifyInputPayload(payload: string) { return inputLabelReplacements.reduce( (label, [source, replacement]) => label.replaceAll(source, replacement), payload, ); } function LedTab({ icon, label, active, disabled, onPress }: { icon: React.ReactNode; label: LedMode; active?: boolean; disabled?: boolean; onPress: () => void }) { return ( {icon} {label} ); } function LedColorChip({ active, color, disabled, onPress }: { active: boolean; color: LedColor; disabled: boolean; onPress: () => void }) { return ( {capitalize(color)} ); } function MicControlButton({ active, children, disabled, onPress }: { active: boolean; children: React.ReactNode; disabled: boolean; onPress: () => void }) { return ( {children} ); } function VoiceActivityToggle({ active, disabled, onPress }: { active: boolean; disabled: boolean; onPress: () => void }) { return ( {active ? 'VAD on' : 'VAD off'} ); } function SpeakingStatusRow({ enabled, speaking }: { enabled: boolean; speaking: boolean | null }) { const active = enabled && speaking === true; return ( Speech {enabled ? (active ? 'Speaking' : 'Not speaking') : 'VAD off'} ); } function RecordIcon() { return ( ); } function StopIcon({ active }: { active?: boolean }) { return ( ); } function PlayIcon() { return ( ); } function ledSwatchColor(color: LedColor) { switch (color) { case 'red': return colors.red; case 'blue': return colors.ble; case 'orange': return colors.amber; case 'white': return '#FFFFFF'; default: return colors.greenAccent; } } function ledChipBorderColor(color: LedColor) { return color === 'white' ? 'rgba(15,42,29,0.16)' : `${ledSwatchColor(color)}6B`; } function capitalize(value: string) { return value.charAt(0).toUpperCase() + value.slice(1); } const styles = StyleSheet.create({ bigCard: { marginHorizontal: 16, marginTop: 12, borderRadius: 28, paddingVertical: 18, paddingHorizontal: 18, borderWidth: 1, borderColor: colors.border, gap: 12 }, wifiHeader: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }, iconTileSm: { width: 32, height: 32, borderRadius: 10, backgroundColor: 'rgba(125,216,158,0.18)', borderWidth: 1, borderColor: 'rgba(52,199,89,0.22)', alignItems: 'center', justifyContent: 'center' }, wifiTitle: { color: colors.ink, fontSize: 17, fontWeight: '700', letterSpacing: -0.17 }, wifiSub: { color: colors.muted, fontSize: 12, fontWeight: '500' }, scanBtn: { flexDirection: 'row', alignItems: 'center', minHeight: 44, gap: 7, backgroundColor: 'rgba(15,42,29,0.06)', paddingVertical: 9, paddingHorizontal: 14, borderRadius: 999 }, disabled: { opacity: 0.45 }, scanText: { color: colors.ink, fontSize: 13, fontWeight: '600' }, networkRow: { flexDirection: 'row', alignItems: 'center', paddingVertical: 14, gap: 12 }, networkBorder: { borderBottomWidth: 1, borderColor: 'rgba(15,42,29,0.06)' }, networkIcon: { width: 28, alignItems: 'center', justifyContent: 'center' }, networkName: { color: colors.ink, fontSize: 15, fontWeight: '700' }, networkSub: { fontSize: 12, fontWeight: '500' }, networkAction: { minHeight: 40, minWidth: 64, alignItems: 'center', justifyContent: 'center', paddingVertical: 8, paddingHorizontal: 12, borderRadius: 999 }, networkActionText: { fontSize: 12, fontWeight: '700' }, wifiErrorText: { color: colors.red, fontSize: 12, fontWeight: '600', marginTop: 8 }, wifiExpandRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 6, borderTopWidth: 1, borderTopColor: 'rgba(15,42,29,0.06)', paddingTop: 12, paddingBottom: 2 }, wifiExpandText: { color: colors.greenInk, fontSize: 12, fontWeight: '700' }, tileCard: { flex: 1, borderRadius: 22, paddingVertical: 16, paddingHorizontal: 16, gap: 10, borderWidth: 1, borderColor: colors.borderSoft }, hotspotCard: { marginHorizontal: 16, marginTop: 12, borderRadius: 22, paddingVertical: 14, paddingHorizontal: 16, gap: 10, borderWidth: 1, borderColor: colors.borderSoft }, wifiAdbCard: { marginHorizontal: 16, marginTop: 8, borderRadius: 22, paddingVertical: 14, paddingHorizontal: 16, gap: 10, borderWidth: 1, borderColor: colors.borderSoft }, wifiAdbActions: { flexDirection: 'row', alignItems: 'center', gap: 8 }, hotspotDivider: { height: 1, backgroundColor: 'rgba(15,42,29,0.05)' }, hotspotGalleryRow: { flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'space-between', gap: 12 }, hotspotGalleryTitle: { color: colors.ink, fontSize: 13, fontWeight: '700' }, hotspotGalleryUrl: { fontSize: 11, fontWeight: '600', lineHeight: 15 }, hotspotGalleryHint: { color: colors.muted, fontSize: 11, fontWeight: '500', lineHeight: 15, marginTop: 2 }, hotspotActions: { alignItems: 'flex-end', gap: 6 }, hotspotActionRow: { flexDirection: 'row', gap: 6 }, hotspotActionChip: { minHeight: 40, minWidth: 72, alignItems: 'center', justifyContent: 'center', paddingVertical: 8, paddingHorizontal: 11, borderRadius: 999, backgroundColor: 'rgba(52,199,89,0.14)' }, hotspotActionChipDisabled: { backgroundColor: 'rgba(15,42,29,0.04)' }, hotspotActionText: { color: colors.greenDeep, fontSize: 12, fontWeight: '700' }, hotspotActionTextDisabled: { color: colors.muted }, hotspotStatus: { fontSize: 12, lineHeight: 16, fontWeight: '600' }, micCard: { marginHorizontal: 16, marginTop: 8, borderRadius: 22, paddingVertical: 16, paddingHorizontal: 16, gap: 10, borderWidth: 1, borderColor: colors.borderSoft }, tileHead: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between' }, toggleOn: { width: 38, height: 22, borderRadius: 999, backgroundColor: '#fff', borderWidth: 1.2, paddingHorizontal: 2, alignItems: 'flex-end', justifyContent: 'center' }, toggleKnob: { width: 18, height: 18, borderRadius: 999, backgroundColor: colors.greenAccent }, micControls: { flexDirection: 'row', alignItems: 'center', gap: 8 }, micControlButton: { width: 44, height: 44, borderRadius: 999, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', shadowColor: '#0F2A1D', shadowOpacity: 0.05, shadowOffset: { width: 0, height: 4 }, shadowRadius: 8, elevation: 1 }, micControlButtonActive: { backgroundColor: colors.greenInk }, voiceActivityToggle: { minWidth: 66, minHeight: 44, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 10, borderRadius: 999, backgroundColor: 'rgba(15,42,29,0.04)', borderWidth: 1, borderColor: 'rgba(15,42,29,0.08)' }, voiceActivityToggleActive: { backgroundColor: 'rgba(52,199,89,0.16)', borderColor: 'rgba(52,199,89,0.34)' }, voiceActivityToggleText: { color: colors.muted, fontSize: 11, fontWeight: '700' }, voiceActivityToggleTextActive: { color: colors.greenInk }, speakingStatusRow: { alignSelf: 'flex-start', minHeight: 32, flexDirection: 'row', alignItems: 'center', gap: 7, marginTop: 6, paddingVertical: 7, paddingHorizontal: 10, borderRadius: 12, backgroundColor: 'rgba(15,42,29,0.04)' }, speakingDot: { width: 8, height: 8, borderRadius: 999 }, speakingLabel: { color: colors.muted, fontSize: 10, fontWeight: '700', letterSpacing: 0.6, textTransform: 'uppercase' }, speakingValue: { fontSize: 12, fontWeight: '600' }, micSettingsButton: { alignSelf: 'flex-start', minHeight: 40, marginTop: 6, backgroundColor: 'rgba(52,199,89,0.14)', borderRadius: 999, paddingHorizontal: 12, paddingVertical: 8, justifyContent: 'center' }, micSettingsText: { color: colors.greenDeep, fontSize: 12, fontWeight: '700' }, micRouteText: { color: colors.muted, fontSize: 12, fontWeight: '600', lineHeight: 16, marginTop: 4 }, micWarning: { color: colors.red, fontSize: 12, fontWeight: '500', lineHeight: 16, marginTop: 4 }, tileTitle: { color: colors.ink, fontSize: 16, fontWeight: '700', letterSpacing: -0.16 }, tileSub: { color: colors.muted, fontSize: 12, fontWeight: '500' }, livePill2: { flexDirection: 'row', alignItems: 'center', gap: 5, backgroundColor: 'rgba(52,199,89,0.16)', borderWidth: 1, borderColor: 'rgba(52,199,89,0.3)', paddingVertical: 4, paddingHorizontal: 9, borderRadius: 999 }, livePill2Text: { color: colors.greenDeep, fontSize: 10, fontWeight: '700', letterSpacing: 0.5 }, inputChips: { flexDirection: 'row', gap: 8 }, inputChip: { flex: 1, flexDirection: 'row', alignItems: 'center', minHeight: 40, gap: 6, backgroundColor: 'rgba(15,42,29,0.04)', paddingVertical: 9, paddingHorizontal: 10, borderRadius: 12 }, inputChipPrefix: { color: colors.muted, fontSize: 11, fontWeight: '600' }, inputChipLabel: { flex: 1, color: colors.ink, fontSize: 12, fontWeight: '700' }, galleryModeBlock: { gap: 6, marginTop: 12 }, galleryModeTitle: { color: colors.ink, fontSize: 14, fontWeight: '700' }, galleryModeBody: { color: colors.muted, fontSize: 11, fontWeight: '500', lineHeight: 15 }, galleryModeChips: { flexDirection: 'row', gap: 8, marginTop: 2 }, galleryModeChip: { minHeight: 44, justifyContent: 'center', paddingVertical: 10, paddingHorizontal: 14, borderRadius: 999, backgroundColor: 'rgba(15,42,29,0.04)', borderWidth: 1, borderColor: 'rgba(15,42,29,0.05)' }, galleryModeChipActive: { backgroundColor: 'rgba(52,199,89,0.16)', borderColor: 'rgba(52,199,89,0.32)' }, galleryModeChipText: { color: colors.muted, fontSize: 12, fontWeight: '500' }, galleryModeChipTextActive: { color: colors.greenInk, fontWeight: '700' }, modalBackdrop: { flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'rgba(0,0,0,0.34)', padding: 24 }, modalCard: { width: '100%', borderRadius: 24, backgroundColor: colors.bg, padding: 20, gap: 12 }, modalTitle: { color: colors.ink, fontSize: 22, fontWeight: '800' }, modalSub: { color: colors.muted, fontSize: 15, fontWeight: '600' }, modalInputRow: { flexDirection: 'row', alignItems: 'center', backgroundColor: 'rgba(15,42,29,0.04)', borderRadius: 14 }, modalInput: { flex: 1, color: colors.ink, fontSize: 16, fontWeight: '500', paddingHorizontal: 14, paddingVertical: 14 }, modalInputEye: { alignItems: 'center', justifyContent: 'center', minWidth: 44, minHeight: 44, paddingRight: 4 }, modalActions: { flexDirection: 'row', gap: 10, marginTop: 4 }, modalCancel: { flex: 1, alignItems: 'center', backgroundColor: 'rgba(15,42,29,0.06)', borderRadius: 16, paddingVertical: 14 }, modalCancelText: { color: colors.ink, fontSize: 15, fontWeight: '700' }, modalConfirm: { flex: 1, alignItems: 'center', backgroundColor: colors.greenPrimary, borderRadius: 16, paddingVertical: 14 }, modalConfirmText: { color: '#fff', fontSize: 15, fontWeight: '700' }, ledTitle: { color: colors.ink, fontSize: 18, fontWeight: '700', letterSpacing: -0.18 }, onPill: { flexDirection: 'row', alignItems: 'center', minHeight: 36, gap: 6, backgroundColor: 'rgba(15,42,29,0.06)', paddingVertical: 7, paddingHorizontal: 12, borderRadius: 999 }, onText: { color: colors.ink, fontSize: 12, fontWeight: '600' }, ledTabs: { flexDirection: 'row', gap: 4, backgroundColor: 'rgba(15,42,29,0.05)', borderRadius: 14, padding: 4 }, ledTab: { flex: 1, paddingVertical: 12, paddingHorizontal: 6, alignItems: 'center', gap: 6, borderRadius: 10 }, ledTabActive: { backgroundColor: '#fff' }, ledTabText: { color: colors.muted, fontSize: 12, fontWeight: '500' }, ledTabTextActive: { color: colors.ink, fontWeight: '600' }, ledColorRow: { flexDirection: 'row', gap: 6 }, ledColorChip: { flex: 1, minWidth: 0, minHeight: 40, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 5, paddingVertical: 9, paddingHorizontal: 8, borderRadius: 999, backgroundColor: 'rgba(15,42,29,0.04)', borderWidth: 1, borderColor: 'rgba(15,42,29,0.05)' }, ledColorChipActive: { backgroundColor: '#fff' }, ledColorDot: { width: 9, height: 9, borderRadius: 999 }, ledColorDotWhite: { borderWidth: 1, borderColor: 'rgba(15,42,29,0.16)' }, ledColorText: { color: colors.muted, fontSize: 11, fontWeight: '500' }, ledColorTextActive: { color: colors.ink, fontWeight: '600' }, ledNote: { color: colors.muted, fontSize: 11, lineHeight: 16, fontWeight: '500' }, });