From e115e0fd12e5650d8b8387c7d86fe49bac6d64a9 Mon Sep 17 00:00:00 2001 From: PunnawithSut Date: Mon, 16 Feb 2026 20:25:38 +0700 Subject: [PATCH 1/3] fix: home navigation --- SignGo-app/app/(app)/home.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SignGo-app/app/(app)/home.tsx b/SignGo-app/app/(app)/home.tsx index 19d47a2..69717a5 100644 --- a/SignGo-app/app/(app)/home.tsx +++ b/SignGo-app/app/(app)/home.tsx @@ -10,17 +10,25 @@ import { import { useRouter } from "expo-router"; import { useSpeech } from "@/contexts/speechContext"; import { SUPPORTED_LANGUAGES } from '../../constants/language'; +import { useAuth } from "@/contexts/AuthContext"; export default function Home() { const router = useRouter(); //const holdTimeout = useRef(null); const SIZE = 160; + const { user } = useAuth() const { targetLanguage, downloadedLanguage } = useSpeech() const [ currLanguage, setCurrLanguage ] = useState("English"); useEffect(() => { console.log(downloadedLanguage); - }, [downloadedLanguage]) + }, [downloadedLanguage]); + + useEffect(() => { + if(!user) { + router.replace("/(auth)/login"); + } + }, [user]) useEffect(() => { const language = SUPPORTED_LANGUAGES.find((lang) => (lang.code === targetLanguage)); From b2fffa2f1b47ec7b415f0c4d6455e34a9e40e25b Mon Sep 17 00:00:00 2001 From: PunnawithSut Date: Mon, 16 Feb 2026 21:39:23 +0700 Subject: [PATCH 2/3] fix: ble session error --- SignGo-app/app/(app)/bluetooth.tsx | 410 +++++++++++------------- SignGo-app/app/(app)/home.tsx | 2 +- SignGo-app/machineLearning/MLService.ts | 4 +- 3 files changed, 191 insertions(+), 225 deletions(-) diff --git a/SignGo-app/app/(app)/bluetooth.tsx b/SignGo-app/app/(app)/bluetooth.tsx index 228fcde..bffb592 100644 --- a/SignGo-app/app/(app)/bluetooth.tsx +++ b/SignGo-app/app/(app)/bluetooth.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect } from "react"; import { View, Text, @@ -9,17 +9,17 @@ import { PermissionsAndroid, Platform, Linking, -} from 'react-native'; -import { BleManager, Device, State } from 'react-native-ble-plx'; -import { BLEService } from '../../bluetooth/BLEService'; -import { Ionicons } from '@expo/vector-icons'; -import { router } from 'expo-router'; -import SensorData from './SensorData'; -import Ai from './ai'; +} from "react-native"; +import { BleManager, Device, State } from "react-native-ble-plx"; +import { BLEService } from "../../bluetooth/BLEService"; +import { Ionicons } from "@expo/vector-icons"; +import { router } from "expo-router"; +import SensorData from "./SensorData"; +import Ai from "./ai"; const manager = new BleManager(); -type TabType = 'sensor' | 'ai'; +type TabType = "sensor" | "ai"; export default function BLEManagerMerged() { const [bleState, setBleState] = useState(State.Unknown); @@ -31,23 +31,23 @@ export default function BLEManagerMerged() { const [permissionsGranted, setPermissionsGranted] = useState(false); // Tab navigation for connected view - const [activeTab, setActiveTab] = useState('sensor'); + const [activeTab, setActiveTab] = useState("sensor"); useEffect(() => { initializeBluetooth(); - return () => { - manager.destroy(); - }; + // return () => { + // manager.destroy(); + // }; }, []); // Show low battery alert useEffect(() => { if (batteryLevel !== null && batteryLevel <= 15 && batteryLevel > 0) { Alert.alert( - '⚠️ Low Battery', - 'Glove battery is low. Please charge soon.', - [{ text: 'OK' }] + "⚠️ Low Battery", + "Glove battery is low. Please charge soon.", + [{ text: "OK" }], ); } }, [batteryLevel]); @@ -59,38 +59,38 @@ export default function BLEManagerMerged() { if (!granted) { Alert.alert( - 'Permissions Required', - 'Bluetooth permissions are required to use this app. Please grant them in settings.', + "Permissions Required", + "Bluetooth permissions are required to use this app. Please grant them in settings.", [ - { text: 'Cancel', style: 'cancel' }, - { text: 'Open Settings', onPress: () => Linking.openSettings() } - ] + { text: "Cancel", style: "cancel" }, + { text: "Open Settings", onPress: () => Linking.openSettings() }, + ], ); return; } // Monitor Bluetooth state const subscription = manager.onStateChange((state) => { - console.log('Bluetooth state:', state); + console.log("Bluetooth state:", state); setBleState(state); if (state === State.PoweredOff) { // Prompt user to enable Bluetooth Alert.alert( - 'Bluetooth is Off', - 'Please enable Bluetooth to use this app.', + "Bluetooth is Off", + "Please enable Bluetooth to use this app.", [ - { text: 'Cancel', style: 'cancel' }, + { text: "Cancel", style: "cancel" }, { - text: 'Enable Bluetooth', - onPress: () => enableBluetooth() - } - ] + text: "Enable Bluetooth", + onPress: () => enableBluetooth(), + }, + ], ); } if (state === State.PoweredOn) { - console.log('✅ Bluetooth is ready'); + console.log("✅ Bluetooth is ready"); } }, true); @@ -99,31 +99,31 @@ export default function BLEManagerMerged() { const enableBluetooth = async () => { try { - if (Platform.OS === 'android') { + if (Platform.OS === "android") { // On Android 12+, we can prompt the user to enable Bluetooth await manager.enable(); } else { // On iOS, we can only ask them to go to settings Alert.alert( - 'Enable Bluetooth', - 'Please enable Bluetooth in your device settings.', + "Enable Bluetooth", + "Please enable Bluetooth in your device settings.", [ - { text: 'Cancel', style: 'cancel' }, - { text: 'Open Settings', onPress: () => Linking.openSettings() } - ] + { text: "Cancel", style: "cancel" }, + { text: "Open Settings", onPress: () => Linking.openSettings() }, + ], ); } } catch (error) { - console.error('Error enabling Bluetooth:', error); + console.error("Error enabling Bluetooth:", error); Alert.alert( - 'Cannot Enable Bluetooth', - 'Please enable Bluetooth manually in your device settings.' + "Cannot Enable Bluetooth", + "Please enable Bluetooth manually in your device settings.", ); } }; const requestPermissions = async () => { - if (Platform.OS === 'android') { + if (Platform.OS === "android") { if (Platform.Version >= 31) { // Android 12+ requires BLUETOOTH_SCAN and BLUETOOTH_CONNECT const granted = await PermissionsAndroid.requestMultiple([ @@ -133,11 +133,11 @@ export default function BLEManagerMerged() { ]); const allGranted = Object.values(granted).every( - (status) => status === PermissionsAndroid.RESULTS.GRANTED + (status) => status === PermissionsAndroid.RESULTS.GRANTED, ); if (!allGranted) { - console.error('Not all permissions granted:', granted); + console.error("Not all permissions granted:", granted); } return allGranted; @@ -145,12 +145,12 @@ export default function BLEManagerMerged() { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, { - title: 'Location Permission', - message: 'Bluetooth Low Energy requires Location permission', - buttonNeutral: 'Ask Me Later', - buttonNegative: 'Cancel', - buttonPositive: 'OK', - } + title: "Location Permission", + message: "Bluetooth Low Energy requires Location permission", + buttonNeutral: "Ask Me Later", + buttonNegative: "Cancel", + buttonPositive: "OK", + }, ); return granted === PermissionsAndroid.RESULTS.GRANTED; } @@ -161,20 +161,20 @@ export default function BLEManagerMerged() { const startScan = () => { if (!permissionsGranted) { Alert.alert( - 'Permissions Required', - 'Please grant Bluetooth permissions to scan for devices.' + "Permissions Required", + "Please grant Bluetooth permissions to scan for devices.", ); return; } if (bleState !== State.PoweredOn) { Alert.alert( - 'Bluetooth Not Available', - 'Please ensure Bluetooth is enabled on your device.', + "Bluetooth Not Available", + "Please ensure Bluetooth is enabled on your device.", [ - { text: 'Cancel', style: 'cancel' }, - { text: 'Enable', onPress: () => enableBluetooth() } - ] + { text: "Cancel", style: "cancel" }, + { text: "Enable", onPress: () => enableBluetooth() }, + ], ); return; } @@ -182,18 +182,18 @@ export default function BLEManagerMerged() { setDevices([]); setScanning(true); - console.log('Starting device scan...'); + console.log("Starting device scan..."); manager.startDeviceScan(null, null, (error, device) => { if (error) { - console.error('Scan error:', error); + console.error("Scan error:", error); setScanning(false); - Alert.alert('Scan Error', error.message); + Alert.alert("Scan Error", error.message); return; } if (device && device.name) { - console.log('Found device:', device.name, device.id); + console.log("Found device:", device.name, device.id); setDevices((prev) => { const exists = prev.find((d) => d.id === device.id); if (!exists) { @@ -211,7 +211,7 @@ export default function BLEManagerMerged() { }; const stopScan = () => { - console.log('Stopping device scan...'); + console.log("Stopping device scan..."); manager.stopDeviceScan(); setScanning(false); }; @@ -220,16 +220,16 @@ export default function BLEManagerMerged() { try { stopScan(); - console.log('Connecting to device:', device.name); + console.log("Connecting to device:", device.name); const connected = await manager.connectToDevice(device.id, { timeout: 10000, // 10 second timeout }); - console.log('Discovering services...'); + console.log("Discovering services..."); await connected.discoverAllServicesAndCharacteristics(); setConnectedDevice(connected); - console.log('✅ Connected successfully!'); + console.log("✅ Connected successfully!"); // Start reading sensor data immediately - no pairing needed await startReadingSensorData(connected); @@ -244,16 +244,15 @@ export default function BLEManagerMerged() { await BLEService.subscribeBatteryLevel(connected, (level) => { setBatteryLevel(level); }); - } catch (error: any) { - console.error('Connection error:', error); + console.error("Connection error:", error); - let errorMessage = 'Could not connect to device'; + let errorMessage = "Could not connect to device"; if (error.message) { errorMessage += `: ${error.message}`; } - Alert.alert('Connection Failed', errorMessage); + Alert.alert("Connection Failed", errorMessage); setConnectedDevice(null); } }; @@ -263,12 +262,12 @@ export default function BLEManagerMerged() { await BLEService.subscribeSensorData(device, (data) => { setSensorData(data); }); - console.log('✅ Sensor data streaming started'); + console.log("✅ Sensor data streaming started"); } catch (error: any) { - console.error('Sensor reading error:', error); + console.error("Sensor reading error:", error); Alert.alert( - 'Sensor Error', - `Could not read sensor data: ${error.message || 'Unknown error'}` + "Sensor Error", + `Could not read sensor data: ${error.message || "Unknown error"}`, ); } }; @@ -277,165 +276,130 @@ export default function BLEManagerMerged() { if (connectedDevice) { try { await manager.cancelDeviceConnection(connectedDevice.id); - console.log('Disconnected from device'); + console.log("Disconnected from device"); } catch (error) { - console.error('Disconnect error:', error); + console.error("Disconnect error:", error); } } setConnectedDevice(null); setSensorData(null); setBatteryLevel(null); - setActiveTab('sensor'); // Reset to sensor tab + setActiveTab("sensor"); // Reset to sensor tab }; - return ( - - {/* FLOATING HOME BUTTON */} - { - await disconnect(); - router.replace("/home"); - }} - > - - - - {/* ===================== NOT CONNECTED ===================== */} - {!connectedDevice ? ( - - Bluetooth Devices - - Scan and connect your SignGo glove - - - {/* Show warnings if needed */} - {!permissionsGranted && ( - - - Bluetooth permissions not granted - - Linking.openSettings()} - > - Open Settings - - - )} - - {bleState !== State.PoweredOn && permissionsGranted && ( - - - Bluetooth is {bleState === State.PoweredOff ? 'Off' : 'Not Available'} - - Enable Bluetooth - - )} - - - - {scanning ? "Scanning..." : "Scan for Devices"} + useEffect(() => { + return () => { + if (connectedDevice) { + disconnect(); + } + }; + }, [connectedDevice]); + + if (connectedDevice) { + return ; + } else { + return ( + + {/* FLOATING HOME BUTTON */} + { + await disconnect(); + //setActiveTab('sensor'); + router.replace("/home"); + }} + > + + + + {/* ===================== NOT CONNECTED ===================== */} + {!connectedDevice && ( + + Bluetooth Devices + + Scan and connect your SignGo glove - - - item.id} - contentContainerStyle={{ paddingBottom: 20 }} - renderItem={({ item }) => ( - handleConnect(item)} - > - - - {item.name || "Unknown Device"} - - {item.id} - - Connect - - )} - ListEmptyComponent={ - - - {scanning - ? 'Scanning for devices...' - : bleState !== State.PoweredOn - ? 'Enable Bluetooth to scan' - : 'Tap "Scan for Devices" to find your glove'} + {/* Show warnings if needed */} + {!permissionsGranted && ( + + + Bluetooth permissions not granted - {scanning && ( - - Make sure your glove is powered on - - )} - - } - /> - - ) : ( - /* ===================== CONNECTED ===================== */ - - - {connectedDevice.name || "Connected Device"} - - - - BLE Connected - {batteryLevel !== null ? ` • 🔋 ${batteryLevel}%` : ""} - - - {/* TABS */} - - {(["sensor", "ai"] as TabType[]).map((tab) => ( - setActiveTab(tab)} - > - Linking.openSettings()} > - {tab === "sensor" ? "Sensor Data" : "AI"} - - - ))} - + Open Settings + + + )} - - {activeTab === "sensor" ? ( - - ) : ( - + {bleState !== State.PoweredOn && permissionsGranted && ( + + + Bluetooth is{" "} + {bleState === State.PoweredOff ? "Off" : "Not Available"} + + Enable Bluetooth + )} - - - Disconnect - - - )} - - ); + + + {scanning ? "Scanning..." : "Scan for Devices"} + + + + item.id} + contentContainerStyle={{ paddingBottom: 20 }} + renderItem={({ item }) => ( + handleConnect(item)} + > + + + {item.name || "Unknown Device"} + + {item.id} + + + Connect + + )} + ListEmptyComponent={ + + + {scanning + ? "Scanning for devices..." + : bleState !== State.PoweredOn + ? "Enable Bluetooth to scan" + : 'Tap "Scan for Devices" to find your glove'} + + {scanning && ( + + Make sure your glove is powered on + + )} + + } + /> + + )} + + ); + } } /* ===================== STYLES ===================== */ @@ -526,7 +490,7 @@ const styles = StyleSheet.create({ flexDirection: "row", justifyContent: "space-between", elevation: 2, - shadowColor: '#000', + shadowColor: "#000", shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, @@ -548,21 +512,21 @@ const styles = StyleSheet.create({ }, emptyContainer: { - alignItems: 'center', - justifyContent: 'center', + alignItems: "center", + justifyContent: "center", marginTop: 60, paddingHorizontal: 20, }, emptyText: { - textAlign: 'center', - color: '#6b7c8f', + textAlign: "center", + color: "#6b7c8f", fontSize: 16, }, emptySubtext: { - textAlign: 'center', - color: '#999', + textAlign: "center", + color: "#999", fontSize: 14, marginTop: 8, }, @@ -612,4 +576,4 @@ const styles = StyleSheet.create({ color: "#2d547e", fontWeight: "600", }, -}); \ No newline at end of file +}); diff --git a/SignGo-app/app/(app)/home.tsx b/SignGo-app/app/(app)/home.tsx index 69717a5..ae13d5d 100644 --- a/SignGo-app/app/(app)/home.tsx +++ b/SignGo-app/app/(app)/home.tsx @@ -47,7 +47,7 @@ export default function Home() { }; const handleAiPress = () => { - router.replace("/ai"); + router.replace("/bluetooth"); }; const handleLanguageManagerPress = () => { diff --git a/SignGo-app/machineLearning/MLService.ts b/SignGo-app/machineLearning/MLService.ts index 6ca67df..ef3be4c 100644 --- a/SignGo-app/machineLearning/MLService.ts +++ b/SignGo-app/machineLearning/MLService.ts @@ -330,11 +330,13 @@ class MLService { console.log('Running model inference...'); const outputs = await this.model.run([flatArray]); const resultData = outputs[0]; + const probabilities = resultData instanceof Float32Array ? Array.from(resultData) : Array.from(new Float32Array(resultData.buffer ?? resultData)); // Step 5: Process results (matches Python's predict_gesture) + const sortedIndices = probabilities .map((prob, idx) => ({ prob, idx })) .sort((a, b) => b.prob - a.prob); @@ -386,7 +388,7 @@ class MLService { }; } catch (error) { - console.error('❌ Prediction error:', error); + console.log('❌ Prediction error:', error); throw error; } } From 1979342c0945e5035a77a478a26e2a6bed9d1fef Mon Sep 17 00:00:00 2001 From: PunnawithSut Date: Mon, 16 Feb 2026 21:59:33 +0700 Subject: [PATCH 3/3] fix: async storage temporary fix --- SignGo-app/app/(app)/languageManager.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SignGo-app/app/(app)/languageManager.tsx b/SignGo-app/app/(app)/languageManager.tsx index 0804dc9..04af8d3 100644 --- a/SignGo-app/app/(app)/languageManager.tsx +++ b/SignGo-app/app/(app)/languageManager.tsx @@ -68,7 +68,10 @@ export default function LanguageManager() { styles.actionButton, isSelected ? styles.selectedButton : styles.selectButton ]} - onPress={() => setTargetLanguage(item.code)} + onPress={() => { + setTargetLanguage(item.code); + downloadLanguage(item.code); + }} disabled={isSelected} >