Search in sources :

Example 1 with SoehnleLib

use of com.health.openscale.core.bluetooth.lib.SoehnleLib in project openScale by oliexdev.

the class BluetoothSoehnle method handleWeightMeasurement.

private void handleWeightMeasurement(byte[] value) {
    // kg
    float weight = Converters.fromUnsignedInt16Be(value, 9) / 10.0f;
    int soehnleUserIndex = (int) value[1];
    final int year = Converters.fromUnsignedInt16Be(value, 2);
    final int month = (int) value[4];
    final int day = (int) value[5];
    final int hours = (int) value[6];
    final int min = (int) value[7];
    final int sec = (int) value[8];
    final int imp5 = Converters.fromUnsignedInt16Be(value, 11);
    final int imp50 = Converters.fromUnsignedInt16Be(value, 13);
    String date_string = year + "/" + month + "/" + day + "/" + hours + "/" + min;
    Date date_time = new Date();
    try {
        date_time = new SimpleDateFormat("yyyy/MM/dd/HH/mm").parse(date_string);
    } catch (ParseException e) {
        Timber.e("parse error " + e.getMessage());
    }
    final ScaleUser scaleUser = OpenScale.getInstance().getSelectedScaleUser();
    int activityLevel = 0;
    switch(scaleUser.getActivityLevel()) {
        case SEDENTARY:
            activityLevel = 0;
            break;
        case MILD:
            activityLevel = 1;
            break;
        case MODERATE:
            activityLevel = 2;
            break;
        case HEAVY:
            activityLevel = 4;
            break;
        case EXTREME:
            activityLevel = 5;
            break;
    }
    int openScaleUserId = prefs.getInt("userScaleIndex" + soehnleUserIndex, -1);
    if (openScaleUserId == -1) {
        Timber.e("Unknown Soehnle user index " + soehnleUserIndex);
    } else {
        SoehnleLib soehnleLib = new SoehnleLib(scaleUser.getGender().isMale(), scaleUser.getAge(), scaleUser.getBodyHeight(), activityLevel);
        ScaleMeasurement scaleMeasurement = new ScaleMeasurement();
        scaleMeasurement.setUserId(openScaleUserId);
        scaleMeasurement.setWeight(weight);
        scaleMeasurement.setDateTime(date_time);
        scaleMeasurement.setWater(soehnleLib.getWater(weight, imp50));
        scaleMeasurement.setFat(soehnleLib.getFat(weight, imp50));
        scaleMeasurement.setMuscle(soehnleLib.getMuscle(weight, imp50, imp5));
        addScaleMeasurement(scaleMeasurement);
    }
}
Also used : ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) ScaleUser(com.health.openscale.core.datatypes.ScaleUser) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) SoehnleLib(com.health.openscale.core.bluetooth.lib.SoehnleLib) Date(java.util.Date)

Aggregations

SoehnleLib (com.health.openscale.core.bluetooth.lib.SoehnleLib)1 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)1 ScaleUser (com.health.openscale.core.datatypes.ScaleUser)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1