use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class OverviewFragment method updateOnView.
@Override
public void updateOnView(List<ScaleMeasurement> scaleMeasurementList) {
if (scaleMeasurementList.isEmpty()) {
lastScaleMeasurement = new ScaleMeasurement();
} else if (userSelectedData != null) {
lastScaleMeasurement = userSelectedData;
} else {
lastScaleMeasurement = scaleMeasurementList.get(0);
}
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(context).getTupleScaleData(lastScaleMeasurement.getId());
ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
updateUserSelection();
updateLastPieChart();
updateLastLineChart(scaleMeasurementList);
for (MeasurementView measurement : measurementViews) {
measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement);
}
}
use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class StatisticsFragment method updateGoal.
private void updateGoal() {
final Converters.WeightUnit unit = currentScaleUser.getScaleUnit();
ScaleMeasurement goalScaleMeasurement = new ScaleMeasurement();
goalScaleMeasurement.setUserId(currentScaleUser.getId());
goalScaleMeasurement.setConvertedWeight(currentScaleUser.getGoalWeight(), unit);
txtGoalWeight.setText(String.format("%.1f %s", goalScaleMeasurement.getConvertedWeight(unit), unit.toString()));
double weight_diff = goalScaleMeasurement.getConvertedWeight(unit) - lastScaleMeasurement.getConvertedWeight(unit);
txtGoalDiff.setText(String.format("%.1f %s", weight_diff, unit.toString()));
Calendar goalCalendar = Calendar.getInstance();
goalCalendar.setTime(currentScaleUser.getGoalDate());
int days = Math.max(0, DateTimeHelpers.daysBetween(Calendar.getInstance(), goalCalendar));
txtGoalDayLeft.setText(getResources().getQuantityString(R.plurals.label_days, days, days));
final float goalBmi = goalScaleMeasurement.getBMI(currentScaleUser.getBodyHeight());
txtLabelGoalWeight.setText(Html.fromHtml(getResources().getString(R.string.label_goal_weight) + " <br> <font color='grey'><small>" + getResources().getString(R.string.label_bmi) + ": " + String.format("%.1f", goalBmi) + " </small></font>"));
txtLabelGoalDiff.setText(Html.fromHtml(getResources().getString(R.string.label_weight_difference) + " <br> <font color='grey'><small>" + getResources().getString(R.string.label_bmi) + ": " + String.format("%.1f", lastScaleMeasurement.getBMI(currentScaleUser.getBodyHeight()) - goalBmi) + " </small></font>"));
txtLabelDayLeft.setText(Html.fromHtml(getResources().getString(R.string.label_days_left) + " <br> <font color='grey'><small>" + getResources().getString(R.string.label_goal_date_is) + " " + DateFormat.getDateInstance(DateFormat.LONG).format(currentScaleUser.getGoalDate()) + " </small></font>"));
}
use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class DataEntryActivity method updateOnView.
private void updateOnView() {
int id = 0;
if (getIntent().hasExtra(EXTRA_ID)) {
id = getIntent().getExtras().getInt(EXTRA_ID);
}
if (scaleMeasurement == null || scaleMeasurement.getId() != id) {
isDirty = false;
scaleMeasurement = null;
previousMeasurement = null;
nextMeasurement = null;
}
OpenScale openScale = OpenScale.getInstance(context);
if (id > 0) {
// Show selected scale data
if (scaleMeasurement == null) {
ScaleMeasurement[] tupleScaleData = openScale.getTupleScaleData(id);
previousMeasurement = tupleScaleData[0];
scaleMeasurement = tupleScaleData[1].clone();
nextMeasurement = tupleScaleData[2];
btnLeft.setEnabled(previousMeasurement != null);
btnRight.setEnabled(nextMeasurement != null);
}
} else {
if (openScale.getScaleMeasurementList().isEmpty()) {
// Show default values
scaleMeasurement = new ScaleMeasurement();
scaleMeasurement.setWeight(openScale.getSelectedScaleUser().getInitialWeight());
} else {
// Show the last scale data as default
scaleMeasurement = openScale.getScaleMeasurementList().get(0).clone();
scaleMeasurement.setId(0);
scaleMeasurement.setDateTime(new Date());
scaleMeasurement.setComment("");
}
isDirty = true;
// clears these values.
for (MeasurementView measurement : dataEntryMeasurements) {
if (!measurement.isVisible()) {
measurement.clearIn(scaleMeasurement);
}
}
}
for (MeasurementView measurement : dataEntryMeasurements) {
measurement.loadFrom(scaleMeasurement, previousMeasurement);
}
txtDataNr.setMinWidth(txtDataNr.getWidth());
txtDataNr.setText(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(scaleMeasurement.getDateTime()));
}
use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class BluetoothBeurerBF700_800 method parseScaleData.
private ScaleMeasurement parseScaleData(byte[] data) throws ParseException {
if (data.length != 11 + 11)
throw new ParseException("Parse scala data: unexpected length", 0);
ScaleMeasurement receivedMeasurement = new ScaleMeasurement();
// Parse timestamp
long timestamp = ByteBuffer.wrap(data, 0, 4).getInt() * 1000L;
SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy 'at' h:mm a");
String date = sdf.format(timestamp);
// little endian
float weight = ((float) (((data[4] & 0xFF) << 8) + (data[5] & 0xFF))) * 50.0f / // unit is 50g
1000.0f;
receivedMeasurement.setWeight(weight);
// Parse impedance level
int impedance = ((data[6] & 0xFF) << 8) + (data[7] & 0xFF);
// Parse fat
float fat = ((float) (((data[8] & 0xFF) << 8) + (data[9] & 0xFF))) / // unit is 0.1%
10.0f;
receivedMeasurement.setFat(fat);
float water = ((float) (((data[10] & 0xFF) << 8) + (data[11] & 0xFF))) / // unit is 0.1%
10.0f;
receivedMeasurement.setWater(water);
float muscle = ((float) (((data[12] & 0xFF) << 8) + (data[13] & 0xFF))) / // unit is 0.1%
10.0f;
receivedMeasurement.setMuscle(muscle);
float boneMass = ((float) (((data[14] & 0xFF) << 8) + (data[15] & 0xFF))) * 50.0f / // unit is 50g
1000.0f;
receivedMeasurement.setBone(boneMass);
// basal metabolic rate
float bmr = ((float) (((data[16] & 0xFF) << 8) + (data[17] & 0xFF))) / 10.0f;
// active metabolic rate
int amr = ((data[18] & 0xFF) << 8) + (data[19] & 0xFF);
float bmi = ((data[20] & 0xFF) << 8) + (data[21] & 0xFF);
Log.i(TAG, "Measurement: " + date + " Impedance: " + impedance + " Weight:" + weight + " Fat: " + fat + " Water: " + water + " Muscle: " + muscle + " BoneMass: " + boneMass + " BMR: " + bmr + " AMR: " + amr + " BMI: " + bmi);
return receivedMeasurement;
}
use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class BluetoothDigooDGSO38H method parseBytes.
private void parseBytes(byte[] weightBytes) {
float weight, fat, water, muscle, boneWeight;
// float subcutaneousFat, visceralFat, metabolicBaseRate, biologicalAge, boneWeight;
final byte ctrlByte = weightBytes[5];
final boolean allValues = isBitSet(ctrlByte, 1);
final boolean weightStabilized = isBitSet(ctrlByte, 0);
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
if (weightStabilized) {
// The weight is stabilized, now we want to measure all available values
byte gender = selectedUser.getGender().isMale() ? (byte) 0x00 : (byte) 0x01;
byte height = (byte) (selectedUser.getBodyHeight() & 0xFF);
byte age = (byte) (selectedUser.getAge(new Date()) & 0xff);
// kg
byte unit = 0x01;
switch(selectedUser.getScaleUnit()) {
case LB:
unit = 0x02;
break;
case ST:
unit = 0x8;
break;
}
byte[] configBytes = new byte[] { (byte) 0x09, (byte) 0x10, (byte) 0x12, (byte) 0x11, (byte) 0x0d, (byte) 0x01, height, age, gender, unit, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
// Write checksum is sum of all bytes % 256
int checksum = 0x00;
for (int i = 3; i < configBytes.length - 1; i++) {
checksum += configBytes[i];
}
configBytes[15] = (byte) (checksum & 0xFF);
writeBytes(WEIGHT_MEASUREMENT_SERVICE, EXTRA_MEASUREMENT_CHARACTERISTIC, configBytes);
} else if (allValues) {
ScaleMeasurement scaleBtData = new ScaleMeasurement();
weight = (float) (((weightBytes[3] & 0xFF) << 8) | (weightBytes[4] & 0xFF)) / 100.0f;
fat = (float) (((weightBytes[6] & 0xFF) << 8) | (weightBytes[7] & 0xFF)) / 10.0f;
if (Math.abs(fat - 0.0) < 0.00001) {
Log.d("BluetoothDigooDGSO38H", "Scale signaled that measurement of all data " + "is done, but fat ist still zero. Settling for just adding weight.");
} else {
// subcutaneousFat = (float) (((weightBytes[8] & 0xFF) << 8) | (weightBytes[9] & 0xFF)) / 10.0f;
// visceralFat = (float) (weightBytes[10] & 0xFF) / 10.0f;
water = (float) (((weightBytes[11] & 0xFF) << 8) | (weightBytes[12] & 0xFF)) / 10.0f;
// metabolicBaseRate = (float) (((weightBytes[13] & 0xFF) << 8) | (weightBytes[14] & 0xFF));
// biologicalAge = (float) (weightBytes[15] & 0xFF) + 1;
muscle = (float) (((weightBytes[16] & 0xFF) << 8) | (weightBytes[17] & 0xFF)) / 10.0f;
boneWeight = (float) (weightBytes[18] & 0xFF) / 10.0f;
// TODO: Add extra measurements?
scaleBtData.setDateTime(new Date());
scaleBtData.setFat(fat);
scaleBtData.setMuscle(muscle);
scaleBtData.setWater(water);
scaleBtData.setBone(boneWeight);
}
scaleBtData.setConvertedWeight(weight, selectedUser.getScaleUnit());
addScaleData(scaleBtData);
}
}
Aggregations