-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate info to new ble api #1001
Open
makeevrserg
wants to merge
18
commits into
makeevrserg/new-ble-api/dev
Choose a base branch
from
makeevrserg/new-ble-api/info
base: makeevrserg/new-ble-api/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9a4b9d7
add connection service
makeevrserg 8c66441
remove unused deps
makeevrserg 5b7de01
add color, alarm features
makeevrserg d17f514
firmware update
makeevrserg c744b04
fix characteristic collect
makeevrserg 526f49a
add fgattinformation to new api
makeevrserg 0eddf41
migrate info to new api
makeevrserg 8917829
add flipper version check for device color get request
makeevrserg 0b12f2b
split FGattInfoFeatureApi
makeevrserg f801926
save color into settings
makeevrserg 202b8e3
emit initial value
makeevrserg 75bbe17
remove version check for FGattInfo
makeevrserg 77ec9e0
replace rpcapi with getInfoFeatureApi
makeevrserg 1e06a7b
add flipper device color into settings
makeevrserg edfc99d
fix serializer for hardware color
makeevrserg 51515f0
fix serializer for hardware color
makeevrserg dad9fcf
fix hardware color location
makeevrserg b5bd897
fix commit for FGetInfoFeatureApiImpl
makeevrserg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.flipperdevices.bridge.connection.config.api.model | ||
|
||
import com.flipperdevices.bridge.connection.config.api.FDeviceType | ||
import com.flipperdevices.bridge.connection.config.api.serialization.HardwareColorSerializer | ||
import com.flipperdevices.core.preference.pb.FlipperZeroBle | ||
import kotlinx.serialization.Serializable | ||
import java.util.UUID | ||
|
||
|
@@ -9,7 +11,9 @@ data class FDeviceFlipperZeroBleModel( | |
val name: String, | ||
val address: String, | ||
override val uniqueId: String = UUID.randomUUID().toString(), | ||
override val humanReadableName: String = "Flipper $name" | ||
override val humanReadableName: String = "Flipper $name", | ||
@Serializable(HardwareColorSerializer::class) | ||
val hardwareColor: FlipperZeroBle.HardwareColor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be better to add |
||
) : FDeviceBaseModel { | ||
override val type = FDeviceType.FLIPPER_ZERO_BLE | ||
} |
25 changes: 25 additions & 0 deletions
25
.../com/flipperdevices/bridge/connection/config/api/serialization/HardwareColorSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.flipperdevices.bridge.connection.config.api.serialization | ||
|
||
import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
internal object HardwareColorSerializer : KSerializer<HardwareColor> { | ||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( | ||
serialName = "com.flipperdevices.SavedDevice.HardwareColor", | ||
kind = PrimitiveKind.INT | ||
) | ||
|
||
override fun deserialize(decoder: Decoder): HardwareColor { | ||
val intValue = decoder.decodeInt() | ||
return HardwareColor.fromValue(intValue) | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: HardwareColor) { | ||
encoder.encodeInt(value.value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
components/bridge/connection/feature/alarm/api/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
plugins { | ||
id("flipper.multiplatform") | ||
id("flipper.multiplatform-dependencies") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.bridge.connection.feature.alarm.api" | ||
|
||
commonDependencies { | ||
implementation(projects.components.core.data) | ||
implementation(projects.components.core.ktx) | ||
|
||
implementation(projects.components.bridge.connection.feature.common.api) | ||
implementation(projects.components.bridge.connection.transport.common.api) | ||
implementation(projects.components.bridge.connection.feature.rpcinfo.api) | ||
|
||
implementation(libs.kotlin.immutable.collections) | ||
implementation(libs.kotlin.coroutines) | ||
} |
7 changes: 7 additions & 0 deletions
7
...monMain/kotlin/com/flipperdevices/bridge/connection/feature/alarm/api/FAlarmFeatureApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.flipperdevices.bridge.connection.feature.alarm.api | ||
|
||
import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi | ||
|
||
interface FAlarmFeatureApi : FDeviceFeatureApi { | ||
suspend fun makeSound() | ||
} |
25 changes: 25 additions & 0 deletions
25
components/bridge/connection/feature/alarm/impl/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id("flipper.multiplatform") | ||
id("flipper.multiplatform-dependencies") | ||
id("flipper.anvil-multiplatform") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.bridge.connection.feature.alarm.impl" | ||
|
||
commonDependencies { | ||
implementation(projects.components.bridge.connection.feature.alarm.api) | ||
|
||
implementation(projects.components.core.di) | ||
implementation(projects.components.core.log) | ||
implementation(projects.components.core.ktx) | ||
|
||
implementation(projects.components.bridge.connection.feature.common.api) | ||
implementation(projects.components.bridge.connection.transport.common.api) | ||
implementation(projects.components.bridge.connection.feature.rpc.api) | ||
implementation(projects.components.bridge.connection.feature.rpc.model) | ||
implementation(projects.components.bridge.connection.feature.rpcinfo.api) | ||
|
||
implementation(projects.components.bridge.connection.pbutils) | ||
|
||
implementation(libs.kotlin.coroutines) | ||
} |
33 changes: 33 additions & 0 deletions
33
...otlin/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureApiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.flipperdevices.bridge.connection.feature.alarm.impl.api | ||
|
||
import com.flipperdevices.bridge.connection.feature.alarm.api.FAlarmFeatureApi | ||
import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi | ||
import com.flipperdevices.bridge.connection.feature.rpc.model.wrapToRequest | ||
import com.flipperdevices.core.log.LogTagProvider | ||
import com.flipperdevices.protobuf.Main | ||
import com.flipperdevices.protobuf.system.PlayAudiovisualAlertRequest | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
|
||
class FAlarmFeatureApiImpl @AssistedInject constructor( | ||
@Assisted private val rpcFeatureApi: FRpcFeatureApi, | ||
) : FAlarmFeatureApi, | ||
LogTagProvider { | ||
override val TAG = "FAlarmFeatureApi" | ||
|
||
override suspend fun makeSound() { | ||
rpcFeatureApi.requestWithoutAnswer( | ||
Main( | ||
system_play_audiovisual_alert_request = PlayAudiovisualAlertRequest() | ||
).wrapToRequest() | ||
) | ||
} | ||
|
||
@AssistedFactory | ||
fun interface InternalFactory { | ||
operator fun invoke( | ||
rpcFeatureApi: FRpcFeatureApi, | ||
): FAlarmFeatureApiImpl | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...n/com/flipperdevices/bridge/connection/feature/alarm/impl/api/FAlarmFeatureFactoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.flipperdevices.bridge.connection.feature.alarm.impl.api | ||
|
||
import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeature | ||
import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi | ||
import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureQualifier | ||
import com.flipperdevices.bridge.connection.feature.common.api.FUnsafeDeviceFeatureApi | ||
import com.flipperdevices.bridge.connection.feature.rpc.api.FRpcFeatureApi | ||
import com.flipperdevices.bridge.connection.transport.common.api.FConnectedDeviceApi | ||
import com.flipperdevices.core.di.AppGraph | ||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import kotlinx.coroutines.CoroutineScope | ||
import javax.inject.Inject | ||
|
||
@FDeviceFeatureQualifier(FDeviceFeature.ALARM) | ||
@ContributesMultibinding(AppGraph::class, FDeviceFeatureApi.Factory::class) | ||
class FAlarmFeatureFactoryImpl @Inject constructor( | ||
private val factory: FAlarmFeatureApiImpl.InternalFactory | ||
) : FDeviceFeatureApi.Factory { | ||
override suspend fun invoke( | ||
unsafeFeatureDeviceApi: FUnsafeDeviceFeatureApi, | ||
scope: CoroutineScope, | ||
connectedDevice: FConnectedDeviceApi | ||
): FDeviceFeatureApi? { | ||
val rpcApi = unsafeFeatureDeviceApi.getUnsafe(FRpcFeatureApi::class) ?: return null | ||
return factory( | ||
rpcFeatureApi = rpcApi, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
components/bridge/connection/feature/device-color/api/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
id("flipper.multiplatform") | ||
id("flipper.multiplatform-dependencies") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.bridge.connection.feature.devicecolor.api" | ||
|
||
commonDependencies { | ||
implementation(projects.components.core.data) | ||
implementation(projects.components.core.ktx) | ||
implementation(projects.components.core.preference) | ||
|
||
implementation(projects.components.bridge.connection.feature.common.api) | ||
implementation(projects.components.bridge.connection.transport.common.api) | ||
implementation(projects.components.bridge.connection.feature.rpcinfo.api) | ||
|
||
implementation(libs.kotlin.immutable.collections) | ||
implementation(libs.kotlin.coroutines) | ||
} |
13 changes: 13 additions & 0 deletions
13
...in/com/flipperdevices/bridge/connection/feature/devicecolor/api/FDeviceColorFeatureApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.flipperdevices.bridge.connection.feature.devicecolor.api | ||
|
||
import com.flipperdevices.bridge.connection.feature.common.api.FDeviceFeatureApi | ||
import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface FDeviceColorFeatureApi : FDeviceFeatureApi { | ||
/** | ||
* Receive color from flipper and save it into settings | ||
* @param default default value on response failure | ||
*/ | ||
fun updateAndGetColorFlow(default: HardwareColor = HardwareColor.WHITE): Flow<HardwareColor> | ||
} |
26 changes: 26 additions & 0 deletions
26
components/bridge/connection/feature/device-color/impl/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
id("flipper.multiplatform") | ||
id("flipper.multiplatform-dependencies") | ||
id("flipper.anvil-multiplatform") | ||
} | ||
|
||
android.namespace = "com.flipperdevices.bridge.connection.feature.devicecolor.impl" | ||
|
||
commonDependencies { | ||
implementation(projects.components.bridge.connection.feature.deviceColor.api) | ||
|
||
implementation(projects.components.core.di) | ||
implementation(projects.components.core.log) | ||
implementation(projects.components.core.ktx) | ||
implementation(projects.components.core.preference) | ||
implementation(projects.components.core.data) | ||
|
||
implementation(projects.components.bridge.connection.feature.common.api) | ||
implementation(projects.components.bridge.connection.transport.common.api) | ||
implementation(projects.components.bridge.connection.feature.getinfo.api) | ||
implementation(projects.components.bridge.connection.config.api) | ||
|
||
implementation(projects.components.bridge.connection.pbutils) | ||
|
||
implementation(libs.kotlin.coroutines) | ||
} |
56 changes: 56 additions & 0 deletions
56
...ipperdevices/bridge/connection/feature/devicecolor/impl/api/FDeviceColorFeatureApiImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.flipperdevices.bridge.connection.feature.devicecolor.impl.api | ||
|
||
import com.flipperdevices.bridge.connection.config.api.FDevicePersistedStorage | ||
import com.flipperdevices.bridge.connection.config.api.model.FDeviceFlipperZeroBleModel | ||
import com.flipperdevices.bridge.connection.feature.devicecolor.api.FDeviceColorFeatureApi | ||
import com.flipperdevices.bridge.connection.feature.getinfo.api.FGetInfoFeatureApi | ||
import com.flipperdevices.bridge.connection.feature.getinfo.model.FGetInfoApiProperty | ||
import com.flipperdevices.core.log.LogTagProvider | ||
import com.flipperdevices.core.log.error | ||
import com.flipperdevices.core.preference.pb.FlipperZeroBle.HardwareColor | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.flow | ||
|
||
class FDeviceColorFeatureApiImpl @AssistedInject constructor( | ||
@Assisted private val fGetInfoFeatureApi: FGetInfoFeatureApi, | ||
private val fDevicePersistedStorage: FDevicePersistedStorage | ||
) : FDeviceColorFeatureApi, | ||
LogTagProvider { | ||
override val TAG = "FDeviceColorFeatureApi" | ||
|
||
override fun updateAndGetColorFlow(default: HardwareColor): Flow<HardwareColor> = flow { | ||
val currentColoredDevice = fDevicePersistedStorage | ||
.getCurrentDevice() | ||
.first() as? FDeviceFlipperZeroBleModel | ||
if (currentColoredDevice != null) { | ||
emit(currentColoredDevice.hardwareColor) | ||
} | ||
|
||
val intHardwareColor = fGetInfoFeatureApi.get(FGetInfoApiProperty.DeviceInfo.HARDWARE_COLOR) | ||
.onFailure { error( | ||
it | ||
) { "#updateAndGetColorFlow could not fetch ${FGetInfoApiProperty.DeviceInfo.HARDWARE_COLOR}" } } | ||
.map { it.toIntOrNull() } | ||
.getOrNull() | ||
|
||
val hardwareColor = when (intHardwareColor) { | ||
HardwareColor.WHITE.value -> HardwareColor.WHITE | ||
HardwareColor.BLACK.value -> HardwareColor.BLACK | ||
HardwareColor.TRANSPARENT.value -> HardwareColor.TRANSPARENT | ||
else -> default | ||
} | ||
fDevicePersistedStorage.setCurrentDeviceColor(hardwareColor) | ||
emit(hardwareColor) | ||
} | ||
|
||
@AssistedFactory | ||
fun interface InternalFactory { | ||
operator fun invoke( | ||
fGetInfoFeatureApi: FGetInfoFeatureApi, | ||
): FDeviceColorFeatureApiImpl | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not
setDeviceColor(id: String, hardwareColor: HardwareColor)
because we can't get color when not connected to device