1
0
Fork 0
mirror of https://github.com/kou029w/megabit.git synced 2025-01-30 21:58:04 +00:00
This commit is contained in:
Nebel 2020-02-07 13:58:09 +09:00
parent 889b494c3f
commit a7a5d1111e
14 changed files with 29 additions and 27 deletions

View file

@ -1,9 +1,9 @@
import Device from "@chirimen/ads1015";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
export function ads1015(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x48,
channel: 0 | 1 | 2 | 3 = 0
): ReadableDevice<number> {

View file

@ -1,12 +1,12 @@
import Device from "@chirimen/adt7410";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
/** @type Temperature (°C) */
type Temperature = number;
export function adt7410(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x48
): ReadableDevice<number> {
const device = new Device(bus, address);

View file

@ -1,12 +1,12 @@
import Device from "@chirimen/grove-accelerometer";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
/** @type Acceleration (g) */
type Acceleration = [number, number, number];
export function adxl345(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x53
): ReadableDevice<Acceleration> {
const device = new Device(bus, address);

View file

@ -1,12 +1,12 @@
import Device from "@chirimen/gp2y0e03";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
/** @type Distance (cm) */
type Distance = number;
export function gp2y0e03(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x40
): ReadableDevice<number> {
const device = new Device(bus, address);

View file

@ -1,9 +1,11 @@
import { I2CPort, I2CSlaveDevice, requestI2CAccess } from "node-web-i2c";
export { I2CPort, I2CSlaveDevice, requestI2CAccess };
export { I2CSlaveDevice, requestI2CAccess };
export class I2C extends I2CPort {}
export function i2c(bus: number = 1) {
return new I2CPort(bus);
return new I2C(bus);
}
export default i2c;

View file

@ -7,7 +7,7 @@ export {
default as gpio
} from "./gpio";
export { I2CSlaveDevice, requestI2CAccess, default as i2c } from "./i2c";
export { I2C, I2CSlaveDevice, requestI2CAccess, default as i2c } from "./i2c";
export { default as ads1015 } from "./ads1015";
export { default as adt7410 } from "./adt7410";

View file

@ -1,6 +1,6 @@
import Device from "@chirimen/grove-touch";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
/** @type true if touched by the finger, false otherwise */
type Touched = [
@ -19,7 +19,7 @@ type Touched = [
];
export function mpr121(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x5a
): ReadableDevice<Touched> {
const device = new Device(bus, address);

View file

@ -1,6 +1,6 @@
import Device from "@chirimen/grove-gesture";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
type Direction =
| ""
@ -14,7 +14,7 @@ type Direction =
| "counterclockwise";
export function paj7620(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x73
): ReadableDevice<Direction> {
const device = new Device(bus, address);

View file

@ -1,6 +1,6 @@
import Device from "@chirimen/pca9685";
import { WritableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
type Channel =
| 0
@ -26,7 +26,7 @@ type Channel =
* @param angleRange deg
*/
export function pca9685(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x40,
channel: Channel = 0,
minPulse?: number,

View file

@ -1,12 +1,12 @@
import Device from "@chirimen/s11059";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
/** @type 8-bit RGB */
type RGB = [number, number, number];
export function s11059(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x2a
): ReadableDevice<RGB> {
const device = new Device(bus, address);

View file

@ -1,9 +1,9 @@
import Device from "@chirimen/grove-oled-display";
import { WritableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
export function ssd1308(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x3c
): WritableDevice<boolean | number | string> {
const device = new Device(bus, address);

View file

@ -1,12 +1,12 @@
import Device from "@chirimen/grove-light";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
/** @type Illuminance (lx) */
type Illuminance = number;
export function tsl2561(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x29
): ReadableDevice<Illuminance> {
const device = new Device(bus, address);

View file

@ -1,12 +1,12 @@
import Device from "@chirimen/veml6070";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
/** @type UVA (μW/cm^2) */
type UVA = number;
/** slave addresses are 0x38 and 0x39 */
export function veml6070(bus: I2CPort = i2c()): ReadableDevice<number> {
export function veml6070(bus: I2C = i2c()): ReadableDevice<number> {
const device = new Device(bus);
return {

View file

@ -1,6 +1,6 @@
import Device from "@chirimen/vl53l0x";
import { ReadableDevice } from "./Device";
import { I2CPort, i2c } from "./i2c";
import { I2C, i2c } from "./i2c";
/** @type Enable long range mode (max 2200mm) */
type EnableLongRangeMode = Boolean;
@ -10,7 +10,7 @@ type Distance = number;
/** max 1200 mm / 2200 mm (long range mode) */
export function vl53l0x(
bus: I2CPort = i2c(),
bus: I2C = i2c(),
address: number = 0x29,
enableLongRangeMode?: EnableLongRangeMode
): ReadableDevice<Distance> {