mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-11 11:50:54 +08:00
Add definitions for github.com/sandeepmistry/noble
This commit is contained in:
@@ -200,6 +200,7 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [Mousetrap](http://craig.is/killing/mice) (by [Dániel Tar](https://github.com/qcz))
|
||||
* [msgpack.js](https://github.com/uupaa/msgpack.js) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki))
|
||||
* [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [noble](https://github.com/sandeepmistry/noble) (by [Seon-Wook Park](https://github.com/swook))
|
||||
* [Node.js](http://nodejs.org/) (from TypeScript samples)
|
||||
* [node_redis](https://github.com/mranney/node_redis) (by [Boris Yankov](https://github.com/borisyankov))
|
||||
* [node-ffi](https://github.com/rbranson/node-ffi) (by [Paul Loyd](https://github.com/loyd))
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/// <reference path="noble.d.ts" />
|
||||
|
||||
import noble = require("noble");
|
||||
|
||||
function test_startScanning(): void {
|
||||
"use strict";
|
||||
noble.startScanning();
|
||||
noble.startScanning(["0x180d"]);
|
||||
noble.startScanning(["0x180d"], true);
|
||||
}
|
||||
test_startScanning();
|
||||
|
||||
function test_stopScanning(): void {
|
||||
"use strict";
|
||||
noble.stopScanning();
|
||||
}
|
||||
test_stopScanning();
|
||||
|
||||
noble.on("stateChange", (state: string): void => {});
|
||||
noble.on("scanStart", (): void => {});
|
||||
noble.on("scanStop", (): void => {});
|
||||
noble.on("discover", (peripheral: noble.Peripheral): void => {
|
||||
peripheral.connect((error: string): void => {});
|
||||
peripheral.disconnect((): void => {});
|
||||
});
|
||||
|
||||
var peripheral: noble.Peripheral = new noble.Peripheral();
|
||||
peripheral.uuid = "12ad4e81";
|
||||
peripheral.advertisement = {
|
||||
localName: "device",
|
||||
serviceData: new Buffer(1),
|
||||
txPowerLevel: 1,
|
||||
manufacturerData: new Buffer(1),
|
||||
serviceUuids: ["0x180a", "0x180d"]
|
||||
};
|
||||
peripheral.connect((error: string): void => {});
|
||||
peripheral.disconnect((): void => {});
|
||||
peripheral.discoverServices(["180d"], (error: string, services: noble.Service[]): void => {});
|
||||
peripheral.discoverAllServicesAndCharacteristics((error: string, services: noble.Service[], characteristics: noble.Characteristic[]): void => {});
|
||||
peripheral.discoverSomeServicesAndCharacteristics(["180d"], ["2a38"], (error: string, services: noble.Service[], characteristics: noble.Characteristic[]): void => {});
|
||||
peripheral.readHandle(new Buffer(1), (error: string, data: NodeBuffer): void => {});
|
||||
peripheral.writeHandle(new Buffer(1), new Buffer(1), true, (error: string): void => {});
|
||||
peripheral.on("connect", (error: string): void => {});
|
||||
peripheral.on("disconnect", (error: string): void => {});
|
||||
peripheral.on("rssiUpdate", (rssi: number): void => {});
|
||||
peripheral.on("servicesDiscover", (services: noble.Service[]): void => {});
|
||||
|
||||
var service: noble.Service = new noble.Service();
|
||||
service.uuid = "180a";
|
||||
service.name = "";
|
||||
service.type = "";
|
||||
service.includedServiceUuids = ["180d"];
|
||||
service.discoverIncludedServices(["180d"], (error: string, includedServiceUuids: string[]): void => {});
|
||||
service.discoverCharacteristics(["2a38"], (error: string, characteristics: noble.Characteristic[]): void => {});
|
||||
service.on("includedServicesDiscover", (includedServiceUuids: string[]): void => {});
|
||||
service.on("characteristicsDiscover", (characteristics: noble.Characteristic[]): void => {});
|
||||
|
||||
var characteristic: noble.Characteristic = new noble.Characteristic();
|
||||
characteristic.uuid = "2a37";
|
||||
characteristic.name = "";
|
||||
characteristic.type = "";
|
||||
characteristic.properties = ["read", "notify"];
|
||||
characteristic.read((error: string, data: NodeBuffer): void => {});
|
||||
characteristic.write(new Buffer(1), true, (error: string): void => {});
|
||||
characteristic.broadcast(true, (error: string): void => {});
|
||||
characteristic.notify(true, (error: string): void => {});
|
||||
characteristic.discoverDescriptors((error: string, descriptors: noble.Descriptor[]): void => {});
|
||||
characteristic.on("read", (data: NodeBuffer, isNotification: boolean): void => {});
|
||||
characteristic.on("write", true, (error: string): void => {});
|
||||
characteristic.on("broadcast", (state: string): void => {});
|
||||
characteristic.on("notify", (state: string): void => {});
|
||||
characteristic.on("descriptorsDiscover", (descriptors: noble.Descriptor[]): void => {});
|
||||
|
||||
var descriptor: noble.Descriptor = new noble.Descriptor();
|
||||
descriptor.uuid = "";
|
||||
descriptor.name = "";
|
||||
descriptor.type = "";
|
||||
descriptor.readValue((error: string, data: NodeBuffer): void => {});
|
||||
descriptor.writeValue(new Buffer(1), (error: string): void => {});
|
||||
descriptor.on("valueRead", (error: string, data: NodeBuffer): void => {});
|
||||
descriptor.on("valueWrite", (error: string): void => {});
|
||||
|
||||
// vim expandtab shiftwidth=4
|
||||
Vendored
+105
@@ -0,0 +1,105 @@
|
||||
// Type definitions for noble
|
||||
// Project: https://github.com/sandeepmistry/noble
|
||||
// Definitions by: Seon-Wook Park <https://github.com/swook>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module "noble" {
|
||||
export function startScanning(): void;
|
||||
export function startScanning(serviceUUIDs: string[]): void;
|
||||
export function startScanning(serviceUUIDs: string[], allowDuplicates: boolean): void;
|
||||
export function stopScanning(): void;
|
||||
|
||||
export function on(event: string, callback: Function): void;
|
||||
export function on(event: "stateChange", callback: (state: string) => void): void;
|
||||
export function on(event: "scanStart", callback: () => void): void;
|
||||
export function on(event: "scanStop", callback: () => void): void;
|
||||
export function on(event: "discover", callback: (peripheral: Peripheral) => void): void;
|
||||
|
||||
export class Peripheral {
|
||||
uuid: string;
|
||||
advertisement: Advertisement;
|
||||
rssi: number;
|
||||
services: string[];
|
||||
|
||||
connect(callback: (error: string) => void): void;
|
||||
disconnect(callback: () => void): void;
|
||||
discoverServices(serviceUUIDs: string[], callback: (error: string, services: Service[]) => void): void;
|
||||
discoverAllServicesAndCharacteristics(callback: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
|
||||
discoverSomeServicesAndCharacteristics(serviceUUIDs: string[], characteristicUUIDs: string[], callback: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
|
||||
|
||||
readHandle(handle: NodeBuffer, callback: (error: string, data: NodeBuffer) => void): void;
|
||||
writeHandle(handle: NodeBuffer, data: NodeBuffer, withoutResponse: boolean, callback: (error: string) => void): void;
|
||||
toString(): string;
|
||||
|
||||
on(event: string, callback: Function): void;
|
||||
on(event: "connect", callback: (error: string) => void): void;
|
||||
on(event: "disconnect", callback: (error: string) => void): void;
|
||||
on(event: "rssiUpdate", callback: (rssi: number) => void): void;
|
||||
on(event: "servicesDiscover", callback: (services: Service[]) => void): void;
|
||||
}
|
||||
|
||||
export interface Advertisement {
|
||||
localName: string;
|
||||
serviceData: NodeBuffer;
|
||||
txPowerLevel: number;
|
||||
manufacturerData: NodeBuffer;
|
||||
serviceUuids: string[];
|
||||
}
|
||||
|
||||
export class Service {
|
||||
uuid: string;
|
||||
name: string;
|
||||
type: string;
|
||||
includedServiceUuids: string[];
|
||||
characteristics: Characteristic[];
|
||||
|
||||
discoverIncludedServices(serviceUUIDs: string[], callback: (error: string, includedServiceUuids: string[]) => void): void;
|
||||
discoverCharacteristics(characteristicUUIDs: string[], callback: (error: string, characteristics: Characteristic[]) => void): void;
|
||||
toString(): string;
|
||||
|
||||
on(event: string, callback: Function): void;
|
||||
on(event: "includedServicesDiscover", callback: (includedServiceUuids: string[]) => void): void;
|
||||
on(event: "characteristicsDiscover", callback: (characteristics: Characteristic[]) => void): void;
|
||||
}
|
||||
|
||||
export class Characteristic {
|
||||
uuid: string;
|
||||
name: string;
|
||||
type: string;
|
||||
properties: string[];
|
||||
descriptors: Descriptor[];
|
||||
|
||||
read(callback: (error: string, data: NodeBuffer) => void): void;
|
||||
write(data: NodeBuffer, notify: boolean, callback: (error: string) => void): void;
|
||||
broadcast(broadcast: boolean, callback: (error: string) => void): void;
|
||||
notify(notify: boolean, callback: (error: string) => void): void;
|
||||
discoverDescriptors(callback: (error: string, descriptors: Descriptor[]) => void): void;
|
||||
toString(): string;
|
||||
|
||||
on(event: string, callback: Function): void;
|
||||
on(event: string, option: boolean, callback: Function): void;
|
||||
on(event: "read", callback: (data: NodeBuffer, isNotification: boolean) => void): void;
|
||||
on(event: "write", withoutResponse: boolean, callback: (error: string) => void): void;
|
||||
on(event: "broadcast", callback: (state: string) => void): void;
|
||||
on(event: "notify", callback: (state: string) => void): void;
|
||||
on(event: "descriptorsDiscover", callback: (descriptors: Descriptor[]) => void): void;
|
||||
}
|
||||
|
||||
export class Descriptor {
|
||||
uuid: string;
|
||||
name: string;
|
||||
type: string;
|
||||
|
||||
readValue(callback: (error: string, data: NodeBuffer) => void): void;
|
||||
writeValue(data: NodeBuffer, callback: (error: string) => void): void;
|
||||
toString(): string;
|
||||
|
||||
on(event: string, callback: Function): void;
|
||||
on(event: "valueRead", callback: (error: string, data: NodeBuffer) => void): void;
|
||||
on(event: "valueWrite", callback: (error: string) => void): void;
|
||||
}
|
||||
}
|
||||
|
||||
// vim expandtab shiftwidth=4
|
||||
Reference in New Issue
Block a user