mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Update AsteroidOS support
Fixed a few bugs. 1. Moved from the depreciated Date object for sending over the time 2. Fixed media info sending. (It would crash when info was missing) 3. Fixed notification dismissal (Typo in removal tag from remove->removed) 4. Fixed quite a few warnings that were being brought up. 5. Added more of the supported models for AsteroidOS. There are still a few problems that exist. Screenshotting still doesn't work. I'm just not sure how it works in GB. The AsteroidOS service is still not being detected, even though the AsteroidOSSync application is detecting it just fine.
This commit is contained in:
parent
e62565cc88
commit
4919be9f6d
@ -16,7 +16,8 @@ public class AsteroidOSConstants {
|
||||
"dory", "firefish", "harmony", "inharmony",
|
||||
"narwhal", "ray", "sawfish", "sawshark",
|
||||
"skipjack", "tunny", "mooneye", "swift",
|
||||
"minnow", "sprat", "tetra"
|
||||
"minnow", "sprat", "tetra", "pike", "hoki",
|
||||
"koi", "ayu"
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl;
|
||||
|
||||
/**
|
||||
* An adapter class for the media commands sent by AsteroidOS
|
||||
@ -14,7 +12,7 @@ public class AsteroidOSMediaCommand {
|
||||
public static final byte COMMAND_PAUSE = 0x3;
|
||||
public static final byte COMMAND_VOLUME = 0x4;
|
||||
|
||||
public byte command = 0x0;
|
||||
public byte command;
|
||||
public AsteroidOSMediaCommand(byte value) {
|
||||
command = value;
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Locale;
|
||||
@ -16,7 +14,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
*/
|
||||
public class AsteroidOSNotification {
|
||||
private String packageName = null;
|
||||
private Integer id = null;
|
||||
private Integer id;
|
||||
private String applicationName = null;
|
||||
private String body = null;
|
||||
private String summary = null;
|
||||
@ -65,6 +63,13 @@ public class AsteroidOSNotification {
|
||||
this.vibrationStrength = VibrationStrength.RINGTONE;
|
||||
this.id = (callSpec.name + callSpec.number).hashCode();
|
||||
break;
|
||||
case CallSpec.CALL_OUTGOING:
|
||||
break;
|
||||
case CallSpec.CALL_REJECT:
|
||||
case CallSpec.CALL_ACCEPT:
|
||||
case CallSpec.CALL_END:
|
||||
case CallSpec.CALL_START:
|
||||
case CallSpec.CALL_UNDEFINED:
|
||||
default:
|
||||
this.id = (callSpec.name + callSpec.number).hashCode();
|
||||
this.remove = true;
|
||||
@ -80,15 +85,16 @@ public class AsteroidOSNotification {
|
||||
this.remove = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Converts the notification to a string to be sent to the device
|
||||
*/
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
if (remove) {
|
||||
return "<remove><id>" + this.id + "</id></remove>";
|
||||
return "<removed><id>" + this.id + "</id></removed>";
|
||||
}
|
||||
String retString = new String();
|
||||
String retString = "";
|
||||
retString += "<insert>";
|
||||
if (id != null)
|
||||
retString += "<id>" + id + "</id>";
|
||||
|
@ -1,7 +1,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
@ -14,7 +13,7 @@ public class AsteroidOSWeather {
|
||||
/**
|
||||
* Provides a day's worth of weather
|
||||
*/
|
||||
public class Day {
|
||||
public static class Day {
|
||||
/**
|
||||
* The minimum temp of the day
|
||||
*/
|
||||
@ -30,7 +29,7 @@ public class AsteroidOSWeather {
|
||||
|
||||
/**
|
||||
* Creates a Day from the forecast given
|
||||
* @param forecast
|
||||
* @param forecast A day in the weather forecast
|
||||
*/
|
||||
public Day(WeatherSpec.Daily forecast) {
|
||||
minTemp = forecast.minTemp;
|
||||
@ -40,7 +39,7 @@ public class AsteroidOSWeather {
|
||||
|
||||
/**
|
||||
* Creates a Day from the WeatherSpec given
|
||||
* @param spec
|
||||
* @param spec The weather spec itself
|
||||
*/
|
||||
public Day(WeatherSpec spec) {
|
||||
minTemp = spec.todayMinTemp;
|
||||
@ -56,12 +55,12 @@ public class AsteroidOSWeather {
|
||||
/**
|
||||
* The city name of the weather
|
||||
*/
|
||||
public String cityName = "";
|
||||
public String cityName;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an AsteroidOSWeather from the WeatherSpec given
|
||||
* @param spec
|
||||
* @param spec The WeatherSpec given to the device support class
|
||||
*/
|
||||
public AsteroidOSWeather(WeatherSpec spec) {
|
||||
cityName = spec.location;
|
||||
|
@ -3,20 +3,16 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.asteroidos;
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.asteroidos.AsteroidOSConstants;
|
||||
@ -24,10 +20,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.asteroidos.AsteroidOSMediaCo
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.asteroidos.AsteroidOSNotification;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.asteroidos.AsteroidOSWeather;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
@ -80,7 +73,6 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
super.onCharacteristicChanged(gatt, characteristic);
|
||||
|
||||
UUID characteristicUUID = characteristic.getUuid();
|
||||
byte[] value = characteristic.getValue();
|
||||
|
||||
if (characteristicUUID.equals(AsteroidOSConstants.MEDIA_COMMANDS_CHAR)) {
|
||||
handleMediaCommand(gatt, characteristic);
|
||||
@ -88,7 +80,7 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
LOG.info("Characteristic changed UUID: " + characteristicUUID);
|
||||
LOG.info("Characteristic changed value: " + characteristic.getValue());
|
||||
LOG.info("Characteristic changed value: " + characteristic.getValue().toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -104,9 +96,6 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
batteryInfoProfile.requestBatteryInfo(builder);
|
||||
batteryInfoProfile.enableNotify(builder, true);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
builder.requestMtu(256);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@ -129,14 +118,13 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
@Override
|
||||
public void onSetTime() {
|
||||
GregorianCalendar now = BLETypeConversions.createCalendar();
|
||||
Date nowTime = now.getTime();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
baos.write((byte) nowTime.getYear());
|
||||
baos.write((byte) nowTime.getMonth());
|
||||
baos.write((byte) nowTime.getDay() + 1);
|
||||
baos.write((byte) nowTime.getHours());
|
||||
baos.write((byte) nowTime.getMinutes());
|
||||
baos.write((byte) nowTime.getSeconds());
|
||||
baos.write((byte) now.get(Calendar.YEAR) - 1900);
|
||||
baos.write((byte) now.get(Calendar.MONTH));
|
||||
baos.write((byte) now.get(Calendar.DAY_OF_MONTH));
|
||||
baos.write((byte) now.get(Calendar.HOUR_OF_DAY));
|
||||
baos.write((byte) now.get(Calendar.MINUTE));
|
||||
baos.write((byte) now.get(Calendar.SECOND));
|
||||
TransactionBuilder builder = new TransactionBuilder("set time");
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.TIME_SET_CHAR, baos.toByteArray());
|
||||
builder.queue(getQueue());
|
||||
@ -166,11 +154,40 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||
TransactionBuilder builder = new TransactionBuilder("send music information");
|
||||
// Send title
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_TITLE_CHAR, musicSpec.track.getBytes(StandardCharsets.UTF_8));
|
||||
{
|
||||
byte[] track_bytes;
|
||||
if (musicSpec.track != null)
|
||||
track_bytes = musicSpec.track.getBytes(StandardCharsets.UTF_8);
|
||||
else
|
||||
track_bytes = "\"\"".getBytes(StandardCharsets.UTF_8);
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_TITLE_CHAR, track_bytes);
|
||||
}
|
||||
// Send album
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ALBUM_CHAR, musicSpec.album.getBytes(StandardCharsets.UTF_8));
|
||||
{
|
||||
byte[] album_bytes;
|
||||
if (musicSpec.album != null)
|
||||
album_bytes = musicSpec.album.getBytes(StandardCharsets.UTF_8);
|
||||
else
|
||||
album_bytes = "\"\"".getBytes(StandardCharsets.UTF_8);
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ALBUM_CHAR, album_bytes);
|
||||
}
|
||||
// Send artist
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ARTIST_CHAR, musicSpec.artist.getBytes(StandardCharsets.UTF_8));
|
||||
{
|
||||
byte[] artist_bytes;
|
||||
if (musicSpec.artist != null)
|
||||
artist_bytes = musicSpec.artist.getBytes(StandardCharsets.UTF_8);
|
||||
else
|
||||
artist_bytes = "\"\"".getBytes(StandardCharsets.UTF_8);
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ARTIST_CHAR, artist_bytes);
|
||||
}
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetPhoneVolume(float volume) {
|
||||
TransactionBuilder builder = new TransactionBuilder("send volume information");
|
||||
byte volByte = (byte) Math.round(volume);
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_VOLUME_CHAR, new byte[]{volByte});
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user