mirror of
https://github.com/ocogeclub/ocoge.git
synced 2024-11-24 08:29:48 +00:00
[update] マルチバイトを含む MicorPython コードの実行とデプロイが Windows 上でも動作するようになった
This commit is contained in:
parent
073bcd5d78
commit
36c3497492
2
index.js
2
index.js
@ -391,7 +391,7 @@ const ugj_runCode = async () => {
|
||||
// Pyboard ocoge
|
||||
const ugj_spawnPyboard = (code, mode) => {
|
||||
let script_path = elutil.path.join(elutil.library_path, 'pybtool.py');
|
||||
let p = require('child_process').spawn('python3', [script_path, mode]);
|
||||
let p = require('child_process').spawn('python3', [script_path, mode], { env: { "PYTHONUTF8": "1" } });
|
||||
p.stdin.write(code);
|
||||
p.stdin.end();
|
||||
p.stderr.on('data', d => { console.error(d.toString()) });
|
||||
|
Binary file not shown.
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
# coding: utf-8
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from tkinter import *
|
||||
from tkinterdnd2 import *
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import pyboard
|
||||
import serial.tools.list_ports
|
||||
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "lgpio",
|
||||
"sources": ["lgpio.cpp"],
|
||||
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
||||
"include_dirs": ["<!@(node -p \"require( 'node-addon-api' ).include\")"],
|
||||
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
||||
"libraries": ["-llgpio"],
|
||||
}
|
||||
]
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
module.exports = require('bindings')('lgpio');
|
||||
|
||||
// module.exports.SET_ACTIVE_LOW = 4;
|
||||
// module.exports.SET_OPEN_DRAIN = 8;
|
||||
// module.exports.SET_OPEN_SOURCE = 16;
|
||||
// module.exports.SET_PULL_UP = 32;
|
||||
// module.exports.SET_PULL_DOWN = 64;
|
||||
// module.exports.SET_PULL_NONE = 128;
|
||||
module.exports.PULL_UP = 32;
|
||||
module.exports.PULL_DOWN = 64;
|
||||
module.exports.PULL_NONE = 128;
|
||||
|
||||
|
||||
let gpio_hand = -1;
|
||||
let ser_hand = -1;
|
||||
let i2c_hand = -1;
|
||||
module.exports.gpio_open = () => {
|
||||
if (gpio_hand < 0) gpio_hand = module.exports._gpiochip_open(0);
|
||||
return gpio_hand;
|
||||
}
|
||||
module.exports.gpio_close = () => {
|
||||
if (gpio_hand >= 0) module.exports._gpiochip_close(gpio_hand);
|
||||
gpio_hand = -1;
|
||||
}
|
||||
module.exports.gpio_set_output = gpio => {
|
||||
if (gpio_hand >= 0) return module.exports._gpio_claim_output(gpio_hand, gpio);
|
||||
}
|
||||
module.exports.gpio_set_input = (gpio, lflag) => {
|
||||
if (gpio_hand >= 0) return module.exports._gpio_claim_input(gpio_hand, gpio, lflag);
|
||||
}
|
||||
module.exports.gpio_read = gpio => {
|
||||
if (gpio_hand >= 0) return module.exports._gpio_read(gpio_hand, gpio);
|
||||
}
|
||||
module.exports.gpio_write = (gpio, value) => {
|
||||
if (gpio_hand >= 0) return module.exports._gpio_write(gpio_hand, gpio, value);
|
||||
}
|
||||
module.exports.servo = (gpio, pulse_width) => {
|
||||
if (gpio_hand >= 0) return module.exports._tx_servo(gpio_hand, gpio, pulse_width);
|
||||
}
|
||||
module.exports.pwm = (gpio, pwm_frequency, pwm_duty_cycle) => {
|
||||
if (gpio_hand >= 0) return module.exports._tx_pwm(gpio_hand, gpio, pwm_frequency, pwm_duty_cycle);
|
||||
}
|
||||
module.exports.serial_open = (tty, baud) => {
|
||||
if (ser_hand >= 0) module.exports._serial_close(ser_hand); // 勝手に閉じる
|
||||
ser_hand = module.exports._serial_open(tty, baud);
|
||||
return ser_hand;
|
||||
}
|
||||
module.exports.serial_close = () => {
|
||||
if (ser_hand >= 0) module.exports._serial_close(ser_hand);
|
||||
ser_hand = -1;
|
||||
}
|
||||
module.exports.serial_write = data => {
|
||||
if (ser_hand >= 0) return module.exports._serial_write(ser_hand, Buffer.from(data));
|
||||
}
|
||||
module.exports.serial_read = count => {
|
||||
if (ser_hand >= 0) return module.exports._serial_read(ser_hand, count).toString('utf8');
|
||||
}
|
||||
module.exports.i2c_open = (i2c_bus, i2c_address) => {
|
||||
if (i2c_hand >= 0) module.exports._i2c_close(i2c_hand); // 勝手に閉じる
|
||||
i2c_hand = module.exports._i2c_open(i2c_bus, i2c_address);
|
||||
return i2c_hand;
|
||||
}
|
||||
module.exports.i2c_close = () => {
|
||||
if (i2c_hand >= 0) module.exports._i2c_close(i2c_hand);
|
||||
i2c_hand = -1;
|
||||
}
|
||||
module.exports.i2c_write_byte_data = (reg, byte_val) => {
|
||||
if (i2c_hand >= 0) return module.exports._i2c_write_byte_data(i2c_hand, reg, byte_val);
|
||||
}
|
||||
module.exports.i2c_read_byte_data = reg => {
|
||||
if (i2c_hand >= 0) return module.exports._i2c_read_byte_data(i2c_hand, reg);
|
||||
}
|
||||
module.exports.i2c_read_device = count => {
|
||||
if (i2c_hand >= 0) return module.exports._i2c_read_device(i2c_hand, count).toString('utf8');
|
||||
}
|
||||
module.exports.i2c_write_device = data => {
|
||||
if (i2c_hand >= 0) return module.exports._i2c_write_device(i2c_hand, Buffer.from(data));
|
||||
}
|
||||
// 終了処理
|
||||
module.exports.close_all_handle = () => {
|
||||
module.exports.gpio_close();
|
||||
module.exports.serial_close();
|
||||
module.exports.i2c_close();
|
||||
}
|
@ -1,555 +0,0 @@
|
||||
/** lgpio を Node.js から利用するモジュール ** */
|
||||
/** 関数名・書式は lgpio Python に準拠 ******************* */
|
||||
|
||||
#include <napi.h>
|
||||
#include <lgpio.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
|
||||
using namespace Napi;
|
||||
|
||||
// gpiochipデバイスを開く
|
||||
Value gpiochipOpen(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 1)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
int gpioDev = info[0].As<Number>().Int32Value();
|
||||
return Number::New(env, lgGpiochipOpen(gpioDev));
|
||||
}
|
||||
|
||||
// gpiochipデバイスを閉じる
|
||||
Value gpiochipClose(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 1)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
return Number::New(env, lgGpiochipClose(handle));
|
||||
}
|
||||
|
||||
// GPIO のモードを出力にする(ことを要求?)
|
||||
Value gpioClaimOutput(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int gpio = info[1].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgGpioClaimOutput(handle, 0, gpio, 0));
|
||||
}
|
||||
|
||||
// GPIO のモードを入力にする(ことを要求?)
|
||||
Value gpioClaimInput(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 3)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int gpio = info[1].As<Number>().Int32Value();
|
||||
int lflag = info[2].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgGpioClaimInput(handle, lflag, gpio));
|
||||
}
|
||||
|
||||
// GPIOの電圧を読む
|
||||
Value gpioRead(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int gpio = info[1].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgGpioRead(handle, gpio));
|
||||
}
|
||||
|
||||
// GPIO の電圧をセットする
|
||||
Value gpioWrite(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 3)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int gpio = info[1].As<Number>().Int32Value();
|
||||
int level = info[2].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgGpioWrite(handle, gpio, level));
|
||||
}
|
||||
|
||||
// サーボパルス幅をセットする
|
||||
Value txServo(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 3)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int gpio = info[1].As<Number>().Int32Value();
|
||||
int pulseWidth = info[2].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgTxServo(handle, gpio, pulseWidth, 50, 0, 0));
|
||||
}
|
||||
|
||||
// PWMを設定して出力
|
||||
Value txPwm(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 4)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber() || !info[3].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int gpio = info[1].As<Number>().Int32Value();
|
||||
float pwmFrequency = info[2].As<Number>().FloatValue();
|
||||
float pwmDutyCycle = info[3].As<Number>().FloatValue();
|
||||
|
||||
return Number::New(env,
|
||||
lgTxPwm(handle, gpio, pwmFrequency, pwmDutyCycle, 0, 0));
|
||||
}
|
||||
|
||||
// シリアルポートを開く
|
||||
Value serialOpen(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsString() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
std::string tty = info[0].As<String>().Utf8Value();
|
||||
|
||||
int baud = info[1].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgSerialOpen(tty.c_str(), baud, 0));
|
||||
}
|
||||
|
||||
// シリアルポートを閉じる
|
||||
Value serialClose(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 1)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgSerialClose(handle));
|
||||
}
|
||||
|
||||
// シリアルデバイスからデータを受け取る
|
||||
Value SerialRead(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int count = info[1].As<Number>().Int32Value();
|
||||
|
||||
char rxBuf[count];
|
||||
int rxCount = lgSerialRead(handle, rxBuf, count);
|
||||
auto outBuf = Buffer<char>::Copy(env, rxBuf, rxCount);
|
||||
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
// シリアルデバイスにバイト列を送る(data: buffer)
|
||||
Value serialWrite(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsBuffer())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
auto txBuf = info[1].As<Buffer<char>>();
|
||||
|
||||
int count = txBuf.Length();
|
||||
|
||||
return Number::New(env,
|
||||
lgSerialWrite(handle, txBuf.Data(), count));
|
||||
}
|
||||
|
||||
// I2Cバスアドレスのデバイスのハンドルを返す
|
||||
Value i2cOpen(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int i2cDev = info[0].As<Number>().Int32Value();
|
||||
int i2cAddr = info[1].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgI2cOpen(i2cDev, i2cAddr, 0));
|
||||
}
|
||||
|
||||
// オープン済みI2Cハンドルを閉じる
|
||||
Value i2cClose(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 1)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgI2cClose(handle));
|
||||
}
|
||||
|
||||
// デバイスに1バイトを送る
|
||||
Value i2cWriteByte(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int byteVal = info[1].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgI2cWriteByte(handle, byteVal));
|
||||
}
|
||||
// デバイスから1バイトを受け取る
|
||||
Value i2cReadByte(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 1)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgI2cReadByte(handle));
|
||||
}
|
||||
|
||||
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタに1バイトを書き込む
|
||||
Value i2cWriteByteData(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 3)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int i2cReg = info[1].As<Number>().Int32Value();
|
||||
int byteVal = info[2].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgI2cWriteByteData(handle, i2cReg, byteVal));
|
||||
}
|
||||
|
||||
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタから1バイトを読み込む
|
||||
Value i2cReadByteData(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int i2cReg = info[1].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgI2cReadByteData(handle, i2cReg));
|
||||
}
|
||||
|
||||
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタからcountバイトを読み込む。countは1~32。
|
||||
Value i2cReadI2cBlockData(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 3)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int i2cReg = info[1].As<Number>().Int32Value();
|
||||
int count = info[2].As<Number>().Int32Value();
|
||||
|
||||
char rxBuf[count];
|
||||
int rxCount = lgI2cReadI2CBlockData(handle, i2cReg, rxBuf, count);
|
||||
auto outBuf = Buffer<char>::Copy(env, rxBuf, rxCount);
|
||||
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタから単一の16ビットワードを読み取る
|
||||
Value I2cReadWordData(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int i2cReg = info[1].As<Number>().Int32Value();
|
||||
|
||||
return Number::New(env,
|
||||
lgI2cReadWordData(handle, i2cReg));
|
||||
}
|
||||
|
||||
// i2c デバイスからデータを受け取る
|
||||
Value I2cReadDevice(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsNumber())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
int count = info[1].As<Number>().Int32Value();
|
||||
|
||||
char rxBuf[count];
|
||||
int rxCount = lgI2cReadDevice(handle, rxBuf, count);
|
||||
auto outBuf = Buffer<char>::Copy(env, rxBuf, rxCount);
|
||||
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
// i2c デバイスにバイト列を送る(data: buffer)
|
||||
Value I2cWriteDevice(const CallbackInfo &info)
|
||||
{
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 2)
|
||||
{
|
||||
TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
if (!info[0].IsNumber() || !info[1].IsBuffer())
|
||||
{
|
||||
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
int handle = info[0].As<Number>().Int32Value();
|
||||
auto txBuf = info[1].As<Buffer<char>>();
|
||||
|
||||
int count = txBuf.Length();
|
||||
|
||||
return Number::New(env,
|
||||
lgI2cWriteDevice(handle, txBuf.Data(), count));
|
||||
}
|
||||
|
||||
Object
|
||||
Init(Env env, Object exports)
|
||||
{
|
||||
exports.Set(String::New(env, "_gpiochip_open"), Function::New(env, gpiochipOpen));
|
||||
exports.Set(String::New(env, "_gpiochip_close"), Function::New(env, gpiochipClose));
|
||||
exports.Set(String::New(env, "_gpio_claim_input"), Function::New(env, gpioClaimInput));
|
||||
exports.Set(String::New(env, "_gpio_claim_output"), Function::New(env, gpioClaimOutput));
|
||||
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, "_tx_servo"), Function::New(env, txServo));
|
||||
exports.Set(String::New(env, "_tx_pwm"), Function::New(env, txPwm));
|
||||
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));
|
||||
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));
|
||||
exports.Set(String::New(env, "_i2c_read_device"), Function::New(env, I2cReadDevice));
|
||||
exports.Set(String::New(env, "_i2c_write_device"), Function::New(env, I2cWriteDevice));
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
NODE_API_MODULE(lgpio, Init)
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "@ocoge.club/lgpio",
|
||||
"version": "0.0.1",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bindings": "^1.5.0",
|
||||
"node-addon-api": "^1.7.1"
|
||||
}
|
||||
}
|
44
package-lock.json
generated
44
package-lock.json
generated
@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "ocoge",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ocoge",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@ocoge.club/pigpio": "file:local_modules/@ocoge.club/pigpio",
|
||||
"@ocoge.club/pigpio": "file:local_modules/pigpio",
|
||||
"@tensorflow-models/blazeface": "^0.0.7",
|
||||
"@tensorflow-models/knn-classifier": "^1.2.4",
|
||||
"@tensorflow-models/mobilenet": "^2.1.0",
|
||||
@ -23,23 +23,19 @@
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^6.0.0-beta.65",
|
||||
"@electron-forge/maker-deb": "^6.0.0-beta.65",
|
||||
"electron": "^19.0.9",
|
||||
"electron": "^19.0.10",
|
||||
"electron-rebuild": "^3.2.8"
|
||||
}
|
||||
},
|
||||
"local_modules/@ocoge.club/pigpio": {
|
||||
"version": "0.0.1",
|
||||
"extraneous": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bindings": "^1.5.0",
|
||||
"node-addon-api": "^1.7.1"
|
||||
}
|
||||
},
|
||||
"local_modules/@ocoge.club/pigpio/node_modules/node-addon-api": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz",
|
||||
"integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg=="
|
||||
},
|
||||
"local_modules/@ocogeclub/amg8833": {
|
||||
"version": "0.0.1",
|
||||
"extraneous": true,
|
||||
@ -73,6 +69,20 @@
|
||||
"node-addon-api": "^1.7.1"
|
||||
}
|
||||
},
|
||||
"local_modules/pigpio": {
|
||||
"name": "@ocoge.club/pigpio",
|
||||
"version": "0.0.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bindings": "^1.5.0",
|
||||
"node-addon-api": "^1.7.1"
|
||||
}
|
||||
},
|
||||
"local_modules/pigpio/node_modules/node-addon-api": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz",
|
||||
"integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg=="
|
||||
},
|
||||
"node_modules/@electron-forge/async-ora": {
|
||||
"version": "6.0.0-beta.65",
|
||||
"resolved": "https://registry.npmjs.org/@electron-forge/async-ora/-/async-ora-6.0.0-beta.65.tgz",
|
||||
@ -815,7 +825,7 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@ocoge.club/pigpio": {
|
||||
"resolved": "local_modules/@ocoge.club/pigpio",
|
||||
"resolved": "local_modules/pigpio",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@sindresorhus/is": {
|
||||
@ -2142,9 +2152,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/electron": {
|
||||
"version": "19.0.9",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-19.0.9.tgz",
|
||||
"integrity": "sha512-ooEwrv8Y7NSzdhKcl6kPCYecnzcg5nFWuS5ryG+VFH3MMBR8zXh9nW2wLsZrBz6OGUxXrcc5BKBC7dA8C6RhGQ==",
|
||||
"version": "19.0.10",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-19.0.10.tgz",
|
||||
"integrity": "sha512-EiWtPWdD7CzkRkp1cw7t0N9W2qhI5XZOudHX7daOh5wI076nsdV2dtlAf/XyTHhPNoKR5qhTWrSnYL9PY6D1vg==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
@ -6795,7 +6805,7 @@
|
||||
}
|
||||
},
|
||||
"@ocoge.club/pigpio": {
|
||||
"version": "file:local_modules/@ocoge.club/pigpio",
|
||||
"version": "file:local_modules/pigpio",
|
||||
"requires": {
|
||||
"bindings": "^1.5.0",
|
||||
"node-addon-api": "^1.7.1"
|
||||
@ -7843,9 +7853,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"electron": {
|
||||
"version": "19.0.9",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-19.0.9.tgz",
|
||||
"integrity": "sha512-ooEwrv8Y7NSzdhKcl6kPCYecnzcg5nFWuS5ryG+VFH3MMBR8zXh9nW2wLsZrBz6OGUxXrcc5BKBC7dA8C6RhGQ==",
|
||||
"version": "19.0.10",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-19.0.10.tgz",
|
||||
"integrity": "sha512-EiWtPWdD7CzkRkp1cw7t0N9W2qhI5XZOudHX7daOh5wI076nsdV2dtlAf/XyTHhPNoKR5qhTWrSnYL9PY6D1vg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@electron/get": "^1.14.1",
|
||||
|
@ -24,11 +24,11 @@
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^6.0.0-beta.65",
|
||||
"@electron-forge/maker-deb": "^6.0.0-beta.65",
|
||||
"electron": "^19.0.9",
|
||||
"electron": "^19.0.10",
|
||||
"electron-rebuild": "^3.2.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ocoge.club/pigpio": "file:local_modules/@ocoge.club/pigpio",
|
||||
"@ocoge.club/pigpio": "file:local_modules/pigpio",
|
||||
"@tensorflow-models/blazeface": "^0.0.7",
|
||||
"@tensorflow-models/knn-classifier": "^1.2.4",
|
||||
"@tensorflow-models/mobilenet": "^2.1.0",
|
||||
|
Loading…
Reference in New Issue
Block a user