diff --git a/.idea/misc.xml b/.idea/misc.xml index 74dd639..b2c751a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/app/.gitignore b/app/.gitignore index 6de5218..c970f09 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -44,7 +44,7 @@ captures/ # Keystore files (NEVER commit these!) *.jks -*.keystore +# *.keystore *.pem # OS-specific files diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 99a51ec..47994d1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -7,12 +7,22 @@ android { namespace = "net.mmanningau.speechtokeyboard" compileSdk = 36 + signingConfigs { + getByName("debug") { + // This tells Gradle to look for the key in the same folder as this build file + storeFile = file("debug.keystore") + storePassword = "android" + keyAlias = "androiddebugkey" + keyPassword = "android" + } + } + defaultConfig { applicationId = "net.mmanningau.speechtokeyboard" minSdk = 28 targetSdk = 36 - versionCode = 12 - versionName = "1.1" + versionCode = 13 + versionName = "1.1.1" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } @@ -29,6 +39,8 @@ android { applicationIdSuffix = ".streaming" // This changes the app name on your homescreen to "MyApp (Dev)" resValue("string", "app_name", "Speech To Keyboard (Streaming)") + // Explicitly tell the debug build to use the config we defined above + signingConfig = signingConfigs["debug"] } } compileOptions { diff --git a/app/debug.keystore b/app/debug.keystore new file mode 100644 index 0000000..d00f5e7 Binary files /dev/null and b/app/debug.keystore differ diff --git a/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt b/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt index efaaacd..f5fc30a 100644 --- a/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt +++ b/app/src/main/java/net/mmanningau/speechtokeyboard/TestModelActivity.kt @@ -48,6 +48,7 @@ class TestModelActivity : AppCompatActivity() { // USB Components private var usbPort: UsbSerialPort? = null + private val ACTION_USB_PERMISSION = "net.mmanningau.speechtokeyboard.USB_PERMISSION" // Text History private var committedText = "" @@ -260,26 +261,51 @@ class TestModelActivity : AppCompatActivity() { } // ---------------------------------------------------------------- - // 3. USB LOGIC (Unchanged from before) + // REVISED USB LOGIC (With Permission Request) // ---------------------------------------------------------------- private fun connectToPico() { val usbManager = getSystemService(Context.USB_SERVICE) as UsbManager + + // Find the driver val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(usbManager) - if (availableDrivers.isEmpty()) return - - val driver = availableDrivers[0] - val connection = usbManager.openDevice(driver.device) ?: return - - usbPort = driver.ports[0] - try { - usbPort?.open(connection) - usbPort?.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE) - outputText.append("\n> USB Connected") - } catch (e: Exception) { - outputText.append("\n> USB Error: ${e.message}") + if (availableDrivers.isEmpty()) { + outputText.append("\n> No USB Device Found") + return } + val driver = availableDrivers[0] + + // CHECK PERMISSION + if (!usbManager.hasPermission(driver.device)) { + outputText.append("\n> Requesting Permission...") + val pendingIntent = android.app.PendingIntent.getBroadcast( + this, + 0, + android.content.Intent(ACTION_USB_PERMISSION), + android.app.PendingIntent.FLAG_IMMUTABLE + ) + usbManager.requestPermission(driver.device, pendingIntent) + return + } + + // OPEN DEVICE + openUsbDevice(driver, usbManager) } + private fun openUsbDevice(driver: com.hoho.android.usbserial.driver.UsbSerialDriver, manager: UsbManager) { + try { + val connection = manager.openDevice(driver.device) ?: return + usbPort = driver.ports[0] + usbPort?.open(connection) + + // CRITICAL: MATCHING BAUD RATE + // We are sticking with 115200. You MUST update your Pico code to match this. + usbPort?.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE) + + outputText.append("\n> USB Connected (115200)!") + } catch (e: Exception) { + outputText.append("\n> Connection Failed: ${e.message}") + } + } private fun sendToPico(text: String) { if (usbPort == null) return try {