package com.ic.work;
import android.app.Service;
+import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.database.ContentObserver;
import com.ic.work.domain.HeartRate;
import com.ic.work.domain.Temperature;
-import com.ic.work.event.AkBloodCheckResultEvent;
import com.ic.work.event.BloodSensorEvent;
import com.ic.work.event.TestTaskEvent;
import com.ic.work.hardware.BloodInfoHelper;
IcLog.d(TAG, "task == start == > " + testTaskEvent);
//当结果回来的时候,如果队列里没有了,那么就false了
isRunning = true;
+ //获取一下,是否有校准值
+ updateAdjustValue();
//这里处理指令,不可以开启子线程
-
switch (testTaskEvent.sensorType) {
case HEART_RATE_AND_OXYGEN:
//获取心率内容
IcLog.d(TAG, "create new task == > " + taskEvent);
synchronized (mTaskLock) {
//判断队列里是否有同样的任务,如果有的话不用发了,
- IcLog.d(TAG, "contains == > " + mTaskList.contains(taskEvent)+", tag = "+tag);
+ IcLog.d(TAG, "contains == > " + mTaskList.contains(taskEvent) + ", tag = " + tag);
if (mTaskList.contains(taskEvent)) {
- IcLog.d(TAG, "task contains..." + fromByValue+", tag = "+tag);
+ IcLog.d(TAG, "task contains..." + fromByValue + ", tag = " + tag);
//通知正在等待执行
if (tag != null) {
dispatchWaiting(censorType, tag);
return;
}
if (taskEvent.equals(currentTask)) {
- IcLog.d(TAG, "current task running..."+", tag = "+tag);
+ IcLog.d(TAG, "current task running..." + ", tag = " + tag);
//通知正在执行
if (tag != null) {
dispatchTaskRunning(censorType, tag);
//直接运行不需要放到队列里了
EventBus.getDefault().post(taskEvent);
} else {
- IcLog.d(TAG, "new task waiting..." + taskEvent +", tag = "+tag);
+ IcLog.d(TAG, "new task waiting..." + taskEvent + ", tag = " + tag);
//要放到队列里头,提示调用者正在等待执行
if (tag != null) {
dispatchWaiting(censorType, tag);
* @param tag
*/
private void dispatchTaskRunning(TestTaskEvent.SensorType censorType, String tag) {
- ICLogger.d("sensorType = "+(censorType == TestTaskEvent.SensorType.HEART_RATE_AND_OXYGEN));
+ ICLogger.d("sensorType = " + (censorType == TestTaskEvent.SensorType.HEART_RATE_AND_OXYGEN));
if (censorType == TestTaskEvent.SensorType.TEMPERATURE) {
//温度的
synchronized (mLock) {
while (i > 0) {
i--;
String callbackTag = (String) heartRateCallbacks.getBroadcastCookie(i);
- ICLogger.d("callbackTag = "+ callbackTag +", tag = "+tag);
+ ICLogger.d("callbackTag = " + callbackTag + ", tag = " + tag);
if (callbackTag != null && callbackTag.equals(tag)) {
heartRateCallbacks.getBroadcastItem(i).onGettingData();
break;
}
}
- @Subscribe(threadMode = ThreadMode.ASYNC)
- public void onMessageEvent(AkBloodCheckResultEvent event) {
- int[] deviation = getPPG_ECG_adjustValue();
- event.heart = event.heart + deviation[0];
- event.high = event.high + deviation[1];
- event.low = event.low + deviation[2];
- event.oxygen = event.oxygen + deviation[3];
- handleBloodResult(event.high, event.low,
- event.heart, event.oxygen);
- IcLog.d(TAG, "on ak blood test end...");
- checkContinue();
- }
-
private void checkContinue() {
try {
if (wakeLock != null) {
wakeLock.release();
}
- }catch (Exception e){
+ } catch (Exception e) {
Log.getStackTraceString(e.fillInStackTrace());
- }finally {
+ } finally {
isRunning = false;
currentTask = null;
int size = mTaskList.size();
private void dispatchHeartRateUpdate(int high, int low, int heart, int oxygen) {
+ //处理一下数据
+ //对数据进行处理
+ ICLogger.d("bloodLowDxValue == > " + bloodLowDxValue);
+ ICLogger.d("bloodHighDxValue == > " + bloodHighDxValue);
+ //差值 = 原始值-校准值 ---->所以,校准值 = 原始值-差值
+ if (bloodLowDxValue != 0) {
+ high = high - bloodLowDxValue;
+ }
+ if (bloodHighDxValue != 0) {
+ low = low - bloodHighDxValue;
+ }
//更新一下数据
HeartRate heartRate = new HeartRate(high, low, heart, oxygen);
synchronized (mLock) {
}
}
+
+ private boolean hasUpdateAdjustBloodPressureValue = false;
+ private int bloodHighDxValue = 0;
+ private int bloodLowDxValue = 0;
+
+ /**
+ * 查一下,是否有校准值
+ * 血压舒张校准值:blood_high_dx
+ * 血压收缩校准值:blood_low_dx
+ * 此为耗时操作,最好在子线程中去完成
+ * 在血压检测开始前,可以调用一下这个方法,去更新一下值
+ * 如果这个值已经更新了,那么就不要再去更新了
+ * 也就是只检查一次即可。
+ */
+ private void updateAdjustValue() {
+ if (hasUpdateAdjustBloodPressureValue) {
+ return;
+ }
+ hasUpdateAdjustBloodPressureValue = true;
+ ContentResolver contentResolver = WorkServiceApp.sContext.getContentResolver();
+ Cursor bloodHighDxCursor = contentResolver.query(Uri.parse(SETTINGS),
+ new String[]{"s_value"}, "s_value=?",
+ new String[]{"blood_high_dx"}, null);
+
+ if (bloodHighDxCursor != null) {
+ bloodHighDxValue = bloodHighDxCursor.getInt(0);
+ ICLogger.d("bloodHighDxValue == > " + bloodHighDxValue);
+ bloodHighDxCursor.close();
+ }
+ Cursor bloodLowDxCursor = contentResolver.query(Uri.parse(SETTINGS),
+ new String[]{"s_value"}, "s_value=?",
+ new String[]{"blood_low_dx"}, null);
+
+ if (bloodLowDxCursor != null) {
+ bloodLowDxValue = bloodLowDxCursor.getInt(0);
+ ICLogger.d("bloodLowDxValue == > " + bloodLowDxValue);
+ bloodLowDxCursor.close();
+ }
+
+
+ }
+
/**
* 分发心率测试结果
*
* @param heartRate
*/
private void dispatchHeartRateResult(HeartRate heartRate) {
+ //对数据进行处理
+ //差值 = 原始值-校准值 ---->所以,校准值 = 原始值-差值
+ if (bloodLowDxValue != 0) {
+ heartRate.setBloodLow(heartRate.getBloodLow() - bloodLowDxValue);
+ }
+ if (bloodHighDxValue != 0) {
+ heartRate.setBloodHeight(heartRate.getBloodHeight() - bloodHighDxValue);
+ }
synchronized (mLock) {
int i = heartRateCallbacks.beginBroadcast();
IcLog.d(TAG, "heart rate callback size == > " + i);