mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 18:15:49 +01:00
Garmin protocol: create custom GBDeviceEvent for weather request
This commit is contained in:
parent
4054326535
commit
8524426b70
@ -16,9 +16,11 @@ import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr.GdiDeviceStatus;
|
||||
import nodomain.freeyourgadget.gadgetbridge.proto.vivomovehr.GdiFindMyWatch;
|
||||
@ -29,8 +31,10 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateA
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.communicator.ICommunicator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.communicator.v1.CommunicatorV1;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.communicator.v2.CommunicatorV2;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.deviceevents.WeatherRequestDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.GlobalDefinitionsEnum;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.RecordData;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.RecordDefinition;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.ConfigurationMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.GFDIMessage;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.MusicControlEntityUpdateMessage;
|
||||
@ -134,6 +138,18 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void evaluateGBDeviceEvent(GBDeviceEvent deviceEvent) {
|
||||
if (deviceEvent instanceof WeatherRequestDeviceEvent) {
|
||||
WeatherSpec weather = Weather.getInstance().getWeatherSpec();
|
||||
if (weather != null) {
|
||||
sendWeatherConditions(weather);
|
||||
}
|
||||
|
||||
}
|
||||
super.evaluateGBDeviceEvent(deviceEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendWeather(final ArrayList<WeatherSpec> weatherSpecs) {
|
||||
sendWeatherConditions(weatherSpecs.get(0));
|
||||
@ -142,6 +158,13 @@ public class GarminSupport extends AbstractBTLEDeviceSupport implements ICommuni
|
||||
private void sendWeatherConditions(WeatherSpec weather) {
|
||||
List<RecordData> weatherData = new ArrayList<>();
|
||||
|
||||
List<RecordDefinition> weatherDefinitions = new ArrayList<>(3);
|
||||
weatherDefinitions.add(GlobalDefinitionsEnum.TODAY_WEATHER_CONDITIONS.getRecordDefinition());
|
||||
weatherDefinitions.add(GlobalDefinitionsEnum.HOURLY_WEATHER_FORECAST.getRecordDefinition());
|
||||
weatherDefinitions.add(GlobalDefinitionsEnum.DAILY_WEATHER_FORECAST.getRecordDefinition());
|
||||
|
||||
communicator.sendMessage(new nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.FitDefinitionMessage(weatherDefinitions).getOutgoingMessage());
|
||||
|
||||
try {
|
||||
RecordData today = new RecordData(GlobalDefinitionsEnum.TODAY_WEATHER_CONDITIONS.getRecordDefinition());
|
||||
today.setFieldByName("weather_report", 0); // 0 = current, 1 = hourly_forecast, 2 = daily_forecast
|
||||
|
@ -0,0 +1,18 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.deviceevents;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
|
||||
public class WeatherRequestDeviceEvent extends GBDeviceEvent {
|
||||
private final int format;
|
||||
private final int latitude;
|
||||
private final int longitude;
|
||||
private final int hoursOfForecast;
|
||||
public WeatherRequestDeviceEvent(int format, int latitude, int longitude, int hoursOfForecast) {
|
||||
this.format = format;
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.hoursOfForecast = hoursOfForecast;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,33 +1,13 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.GlobalDefinitionsEnum;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.RecordDefinition;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.deviceevents.WeatherRequestDeviceEvent;
|
||||
|
||||
public class WeatherMessage extends GFDIMessage {
|
||||
private final int format;
|
||||
private final int latitude;
|
||||
private final int longitude;
|
||||
private final int hoursOfForecast;
|
||||
|
||||
|
||||
private final List<RecordDefinition> weatherDefinitions;
|
||||
|
||||
private final WeatherRequestDeviceEvent weatherRequestDeviceEvent;
|
||||
public WeatherMessage(int format, int latitude, int longitude, int hoursOfForecast, GarminMessage garminMessage) {
|
||||
this.format = format;
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.hoursOfForecast = hoursOfForecast;
|
||||
|
||||
this.garminMessage = garminMessage;
|
||||
|
||||
|
||||
weatherDefinitions = new ArrayList<>(3);
|
||||
weatherDefinitions.add(GlobalDefinitionsEnum.TODAY_WEATHER_CONDITIONS.getRecordDefinition());
|
||||
weatherDefinitions.add(GlobalDefinitionsEnum.HOURLY_WEATHER_FORECAST.getRecordDefinition());
|
||||
weatherDefinitions.add(GlobalDefinitionsEnum.DAILY_WEATHER_FORECAST.getRecordDefinition());
|
||||
|
||||
weatherRequestDeviceEvent = new WeatherRequestDeviceEvent(format, latitude, longitude, hoursOfForecast);
|
||||
this.statusMessage = this.getStatusMessage();
|
||||
|
||||
}
|
||||
@ -41,14 +21,13 @@ public class WeatherMessage extends GFDIMessage {
|
||||
return new WeatherMessage(format, latitude, longitude, hoursOfForecast, garminMessage);
|
||||
}
|
||||
|
||||
public WeatherRequestDeviceEvent getGBDeviceEvent() {
|
||||
return weatherRequestDeviceEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean generateOutgoing() {
|
||||
final MessageWriter writer = new MessageWriter(response);
|
||||
writer.writeShort(0); // packet size will be filled below
|
||||
writer.writeShort(GarminMessage.FIT_DEFINITION.getId());
|
||||
for (RecordDefinition definition : weatherDefinitions) {
|
||||
definition.generateOutgoingPayload(writer);
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user