mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-02-22 23:24:36 +01:00
Add proto data store for macros
This commit is contained in:
@@ -15,6 +15,7 @@ buildscript {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE"
|
||||
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40.4"
|
||||
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.18'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
apply from: rootProject.file("library.gradle")
|
||||
apply plugin: 'kotlin-parcelize'
|
||||
apply plugin: 'com.google.protobuf'
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = "com.google.protobuf:protoc:3.14.0"
|
||||
}
|
||||
|
||||
// Generates the java Protobuf-lite code for the Protobufs in this project. See
|
||||
// https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
|
||||
// for more information.
|
||||
generateProtoTasks {
|
||||
all().each { task ->
|
||||
task.builtins {
|
||||
java {
|
||||
option 'lite'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":lib_service")
|
||||
@@ -14,6 +35,7 @@ dependencies {
|
||||
implementation libs.nordic.ui.scanner
|
||||
implementation libs.nordic.navigation
|
||||
|
||||
implementation libs.bundles.datastore
|
||||
implementation libs.bundles.compose
|
||||
implementation libs.androidx.core
|
||||
implementation libs.material
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package no.nordicsemi.android.uart.data
|
||||
|
||||
import androidx.datastore.core.Serializer
|
||||
import no.nordicsemi.android.Macro
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
object MacroSerializer : Serializer<Macro> {
|
||||
override val defaultValue: UARTMacro = Macro.getDefaultInstance()
|
||||
|
||||
override suspend fun readFrom(input: InputStream): UARTMacro {
|
||||
try {
|
||||
return Settings.parseFrom(input)
|
||||
} catch (exception: InvalidProtocolBufferException) {
|
||||
throw CorruptionException("Cannot read proto.", exception)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun writeTo(
|
||||
t: UARTMacro,
|
||||
output: OutputStream
|
||||
) = t.writeTo(output)
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package no.nordicsemi.android.uart.data
|
||||
|
||||
fun NewLineChar.parseString(text: String): String {
|
||||
return when (this) {
|
||||
NewLineChar.LF -> text
|
||||
NewLineChar.CR_LF -> text.replace("\n", "\r\n")
|
||||
NewLineChar.CR -> text.replace("\n", "\r")
|
||||
fun String.parseWithNewLineChar(newLineChar: NewLineChar): String {
|
||||
return when (newLineChar) {
|
||||
NewLineChar.LF -> this
|
||||
NewLineChar.CR_LF -> this.replace("\n", "\r\n")
|
||||
NewLineChar.CR -> this.replace("\n", "\r")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package no.nordicsemi.android.uart.data
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.dataStore
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import java.util.prefs.Preferences
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val MACRO_FILE = "macro.proto"
|
||||
|
||||
internal class UARTSharedPrefDataSource @Inject constructor(
|
||||
@ApplicationContext
|
||||
context: Context
|
||||
) {
|
||||
// val Context.dataStore: DataStore<Preferences> by dataStore(fileName = MACRO_FILE, MacroSerializer)
|
||||
//
|
||||
// private val sp = context.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
|
||||
//
|
||||
//// val macros:
|
||||
//
|
||||
// init {
|
||||
//
|
||||
// sp.edit()
|
||||
// }
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import no.nordicsemi.android.ble.ktx.suspend
|
||||
import no.nordicsemi.android.service.BleManagerResult
|
||||
import no.nordicsemi.android.service.ConnectingResult
|
||||
import no.nordicsemi.android.service.ServiceManager
|
||||
import no.nordicsemi.android.uart.data.*
|
||||
import no.nordicsemi.android.uart.data.UARTData
|
||||
import no.nordicsemi.android.uart.data.UARTMacro
|
||||
import no.nordicsemi.android.uart.data.UARTManager
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@@ -48,7 +48,7 @@ class UARTRepository @Inject constructor(
|
||||
}
|
||||
|
||||
fun runMacro(macro: UARTMacro) {
|
||||
manager?.send(macro.command)
|
||||
manager?.send(macro.command.parseWithNewLineChar(macro.newLineChar))
|
||||
}
|
||||
|
||||
private suspend fun UARTManager.start(device: BluetoothDevice) {
|
||||
|
||||
18
profile_uart/src/main/proto/macro.proto
Normal file
18
profile_uart/src/main/proto/macro.proto
Normal file
@@ -0,0 +1,18 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option java_package = "no.nordicsemi.android";
|
||||
option java_multiple_files = true;
|
||||
|
||||
message Macro {
|
||||
string name = 1;
|
||||
enum NewLineType {
|
||||
LF = 0;
|
||||
LF_CR = 1;
|
||||
CR = 2;
|
||||
}
|
||||
NewLineType newLineType = 2;
|
||||
}
|
||||
|
||||
message MacroSettings {
|
||||
string macros = 1;
|
||||
}
|
||||
@@ -37,6 +37,12 @@ dependencyResolutionManagement {
|
||||
alias('androidx-core').to('androidx.core:core-ktx:1.7.0')
|
||||
alias('compose-activity').to('androidx.activity:activity-compose:1.4.0')
|
||||
|
||||
version('datastore', '1.0.0')
|
||||
alias('datastore-core').to('androidx.datastore', 'datastore').versionRef('datastore')
|
||||
alias('datastore-prefs').to('androidx.datastore', 'datastore-preferences').versionRef('datastore')
|
||||
alias('datastore-protobuf').to('com.google.protobuf:protobuf-javalite:3.18.0')
|
||||
bundle('datastore', ['datastore-core', 'datastore-prefs', 'datastore-protobuf'])
|
||||
|
||||
version('compose', '1.1.0')
|
||||
alias('compose-ui').to('androidx.compose.ui', 'ui').versionRef('compose')
|
||||
alias('compose-material').to('androidx.compose.material3:material3:1.0.0-alpha05')
|
||||
|
||||
Reference in New Issue
Block a user