mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-03-13 17:50:23 +01:00
Code clean-up and documentation
This commit is contained in:
parent
8f5997d174
commit
ead7ada987
@ -2,9 +2,13 @@ package nodomain.freeyourgadget.gadgetbridge.devices.asteroidos;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A class to hold all the constants needed by the AsteroidOS devices
|
||||
*/
|
||||
public class AsteroidOSConstants {
|
||||
|
||||
// A list of all the supported devices and their codenames
|
||||
/**
|
||||
* A list of all the supported devices and their codenames
|
||||
*/
|
||||
public static final String[] SUPPORTED_DEVICE_CODENAMES = {
|
||||
"bass", "sturgeon", "catfish", "catfish_ext",
|
||||
"catshark", "lenok", "smelt", "carp",
|
||||
@ -15,40 +19,102 @@ public class AsteroidOSConstants {
|
||||
"minnow", "sprat", "tetra"
|
||||
};
|
||||
|
||||
// AsteroidOS Service Watch Filter UUID
|
||||
/**
|
||||
* AsteroidOS Service Watch Filter UUID
|
||||
*/
|
||||
public static final UUID SERVICE_UUID = UUID.fromString("00000000-0000-0000-0000-00A57E401D05");
|
||||
|
||||
// Battery level
|
||||
/**
|
||||
* Battery level service
|
||||
*/
|
||||
public static final UUID BATTERY_SERVICE_UUID = UUID.fromString("0000180F-0000-1000-8000-00805F9B34FB");
|
||||
/**
|
||||
* Battery level characteristic
|
||||
*/
|
||||
public static final UUID BATTERY_UUID = UUID.fromString("00002A19-0000-1000-8000-00805F9B34FB");
|
||||
|
||||
// Time
|
||||
/**
|
||||
* Time service
|
||||
*/
|
||||
public static final UUID TIME_SERVICE_UUID = UUID.fromString("00005071-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Time characteristic
|
||||
*/
|
||||
public static final UUID TIME_SET_CHAR = UUID.fromString("00005001-0000-0000-0000-00A57E401D05");
|
||||
|
||||
// ScreenshotService
|
||||
/**
|
||||
* Screenshot service
|
||||
*/
|
||||
public static final UUID SCREENSHOT_SERVICE_UUID = UUID.fromString("00006071-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Screenshot request characteristic
|
||||
*/
|
||||
public static final UUID SCREENSHOT_REQUEST = UUID.fromString("00006001-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Screenshot content characteristic
|
||||
*/
|
||||
public static final UUID SCREENSHOT_CONTENT = UUID.fromString("00006002-0000-0000-0000-00A57E401D05");
|
||||
|
||||
// MediaService
|
||||
/**
|
||||
* Media service
|
||||
*/
|
||||
public static final UUID MEDIA_SERVICE_UUID = UUID.fromString("00007071-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Media title characteristic
|
||||
*/
|
||||
public static final UUID MEDIA_TITLE_CHAR = UUID.fromString("00007001-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Media album characteristic
|
||||
*/
|
||||
public static final UUID MEDIA_ALBUM_CHAR = UUID.fromString("00007002-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Media artist characteristic
|
||||
*/
|
||||
public static final UUID MEDIA_ARTIST_CHAR = UUID.fromString("00007003-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Media playing status characteristic
|
||||
*/
|
||||
public static final UUID MEDIA_PLAYING_CHAR = UUID.fromString("00007004-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Media command characteristic
|
||||
*/
|
||||
public static final UUID MEDIA_COMMANDS_CHAR = UUID.fromString("00007005-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Media volume characteristic
|
||||
*/
|
||||
public static final UUID MEDIA_VOLUME_CHAR = UUID.fromString("00007006-0000-0000-0000-00A57E401D05");
|
||||
|
||||
// WeatherService
|
||||
/**
|
||||
* Weather service
|
||||
*/
|
||||
public static final UUID WEATHER_SERVICE_UUID = UUID.fromString("00008071-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Weather city name characteristic
|
||||
*/
|
||||
public static final UUID WEATHER_CITY_CHAR = UUID.fromString("00008001-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Weather condition codes characteristic
|
||||
*/
|
||||
public static final UUID WEATHER_IDS_CHAR = UUID.fromString("00008002-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Weather minimum temps characteristic
|
||||
*/
|
||||
public static final UUID WEATHER_MIN_TEMPS_CHAR = UUID.fromString("00008003-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Weather maximum temps characteristic
|
||||
*/
|
||||
public static final UUID WEATHER_MAX_TEMPS_CHAR = UUID.fromString("00008004-0000-0000-0000-00A57E401D05");
|
||||
|
||||
// Notification Service
|
||||
/**
|
||||
* Notification service
|
||||
*/
|
||||
public static final UUID NOTIFICATION_SERVICE_UUID = UUID.fromString("00009071-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Notification update characteristic
|
||||
*/
|
||||
public static final UUID NOTIFICATION_UPDATE_CHAR = UUID.fromString("00009001-0000-0000-0000-00A57E401D05");
|
||||
/**
|
||||
* Notification feedback characteristic
|
||||
*/
|
||||
public static final UUID NOTIFICATION_FEEDBACK_CHAR = UUID.fromString("00009002-0000-0000-0000-00A57E401D05");
|
||||
}
|
||||
|
@ -156,6 +156,4 @@ public class AsteroidOSDeviceCoordinator extends AbstractDeviceCoordinator {
|
||||
public boolean supportsMusicInfo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ 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
|
||||
*/
|
||||
public class AsteroidOSMediaCommand {
|
||||
public static final byte COMMAND_PREVIOUS = 0x0;
|
||||
public static final byte COMMAND_NEXT = 0x1;
|
||||
@ -16,6 +19,10 @@ public class AsteroidOSMediaCommand {
|
||||
command = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the MediaCommand to a music control event
|
||||
* @return the matching music control event
|
||||
*/
|
||||
public GBDeviceEventMusicControl toMusicControlEvent() {
|
||||
GBDeviceEventMusicControl event = new GBDeviceEventMusicControl();
|
||||
switch (command) {
|
||||
@ -34,9 +41,7 @@ public class AsteroidOSMediaCommand {
|
||||
case COMMAND_VOLUME:
|
||||
default:
|
||||
event.event = GBDeviceEventMusicControl.Event.UNKNOWN;
|
||||
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
|
||||
/**
|
||||
* An adapter for notifications on AsteroidOS
|
||||
*/
|
||||
public class AsteroidOSNotification {
|
||||
private String packageName = null;
|
||||
private Integer id = null;
|
||||
@ -20,6 +23,9 @@ public class AsteroidOSNotification {
|
||||
private String icon = null;
|
||||
private Boolean remove = false;
|
||||
|
||||
/**
|
||||
* The vibration strength of a notification
|
||||
*/
|
||||
public enum VibrationStrength {
|
||||
STRONG,
|
||||
NORMAL,
|
||||
@ -33,6 +39,11 @@ public class AsteroidOSNotification {
|
||||
}
|
||||
}
|
||||
private VibrationStrength vibrationStrength = VibrationStrength.NORMAL;
|
||||
|
||||
/**
|
||||
* Creates a notification
|
||||
* @param spec The NotificationSpec to create the notification from
|
||||
*/
|
||||
public AsteroidOSNotification(NotificationSpec spec) {
|
||||
this.body = spec.body;
|
||||
this.applicationName = spec.sourceName;
|
||||
@ -57,7 +68,6 @@ public class AsteroidOSNotification {
|
||||
default:
|
||||
this.id = (callSpec.name + callSpec.number).hashCode();
|
||||
this.remove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,6 +81,9 @@ public class AsteroidOSNotification {
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Converts the notification to a string to be sent to the device
|
||||
*/
|
||||
public String toString() {
|
||||
if (remove) {
|
||||
return "<remove><id>" + this.id + "</id></remove>";
|
||||
|
@ -6,26 +6,63 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
|
||||
|
||||
/**
|
||||
* An adapter class for weather
|
||||
*/
|
||||
public class AsteroidOSWeather {
|
||||
/**
|
||||
* Provides a day's worth of weather
|
||||
*/
|
||||
public class Day {
|
||||
/**
|
||||
* The minimum temp of the day
|
||||
*/
|
||||
public int minTemp;
|
||||
/**
|
||||
* The maximum temp of the day
|
||||
*/
|
||||
public int maxTemp;
|
||||
/**
|
||||
* The current OWM weather condition code
|
||||
*/
|
||||
public int condition;
|
||||
|
||||
/**
|
||||
* Creates a Day from the forecast given
|
||||
* @param forecast
|
||||
*/
|
||||
public Day(WeatherSpec.Forecast forecast) {
|
||||
minTemp = forecast.minTemp;
|
||||
maxTemp = forecast.maxTemp;
|
||||
condition = forecast.conditionCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Day from the WeatherSpec given
|
||||
* @param spec
|
||||
*/
|
||||
public Day(WeatherSpec spec) {
|
||||
minTemp = spec.todayMinTemp;
|
||||
maxTemp = spec.todayMaxTemp;
|
||||
condition = spec.currentConditionCode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The days of the weather
|
||||
*/
|
||||
public Day[] days = new Day[5];
|
||||
/**
|
||||
* The city name of the weather
|
||||
*/
|
||||
public String cityName = "";
|
||||
|
||||
|
||||
/**
|
||||
* Creates an AsteroidOSWeather from the WeatherSpec given
|
||||
* @param spec
|
||||
*/
|
||||
public AsteroidOSWeather(WeatherSpec spec) {
|
||||
cityName = spec.location;
|
||||
days[0] = new Day(spec);
|
||||
@ -34,10 +71,18 @@ public class AsteroidOSWeather {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a byte array of the city name
|
||||
* @return a byte array of the city name
|
||||
*/
|
||||
public byte[] getCityName() {
|
||||
return cityName.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the days' weather conditions and returns them in a format AsteroidOS can handle
|
||||
* @return a byte array to be sent to the device
|
||||
*/
|
||||
public byte[] getWeatherConditions() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
for (Day day : days) {
|
||||
@ -47,6 +92,10 @@ public class AsteroidOSWeather {
|
||||
return stream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the days' min temps and returns them in a format AsteroidOS can handle
|
||||
* @return a byte array to be sent to the device
|
||||
*/
|
||||
public byte[] getMinTemps() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
for (Day day : days) {
|
||||
@ -56,6 +105,10 @@ public class AsteroidOSWeather {
|
||||
return stream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the days' max temps and returns them in a format AsteroidOS can handle
|
||||
* @return a byte array to be sent to the device
|
||||
*/
|
||||
public byte[] getMaxTemps() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
for (Day day : days) {
|
||||
|
@ -43,8 +43,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.Batter
|
||||
public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AsteroidOSDeviceSupport.class);
|
||||
private final BatteryInfoProfile<AsteroidOSDeviceSupport> batteryInfoProfile;
|
||||
|
||||
private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo();
|
||||
|
||||
public AsteroidOSDeviceSupport() {
|
||||
super(LOG);
|
||||
addSupportedService(AsteroidOSConstants.SERVICE_UUID);
|
||||
@ -68,8 +68,6 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
batteryInfoProfile = new BatteryInfoProfile<>(this);
|
||||
batteryInfoProfile.addListener(mListener);
|
||||
addSupportedProfile(batteryInfoProfile);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void handleBatteryInfo(nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.battery.BatteryInfo info) {
|
||||
@ -232,6 +230,12 @@ public class AsteroidOSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles a media command sent from the AsteroidOS device
|
||||
* @param gatt The bluetooth device's GATT info
|
||||
* @param characteristic The Characteristic information
|
||||
*/
|
||||
public void handleMediaCommand (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
||||
LOG.info("handle media command");
|
||||
AsteroidOSMediaCommand command = new AsteroidOSMediaCommand(characteristic.getValue()[0]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user