mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +01:00
AsteroidOS: Small code improvements
Removed logging in the DeviceCoordinator, fixed the time setting (day was off by 1), consolodated many characteristic transactions to one buidler and queue, and added Find My Device, by just initiating a call.
This commit is contained in:
parent
f7395ec6b2
commit
d3d4baedea
@ -73,13 +73,6 @@ public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
|
||||
if (candidate.supportsService(AsteroidOSConstants.SERVICE_UUID)) {
|
||||
return DeviceType.ASTEROIDOS;
|
||||
}
|
||||
{
|
||||
LOG.debug("Name: " + candidate.getName());
|
||||
LOG.debug("Num services: " + candidate.getServiceUuids().length);
|
||||
for (ParcelUuid uuid : candidate.getServiceUuids()) {
|
||||
LOG.debug("Service UUID: " + uuid.toString());
|
||||
}
|
||||
}
|
||||
return DeviceType.UNKNOWN;
|
||||
}
|
||||
|
||||
@ -131,7 +124,7 @@ public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
|
||||
|
||||
@Override
|
||||
public boolean supportsFindDevice() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl;
|
||||
|
||||
public class AsteroidOSMediaCommand {
|
||||
public static final byte COMMAND_PREVIOUS = 0x0;
|
||||
|
@ -4,6 +4,8 @@ import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
@ -27,17 +29,7 @@ public class AsteroidOSNotification {
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (this) {
|
||||
case STRONG:
|
||||
return "strong";
|
||||
case NORMAL:
|
||||
return "normal";
|
||||
case RINGTONE:
|
||||
return "ringtone";
|
||||
case NONE:
|
||||
return "none";
|
||||
}
|
||||
return "";
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
private VibrationStrength vibrationStrength = VibrationStrength.NORMAL;
|
||||
|
@ -135,7 +135,7 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
baos.write((byte) nowTime.getYear());
|
||||
baos.write((byte) nowTime.getMonth());
|
||||
baos.write((byte) nowTime.getDay());
|
||||
baos.write((byte) nowTime.getDay() + 1);
|
||||
baos.write((byte) nowTime.getHours());
|
||||
baos.write((byte) nowTime.getMinutes());
|
||||
baos.write((byte) nowTime.getSeconds());
|
||||
@ -176,27 +176,16 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onSetMusicInfo(MusicSpec musicSpec) {
|
||||
TransactionBuilder builder = new TransactionBuilder("send music information");
|
||||
// Send title
|
||||
{
|
||||
TransactionBuilder builder = new TransactionBuilder("set music title");
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_TITLE_CHAR, musicSpec.track.getBytes(StandardCharsets.UTF_8));
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
// Send album
|
||||
{
|
||||
TransactionBuilder builder = new TransactionBuilder("set music album");
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ALBUM_CHAR, musicSpec.album.getBytes(StandardCharsets.UTF_8));
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
// Send artist
|
||||
{
|
||||
TransactionBuilder builder = new TransactionBuilder("set music artist");
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ARTIST_CHAR, musicSpec.artist.getBytes(StandardCharsets.UTF_8));
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnableRealtimeSteps(boolean enable) {
|
||||
|
||||
@ -254,7 +243,10 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
@Override
|
||||
public void onFindDevice(boolean start) {
|
||||
|
||||
final CallSpec callSpec = new CallSpec();
|
||||
callSpec.command = start ? CallSpec.CALL_INCOMING : CallSpec.CALL_END;
|
||||
callSpec.name = "Gadgetbridge";
|
||||
onSetCallState(callSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -305,31 +297,18 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
@Override
|
||||
public void onSendWeather(WeatherSpec weatherSpec) {
|
||||
AsteroidOSWeather asteroidOSWeather = new AsteroidOSWeather(weatherSpec);
|
||||
// Send weather city
|
||||
{
|
||||
TransactionBuilder builder = new TransactionBuilder("send weather city");
|
||||
TransactionBuilder builder = new TransactionBuilder("send weather info");
|
||||
// Send city name
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_CITY_CHAR, asteroidOSWeather.getCityName());
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
// Send weather conditions
|
||||
{
|
||||
TransactionBuilder builder = new TransactionBuilder("send weather conditions");
|
||||
// Send conditions
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_IDS_CHAR, asteroidOSWeather.getWeatherConditions());
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
// Send min temps
|
||||
{
|
||||
TransactionBuilder builder = new TransactionBuilder("send weather min temps");
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_MIN_TEMPS_CHAR, asteroidOSWeather.getMinTemps());
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
// Send max temps
|
||||
{
|
||||
TransactionBuilder builder = new TransactionBuilder("send weather max temps");
|
||||
safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_MAX_TEMPS_CHAR, asteroidOSWeather.getMaxTemps());
|
||||
// Flush queue
|
||||
builder.queue(getQueue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAutoConnect() {
|
||||
|
Loading…
Reference in New Issue
Block a user