homebridge-lanternic 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +260 -0
- package/config.schema.json +412 -0
- package/dist/ble/magicLanternBleManager.d.ts +78 -0
- package/dist/ble/magicLanternBleManager.js +325 -0
- package/dist/ble/magicLanternBleManager.js.map +1 -0
- package/dist/ble/magicLanternCommands.d.ts +16 -0
- package/dist/ble/magicLanternCommands.js +49 -0
- package/dist/ble/magicLanternCommands.js.map +1 -0
- package/dist/ble/nobleTypes.d.ts +33 -0
- package/dist/ble/nobleTypes.js +2 -0
- package/dist/ble/nobleTypes.js.map +1 -0
- package/dist/color.d.ts +10 -0
- package/dist/color.js +65 -0
- package/dist/color.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +23 -0
- package/dist/platform.js +150 -0
- package/dist/platform.js.map +1 -0
- package/dist/platformAccessory.d.ts +26 -0
- package/dist/platformAccessory.js +139 -0
- package/dist/platformAccessory.js.map +1 -0
- package/dist/settings.d.ts +2 -0
- package/dist/settings.js +3 -0
- package/dist/settings.js.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/util/async.d.ts +2 -0
- package/dist/util/async.js +24 -0
- package/dist/util/async.js.map +1 -0
- package/dist/util/bluetooth.d.ts +3 -0
- package/dist/util/bluetooth.js +15 -0
- package/dist/util/bluetooth.js.map +1 -0
- package/package.json +81 -0
- package/tools/calibrate.mjs +314 -0
- package/tools/calibrator/app.js +399 -0
- package/tools/calibrator/index.html +91 -0
- package/tools/calibrator/styles.css +302 -0
- package/tools/explore.mjs +73 -0
- package/tools/scan.mjs +88 -0
- package/tools/send-sequence.mjs +76 -0
- package/tools/send.mjs +106 -0
package/tools/send.mjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { withBindings } from '@stoprocent/noble';
|
|
3
|
+
|
|
4
|
+
const binding = process.env.LANTERNIC_BINDING ?? 'default';
|
|
5
|
+
const serviceUuid = (process.env.LANTERNIC_SERVICE_UUID ?? 'fff0').replace(/[^0-9a-f]/gi, '').toLowerCase();
|
|
6
|
+
const characteristicUuid = (process.env.LANTERNIC_CHARACTERISTIC_UUID ?? 'fff3').replace(/[^0-9a-f]/gi, '').toLowerCase();
|
|
7
|
+
const address = process.argv[2];
|
|
8
|
+
const command = process.argv[3];
|
|
9
|
+
const value = process.argv[4];
|
|
10
|
+
|
|
11
|
+
if (!address || !command) {
|
|
12
|
+
console.error('Usage: lanternic-send <address> <on|off|brightness|rgb|raw> [value]');
|
|
13
|
+
console.error('Repo development: npm run send -- <address> <on|off|brightness|rgb|raw> [value]');
|
|
14
|
+
console.error('Examples:');
|
|
15
|
+
console.error(' lanternic-send be:16:70:00:08:2a on');
|
|
16
|
+
console.error(' lanternic-send be:16:70:00:08:2a brightness 50');
|
|
17
|
+
console.error(' lanternic-send be:16:70:00:08:2a rgb ff0000');
|
|
18
|
+
console.error(' lanternic-send be:16:70:00:08:2a raw 7e0404f00001ff00ef');
|
|
19
|
+
process.exit(2);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const cleanId = input => String(input ?? '').replace(/[^0-9a-f]/gi, '').toLowerCase();
|
|
23
|
+
const peripheralId = peripheral => peripheral.address || peripheral.uuid || peripheral.id;
|
|
24
|
+
const targetId = cleanId(address);
|
|
25
|
+
const noble = withBindings(binding);
|
|
26
|
+
|
|
27
|
+
const byte = number => Math.max(0, Math.min(255, Math.round(number)));
|
|
28
|
+
const percent = number => Math.max(0, Math.min(100, Math.round(number)));
|
|
29
|
+
const frame = (...bytes) => Buffer.from(bytes.map(byte));
|
|
30
|
+
|
|
31
|
+
const buildPayload = () => {
|
|
32
|
+
if (command === 'on') {
|
|
33
|
+
return Buffer.from('7e0404f00001ff00ef', 'hex');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (command === 'off') {
|
|
37
|
+
return Buffer.from('7e0404000000ff00ef', 'hex');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (command === 'brightness') {
|
|
41
|
+
return frame(0x7e, 0x04, 0x01, percent(Number(value)), 0x01, 0xff, 0xff, 0x00, 0xef);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (command === 'rgb') {
|
|
45
|
+
const rgb = cleanId(value);
|
|
46
|
+
if (rgb.length !== 6) {
|
|
47
|
+
throw new Error('rgb value must be RRGGBB hex, for example ff0000');
|
|
48
|
+
}
|
|
49
|
+
return Buffer.from(`7e070503${rgb}10ef`, 'hex');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (command === 'raw') {
|
|
53
|
+
return Buffer.from(cleanId(value), 'hex');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
throw new Error(`Unknown command: ${command}`);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const payload = buildPayload();
|
|
60
|
+
console.log(`Sending ${payload.toString('hex')} to ${address} with binding=${binding}`);
|
|
61
|
+
|
|
62
|
+
await noble.waitForPoweredOnAsync(15_000);
|
|
63
|
+
await noble.startScanningAsync([], true);
|
|
64
|
+
|
|
65
|
+
const peripheral = await new Promise((resolve, reject) => {
|
|
66
|
+
const timeout = setTimeout(() => {
|
|
67
|
+
noble.removeListener('discover', onDiscover);
|
|
68
|
+
reject(new Error(`Timed out scanning for ${address}`));
|
|
69
|
+
}, 20_000);
|
|
70
|
+
|
|
71
|
+
const onDiscover = candidate => {
|
|
72
|
+
const ids = [candidate.id, candidate.uuid, candidate.address, peripheralId(candidate)].map(cleanId);
|
|
73
|
+
if (!ids.includes(targetId)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
clearTimeout(timeout);
|
|
78
|
+
noble.removeListener('discover', onDiscover);
|
|
79
|
+
resolve(candidate);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
noble.on('discover', onDiscover);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await noble.stopScanningAsync();
|
|
86
|
+
await peripheral.connectAsync();
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const { characteristics } = await peripheral.discoverSomeServicesAndCharacteristicsAsync(
|
|
90
|
+
[serviceUuid],
|
|
91
|
+
[characteristicUuid],
|
|
92
|
+
);
|
|
93
|
+
const characteristic = characteristics[0];
|
|
94
|
+
|
|
95
|
+
if (!characteristic) {
|
|
96
|
+
throw new Error(`Missing characteristic ${serviceUuid}/${characteristicUuid}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const withoutResponse = !characteristic.properties.includes('write')
|
|
100
|
+
&& characteristic.properties.includes('writeWithoutResponse');
|
|
101
|
+
await characteristic.writeAsync(payload, withoutResponse);
|
|
102
|
+
console.log(`Write complete withoutResponse=${withoutResponse}`);
|
|
103
|
+
} finally {
|
|
104
|
+
await peripheral.disconnectAsync();
|
|
105
|
+
noble.stop();
|
|
106
|
+
}
|