diff --git a/SleepGarmin-android/app/src/main/java/com/urbandroid/sleep/garmin/Constants.java b/SleepGarmin-android/app/src/main/java/com/urbandroid/sleep/garmin/Constants.java index a059761..9455abf 100644 --- a/SleepGarmin-android/app/src/main/java/com/urbandroid/sleep/garmin/Constants.java +++ b/SleepGarmin-android/app/src/main/java/com/urbandroid/sleep/garmin/Constants.java @@ -26,6 +26,8 @@ public class Constants { public final static String STARTED_ON_WATCH_NAME = "com.urbandroid.sleep.watch.STARTED_ON_WATCH"; public final static String STOP_SLEEP_TRACK_ACTION = "com.urbandroid.sleep.alarmclock.STOP_SLEEP_TRACK"; // private final static String WATCH_TYPE_EXTRA = "com.urbandroid.sleep.watch.WATCH_TIME_EXTRA"; + public final static String DATA_WITH_EXTRA = "com.urbandroid.sleep.watch.ACTION_EXTRA_DATA_UPDATE"; + public final static String SPO2_DATA_EXTRA = "com.urbandroid.sleep.EXTRA_DATA_SPO2"; // supposed to be float // From sleep to plugin final static String START_WATCH_APP = "com.urbandroid.sleep.watch.START_TRACKING"; diff --git a/SleepGarmin-android/app/src/main/java/com/urbandroid/sleep/garmin/MessageHandler.java b/SleepGarmin-android/app/src/main/java/com/urbandroid/sleep/garmin/MessageHandler.java index 242499a..4cf0bc5 100644 --- a/SleepGarmin-android/app/src/main/java/com/urbandroid/sleep/garmin/MessageHandler.java +++ b/SleepGarmin-android/app/src/main/java/com/urbandroid/sleep/garmin/MessageHandler.java @@ -12,6 +12,7 @@ import java.util.List; import static com.urbandroid.sleep.garmin.Constants.CHECK_CONNECTED; +import static com.urbandroid.sleep.garmin.Constants.DATA_WITH_EXTRA; import static com.urbandroid.sleep.garmin.Constants.DISMISS_ACTION_NAME; import static com.urbandroid.sleep.garmin.Constants.DO_HR_MONITORING; import static com.urbandroid.sleep.garmin.Constants.HINT; @@ -23,6 +24,7 @@ import static com.urbandroid.sleep.garmin.Constants.SET_BATCH_SIZE; import static com.urbandroid.sleep.garmin.Constants.SET_PAUSE; import static com.urbandroid.sleep.garmin.Constants.SNOOZE_ACTION_NAME; +import static com.urbandroid.sleep.garmin.Constants.SPO2_DATA_EXTRA; import static com.urbandroid.sleep.garmin.Constants.STARTED_ON_WATCH_NAME; import static com.urbandroid.sleep.garmin.Constants.START_ALARM; import static com.urbandroid.sleep.garmin.Constants.START_WATCH_APP; @@ -135,6 +137,12 @@ public void handleMessageFromWatch(List message, ConnectIQ.IQMessageStat queueToWatch.emptyQueue(); queueToWatch.enqueue(TO_WATCH_STOP); break; + case "SPO2": + float[] spo2Data = new float[]{Float.parseFloat(msgArray[1])}; + Logger.logInfo(TAG + ": received SpO2 data from watch " + spo2Data[0]); + Intent spo2Intent = new Intent(DATA_WITH_EXTRA); + spo2Intent.putExtra(SPO2_DATA_EXTRA, spo2Data); + sendExplicitBroadcastToSleep(spo2Intent, context); } if (maxRawFloatValues != null) { diff --git a/SleepGarmin-watch2/source/BusinessManager.mc b/SleepGarmin-watch2/source/BusinessManager.mc index 63f86be..025c861 100644 --- a/SleepGarmin-watch2/source/BusinessManager.mc +++ b/SleepGarmin-watch2/source/BusinessManager.mc @@ -42,6 +42,9 @@ class BusinessManager { DebugManager.log("sendHrData " + hr); self.ctx.commManager.enqueue([CommManager.MSG_HR, hr]); } + function sendOxyData(oxygenSaturation) { + self.ctx.commManager.enqueue([CommManager.MSG_OXY, oxygenSaturation]); + } function sendPause() { self.ctx.commManager.enqueue(CommManager.MSG_PAUSE_TRACKING); diff --git a/SleepGarmin-watch2/source/CommManager.mc b/SleepGarmin-watch2/source/CommManager.mc index e3e1f45..548103f 100644 --- a/SleepGarmin-watch2/source/CommManager.mc +++ b/SleepGarmin-watch2/source/CommManager.mc @@ -27,6 +27,7 @@ class CommManager { static const MSG_RESUME_TRACKING = "RESUME"; static const MSG_DATA = "DATA_NEW"; static const MSG_HR = "HR"; + static const MSG_OXY = "SPO2"; const MAX_DELIVERY_ERROR = 3; const MAX_DELIVERY_PAUSE = 3; diff --git a/SleepGarmin-watch2/source/SensorManager.mc b/SleepGarmin-watch2/source/SensorManager.mc index 5f6169a..48d48f4 100644 --- a/SleepGarmin-watch2/source/SensorManager.mc +++ b/SleepGarmin-watch2/source/SensorManager.mc @@ -2,7 +2,8 @@ using Toybox.Sensor; class SensorManager { - const SENSOR_PERIOD_SEC = 4; + const SENSOR_PERIOD_SEC = 4; + const OXI_READING_PERIOD_SEC = 60; var ctx; @@ -12,6 +13,8 @@ class SensorManager { var accBatch = []; var hrBuf = []; + + var lastOximeterReadingSec = 0; function initialize(ctx) { DebugManager.log("SensorManager initialized"); @@ -45,8 +48,19 @@ class SensorManager { if (sensorData has :heartRateData && sensorData.heartRateData != null) { onHRData(sensorData.heartRateData.heartBeatIntervals); - } + } + + if (lastOximeterReadingSec > OXI_READING_PERIOD_SEC) { + lastOximeterReadingSec = 0; + var sensorInfo = Sensor.getInfo(); + if (sensorInfo has :oxygenSaturation && sensorInfo.oxygenSaturation != null) { + onOxyData(oxygenSaturation); + } + } + lastOximeterReadingSec = lastOximeterReadingSec + SENSOR_PERIOD_SEC; } + + self.ctx.businessManager.onDataHook(); } @@ -101,5 +115,11 @@ class SensorManager { hrBuf = []; } } + + function onOxyData(oxygenSaturation) { + DebugManager.log("onOxyData"); + + self.ctx.businessManager.sendOxyData(oxygenSaturation); + } } \ No newline at end of file