mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Added types for ds18b20 (#38221)
This commit is contained in:
committed by
Ben Lichtman
parent
8fb3e852c2
commit
a36fbaaafa
@@ -0,0 +1,34 @@
|
||||
// Tests taken from documentation samples.
|
||||
|
||||
import * as ds18b20 from 'ds18b20';
|
||||
|
||||
ds18b20.sensors((err, ids) => {
|
||||
if (err) {
|
||||
console.log('Can not get sensor IDs', err);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Sensor IDs', ids);
|
||||
ids.forEach((id) => {
|
||||
ds18b20.temperature(id, (err, result) => {
|
||||
if (err) {
|
||||
console.log('Can not get temperature from sensor', err);
|
||||
} else {
|
||||
console.log(`Sensor ${id} :`, result);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
ds18b20.sensors((err, ids) => {
|
||||
if (err) {
|
||||
console.log('Can not get sensor IDs', err);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Sensor IDs', ids);
|
||||
ids.forEach((id) => {
|
||||
console.log(`Sensor ${id} (decimal) :`, ds18b20.temperatureSync(id));
|
||||
console.log(`Sensor ${id} (hex) :`, ds18b20.temperatureSync(id, {parser: 'hex'}));
|
||||
});
|
||||
});
|
||||
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
// Type definitions for ds18b20 0.1
|
||||
// Project: https://github.com/chamerling/ds18b20
|
||||
// Definitions by: Peter Müller <https://github.com/crycode-de>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
/**
|
||||
* Options for a `temperature` call
|
||||
*/
|
||||
export interface TemperatureOptions {
|
||||
parser: 'decimal' | 'default' | 'hex';
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for a `sensors` call
|
||||
* @param err An error or null
|
||||
* @param ids An array of sensor IDs
|
||||
*/
|
||||
export type SensorsCallback = (err: Error | null, ids: string[]) => void;
|
||||
|
||||
/**
|
||||
* Callback for a `temperature` call
|
||||
* @param err An error or null
|
||||
* @param value The temperature
|
||||
*/
|
||||
export type TemperatureCallback = (err: Error | null, value: number) => void;
|
||||
|
||||
/**
|
||||
* Get all connected sensor IDs as array
|
||||
* @param callback callback(err, array)
|
||||
*/
|
||||
export function sensors(callback: SensorsCallback): void;
|
||||
|
||||
/**
|
||||
* Get the temperature of a given sensor
|
||||
* @param sensorId The sensor ID
|
||||
* @param callback callback(err, value)
|
||||
*/
|
||||
export function temperature(sensorId: string, callback: TemperatureCallback): void;
|
||||
|
||||
/**
|
||||
* Get the temperature of a given sensor
|
||||
* @param sensorId The sensor ID
|
||||
* @param options The options
|
||||
* @param callback callback(err, value)
|
||||
*/
|
||||
export function temperature(sensorId: string, options: TemperatureOptions, callback: TemperatureCallback): void;
|
||||
|
||||
/**
|
||||
* Get the temperature of a given sensor sync
|
||||
* @param sensorId The sensor ID
|
||||
* @param options The options
|
||||
* @return The temperature
|
||||
*/
|
||||
export function temperatureSync(sensorId: string, options?: TemperatureOptions): number;
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ds18b20-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user