1
+ package io.rebble.libpebblecommon.packets
2
+
3
+ import io.rebble.libpebblecommon.protocolhelpers.PacketRegistry
4
+ import io.rebble.libpebblecommon.protocolhelpers.PebblePacket
5
+ import io.rebble.libpebblecommon.protocolhelpers.ProtocolEndpoint
6
+ import io.rebble.libpebblecommon.structmapper.*
7
+
8
+ open class MusicControl (val message : Message ) : PebblePacket(ProtocolEndpoint .MUSIC_CONTROL ) {
9
+ val command = SUByte (m, message.value)
10
+
11
+ init {
12
+ type = command.get()
13
+ }
14
+
15
+ enum class Message (val value : UByte ) {
16
+ PlayPause (0x01u ),
17
+ Pause (0x02u ),
18
+ Play (0x03u ),
19
+ NextTrack (0x04u ),
20
+ PreviousTrack (0x05u ),
21
+ VolumeUp (0x06u ),
22
+ VolumeDown (0x07u ),
23
+ GetCurrentTrack (0x08u ),
24
+ UpdateCurrentTrack (0x10u ),
25
+ UpdatePlayStateInfo (0x11u ),
26
+ UpdateVolumeInfo (0x12u ),
27
+ UpdatePlayerInfo (0x13u )
28
+ }
29
+
30
+ class UpdateCurrentTrack (
31
+ artist : String = " " ,
32
+ album : String = " " ,
33
+ title : String = " " ,
34
+ trackLength : Int? = null ,
35
+ trackCount : Int? = null ,
36
+ currentTrack : Int? = null
37
+ ) : MusicControl(Message .UpdateCurrentTrack ) {
38
+ val artist = SString (m, artist)
39
+ val album = SString (m, album)
40
+ val title = SString (m, title)
41
+ val trackLength = SOptional (
42
+ m,
43
+ SUInt (StructMapper (), trackLength?.toUInt() ? : 0u , ' <' ),
44
+ trackLength != null
45
+ )
46
+ val trackCount = SOptional (
47
+ m,
48
+ SUInt (StructMapper (), trackCount?.toUInt() ? : 0u , ' <' ),
49
+ trackCount != null
50
+ )
51
+ val currentTrack = SOptional (
52
+ m,
53
+ SUInt (StructMapper (), currentTrack?.toUInt() ? : 0u , ' <' ),
54
+ currentTrack != null
55
+ )
56
+ }
57
+
58
+ class UpdatePlayStateInfo (
59
+ playbackState : PlaybackState = PlaybackState .Unknown ,
60
+ trackPosition : UInt = 0u ,
61
+ playRate : UInt = 0u ,
62
+ shuffle : ShuffleState = ShuffleState .Unknown ,
63
+ repeat : RepeatState = RepeatState .Unknown
64
+ ) : MusicControl(Message .UpdatePlayStateInfo ) {
65
+ val state = SUByte (m, playbackState.value)
66
+ val trackPosition = SUInt (m, trackPosition, ' <' )
67
+ val playRate = SUInt (m, playRate, ' <' )
68
+ val shuffle = SUByte (m, shuffle.value)
69
+ val repeat = SUByte (m, repeat.value)
70
+ }
71
+
72
+ class UpdateVolumeInfo (
73
+ volumePercent : UByte = 0u ,
74
+ ) : MusicControl(Message .UpdateVolumeInfo ) {
75
+ val volumePercent = SUByte (m, volumePercent)
76
+ }
77
+
78
+ class UpdatePlayerInfo (
79
+ pkg : String = " " ,
80
+ name : String = " "
81
+ ) : MusicControl(Message .UpdatePlayerInfo ) {
82
+ val pkg = SString (m, pkg)
83
+ val name = SString (m, name)
84
+ }
85
+
86
+ enum class PlaybackState (val value : UByte ) {
87
+ Paused (0x00u ),
88
+ Playing (0x01u ),
89
+ Rewinding (0x02u ),
90
+ FastForwarding (0x03u ),
91
+ Unknown (0x04u ),
92
+ }
93
+
94
+ enum class ShuffleState (val value : UByte ) {
95
+ Unknown (0x00u ),
96
+ Off (0x01u ),
97
+ On (0x02u ),
98
+ }
99
+
100
+ enum class RepeatState (val value : UByte ) {
101
+ Unknown (0x00u ),
102
+ Off (0x01u ),
103
+ One (0x02u ),
104
+ All (0x03u ),
105
+ }
106
+ }
107
+
108
+ fun musicPacketsRegister () {
109
+ PacketRegistry .register(
110
+ ProtocolEndpoint .MUSIC_CONTROL ,
111
+ MusicControl .Message .PlayPause .value
112
+ ) { MusicControl (MusicControl .Message .PlayPause ) }
113
+
114
+ PacketRegistry .register(
115
+ ProtocolEndpoint .MUSIC_CONTROL ,
116
+ MusicControl .Message .Pause .value
117
+ ) { MusicControl (MusicControl .Message .Pause ) }
118
+
119
+ PacketRegistry .register(
120
+ ProtocolEndpoint .MUSIC_CONTROL ,
121
+ MusicControl .Message .Play .value
122
+ ) { MusicControl (MusicControl .Message .Play ) }
123
+
124
+ PacketRegistry .register(
125
+ ProtocolEndpoint .MUSIC_CONTROL ,
126
+ MusicControl .Message .NextTrack .value
127
+ ) { MusicControl (MusicControl .Message .NextTrack ) }
128
+
129
+ PacketRegistry .register(
130
+ ProtocolEndpoint .MUSIC_CONTROL ,
131
+ MusicControl .Message .PreviousTrack .value
132
+ ) { MusicControl (MusicControl .Message .PreviousTrack ) }
133
+
134
+ PacketRegistry .register(
135
+ ProtocolEndpoint .MUSIC_CONTROL ,
136
+ MusicControl .Message .VolumeUp .value
137
+ ) { MusicControl (MusicControl .Message .VolumeUp ) }
138
+
139
+ PacketRegistry .register(
140
+ ProtocolEndpoint .MUSIC_CONTROL ,
141
+ MusicControl .Message .VolumeDown .value
142
+ ) { MusicControl (MusicControl .Message .VolumeDown ) }
143
+
144
+ PacketRegistry .register(
145
+ ProtocolEndpoint .MUSIC_CONTROL ,
146
+ MusicControl .Message .GetCurrentTrack .value
147
+ ) { MusicControl (MusicControl .Message .GetCurrentTrack ) }
148
+
149
+ PacketRegistry .register(
150
+ ProtocolEndpoint .MUSIC_CONTROL ,
151
+ MusicControl .Message .UpdateCurrentTrack .value
152
+ ) { MusicControl .UpdateCurrentTrack () }
153
+
154
+ PacketRegistry .register(
155
+ ProtocolEndpoint .MUSIC_CONTROL ,
156
+ MusicControl .Message .UpdatePlayStateInfo .value
157
+ ) { MusicControl .UpdatePlayStateInfo () }
158
+
159
+ PacketRegistry .register(
160
+ ProtocolEndpoint .MUSIC_CONTROL ,
161
+ MusicControl .Message .UpdateVolumeInfo .value
162
+ ) { MusicControl .UpdateVolumeInfo () }
163
+
164
+ PacketRegistry .register(
165
+ ProtocolEndpoint .MUSIC_CONTROL ,
166
+ MusicControl .Message .UpdatePlayerInfo .value
167
+ ) { MusicControl .UpdatePlayerInfo () }
168
+ }
0 commit comments