mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 09:01:55 +01:00
Amazfit Bip S: Send sunrise and sunset on latest firmware if enabled
This still has to be enabled in Pebble settings..... :/
This commit is contained in:
parent
5bdee2c130
commit
1337644a14
@ -1,6 +1,7 @@
|
||||
### Changelog
|
||||
|
||||
#### 0.47.2 (WIP)
|
||||
* Amazfit Bip S: Send sunrise and sunset on latest firmware if enabled
|
||||
* Huami: Support new firmware update protocol (fixes firmware flashing with firmware 2.1.1.50/4.1.5.55 on Amazfit Bip S)
|
||||
* Huami: Allow flashing latest GPS firmware
|
||||
* InfiniTime: Add support for music control
|
||||
|
@ -17,16 +17,11 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
||||
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Criteria;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
|
||||
import net.e175.klaus.solarpositioning.DeltaT;
|
||||
import net.e175.klaus.solarpositioning.SPA;
|
||||
@ -38,11 +33,10 @@ import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||
|
||||
public class AlarmReceiver extends BroadcastReceiver {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AlarmReceiver.class);
|
||||
@ -86,26 +80,11 @@ public class AlarmReceiver extends BroadcastReceiver {
|
||||
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNRISE, id_tomorrow);
|
||||
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_SUNSET, id_tomorrow);
|
||||
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
GBPrefs gbPrefs = GBApplication.getGBPrefs();
|
||||
float[] longlat = gbPrefs.getLongLat(context);
|
||||
float longitude = longlat[0];
|
||||
float latitude = longlat[1];
|
||||
|
||||
float latitude = prefs.getFloat("location_latitude", 0);
|
||||
float longitude = prefs.getFloat("location_longitude", 0);
|
||||
LOG.info("got longitude/latitude from preferences: " + latitude + "/" + longitude);
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
||||
prefs.getBoolean("use_updated_location_if_available", false)) {
|
||||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
Criteria criteria = new Criteria();
|
||||
String provider = locationManager.getBestProvider(criteria, false);
|
||||
if (provider != null) {
|
||||
Location lastKnownLocation = locationManager.getLastKnownLocation(provider);
|
||||
if (lastKnownLocation != null) {
|
||||
latitude = (float) lastKnownLocation.getLatitude();
|
||||
longitude = (float) lastKnownLocation.getLongitude();
|
||||
LOG.info("got longitude/latitude from last known location: " + latitude + "/" + longitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
GregorianCalendar[] sunriseTransitSetTomorrow = SPA.calculateSunriseTransitSet(dateTimeTomorrow, latitude, longitude, DeltaT.estimate(dateTimeTomorrow));
|
||||
|
||||
CalendarEventSpec calendarEventSpec = new CalendarEventSpec();
|
||||
|
@ -30,6 +30,9 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import net.e175.klaus.solarpositioning.DeltaT;
|
||||
import net.e175.klaus.solarpositioning.SPA;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -249,10 +252,15 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
public boolean supportsSunriseSunset() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* to the timezone.
|
||||
*
|
||||
* @param calendar
|
||||
* @param precision
|
||||
* @return
|
||||
@ -2126,6 +2134,37 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport {
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Error sending current forecast location", ex);
|
||||
}
|
||||
|
||||
if (supportsSunriseSunset() && 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();
|
||||
|
||||
GregorianCalendar[] sunriseTransitSet = SPA.calculateSunriseTransitSet(dateTimeToday, latitude, longitude, DeltaT.estimate(dateTimeToday));
|
||||
|
||||
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));
|
||||
|
||||
writeToChunked(builder, 1, buf.array());
|
||||
builder.queue(getQueue());
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Error sending sunset/sunrise", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HuamiSupport setDateDisplay(TransactionBuilder builder) {
|
||||
|
@ -64,6 +64,12 @@ public class AmazfitBipSSupport extends AmazfitBipSupport {
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsSunriseSunset() {
|
||||
Version version = new Version(gbDevice.getFirmwareVersion());
|
||||
return (!isDTH(version) && (version.compareTo(new Version("2.1.1.50")) >= 0) || (version.compareTo(new Version("4.1.5.55")) >= 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetCallState(CallSpec callSpec) {
|
||||
if (callSpec.command == CallSpec.CALL_INCOMING) {
|
||||
@ -100,9 +106,7 @@ public class AmazfitBipSSupport extends AmazfitBipSupport {
|
||||
@Override
|
||||
public UpdateFirmwareOperation createUpdateFirmwareOperation(Uri uri) {
|
||||
Version version = new Version(gbDevice.getFirmwareVersion());
|
||||
// 4.0.0.00 is here to not confuse with DTH variant
|
||||
if ((version.compareTo(new Version("2.1.1.50")) >= 0 && version.compareTo(new Version("4.0.0.00")) < 0) ||
|
||||
(version.compareTo(new Version("4.1.5.55")) >= 0)) {
|
||||
if ((!isDTH(version) && (version.compareTo(new Version("2.1.1.50")) >= 0) || (version.compareTo(new Version("4.1.5.55")) >= 0))) {
|
||||
return new UpdateFirmwareOperation2020(uri, this);
|
||||
}
|
||||
|
||||
@ -219,4 +223,7 @@ public class AmazfitBipSSupport extends AmazfitBipSupport {
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean isDTH(Version version) {
|
||||
return version.compareTo(new Version("4.0.0.00")) >= 0;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,19 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.Criteria;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
@ -26,6 +37,8 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||
|
||||
public class GBPrefs {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GBPrefs.class);
|
||||
|
||||
public static final String PACKAGE_BLACKLIST = "package_blacklist";
|
||||
public static final String PACKAGE_PEBBLEMSG_BLACKLIST = "package_pebblemsg_blacklist";
|
||||
public static final String CALENDAR_BLACKLIST = "calendar_blacklist";
|
||||
@ -99,4 +112,28 @@ public class GBPrefs {
|
||||
|
||||
return timeFormat;
|
||||
}
|
||||
|
||||
public float[] getLongLat(Context context) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
|
||||
float latitude = prefs.getFloat("location_latitude", 0);
|
||||
float longitude = prefs.getFloat("location_longitude", 0);
|
||||
LOG.info("got longitude/latitude from preferences: " + latitude + "/" + longitude);
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
|
||||
prefs.getBoolean("use_updated_location_if_available", false)) {
|
||||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||
Criteria criteria = new Criteria();
|
||||
String provider = locationManager.getBestProvider(criteria, false);
|
||||
if (provider != null) {
|
||||
Location lastKnownLocation = locationManager.getLastKnownLocation(provider);
|
||||
if (lastKnownLocation != null) {
|
||||
latitude = (float) lastKnownLocation.getLatitude();
|
||||
longitude = (float) lastKnownLocation.getLongitude();
|
||||
LOG.info("got longitude/latitude from last known location: " + latitude + "/" + longitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new float[]{longitude, latitude};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user