"use strict";
const getBLEDeviceServices = (deviceId) => {
  return new Promise((resolve, reject) => {
    wx.getBLEDeviceServices({
      deviceId,
      success: (result) => {
        console.log("\u6210\u529F");
        resolve(result);
      },
      fail: (err) => {
        wx.showToast({
          title: "\u672A\u80FD\u83B7\u53D6\u670D\u52A1"
        });
        reject(err);
      }
    });
  });
};
const getBLEDeviceCharacteristics = (deviceId, serviceId) => {
  return new Promise((resolve, reject) => {
    wx.getBLEDeviceCharacteristics({
      deviceId,
      serviceId,
      success: (result) => {
        resolve(result);
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
};
const notifyBLECharacteristicValueChange = (deviceId, serviceId, notifyCharacteristicId) => {
  return new Promise((resolve, reject) => {
    wx.notifyBLECharacteristicValueChange({
      deviceId,
      serviceId,
      characteristicId: notifyCharacteristicId,
      state: true,
      success: (result) => {
        resolve(result);
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
};
const writeBLECharacteristicValue = (deviceId, serviceId, writeCharacteristicId, value) => {
  return new Promise((resolve, reject) => {
    wx.writeBLECharacteristicValue({
      deviceId,
      serviceId,
      characteristicId: writeCharacteristicId,
      value,
      success: (result) => {
        wx.showToast({
          title: "\u5DF2\u6210\u529F\u53D1\u9001\u6570\u636E,\u84DD\u7259\u5DF2\u6253\u5F00"
        });
        resolve(result);
      },
      fail: (err) => {
        reject(err);
      }
    });
  });
};
const closeBluetoothAdapter = () => {
  return new Promise((resolve, reject) => {
    wx.closeBluetoothAdapter({
      success: (result) => {
        resolve(result);
      },
      fail: (err) => {
        wx.showToast({
          title: "\u6570\u636E\u53D1\u9001\u6210\u529F\uFF0C\u4F46\u672A\u5173\u95ED\u84DD\u7259\uFF0C\u8BF7\u624B\u52A8\u5173\u95ED",
          icon: "none"
        });
        reject(err);
      }
    });
  });
};
exports.closeBluetoothAdapter = closeBluetoothAdapter;
exports.getBLEDeviceCharacteristics = getBLEDeviceCharacteristics;
exports.getBLEDeviceServices = getBLEDeviceServices;
exports.notifyBLECharacteristicValueChange = notifyBLECharacteristicValueChange;
exports.writeBLECharacteristicValue = writeBLECharacteristicValue;
