mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
CMF Watch Pro: Do not send sunrise / sunset
Weather breaks since the watch does not support it. Aditionally, only send up to 30 bytes for the location.
This commit is contained in:
parent
bd88cffcfc
commit
42de2fadd4
@ -40,4 +40,9 @@ public class CmfWatchPro2Coordinator extends CmfWatchProCoordinator {
|
|||||||
public int getDisabledIconResource() {
|
public int getDisabledIconResource() {
|
||||||
return R.drawable.ic_device_watchxplus_disabled;
|
return R.drawable.ic_device_watchxplus_disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsSunriseSunset() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,4 +370,8 @@ public class CmfWatchProCoordinator extends AbstractBLEDeviceCoordinator {
|
|||||||
protected static Prefs getPrefs(final GBDevice device) {
|
protected static Prefs getPrefs(final GBDevice device) {
|
||||||
return new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()));
|
return new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean supportsSunriseSunset() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventUpdateDeviceInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.cmfwatchpro.CmfWatchProCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||||
@ -393,6 +394,10 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf
|
|||||||
return authKeyBytes;
|
return authKeyBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected CmfWatchProCoordinator getCoordinator() {
|
||||||
|
return (CmfWatchProCoordinator) gbDevice.getDeviceCoordinator();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetGpsLocation(final Location location) {
|
public void onSetGpsLocation(final Location location) {
|
||||||
final TransactionBuilder builder = createTransactionBuilder("set gps location");
|
final TransactionBuilder builder = createTransactionBuilder("set gps location");
|
||||||
@ -623,9 +628,11 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf
|
|||||||
// Each weather entry takes up 9 bytes
|
// Each weather entry takes up 9 bytes
|
||||||
// There are 7 of those weather entries - 7*9 bytes
|
// There are 7 of those weather entries - 7*9 bytes
|
||||||
// Then there are 24-hour entries of temp and weather condition (2 bytes each)
|
// Then there are 24-hour entries of temp and weather condition (2 bytes each)
|
||||||
// Then the location name as bytes - allow for 31 bytes, watch auto-scrolls. Pad it to 32 bytes
|
// Then the location name as bytes - allow for 30 bytes, watch auto-scrolls. Pad it to 32 bytes if it supports sunset/sunrise
|
||||||
// Then finally the sunrise / sunset pairs, for 7 days (7*8)
|
// Then finally the sunrise / sunset pairs, for 7 days (7*8)
|
||||||
final ByteBuffer buf = ByteBuffer.allocate((7 * 9) + (24 * 2) + 32 + (7 * 8)).order(ByteOrder.BIG_ENDIAN);
|
final boolean supportsSunriseSunset = getCoordinator().supportsSunriseSunset();
|
||||||
|
final int payloadLength = (7 * 9) + (24 * 2) + (supportsSunriseSunset ? 32 : 30) + (supportsSunriseSunset ? 7 * 8 : 0);
|
||||||
|
final ByteBuffer buf = ByteBuffer.allocate(payloadLength).order(ByteOrder.BIG_ENDIAN);
|
||||||
// start with the current day's weather
|
// start with the current day's weather
|
||||||
buf.put(Weather.mapToCmfCondition(weatherSpec.currentConditionCode));
|
buf.put(Weather.mapToCmfCondition(weatherSpec.currentConditionCode));
|
||||||
buf.put((byte) (weatherSpec.currentTemp - 273 + 100)); // convert Kelvin to C, add 100
|
buf.put((byte) (weatherSpec.currentTemp - 273 + 100)); // convert Kelvin to C, add 100
|
||||||
@ -676,30 +683,33 @@ public class CmfWatchProSupport extends AbstractBTLEDeviceSupport implements Cmf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// place name - watch scrolls after ~10 chars. Pad up to 32 bytes.
|
// place name - watch scrolls after ~10 chars. Pad up to 32 bytes.
|
||||||
final byte[] locationNameBytes = nodomain.freeyourgadget.gadgetbridge.util.StringUtils.truncateToBytes(weatherSpec.location, 31);
|
final byte[] locationNameBytes = nodomain.freeyourgadget.gadgetbridge.util.StringUtils.truncateToBytes(weatherSpec.location, 30);
|
||||||
buf.put(locationNameBytes);
|
buf.put(locationNameBytes);
|
||||||
buf.put(new byte[32 - locationNameBytes.length]);
|
|
||||||
|
|
||||||
// Sunrise / sunset
|
// Sunrise / sunset
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN); // why...
|
if (supportsSunriseSunset) {
|
||||||
final Location location = weatherSpec.getLocation() != null ? weatherSpec.getLocation() : new CurrentPosition().getLastKnownLocation();
|
buf.put(new byte[32 - locationNameBytes.length]);
|
||||||
final GregorianCalendar sunriseDate = new GregorianCalendar();
|
|
||||||
|
|
||||||
if (weatherSpec.sunRise != 0 && weatherSpec.sunSet != 0) {
|
buf.order(ByteOrder.LITTLE_ENDIAN); // why...
|
||||||
buf.putInt(weatherSpec.sunRise);
|
final Location location = weatherSpec.getLocation() != null ? weatherSpec.getLocation() : new CurrentPosition().getLastKnownLocation();
|
||||||
buf.putInt(weatherSpec.sunSet);
|
final GregorianCalendar sunriseDate = new GregorianCalendar();
|
||||||
} else {
|
|
||||||
putSunriseSunset(buf, location, sunriseDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
if (weatherSpec.sunRise != 0 && weatherSpec.sunSet != 0) {
|
||||||
sunriseDate.add(Calendar.DAY_OF_MONTH, 1);
|
buf.putInt(weatherSpec.sunRise);
|
||||||
if (i < weatherSpec.forecasts.size() && weatherSpec.forecasts.get(i).sunRise != 0 && weatherSpec.forecasts.get(i).sunSet != 0) {
|
buf.putInt(weatherSpec.sunSet);
|
||||||
buf.putInt(weatherSpec.forecasts.get(i).sunRise);
|
|
||||||
buf.putInt(weatherSpec.forecasts.get(i).sunSet);
|
|
||||||
} else {
|
} else {
|
||||||
putSunriseSunset(buf, location, sunriseDate);
|
putSunriseSunset(buf, location, sunriseDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
sunriseDate.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
|
if (i < weatherSpec.forecasts.size() && weatherSpec.forecasts.get(i).sunRise != 0 && weatherSpec.forecasts.get(i).sunSet != 0) {
|
||||||
|
buf.putInt(weatherSpec.forecasts.get(i).sunRise);
|
||||||
|
buf.putInt(weatherSpec.forecasts.get(i).sunSet);
|
||||||
|
} else {
|
||||||
|
putSunriseSunset(buf, location, sunriseDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendCommand("send weather", CmfCommand.WEATHER_SET_1, buf.array());
|
sendCommand("send weather", CmfCommand.WEATHER_SET_1, buf.array());
|
||||||
|
Loading…
Reference in New Issue
Block a user