Search in sources :

Example 6 with Version

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);
            }
        }
    }
}
Also used : FirmwareType(nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.FirmwareType) Version(nodomain.freeyourgadget.gadgetbridge.util.Version)

Example 7 with Version

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;
}
Also used : Matcher(java.util.regex.Matcher) Version(nodomain.freeyourgadget.gadgetbridge.util.Version)

Example 8 with Version

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);
    }
}
Also used : ButtonConfigurationPutRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest) SharedPreferences(android.content.SharedPreferences) CommuteConfigPutRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.commute.CommuteConfigPutRequest) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ButtonConfiguration(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfiguration) JSONException(org.json.JSONException) Paint(android.graphics.Paint) Version(nodomain.freeyourgadget.gadgetbridge.util.Version) ApplicationInformation(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.application.ApplicationInformation)

Example 9 with Version

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());
    }
}
Also used : ConfirmOnDeviceRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.ConfirmOnDeviceRequest) Version(nodomain.freeyourgadget.gadgetbridge.util.Version)

Example 10 with Version

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);
            }
        }
    }
}
Also used : MiBandConst(nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst) GregorianCalendar(java.util.GregorianCalendar) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) Version(nodomain.freeyourgadget.gadgetbridge.util.Version) WeatherSpec(nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec)

Aggregations

Version (nodomain.freeyourgadget.gadgetbridge.util.Version)11 Paint (android.graphics.Paint)3 ArrayList (java.util.ArrayList)3 CustomWidget (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget)3 Widget (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.Widget)3 IOException (java.io.IOException)2 CustomWidgetElement (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidgetElement)2 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1