0.2.5 • Published 6 months ago
oxyzen-sdk v0.2.5
OxyzenSDK NodeJS
Requirement
- BLE 4.2 or later
- Mac 10.15 or later
- Windows 10 build 10.0.15063 or later
- Raspberrypi OS 5.10
- NodeJS >=12.18.0 | >=14.17.0 | >=16.13.0
Integration
package.json
"dependencies": {
"oxyzen-sdk": "^0.0.17"
},
Usage
Init
let _ozSDK;
async function initSDK(onAdapterStateChanged) {
if (_ozSDK) return;
OzLogger.i('OzSDK.init');
// eslint-disable-next-line require-atomic-updates
_ozSDK = await OzSDK.init(OZLogLevel.enum('info')); //info/error/warn
_ozSDK.on('error', (e) => _runErrorCB(e));
_ozSDK.on('onAdapterStateChanged', async (available) => {
if (available) {
// if (ozDeviceMap.size > 0) _startReconnectTimer();
} else {
_runErrorCB(OZError.enum('ble_power_off'));
await stopScan();
//NOTE: 在ozDeviceMap中保留,不删除,用于设备重连
ozDeviceMap.forEach(device => device.disconnect(false));
}
if (onAdapterStateChanged) onAdapterStateChanged(available);
});
if (_ozSDK.adapter.available) onAdapterStateChanged(true);
OzLogger.i('OzSDK.init done');
};
(async function main() {
OzLogger.i('------------- Example Main -------------');
await initSDK(async (adapterAvailable) => {
if (adapterAvailable) await startScan();
});
})();
Scan 扫描
首次配对新设备时,需要先将头环设置为配对模式-->蓝灯快闪
_ozSDK.startScan(async device => {
console.log(`found device, [${p.name}] ${p.address}`);
});
Connect 连接
device.listener = exampleListener;
await device.connect();
Disconnect 断开连接
// disconnect device
await device.disconnect();
async function disposeSDK(cb) {
disconnectAll();
await OzSDK.dispose();
_ozSDK = null;
if (cb) cb();
};
// when exit application, disconnect all devices & clean resources
process.on('SIGINT', async () => {
OzLogger.i({ message: `SIGINT signal received.` });
await disposeSDK();
OzLogger.i('End program');
process.exit(0);
});
async function disconnectAll() {
ozDeviceMap.forEach(device => device.disconnect());
ozDeviceMap.clear();
await stopScan();
}
ENUM
// 头环连接状态
const CONNECTIVITY = createEnum({
connecting: 0,
connected: 1,
disconnecting: 2,
disconnected: 3,
});
// 佩戴状态,电极与皮肤接触良好
// 佩戴方向,检测是否佩戴反
const ORIENTATION = createEnum({
unknown: 0,
normal: 1, //头环戴正
upsideDown: 2, //头环戴反
});
StartIMU 开启传输陀螺仪数据
device.listener = exampleListener;
device.startIMU();
More
class ZenliteDevice {
id,
name,
connectivity,
connect()
disconnect()
pair(cb)
startEEG(cb)
stopEEG(cb)
startIMU(cb)
stopIMU(cb)
startPPG(cb)
stopPPG(cb)
shutdown(cb)
// @param name length should be 4 ~ 18
setDeviceName(name, cb)
}
Oxyzen Docs
0.2.1
6 months ago
0.2.0
6 months ago
0.2.3
6 months ago
0.2.2
6 months ago
0.2.5
6 months ago
0.2.4
6 months ago
0.0.20
8 months ago
0.0.18
8 months ago
0.0.19
8 months ago
0.1.0
8 months ago
0.1.2
8 months ago
0.1.1
8 months ago
0.1.7
8 months ago
0.1.4
8 months ago
0.1.3
8 months ago
0.1.6
8 months ago
0.1.5
8 months ago
0.0.17
10 months ago
0.0.16
11 months ago
0.0.15
11 months ago
0.0.14
11 months ago
0.0.13
11 months ago
0.0.12
11 months ago
0.0.11
11 months ago
0.0.10
11 months ago
0.0.9
11 months ago
0.0.8
11 months ago
0.0.7
11 months ago
0.0.6
11 months ago
0.0.5
11 months ago
0.0.4
11 months ago
0.0.3
11 months ago
0.0.2
11 months ago
0.0.1
11 months ago