mirror of
https://github.com/kou029w/megabit.git
synced 2025-01-30 21:58:04 +00:00
refactor
This commit is contained in:
parent
889b494c3f
commit
a7a5d1111e
14 changed files with 29 additions and 27 deletions
|
@ -1,9 +1,9 @@
|
||||||
import Device from "@chirimen/ads1015";
|
import Device from "@chirimen/ads1015";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
export function ads1015(
|
export function ads1015(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x48,
|
address: number = 0x48,
|
||||||
channel: 0 | 1 | 2 | 3 = 0
|
channel: 0 | 1 | 2 | 3 = 0
|
||||||
): ReadableDevice<number> {
|
): ReadableDevice<number> {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Device from "@chirimen/adt7410";
|
import Device from "@chirimen/adt7410";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
/** @type Temperature (°C) */
|
/** @type Temperature (°C) */
|
||||||
type Temperature = number;
|
type Temperature = number;
|
||||||
|
|
||||||
export function adt7410(
|
export function adt7410(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x48
|
address: number = 0x48
|
||||||
): ReadableDevice<number> {
|
): ReadableDevice<number> {
|
||||||
const device = new Device(bus, address);
|
const device = new Device(bus, address);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Device from "@chirimen/grove-accelerometer";
|
import Device from "@chirimen/grove-accelerometer";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
/** @type Acceleration (g) */
|
/** @type Acceleration (g) */
|
||||||
type Acceleration = [number, number, number];
|
type Acceleration = [number, number, number];
|
||||||
|
|
||||||
export function adxl345(
|
export function adxl345(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x53
|
address: number = 0x53
|
||||||
): ReadableDevice<Acceleration> {
|
): ReadableDevice<Acceleration> {
|
||||||
const device = new Device(bus, address);
|
const device = new Device(bus, address);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Device from "@chirimen/gp2y0e03";
|
import Device from "@chirimen/gp2y0e03";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
/** @type Distance (cm) */
|
/** @type Distance (cm) */
|
||||||
type Distance = number;
|
type Distance = number;
|
||||||
|
|
||||||
export function gp2y0e03(
|
export function gp2y0e03(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x40
|
address: number = 0x40
|
||||||
): ReadableDevice<number> {
|
): ReadableDevice<number> {
|
||||||
const device = new Device(bus, address);
|
const device = new Device(bus, address);
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { I2CPort, I2CSlaveDevice, requestI2CAccess } from "node-web-i2c";
|
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) {
|
export function i2c(bus: number = 1) {
|
||||||
return new I2CPort(bus);
|
return new I2C(bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default i2c;
|
export default i2c;
|
||||||
|
|
|
@ -7,7 +7,7 @@ export {
|
||||||
default as gpio
|
default as gpio
|
||||||
} from "./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 ads1015 } from "./ads1015";
|
||||||
export { default as adt7410 } from "./adt7410";
|
export { default as adt7410 } from "./adt7410";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Device from "@chirimen/grove-touch";
|
import Device from "@chirimen/grove-touch";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
/** @type true if touched by the finger, false otherwise */
|
/** @type true if touched by the finger, false otherwise */
|
||||||
type Touched = [
|
type Touched = [
|
||||||
|
@ -19,7 +19,7 @@ type Touched = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export function mpr121(
|
export function mpr121(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x5a
|
address: number = 0x5a
|
||||||
): ReadableDevice<Touched> {
|
): ReadableDevice<Touched> {
|
||||||
const device = new Device(bus, address);
|
const device = new Device(bus, address);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Device from "@chirimen/grove-gesture";
|
import Device from "@chirimen/grove-gesture";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
type Direction =
|
type Direction =
|
||||||
| ""
|
| ""
|
||||||
|
@ -14,7 +14,7 @@ type Direction =
|
||||||
| "counterclockwise";
|
| "counterclockwise";
|
||||||
|
|
||||||
export function paj7620(
|
export function paj7620(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x73
|
address: number = 0x73
|
||||||
): ReadableDevice<Direction> {
|
): ReadableDevice<Direction> {
|
||||||
const device = new Device(bus, address);
|
const device = new Device(bus, address);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Device from "@chirimen/pca9685";
|
import Device from "@chirimen/pca9685";
|
||||||
import { WritableDevice } from "./Device";
|
import { WritableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
type Channel =
|
type Channel =
|
||||||
| 0
|
| 0
|
||||||
|
@ -26,7 +26,7 @@ type Channel =
|
||||||
* @param angleRange deg
|
* @param angleRange deg
|
||||||
*/
|
*/
|
||||||
export function pca9685(
|
export function pca9685(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x40,
|
address: number = 0x40,
|
||||||
channel: Channel = 0,
|
channel: Channel = 0,
|
||||||
minPulse?: number,
|
minPulse?: number,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Device from "@chirimen/s11059";
|
import Device from "@chirimen/s11059";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
/** @type 8-bit RGB */
|
/** @type 8-bit RGB */
|
||||||
type RGB = [number, number, number];
|
type RGB = [number, number, number];
|
||||||
|
|
||||||
export function s11059(
|
export function s11059(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x2a
|
address: number = 0x2a
|
||||||
): ReadableDevice<RGB> {
|
): ReadableDevice<RGB> {
|
||||||
const device = new Device(bus, address);
|
const device = new Device(bus, address);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import Device from "@chirimen/grove-oled-display";
|
import Device from "@chirimen/grove-oled-display";
|
||||||
import { WritableDevice } from "./Device";
|
import { WritableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
export function ssd1308(
|
export function ssd1308(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x3c
|
address: number = 0x3c
|
||||||
): WritableDevice<boolean | number | string> {
|
): WritableDevice<boolean | number | string> {
|
||||||
const device = new Device(bus, address);
|
const device = new Device(bus, address);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Device from "@chirimen/grove-light";
|
import Device from "@chirimen/grove-light";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
/** @type Illuminance (lx) */
|
/** @type Illuminance (lx) */
|
||||||
type Illuminance = number;
|
type Illuminance = number;
|
||||||
|
|
||||||
export function tsl2561(
|
export function tsl2561(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x29
|
address: number = 0x29
|
||||||
): ReadableDevice<Illuminance> {
|
): ReadableDevice<Illuminance> {
|
||||||
const device = new Device(bus, address);
|
const device = new Device(bus, address);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import Device from "@chirimen/veml6070";
|
import Device from "@chirimen/veml6070";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
/** @type UVA (μW/cm^2) */
|
/** @type UVA (μW/cm^2) */
|
||||||
type UVA = number;
|
type UVA = number;
|
||||||
|
|
||||||
/** slave addresses are 0x38 and 0x39 */
|
/** 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);
|
const device = new Device(bus);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Device from "@chirimen/vl53l0x";
|
import Device from "@chirimen/vl53l0x";
|
||||||
import { ReadableDevice } from "./Device";
|
import { ReadableDevice } from "./Device";
|
||||||
import { I2CPort, i2c } from "./i2c";
|
import { I2C, i2c } from "./i2c";
|
||||||
|
|
||||||
/** @type Enable long range mode (max 2200mm) */
|
/** @type Enable long range mode (max 2200mm) */
|
||||||
type EnableLongRangeMode = Boolean;
|
type EnableLongRangeMode = Boolean;
|
||||||
|
@ -10,7 +10,7 @@ type Distance = number;
|
||||||
|
|
||||||
/** max 1200 mm / 2200 mm (long range mode) */
|
/** max 1200 mm / 2200 mm (long range mode) */
|
||||||
export function vl53l0x(
|
export function vl53l0x(
|
||||||
bus: I2CPort = i2c(),
|
bus: I2C = i2c(),
|
||||||
address: number = 0x29,
|
address: number = 0x29,
|
||||||
enableLongRangeMode?: EnableLongRangeMode
|
enableLongRangeMode?: EnableLongRangeMode
|
||||||
): ReadableDevice<Distance> {
|
): ReadableDevice<Distance> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue