Merge pull request #2080 from swook/master

Add definitions for github.com/sandeepmistry/noble
This commit is contained in:
Bart van der Schoor
2014-04-28 17:51:39 +02:00
3 changed files with 190 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
# Contributors
This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url.
This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url.
All definitions files include a header with the author and editors, so at some point this list will be auto-generated.
@@ -207,6 +207,7 @@ All definitions files include a header with the author and editors, so at some p
* [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))
* [nconf](https://github.com/flatiron/nconf) (by [Jeff Goddard](https://github.com/jedigo))
* [noble](https://github.com/sandeepmistry/noble) (by [Seon-Wook Park](https://github.com/swook))
* [nock](https://github.com/pgte/nock) (by [bonnici](https://github.com/bonnici))
* [Node.js](http://nodejs.org/) (from TypeScript samples)
* [node_redis](https://github.com/mranney/node_redis) (by [Boris Yankov](https://github.com/borisyankov))

82
noble/noble-tests.ts Normal file
View File

@@ -0,0 +1,82 @@
/// <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 => {});

106
noble/noble.d.ts vendored Normal file
View File

@@ -0,0 +1,106 @@
// 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" {
import events = require("events");
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, listener: Function): events.EventEmitter;
export function on(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
export function on(event: "scanStart", listener: () => void): events.EventEmitter;
export function on(event: "scanStop", listener: () => void): events.EventEmitter;
export function on(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
export class Peripheral extends events.EventEmitter {
uuid: string;
advertisement: Advertisement;
rssi: number;
services: string[];
connect(callback: (error: string) => void): void;
disconnect(callback: () => void): void;
discoverServices(serviceUUIDs: string[], listener: (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, listener: Function): events.EventEmitter;
on(event: "connect", listener: (error: string) => void): events.EventEmitter;
on(event: "disconnect", listener: (error: string) => void): events.EventEmitter;
on(event: "rssiUpdate", listener: (rssi: number) => void): events.EventEmitter;
on(event: "servicesDiscover", listener: (services: Service[]) => void): events.EventEmitter;
}
export interface Advertisement {
localName: string;
serviceData: NodeBuffer;
txPowerLevel: number;
manufacturerData: NodeBuffer;
serviceUuids: string[];
}
export class Service extends events.EventEmitter {
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, listener: Function): events.EventEmitter;
on(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): events.EventEmitter;
on(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): events.EventEmitter;
}
export class Characteristic extends events.EventEmitter {
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, listener: Function): events.EventEmitter;
on(event: string, option: boolean, listener: Function): events.EventEmitter;
on(event: "read", listener: (data: NodeBuffer, isNotification: boolean) => void): events.EventEmitter;
on(event: "write", withoutResponse: boolean, listener: (error: string) => void): events.EventEmitter;
on(event: "broadcast", listener: (state: string) => void): events.EventEmitter;
on(event: "notify", listener: (state: string) => void): events.EventEmitter;
on(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): events.EventEmitter;
}
export class Descriptor extends events.EventEmitter {
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, listener: Function): events.EventEmitter;
on(event: "valueRead", listener: (error: string, data: NodeBuffer) => void): events.EventEmitter;
on(event: "valueWrite", listener: (error: string) => void): events.EventEmitter;
}
}