Auto-Commit: 2026-08-18 20:54:11
This commit is contained in:
1 parent
b304344278
commit
176608d8b7
17 files changed
+123
-51
No files matched your search
@@ -3,13 +3,31 @@ package expo.modules.usbcamera
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
import expo.modules.kotlin.Promise
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
|
||||
class UsbCameraModule : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("UsbCamera")
|
||||
|
||||
AsyncFunction("getLogcat") { promise: Promise ->
|
||||
try {
|
||||
val process = Runtime.getRuntime().exec("logcat -d -v time -s UsbCameraView CameraClient")
|
||||
val bufferedReader = BufferedReader(InputStreamReader(process.inputStream))
|
||||
val log = java.lang.StringBuilder()
|
||||
var line: String? = bufferedReader.readLine()
|
||||
while (line != null) {
|
||||
log.append(line).append("\n")
|
||||
line = bufferedReader.readLine()
|
||||
}
|
||||
promise.resolve(log.toString())
|
||||
} catch (e: Exception) {
|
||||
promise.resolve("Error reading logcat: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
View(UsbCameraView::class) {
|
||||
Events("onCameraReady")
|
||||
Events("onCameraReady", "onCameraError", "onCameraState")
|
||||
|
||||
AsyncFunction("takePicture") { view: UsbCameraView, savePath: String, promise: Promise ->
|
||||
view.takePicture(savePath, promise)
|
||||
|
||||
@@ -12,9 +12,15 @@ import expo.modules.kotlin.views.ExpoView
|
||||
import expo.modules.kotlin.AppContext
|
||||
import expo.modules.kotlin.Promise
|
||||
|
||||
import expo.modules.kotlin.viewevent.EventDispatcher
|
||||
|
||||
class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context, appContext) {
|
||||
private val textureView: AspectRatioTextureView
|
||||
private var cameraClient: CameraClient? = null
|
||||
|
||||
private val onCameraReady by EventDispatcher()
|
||||
private val onCameraError by EventDispatcher()
|
||||
private val onCameraState by EventDispatcher()
|
||||
|
||||
init {
|
||||
textureView = AspectRatioTextureView(context)
|
||||
@@ -89,8 +95,13 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
|
||||
private fun startPreview() {
|
||||
try {
|
||||
cameraClient?.openCamera(textureView)
|
||||
onCameraReady(mapOf("status" to "ready"))
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
appContext.currentActivity?.runOnUiThread {
|
||||
android.util.Log.e("UsbCameraView", "startPreview error: ${e.message}")
|
||||
onCameraError(mapOf("error" to (e.message ?: "Unknown error")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import { requireNativeViewManager } from 'expo-modules-core';
|
||||
import { requireNativeViewManager, requireNativeModule } from 'expo-modules-core';
|
||||
import * as React from 'react';
|
||||
import { ViewProps, Platform } from 'react-native';
|
||||
|
||||
const viewName = 'UsbCamera';
|
||||
export const UsbCamera = requireNativeModule('UsbCamera');
|
||||
|
||||
export async function getUsbCameraLogcat(): Promise<string> {
|
||||
if (UsbCamera && UsbCamera.getLogcat) {
|
||||
return await UsbCamera.getLogcat();
|
||||
}
|
||||
return 'Not supported';
|
||||
}
|
||||
|
||||
export interface UsbCameraViewProps extends ViewProps {
|
||||
// Add props here if we decide to pass them from JS
|
||||
|
||||
Reference in new issue
Block a user