import React, { useState } from 'react'; import { View, Text, TouchableOpacity, StyleSheet, ScrollView, ActivityIndicator, Platform } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { router } from 'expo-router'; import { DeviceStatusBar } from '../../src/components/DeviceStatusBar'; import { ParamForm } from '../../src/components/ParamForm'; import { useDevice } from '../../src/hooks/useDevice'; import { useDataStore } from '../../src/stores/dataStore'; export default function ControlScreen() { const insets = useSafeAreaInsets(); const { busy, connected, deviceStatus, setup, startContinuous, startSingle, stop } = useDevice(); const frame = useDataStore((s) => s.currentFrame); const sessionId = useDataStore((s) => s.sessionId); const projectId = useDataStore((s) => s.projectId); const [configDirty, setConfigDirty] = useState(false); const [projectName, setProjectName] = React.useState(null); React.useEffect(() => { if (!projectId) { setProjectName(null); return; } import('../../src/services/StorageService').then(({ listProjects }) => listProjects().then((ps) => setProjectName(ps.find(p => p.projectId === projectId)?.name ?? null)), ); }, [projectId]); const handleSetup = async () => { await setup(); setConfigDirty(false); }; if (!connected) { return ( 未连接设备 router.push('/connect')} activeOpacity={0.8}> 前往连接 ); } const running = deviceStatus === 'running'; const single = deviceStatus === 'single'; const canStart = !running && !single && !busy; const canStop = (running || single) && !busy; return ( {/* Project / line context */} {projectName ? {projectName} · {sessionId} : {sessionId} } {/* Control buttons */} {busy && !canStop ? : <> 连续采集 } 单 次 {busy && canStop ? : <> 停 止 } {/* Frame info */} {frame && ( 帧号 #{frame.frameId} 叠加 {frame.accNum}次 通道 {frame.meta?.channelNum ?? '-'}ch 电流 {frame.meta?.current ?? '--'} )} {/* Param form */} 采集参数 {configDirty && ( 待下发 )} setConfigDirty(true)} /> {busy ? : 下 发 配 置} ); } const S = StyleSheet.create({ container: { flex: 1, backgroundColor: '#090912' }, notConnected: { flex: 1, justifyContent: 'center', alignItems: 'center', gap: 12, backgroundColor: '#090912' }, notConnectedIcon: { fontSize: 48, color: '#2a2a4a' }, notConnectedText: { color: '#4a4a6a', fontSize: 15 }, goConnectBtn: { backgroundColor: '#111120', borderRadius: 10, paddingVertical: 10, paddingHorizontal: 28, borderWidth: 1, borderColor: '#4a9eff' }, goConnectBtnText: { color: '#4a9eff', fontWeight: '600' }, // Control buttons ctrlRow: { flexDirection: 'row', gap: 8, padding: 12 }, ctrlBtn: { flex: 1, paddingVertical: 14, borderRadius: 12, alignItems: 'center', justifyContent: 'center', gap: 4, borderWidth: 1, }, btnStart: { backgroundColor: '#0d2018', borderColor: '#1a4a28' }, btnSingle: { backgroundColor: '#0d1a30', borderColor: '#1a2e54' }, btnStop: { backgroundColor: '#1e0d12', borderColor: '#3a1520' }, btnDisabled: { opacity: 0.3 }, ctrlIcon: { fontSize: 12, color: '#ffffff88' }, ctrlText: { fontSize: 12, fontWeight: '700', letterSpacing: 1 }, ctrlTextGreen: { color: '#3ddc84' }, ctrlTextBlue: { color: '#4a9eff' }, ctrlTextRed: { color: '#ff5c6e' }, // Frame info bar frameBar: { flexDirection: 'row', marginHorizontal: 12, marginBottom: 8, backgroundColor: '#0c0c1a', borderRadius: 10, borderWidth: 1, borderColor: '#1a1a2a', overflow: 'hidden', }, frameItem: { flex: 1, alignItems: 'center', paddingVertical: 8 }, frameItemLabel: { color: '#3a3a5a', fontSize: 9, fontWeight: '600', letterSpacing: 0.5, marginBottom: 2 }, frameItemValue: { color: '#8888aa', fontSize: 12, fontWeight: '600', fontFamily: Platform.OS === 'ios' ? 'Courier' : 'monospace' }, frameSep: { width: StyleSheet.hairlineWidth, backgroundColor: '#1e1e30', marginVertical: 6 }, // Form formScroll: { flex: 1 }, formHeader: { flexDirection: 'row', alignItems: 'center', gap: 10, paddingHorizontal: 16, paddingVertical: 10 }, formTitle: { color: '#4a4a6a', fontSize: 10, fontWeight: '700', letterSpacing: 1.5, textTransform: 'uppercase' }, dirtyBadge: { backgroundColor: '#2a1a05', borderRadius: 4, paddingHorizontal: 6, paddingVertical: 2, borderWidth: 1, borderColor: '#4a2a05' }, dirtyBadgeText: { color: '#ffb84d', fontSize: 9, fontWeight: '700' }, setupBtn: { margin: 16, backgroundColor: '#111120', borderRadius: 12, paddingVertical: 14, alignItems: 'center', borderWidth: 1, borderColor: '#4a9eff', }, setupBtnText: { color: '#4a9eff', fontWeight: '700', fontSize: 14, letterSpacing: 3 }, contextBar: { paddingHorizontal: 16, paddingVertical: 5, backgroundColor: '#08080f', borderBottomWidth: 1, borderBottomColor: '#141422' }, contextText: { color: '#2a2a4a', fontSize: 9, fontFamily: Platform.OS === 'ios' ? 'Courier' : 'monospace' }, });