Skip to content

Commit

Permalink
Merge remote-tracking branch 'oliexdev/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolkenschieber committed Dec 14, 2017
2 parents e3814b7 + e8170ac commit 9c4f6f8
Show file tree
Hide file tree
Showing 58 changed files with 1,608 additions and 942 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android:
components:
- platform-tools
- tools
- build-tools-25.0.2
- build-tools-26.0.2
- android-24
- extra-android-m2repository

Expand All @@ -23,4 +23,4 @@ after_success:
- chmod +x ./upload_apk.sh
- ./upload_apk.sh

script: cd android_app && ./gradlew assembleDebug
script: cd android_app && ./gradlew assembleDebug
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Please see in the [openScale wiki](https://github.com/oliexdev/openScale/wiki/Su

If you found a bug, have an idea how to improve the openScale app or have a question, please create new issue or comment existing one. If you would like to contribute code, fork the repository and send a pull request.

If you want to help to support your Bluetooth scale please see [here](https://github.com/oliexdev/openScale/wiki/How-to-reverse-engineer-a-Blueeoth-4.x-scale) for further information.
If you want to help to support your Bluetooth scale please see [here](https://github.com/oliexdev/openScale/wiki/How-to-reverse-engineer-a-Bluetooth-4.x-scale) for further information.

# Screens

Expand Down
1 change: 0 additions & 1 deletion android_app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '25.0.2'

defaultConfig {
applicationId "com.health.openscale"
Expand Down
144 changes: 73 additions & 71 deletions android_app/app/src/main/java/com/health/openscale/core/OpenScale.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,40 @@

public class OpenScale {

private static OpenScale instance;
private static OpenScale instance;

private ScaleDatabase scaleDB;
private ScaleDatabase scaleDB;
private ScaleUserDatabase scaleUserDB;
private ArrayList<ScaleData> scaleDataList;
private ArrayList<ScaleData> scaleDataList;

private BluetoothCommunication btCom;
private String btDeviceName;
private BluetoothCommunication btCom;
private String btDeviceName;
private AlarmHandler alarmHandler;

private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");

private Context context;

private ArrayList<FragmentUpdateListener> fragmentList;

private OpenScale(Context context) {
private OpenScale(Context context) {
this.context = context;
scaleDB = new ScaleDatabase(context);
scaleDB = new ScaleDatabase(context);
scaleUserDB = new ScaleUserDatabase(context);
alarmHandler = new AlarmHandler();
btCom = null;
fragmentList = new ArrayList<>();

updateScaleData();
}
}

public static OpenScale getInstance(Context context) {
if (instance == null) {
instance = new OpenScale(context);
}
public static OpenScale getInstance(Context context) {
if (instance == null) {
instance = new OpenScale(context);
}

return instance;
}
return instance;
}

public void addScaleUser(String name, Date birthday, int body_height, int scale_unit, int gender, float initial_weight, float goal_weight, Date goal_date)
{
Expand Down Expand Up @@ -156,17 +156,17 @@ public void updateScaleUser(int id, String name, Date birthday, int body_height,
}


public ArrayList<ScaleData> getScaleDataList() {
return scaleDataList;
}
public ArrayList<ScaleData> getScaleDataList() {
return scaleDataList;
}


public ScaleData[] getTupleScaleData(long id)
{
return scaleDB.getTupleDataEntry(getSelectedScaleUser().id, id);
}

public int addScaleData(ScaleData scaleData) {
public int addScaleData(ScaleData scaleData) {

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

Expand Down Expand Up @@ -201,7 +201,7 @@ public int addScaleData(ScaleData scaleData) {
scaleData.setFat(fatMetric.getFat(getScaleUser(scaleData.getUserId()), scaleData));
}

if (scaleDB.insertEntry(scaleData)) {
if (scaleDB.insertEntry(scaleData)) {
ScaleUser scaleUser = getScaleUser(scaleData.getUserId());

String infoText = String.format(context.getString(R.string.info_new_data_added), scaleData.getConvertedWeight(scaleUser.scale_unit), scaleUser.UNIT_STRING[scaleUser.scale_unit], dateTimeFormat.format(scaleData.getDateTime()), scaleUser.user_name);
Expand All @@ -211,7 +211,7 @@ public int addScaleData(ScaleData scaleData) {
}

return scaleData.getUserId();
}
}

private int getSmartUserAssignment(float weight, float range) {
ArrayList<ScaleUser> scaleUser = getScaleUserList();
Expand Down Expand Up @@ -263,31 +263,31 @@ public void deleteScaleData(long id)
updateScaleData();
}

public void importData(String filename) throws IOException {
File file = new File(filename);
public void importData(String filename) throws IOException {
File file = new File(filename);

FileInputStream inputStream = new FileInputStream(file);
FileInputStream inputStream = new FileInputStream(file);

InputStreamReader inputReader = new InputStreamReader(inputStream);
BufferedReader csvReader = new BufferedReader(inputReader);
InputStreamReader inputReader = new InputStreamReader(inputStream);
BufferedReader csvReader = new BufferedReader(inputReader);

String line = csvReader.readLine();
String line = csvReader.readLine();

try {
while (line != null) {
String csvField[] = line.split(",", -1);
try {
while (line != null) {
String csvField[] = line.split(",", -1);

if (csvField.length < 9) {
throw new IOException("Can't parse CSV file. Field length is wrong.");
}

ScaleData newScaleData = new ScaleData();
ScaleData newScaleData = new ScaleData();

newScaleData.setDateTime(dateTimeFormat.parse(csvField[0]));
newScaleData.setWeight(Float.parseFloat(csvField[1]));
newScaleData.setFat(Float.parseFloat(csvField[2]));
newScaleData.setWater(Float.parseFloat(csvField[3]));
newScaleData.setMuscle(Float.parseFloat(csvField[4]));
newScaleData.setDateTime(dateTimeFormat.parse(csvField[0]));
newScaleData.setWeight(Float.parseFloat(csvField[1]));
newScaleData.setFat(Float.parseFloat(csvField[2]));
newScaleData.setWater(Float.parseFloat(csvField[3]));
newScaleData.setMuscle(Float.parseFloat(csvField[4]));
newScaleData.setLBW(Float.parseFloat(csvField[5]));
newScaleData.setBone(Float.parseFloat(csvField[6]));
newScaleData.setWaist(Float.parseFloat(csvField[7]));
Expand All @@ -296,37 +296,39 @@ public void importData(String filename) throws IOException {

newScaleData.setUserId(getSelectedScaleUser().id);

scaleDB.insertEntry(newScaleData);
scaleDB.insertEntry(newScaleData);

line = csvReader.readLine();
}
line = csvReader.readLine();
}

} catch (ParseException e) {
throw new IOException("Can't parse date format. Please set the date time format as <dd.MM.yyyy HH:mm> (e.g. 31.10.2014 05:23)");
} catch (NumberFormatException e) {
} catch (ParseException e) {
throw new IOException("Can't parse date format. Please set the date time format as <dd.MM.yyyy HH:mm> (e.g. 31.10.2014 05:23)");
} catch (NumberFormatException e) {
throw new IOException("Can't parse float number (" + e.getMessage()+")");
} catch (ArrayIndexOutOfBoundsException e) {
throw new IOException("Can't parse format column number mismatch");
}

updateScaleData();

csvReader.close();
inputReader.close();
}
csvReader.close();
inputReader.close();
}

public void exportData(String filename) throws IOException {
File file = new File(filename);
file.createNewFile();
public void exportData(String filename) throws IOException {
File file = new File(filename);
file.createNewFile();

FileOutputStream outputStream = new FileOutputStream(file);
FileOutputStream outputStream = new FileOutputStream(file);

OutputStreamWriter csvWriter = new OutputStreamWriter(outputStream);
OutputStreamWriter csvWriter = new OutputStreamWriter(outputStream);

for (ScaleData scaleData : scaleDataList) {
csvWriter.append(dateTimeFormat.format(scaleData.getDateTime()) + ",");
csvWriter.append(Float.toString(scaleData.getWeight()) + ",");
csvWriter.append(Float.toString(scaleData.getFat()) + ",");
csvWriter.append(Float.toString(scaleData.getWater()) + ",");
csvWriter.append(Float.toString(scaleData.getMuscle()) + ",");
for (ScaleData scaleData : scaleDataList) {
csvWriter.append(dateTimeFormat.format(scaleData.getDateTime()) + ",");
csvWriter.append(Float.toString(scaleData.getWeight()) + ",");
csvWriter.append(Float.toString(scaleData.getFat()) + ",");
csvWriter.append(Float.toString(scaleData.getWater()) + ",");
csvWriter.append(Float.toString(scaleData.getMuscle()) + ",");
csvWriter.append(Float.toString(scaleData.getLBW()) + ",");
csvWriter.append(Float.toString(scaleData.getBone()) + ",");
csvWriter.append(Float.toString(scaleData.getWaist()) + ",");
Expand All @@ -335,20 +337,20 @@ public void exportData(String filename) throws IOException {
csvWriter.append(scaleData.getComment());
}

csvWriter.append("\n");
}
csvWriter.append("\n");
}

csvWriter.close();
outputStream.close();
}
csvWriter.close();
outputStream.close();
}

public void clearScaleData(int userId) {
public void clearScaleData(int userId) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt("uniqueNumber", 0x00).commit();
scaleDB.clearScaleData(userId);
scaleDB.clearScaleData(userId);

updateScaleData();
}
}

public int[] getCountsOfMonth(int year) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Expand All @@ -371,8 +373,8 @@ public ArrayList<ScaleData> getScaleDataOfYear(int year) {
return scaleDB.getScaleDataOfYear(selectedUserId, year);
}

public boolean startSearchingForBluetooth(String deviceName, Handler callbackBtHandler) {
Log.d("OpenScale", "Bluetooth Server started! I am searching for device ...");
public boolean startSearchingForBluetooth(String deviceName, Handler callbackBtHandler) {
Log.d("OpenScale", "Bluetooth Server started! I am searching for device ...");

for (BluetoothCommunication.BT_DEVICE_ID btScaleID : BluetoothCommunication.BT_DEVICE_ID.values()) {
btCom = BluetoothCommunication.getBtDevice(context, btScaleID);
Expand All @@ -390,12 +392,12 @@ public boolean startSearchingForBluetooth(String deviceName, Handler callbackBtH
return false;
}

public void stopSearchingForBluetooth() {
if (btCom != null) {
public void stopSearchingForBluetooth() {
if (btCom != null) {
btCom.stopSearching();
Log.d("OpenScale", "Bluetooth Server explicit stopped!");
}
}
}
}

public void registerFragment(FragmentUpdateListener fragment) {
fragmentList.add(fragment);
Expand All @@ -415,7 +417,7 @@ public void updateScaleData()

scaleDataList = scaleDB.getScaleDataList(selectedUserId);

for(FragmentUpdateListener fragment : fragmentList) {
for (FragmentUpdateListener fragment : fragmentList) {
if (fragment != null) {
if (((Fragment)fragment).isAdded()) {
fragment.updateOnView(scaleDataList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void entryChanged(Context context, ScaleData data)
Calendar dataTimestamp = Calendar.getInstance();
dataTimestamp.setTimeInMillis(dataMillis);

if(AlarmHandler.isSameDate(dataTimestamp, Calendar.getInstance()))
if (AlarmHandler.isSameDate(dataTimestamp, Calendar.getInstance()))
{
cancelAlarmNotification(context);
cancelAndRescheduleAlarmForNextWeek( context, dataTimestamp );
cancelAndRescheduleAlarmForNextWeek(context, dataTimestamp);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public enum BT_STATUS_CODE {BT_RETRIEVE_SCALE_DATA, BT_INIT_PROCESS, BT_CONNECTI
BT_CONNECTION_LOST, BT_NO_DEVICE_FOUND, BT_UNEXPECTED_ERROR, BT_SCALE_MESSAGE
};
public enum BT_MACHINE_STATE {BT_INIT_STATE, BT_CMD_STATE, BT_CLEANUP_STATE}
public enum BT_DEVICE_ID {CUSTOM_OPENSCALE, MI_SCALE_V1, MI_SCALE_V2, SANITAS_SBF70, MEDISANA_BS444, DIGOO_DGS038H, EXCELVANT_CF369BLE, YUNMAI_MINI, YUNMAI_SE, MGB}
public enum BT_DEVICE_ID {CUSTOM_OPENSCALE, MI_SCALE_V1, MI_SCALE_V2, SANITAS_SBF70, MEDISANA_BS444, DIGOO_DGS038H, EXCELVANT_CF369BLE, YUNMAI_MINI, YUNMAI_SE, MGB, EXINGTECH_Y1}

protected Context context;

Expand Down Expand Up @@ -97,6 +97,8 @@ public static BluetoothCommunication getBtDevice(Context context, BT_DEVICE_ID b
return new BluetoothYunmaiSE(context);
case MGB:
return new BluetoothMGB(context);
case EXINGTECH_Y1:
return new BluetoothExingtechY1(context);
}

return null;
Expand Down Expand Up @@ -240,15 +242,15 @@ protected void setNextCmd(int nextCommand) {
* @param gattCharacteristic the Bluetooth Gatt characteristic
* @param status the status code
*/
protected void onBluetoothDataRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic, int status){};
protected void onBluetoothDataRead(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic, int status) {};

/**
* Method is triggered if a Bluetooth data from a device is notified or indicated.
*
* @param bluetoothGatt the Bluetooth Gatt
* @param gattCharacteristic the Bluetooth characteristic
*/
protected void onBluetoothDataChange(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic){};
protected void onBluetoothDataChange(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic gattCharacteristic) {};

/**
* Set the Bluetooth machine state to a specific state.
Expand Down Expand Up @@ -369,7 +371,7 @@ protected String byteInHex(byte[] data) {
}

final StringBuilder stringBuilder = new StringBuilder(data.length);
for(byte byteChar : data) {
for (byte byteChar : data) {
stringBuilder.append(String.format("%02X ", byteChar));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void stopSearching() {
btConnectThread = null;
}
}

public void clearEEPROM()
{
sendBtData("9");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void parseBytes(byte[] weightBytes) {
ScaleData scaleBtData = new ScaleData();
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) {
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 {
Expand Down
Loading

0 comments on commit 9c4f6f8

Please sign in to comment.