1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-26 20:06:52 +01:00

Moyoung: Send volume level with music info

This commit is contained in:
Arjan Schrijver 2024-09-23 20:59:56 +02:00
parent 504faf6db0
commit 5c7d8c8fa8
2 changed files with 13 additions and 0 deletions

View File

@ -206,6 +206,7 @@ public class MoyoungConstants {
public static final byte ARG_OPERATION_VOLUME_DOWN = 5;
public static final byte ARG_OPERATION_PLAY = 6;
public static final byte ARG_OPERATION_PAUSE = 7;
public static final byte ARG_OPERATION_SEND_CURRENT_VOLUME = 12; // {0x00-0x10}
public static final byte CMD_QUERY_ALARM_CLOCK = 33; // (?) {} -> a list of entries like below
public static final byte CMD_SET_ALARM_CLOCK = 17; // (?) {id, enable ? 1 : 0, repeat, hour, minute, i >> 8, i, repeatMode}, repeatMode is 0(SINGLE), 127(EVERYDAY), or bitmask of 1,2,4,8,16,32,64(SUNDAY-SATURDAY) is 0,1,2, i is ((year << 12) + (month << 8) + day) where year is 2015-based, month and day start at 1 for repeatMode=SINGLE and 0 otherwise, repeat is 0(SINGLE),1(EVERYDAY),2(OTHER)

View File

@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.moyoung;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Handler;
@ -801,6 +802,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
public void onSetMusicInfo(MusicSpec musicSpec) {
try {
TransactionBuilder builder = performInitialized("sendMusicInfo");
byte[] artistBytes = musicSpec.artist.getBytes();
byte[] artistPayload = new byte[artistBytes.length + 1];
artistPayload[0] = 1;
@ -811,6 +813,16 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport {
trackPayload[0] = 0;
System.arraycopy(trackBytes, 0, trackPayload, 1, trackBytes.length);
sendPacket(builder, MoyoungPacketOut.buildPacket(mtu, MoyoungConstants.CMD_SET_MUSIC_INFO, trackPayload));
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
int volumeLevel = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int volumeMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volumeFraction = (float) volumeLevel / volumeMax;
sendPacket(builder, MoyoungPacketOut.buildPacket(mtu, MoyoungConstants.CMD_NOTIFY_PHONE_OPERATION, new byte[]{
MoyoungConstants.ARG_OPERATION_SEND_CURRENT_VOLUME,
(byte) (16 * volumeFraction)
}));
builder.queue(getQueue());
} catch (IOException e) {
LOG.error("Error sending music info: ", e);