Compare commits

..

No commits in common. "da6bdba5a0bf4507856cea43d0275beda617df35" and "e5680504e0e828f9c42a7270091f6d955fe9bc69" have entirely different histories.

1 changed files with 2 additions and 30 deletions

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import React, { Component } from 'react'; import React, { Component } from 'react';
import { NativeModules, DeviceEventEmitter, Platform,AppState, } from 'react-native'; import { NativeModules, DeviceEventEmitter, Platform } from 'react-native';
@ -74,11 +74,9 @@ export default class RNDYGlucoseDriver {
this._timeoutPromise = this._timeoutPromise.bind(this); this._timeoutPromise = this._timeoutPromise.bind(this);
this.connectDevice = this.connectDevice.bind(this); this.connectDevice = this.connectDevice.bind(this);
this._mixTimeoutPromise = this._mixTimeoutPromise.bind(this); this._mixTimeoutPromise = this._mixTimeoutPromise.bind(this);
this._blockSleep = this._blockSleep.bind(this);
this._executeEvent = this._executeEvent.bind(this); this._executeEvent = this._executeEvent.bind(this);
this._registerEvent = this._registerEvent.bind(this); this._registerEvent = this._registerEvent.bind(this);
this._commadTimeInterval = this._commadTimeInterval.bind(this); this._commadTimeInterval = this._commadTimeInterval.bind(this);
this._commadTimeIntervalWithTimer = this._commadTimeIntervalWithTimer.bind(this);
this.createAuthChannel = this.createAuthChannel.bind(this); this.createAuthChannel = this.createAuthChannel.bind(this);
this.disconnecAllDevicestWithout = this.disconnecAllDevicestWithout.bind(this); this.disconnecAllDevicestWithout = this.disconnecAllDevicestWithout.bind(this);
this.getAllDataFromIndex = this.getAllDataFromIndex.bind(this); this.getAllDataFromIndex = this.getAllDataFromIndex.bind(this);
@ -639,7 +637,7 @@ export default class RNDYGlucoseDriver {
}); });
} }
_commadTimeIntervalWithTimer(interval) { _commadTimeInterval(interval) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
resolve('command await time out'); resolve('command await time out');
@ -647,30 +645,6 @@ export default class RNDYGlucoseDriver {
}); });
} }
// 阻塞方法,模拟 sleep 功能
_blockSleep(milliseconds) {
return new Promise(resolve => {
const start = new Date().getTime();
let current = start;
while (current - start < milliseconds) {
current = new Date().getTime();
}
resolve();
});
}
_commadTimeInterval(interval) {
if (Platform.OS === 'android' && AppState.currentState !== 'active') {
// 如果在后台运行,使用阻塞方法
console.log(TAG,'start blocker');
return this._blockSleep(interval);
} else {
// 如果在前台运行,使用 setTimeout
console.log(TAG,'start timer');
return this._commadTimeIntervalWithTimer(interval);
}
}
_registerEvent(eventName) { _registerEvent(eventName) {
this._eventMap[eventName] = (deviceInfo) => { this._eventMap[eventName] = (deviceInfo) => {
@ -696,8 +670,6 @@ export default class RNDYGlucoseDriver {
this._eventMap[eventName] = null; this._eventMap[eventName] = null;
} }
/** 监控底层驱动发送的消息 */ /** 监控底层驱动发送的消息 */
startMonitorDriverEvent() { startMonitorDriverEvent() {
this._createChannel = (deviceInfo) => { this._createChannel = (deviceInfo) => {