压缩png图片,修改5515 3220发送指令,类型为int类型
@ -56,8 +56,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
// 发送佩戴检测请求
|
||||
deviceManager.sendWearDetectionRequest();
|
||||
|
||||
// 1秒后再次执行
|
||||
handler.postDelayed(this, 1000);
|
||||
// 2秒后再次执行
|
||||
handler.postDelayed(this, 2000);
|
||||
}
|
||||
};
|
||||
private GpioManager gpioManager;
|
||||
@ -86,14 +86,25 @@ public class MainActivity extends AppCompatActivity {
|
||||
// 初始化动画管理器
|
||||
animationManager = new RobotFaceAnimationManager(this, ivFace);
|
||||
|
||||
// 每5秒自动切换一次表情
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
playRandomFaceAnimation();
|
||||
handler.postDelayed(this, 10000); // 10秒后再次执行
|
||||
// 预加载所有动画资源
|
||||
new Thread(() -> {
|
||||
// 预加载所有动画
|
||||
for (int i = 0; i < 5; i++) {
|
||||
animationManager.loadFaceAnimation(i);
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
// 创建可重复执行的Runnable
|
||||
Runnable faceAnimationRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
playRandomFaceAnimation();
|
||||
handler.postDelayed(this, 20000); // 20秒后再次执行
|
||||
}
|
||||
};
|
||||
|
||||
// 启动第一次动画切换
|
||||
handler.post(faceAnimationRunnable);
|
||||
}).start();
|
||||
|
||||
// 检查并请求必要的权限
|
||||
checkAndRequestPermissions();
|
||||
@ -225,22 +236,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
public void onAlgoResultReceived(ASR5515Protocol.AlgoResultResponse response) {
|
||||
LogManager.d(TAG, "算法结果: " + response.toString());
|
||||
|
||||
// 根据类型处理不同的算法结果
|
||||
if (response.type == ASR5515Protocol.AlgoResultResponse.TYPE_HEART_RATE) {
|
||||
// 处理心率结果
|
||||
LogManager.d(TAG, "心率值: " + response.getHeartRate());
|
||||
// LogManager.d(TAG, "信噪比: " + response.getSignalNoiseRatio());
|
||||
LogManager.d(TAG, "置信度: " + response.getConfidence() + "%");
|
||||
// 可以在这里更新UI或进行其他操作
|
||||
} else if (response.type == ASR5515Protocol.AlgoResultResponse.TYPE_SPO2) {
|
||||
// 处理血氧结果
|
||||
if (response.getSpo2() > 0) {
|
||||
LogManager.d(TAG, "血氧值: " + response.getSpo2() + "%");
|
||||
LogManager.d(TAG, "R值: " + response.getRValue());
|
||||
LogManager.d(TAG, "置信度: " + response.getConfidence() + "%");
|
||||
// 可以在这里更新UI或进行其他操作
|
||||
// 在后台线程处理算法结果
|
||||
new Thread(() -> {
|
||||
// 根据类型处理不同的算法结果
|
||||
if (response.type == ASR5515Protocol.AlgoResultResponse.TYPE_HEART_RATE) {
|
||||
// 简化日志输出
|
||||
LogManager.d(TAG, "HR: " + response.getHeartRate() +
|
||||
" Conf: " + response.getConfidence() + "%");
|
||||
} else if (response.type == ASR5515Protocol.AlgoResultResponse.TYPE_SPO2 &&
|
||||
response.getSpo2() > 0) {
|
||||
LogManager.d(TAG, "SpO2: " + response.getSpo2() + "%");
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
});
|
||||
|
||||
@ -263,15 +270,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
// }
|
||||
// }, 2000);
|
||||
|
||||
|
||||
// deviceManager.startGH3220Measure(ASR5515Protocol.GH3220MeasureType.ADT);
|
||||
deviceManager.stopGH3220Measure(ASR5515Protocol.GH3220MeasureType.LEAD);
|
||||
deviceManager.startGH3220Measure(ASR5515Protocol.GH3220MeasureType.ADT);
|
||||
deviceManager.startGH3220Measure(ASR5515Protocol.GH3220MeasureType.LEAD);
|
||||
// deviceManager.switchEcgDataReport((byte) 0x01);
|
||||
// deviceManager.stopGH3220Measure(ASR5515Protocol.GH3220MeasureType.HR);
|
||||
// deviceManager.stopGH3220Measure(ASR5515Protocol.GH3220MeasureType.SPO2);
|
||||
// deviceManager.startGH3220Measure(ASR5515Protocol.GH3220MeasureType.ECG);
|
||||
|
||||
// handler.postDelayed(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// deviceManager.startGH3220Measure(ASR5515Protocol.GH3220MeasureType.SPO2);
|
||||
// deviceManager.startGH3220Measure(ASR5515Protocol.GH3220MeasureType.HR);
|
||||
// }
|
||||
// }, 1000);
|
||||
// deviceManager.sendWearDetectionRequest();
|
||||
@ -300,6 +310,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (deviceManager != null) {
|
||||
deviceManager.stopGH3220Measure(ASR5515Protocol.GH3220MeasureType.HR);
|
||||
deviceManager.stopGH3220Measure(ASR5515Protocol.GH3220MeasureType.SPO2);
|
||||
deviceManager.stopGH3220Measure(ASR5515Protocol.GH3220MeasureType.LEAD);
|
||||
deviceManager.syncHostStatus(false);
|
||||
deviceManager.close();
|
||||
deviceManager = null;
|
||||
|
@ -604,7 +604,7 @@ public class ASR5515DeviceManager {
|
||||
* 发送GH3220开启测量请求
|
||||
* @param type 测量类型,参考ASR5515Protocol.GH3220MeasureType
|
||||
*/
|
||||
public void startGH3220Measure(byte type) {
|
||||
public void startGH3220Measure(int type) {
|
||||
wakeupDevice();
|
||||
serialPortHelper.startGH3220Measure(type);
|
||||
}
|
||||
@ -613,7 +613,7 @@ public class ASR5515DeviceManager {
|
||||
* 发送GH3220停止测量请求
|
||||
* @param type 测量类型,参考ASR5515Protocol.GH3220MeasureType
|
||||
*/
|
||||
public void stopGH3220Measure(byte type) {
|
||||
public void stopGH3220Measure(int type) {
|
||||
wakeupDevice();
|
||||
serialPortHelper.stopGH3220Measure(type);
|
||||
}
|
||||
@ -658,6 +658,20 @@ public class ASR5515DeviceManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void switchEcgDataReport(byte type)
|
||||
{
|
||||
if (!isDeviceReady()) {
|
||||
LogManager.e(TAG, "设备未就绪,无法发送ECG数据上报开关");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
wakeupDevice();
|
||||
serialPortHelper.switchEcgDataReport(type);
|
||||
} catch (Exception e) {
|
||||
LogManager.e(TAG, "发送ECG数据上报开关失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 唤醒设备
|
||||
* 通过GPIO33唤醒蓝牙,ASR休眠时会自动发送'w'字符
|
||||
|
@ -219,6 +219,7 @@ public class ASR5515Protocol {
|
||||
public static final short CMD_HEART_RATE_RECEIVED = 0x01FF; // 心率接收确认 [511 sn 0]
|
||||
public static final short CMD_SPO2_RESULT = 0x0200; // 主动上报算法结果(血氧) [512 sn len AlgoResult]
|
||||
public static final short CMD_SPO2_RECEIVED = 0x0201; // 血氧接收确认 [513 sn 0]
|
||||
public static final short CMD_ECG_DATA_REPORT = 0x020D; // 切换ECG数据上报类型 [525 sn len type]
|
||||
}
|
||||
|
||||
public static class Frame {
|
||||
@ -608,6 +609,11 @@ public class ASR5515Protocol {
|
||||
return createFrame(Commands.CMD_WEAR_ACK, sn, new byte[]{});
|
||||
}
|
||||
|
||||
public static byte[] createEcgDataReportSwitchRequest(byte type) {
|
||||
// 发送格式:[525 0 len type]
|
||||
return createFrame(Commands.CMD_ECG_DATA_REPORT, (short) 0, new byte[]{type});
|
||||
}
|
||||
|
||||
// 佩戴检测响应类
|
||||
public static class WearDetectionResponse {
|
||||
public boolean isWearing; // true表示已佩戴,false表示未佩戴
|
||||
@ -646,20 +652,31 @@ public class ASR5515Protocol {
|
||||
|
||||
// GH3220测量类型常量
|
||||
public static class GH3220MeasureType {
|
||||
public static final byte ADT = 0x01; // ADT
|
||||
public static final byte HR = 0x02; // 心率
|
||||
public static final byte LEAD = 0x03; // LEAD
|
||||
public static final byte SPO2 = 0x40; // 血氧
|
||||
public static final int ADT = 0x01; // ADT
|
||||
public static final int HR = 0x02; // 心率
|
||||
public static final int LEAD = 0x03; // LEAD
|
||||
public static final int SPO2 = 0x40; // 血氧
|
||||
public static final int ECG = 0x80; //ECG
|
||||
}
|
||||
|
||||
// 创建GH3220开启测量请求帧 [501 0 len type]
|
||||
public static byte[] createGH3220MeasureStartRequest(byte type) {
|
||||
return createFrame(Commands.CMD_GH3220_MEASURE_START, (short) 0, new byte[]{(byte)type});
|
||||
public static byte[] createGH3220MeasureStartRequest(int type) {
|
||||
byte[] data = new byte[4];
|
||||
data[3] = (byte) (type >> 24);
|
||||
data[2] = (byte) (type >> 16);
|
||||
data[1] = (byte) (type >> 8);
|
||||
data[0] = (byte) type;
|
||||
return createFrame(Commands.CMD_GH3220_MEASURE_START, (short) 0, data);
|
||||
}
|
||||
|
||||
// 创建GH3220停止测量请求帧 [503 0 len type]
|
||||
public static byte[] createGH3220MeasureStopRequest(byte type) {
|
||||
return createFrame(Commands.CMD_GH3220_MEASURE_STOP, (short) 0, new byte[]{(byte)type});
|
||||
public static byte[] createGH3220MeasureStopRequest(int type) {
|
||||
byte[] data = new byte[4];
|
||||
data[3] = (byte) (type >> 24);
|
||||
data[2] = (byte) (type >> 16);
|
||||
data[1] = (byte) (type >> 8);
|
||||
data[0] = (byte) type;
|
||||
return createFrame(Commands.CMD_GH3220_MEASURE_STOP, (short) 0, data);
|
||||
}
|
||||
|
||||
// 创建心率接收确认请求帧 [511 sn 0]
|
||||
|
@ -283,7 +283,7 @@ public class SerialPortHelper {
|
||||
* 发送GH3220开启测量请求
|
||||
* @param type 测量类型,参考ASR5515Protocol.GH3220MeasureType
|
||||
*/
|
||||
public void startGH3220Measure(byte type) {
|
||||
public void startGH3220Measure(int type) {
|
||||
byte[] data = ASR5515Protocol.createGH3220MeasureStartRequest(type);
|
||||
sendData(data, null);
|
||||
}
|
||||
@ -292,7 +292,7 @@ public class SerialPortHelper {
|
||||
* 发送GH3220停止测量请求
|
||||
* @param type 测量类型,参考ASR5515Protocol.GH3220MeasureType
|
||||
*/
|
||||
public void stopGH3220Measure(byte type) {
|
||||
public void stopGH3220Measure(int type) {
|
||||
byte[] data = ASR5515Protocol.createGH3220MeasureStopRequest(type);
|
||||
sendData(data, null);
|
||||
}
|
||||
@ -333,6 +333,11 @@ public class SerialPortHelper {
|
||||
sendData(data, null);
|
||||
}
|
||||
|
||||
public void switchEcgDataReport(byte type) {
|
||||
byte[] data = ASR5515Protocol.createEcgDataReportSwitchRequest(type);
|
||||
sendData(data, null);
|
||||
}
|
||||
|
||||
|
||||
public boolean open() {
|
||||
try {
|
||||
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 681 B |
Before Width: | Height: | Size: 899 B After Width: | Height: | Size: 154 B |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 681 B |
Before Width: | Height: | Size: 899 B After Width: | Height: | Size: 154 B |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 2.9 KiB |