use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class MiBand2FWInstallHandler method maybeAddFw53Hint.
private void maybeAddFw53Hint(InstallActivity installActivity, GBDevice device) {
FirmwareType type = getFirmwareType();
if (type != FirmwareType.FIRMWARE) {
return;
}
Version deviceVersion = getFirmwareVersionOf(device);
if (deviceVersion != null) {
Version v53 = MiBandConst.MI2_FW_VERSION_INTERMEDIATE_UPGRADE_53;
if (deviceVersion.compareTo(v53) < 0) {
String vInstall = getHelper().format(getHelper().getFirmwareVersion());
if (vInstall == null || new Version(vInstall).compareTo(v53) > 0) {
String newInfoText = getContext().getString(R.string.mi2_fw_installhandler_fw53_hint, v53.get()) + "\n\n" + installActivity.getInfoText();
installActivity.setInfoText(newInfoText);
}
}
}
}
use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class FossilHRWatchAdapter method getCleanFWVersion.
private Version getCleanFWVersion() {
String firmware = getDeviceSupport().getDevice().getFirmwareVersion();
// DN1.0.2.19r.v5
Matcher matcher = Pattern.compile("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+").matcher(firmware);
if (matcher.find()) {
firmware = matcher.group(0);
return new Version(firmware);
}
return null;
}
use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class FossilHRWatchAdapter method overwriteButtons.
@Override
public void overwriteButtons(String jsonConfigString) {
try {
SharedPreferences prefs = getDeviceSpecificPreferences();
String singlePressEvent = "short_press_release";
Version firmwareVersion = getCleanFWVersion();
if (firmwareVersion != null && firmwareVersion.compareTo(new Version("1.0.2.19")) < 0) {
singlePressEvent = "single_click";
}
ArrayList<ButtonConfiguration> configs = new ArrayList<>(5);
configs.add(new ButtonConfiguration("top_" + singlePressEvent, prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_SHORT, "weatherApp")));
configs.add(new ButtonConfiguration("top_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_LONG, "weatherApp")));
// configs.add(new ButtonConfiguration("top_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_DOUBLE, "weatherApp")));
configs.add(new ButtonConfiguration("middle_" + singlePressEvent, prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_SHORT, "commuteApp")));
// configs.add(new ButtonConfiguration("middle_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_LONG, "commuteApp")));
// configs.add(new ButtonConfiguration("middle_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_DOUBLE, "commuteApp")));
configs.add(new ButtonConfiguration("bottom_" + singlePressEvent, prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_SHORT, "musicApp")));
configs.add(new ButtonConfiguration("bottom_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_LONG, "musicApp")));
// configs.add(new ButtonConfiguration("bottom_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_DOUBLE, "musicApp")));
// filter out all apps not installed on watch
ArrayList<ButtonConfiguration> availableConfigs = new ArrayList<>();
outerLoop: for (ButtonConfiguration config : configs) {
for (ApplicationInformation installedApp : installedApplications) {
if (installedApp.getAppName().equals(config.getAction())) {
availableConfigs.add(config);
continue outerLoop;
}
}
}
queueWrite(new ButtonConfigurationPutRequest(availableConfigs.toArray(new ButtonConfiguration[0]), this));
for (ApplicationInformation info : installedApplications) {
if (info.getAppName().equals("commuteApp")) {
JSONArray jsonArray = new JSONArray(GBApplication.getPrefs().getString(CommuteActionsActivity.CONFIG_KEY_Q_ACTIONS, "[]"));
String[] menuItems = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) menuItems[i] = jsonArray.getString(i);
queueWrite(new CommuteConfigPutRequest(menuItems, this));
break;
}
}
} catch (JSONException e) {
LOG.error("Error while configuring buttons", e);
}
}
use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class FossilHRWatchAdapter method onFindDevice.
@Override
public void onFindDevice(boolean start) {
super.onFindDevice(start);
boolean versionSupportsConfirmation = getCleanFWVersion().compareTo(new Version("1.0.2.22")) != -1;
if (!versionSupportsConfirmation) {
GB.toast("not supported in this version", Toast.LENGTH_SHORT, GB.ERROR);
return;
}
if (start) {
queueWrite(new ConfirmOnDeviceRequest());
}
}
use of nodomain.freeyourgadget.gadgetbridge.util.Version in project Gadgetbridge by Freeyourgadget.
the class HuamiSupport method onSendWeather.
@Override
public void onSendWeather(WeatherSpec weatherSpec) {
// FIXME: currently HuamiSupport *is* MiBand2 support, so return if we are using Mi Band 2
if (gbDevice.getType() == DeviceType.MIBAND2) {
return;
}
if (gbDevice.getFirmwareVersion() == null) {
LOG.warn("Device not initialized yet, so not sending weather info");
return;
}
boolean supportsConditionString = true;
Version version = new Version(gbDevice.getFirmwareVersion());
if (gbDevice.getType() == DeviceType.AMAZFITBIP && version.compareTo(new Version("0.0.8.74")) < 0) {
supportsConditionString = false;
}
MiBandConst.DistanceUnit unit = HuamiCoordinator.getDistanceUnit();
int tz_offset_hours = SimpleTimeZone.getDefault().getOffset(weatherSpec.timestamp * 1000L) / (1000 * 60 * 60);
try {
TransactionBuilder builder;
builder = performInitialized("Sending current temp");
byte condition = HuamiWeatherConditions.mapToAmazfitBipWeatherCode(weatherSpec.currentConditionCode);
int length = 8;
if (supportsConditionString) {
length += weatherSpec.currentCondition.getBytes().length + 1;
}
ByteBuffer buf = ByteBuffer.allocate(length);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 2);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) (tz_offset_hours * 4));
buf.put(condition);
int currentTemp = weatherSpec.currentTemp - 273;
if (unit == MiBandConst.DistanceUnit.IMPERIAL) {
currentTemp = (int) WeatherUtils.celsiusToFahrenheit(currentTemp);
}
buf.put((byte) currentTemp);
if (supportsConditionString) {
buf.put(weatherSpec.currentCondition.getBytes());
buf.put((byte) 0);
}
if (characteristicChunked != null) {
writeToChunked(builder, 1, buf.array());
} else {
builder.write(getCharacteristic(AmazfitBipService.UUID_CHARACTERISTIC_WEATHER), buf.array());
}
builder.queue(getQueue());
} catch (Exception ex) {
LOG.error("Error sending current weather", ex);
}
try {
TransactionBuilder builder;
builder = performInitialized("Sending air quality index");
int length = 8;
String aqiString = "(n/a)";
if (supportsConditionString) {
length += aqiString.getBytes().length + 1;
}
ByteBuffer buf = ByteBuffer.allocate(length);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 4);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) (tz_offset_hours * 4));
buf.putShort((short) -1);
if (supportsConditionString) {
buf.put(aqiString.getBytes());
buf.put((byte) 0);
}
if (characteristicChunked != null) {
writeToChunked(builder, 1, buf.array());
} else {
builder.write(getCharacteristic(AmazfitBipService.UUID_CHARACTERISTIC_WEATHER), buf.array());
}
builder.queue(getQueue());
} catch (IOException ex) {
LOG.error("Error sending air quality");
}
try {
TransactionBuilder builder = performInitialized("Sending weather forecast");
if (weatherSpec.forecasts.size() > 6) {
// TDOD: find out the limits for each device
weatherSpec.forecasts.subList(6, weatherSpec.forecasts.size()).clear();
}
final byte NR_DAYS = (byte) (1 + weatherSpec.forecasts.size());
int bytesPerDay = 4;
int conditionsLength = 0;
if (supportsConditionString) {
bytesPerDay = 5;
conditionsLength = weatherSpec.currentCondition.getBytes().length;
for (WeatherSpec.Forecast forecast : weatherSpec.forecasts) {
conditionsLength += Weather.getConditionString(forecast.conditionCode).getBytes().length;
}
}
int length = 7 + bytesPerDay * NR_DAYS + conditionsLength;
ByteBuffer buf = ByteBuffer.allocate(length);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 1);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) (tz_offset_hours * 4));
buf.put(NR_DAYS);
byte condition = HuamiWeatherConditions.mapToAmazfitBipWeatherCode(weatherSpec.currentConditionCode);
buf.put(condition);
buf.put(condition);
int todayMaxTemp = weatherSpec.todayMaxTemp - 273;
int todayMinTemp = weatherSpec.todayMinTemp - 273;
if (unit == MiBandConst.DistanceUnit.IMPERIAL) {
todayMaxTemp = (int) WeatherUtils.celsiusToFahrenheit(todayMaxTemp);
todayMinTemp = (int) WeatherUtils.celsiusToFahrenheit(todayMinTemp);
}
buf.put((byte) todayMaxTemp);
buf.put((byte) todayMinTemp);
if (supportsConditionString) {
buf.put(weatherSpec.currentCondition.getBytes());
buf.put((byte) 0);
}
for (WeatherSpec.Forecast forecast : weatherSpec.forecasts) {
condition = HuamiWeatherConditions.mapToAmazfitBipWeatherCode(forecast.conditionCode);
buf.put(condition);
buf.put(condition);
int forecastMaxTemp = forecast.maxTemp - 273;
int forecastMinTemp = forecast.minTemp - 273;
if (unit == MiBandConst.DistanceUnit.IMPERIAL) {
forecastMaxTemp = (int) WeatherUtils.celsiusToFahrenheit(forecastMaxTemp);
forecastMinTemp = (int) WeatherUtils.celsiusToFahrenheit(forecastMinTemp);
}
buf.put((byte) forecastMaxTemp);
buf.put((byte) forecastMinTemp);
if (supportsConditionString) {
buf.put(Weather.getConditionString(forecast.conditionCode).getBytes());
buf.put((byte) 0);
}
}
if (characteristicChunked != null) {
writeToChunked(builder, 1, buf.array());
} else {
builder.write(getCharacteristic(AmazfitBipService.UUID_CHARACTERISTIC_WEATHER), buf.array());
}
builder.queue(getQueue());
} catch (Exception ex) {
LOG.error("Error sending weather forecast", ex);
}
try {
TransactionBuilder builder;
builder = performInitialized("Sending forecast location");
int length = 2 + weatherSpec.location.getBytes().length;
ByteBuffer buf = ByteBuffer.allocate(length);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 8);
buf.put(weatherSpec.location.getBytes());
buf.put((byte) 0);
if (characteristicChunked != null) {
writeToChunked(builder, 1, buf.array());
} else {
builder.write(getCharacteristic(AmazfitBipService.UUID_CHARACTERISTIC_WEATHER), buf.array());
}
builder.queue(getQueue());
} catch (Exception ex) {
LOG.error("Error sending current forecast location", ex);
}
if (supportsSunriseSunsetWindHumidity()) {
try {
TransactionBuilder builder;
builder = performInitialized("Sending wind/humidity");
String windString = this.windSpeedString(weatherSpec);
String humidityString = weatherSpec.currentHumidity + "%";
int length = 8 + windString.getBytes().length + humidityString.getBytes().length;
ByteBuffer buf = ByteBuffer.allocate(length);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.put((byte) 64);
buf.putInt(weatherSpec.timestamp);
buf.put((byte) (tz_offset_hours * 4));
buf.put(windString.getBytes());
buf.put((byte) 0);
buf.put(humidityString.getBytes());
buf.put((byte) 0);
writeToChunked(builder, 1, buf.array());
builder.queue(getQueue());
} catch (Exception ex) {
LOG.error("Error sending wind/humidity", ex);
}
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);
}
}
}
}
Aggregations