mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-24 16:21:16 +02:00
UM-25: made cumulative values resettable
This commit is contained in:
parent
8e34311f01
commit
f61008c9ae
@ -5,17 +5,21 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.um25.Data.MeasurementData;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.um25.Support.UM25Support;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class DataActivity extends AbstractGBActivity {
|
||||
private HashMap<Integer, TextView> valueViews = new HashMap<>(ValueDisplay.values().length);
|
||||
@ -51,6 +55,21 @@ public class DataActivity extends AbstractGBActivity {
|
||||
setContentView(R.layout.activity_um25_data);
|
||||
|
||||
chargeDurationTextView = findViewById(R.id.um25_text_charge_duration);
|
||||
TextView wattHoursTextView = findViewById(R.id.um25_text_wattage_sum);
|
||||
|
||||
View.OnLongClickListener longClickListener = new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
GB.toast("resetting", Toast.LENGTH_SHORT, GB.INFO);
|
||||
LocalBroadcastManager.getInstance(DataActivity.this).sendBroadcast(
|
||||
new Intent(UM25Support.ACTION_RESET_STATS)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
chargeDurationTextView.setOnLongClickListener(longClickListener);
|
||||
wattHoursTextView.setOnLongClickListener(longClickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,10 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.um25.Support;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
@ -29,10 +32,12 @@ public class UM25Support extends UM25BaseSupport {
|
||||
public static final String UUID_CHAR = "0000ffe1-0000-1000-8000-00805f9b34fb";
|
||||
|
||||
public static final String ACTION_MEASUREMENT_TAKEN = "com.nodomain.gadgetbridge.um25.MEASUREMENT_TAKEN";
|
||||
public static final String ACTION_RESET_STATS = "com.nodomain.gadgetbridge.um25.RESET_STATS";
|
||||
public static final String EXTRA_KEY_MEASUREMENT_DATA = "EXTRA_MEASUREMENT_DATA";
|
||||
public static final int LOOP_DELAY = 500;
|
||||
|
||||
private final byte[] COMMAND_UPDATE = new byte[]{(byte) 0xF0};
|
||||
private final byte[] COMMAND_RESET_STATS = new byte[]{(byte) 0xF4};
|
||||
private final int PAYLOAD_LENGTH = 130;
|
||||
|
||||
private ByteBuffer buffer = ByteBuffer.allocate(PAYLOAD_LENGTH);
|
||||
@ -46,6 +51,18 @@ public class UM25Support extends UM25BaseSupport {
|
||||
this.buffer.mark();
|
||||
}
|
||||
|
||||
BroadcastReceiver resetReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(!ACTION_RESET_STATS.equals(intent.getAction())){
|
||||
return;
|
||||
}
|
||||
new TransactionBuilder("reset stats")
|
||||
.write(getCharacteristic(UUID.fromString(UUID_CHAR)), COMMAND_RESET_STATS)
|
||||
.queue(getQueue());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||
return builder
|
||||
@ -60,6 +77,11 @@ public class UM25Support extends UM25BaseSupport {
|
||||
@Override
|
||||
public boolean run(BluetoothGatt gatt) {
|
||||
logger.debug("initialized, starting timers");
|
||||
LocalBroadcastManager.getInstance(getContext())
|
||||
.registerReceiver(
|
||||
resetReceiver,
|
||||
new IntentFilter(ACTION_RESET_STATS)
|
||||
);
|
||||
startLoop();
|
||||
return true;
|
||||
}
|
||||
@ -67,6 +89,13 @@ public class UM25Support extends UM25BaseSupport {
|
||||
.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
LocalBroadcastManager.getInstance(getContext())
|
||||
.unregisterReceiver(resetReceiver);
|
||||
}
|
||||
|
||||
private void startLoop(){
|
||||
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
|
||||
executor.scheduleWithFixedDelay(new Runnable() {
|
||||
|
Loading…
Reference in New Issue
Block a user