mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-05 07:44:20 +01:00
Added EOL unicode for all uart messages.
This commit is contained in:
@@ -141,7 +141,7 @@ private fun MessageItemInput(record: UARTRecord) {
|
||||
horizontalAlignment = Alignment.End
|
||||
) {
|
||||
Text(
|
||||
text = record.text,
|
||||
text = record.text.visualizeNewlines(),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
@@ -182,7 +182,7 @@ private fun MessageItemOutput(record: UARTRecord) {
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
Text(
|
||||
text = record.text,
|
||||
text = record.text.visualizeNewlines(),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onPrimary
|
||||
)
|
||||
@@ -224,4 +224,18 @@ private val datFormatter = SimpleDateFormat("dd MMMM yyyy, HH:mm:ss", Locale.ENG
|
||||
|
||||
private fun UARTRecord.timeToString(): String {
|
||||
return datFormatter.format(timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Visualizes newlines in a string by replacing them with Unicode characters.
|
||||
* - `\n` is replaced with `` (U+240A)
|
||||
* - `\r` is replaced with `␍` (U+240D)
|
||||
* - `\r\n` is replaced with `␍` (U+240A U+240D)
|
||||
*/
|
||||
internal fun String.visualizeNewlines(): String {
|
||||
return this
|
||||
.replace("\r\n", "\u240A\u240D\r")
|
||||
.replace(Regex("(?<!\r)\n"), "\u240A")
|
||||
.replace(Regex("(?<!\u240D)\r(?!\n)"), "\u240D")
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,3 @@ fun String.parseWithNewLineChar(newLineChar: MacroEol): String {
|
||||
MacroEol.CR -> this.replace("\n", "\r")
|
||||
}
|
||||
}
|
||||
|
||||
fun String.toMacroEolUnicodeCharDisplay(newLineChar: MacroEol): String {
|
||||
return when (newLineChar) {
|
||||
MacroEol.CR -> this.replace("\n", "\u240D\r\n")
|
||||
MacroEol.LF -> this + "\u240A"
|
||||
MacroEol.CR_LF -> this.replace("\n", "\u240A\u240D\r")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ internal class UARTManager : ServiceManager {
|
||||
device: String,
|
||||
message: String,
|
||||
maxWriteLength: Int,
|
||||
macroEolUnicodeMessage: String? = null,
|
||||
) {
|
||||
val messageBytes = message.toByteArray()
|
||||
try {
|
||||
@@ -82,7 +81,7 @@ internal class UARTManager : ServiceManager {
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("UARTService").e("Error ${e.message}")
|
||||
} finally {
|
||||
UartRepository.onNewMessageSent(device, macroEolUnicodeMessage ?: message)
|
||||
UartRepository.onNewMessageSent(device, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import no.nordicsemi.android.toolbox.profile.data.uart.MacroEol
|
||||
import no.nordicsemi.android.toolbox.profile.data.uart.UARTConfiguration
|
||||
import no.nordicsemi.android.toolbox.profile.data.uart.UARTMacro
|
||||
import no.nordicsemi.android.toolbox.profile.data.uart.parseWithNewLineChar
|
||||
import no.nordicsemi.android.toolbox.profile.data.uart.toMacroEolUnicodeCharDisplay
|
||||
import no.nordicsemi.android.toolbox.profile.manager.UARTManager
|
||||
|
||||
object UartRepository {
|
||||
@@ -60,7 +59,6 @@ object UartRepository {
|
||||
deviceId,
|
||||
macro.command!!.parseWithNewLineChar(macro.newLineChar),
|
||||
getMaxWriteLength(deviceId),
|
||||
macro.command!!.toMacroEolUnicodeCharDisplay(macro.newLineChar)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -130,7 +128,7 @@ object UartRepository {
|
||||
// Save the new configuration and edited position.
|
||||
val newConfiguration = it.uartViewState.configurations.map { config ->
|
||||
if (config.id == selectedConfiguration.id) {
|
||||
newConfig!!
|
||||
newConfig
|
||||
} else {
|
||||
config
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user