1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 10:56:50 +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:
Noodlez 2023-01-03 11:49:41 -08:00 committed by Gitea
parent f7395ec6b2
commit d3d4baedea
4 changed files with 24 additions and 59 deletions

View File

@ -73,13 +73,6 @@ public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
if (candidate.supportsService(AsteroidOSConstants.SERVICE_UUID)) { if (candidate.supportsService(AsteroidOSConstants.SERVICE_UUID)) {
return DeviceType.ASTEROIDOS; 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; return DeviceType.UNKNOWN;
} }
@ -131,7 +124,7 @@ public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
@Override @Override
public boolean supportsFindDevice() { public boolean supportsFindDevice() {
return false; return true;
} }
@Override @Override

View File

@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventNotificationControl;
public class AsteroidOSMediaCommand { public class AsteroidOSMediaCommand {
public static final byte COMMAND_PREVIOUS = 0x0; public static final byte COMMAND_PREVIOUS = 0x0;

View File

@ -4,6 +4,8 @@ import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import java.util.Locale;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
@ -27,17 +29,7 @@ public class AsteroidOSNotification {
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
switch (this) { return name().toLowerCase(Locale.ROOT);
case STRONG:
return "strong";
case NORMAL:
return "normal";
case RINGTONE:
return "ringtone";
case NONE:
return "none";
}
return "";
} }
} }
private VibrationStrength vibrationStrength = VibrationStrength.NORMAL; private VibrationStrength vibrationStrength = VibrationStrength.NORMAL;

View File

@ -135,7 +135,7 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write((byte) nowTime.getYear()); baos.write((byte) nowTime.getYear());
baos.write((byte) nowTime.getMonth()); 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.getHours());
baos.write((byte) nowTime.getMinutes()); baos.write((byte) nowTime.getMinutes());
baos.write((byte) nowTime.getSeconds()); baos.write((byte) nowTime.getSeconds());
@ -176,25 +176,14 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSetMusicInfo(MusicSpec musicSpec) { public void onSetMusicInfo(MusicSpec musicSpec) {
TransactionBuilder builder = new TransactionBuilder("send music information");
// Send title // Send title
{ safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_TITLE_CHAR, musicSpec.track.getBytes(StandardCharsets.UTF_8));
TransactionBuilder builder = new TransactionBuilder("set music title");
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_TITLE_CHAR, musicSpec.track.getBytes(StandardCharsets.UTF_8));
builder.queue(getQueue());
}
// Send album // Send album
{ safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ALBUM_CHAR, musicSpec.album.getBytes(StandardCharsets.UTF_8));
TransactionBuilder builder = new TransactionBuilder("set music album");
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ALBUM_CHAR, musicSpec.album.getBytes(StandardCharsets.UTF_8));
builder.queue(getQueue());
}
// Send artist // Send artist
{ safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ARTIST_CHAR, musicSpec.artist.getBytes(StandardCharsets.UTF_8));
TransactionBuilder builder = new TransactionBuilder("set music artist"); builder.queue(getQueue());
safeWriteToCharacteristic(builder, AsteroidOSConstants.MEDIA_ARTIST_CHAR, musicSpec.artist.getBytes(StandardCharsets.UTF_8));
builder.queue(getQueue());
}
} }
@Override @Override
@ -254,7 +243,10 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onFindDevice(boolean start) { 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 @Override
@ -305,30 +297,17 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
@Override @Override
public void onSendWeather(WeatherSpec weatherSpec) { public void onSendWeather(WeatherSpec weatherSpec) {
AsteroidOSWeather asteroidOSWeather = new AsteroidOSWeather(weatherSpec); AsteroidOSWeather asteroidOSWeather = new AsteroidOSWeather(weatherSpec);
// Send weather city TransactionBuilder builder = new TransactionBuilder("send weather info");
{ // Send city name
TransactionBuilder builder = new TransactionBuilder("send weather city"); safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_CITY_CHAR, asteroidOSWeather.getCityName());
safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_CITY_CHAR, asteroidOSWeather.getCityName()); // Send conditions
builder.queue(getQueue()); safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_IDS_CHAR, asteroidOSWeather.getWeatherConditions());
}
// Send weather conditions
{
TransactionBuilder builder = new TransactionBuilder("send weather conditions");
safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_IDS_CHAR, asteroidOSWeather.getWeatherConditions());
builder.queue(getQueue());
}
// Send min temps // Send min temps
{ safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_MIN_TEMPS_CHAR, asteroidOSWeather.getMinTemps());
TransactionBuilder builder = new TransactionBuilder("send weather min temps");
safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_MIN_TEMPS_CHAR, asteroidOSWeather.getMinTemps());
builder.queue(getQueue());
}
// Send max temps // Send max temps
{ safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_MAX_TEMPS_CHAR, asteroidOSWeather.getMaxTemps());
TransactionBuilder builder = new TransactionBuilder("send weather max temps"); // Flush queue
safeWriteToCharacteristic(builder, AsteroidOSConstants.WEATHER_MAX_TEMPS_CHAR, asteroidOSWeather.getMaxTemps()); builder.queue(getQueue());
builder.queue(getQueue());
}
} }
@Override @Override