Initial commit
This commit is contained in:
46
uni_modules/ak-sbsrv/utssdk/web/index.uts
Normal file
46
uni_modules/ak-sbsrv/utssdk/web/index.uts
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as BluetoothManager from './bluetooth_manager.uts';
|
||||
|
||||
export const bluetoothService = {
|
||||
scanDevices: BluetoothManager.scanDevices,
|
||||
connectDevice: BluetoothManager.connectDevice,
|
||||
disconnectDevice: BluetoothManager.disconnectDevice,
|
||||
getConnectedDevices: BluetoothManager.getConnectedDevices,
|
||||
discoverServices: BluetoothManager.discoverServices,
|
||||
// compatibility aliases used by app code
|
||||
getServices: BluetoothManager.discoverServices,
|
||||
getCharacteristics: BluetoothManager.getCharacteristics,
|
||||
readCharacteristic: BluetoothManager.readCharacteristic,
|
||||
writeCharacteristic: BluetoothManager.writeCharacteristic,
|
||||
subscribeCharacteristic: BluetoothManager.subscribeCharacteristic,
|
||||
unsubscribeCharacteristic: BluetoothManager.unsubscribeCharacteristic,
|
||||
sendCommand: BluetoothManager.sendCommand,
|
||||
onConnectionStateChange: BluetoothManager.onConnectionStateChange,
|
||||
// 兼容旧接口,如有 readCharacteristic 可补充
|
||||
};
|
||||
|
||||
// Provide a minimal EventEmitter-style `.on(eventName, handler)` to match app code
|
||||
// Supported events: 'deviceFound', 'scanFinished', 'connectionStateChanged'
|
||||
bluetoothService.on = function(eventName: string, handler: Function) {
|
||||
if (!eventName || typeof handler !== 'function') return;
|
||||
switch (eventName) {
|
||||
case 'deviceFound':
|
||||
return BluetoothManager.onDeviceFound(handler);
|
||||
case 'scanFinished':
|
||||
return BluetoothManager.onScanFinished(handler);
|
||||
case 'connectionStateChanged':
|
||||
return BluetoothManager.onConnectionStateChange(handler);
|
||||
default:
|
||||
// no-op for unsupported events
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Backwards-compat: getAutoBleInterfaces expected by pages -> maps to autoConnect
|
||||
if (!bluetoothService.getAutoBleInterfaces) {
|
||||
bluetoothService.getAutoBleInterfaces = function(deviceId: string) {
|
||||
return BluetoothManager.autoConnect(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
import { dfuManager as webDfuManager } from './dfu_manager.uts'
|
||||
export const dfuManager = webDfuManager;
|
||||
Reference in New Issue
Block a user