use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class BluetoothExingtechY1 method parseBytes.
private void parseBytes(byte[] weightBytes) {
int userId = (int) (weightBytes[0] & 0x0F);
// 0x00 male; 0x01 female
int gender = (int) (weightBytes[1]);
// 10 ~ 99
int age = (int) (weightBytes[2]);
// 0 ~ 255
int height = (int) (weightBytes[3]);
// kg
float weight = (float) (((weightBytes[4] & 0xFF) << 8) | (weightBytes[5] & 0xFF)) / 10.0f;
// %
float fat = (float) (((weightBytes[6] & 0xFF) << 8) | (weightBytes[7] & 0xFF)) / 10.0f;
// %
float water = (float) (((weightBytes[8] & 0xFF) << 8) | (weightBytes[9] & 0xFF)) / 10.0f;
// kg
float bone = (float) (((weightBytes[10] & 0xFF) << 8) | (weightBytes[11] & 0xFF)) / weight * 10.0f;
// %
float muscle = (float) (((weightBytes[12] & 0xFF) << 8) | (weightBytes[13] & 0xFF)) / 10.0f;
// %
float visc_muscle = (float) (weightBytes[14] & 0xFF);
float calorie = (float) (((weightBytes[15] & 0xFF) << 8) | (weightBytes[16] & 0xFF));
float bmi = (float) (((weightBytes[17] & 0xFF) << 8) | (weightBytes[18] & 0xFF)) / 10.0f;
ScaleMeasurement scaleBtData = new ScaleMeasurement();
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
scaleBtData.setConvertedWeight(weight, selectedUser.getScaleUnit());
scaleBtData.setFat(fat);
scaleBtData.setMuscle(muscle);
scaleBtData.setWater(water);
scaleBtData.setBone(bone);
scaleBtData.setDateTime(new Date());
addScaleData(scaleBtData);
}
use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class BluetoothHesley method parseBytes.
private void parseBytes(byte[] weightBytes) {
// 10 ~ 99
int bodyage = (int) (weightBytes[17]);
// kg
float weight = (float) (((weightBytes[2] & 0xFF) << 8) | (weightBytes[3] & 0xFF)) / 100.0f;
// %
float fat = (float) (((weightBytes[4] & 0xFF) << 8) | (weightBytes[5] & 0xFF)) / 10.0f;
// %
float water = (float) (((weightBytes[8] & 0xFF) << 8) | (weightBytes[9] & 0xFF)) / 10.0f;
// %
float muscle = (float) (((weightBytes[10] & 0xFF) << 8) | (weightBytes[11] & 0xFF)) / 10.0f;
// %
float bone = (float) (((weightBytes[12] & 0xFF) << 8) | (weightBytes[13] & 0xFF)) / 10.0f;
// kcal
float calorie = (float) (((weightBytes[14] & 0xFF) << 8) | (weightBytes[15] & 0xFF));
ScaleMeasurement scaleBtData = new ScaleMeasurement();
scaleBtData.setWeight(weight);
scaleBtData.setFat(fat);
scaleBtData.setMuscle(muscle);
scaleBtData.setWater(water);
scaleBtData.setBone(bone);
scaleBtData.setDateTime(new Date());
addScaleData(scaleBtData);
}
use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class ScaleDatabase method readAtCursor.
private ScaleMeasurement readAtCursor(Cursor cur) {
ScaleMeasurement scaleMeasurement = new ScaleMeasurement();
try {
scaleMeasurement.setId(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_ID)));
scaleMeasurement.setUserId(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_USER_ID)));
String date_time = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_DATE_TIME));
scaleMeasurement.setWeight(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WEIGHT)));
scaleMeasurement.setFat(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_FAT)));
scaleMeasurement.setWater(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WATER)));
scaleMeasurement.setMuscle(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_MUSCLE)));
scaleMeasurement.setLbw(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_LBW)));
scaleMeasurement.setBone(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_BONE)));
scaleMeasurement.setWaist(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WAIST)));
scaleMeasurement.setHip(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_HIP)));
scaleMeasurement.setComment(cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_COMMENT)));
scaleMeasurement.setDateTime(formatDateTime.parse(date_time));
} catch (ParseException ex) {
Log.e("ScaleDatabase", "Can't parse the date time string: " + ex.getMessage());
} catch (IllegalArgumentException ex) {
Log.e("ScaleDatabase", "Illegal argument while reading from scale database: " + ex.getMessage());
}
return scaleMeasurement;
}
use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class ScaleDatabase method getScaleDataList.
public ArrayList<ScaleMeasurement> getScaleDataList(int userId) {
ArrayList<ScaleMeasurement> scaleMeasurementList = new ArrayList<ScaleMeasurement>();
try {
String sortOrder = COLUMN_NAME_DATE_TIME + " DESC";
Cursor cursorScaleDB = getReadableDatabase().query(// The table to query
TABLE_NAME, // The columns to return
projection, // The columns for the WHERE clause
COLUMN_NAME_USER_ID + "=? AND " + COLUMN_NAME_ENABLE + "=1", // The values for the WHERE clause
new String[] { Integer.toString(userId) }, // don't group the rows
null, // don't filter by row groups
null, // The sort order
sortOrder);
cursorScaleDB.moveToFirst();
while (!cursorScaleDB.isAfterLast()) {
scaleMeasurementList.add(readAtCursor(cursorScaleDB));
cursorScaleDB.moveToNext();
}
cursorScaleDB.close();
} catch (SQLException ex) {
Log.e("ScaleDatabase", "SQL exception occured while getting scale data list: " + ex.getMessage());
}
return scaleMeasurementList;
}
use of com.health.openscale.core.datatypes.ScaleMeasurement in project openScale by oliexdev.
the class CsvHelperTest method oldVersion10SingleEntry.
@Test
public void oldVersion10SingleEntry() throws Exception {
final String data = "01.03.2018 12:45,8.0,2.0,7.0,some text\n";
List<ScaleMeasurement> list = CsvHelper.importFrom(new BufferedReader(new StringReader(data)));
assertEquals(1, list.size());
validateEntry(list.get(0), 0);
}
Aggregations