Skip to content

Commit adafb60

Browse files
committed
add phone control service
1 parent 80c0cf1 commit adafb60

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)