1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-14 04:34:18 +02:00

optimize Mi scale history weight measurement

This commit is contained in:
OliE
2016-12-20 19:55:31 +01:00
parent 4613afd3e3
commit 4b0c2c20f6
6 changed files with 17 additions and 16 deletions

View File

@@ -24,10 +24,11 @@ public abstract class BluetoothCommunication {
public static final int BT_OPEN_SCALE = 1;
public static final int BT_RETRIEVE_SCALE_DATA = 0;
public static final int BT_CONNECTION_ESTABLISHED = 1;
public static final int BT_CONNECTION_LOST = 2;
public static final int BT_NO_DEVICE_FOUND = 3;
public static final int BT_UNEXPECTED_ERROR = 4;
public static final int BT_INIT_PROCESS = 1;
public static final int BT_CONNECTION_ESTABLISHED = 2;
public static final int BT_CONNECTION_LOST = 3;
public static final int BT_NO_DEVICE_FOUND = 4;
public static final int BT_UNEXPECTED_ERROR = 5;
protected Handler callbackBtHandler;
protected BluetoothAdapter btAdapter;

View File

@@ -14,11 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/*
* Modified version of Mnkai <https://github.com/Mnkai/OpenXiaomiScale> original BTUtils.java source code
* Copyright (C) Mnkai Apache 2.0 license <http://www.apache.org/licenses/LICENSE-2.0>
*/
package com.health.openscale.core;
import android.bluetooth.BluetoothAdapter;
@@ -77,7 +72,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
if (device.getAddress().replace(":", "").startsWith("880f10") ||
device.getAddress().replace(":", "").startsWith("880F10")) // Xiaomi
{
if (device.getName().equals(btDeviceName)) { // It really is scale
if (device.getName().equals(btDeviceName)) {
Log.d("BluetoothMiScale", "Mi Scale found trying to connect...");
bluetoothGatt = device.connectGatt(context, false, gattCallback);
@@ -142,8 +137,6 @@ public class BluetoothMiScale extends BluetoothCommunication {
BluetoothGattCharacteristic characteristic;
BluetoothGattDescriptor descriptor;
Log.d("BluetoothMiScale", "Cmd State " + nextCmdState);
switch (nextCmdState) {
case 0:
// read device time
@@ -202,10 +195,10 @@ public class BluetoothMiScale extends BluetoothCommunication {
initProcessOn = true;
Log.d("BluetoothMiScale", "Init State " + nextInitState);
switch (nextInitState) {
case 0:
callbackBtHandler.obtainMessage(BluetoothCommunication.BT_INIT_PROCESS).sendToTarget();
// set current time
characteristic = gatt.getService(WEIGHT_MEASUREMENT_SERVICE)
.getCharacteristic(WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC);
@@ -365,7 +358,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
callbackBtHandler.obtainMessage(BluetoothCommunication.BT_RETRIEVE_SCALE_DATA, scaleBtData).sendToTarget();
} else {
Log.e("BluetoothMiScale", "Invalid weight year " + year);
Log.e("BluetoothMiScale", "Invalid Mi scale weight year " + year);
}
}
} catch (ParseException e) {

View File

@@ -220,7 +220,11 @@ public class MainActivity extends ActionBarActivity implements
}
OpenScale.getInstance(getApplicationContext()).addScaleData(scaleBtData);
OpenScale.getInstance(getApplicationContext()).updateScaleData();
break;
case BluetoothCommunication.BT_INIT_PROCESS:
setBluetoothStatusIcon(R.drawable.bluetooth_connection_success);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_init), Toast.LENGTH_SHORT).show();
Log.d("OpenScale", "Bluetooth initializing");
break;
case BluetoothCommunication.BT_CONNECTION_LOST:
setBluetoothStatusIcon(R.drawable.bluetooth_connection_lost);

View File

@@ -103,4 +103,5 @@
<string name="info_bluetooth_no_device">Kein Bluetooth Gerät gefunden</string>
<string name="info_bluetooth_try_reconnection">Versuche Verbindung herzustellen zu</string>
<string name="label_device_type">Gerätetyp</string>
<string name="info_bluetooth_init">Initializiere Bluetooth Gerät</string>
</resources>

View File

@@ -103,4 +103,5 @@
<string name="info_bluetooth_connection_lost">Bluetooth接続を失いました</string>
<string name="info_bluetooth_connection_successful">接続に成功しました</string>
<string name="label_device_type">デバイスタイプ</string>
<string name="info_bluetooth_init">Bluetooth接続を初期化する</string>
</resources>

View File

@@ -96,6 +96,7 @@
<string name="info_bluetooth_connection_lost">Lost Bluetooth connection.</string>
<string name="info_bluetooth_no_device">No Bluetooth device found</string>
<string name="info_bluetooth_connection_successful">Connection successful established</string>
<string name="info_bluetooth_init">Initialize Bluetooth device</string>
<string name="info_bluetooth_connection_error">Bluetooth has an unexpected error</string>
<string name="info_enter_user_name">Enter your name</string>