Add new types for pigpio-dht NPM package

This commit is contained in:
erikma
2018-09-19 23:01:33 -07:00
parent 14d0a6329a
commit 45d945ebb5
4 changed files with 82 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
// Type definitions for pigpio-dht 1.1
// Project: https://github.com/depuits/pigpio-dht
// Definitions by: Erik Mavrinac <https://github.com/erikma>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export = dht;
/**
* Returns a new DHT object for accessing a DHT11 or DHT22/AM2302 via GPIO.
* @param gpio an unsigned integer specifying the GPIO number
* @param type A DhtType enumeration value for the sensor type
*/
declare function dht(gpio: number, type: dht.DhtType | number): dht.Dht;
declare namespace dht {
/** The various sensor types supported by pigpio-dht. */
enum DhtType {
DHT11 = 11,
DHT22 = 22,
AM2302 = 22,
}
interface Dht extends NodeJS.EventEmitter {
/**
* Starts reading the sensor value. Emits the 'start' event before starting,
* the 'end' event on end whether or not an error occurred, the 'result'
* event with a DhtResult on success, and the 'badChecksum' event on a
* receive failure.
* @returns false if a read is already underway, true if a new read was started.
*/
read(): boolean;
}
/**
* Result from a successful sensor read.
*/
interface DhtResult {
/** The temperature value in degress Celsius. */
temperature: number;
/** The humidity value in percentage points. */
humidity: number;
}
}
+9
View File
@@ -0,0 +1,9 @@
import * as dht from 'pigpio-dht';
const dhtReadPin = 2;
const sensor: dht.Dht = dht(dhtReadPin, dht.DhtType.DHT11);
sensor.on('start', () => console.log("start"));
sensor.on('end', () => console.log("end"));
sensor.on('result', (result: dht.DhtResult) => console.log(`result: ${result.temperature} degC, ${result.humidity}% relative humidity`));
sensor.on('badChecksum', () => console.log("bad checksum!"));
sensor.read();
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"pigpio-dht-tests.ts"
]
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "dtslint/dt.json",
"rules": { }
}