wechat/device

device module provides device sensor API bindings details in wechat document

Types

BLE Peripheral Server (蓝牙低功耗外围设备)

BLEPeripheralServer type

pub type BLEPeripheralServer

Values

pub fn ble_peripheral_server_add_service(
  server: BLEPeripheralServer,
  service s: object.JsObject,
) -> Nil

BLEPeripheralServer.addService Add service

pub fn ble_peripheral_server_close(
  server: BLEPeripheralServer,
) -> Nil

BLEPeripheralServer.close Close server

pub fn ble_peripheral_server_off_characteristic_read_request(
  server: BLEPeripheralServer,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

BLEPeripheralServer.offCharacteristicReadRequest Remove characteristic read request listener

pub fn ble_peripheral_server_off_characteristic_subscribed(
  server: BLEPeripheralServer,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

BLEPeripheralServer.offCharacteristicSubscribed Remove characteristic subscribed listener

pub fn ble_peripheral_server_off_characteristic_unsubscribed(
  server: BLEPeripheralServer,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

BLEPeripheralServer.offCharacteristicUnsubscribed Remove characteristic unsubscribed listener

pub fn ble_peripheral_server_off_characteristic_write_request(
  server: BLEPeripheralServer,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

BLEPeripheralServer.offCharacteristicWriteRequest Remove characteristic write request listener

pub fn ble_peripheral_server_on_characteristic_read_request(
  server: BLEPeripheralServer,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

BLEPeripheralServer.onCharacteristicReadRequest Listen for characteristic read request

pub fn ble_peripheral_server_on_characteristic_subscribed(
  server: BLEPeripheralServer,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

BLEPeripheralServer.onCharacteristicSubscribed Listen for characteristic subscribed

pub fn ble_peripheral_server_on_characteristic_unsubscribed(
  server: BLEPeripheralServer,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

BLEPeripheralServer.onCharacteristicUnsubscribed Listen for characteristic unsubscribed

pub fn ble_peripheral_server_on_characteristic_write_request(
  server: BLEPeripheralServer,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

BLEPeripheralServer.onCharacteristicWriteRequest Listen for characteristic write request

pub fn ble_peripheral_server_remove_service(
  server: BLEPeripheralServer,
  service s: object.JsObject,
) -> Nil

BLEPeripheralServer.removeService Remove service

pub fn ble_peripheral_server_start_advertising(
  server: BLEPeripheralServer,
) -> Nil

BLEPeripheralServer.startAdvertising Start advertising

pub fn ble_peripheral_server_stop_advertising(
  server: BLEPeripheralServer,
) -> Nil

BLEPeripheralServer.stopAdvertising Stop advertising

pub fn ble_peripheral_server_write_characteristic_value(
  server: BLEPeripheralServer,
  data d: object.JsObject,
) -> Nil

BLEPeripheralServer.writeCharacteristicValue Write characteristic value

pub fn check_is_open_accessibility() -> Bool

Phase 13: Device Advanced - Accessibility

wx.checkIsOpenAccessibility Check if accessibility is enabled on the device

pub fn close_ble_connection(
  device_id d: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.closeBLEConnection Disconnect from BLE peripheral

pub fn close_bluetooth_adapter(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.closeBluetoothAdapter Close Bluetooth adapter

pub fn connect_wifi(
  ssid s: String,
  bssid b: String,
  password p: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

Phase 13: Device Advanced - WiFi

wx.connectWifi Connect to a WiFi network

pub fn create_ble_connection(
  device_id d: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.createBLEConnection Connect to BLE peripheral

pub fn create_ble_peripheral_server(
  options o: object.JsObject,
) -> BLEPeripheralServer

wx.createBLEPeripheralServer Create BLE peripheral server

pub fn get_battery_info_sync() -> object.JsObject

Phase 13: Device Advanced - Battery

wx.getBatteryInfoSync Synchronously get battery information

pub fn get_beacons(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.getBeacons Get all discovered Beacon devices

pub fn get_ble_device_characteristics(
  device_id d: String,
  service_id s: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.getBLEDeviceCharacteristics Get characteristic values of specified service

pub fn get_ble_device_rssi(
  device_id d: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.getBLEDeviceRSSI Get BLE device RSSI (signal strength)

pub fn get_ble_device_services(
  device_id d: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.getBLEDeviceServices Get services of BLE device

pub fn get_ble_mtu(
  device_id d: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.getBLEMTU Get current BLE MTU size for a connection

pub fn get_bluetooth_adapter_state(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.getBluetoothAdapterState Get Bluetooth adapter state

pub fn get_bluetooth_devices(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.getBluetoothDevices Get all discovered devices

pub fn get_connected_bluetooth_devices(
  services s: object.JsObject,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.getConnectedBluetoothDevices Get devices connected according to UUID

pub fn get_nfc_adapter() -> object.JsObject

Near Field Communication (NFC)

wx.getNFCAdapter Get NFC adapter

pub fn is_bluetooth_device_paired(
  device_id d: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.isBluetoothDevicePaired Check if a Bluetooth device is paired

pub fn make_bluetooth_pair(
  device_id d: String,
  pin p: String,
  timeout t: Int,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

Phase 12: Bluetooth Advanced

wx.makeBluetoothPair Initiate Bluetooth pairing with a device

pub fn nfc_adapter_off_discovered(
  adapter: object.JsObject,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

NfcAdapter.offDiscovered Cancel listening for discovered NFC tags

pub fn nfc_adapter_on_discovered(
  adapter: object.JsObject,
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

NfcAdapter.onDiscovered Listen for discovered NFC tags

pub fn nfc_adapter_start_discovery(
  adapter: object.JsObject,
  options o: object.JsObject,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

NfcAdapter.startDiscovery Start searching for NFC tags

pub fn nfc_adapter_stop_discovery(
  adapter: object.JsObject,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

NfcAdapter.stopDiscovery Stop searching for NFC tags

pub fn notify_ble_characteristic_value_change(
  device_id d: String,
  service_id s: String,
  characteristic_id c: String,
  state s2: Bool,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.notifyBLECharacteristicValueChange Enable notifications for characteristic value changes

pub fn off_accelerometer_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offAccelerometerChange Remove accelerometer change listener

pub fn off_beacon_service_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offBeaconServiceChange Remove Beacon service state change event listener

pub fn off_beacon_update(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offBeaconUpdate Remove Beacon device update event listener

pub fn off_ble_characteristic_value_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offBLECharacteristicValueChange Cancel listening for characteristic value change

pub fn off_ble_connection_state_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offBLEConnectionStateChange Cancel listening for BLE connection state change

pub fn off_ble_mtu_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offBLEMTUChange Remove BLE MTU change event listener

pub fn off_ble_peripheral_connection_state_changed(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offBLEPeripheralConnectionStateChanged Remove BLE peripheral connection state change listener

pub fn off_bluetooth_adapter_state_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offBluetoothAdapterStateChange Cancel listening for Bluetooth adapter state change

pub fn off_bluetooth_device_found(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offBluetoothDeviceFound Cancel listening for newly discovered devices

pub fn off_compass_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offCompassChange Remove compass change listener

pub fn off_device_motion_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offDeviceMotionChange Remove device motion change listener

pub fn off_gyroscope_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offGyroscopeChange Remove gyroscope change listener

pub fn off_key_down(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offKeyDown Remove keyboard key down event listener

pub fn off_key_up(callback cb: fn(object.JsObject) -> Nil) -> Nil

wx.offKeyUp Remove keyboard key up event listener

pub fn off_memory_warning(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offMemoryWarning Remove memory warning event listener

pub fn off_wifi_connected_with_partial_info(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.offWifiConnectedWithPartialInfo Remove WiFi connection event listener

pub fn on_accelerometer_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onAccelerometerChange Listen for accelerometer changes

pub fn on_beacon_service_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onBeaconServiceChange Listen for Beacon service state change event

pub fn on_beacon_update(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onBeaconUpdate Listen for Beacon device update event

pub fn on_ble_characteristic_value_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onBLECharacteristicValueChange Listen for characteristic value change

pub fn on_ble_connection_state_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onBLEConnectionStateChange Listen for BLE connection state change

pub fn on_ble_mtu_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onBLEMTUChange Listen for BLE MTU change events

pub fn on_ble_peripheral_connection_state_changed(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onBLEPeripheralConnectionStateChanged Listen for BLE peripheral connection state change

pub fn on_bluetooth_adapter_state_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onBluetoothAdapterStateChange Listen for Bluetooth adapter state change

pub fn on_bluetooth_device_found(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onBluetoothDeviceFound Listen for newly discovered devices

pub fn on_compass_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onCompassChange Listen for compass changes

pub fn on_device_motion_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onDeviceMotionChange Listen for device motion changes

pub fn on_gyroscope_change(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onGyroscopeChange Listen for gyroscope changes

pub fn on_key_down(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

Phase 13: Device Advanced - Keyboard Events

wx.onKeyDown Listen for keyboard key down events

pub fn on_key_up(callback cb: fn(object.JsObject) -> Nil) -> Nil

wx.onKeyUp Listen for keyboard key up events

pub fn on_memory_warning(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

System Memory

wx.onMemoryWarning Listen for memory warning event

pub fn on_wifi_connected_with_partial_info(
  callback cb: fn(object.JsObject) -> Nil,
) -> Nil

wx.onWifiConnectedWithPartialInfo Listen for WiFi connection events with partial information

pub fn open_bluetooth_adapter(
  options o: object.JsObject,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

Bluetooth Low Energy (BLE)

wx.openBluetoothAdapter Initialize Bluetooth adapter

pub fn read_ble_characteristic_value(
  device_id d: String,
  service_id s: String,
  characteristic_id c: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.readBLECharacteristicValue Read characteristic value

pub fn set_ble_mtu(
  device_id d: String,
  mtu m: Int,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.setBLEMTU Set BLE MTU size for a connection

pub fn set_visual_effect_on_capture(
  visual_effect_enabled v: Bool,
  visual_effect_type t: String,
) -> Nil

Phase 13: Device Advanced - Screen

wx.setVisualEffectOnCapture Set visual effect when capturing screen

pub fn start_accelerometer(
  interval i: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

Accelerometer

wx.startAccelerometer Start accelerometer

pub fn start_beacon_discovery(
  options o: object.JsObject,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

Beacon (蓝牙信标)

wx.startBeaconDiscovery Start searching for Beacon devices

pub fn start_bluetooth_devices_discovery(
  options o: object.JsObject,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.startBluetoothDevicesDiscovery Start searching for nearby BLE devices

pub fn start_compass(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

Compass

wx.startCompass Start compass

pub fn start_device_motion_listening(
  acceleration ai: Bool,
  rotation_rate rr: Bool,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

Device Motion

wx.startDeviceMotionListening Start device motion listening

pub fn start_gyroscope(
  interval i: String,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

Gyroscope

wx.startGyroscope Start gyroscope

pub fn stop_accelerometer(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.stopAccelerometer Stop accelerometer

pub fn stop_beacon_discovery() -> Nil

wx.stopBeaconDiscovery Stop searching for Beacon devices

pub fn stop_bluetooth_devices_discovery(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.stopBluetoothDevicesDiscovery Stop searching for nearby BLE devices

pub fn stop_compass(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.stopCompass Stop compass

pub fn stop_device_motion_listening(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.stopDeviceMotionListening Stop device motion listening

pub fn stop_gyroscope(
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.stopGyroscope Stop gyroscope

pub fn write_ble_characteristic_value(
  device_id d: String,
  service_id s: String,
  characteristic_id c: String,
  value v: object.JsObject,
  complete cb: fn() -> Nil,
) -> promise.Promise(Result(object.JsObject, object.WechatError))

wx.writeBLECharacteristicValue Write characteristic value

Search Document