Search in sources :

Example 11 with BluetoothBytesParser

use of com.welie.blessed.BluetoothBytesParser in project openScale by oliexdev.

the class BluetoothBeurerBF600 method writeInitials.

@Override
protected void writeInitials() {
    if (haveCharacteristic(SERVICE_BEURER_CUSTOM_BF600, CHARACTERISTIC_BEURER_BF850_INITIALS)) {
        BluetoothBytesParser parser = new BluetoothBytesParser();
        String initials = getInitials(this.selectedUser.getUserName());
        Timber.d("Initials: " + initials);
        parser.setString(initials);
        writeBytes(SERVICE_BEURER_CUSTOM_BF600, CHARACTERISTIC_BEURER_BF850_INITIALS, parser.getValue());
    }
}
Also used : BluetoothBytesParser(com.welie.blessed.BluetoothBytesParser)

Example 12 with BluetoothBytesParser

use of com.welie.blessed.BluetoothBytesParser in project openScale by oliexdev.

the class BluetoothBeurerBF600 method writeActivityLevel.

@Override
protected void writeActivityLevel() {
    Converters.ActivityLevel al = selectedUser.getActivityLevel();
    BluetoothBytesParser parser = new BluetoothBytesParser(new byte[] { 0 });
    parser.setIntValue(al.toInt() + 1, FORMAT_UINT8, 0);
    Timber.d(String.format("setCurrentUserData Activity level: %d", al.toInt() + 1));
    writeBytes(SERVICE_BEURER_CUSTOM_BF600, CHARACTERISTIC_BEURER_BF600_ACTIVITY_LEVEL, parser.getValue());
}
Also used : BluetoothBytesParser(com.welie.blessed.BluetoothBytesParser) Converters(com.health.openscale.core.utils.Converters)

Example 13 with BluetoothBytesParser

use of com.welie.blessed.BluetoothBytesParser in project openScale by oliexdev.

the class BluetoothBeurerBF600 method requestMeasurement.

@Override
protected void requestMeasurement() {
    BluetoothBytesParser parser = new BluetoothBytesParser(new byte[] { 0 });
    parser.setIntValue(0x00, FORMAT_UINT8, 0);
    Timber.d(String.format("requestMeasurement BEURER 0xFFF4 magic: 0x00"));
    writeBytes(SERVICE_BEURER_CUSTOM_BF600, CHARACTERISTIC_BEURER_BF600_TAKE_MEASUREMENT, parser.getValue());
}
Also used : BluetoothBytesParser(com.welie.blessed.BluetoothBytesParser)

Example 14 with BluetoothBytesParser

use of com.welie.blessed.BluetoothBytesParser in project openScale by oliexdev.

the class BluetoothSoehnle method onNextStep.

@Override
protected boolean onNextStep(int stepNr) {
    switch(stepNr) {
        case 0:
            List<ScaleUser> openScaleUserList = OpenScale.getInstance().getScaleUserList();
            int index = -1;
            // check if an openScale user is stored as a Soehnle user otherwise do a factory reset
            for (ScaleUser openScaleUser : openScaleUserList) {
                index = getSoehnleUserIndex(openScaleUser.getId());
                if (index != -1) {
                    break;
                }
            }
            if (index == -1) {
                invokeScaleFactoryReset();
            }
            break;
        case 1:
            setNotificationOn(BluetoothGattUuid.SERVICE_BATTERY_LEVEL, BluetoothGattUuid.CHARACTERISTIC_BATTERY_LEVEL);
            readBytes(BluetoothGattUuid.SERVICE_BATTERY_LEVEL, BluetoothGattUuid.CHARACTERISTIC_BATTERY_LEVEL);
            break;
        case 2:
            // Write the current time
            BluetoothBytesParser parser = new BluetoothBytesParser();
            parser.setCurrentTime(Calendar.getInstance());
            writeBytes(BluetoothGattUuid.SERVICE_CURRENT_TIME, BluetoothGattUuid.CHARACTERISTIC_CURRENT_TIME, parser.getValue());
            break;
        case 3:
            // Turn on notification for User Data Service
            setNotificationOn(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_CONTROL_POINT);
            break;
        case 4:
            int openScaleUserId = OpenScale.getInstance().getSelectedScaleUserId();
            int soehnleUserIndex = getSoehnleUserIndex(openScaleUserId);
            if (soehnleUserIndex == -1) {
                // create new user
                Timber.d("create new Soehnle scale user");
                writeBytes(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_CONTROL_POINT, new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x00 });
            } else {
                // select user
                Timber.d("select Soehnle scale user with index " + soehnleUserIndex);
                writeBytes(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_CONTROL_POINT, new byte[] { (byte) 0x02, (byte) soehnleUserIndex, (byte) 0x00, (byte) 0x00 });
            }
            break;
        case 5:
            // set age
            writeBytes(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_AGE, new byte[] { (byte) OpenScale.getInstance().getSelectedScaleUser().getAge() });
            break;
        case 6:
            // set gender
            writeBytes(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_GENDER, new byte[] { OpenScale.getInstance().getSelectedScaleUser().getGender().isMale() ? (byte) 0x00 : (byte) 0x01 });
            break;
        case 7:
            // set height
            writeBytes(BluetoothGattUuid.SERVICE_USER_DATA, BluetoothGattUuid.CHARACTERISTIC_USER_HEIGHT, Converters.toInt16Le((int) OpenScale.getInstance().getSelectedScaleUser().getBodyHeight()));
            break;
        case 8:
            setNotificationOn(WEIGHT_CUSTOM_SERVICE, WEIGHT_CUSTOM_A_CHARACTERISTIC);
            setNotificationOn(WEIGHT_CUSTOM_SERVICE, WEIGHT_CUSTOM_B_CHARACTERISTIC);
            // writeBytes(WEIGHT_CUSTOM_SERVICE, WEIGHT_CUSTOM_CMD_CHARACTERISTIC, new byte[] {(byte)0x0c, (byte)0xff});
            break;
        case 9:
            for (int i = 1; i < 8; i++) {
                // get history data for soehnle user index i
                writeBytes(WEIGHT_CUSTOM_SERVICE, WEIGHT_CUSTOM_CMD_CHARACTERISTIC, new byte[] { (byte) 0x09, (byte) i });
            }
            break;
        default:
            return false;
    }
    return true;
}
Also used : BluetoothBytesParser(com.welie.blessed.BluetoothBytesParser) ScaleUser(com.health.openscale.core.datatypes.ScaleUser)

Example 15 with BluetoothBytesParser

use of com.welie.blessed.BluetoothBytesParser in project openScale by oliexdev.

the class BluetoothStandardWeightProfile method handleVendorSpecificUserList.

protected void handleVendorSpecificUserList(byte[] value) {
    Timber.d(String.format("Got user data: <%s>", byteInHex(value)));
    BluetoothBytesParser parser = new BluetoothBytesParser(value);
    int userListStatus = parser.getIntValue(FORMAT_UINT8);
    if (userListStatus == 2) {
        Timber.d("scale have no users!");
        storeUserScaleConsentCode(selectedUser.getId(), -1);
        storeUserScaleIndex(selectedUser.getId(), -1);
        jumpNextToStepNr(SM_STEPS.REGISTER_NEW_SCALE_USER.ordinal());
        resumeMachineState();
        return;
    } else if (userListStatus == 1) {
        for (int i = 0; i < scaleUserList.size(); i++) {
            if (i == 0) {
                Timber.d("scale user list:");
            }
            Timber.d("\n" + (i + 1) + ". " + scaleUserList.get(i));
        }
        if ((scaleUserList.size() == 0)) {
            storeUserScaleConsentCode(selectedUser.getId(), -1);
            storeUserScaleIndex(selectedUser.getId(), -1);
            jumpNextToStepNr(SM_STEPS.REGISTER_NEW_SCALE_USER.ordinal());
            resumeMachineState();
            return;
        }
        if (getUserScaleIndex(selectedUser.getId()) == -1 || getUserScaleConsent(selectedUser.getId()) == -1) {
            chooseExistingScaleUser(scaleUserList);
            return;
        }
        resumeMachineState();
        return;
    }
    int index = parser.getIntValue(FORMAT_UINT8);
    String initials = parser.getStringValue();
    int end = 3 > initials.length() ? initials.length() : 3;
    initials = initials.substring(0, end);
    if (initials.length() == 3) {
        if (initials.charAt(0) == 0xff && initials.charAt(1) == 0xff && initials.charAt(2) == 0xff) {
            initials = "";
        }
    }
    parser.setOffset(5);
    int year = parser.getIntValue(FORMAT_UINT16);
    int month = parser.getIntValue(FORMAT_UINT8);
    int day = parser.getIntValue(FORMAT_UINT8);
    int height = parser.getIntValue(FORMAT_UINT8);
    int gender = parser.getIntValue(FORMAT_UINT8);
    int activityLevel = parser.getIntValue(FORMAT_UINT8);
    GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
    ScaleUser scaleUser = new ScaleUser();
    scaleUser.setUserName(initials);
    scaleUser.setBirthday(calendar.getTime());
    scaleUser.setBodyHeight(height);
    scaleUser.setGender(Converters.Gender.fromInt(gender));
    scaleUser.setActivityLevel(Converters.ActivityLevel.fromInt(activityLevel - 1));
    scaleUser.setId(index);
    scaleUserList.add(scaleUser);
    if (scaleUserList.size() == getVendorSpecificMaxUserCount()) {
        if (getUserScaleIndex(selectedUser.getId()) == -1 || getUserScaleConsent(selectedUser.getId()) == -1) {
            chooseExistingScaleUser(scaleUserList);
            return;
        }
        resumeMachineState();
    }
}
Also used : BluetoothBytesParser(com.welie.blessed.BluetoothBytesParser) ScaleUser(com.health.openscale.core.datatypes.ScaleUser) GregorianCalendar(java.util.GregorianCalendar)

Aggregations

BluetoothBytesParser (com.welie.blessed.BluetoothBytesParser)22 Date (java.util.Date)3 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)2 ScaleUser (com.health.openscale.core.datatypes.ScaleUser)2 Converters (com.health.openscale.core.utils.Converters)1 GregorianCalendar (java.util.GregorianCalendar)1