2021-10-08 13:30:52 +00:00
|
|
|
|
/** PIGPIO デーモンを Node.js から利用するモジュール ** */
|
|
|
|
|
/** 関数名・書式は Python Interface に準拠 ******************* */
|
|
|
|
|
|
|
|
|
|
#include <napi.h>
|
|
|
|
|
#include <pigpiod_if2.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using namespace Napi;
|
|
|
|
|
|
|
|
|
|
// pigpio 初期化
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _pigpioStart(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 2)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsString() || !info[1].IsString())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::string addrStr = info[0].As<String>().Utf8Value();
|
|
|
|
|
std::string portStr = info[1].As<String>().Utf8Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, pigpio_start(addrStr.c_str(), portStr.c_str())));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pigpio 後始末
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _pigpioStop(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 1)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "IInvalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid aargument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
pigpio_stop(pi);
|
|
|
|
|
deferred.Resolve(env.Null());
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GPIO 端子のモードを設定
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _setMode(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int gpio = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int mode = info[2].As<Number>().Uint32Value();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Resolve(Number::New(env, set_mode(pi, gpio, mode)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GPIOの内部プルアップ/ダウン抵抗の設定/クリア
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _setPullUpDown(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int gpio = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int pud = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, set_pull_up_down(pi, gpio, pud)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GPIOの電圧を読む
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _gpioRead(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 2)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int gpio = info[1].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, gpio_read(pi, gpio)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GPIO の電圧をセットする
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _gpioWrite(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int gpio = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int value = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, gpio_write(pi, gpio, value)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// サーボパルス幅をセットする
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _setServoPulsewidth(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int user_gpio = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int pulsewidth = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, set_servo_pulsewidth(pi, user_gpio, pulsewidth)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PWM周波数を設定する
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _setPwmFrequency(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int user_gpio = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int frequency = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, set_PWM_frequency(pi, user_gpio, frequency)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PWMのデューティ比を指定して出力を開始する
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _setPwmDutycycle(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int user_gpio = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int dutycycle = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, set_PWM_dutycycle(pi, user_gpio, dutycycle)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// シリアルポートを開く
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _serialOpen(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
|
|
|
|
{
|
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
|
|
|
|
}
|
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsString() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
std::string ser_tty = info[1].As<String>().Utf8Value();
|
|
|
|
|
unsigned int baud = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, serial_open(pi, (char *)ser_tty.c_str(), baud, 0)));
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// シリアルポートを閉じる
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _serialClose(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 2)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, serial_close(pi, handle)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// シリアルデバイスからデータを読む
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _serialRead(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int count = info[2].As<Number>().Uint32Value();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
|
2021-11-25 14:23:54 +00:00
|
|
|
|
char buf[count];
|
|
|
|
|
int rxCount = serial_read(pi, handle, buf, count);
|
|
|
|
|
auto outBuf = Buffer<char>::Copy(env, buf, rxCount);
|
|
|
|
|
deferred.Resolve(outBuf);
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// シリアルデバイスにバイト列を書き込む(data: string)
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _serialWrite(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsBuffer())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
auto buf = info[2].As<Buffer<char>>();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
|
2021-11-25 14:23:54 +00:00
|
|
|
|
int count = buf.Length();
|
|
|
|
|
deferred.Resolve(Number::New(env, serial_write(pi, handle, buf.Data(), count)););
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I2Cバスアドレスのデバイスのハンドルを返す
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cOpen(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int i2c_bus = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int i2c_addr = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_open(pi, i2c_bus, i2c_addr, 0)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
// オープン済みI2Cハンドルを閉じる
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cClose(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 2)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_close(pi, handle)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// デバイスに1バイトを送る
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cWriteByte(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int bVal = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_write_byte(pi, handle, bVal)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
// デバイスから1バイトを受け取る
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cReadByte(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 2)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[0].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_read_byte(pi, handle)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタに1バイトを書き込む
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cWriteByteData(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 4)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber() || !info[3].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int i2c_reg = info[2].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int bVal = info[3].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_write_byte_data(pi, handle, i2c_reg, bVal)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタから1バイトを読み込む
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cReadByteData(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int i2c_reg = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_read_byte_data(pi, handle, i2c_reg)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 14:40:18 +00:00
|
|
|
|
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタに最大32バイトのデータを書き込む。
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cWriteI2cBlockData(const CallbackInfo &info)
|
2021-10-11 14:40:18 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 4)
|
2021-10-11 14:40:18 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-11 14:40:18 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber() || !info[3].IsBuffer())
|
2021-10-11 14:40:18 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-11 14:40:18 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int i2c_reg = info[2].As<Number>().Uint32Value();
|
|
|
|
|
auto buf = info[3].As<Buffer<char>>();
|
2021-10-11 14:40:18 +00:00
|
|
|
|
|
2021-11-25 14:23:54 +00:00
|
|
|
|
unsigned int count = buf.Length();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_write_i2c_block_data(pi, handle, i2c_reg, buf.Data(), count)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-11 14:40:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-08 13:30:52 +00:00
|
|
|
|
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタからcountバイトを読み込む。countは1~32。
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cReadI2cBlockData(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 4)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber() || !info[3].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int i2cReg = info[2].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int count = info[3].As<Number>().Uint32Value();
|
|
|
|
|
char buf[count];
|
|
|
|
|
int rxCount = i2c_read_i2c_block_data(pi, handle, i2cReg, buf, count);
|
|
|
|
|
auto outBuf = Buffer<char>::Copy(env, buf, rxCount);
|
|
|
|
|
deferred.Resolve(outBuf);
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタから単一の16ビットワードを読み取る
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cReadWordData(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int i2c_reg = info[2].As<Number>().Uint32Value();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_read_word_data(pi, handle, i2c_reg)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-22 14:33:59 +00:00
|
|
|
|
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタに単一の16ビットワードを書き込む
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cWriteWordData(const CallbackInfo &info)
|
2021-10-22 14:33:59 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 4)
|
2021-10-22 14:33:59 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-22 14:33:59 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber() || !info[3].IsNumber())
|
2021-10-22 14:33:59 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-22 14:33:59 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int i2c_reg = info[2].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int wVal = info[3].As<Number>().Uint32Value();
|
2021-10-22 14:33:59 +00:00
|
|
|
|
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Resolve(Number::New(env, i2c_write_word_data(pi, handle, i2c_reg, wVal)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-22 14:33:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-08 13:30:52 +00:00
|
|
|
|
// i2c デバイスからデータを受け取る
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cReadDevice(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
unsigned int count = info[2].As<Number>().Uint32Value();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
|
2021-11-25 14:23:54 +00:00
|
|
|
|
char buf[count];
|
|
|
|
|
int rxCount = i2c_read_device(pi, handle, buf, count);
|
|
|
|
|
auto outBuf = Buffer<char>::Copy(env, buf, rxCount);
|
|
|
|
|
deferred.Resolve(outBuf);
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// i2c デバイスにバイト列を送る(data: buffer)
|
2021-11-25 14:23:54 +00:00
|
|
|
|
Promise _i2cWriteDevice(const CallbackInfo &info)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
|
|
|
|
Env env = info.Env();
|
2021-11-25 14:23:54 +00:00
|
|
|
|
auto deferred = Napi::Promise::Deferred::New(env);
|
|
|
|
|
if (info.Length() != 3)
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
TypeError::New(env, "Invalid argument count").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsBuffer())
|
2021-10-08 13:30:52 +00:00
|
|
|
|
{
|
2021-11-25 14:23:54 +00:00
|
|
|
|
deferred.Reject(
|
|
|
|
|
Napi::TypeError::New(env, "Invalid argument types").Value());
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
2021-11-25 14:23:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int pi = info[0].As<Number>().Int32Value();
|
|
|
|
|
unsigned int handle = info[1].As<Number>().Uint32Value();
|
|
|
|
|
auto buf = info[2].As<Buffer<char>>();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
|
2021-11-25 14:23:54 +00:00
|
|
|
|
unsigned int count = buf.Length();
|
|
|
|
|
deferred.Resolve(Number::New(env, i2c_write_device(pi, handle, buf.Data(), count)));
|
|
|
|
|
}
|
|
|
|
|
return deferred.Promise();
|
2021-10-08 13:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Object
|
|
|
|
|
Init(Env env, Object exports)
|
|
|
|
|
{
|
|
|
|
|
exports.Set(String::New(env, "_pigpio_start"), Function::New(env, _pigpioStart));
|
|
|
|
|
exports.Set(String::New(env, "_pigpio_stop"), Function::New(env, _pigpioStop));
|
|
|
|
|
exports.Set(String::New(env, "_set_mode"), Function::New(env, _setMode));
|
|
|
|
|
exports.Set(String::New(env, "_set_pull_up_down"), Function::New(env, _setPullUpDown));
|
|
|
|
|
exports.Set(String::New(env, "_gpio_read"), Function::New(env, _gpioRead));
|
|
|
|
|
exports.Set(String::New(env, "_gpio_write"), Function::New(env, _gpioWrite));
|
|
|
|
|
exports.Set(String::New(env, "_set_servo_pulsewidth"), Function::New(env, _setServoPulsewidth));
|
|
|
|
|
exports.Set(String::New(env, "_set_PWM_frequency"), Function::New(env, _setPwmFrequency));
|
|
|
|
|
exports.Set(String::New(env, "_set_PWM_dutycycle"), Function::New(env, _setPwmDutycycle));
|
|
|
|
|
exports.Set(String::New(env, "_serial_open"), Function::New(env, _serialOpen));
|
|
|
|
|
exports.Set(String::New(env, "_serial_close"), Function::New(env, _serialClose));
|
|
|
|
|
exports.Set(String::New(env, "_serial_read"), Function::New(env, _serialRead));
|
|
|
|
|
exports.Set(String::New(env, "_serial_write"), Function::New(env, _serialWrite));
|
|
|
|
|
exports.Set(String::New(env, "_i2c_open"), Function::New(env, _i2cOpen));
|
|
|
|
|
exports.Set(String::New(env, "_i2c_close"), Function::New(env, _i2cClose));
|
|
|
|
|
exports.Set(String::New(env, "_i2c_write_byte"), Function::New(env, _i2cWriteByte));
|
|
|
|
|
exports.Set(String::New(env, "_i2c_read_byte"), Function::New(env, _i2cReadByte));
|
|
|
|
|
exports.Set(String::New(env, "_i2c_write_byte_data"), Function::New(env, _i2cWriteByteData));
|
|
|
|
|
exports.Set(String::New(env, "_i2c_read_byte_data"), Function::New(env, _i2cReadByteData));
|
2021-10-11 14:40:18 +00:00
|
|
|
|
exports.Set(String::New(env, "_i2c_write_i2c_block_data"), Function::New(env, _i2cWriteI2cBlockData));
|
2021-10-08 13:30:52 +00:00
|
|
|
|
exports.Set(String::New(env, "_i2c_read_i2c_block_data"), Function::New(env, _i2cReadI2cBlockData));
|
|
|
|
|
exports.Set(String::New(env, "_i2c_read_word_data"), Function::New(env, _i2cReadWordData));
|
2021-10-22 14:33:59 +00:00
|
|
|
|
exports.Set(String::New(env, "_i2c_write_word_data"), Function::New(env, _i2cWriteWordData));
|
2021-10-08 13:30:52 +00:00
|
|
|
|
exports.Set(String::New(env, "_i2c_write_device"), Function::New(env, _i2cWriteDevice));
|
|
|
|
|
exports.Set(String::New(env, "_i2c_read_device"), Function::New(env, _i2cReadDevice));
|
|
|
|
|
return exports;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NODE_API_MODULE(pigpio, Init)
|