File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/commonMain/kotlin/io/rebble/libpebblecommon/services Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ package io.rebble.libpebblecommon.services
2+
3+ import io.rebble.libpebblecommon.ProtocolHandler
4+ import io.rebble.libpebblecommon.packets.PhoneControl
5+ import io.rebble.libpebblecommon.protocolhelpers.PebblePacket
6+ import io.rebble.libpebblecommon.protocolhelpers.ProtocolEndpoint
7+ import kotlinx.coroutines.channels.Channel
8+
9+ class PhoneControlService (private val protocolHandler : ProtocolHandler ) : ProtocolService {
10+ val receivedMessages = Channel <PhoneControl >(Channel .BUFFERED )
11+
12+ init {
13+ protocolHandler.registerReceiveCallback(ProtocolEndpoint .PHONE_CONTROL , this ::receive)
14+ }
15+
16+ suspend fun send (packet : PhoneControl ) {
17+ protocolHandler.send(packet)
18+ }
19+
20+ fun receive (packet : PebblePacket ) {
21+ if (packet !is PhoneControl ) {
22+ throw IllegalStateException (" Received invalid packet type: $packet " )
23+ }
24+
25+ receivedMessages.trySend(packet)
26+ }
27+
28+ }
You can’t perform that action at this time.
0 commit comments