add toast to usb listener
This commit is contained in:
@@ -22,6 +22,8 @@ import com.example.hpostesting.domain.LogFileManager
|
|||||||
import com.example.hpostesting.domain.LogFileManagerImpl
|
import com.example.hpostesting.domain.LogFileManagerImpl
|
||||||
import com.example.hpostesting.domain.SaveRawData
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
import com.example.hpostesting.domain.SaveRawDataTest
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
|
import com.example.hpostesting.presentation.UsbServiceListenerImpl
|
||||||
import com.example.hpostesting.util.PropertyProviderImpl
|
import com.example.hpostesting.util.PropertyProviderImpl
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
@@ -179,4 +181,10 @@ object AppModule {
|
|||||||
fun provideLocalFileDataSource(): LocalFileDataSource {
|
fun provideLocalFileDataSource(): LocalFileDataSource {
|
||||||
return LocalFileDataSourceImpl()
|
return LocalFileDataSourceImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideUsbServiceListener(): UsbServiceListener {
|
||||||
|
return UsbServiceListenerImpl()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.example.hpostesting.presentation
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
|
|
||||||
|
class UsbServiceListenerImpl(private val context: Context): UsbServiceListener {
|
||||||
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
|
if (data != null) {
|
||||||
|
val receivedData = String(data)
|
||||||
|
logData(receivedData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUsbError(e: Exception?) {
|
||||||
|
showToast("USB Error: ${e?.message}")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showToast(message: String) {
|
||||||
|
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun logData(data: String) {
|
||||||
|
Log.d("UsbServiceListener", "Received data from USB: $data")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user