1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-28 03:25:49 +01:00
This commit is contained in:
Gordon Williams 2020-12-04 16:30:19 +00:00
parent c1195ba05d
commit 480ec40ff2
3 changed files with 25 additions and 9 deletions

View File

@ -92,10 +92,8 @@ public class BangleJSCoordinator extends AbstractDeviceCoordinator {
}
@Override
public boolean supportsRealtimeData() {
// We could support this easily but I can't figure out how to push the
// act event into real-time data :(
return false;
public boolean supportsRealtimeData() {
return true;
}
@Override

View File

@ -28,12 +28,15 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.ID115ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.ID115ActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public class BangleJSSampleProvider extends AbstractSampleProvider<BangleJSActivitySample> {
public BangleJSSampleProvider(GBDevice device, DaoSession session) {
super(device, session);
}
public static final int TYPE_ACTIVITY = 0;
@Override
public AbstractDao<BangleJSActivitySample, ?> getSampleDao() {
return getSession().getBangleJSActivitySampleDao();
@ -59,12 +62,17 @@ public class BangleJSSampleProvider extends AbstractSampleProvider<BangleJSActiv
@Override
public int normalizeType(int rawType) {
return rawType;
switch (rawType) {
case TYPE_ACTIVITY:
return ActivityKind.TYPE_ACTIVITY;
default: // fall through
return ActivityKind.TYPE_UNKNOWN;
}
}
@Override
public int toRawActivityKind(int activityKind) {
return activityKind;
return TYPE_ACTIVITY;
}
@Override

View File

@ -19,9 +19,12 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.banglejs;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -55,6 +58,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.CannedMessagesSpec;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
@ -226,8 +230,8 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
int steps = 0;
if (json.has("hrm")) hrm = json.getInt("hrm");
if (json.has("stp")) steps = json.getInt("stp");
int activity = ActivityKind.TYPE_UNKNOWN;
if (json.has("act")) {
int activity = BangleJSSampleProvider.TYPE_ACTIVITY;
/*if (json.has("act")) {
String actName = "TYPE_" + json.getString("act").toUpperCase();
try {
Field f = ActivityKind.class.getField(actName);
@ -239,7 +243,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
} catch (NoSuchFieldException e) {
LOG.info("JSON activity '"+actName+"' not found");
}
}
}*/
sample.setRawKind(activity);
sample.setHeartRate(hrm);
sample.setSteps(steps);
@ -253,6 +257,12 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
} catch (Exception ex) {
LOG.warn("Error saving activity: " + ex.getLocalizedMessage());
}
// push realtime data
if (realtimeHRM || realtimeStep) {
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
}
} break;
}
}