1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 09:17:29 +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 @Override
public boolean supportsRealtimeData() { public boolean supportsRealtimeData() {
// We could support this easily but I can't figure out how to push the return true;
// act event into real-time data :(
return false;
} }
@Override @Override

View File

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

View File

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