mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-02-16 12:26:47 +01:00
Fix music control. Now everytime the track changes the correct title is displayed. Set limits for volume up and down. Set a initial value of 50% at connect...
This commit is contained in:
parent
c2d608b0ef
commit
0a37b8ef87
@ -64,8 +64,9 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
private final int maxMsgLength = 20;
|
private final int maxMsgLength = 20;
|
||||||
private boolean callIncoming = false;
|
private boolean callIncoming = false;
|
||||||
private String songtitle = null;
|
private String songtitle = null;
|
||||||
|
private byte musicState = -1;
|
||||||
public byte[] music = null;
|
public byte[] music = null;
|
||||||
public byte volume = 90;
|
public byte volume = 50;
|
||||||
|
|
||||||
public BluetoothGattCharacteristic notifyCharacteristic = null;
|
public BluetoothGattCharacteristic notifyCharacteristic = null;
|
||||||
public BluetoothGattCharacteristic writeCharacteristic = null;
|
public BluetoothGattCharacteristic writeCharacteristic = null;
|
||||||
@ -104,6 +105,15 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
requestActivityInfo(builder);
|
requestActivityInfo(builder);
|
||||||
synchronizeTime(builder);
|
synchronizeTime(builder);
|
||||||
|
|
||||||
|
replyMsgToWatch(builder, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
|
||||||
|
ZeTimeConstants.CMD_MUSIC_CONTROL,
|
||||||
|
ZeTimeConstants.CMD_REQUEST_RESPOND,
|
||||||
|
0x02,
|
||||||
|
0x00,
|
||||||
|
0x02,
|
||||||
|
volume,
|
||||||
|
ZeTimeConstants.CMD_END});
|
||||||
|
|
||||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||||
LOG.info("Initialization Done");
|
LOG.info("Initialization Done");
|
||||||
return builder;
|
return builder;
|
||||||
@ -162,21 +172,24 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
@Override
|
@Override
|
||||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||||
songtitle = musicSpec.track;
|
songtitle = musicSpec.track;
|
||||||
if (music != null) {
|
if(musicState != -1) {
|
||||||
try {
|
music = new byte[songtitle.getBytes(StandardCharsets.UTF_8).length + 7]; // 7 bytes for status and overhead
|
||||||
byte [] musicT = new byte[songtitle.getBytes(StandardCharsets.UTF_8).length + 7]; // 7 bytes for status and overhead
|
music[0] = ZeTimeConstants.CMD_PREAMBLE;
|
||||||
System.arraycopy(music, 0, musicT, 0, 6);
|
music[1] = ZeTimeConstants.CMD_MUSIC_CONTROL;
|
||||||
System.arraycopy(songtitle.getBytes(StandardCharsets.UTF_8), 0, musicT, 6, songtitle.getBytes(StandardCharsets.UTF_8).length);
|
music[2] = ZeTimeConstants.CMD_REQUEST_RESPOND;
|
||||||
musicT[musicT.length - 1] = ZeTimeConstants.CMD_END;
|
music[3] = (byte) ((songtitle.getBytes(StandardCharsets.UTF_8).length + 1) & 0xff);
|
||||||
musicT[3] = (byte) ((songtitle.getBytes(StandardCharsets.UTF_8).length + 1) & 0xff);
|
music[4] = (byte) ((songtitle.getBytes(StandardCharsets.UTF_8).length + 1) >> 8);
|
||||||
musicT[4] = (byte) ((songtitle.getBytes(StandardCharsets.UTF_8).length + 1) >> 8);
|
music[5] = musicState;
|
||||||
TransactionBuilder builder = performInitialized("setMusicInfo");
|
System.arraycopy(songtitle.getBytes(StandardCharsets.UTF_8), 0, music, 6, songtitle.getBytes(StandardCharsets.UTF_8).length);
|
||||||
replyMsgToWatch(builder, music);
|
music[music.length - 1] = ZeTimeConstants.CMD_END;
|
||||||
musicT[2] = ZeTimeConstants.CMD_SEND;
|
if (music != null) {
|
||||||
sendMsgToWatch(builder, music);
|
try {
|
||||||
performConnected(builder.getTransaction());
|
TransactionBuilder builder = performInitialized("setMusicStateInfo");
|
||||||
} catch (IOException e) {
|
replyMsgToWatch(builder, music);
|
||||||
GB.toast(getContext(), "Error setting music info: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
performConnected(builder.getTransaction());
|
||||||
|
} catch (IOException e) {
|
||||||
|
GB.toast(getContext(), "Error setting music state and info: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,6 +310,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetMusicState(MusicStateSpec stateSpec) {
|
public void onSetMusicState(MusicStateSpec stateSpec) {
|
||||||
|
musicState = stateSpec.state;
|
||||||
if(songtitle != null) {
|
if(songtitle != null) {
|
||||||
music = new byte[songtitle.getBytes(StandardCharsets.UTF_8).length + 7]; // 7 bytes for status and overhead
|
music = new byte[songtitle.getBytes(StandardCharsets.UTF_8).length + 7]; // 7 bytes for status and overhead
|
||||||
music[0] = ZeTimeConstants.CMD_PREAMBLE;
|
music[0] = ZeTimeConstants.CMD_PREAMBLE;
|
||||||
@ -1113,7 +1127,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
case 4: // change volume
|
case 4: // change volume
|
||||||
if (musicControlMsg[6] > volume) {
|
if (musicControlMsg[6] > volume) {
|
||||||
musicCmd.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
|
musicCmd.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
|
||||||
if(volume < 170) {
|
if(volume < 90) {
|
||||||
volume += 10;
|
volume += 10;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user