小编Sen*_*tal的帖子

蓝牙LE收听多个特征通知

我在Android手机上使用BLE应用程序与自定义BLE传感器板通信.电路板提供两个特性,加速和心电图.在电话方面,我想从传感器板接收两个特征的通知.我设置通知的代码:

mGatt.setCharacteristicNotification(ecgChar, true);
            BluetoothGattDescriptor descriptor = ecgChar.getDescriptor(
                    UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            mGatt.writeDescriptor(descriptor);
            mGatt.setCharacteristicNotification(accelChar, true);
            descriptor = ecgChar.getDescriptor(
                    UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            mGatt.writeDescriptor(descriptor);
Run Code Online (Sandbox Code Playgroud)

但是,我只能收到第一个特征的通知.当我只注册一个特征的通知时,它运作良好.ECG和加速度的采样频率均为100Hz.那么如何从这两个特征中接收通知?谢谢.

notifications android bluetooth characteristics

2
推荐指数
1
解决办法
3509
查看次数

Swing计时器同步

我对Swing计时器的工作原理感到困惑.在下面的代码中,我想在按START(一次)时在第一个文本字段中每隔400ms显示0~9.之后,第二个文本字段将显示"已完成".

在此输入图像描述

public class Main extends JPanel{

private static final long serialVersionUID = 1L;
private JButton bStart;
private JTextField tTest;
private JTextField tNumber;

Main(){
    bStart = new JButton("Start");
    bStart.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            displayNumbers();
        }       
    });

    tTest = new JTextField(null, 30);
    tNumber = new JTextField(" ", 30);
    tNumber.setEditable(false);
    this.setSize(300, 100);
    this.add(bStart);
    this.add(tNumber);
    this.add(tTest);

}

public void displayNumbers(){
    new Timer(400, new ActionListener() {
        int i = 0;
        public void actionPerformed(ActionEvent evt) {
            if(i<10){
                tNumber.setText(Integer.toString(i)); …
Run Code Online (Sandbox Code Playgroud)

java swing multithreading synchronization timer

1
推荐指数
1
解决办法
331
查看次数