Correct discarding for invalid messages and small fixes

This commit is contained in:
2024-03-19 19:14:51 +07:00
parent 0557622dc3
commit 682af406f5
5 changed files with 17 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ import com.helible.pilot.components.deviceScreen.DeviceControlScreen
import com.helible.pilot.components.deviceScreen.defaultDeviceActionsList
import com.helible.pilot.components.PidSettingsPage
import com.helible.pilot.components.scannerScreen.ScannerScreen
import com.helible.pilot.dataclasses.DeviceStatus
import com.helible.pilot.permissions.PermissionsLauncher
import com.helible.pilot.permissions.PermissionsRequest
import com.helible.pilot.permissions.RequestHardwareFeatures

View File

@@ -1,5 +1,6 @@
package com.helible.pilot.components
import android.content.res.Configuration
import android.widget.Spinner
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@@ -70,7 +71,7 @@ fun CalibrationPage(
}
}
@Preview
@Preview(showSystemUi = true)
@Composable
fun CalibrationPagePreview() {
Surface {

View File

@@ -27,6 +27,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.helible.pilot.R
import com.helible.pilot.dataclasses.BluetoothUiState
import com.helible.pilot.dataclasses.DeviceState
import com.helible.pilot.dataclasses.DeviceStatus
import com.helible.pilot.viewmodels.AppPreferences
@@ -103,7 +104,14 @@ fun DeviceBadge(
@Composable
fun DeviceBadgePreview() {
DeviceBadge(
bluetoothUiState = BluetoothUiState(isConnected = true),
bluetoothUiState = BluetoothUiState(
isConnected = false,
isConnecting = true,
deviceState = DeviceState(
status = DeviceStatus.Idle,
batteryCharge = 50,
)
),
tryToReconnect = {},
getPreferences = { AppPreferences("Helicopter", "AA:BB:CC:FF:DD") }
)

View File

@@ -22,7 +22,6 @@ class BluetoothDataTransferService(
return flow {
if (!socket.isConnected)
return@flow
val buffer = BufferedInputStream(socket.inputStream, maxPackageSize)
while (true) {
val message: String = try {
@@ -39,9 +38,11 @@ class BluetoothDataTransferService(
emit(GeneralMessage(messageType, messageData))
}
} catch (e: NoSuchElementException) {
Log.e("BluetoothController", "Message type is invalid: $message")
Log.e("BluetoothController", "Message type is invalid: ${e.message}")
} catch (e: NumberFormatException) {
Log.e("BluetoothController", "Message invalid, may be device buffer congested: $message")
Log.e("BluetoothController", "Message invalid, may be device buffer congested: ${e.message}")
} catch (e: Exception) {
Log.e("BluetoothController", "Unknown error: ${e.message}")
}
}
}.flowOn(Dispatchers.IO)

View File

@@ -2,6 +2,6 @@
<string name="app_name">Digital Pilot</string>
<string name="calibration_description">Расположите устройство на ровной горизонтальной поверхности, чтобы сани вертолета полностью лежали на ней. Нажмите кнопку калибровки ниже и ждите её окончания, не создавая тряски.</string>
<string name="p_pid_value_description">Сначала подберите значение коэффицента P, которое балансирует между слишком низкой и слишком высокой чувствительностью.</string>
<string name="i_pid_value_description">Затем подберите значение коэффицента I, которое уберёт нежелательный дрейв, но не повлияет на отзывчивость.</string>
<string name="i_pid_value_description">Затем подберите значение коэффицента I, которое уберёт нежелательный дрейф, но не повлияет на отзывчивость.</string>
<string name="d_pid_value_description">После установите значение коэффицента D таким образом, чтобы обеспечить более стабильное и плавное управление.</string>
</resources>