Manual unsubscribing
This commit is contained in:
parent
8f6c26148e
commit
0fe2a4e524
@ -197,6 +197,14 @@ class BoostHub extends Hub {
|
||||
}
|
||||
|
||||
|
||||
_deactivatePortDevice (port, type, mode, format, callback) {
|
||||
const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL];
|
||||
if (characteristic) {
|
||||
characteristic.write(Buffer.from([0x0a, 0x00, 0x41, port, mode, 0x01, 0x00, 0x00, 0x00, 0x00]), callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_parseSensorMessage (data) {
|
||||
|
||||
let port = this._getPortForPortNumber(data[3]);
|
||||
|
27
hub.js
27
hub.js
@ -112,6 +112,33 @@ class Hub extends EventEmitter {
|
||||
}
|
||||
|
||||
|
||||
unsubscribe (port, mode = false) {
|
||||
if (!mode) {
|
||||
switch (this.ports[port].type) {
|
||||
case Consts.Devices.BASIC_MOTOR:
|
||||
mode = 0x02;
|
||||
break;
|
||||
case Consts.Devices.BOOST_INTERACTIVE_MOTOR:
|
||||
mode = 0x02;
|
||||
break;
|
||||
case Consts.Devices.BOOST_MOVE_HUB_MOTOR:
|
||||
mode = 0x02;
|
||||
break;
|
||||
case Consts.Devices.BOOST_DISTANCE:
|
||||
mode = Consts.Hubs.WEDO2_SMART_HUB ? 0x00 : 0x08
|
||||
break;
|
||||
case Consts.Devices.BOOST_TILT:
|
||||
mode = 0x04;
|
||||
break;
|
||||
default:
|
||||
mode = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._deactivatePortDevice(this.ports[port].value, this.ports[port].type, mode, 0x00);
|
||||
}
|
||||
|
||||
|
||||
_subscribeToCharacteristic (characteristic, callback) {
|
||||
characteristic.on("data", (data, isNotification) => {
|
||||
return callback(data);
|
||||
|
@ -116,6 +116,14 @@ class WeDo2Hub extends Hub {
|
||||
}
|
||||
|
||||
|
||||
_deactivatePortDevice (port, type, mode, format, callback) {
|
||||
const characteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.PORT_TYPE_WRITE];
|
||||
if (characteristic) {
|
||||
characteristic.write(Buffer.from([0x01, 0x02, port, type, mode, 0x01, 0x00, 0x00, 0x00, format, 0x00]), callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_parseSensorMessage (data) {
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user