diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7153d68..376c919 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,7 +11,7 @@ android { applicationId = "net.mmanningau.speechtokeyboard" minSdk = 28 targetSdk = 36 - versionCode = 4 + versionCode = 5 versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt b/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt index 3f9610a..0f82aca 100644 --- a/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt +++ b/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt @@ -54,46 +54,47 @@ class TestModelActivity : AppCompatActivity(), RecognitionListener { toggleListening() } - private fun connectToPico() { - val usbManager = getSystemService(Context.USB_SERVICE) as UsbManager - - // 1. Find the Device - // (This probes specifically for devices listed in your device_filter.xml) - val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager) - if (availableDrivers.isEmpty()) { - outputText.append("\n> No USB device found.") - return - } - - // Assume the first device found is the Pico - val driver = availableDrivers[0] - val connection = usbManager.openDevice(driver.device) - - if (connection == null) { - outputText.append("\n> Permission denied. Re-plug device?") - return - } - - // 2. Open the Port - // Most Picos use port 0. - usbPort = driver.ports[0] - - try { - usbPort?.open(connection) - // 3. Set Parameters (Must match your Pico's C/Python code!) - // 115200 Baud, 8 Data bits, 1 Stop bit, No Parity - usbPort?.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE) - - outputText.append("\n> USB Connected to Pico!") - } catch (e: Exception) { - outputText.append("\n> USB Error: ${e.message}") - } - } - // Initialize the model in background initModel() } + private fun connectToPico() { + val usbManager = getSystemService(Context.USB_SERVICE) as UsbManager + + // 1. Find the Device + // (This probes specifically for devices listed in your device_filter.xml) + val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager) + if (availableDrivers.isEmpty()) { + outputText.append("\n> No USB device found.") + return + } + + // Assume the first device found is the Pico + val driver = availableDrivers[0] + val connection = usbManager.openDevice(driver.device) + + if (connection == null) { + outputText.append("\n> Permission denied. Re-plug device?") + return + } + + // 2. Open the Port + // Most Picos use port 0. + usbPort = driver.ports[0] + + try { + usbPort?.open(connection) + // 3. Set Parameters (Must match your Pico's C/Python code!) + // 115200 Baud, 8 Data bits, 1 Stop bit, No Parity + usbPort?.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE) + + outputText.append("\n> USB Connected to Pico!") + } catch (e: Exception) { + outputText.append("\n> USB Error: ${e.message}") + } + } + + private fun initModel() { // We look for the folder inside private storage (same logic as MainActivity) val modelPath = File(filesDir, "vosk-model")