Search in sources :

Example 46 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class BluetoothMiScale2 method nextInitCmd.

@Override
boolean nextInitCmd(int stateNr) {
    switch(stateNr) {
        case 0:
            // set scale units
            final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
            byte[] setUnitCmd = new byte[] { (byte) 0x06, (byte) 0x04, (byte) 0x00, (byte) selectedUser.getScaleUnit().toInt() };
            writeBytes(WEIGHT_CUSTOM_SERVICE, WEIGHT_CUSTOM_CONFIG, setUnitCmd);
            break;
        case 1:
            // set current time
            Calendar currentDateTime = Calendar.getInstance();
            int year = currentDateTime.get(Calendar.YEAR);
            byte month = (byte) (currentDateTime.get(Calendar.MONTH) + 1);
            byte day = (byte) currentDateTime.get(Calendar.DAY_OF_MONTH);
            byte hour = (byte) currentDateTime.get(Calendar.HOUR_OF_DAY);
            byte min = (byte) currentDateTime.get(Calendar.MINUTE);
            byte sec = (byte) currentDateTime.get(Calendar.SECOND);
            byte[] dateTimeByte = { (byte) (year), (byte) (year >> 8), month, day, hour, min, sec, 0x03, 0x00, 0x00 };
            writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC, dateTimeByte);
            break;
        case 2:
            // set notification on for weight measurement history
            setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_HISTORY_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
            break;
        default:
            return false;
    }
    return true;
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser) Calendar(java.util.Calendar)

Example 47 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class BluetoothSanitasSbf70 method setUnitCommand.

private void setUnitCommand() {
    byte[] command = SET_UNIT_COMMAND;
    final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
    switch(selectedUser.getScaleUnit()) {
        case KG:
            command[2] = (byte) 0x01;
            break;
        case LB:
            command[2] = (byte) 0x02;
            break;
        case ST:
            command[3] = (byte) 0x04;
            break;
    }
    Log.d(TAG, "Setting unit " + selectedUser.getScaleUnit().toString());
    writeBytes(command);
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser)

Example 48 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class BluetoothYunmaiMini method nextInitCmd.

@Override
boolean nextInitCmd(int stateNr) {
    switch(stateNr) {
        case 0:
            int user_id = getUniqueNumber();
            final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
            byte sex = selectedUser.getGender().isMale() ? (byte) 0x01 : (byte) 0x02;
            byte display_unit = selectedUser.getScaleUnit() == Converters.WeightUnit.KG ? (byte) 0x01 : (byte) 0x02;
            byte[] user_add_or_query = new byte[] { (byte) 0x0d, (byte) 0x12, (byte) 0x10, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) ((user_id & 0xFF00) >> 8), (byte) ((user_id & 0xFF) >> 0), (byte) selectedUser.getBodyHeight(), (byte) sex, (byte) selectedUser.getAge(new Date()), (byte) 0x55, (byte) 0x5a, (byte) 0x00, (byte) 0x00, (byte) display_unit, (byte) 0x03, (byte) 0x00 };
            user_add_or_query[17] = xor_checksum(user_add_or_query);
            writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, user_add_or_query);
            break;
        case 1:
            long unix_time = new Date().getTime() / 1000;
            byte[] set_time = new byte[] { (byte) 0x0d, (byte) 0x0d, (byte) 0x11, (byte) ((unix_time & 0xFF000000) >> 32), (byte) ((unix_time & 0xFF0000) >> 16), (byte) ((unix_time & 0xFF00) >> 8), (byte) ((unix_time & 0xFF) >> 0), (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
            set_time[12] = xor_checksum(set_time);
            writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, set_time);
            break;
        case 2:
            setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
            break;
        case 3:
            byte[] magic_bytes = new byte[] { (byte) 0x0d, (byte) 0x05, (byte) 0x13, (byte) 0x00, (byte) 0x16 };
            writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, magic_bytes);
            break;
        default:
            return false;
    }
    return true;
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser) Date(java.util.Date)

Example 49 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class BluetoothYunmaiSE method nextInitCmd.

@Override
boolean nextInitCmd(int stateNr) {
    switch(stateNr) {
        case 0:
            int user_id = getUniqueNumber();
            final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
            byte sex = selectedUser.getGender().isMale() ? (byte) 0x01 : (byte) 0x02;
            byte display_unit = selectedUser.getScaleUnit() == Converters.WeightUnit.KG ? (byte) 0x01 : (byte) 0x02;
            byte[] user_add_or_query = new byte[] { (byte) 0x0d, (byte) 0x12, (byte) 0x10, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) ((user_id & 0xFF00) >> 8), (byte) ((user_id & 0xFF) >> 0), (byte) selectedUser.getBodyHeight(), (byte) sex, (byte) selectedUser.getAge(new Date()), (byte) 0x55, (byte) 0x5a, (byte) 0x00, (byte) 0x00, (byte) display_unit, (byte) 0x03, (byte) 0x00 };
            user_add_or_query[17] = xor_checksum(user_add_or_query);
            writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, user_add_or_query);
            break;
        case 1:
            long unix_time = new Date().getTime() / 1000;
            byte[] set_time = new byte[] { (byte) 0x0d, (byte) 0x0d, (byte) 0x11, (byte) ((unix_time & 0xFF000000) >> 32), (byte) ((unix_time & 0xFF0000) >> 16), (byte) ((unix_time & 0xFF00) >> 8), (byte) ((unix_time & 0xFF) >> 0), (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
            set_time[12] = xor_checksum(set_time);
            writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, set_time);
            break;
        case 2:
            setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, WEIGHT_MEASUREMENT_CONFIG);
            break;
        case 3:
            byte[] magic_bytes = new byte[] { (byte) 0x0d, (byte) 0x05, (byte) 0x13, (byte) 0x00, (byte) 0x16 };
            writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, magic_bytes);
            break;
        default:
            return false;
    }
    return true;
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser) Date(java.util.Date)

Example 50 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class BluetoothExcelvanCF36xBLE method onNextStep.

@Override
protected boolean onNextStep(int stepNr) {
    switch(stepNr) {
        case 0:
            final ScaleUser selectedUser = OpenScale.getInstance().getSelectedScaleUser();
            byte userId = (byte) 0x01;
            byte sex = selectedUser.getGender().isMale() ? (byte) 0x01 : (byte) 0x00;
            // 0x00 = ordinary, 0x01 = amateur, 0x02 = professional
            byte exerciseLevel = (byte) 0x01;
            switch(selectedUser.getActivityLevel()) {
                case SEDENTARY:
                case MILD:
                    exerciseLevel = (byte) 0x00;
                    break;
                case MODERATE:
                    exerciseLevel = (byte) 0x01;
                    break;
                case HEAVY:
                case EXTREME:
                    exerciseLevel = (byte) 0x02;
                    break;
            }
            byte height = (byte) selectedUser.getBodyHeight();
            byte age = (byte) selectedUser.getAge();
            // kg
            byte unit = 0x01;
            switch(selectedUser.getScaleUnit()) {
                case LB:
                    unit = 0x02;
                    break;
                case ST:
                    unit = 0x04;
                    break;
            }
            byte[] configBytes = { (byte) 0xfe, userId, sex, exerciseLevel, height, age, unit, (byte) 0x00 };
            configBytes[configBytes.length - 1] = xorChecksum(configBytes, 1, configBytes.length - 2);
            writeBytes(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_MEASUREMENT_CHARACTERISTIC, configBytes);
            break;
        case 1:
            setNotificationOn(WEIGHT_MEASUREMENT_SERVICE, WEIGHT_CUSTOM0_CHARACTERISTIC);
            break;
        case 2:
            sendMessage(R.string.info_step_on_scale, 0);
            break;
        default:
            return false;
    }
    return true;
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser)

Aggregations

ScaleUser (com.health.openscale.core.datatypes.ScaleUser)69 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)23 Date (java.util.Date)21 Calendar (java.util.Calendar)9 OpenScale (com.health.openscale.core.OpenScale)8 ParseException (java.text.ParseException)6 Converters (com.health.openscale.core.utils.Converters)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 SimpleDateFormat (java.text.SimpleDateFormat)3 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 Uri (android.net.Uri)2 ArrayAdapter (android.widget.ArrayAdapter)2 Spinner (android.widget.Spinner)2 TableRow (android.widget.TableRow)2 TextView (android.widget.TextView)2