mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-17 22:11:35 +02:00
optimize Mi scale history weight measurement
This commit is contained in:
@@ -24,10 +24,11 @@ public abstract class BluetoothCommunication {
|
|||||||
public static final int BT_OPEN_SCALE = 1;
|
public static final int BT_OPEN_SCALE = 1;
|
||||||
|
|
||||||
public static final int BT_RETRIEVE_SCALE_DATA = 0;
|
public static final int BT_RETRIEVE_SCALE_DATA = 0;
|
||||||
public static final int BT_CONNECTION_ESTABLISHED = 1;
|
public static final int BT_INIT_PROCESS = 1;
|
||||||
public static final int BT_CONNECTION_LOST = 2;
|
public static final int BT_CONNECTION_ESTABLISHED = 2;
|
||||||
public static final int BT_NO_DEVICE_FOUND = 3;
|
public static final int BT_CONNECTION_LOST = 3;
|
||||||
public static final int BT_UNEXPECTED_ERROR = 4;
|
public static final int BT_NO_DEVICE_FOUND = 4;
|
||||||
|
public static final int BT_UNEXPECTED_ERROR = 5;
|
||||||
|
|
||||||
protected Handler callbackBtHandler;
|
protected Handler callbackBtHandler;
|
||||||
protected BluetoothAdapter btAdapter;
|
protected BluetoothAdapter btAdapter;
|
||||||
|
@@ -14,11 +14,6 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
* 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;
|
package com.health.openscale.core;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -77,7 +72,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
|||||||
if (device.getAddress().replace(":", "").startsWith("880f10") ||
|
if (device.getAddress().replace(":", "").startsWith("880f10") ||
|
||||||
device.getAddress().replace(":", "").startsWith("880F10")) // Xiaomi
|
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...");
|
Log.d("BluetoothMiScale", "Mi Scale found trying to connect...");
|
||||||
bluetoothGatt = device.connectGatt(context, false, gattCallback);
|
bluetoothGatt = device.connectGatt(context, false, gattCallback);
|
||||||
|
|
||||||
@@ -142,8 +137,6 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
|||||||
BluetoothGattCharacteristic characteristic;
|
BluetoothGattCharacteristic characteristic;
|
||||||
BluetoothGattDescriptor descriptor;
|
BluetoothGattDescriptor descriptor;
|
||||||
|
|
||||||
Log.d("BluetoothMiScale", "Cmd State " + nextCmdState);
|
|
||||||
|
|
||||||
switch (nextCmdState) {
|
switch (nextCmdState) {
|
||||||
case 0:
|
case 0:
|
||||||
// read device time
|
// read device time
|
||||||
@@ -202,10 +195,10 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
|||||||
|
|
||||||
initProcessOn = true;
|
initProcessOn = true;
|
||||||
|
|
||||||
Log.d("BluetoothMiScale", "Init State " + nextInitState);
|
|
||||||
|
|
||||||
switch (nextInitState) {
|
switch (nextInitState) {
|
||||||
case 0:
|
case 0:
|
||||||
|
callbackBtHandler.obtainMessage(BluetoothCommunication.BT_INIT_PROCESS).sendToTarget();
|
||||||
|
|
||||||
// set current time
|
// set current time
|
||||||
characteristic = gatt.getService(WEIGHT_MEASUREMENT_SERVICE)
|
characteristic = gatt.getService(WEIGHT_MEASUREMENT_SERVICE)
|
||||||
.getCharacteristic(WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC);
|
.getCharacteristic(WEIGHT_MEASUREMENT_TIME_CHARACTERISTIC);
|
||||||
@@ -365,7 +358,7 @@ public class BluetoothMiScale extends BluetoothCommunication {
|
|||||||
|
|
||||||
callbackBtHandler.obtainMessage(BluetoothCommunication.BT_RETRIEVE_SCALE_DATA, scaleBtData).sendToTarget();
|
callbackBtHandler.obtainMessage(BluetoothCommunication.BT_RETRIEVE_SCALE_DATA, scaleBtData).sendToTarget();
|
||||||
} else {
|
} else {
|
||||||
Log.e("BluetoothMiScale", "Invalid weight year " + year);
|
Log.e("BluetoothMiScale", "Invalid Mi scale weight year " + year);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
|
@@ -220,7 +220,11 @@ public class MainActivity extends ActionBarActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
OpenScale.getInstance(getApplicationContext()).addScaleData(scaleBtData);
|
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;
|
break;
|
||||||
case BluetoothCommunication.BT_CONNECTION_LOST:
|
case BluetoothCommunication.BT_CONNECTION_LOST:
|
||||||
setBluetoothStatusIcon(R.drawable.bluetooth_connection_lost);
|
setBluetoothStatusIcon(R.drawable.bluetooth_connection_lost);
|
||||||
|
@@ -103,4 +103,5 @@
|
|||||||
<string name="info_bluetooth_no_device">Kein Bluetooth Gerät gefunden</string>
|
<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="info_bluetooth_try_reconnection">Versuche Verbindung herzustellen zu</string>
|
||||||
<string name="label_device_type">Gerätetyp</string>
|
<string name="label_device_type">Gerätetyp</string>
|
||||||
|
<string name="info_bluetooth_init">Initializiere Bluetooth Gerät</string>
|
||||||
</resources>
|
</resources>
|
@@ -103,4 +103,5 @@
|
|||||||
<string name="info_bluetooth_connection_lost">Bluetooth接続を失いました</string>
|
<string name="info_bluetooth_connection_lost">Bluetooth接続を失いました</string>
|
||||||
<string name="info_bluetooth_connection_successful">接続に成功しました</string>
|
<string name="info_bluetooth_connection_successful">接続に成功しました</string>
|
||||||
<string name="label_device_type">デバイスタイプ</string>
|
<string name="label_device_type">デバイスタイプ</string>
|
||||||
|
<string name="info_bluetooth_init">Bluetooth接続を初期化する</string>
|
||||||
</resources>
|
</resources>
|
@@ -96,6 +96,7 @@
|
|||||||
<string name="info_bluetooth_connection_lost">Lost Bluetooth connection.</string>
|
<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_no_device">No Bluetooth device found</string>
|
||||||
<string name="info_bluetooth_connection_successful">Connection successful established</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_bluetooth_connection_error">Bluetooth has an unexpected error</string>
|
||||||
|
|
||||||
<string name="info_enter_user_name">Enter your name</string>
|
<string name="info_enter_user_name">Enter your name</string>
|
||||||
|
Reference in New Issue
Block a user