npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ux-xu/konashi-web-bluetooth

v0.3.2

Published

konashi Web Bluetooth SDK

Downloads

13

Readme

konashi 3.0 SDK for Web Bluetooth

konashi 3.0 を Web Bluetooth で操作することができます。

開発言語は以下のものに対応しております。

  • JavaScript(ES2015, async await)
  • typescript

konashi 公式ドキュメント:https://konashi.ux-xu.com/

import { Konashi } from "@ux-xu/konashi-web-bluetooth";

window.addEventListener("click", async () => {
  const k = await Konashi.find();
  await k
    .pinMode(Konashi.PIO0, Konashi.OUTPUT)
    .catch((error) => console.log(error));
  let i = 0;
  setInterval(async () => {
    k.digitalWrite(Konashi.PIO0, i % 2 === 0 ? Konashi.HIGH : Konashi.LOW);
  }, 1000);
});

動作環境

Web Bluetooth API 公式 Github の Implementation Status をご確認ください。

https://github.com/WebBluetoothCG/web-bluetooth/blob/master/implementation-status.md

導入

Windows, Mac, Linux

Chrome をインストール・アップグレードする。

Android

Chrome をインストール・アップグレードする。

iOS

WebBLE(有料)アプリをインストールする。
https://apps.apple.com/jp/app/webble/id1193531073

機能と関数について

現在対応している機能は以下の通りです。

  • Digital I/O
  • Digital Input Notification
  • Analog Input
  • PWM
  • UART

対応していない機能は以下の通りです

  • Analog Output(未実装)
  • SPI(未実装)
  • I2C(未検証)

関数について

typescript の定義を利用して説明します。

定数

Konashi.HIGH で呼びだせる定数です。

static get HIGH(): number;  // Digital HIGH
static get LOW(): number;  // Digital LOW
static get OUTPUT(): number;  // mode: Digital Pin OUTPUT
static get INPUT(): number;  // mode: Digital Pin INPUT
static get PULLUP(): number;  // mode: Digital pullup
static get NO_PULLS(): number;  // mode: Digital no pullup

// ピンの定義
static get PIO0(): number;
static get PIO1(): number;
static get PIO2(): number;
static get PIO3(): number;
static get PIO4(): number;
static get PIO5(): number;
static get PIO6(): number;
static get PIO7(): number;
static get AIO0(): number;
static get AIO1(): number;
static get AIO2(): number;
static get I2C_SDA(): number;
static get I2C_SCL(): number;

// PWM
static get PWM_DISABLE(): number;  // PWM mode: disable
static get PWM_ENABLE(): number;  // PWM mode: enable
static get PWM_ENABLE_LED_MODE(): number;  // PWM mode: LED mode
static get PWM_LED_PERIOD(): number;  // PWM constant: LED mode period

// analog I/O
static get ANALOG_REFERENCE(): number;  // konashi3.0 のアナログ値 1300mV

// I2C
static get I2C_DATA_MAX_LENGTH(): number;
static get I2C_DISABLE(): number;
static get I2C_ENABLE(): number;
static get I2C_ENABLE_100K(): number;
static get I2C_ENABLE_400K(): number;
static get I2C_STOP_CONDITION(): number;
static get I2C_START_CONDITION(): number;
static get I2C_RESTART_CONDITION(): number;

// UART
static get UART_RATE_2K4(): number;
static get UART_RATE_9K6(): number;
static get UART_DATA_MAX_LENGTH(): number;
static get UART_DISABLE(): number;
static get UART_ENABLE(): number;

static get _serviceUUID(): string;
static get defaultFilter(): object;

クラス関数

konashi のインスタンスを作成するために利用する関数群

static _createUUID(part: string): string;
static find(willAutoConnect: boolean, options: Object): Promise<Konashi>;

以下のサンプルは,

①konashiを見つけて自動的に接続する ②cocorokitを見つけて接続する

const konashi = await Konashi.findk();
const konashi = await Konashi.find({
  filters: [{ namePrefix: "cocorokit" }],
  optionalServices: [Konashi._serviceUUID],
});

インスタンス関数

find 関数に willAutoConnect = false を設定した場合,別途接続する必要があります.

connect(): void;
disconnect(): void;

以下,見つけて接続するサンプルです.

const konashi = await Konashi.find(willAutoConnect = false);
await konashi.connect().catch(async error => {
  whatyouwant();
});

接続したkonashiの情報を取得する関数

get _c12cUUIDs(): { [key: string]: string };
get isConnected(): boolean;
get deviceName(): string;

デジタルピンの入出力

// start Digital I/O {
pinMode(pin: number, mode: number): Promise<void>;
pinModeAll(modes: number): Promise<void>;
pinPullUp(pin: number, mode: number): Promise<void>;
digitalWrite(pin: number, value: number): Promise<void>;
digitalWriteAll(values: number): Promise<void>;
digitalRead(pin: number): Promise<number>;
startDigitalInputNotification(callback: (arg0: number) => void): Promise<void>;
stopDigitalInputNotification(): Promise<void>;
// close Digital I/O }
const konashi = await Konashi.find();

async () => {
  await konashi.pinMode(Konashi.PIO0, Konashi.OUTPUT);
  await konashi.digitalWrite(Konashi.PIO0, Konashi.HIGH);
}

async () => {
  await konashi.pinModeAll(0b11111111);
  await konashi.digitalWriteAll(0b11111111);
}

async () => {
  await konashi.pinMode(Konashi.PIO0, Konashi.INPUT)
  const p0_input = await konashi.digitalRead(Konashi.PIO0);
}

const printValue = (value) => {
  console.log("received: " + value);
}

konashi.startDigitalInputNotification(printValue);

// if input pin 1 value changed to HIGH
// received: 0b00000010

konashi.startDigitalInputNotification(printValue);

アナログピンの入力

// start Analog Input {
analogRead(pin: number): Promise<number>;
// close Analog Input }
const konashi = await Konashi.find();
const analog0_value = konashi.analogRead(Konashi.AIO0);

PWM の操作

// start PWM {
pwmMode(pin: number, mode: number): Promise<void>;
pwmPeriod(pin: number, period: number): Promise<void>;
pwmDuty(pin: number, duty: number): Promise<void>;
pwmWrite(pin: number, ratio: number): Promise<void>;
// close PWM }
const konashi = await Konashi.find();
konashi.pwmMode(Konashi.PIO1, Konashi.PWM_ENABLE_LED_MODE);
konashi.pwmWrite(Konashi.PIO1, 100);

その他デバイスの操作

// start Hardware control {
reset(): Promise<void>;
readBatteryLevel(): Promise<number>;
readSignalStrength(): Promise<number>;
// close Hardware control }