node-red-contrib-jacdac
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -11,25 +11,27 @@ "use strict"; | ||
const filterEvent = filters_1.createEventFilter(config); | ||
const sendEvent = (evt) => { | ||
const { service } = evt; | ||
const { device } = service; | ||
this.debug(`event ${evt}`); | ||
this.send({ | ||
payload: { | ||
deviceId: device.deviceId, | ||
deviceShortId: device.shortId, | ||
serviceIndex: service.serviceIndex, | ||
serviceInstanceName: service.instanceName, | ||
serviceName: service.name, | ||
eventCode: evt.code, | ||
eventName: evt.name, | ||
data: evt.data | ||
} | ||
}); | ||
}; | ||
const registerDevice = (dev) => { | ||
if (!filterDevice(dev)) | ||
return; | ||
this.log(`registering device ${dev}`); | ||
if (filterDevice(dev)) { | ||
// register events | ||
for (const srv of dev.services().filter(filterService)) { | ||
for (const evt of srv.events.filter(filterEvent)) { | ||
this.log(`registering event ${evt}`); | ||
evt.on(jacdac_ts_1.EVENT, () => { | ||
this.debug(`event ${evt}`); | ||
this.send({ | ||
payload: { | ||
deviceId: dev.deviceId, | ||
deviceShortId: dev.shortId, | ||
serviceIndex: srv.serviceIndex, | ||
serviceClass: srv.serviceClass, | ||
serviceName: srv.name, | ||
eventCode: evt.code, | ||
eventName: evt.name, | ||
data: evt.data | ||
} | ||
}); | ||
}); | ||
} | ||
for (const srv of dev.services().filter(filterService)) { | ||
for (const evt of srv.events.filter(filterEvent)) { | ||
this.log(`registering event ${evt}`); | ||
evt.on(jacdac_ts_1.EVENT, sendEvent); | ||
} | ||
@@ -36,0 +38,0 @@ } |
@@ -11,2 +11,4 @@ "use strict"; | ||
const filterRegister = filters_1.createRegisterFilter(config); | ||
const { updates } = config; | ||
const reportEvent = updates ? jacdac_ts_1.REPORT_UPDATE : jacdac_ts_1.REPORT_RECEIVE; | ||
const registerDevice = (dev) => { | ||
@@ -18,14 +20,17 @@ this.log(`registering device ${dev}`); | ||
this.log(`registering register ${reg}`); | ||
reg.on(jacdac_ts_1.REPORT_RECEIVE, () => { | ||
this.debug(`report ${reg}`); | ||
// register this register will automatically | ||
// automatically have the bus | ||
// refresh its value | ||
reg.on(reportEvent, () => { | ||
this.send({ | ||
payload: { | ||
deviceId: dev.deviceId, | ||
data: reg.objectValue, | ||
deviceShortId: dev.shortId, | ||
serviceIndex: srv.serviceIndex, | ||
serviceName: srv.name, | ||
registerName: reg.name, | ||
// low-level info | ||
deviceId: dev.deviceId, | ||
serviceClass: srv.serviceClass, | ||
serviceName: srv.name, | ||
eventCode: reg.code, | ||
eventName: reg.name, | ||
data: reg.unpackedValue | ||
registerCode: reg.code, | ||
} | ||
@@ -32,0 +37,0 @@ }); |
@@ -14,6 +14,9 @@ "use strict"; | ||
function createServiceFilter(options) { | ||
const { service } = options; | ||
return (srv) => !service | ||
const { service, serviceIndex, serviceInstanceName } = options; | ||
const instanceNameRx = serviceInstanceName ? new RegExp(serviceInstanceName, "i") : undefined; | ||
return (srv) => (!service | ||
|| srv.serviceClass === parseInt(service, 16) | ||
|| (srv.name && srv.name.toLocaleLowerCase() === service.toLocaleLowerCase()); | ||
|| (srv.name && srv.name.toLocaleLowerCase() === service.toLocaleLowerCase())) | ||
&& (serviceIndex === undefined || serviceIndex == srv.serviceIndex) | ||
&& (!instanceNameRx || instanceNameRx.test(srv.instanceName)); | ||
} | ||
@@ -20,0 +23,0 @@ exports.createServiceFilter = createServiceFilter; |
{ | ||
"name": "node-red-contrib-jacdac", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Microsoft Jacdac for node-red", | ||
@@ -32,10 +32,9 @@ "keywords": [ | ||
"dependencies": { | ||
"jacdac-ts": "^1.13.9", | ||
"jacdac-ts": "^1.13.17", | ||
"webusb": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"semantic-release": "^17.4.2", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@semantic-release/exec": "^5.0.0", | ||
"@semantic-release/git": "^9.0.0", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@types/express": "^4.17.11", | ||
@@ -48,4 +47,4 @@ "@types/jest": "^26.0.23", | ||
"@types/supertest": "^2.0.11", | ||
"@typescript-eslint/eslint-plugin": "^4.22.1", | ||
"@typescript-eslint/parser": "^4.22.1", | ||
"@typescript-eslint/eslint-plugin": "^4.23.0", | ||
"@typescript-eslint/parser": "^4.23.0", | ||
"colorette": "^1.2.2", | ||
@@ -65,2 +64,3 @@ "concurrently": "^6.1.0", | ||
"rollup": "^2.47.0", | ||
"semantic-release": "^17.4.2", | ||
"ts-jest": "^26.5.6", | ||
@@ -67,0 +67,0 @@ "typescript": "^4.2.4" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
160
357273
Updatedjacdac-ts@^1.13.17