huami: send windspeed in beaufort (#2247)

fixup! huamni: send windspeed in beaufort

BipS: send windspeed as km/h

huami: Always send sunrise and sunset

There is no need to look at send_sunrise_sunset, this is peble spesific
because it could be annoying on that platform (an extra line in the
timeline). On huami devices, the watchface desides what to show.

Signed-off-by: Robbert Gurdeep Singh <git@beardhatcode.be>

Mi5: set supportsSunriseSunsetWindHumidity to true

Signed-off-by: Robbert Gurdeep Singh <git@beardhatcode.be>

huamni: send windspeed in beaufort

Signed-off-by: Robbert Gurdeep Singh <git@beardhatcode.be>

Co-authored-by: Robbert Gurdeep Singh <git@beardhatcode.be>
Reviewed-on: https://codeberg.org/Freeyourgadget/Gadgetbridge/pulls/2247
Co-Authored-By: beardhatcode <beardhatcode@noreply.codeberg.org>
Co-Committed-By: beardhatcode <beardhatcode@noreply.codeberg.org>
This commit is contained in:
beardhatcode 2021-04-21 17:12:20 +02:00 committed by Andreas Shimokawa
parent 2d7bd6ae7b
commit 32a6049207
4 changed files with 63 additions and 25 deletions

View File

@ -22,6 +22,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.Arrays;
// FIXME: document me and my fields, including units
public class WeatherSpec implements Parcelable {
@ -54,6 +55,19 @@ public class WeatherSpec implements Parcelable {
}
// Lower bounds of beaufort regions 1 to 12
// Values from https://en.wikipedia.org/wiki/Beaufort_scale
static final float[] beaufort = new float[] { 2, 6, 12, 20, 29, 39, 50, 62, 75, 89, 103, 118 };
// level: 0 1 2 3 4 5 6 7 8 9 10 11 12
public int windSpeedAsBeaufort() {
int l = 0;
while (l < beaufort.length && beaufort[l] < this.windSpeed) {
l++;
}
return l;
}
protected WeatherSpec(Parcel in) {
int version = in.readInt();
if (version == VERSION) {

View File

@ -264,6 +264,20 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
return false;
}
/**
* Return the wind speed as sting in a format that is supported by the device.
*
* A lot of devices only support "levels", in GB we send the Beaufort speed.
* Override this in the device specific support class if other, more clear,
* formats are supported.
*
* @param weatherSpec
* @return
*/
public String windSpeedString(WeatherSpec weatherSpec){
return weatherSpec.windSpeedAsBeaufort() + ""; // cast to string
}
/**
* Returns the given date/time (calendar) as a byte sequence, suitable for sending to the
* Mi Band 2 (or derivative). The band appears to not handle DST offsets, so we simply add this
@ -2217,7 +2231,7 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
TransactionBuilder builder;
builder = performInitialized("Sending wind/humidity");
String windString = weatherSpec.windSpeed + "km/h";
String windString = this.windSpeedString(weatherSpec);
String humidityString = weatherSpec.currentHumidity + "%";
int length = 8 + windString.getBytes().length + humidityString.getBytes().length;
@ -2237,34 +2251,32 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
LOG.error("Error sending wind/humidity", ex);
}
if (GBApplication.getPrefs().getBoolean("send_sunrise_sunset", false)) {
float[] longlat = GBApplication.getGBPrefs().getLongLat(getContext());
float longitude = longlat[0];
float latitude = longlat[1];
if (longitude != 0 && latitude != 0) {
final GregorianCalendar dateTimeToday = new GregorianCalendar();
float[] longlat = GBApplication.getGBPrefs().getLongLat(getContext());
float longitude = longlat[0];
float latitude = longlat[1];
if (longitude != 0 && latitude != 0) {
final GregorianCalendar dateTimeToday = new GregorianCalendar();
GregorianCalendar[] sunriseTransitSet = SPA.calculateSunriseTransitSet(dateTimeToday, latitude, longitude, DeltaT.estimate(dateTimeToday));
GregorianCalendar[] sunriseTransitSet = SPA.calculateSunriseTransitSet(dateTimeToday, latitude, longitude, DeltaT.estimate(dateTimeToday));
try {
TransactionBuilder builder;
builder = performInitialized("Sending sunrise/sunset");
try {
TransactionBuilder builder;
builder = performInitialized("Sending sunrise/sunset");
ByteBuffer buf = ByteBuffer.allocate(10);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 16);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) (tz_offset_hours * 4));
buf.put((byte) sunriseTransitSet[0].get(GregorianCalendar.HOUR_OF_DAY));
buf.put((byte) sunriseTransitSet[0].get(GregorianCalendar.MINUTE));
buf.put((byte) sunriseTransitSet[2].get(GregorianCalendar.HOUR_OF_DAY));
buf.put((byte) sunriseTransitSet[2].get(GregorianCalendar.MINUTE));
ByteBuffer buf = ByteBuffer.allocate(10);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 16);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) (tz_offset_hours * 4));
buf.put((byte) sunriseTransitSet[0].get(GregorianCalendar.HOUR_OF_DAY));
buf.put((byte) sunriseTransitSet[0].get(GregorianCalendar.MINUTE));
buf.put((byte) sunriseTransitSet[2].get(GregorianCalendar.HOUR_OF_DAY));
buf.put((byte) sunriseTransitSet[2].get(GregorianCalendar.MINUTE));
writeToChunked(builder, 1, buf.array());
builder.queue(getQueue());
} catch (Exception ex) {
LOG.error("Error sending sunset/sunrise", ex);
}
writeToChunked(builder, 1, buf.array());
builder.queue(getQueue());
} catch (Exception ex) {
LOG.error("Error sending sunset/sunrise", ex);
}
}
}

View File

@ -29,6 +29,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitbips.AmazfitBipSFWHelper;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitbip.AmazfitBipSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.operations.UpdateFirmwareOperation;
@ -61,6 +62,11 @@ public class AmazfitBipSSupport extends AmazfitBipSupport {
return (!isDTH(version) && (version.compareTo(new Version("2.1.1.50")) >= 0) || (version.compareTo(new Version("4.1.5.55")) >= 0));
}
@Override
public String windSpeedString(WeatherSpec weatherSpec){
return weatherSpec.windSpeed + "km/h";
}
@Override
public void onSetCallState(CallSpec callSpec) {
onSetCallStateNew(callSpec);

View File

@ -50,6 +50,12 @@ public class MiBand5Support extends MiBand4Support {
return new MiBand5FWHelper(uri, context);
}
@Override
public boolean supportsSunriseSunsetWindHumidity() {
return true;
}
@Override
public int getActivitySampleSize() {
return 8;