@tanislav000/bluez
Version:
Bluez5 D-Bus bindings for easy to use bluetooth access in Node.js
129 lines • 6.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrgBluezGattCharacteristic1 = void 0;
const utilts_1 = require("../utilts");
/**
* Service: org.bluez
* ObjectPath: /org/bluez/hci0/dev_80_E1_26_08_94_85/-/-
* Interface: org.bluez.GattCharacteristic1
*/
class OrgBluezGattCharacteristic1 extends utilts_1.LooselyTypedEmitter {
static Connect(bus, objectPath, xml) {
return bus.getProxyObject("org.bluez", objectPath, xml).then((obj) => new OrgBluezGattCharacteristic1(obj));
}
constructor(dbusObject) {
super();
this.dbusObject = dbusObject;
this.thisDBusInterface = this.dbusObject.getInterface("org.bluez.GattCharacteristic1");
this.propertiesDBusInterface = this.dbusObject.getInterface("org.freedesktop.DBus.Properties");
// forward property change events
const forwardPropertyChange = (iface, changed, invalidated) => {
if (iface === OrgBluezGattCharacteristic1.DbusInterfaceName) {
this.emit("PropertiesChanged", iface, (0, utilts_1.unwrapDbusVariantObject)(changed), invalidated);
}
};
// forward all signals
this.on("newListener", (event, listener) => {
if (event === "PropertiesChanged" && this.listenerCount("PropertiesChanged") === 0) {
this.propertiesDBusInterface.addListener("PropertiesChanged", forwardPropertyChange);
}
else {
this.thisDBusInterface.addListener(event, listener);
}
});
this.on("removeListener", (event, listener) => {
if (event === "PropertiesChanged" && this.listenerCount("PropertiesChanged") === 0) {
this.propertiesDBusInterface.removeListener("PropertiesChanged", forwardPropertyChange);
}
else {
this.thisDBusInterface.removeListener(event, listener);
}
});
}
/***** Properties *****/
getProperties() {
return this.propertiesDBusInterface
.GetAll(OrgBluezGattCharacteristic1.DbusInterfaceName)
.then(utilts_1.unwrapDbusVariantObject);
}
getProperty(name) {
return this.propertiesDBusInterface
.Get(OrgBluezGattCharacteristic1.DbusInterfaceName, name)
.then(utilts_1.unwrapDbusVariant);
}
setProperty(name, value) {
return this.propertiesDBusInterface.Set(OrgBluezGattCharacteristic1.DbusInterfaceName, name, (0, utilts_1.wrapDbusVariant)(value));
}
//@property({ name: 'UUID', signature: 's', access: ACCESS_READ })
UUID() {
return this.propertiesDBusInterface
.Get(OrgBluezGattCharacteristic1.DbusInterfaceName, "UUID")
.then(utilts_1.unwrapDbusVariant);
}
//@property({ name: 'Service', signature: 'o', access: ACCESS_READ })
Service() {
return this.propertiesDBusInterface
.Get(OrgBluezGattCharacteristic1.DbusInterfaceName, "Service")
.then(utilts_1.unwrapDbusVariant);
}
//@property({ name: 'Value', signature: 'ay', access: ACCESS_READ })
Value() {
return this.propertiesDBusInterface
.Get(OrgBluezGattCharacteristic1.DbusInterfaceName, "Value")
.then(utilts_1.unwrapDbusVariant);
}
//@property({ name: 'Notifying', signature: 'b', access: ACCESS_READ })
Notifying() {
return this.propertiesDBusInterface
.Get(OrgBluezGattCharacteristic1.DbusInterfaceName, "Notifying")
.then(utilts_1.unwrapDbusVariant);
}
//@property({ name: 'Flags', signature: 'as', access: ACCESS_READ })
Flags() {
return this.propertiesDBusInterface
.Get(OrgBluezGattCharacteristic1.DbusInterfaceName, "Flags")
.then(utilts_1.unwrapDbusVariant);
}
//@property({ name: 'WriteAcquired', signature: 'b', access: ACCESS_READ })
WriteAcquired() {
return this.propertiesDBusInterface
.Get(OrgBluezGattCharacteristic1.DbusInterfaceName, "WriteAcquired")
.then(utilts_1.unwrapDbusVariant);
}
//@property({ name: 'NotifyAcquired', signature: 'b', access: ACCESS_READ })
NotifyAcquired() {
return this.propertiesDBusInterface
.Get(OrgBluezGattCharacteristic1.DbusInterfaceName, "NotifyAcquired")
.then(utilts_1.unwrapDbusVariant);
}
/***** Methods *****/
//@method({ name: 'ReadValue', inSignature: 'a{sv}', outSignature: 'ay' })
ReadValue(options) {
return this.thisDBusInterface.ReadValue((0, utilts_1.wrapDbusSignature)(options, "a{sv}")).then((0, utilts_1.unwrapDbusSignature)("ay"));
}
//@method({ name: 'WriteValue', inSignature: 'aya{sv}', outSignature: '' })
WriteValue(value, options) {
return this.thisDBusInterface.WriteValue((0, utilts_1.wrapDbusSignature)(value, "ay"), (0, utilts_1.wrapDbusSignature)(options, "a{sv}"));
}
//@method({ name: 'AcquireWrite', inSignature: 'a{sv}', outSignature: 'hq' })
AcquireWrite(options) {
return this.thisDBusInterface.AcquireWrite((0, utilts_1.wrapDbusSignature)(options, "a{sv}")).then((0, utilts_1.unwrapDbusSignature)("hq"));
}
//@method({ name: 'AcquireNotify', inSignature: 'a{sv}', outSignature: 'hq' })
AcquireNotify(options) {
return this.thisDBusInterface
.AcquireNotify((0, utilts_1.wrapDbusSignature)(options, "a{sv}"))
.then((0, utilts_1.unwrapDbusSignature)("hq"));
}
//@method({ name: 'StartNotify', inSignature: '', outSignature: '' })
StartNotify() {
return this.thisDBusInterface.StartNotify();
}
//@method({ name: 'StopNotify', inSignature: '', outSignature: '' })
StopNotify() {
return this.thisDBusInterface.StopNotify();
}
}
exports.OrgBluezGattCharacteristic1 = OrgBluezGattCharacteristic1;
OrgBluezGattCharacteristic1.DbusInterfaceName = "org.bluez.GattCharacteristic1";
//# sourceMappingURL=GattCharacteristic1.js.map