mirror of
https://github.com/ocogeclub/ocoge.git
synced 2024-11-21 23:29:48 +00:00
[update] センサーブロックを別ファイルにして必要なものだけ読み込むようにした
This commit is contained in:
parent
bbf0077d6e
commit
559cf7eafa
58
index.html
58
index.html
@ -488,62 +488,8 @@
|
|||||||
<label text="Extra" web-line="4.0" web-line-width="200"></label>
|
<label text="Extra" web-line="4.0" web-line-width="200"></label>
|
||||||
<label text="_" web-line="4.0" web-line-width="200"></label>
|
<label text="_" web-line="4.0" web-line-width="200"></label>
|
||||||
</category>
|
</category>
|
||||||
<category name="センサー" css-icon="customIcon fas fa-microchip" categorystyle="sensor_category">
|
<category toolboxitemid="category_sensors" name="センサー" css-icon="customIcon fas fa-microchip"
|
||||||
<label text="温湿度気圧センサー BME280" web-line="4.0" web-line-width="200"></label>
|
categorystyle="sensor_category">
|
||||||
<block type="ugj_bme280">
|
|
||||||
<field name="addr">0x76</field>
|
|
||||||
</block>
|
|
||||||
<block type="ugj_bme280_data">
|
|
||||||
<field name="thp">0</field>
|
|
||||||
</block>
|
|
||||||
<label text="ジェスチャーセンサー PAJ7620" web-line="4.0" web-line-width="200"></label>
|
|
||||||
<block type="ugj_gesture_init">
|
|
||||||
<value name="i2c_addr">
|
|
||||||
<shadow type="ugj_hextodec">
|
|
||||||
<value name="hex">
|
|
||||||
<shadow type="text">
|
|
||||||
<field name="TEXT">73</field>
|
|
||||||
</shadow>
|
|
||||||
</value>
|
|
||||||
</shadow>
|
|
||||||
</value>
|
|
||||||
</block>
|
|
||||||
<block type="ugj_gesture_read"></block>
|
|
||||||
<block type="ugj_gesture_stop"></block>
|
|
||||||
<label text="赤外線アレイセンサー(サーマルカメラ)AMG8833" web-line="4.0" web-line-width="200"></label>
|
|
||||||
<block type="ugj_grideye_init">
|
|
||||||
<field name="addr">0x69</field>
|
|
||||||
</block>
|
|
||||||
<block type="ugj_grideye_thermistor"></block>
|
|
||||||
<block type="ugj_grideye_read"></block>
|
|
||||||
<block type="ugj_grideye_stop"></block>
|
|
||||||
<block type="ugj_grideye_canvas_create"></block>
|
|
||||||
<block type="ugj_draw_grideyedata">
|
|
||||||
<field name="color_high">#ff0000</field>
|
|
||||||
<field name="color_low">#3333ff</field>
|
|
||||||
<value name="temp_high">
|
|
||||||
<shadow type="math_number">
|
|
||||||
<field name="NUM">28</field>
|
|
||||||
</shadow>
|
|
||||||
</value>
|
|
||||||
<value name="temp_low">
|
|
||||||
<shadow type="math_number">
|
|
||||||
<field name="NUM">15</field>
|
|
||||||
</shadow>
|
|
||||||
</value>
|
|
||||||
</block>
|
|
||||||
<block type="ugj_teachable_machine"></block>
|
|
||||||
<block type="ugj_grideye_predict_class"></block>
|
|
||||||
<block type="ugj_grideye_add_example">
|
|
||||||
<value name="class_id">
|
|
||||||
<shadow type="math_number">
|
|
||||||
<field name="NUM">0</field>
|
|
||||||
</shadow>
|
|
||||||
</value>
|
|
||||||
</block>
|
|
||||||
<block type="ugj_tensorset_stringify"></block>
|
|
||||||
<block type="ugj_tensorset_parse"></block>
|
|
||||||
<label text="_" web-line="4.0" web-line-width="200"></label>
|
|
||||||
</category>
|
</category>
|
||||||
<category name="マルチメディア" css-icon="customIcon fas fa-gamepad" categorystyle="multimedia_category">
|
<category name="マルチメディア" css-icon="customIcon fas fa-gamepad" categorystyle="multimedia_category">
|
||||||
<label text="キャンバス" web-line="4.0" web-line-width="200"></label>
|
<label text="キャンバス" web-line="4.0" web-line-width="200"></label>
|
||||||
|
59
index.js
59
index.js
@ -93,9 +93,6 @@ Blockly.Msg["UGJ_FOREACH_TITLE"] = "リスト %1 の各 %2 について %3 %4";
|
|||||||
Blockly.Msg["UGJ_FOREACH_ITEM"] = "項目";
|
Blockly.Msg["UGJ_FOREACH_ITEM"] = "項目";
|
||||||
Blockly.Msg["UGJ_FOREACH_TOOLTIP"] = "リストの各項目について、その項目を変数「項目」としてステートメントを実行します。";
|
Blockly.Msg["UGJ_FOREACH_TOOLTIP"] = "リストの各項目について、その項目を変数「項目」としてステートメントを実行します。";
|
||||||
|
|
||||||
Blockly.Msg["UGJ_DRAW_GRIDEYEDATA_TITLE"] = "赤外線アレイセンサ画像表示 %1 温度データ %2 温度範囲上限 %3 %4 温度範囲下限 %5 %6";
|
|
||||||
Blockly.Msg["UGJ_DRAW_GRIDEYEDATA_TOOLTIP"] = "AMG8833の温度データを、画像としてキャンバスに描画します。「着色」をチェックすると、温度範囲で設定されている色をつけて表示します。";
|
|
||||||
|
|
||||||
Blockly.Msg["GPIO_OPEN_TITLE"] = "GPIO を使えるようにする";
|
Blockly.Msg["GPIO_OPEN_TITLE"] = "GPIO を使えるようにする";
|
||||||
Blockly.Msg["GPIO_OPEN_TOOLTIP"] = "GPIOを初期化して接続します。";
|
Blockly.Msg["GPIO_OPEN_TOOLTIP"] = "GPIOを初期化して接続します。";
|
||||||
Blockly.Msg["GPIO_CLOSE_TITLE"] = "GPIO の後片付けをする";
|
Blockly.Msg["GPIO_CLOSE_TITLE"] = "GPIO の後片付けをする";
|
||||||
@ -143,38 +140,6 @@ Blockly.Msg["I2C_READ_DEVICE_TOOLTIP"] = "デバイスから指定したバイ
|
|||||||
Blockly.Msg["I2C_WRITE_DEVICE_TITLE"] = "i2c デバイスに %1 を送信";
|
Blockly.Msg["I2C_WRITE_DEVICE_TITLE"] = "i2c デバイスに %1 を送信";
|
||||||
Blockly.Msg["I2C_WRITE_DEVICE_TOOLTIP"] = "i2c デバイスにデータを送信します。";
|
Blockly.Msg["I2C_WRITE_DEVICE_TOOLTIP"] = "i2c デバイスにデータを送信します。";
|
||||||
|
|
||||||
Blockly.Msg["UGJ_BME280_TITLE"] = "BME280(アドレス %1 )から %2 %3 %4 を取得";
|
|
||||||
Blockly.Msg["UGJ_BME280_TOOLTIP"] = "環境センサーBME280で、気温(摂氏)、湿度(%)、気圧(hPa)を計測し、それぞれを変数に代入します。";
|
|
||||||
Blockly.Msg["UGJ_BME280_READ_TEMP"] = "気温";
|
|
||||||
Blockly.Msg["UGJ_BME280_READ_HUM"] = "湿度";
|
|
||||||
Blockly.Msg["UGJ_BME280_READ_PRES"] = "気圧";
|
|
||||||
Blockly.Msg["UGJ_GESTURE_INIT_TITLE"] = "ジェスチャーセンサー(アドレス: %1 )を初期化";
|
|
||||||
Blockly.Msg["UGJ_GESTURE_INIT_TOOLTIP"] = "PAJ7620 ジェスチャーセンサーを使用する準備をします。";
|
|
||||||
Blockly.Msg["UGJ_GESTURE_READ_TITLE"] = "ジェスチャーの値";
|
|
||||||
Blockly.Msg["UGJ_GESTURE_READ_TOOLTIP"] = "センサーから現在のジェスチャーの値(0〜9)を読み込みます";
|
|
||||||
Blockly.Msg["UGJ_GESTURE_STOP_TITLE"] = "ジェスチャーセンサーから切断";
|
|
||||||
Blockly.Msg["UGJ_GESTURE_STOP_TOOLTIP"] = "センサーとの接続を停止します。";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_INIT_TITLE"] = "赤外線アレイセンサ(アドレス: %1 )を初期化";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_INIT_TOOLTIP"] = "赤外線アレイセンサ AMG8833 の使用準備をします。";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_THERMISTOR_TITLE"] = "赤外線アレイセンサ本体温度";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_THERMISTOR_TOOLTIP"] = "AMG8833に内蔵されたサーミスタ(温度センサ)の値を取得します。";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_READ_TITLE"] = "赤外線アレイセンサの値";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_READ_TOOLTIP"] = "AMG8833から読み取った温度データを、8x8の配列で取得します。";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_STOP_TITLE"] = "赤外線アレイセンサから切断";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_STOP_TOOLTIP"] = "センサーとの接続を停止します。";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_CANVAS_CREATE_TITLE"] = "赤外線アレイセンサデータ表示キャンバスを作成";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_CANVAS_CREATE_TOOLTIP"] = "ディスプレイエリアにAMG8833データ表示用キャンバスを作成します。";
|
|
||||||
Blockly.Msg["UGJ_TEACHABLE_MACHINE_TITLE"] = "TensorFlow.jsによる画像分類器の準備";
|
|
||||||
Blockly.Msg["UGJ_TEACHABLE_MACHINE_TOOLTIP"] = "TensorFlow.jsにMobileNet, KNN Classifierを読み込んで、画像認識(分類)を行う準備をします。";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_PREDICT_CLASS_TITLE"] = "赤外線アレイセンサの画像で推論を行う";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_PREDICT_CLASS_TOOLTIP"] = "キャンバスに表示されたAMG8833の画像を元に画像分類の推論を行います。推論の結果として定義済みのラベルを返します。";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_ADD_EXAMPLE_TITLE"] = "赤外線アレイセンサの画像にラベル %1 をつけてデータセットへ追加";
|
|
||||||
Blockly.Msg["UGJ_GRIDEYE_ADD_EXAMPLE_TOOLTIP"] = "キャンバスに表示されているAMG8833の画像にラベル(クラス名)をつけてデータセットへ追加します。";
|
|
||||||
Blockly.Msg["UGJ_TENSORSET_STRINGIFY_TITLE"] = "学習したクラスデータセットを文字列に変換";
|
|
||||||
Blockly.Msg["UGJ_TENSORSET_STRINGIFY_TOOLTIP"] = "学習したクラスデータセットを文字列に変換して保存します。";
|
|
||||||
Blockly.Msg["UGJ_TENSORSET_PARSE_TITLE"] = "クラスデータ文字列 %1 を画像分類器にセット";
|
|
||||||
Blockly.Msg["UGJ_TENSORSET_PARSE_TOOLTIP"] = "JSONテキストをパースして画像分類器に戻します。";
|
|
||||||
|
|
||||||
Blockly.Msg["UGJ_CODECHAR_TITLE"] = "コード %1 の文字";
|
Blockly.Msg["UGJ_CODECHAR_TITLE"] = "コード %1 の文字";
|
||||||
Blockly.Msg["UGJ_CODECHAR_TOOLTIP"] = "文字コードを文字に変換します。";
|
Blockly.Msg["UGJ_CODECHAR_TOOLTIP"] = "文字コードを文字に変換します。";
|
||||||
Blockly.Msg["UGJ_CHARCODE_TITLE"] = "%1 の文字コード";
|
Blockly.Msg["UGJ_CHARCODE_TITLE"] = "%1 の文字コード";
|
||||||
@ -670,3 +635,27 @@ window.onbeforeunload = () => {
|
|||||||
elutil.cleanupGPIO();
|
elutil.cleanupGPIO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// センサーブロック
|
||||||
|
// ブロックデータ格納ディレクトリのリスト
|
||||||
|
const allDirents = elutil.fs.readdirSync(elutil.blocks_sensors_dir, { withFileTypes: true });
|
||||||
|
const blocks_list = allDirents.filter(dirent => dirent.isDirectory()).map(({ name }) => name);
|
||||||
|
// センサーカテゴリのインスタンス
|
||||||
|
var category_sensors = workspace.getToolbox().getToolboxItemById('category_sensors');
|
||||||
|
var flyout_contents = []; // フライアウトのjsonのリスト
|
||||||
|
for (const sensor_dir of blocks_list) { //ディレクトリ巡り
|
||||||
|
if (sensor_dir.charAt(0) == '.') continue; //隠しディレクトリをスキップ
|
||||||
|
// フライアウトのjsonを取得してパース、リストに追加
|
||||||
|
let fname = elutil.path.join(elutil.blocks_sensors_dir, sensor_dir, 'index.json');
|
||||||
|
let json_text = elutil.fs.readFileSync(fname);
|
||||||
|
let obj = JSON.parse(json_text);
|
||||||
|
flyout_contents = flyout_contents.concat(obj);
|
||||||
|
// ブロック定義のスクリプト要素をbody要素の最後に追加
|
||||||
|
fname = elutil.path.join(elutil.blocks_sensors_dir, sensor_dir, 'index.js');
|
||||||
|
let script = document.createElement('script');
|
||||||
|
script.type = 'text/javascript';
|
||||||
|
script.src = fname;
|
||||||
|
document.body.appendChild(script);
|
||||||
|
}
|
||||||
|
// センサーカテゴリのフライアウトをアップデート
|
||||||
|
category_sensors.updateFlyoutContents(flyout_contents);
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@ const ugj_const = {
|
|||||||
mascot_defname: 'tamachee.png',
|
mascot_defname: 'tamachee.png',
|
||||||
library_dirname: 'lib',
|
library_dirname: 'lib',
|
||||||
document_root: 'Documents',
|
document_root: 'Documents',
|
||||||
executable_path: '.local/lib/ocogeclub',
|
executable_path: '.ocogeclub/apps/',
|
||||||
|
blocks_sensors_dir: '.ocogeclub/sensors/',
|
||||||
localStorage_fname: 'ocoge.json',
|
localStorage_fname: 'ocoge.json',
|
||||||
error_ja_all: 'エラーが発生しました。\n『おこげ倶楽部』までお問い合わせください。',
|
error_ja_all: 'エラーが発生しました。\n『おこげ倶楽部』までお問い合わせください。',
|
||||||
pig: 'pigpio',
|
pig: 'pigpio',
|
||||||
@ -34,6 +35,7 @@ class elUtil {
|
|||||||
this.doc_root = this.path.join(process.env["HOME"], ugj_const.document_root);
|
this.doc_root = this.path.join(process.env["HOME"], ugj_const.document_root);
|
||||||
this.doc_current = this.path.join(process.env["HOME"], ugj_const.document_root);
|
this.doc_current = this.path.join(process.env["HOME"], ugj_const.document_root);
|
||||||
this.executable_path = this.path.join(process.env["HOME"], ugj_const.executable_path);
|
this.executable_path = this.path.join(process.env["HOME"], ugj_const.executable_path);
|
||||||
|
this.blocks_sensors_dir = this.path.join(process.env["HOME"], ugj_const.blocks_sensors_dir);
|
||||||
}
|
}
|
||||||
// static init = async () => {
|
// static init = async () => {
|
||||||
// return new elUtil(await elUtil.get_app_path());
|
// return new elUtil(await elUtil.get_app_path());
|
||||||
@ -214,8 +216,8 @@ class elUtil {
|
|||||||
// GPIO 関連:リロードでGPIOをロックしたままハンドルを失うのを防ぐ
|
// GPIO 関連:リロードでGPIOをロックしたままハンドルを失うのを防ぐ
|
||||||
cleanupGPIO() {
|
cleanupGPIO() {
|
||||||
require('@ocogeclub/' + this.gpio_backend).close_all_handle();
|
require('@ocogeclub/' + this.gpio_backend).close_all_handle();
|
||||||
require('@ocogeclub/paj7620').stop();
|
// require('@ocogeclub/paj7620').stop();
|
||||||
require('@ocogeclub/amg8833').stop();
|
// require('@ocogeclub/amg8833').stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 設定(保存ファイルパスと未保存フラグ)をローカルストレージに保存
|
// 設定(保存ファイルパスと未保存フラグ)をローカルストレージに保存
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const pig = require('@ocogeclub/pigpio');
|
|
||||||
|
|
||||||
let pi = -1;
|
|
||||||
let i2c_hand = -1;
|
|
||||||
exports.init = async (i2c_bus, i2c_addr) => {
|
|
||||||
if (pi < 0) pi = await pig._pigpio_start('', '');
|
|
||||||
if (i2c_hand < 0) await pig._i2c_close(pi, i2c_hand);
|
|
||||||
i2c_hand = await pig._i2c_open(pi, i2c_bus, i2c_addr);
|
|
||||||
await pig._i2c_write_byte_data(pi, i2c_hand, 0x00, 0x00); //Normal mode
|
|
||||||
await pig._i2c_write_byte_data(pi, i2c_hand, 0x02, 0x00); //10FPS
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.read_thermistor = async () => {
|
|
||||||
let temp = await pig._i2c_read_word_data(pi, i2c_hand, 0x0e);
|
|
||||||
return temp * 0.0625;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.read_temp_array = async () => {
|
|
||||||
let linedata = [];
|
|
||||||
for (let i = 0; i < 8; i++) {
|
|
||||||
let data = await pig._i2c_read_i2c_block_data(pi, i2c_hand, 0x80 + 0x10 * i, 16);
|
|
||||||
let oneline = [];
|
|
||||||
for (let j = 0; j < 8; j++) {
|
|
||||||
oneline.push(((data[2 * j + 1] & 0x07) * 256 + data[2 * j]) * 0.25);
|
|
||||||
}
|
|
||||||
linedata.push(oneline);
|
|
||||||
}
|
|
||||||
return linedata;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.stop = async () => {
|
|
||||||
if (i2c_hand >= 0) {
|
|
||||||
await pig._i2c_close(pi, i2c_hand);
|
|
||||||
i2c_hand = -1;
|
|
||||||
}
|
|
||||||
if (pi >= 0) {
|
|
||||||
await pig._pigpio_stop(pi);
|
|
||||||
pi = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This code was ported from https://www.denshi.club/pc/raspi/5raspberry-pi-zeroiot381i2c-amg8833.html
|
|
||||||
*/
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@ocogeclub/amg8833",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"main": "AMG8833.js",
|
|
||||||
"private": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@ocogeclub/pigpio": "file:../pigpio"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,291 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
this.pig = null;
|
|
||||||
this.pi = null;
|
|
||||||
|
|
||||||
this.i2cBusNo = null;
|
|
||||||
this.i2cAddress = null;
|
|
||||||
this.i2cHand = null;
|
|
||||||
|
|
||||||
this.I2C_ADDRESS_B = 0x76;
|
|
||||||
this.I2C_ADDRESS_A = 0x77;
|
|
||||||
this.CHIP_ID = 0x58;
|
|
||||||
|
|
||||||
this.REGISTER_DIG_T1 = 0x88;
|
|
||||||
this.REGISTER_DIG_T2 = 0x8A;
|
|
||||||
this.REGISTER_DIG_T3 = 0x8C;
|
|
||||||
|
|
||||||
this.REGISTER_DIG_P1 = 0x8E;
|
|
||||||
this.REGISTER_DIG_P2 = 0x90;
|
|
||||||
this.REGISTER_DIG_P3 = 0x92;
|
|
||||||
this.REGISTER_DIG_P4 = 0x94;
|
|
||||||
this.REGISTER_DIG_P5 = 0x96;
|
|
||||||
this.REGISTER_DIG_P6 = 0x98;
|
|
||||||
this.REGISTER_DIG_P7 = 0x9A;
|
|
||||||
this.REGISTER_DIG_P8 = 0x9C;
|
|
||||||
this.REGISTER_DIG_P9 = 0x9E;
|
|
||||||
|
|
||||||
this.REGISTER_DIG_H1 = 0xA1;
|
|
||||||
this.REGISTER_DIG_H2 = 0xE1;
|
|
||||||
this.REGISTER_DIG_H3 = 0xE3;
|
|
||||||
this.REGISTER_DIG_H4 = 0xE4;
|
|
||||||
this.REGISTER_DIG_H5 = 0xE5;
|
|
||||||
this.REGISTER_DIG_H6 = 0xE7;
|
|
||||||
|
|
||||||
this.REGISTER_CHIPID = 0xD0;
|
|
||||||
this.REGISTER_RESET = 0xE0;
|
|
||||||
|
|
||||||
this.REGISTER_CONTROL_HUM = 0xF2;
|
|
||||||
this.REGISTER_CONTROL = 0xF4;
|
|
||||||
this.REGISTER_PRESSURE_DATA = 0xF7;
|
|
||||||
this.REGISTER_TEMP_DATA = 0xFA;
|
|
||||||
this.REGISTER_HUMIDITY_DATA = 0xFD;
|
|
||||||
|
|
||||||
exports.init = async (options) => {
|
|
||||||
this.pig = require('@ocogeclub/pigpio')
|
|
||||||
// console.log('pig= ' + this.pig)
|
|
||||||
this.pi = await this.pig._pigpio_start('', '');
|
|
||||||
// console.log('pi= ' + this.pi)
|
|
||||||
// this.pi = require('@ocogeclub/lgpio');
|
|
||||||
|
|
||||||
this.i2cBusNo = (options && options.hasOwnProperty('i2cBusNo')) ? options.i2cBusNo : 1;
|
|
||||||
this.i2cAddress = (options && options.hasOwnProperty('i2cAddress')) ? options.i2cAddress : this.BME280_DEFAULT_I2C_ADDRESS();
|
|
||||||
this.i2cHand = await this.pig._i2c_open(this.pi, this.i2cBusNo, this.i2cAddress);
|
|
||||||
// console.log('i2cHand= ' + this.i2cHand)
|
|
||||||
// this.i2cHand = this.pi._i2c_open(this.i2cBusNo, this.i2cAddress);
|
|
||||||
|
|
||||||
let r;
|
|
||||||
r = await this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CHIPID, 0);
|
|
||||||
// r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CHIPID, 0);
|
|
||||||
if (r < 0) return r;
|
|
||||||
let chipId = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_CHIPID);
|
|
||||||
// let chipId = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_CHIPID);
|
|
||||||
if (chipId !== this.CHIP_ID_BME280() &&
|
|
||||||
chipId !== this.CHIP_ID1_BMP280() &&
|
|
||||||
chipId !== this.CHIP_ID2_BMP280() &&
|
|
||||||
chipId !== this.CHIP_ID3_BMP280()) {
|
|
||||||
return `Unexpected BMx280 chip ID: 0x${chipId.toString(16).toUpperCase()}`;
|
|
||||||
}
|
|
||||||
// console.log(`Found BMx280 chip ID 0x${chipId.toString(16).toUpperCase()} on bus i2c-${this.i2cBusNo}, address 0x${this.i2cAddress.toString(16).toUpperCase()}`);
|
|
||||||
await this.loadCalibration(async (err) => {
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
// Humidity 16x oversampling
|
|
||||||
//
|
|
||||||
let r = await this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CONTROL_HUM, 0b00000101);
|
|
||||||
// let r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CONTROL_HUM, 0b00000101);
|
|
||||||
if (r < 0) return `Humidity 16x oversampling error: ${r}`;
|
|
||||||
// Temperture/pressure 16x oversampling, normal mode
|
|
||||||
//
|
|
||||||
r = await this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_CONTROL, 0b10110111);
|
|
||||||
// r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_CONTROL, 0b10110111);
|
|
||||||
if (r < 0) return `Temperture/pressure 16x oversampling error: ${r}`;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset()
|
|
||||||
//
|
|
||||||
// Perform a power-on reset procedure. You will need to call init() following a reset()
|
|
||||||
//
|
|
||||||
exports.reset = async () => {
|
|
||||||
const POWER_ON_RESET_CMD = 0xB6;
|
|
||||||
let r = await this.pig._i2c_write_byte_data(this.pi, this.i2cHand, this.REGISTER_RESET, POWER_ON_RESET_CMD);
|
|
||||||
// let r = this.pi._i2c_write_byte_data(this.i2cHand, this.REGISTER_RESET, POWER_ON_RESET_CMD);
|
|
||||||
if (r < 0) return `cannot power-on reset: ${r}`;
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cancel()
|
|
||||||
//
|
|
||||||
// Cancels the sensor and releases resources.
|
|
||||||
//
|
|
||||||
exports.cancel = async () => {
|
|
||||||
if (this.i2cHand >= 0) {
|
|
||||||
await this.pig._i2c_close(this.pi, this.i2cHand);
|
|
||||||
// this.pi._i2c_close(this.i2cHand);
|
|
||||||
this.i2cHand = null;
|
|
||||||
await this.pig._pigpio_stop(this.pi);
|
|
||||||
this.pi = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.readSensorData = async () => {
|
|
||||||
if (!this.cal) {
|
|
||||||
return 'You must first call bme280.init()';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grab temperature, humidity, and pressure in a single read
|
|
||||||
//
|
|
||||||
let buffer = await this.pig._i2c_read_i2c_block_data(this.pi, this.i2cHand, this.REGISTER_PRESSURE_DATA, 8);
|
|
||||||
// let buffer = this.pi._i2c_read_i2c_block_data(this.i2cHand, this.REGISTER_PRESSURE_DATA, 8);
|
|
||||||
if (!buffer) return `couldn't grab data`;
|
|
||||||
// Temperature (temperature first since we need t_fine for pressure and humidity)
|
|
||||||
//
|
|
||||||
let adc_T = this.uint20(buffer[3], buffer[4], buffer[5]);
|
|
||||||
let tvar1 = ((((adc_T >> 3) - (this.cal.dig_T1 << 1))) * this.cal.dig_T2) >> 11;
|
|
||||||
let tvar2 = (((((adc_T >> 4) - this.cal.dig_T1) * ((adc_T >> 4) - this.cal.dig_T1)) >> 12) * this.cal.dig_T3) >> 14;
|
|
||||||
let t_fine = tvar1 + tvar2;
|
|
||||||
|
|
||||||
let temperature_C = ((t_fine * 5 + 128) >> 8) / 100;
|
|
||||||
|
|
||||||
// Pressure
|
|
||||||
//
|
|
||||||
let adc_P = this.uint20(buffer[0], buffer[1], buffer[2]);
|
|
||||||
let pvar1 = t_fine / 2 - 64000;
|
|
||||||
let pvar2 = pvar1 * pvar1 * this.cal.dig_P6 / 32768;
|
|
||||||
pvar2 = pvar2 + pvar1 * this.cal.dig_P5 * 2;
|
|
||||||
pvar2 = pvar2 / 4 + this.cal.dig_P4 * 65536;
|
|
||||||
pvar1 = (this.cal.dig_P3 * pvar1 * pvar1 / 524288 + this.cal.dig_P2 * pvar1) / 524288;
|
|
||||||
pvar1 = (1 + pvar1 / 32768) * this.cal.dig_P1;
|
|
||||||
|
|
||||||
let pressure_hPa = 0;
|
|
||||||
|
|
||||||
if (pvar1 !== 0) {
|
|
||||||
let p = 1048576 - adc_P;
|
|
||||||
p = ((p - pvar2 / 4096) * 6250) / pvar1;
|
|
||||||
pvar1 = this.cal.dig_P9 * p * p / 2147483648;
|
|
||||||
pvar2 = p * this.cal.dig_P8 / 32768;
|
|
||||||
p = p + (pvar1 + pvar2 + this.cal.dig_P7) / 16;
|
|
||||||
|
|
||||||
pressure_hPa = p / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Humidity (available on the BME280, will be zero on the BMP280 since it has no humidity sensor)
|
|
||||||
//
|
|
||||||
let adc_H = this.uint16(buffer[6], buffer[7]);
|
|
||||||
|
|
||||||
let h = t_fine - 76800;
|
|
||||||
h = (adc_H - (this.cal.dig_H4 * 64 + this.cal.dig_H5 / 16384 * h)) *
|
|
||||||
(this.cal.dig_H2 / 65536 * (1 + this.cal.dig_H6 / 67108864 * h * (1 + this.cal.dig_H3 / 67108864 * h)));
|
|
||||||
h = h * (1 - this.cal.dig_H1 * h / 524288);
|
|
||||||
|
|
||||||
let humidity = (h > 100) ? 100 : (h < 0 ? 0 : h);
|
|
||||||
|
|
||||||
return {
|
|
||||||
temperature_C: temperature_C,
|
|
||||||
humidity: humidity,
|
|
||||||
pressure_hPa: pressure_hPa
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.loadCalibration = async (callback) => {
|
|
||||||
let buffer = await this.pig._i2c_read_i2c_block_data(this.pi, this.i2cHand, this.REGISTER_DIG_T1, 24);
|
|
||||||
// let buffer = this.pi._i2c_read_i2c_block_data(this.i2cHand, this.REGISTER_DIG_T1, 24);
|
|
||||||
// for (let i = 0; i < 24; i++) console.log(parseInt(buffer[i], 16));
|
|
||||||
if (buffer) {
|
|
||||||
let h1 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H1);
|
|
||||||
let h2 = await this.pig._i2c_read_word_data(this.pi, this.i2cHand, this.REGISTER_DIG_H2);
|
|
||||||
let h3 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H3);
|
|
||||||
let h4 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H4);
|
|
||||||
let h5 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H5);
|
|
||||||
let h5_1 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H5 + 1);
|
|
||||||
let h6 = await this.pig._i2c_read_byte_data(this.pi, this.i2cHand, this.REGISTER_DIG_H6);
|
|
||||||
// let h1 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H1);
|
|
||||||
// let h2 = this.pi._i2c_read_word_data(this.i2cHand, this.REGISTER_DIG_H2);
|
|
||||||
// let h3 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H3);
|
|
||||||
// let h4 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H4);
|
|
||||||
// let h5 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H5);
|
|
||||||
// let h5_1 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H5 + 1);
|
|
||||||
// let h6 = this.pi._i2c_read_byte_data(this.i2cHand, this.REGISTER_DIG_H6);
|
|
||||||
|
|
||||||
this.cal = {
|
|
||||||
dig_T1: this.uint16(buffer[1], buffer[0]),
|
|
||||||
dig_T2: this.int16(buffer[3], buffer[2]),
|
|
||||||
dig_T3: this.int16(buffer[5], buffer[4]),
|
|
||||||
|
|
||||||
dig_P1: this.uint16(buffer[7], buffer[6]),
|
|
||||||
dig_P2: this.int16(buffer[9], buffer[8]),
|
|
||||||
dig_P3: this.int16(buffer[11], buffer[10]),
|
|
||||||
dig_P4: this.int16(buffer[13], buffer[12]),
|
|
||||||
dig_P5: this.int16(buffer[15], buffer[14]),
|
|
||||||
dig_P6: this.int16(buffer[17], buffer[16]),
|
|
||||||
dig_P7: this.int16(buffer[19], buffer[18]),
|
|
||||||
dig_P8: this.int16(buffer[21], buffer[20]),
|
|
||||||
dig_P9: this.int16(buffer[23], buffer[22]),
|
|
||||||
|
|
||||||
dig_H1: h1,
|
|
||||||
dig_H2: h2,
|
|
||||||
dig_H3: h3,
|
|
||||||
dig_H4: (h4 << 4) | (h5 & 0xF),
|
|
||||||
dig_H5: (h5_1 << 4) | (h5 >> 4),
|
|
||||||
dig_H6: h6
|
|
||||||
};
|
|
||||||
|
|
||||||
// console.log('BME280 cal = ' + JSON.stringify(this.cal, null, 2));
|
|
||||||
await callback();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.BME280_DEFAULT_I2C_ADDRESS = () => {
|
|
||||||
return 0x77;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.CHIP_ID1_BMP280 = () => {
|
|
||||||
return 0x56;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.CHIP_ID2_BMP280 = () => {
|
|
||||||
return 0x57;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.CHIP_ID3_BMP280 = () => {
|
|
||||||
return 0x58;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.CHIP_ID_BME280 = () => {
|
|
||||||
return 0x60;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.int16 = (msb, lsb) => {
|
|
||||||
let val = this.uint16(msb, lsb);
|
|
||||||
return val > 32767 ? (val - 65536) : val;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.uint16 = (msb, lsb) => {
|
|
||||||
return msb << 8 | lsb;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.uint20 = (msb, lsb, xlsb) => {
|
|
||||||
return ((msb << 8 | lsb) << 8 | xlsb) >> 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.convertCelciusToFahrenheit = (c) => {
|
|
||||||
return c * 9 / 5 + 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.convertHectopascalToInchesOfMercury = (hPa) => {
|
|
||||||
return hPa * 0.02952998751;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.convertMetersToFeet = (m) => {
|
|
||||||
return m * 3.28084;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.calculateHeatIndexCelcius = (temperature_C, humidity) => {
|
|
||||||
return -8.784695 + 1.61139411 * temperature_C + 2.33854900 * humidity +
|
|
||||||
-0.14611605 * temperature_C * humidity + -0.01230809 * Math.pow(temperature_C, 2) +
|
|
||||||
-0.01642482 * Math.pow(humidity, 2) + 0.00221173 * Math.pow(temperature_C, 2) * humidity +
|
|
||||||
0.00072546 * temperature_C * Math.pow(humidity, 2) +
|
|
||||||
-0.00000358 * Math.pow(temperature_C, 2) * Math.pow(humidity, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.calculateDewPointCelcius = (temperature_C, humidity) => {
|
|
||||||
return 243.04 * (Math.log(humidity / 100.0) + ((17.625 * temperature_C) / (243.04 + temperature_C))) /
|
|
||||||
(17.625 - Math.log(humidity / 100.0) - ((17.625 * temperature_C) / (243.04 + temperature_C)));
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.calculateAltitudeMeters = (pressure_hPa, seaLevelPressure_hPa) => {
|
|
||||||
if (!seaLevelPressure_hPa) {
|
|
||||||
seaLevelPressure_hPa = 1013.25;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (1.0 - Math.pow(pressure_hPa / seaLevelPressure_hPa, (1 / 5.2553))) * 145366.45 * 0.3048;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This code was forked from skylarstein's bme280-sensor: https://github.com/skylarstein/bme280-sensor
|
|
||||||
*/
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@ocogeclub/bme280",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"main": "BME280.js",
|
|
||||||
"private": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@ocogeclub/pigpio": "file:../pigpio"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,474 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
const pig = require('@ocogeclub/pigpio');
|
|
||||||
|
|
||||||
const sleep = sec =>
|
|
||||||
new Promise(r => setTimeout(r, sec * 1000));
|
|
||||||
|
|
||||||
const GES_REACTION_TIME = .100; // default:0.5 // You can adjust the reaction time according to the actual circumstance.
|
|
||||||
const GES_ENTRY_TIME = .050; // default:0.8 // When you want to recognize the Forward/Backward gestures, your gestures' reaction time must less than GES_ENTRY_TIME(0.8s).
|
|
||||||
const GES_QUIT_TIME = 1.000;
|
|
||||||
|
|
||||||
const BANK0 = 0;
|
|
||||||
const BANK1 = 1;
|
|
||||||
|
|
||||||
const PAJ7620_ADDR_BASE = 0x00;
|
|
||||||
|
|
||||||
//REGISTER BANK SELECT
|
|
||||||
const PAJ7620_REGITER_BANK_SEL = (PAJ7620_ADDR_BASE + 0xEF); //W
|
|
||||||
|
|
||||||
//DEVICE ID
|
|
||||||
// const PAJ7620_ID = 0x73;
|
|
||||||
|
|
||||||
//REGISTER BANK 0
|
|
||||||
const PAJ7620_ADDR_SUSPEND_CMD = (PAJ7620_ADDR_BASE + 0x3); //W
|
|
||||||
const PAJ7620_ADDR_GES_PS_DET_MASK_0 = (PAJ7620_ADDR_BASE + 0x41); //RW
|
|
||||||
const PAJ7620_ADDR_GES_PS_DET_MASK_1 = (PAJ7620_ADDR_BASE + 0x42); //RW
|
|
||||||
const PAJ7620_ADDR_GES_PS_DET_FLAG_0 = (PAJ7620_ADDR_BASE + 0x43); //R
|
|
||||||
const PAJ7620_ADDR_GES_PS_DET_FLAG_1 = (PAJ7620_ADDR_BASE + 0x44); //R
|
|
||||||
const PAJ7620_ADDR_STATE_INDICATOR = (PAJ7620_ADDR_BASE + 0x45); //R
|
|
||||||
const PAJ7620_ADDR_PS_HIGH_THRESHOLD = (PAJ7620_ADDR_BASE + 0x69); //RW
|
|
||||||
const PAJ7620_ADDR_PS_LOW_THRESHOLD = (PAJ7620_ADDR_BASE + 0x6A); //RW
|
|
||||||
const PAJ7620_ADDR_PS_APPROACH_STATE = (PAJ7620_ADDR_BASE + 0x6B); //R
|
|
||||||
const PAJ7620_ADDR_PS_RAW_DATA = (PAJ7620_ADDR_BASE + 0x6C); //R
|
|
||||||
|
|
||||||
//REGISTER BANK 1
|
|
||||||
const PAJ7620_ADDR_PS_GAIN = (PAJ7620_ADDR_BASE + 0x44); //RW
|
|
||||||
const PAJ7620_ADDR_IDLE_S1_STEP_0 = (PAJ7620_ADDR_BASE + 0x67); //RW
|
|
||||||
const PAJ7620_ADDR_IDLE_S1_STEP_1 = (PAJ7620_ADDR_BASE + 0x68); //RW
|
|
||||||
const PAJ7620_ADDR_IDLE_S2_STEP_0 = (PAJ7620_ADDR_BASE + 0x69); //RW
|
|
||||||
const PAJ7620_ADDR_IDLE_S2_STEP_1 = (PAJ7620_ADDR_BASE + 0x6A); //RW
|
|
||||||
const PAJ7620_ADDR_OP_TO_S1_STEP_0 = (PAJ7620_ADDR_BASE + 0x6B); //RW
|
|
||||||
const PAJ7620_ADDR_OP_TO_S1_STEP_1 = (PAJ7620_ADDR_BASE + 0x6C); //RW
|
|
||||||
const PAJ7620_ADDR_OP_TO_S2_STEP_0 = (PAJ7620_ADDR_BASE + 0x6D); //RW
|
|
||||||
const PAJ7620_ADDR_OP_TO_S2_STEP_1 = (PAJ7620_ADDR_BASE + 0x6E); //RW
|
|
||||||
const PAJ7620_ADDR_OPERATION_ENABLE = (PAJ7620_ADDR_BASE + 0x72); //RW
|
|
||||||
|
|
||||||
//PAJ7620_REGITER_BANK_SEL
|
|
||||||
const PAJ7620_BANK0 = 0;
|
|
||||||
const PAJ7620_BANK1 = 1;
|
|
||||||
|
|
||||||
//PAJ7620_ADDR_SUSPEND_CMD
|
|
||||||
const PAJ7620_I2C_WAKEUP = 1;
|
|
||||||
const PAJ7620_I2C_SUSPEND = 0;
|
|
||||||
|
|
||||||
//PAJ7620_ADDR_OPERATION_ENABLE
|
|
||||||
const PAJ7620_ENABLE = 1;
|
|
||||||
const PAJ7620_DISABLE = 0;
|
|
||||||
|
|
||||||
//ADC, delete
|
|
||||||
const REG_ADDR_RESULT = 0x00;
|
|
||||||
const REG_ADDR_ALERT = 0x01;
|
|
||||||
const REG_ADDR_CONFIG = 0x02;
|
|
||||||
const REG_ADDR_LIMITL = 0x03;
|
|
||||||
const REG_ADDR_LIMITH = 0x04;
|
|
||||||
const REG_ADDR_HYST = 0x05;
|
|
||||||
const REG_ADDR_CONVL = 0x06;
|
|
||||||
const REG_ADDR_CONVH = 0x07;
|
|
||||||
|
|
||||||
const GES_RIGHT_FLAG = 1 << 0;
|
|
||||||
const GES_LEFT_FLAG = 1 << 1;
|
|
||||||
const GES_UP_FLAG = 1 << 2;
|
|
||||||
const GES_DOWN_FLAG = 1 << 3;
|
|
||||||
const GES_FORWARD_FLAG = 1 << 4;
|
|
||||||
const GES_BACKWARD_FLAG = 1 << 5;
|
|
||||||
const GES_CLOCKWISE_FLAG = 1 << 6;
|
|
||||||
const GES_COUNT_CLOCKWISE_FLAG = 1 << 7;
|
|
||||||
const GES_WAVE_FLAG = 1 << 0;
|
|
||||||
|
|
||||||
//Gesture output
|
|
||||||
exports.FORWARD = 1;
|
|
||||||
exports.BACKWARD = 2;
|
|
||||||
exports.RIGHT = 3;
|
|
||||||
exports.LEFT = 4;
|
|
||||||
exports.UP = 5;
|
|
||||||
exports.DOWN = 6;
|
|
||||||
exports.CLOCKWISE = 7;
|
|
||||||
exports.ANTI_CLOCKWISE = 8;
|
|
||||||
exports.WAVE = 9;
|
|
||||||
|
|
||||||
//Initial register state
|
|
||||||
const initRegisterArray = [
|
|
||||||
[0xEF, 0x00],
|
|
||||||
[0x32, 0x29],
|
|
||||||
[0x33, 0x01],
|
|
||||||
[0x34, 0x00],
|
|
||||||
[0x35, 0x01],
|
|
||||||
[0x36, 0x00],
|
|
||||||
[0x37, 0x07],
|
|
||||||
[0x38, 0x17],
|
|
||||||
[0x39, 0x06],
|
|
||||||
[0x3A, 0x12],
|
|
||||||
[0x3F, 0x00],
|
|
||||||
[0x40, 0x02],
|
|
||||||
[0x41, 0xFF],
|
|
||||||
[0x42, 0x01],
|
|
||||||
[0x46, 0x2D],
|
|
||||||
[0x47, 0x0F],
|
|
||||||
[0x48, 0x3C],
|
|
||||||
[0x49, 0x00],
|
|
||||||
[0x4A, 0x1E],
|
|
||||||
[0x4B, 0x00],
|
|
||||||
[0x4C, 0x20],
|
|
||||||
[0x4D, 0x00],
|
|
||||||
[0x4E, 0x1A],
|
|
||||||
[0x4F, 0x14],
|
|
||||||
[0x50, 0x00],
|
|
||||||
[0x51, 0x10],
|
|
||||||
[0x52, 0x00],
|
|
||||||
[0x5C, 0x02],
|
|
||||||
[0x5D, 0x00],
|
|
||||||
[0x5E, 0x10],
|
|
||||||
[0x5F, 0x3F],
|
|
||||||
[0x60, 0x27],
|
|
||||||
[0x61, 0x28],
|
|
||||||
[0x62, 0x00],
|
|
||||||
[0x63, 0x03],
|
|
||||||
[0x64, 0xF7],
|
|
||||||
[0x65, 0x03],
|
|
||||||
[0x66, 0xD9],
|
|
||||||
[0x67, 0x03],
|
|
||||||
[0x68, 0x01],
|
|
||||||
[0x69, 0xC8],
|
|
||||||
[0x6A, 0x40],
|
|
||||||
[0x6D, 0x04],
|
|
||||||
[0x6E, 0x00],
|
|
||||||
[0x6F, 0x00],
|
|
||||||
[0x70, 0x80],
|
|
||||||
[0x71, 0x00],
|
|
||||||
[0x72, 0x00],
|
|
||||||
[0x73, 0x00],
|
|
||||||
[0x74, 0xF0],
|
|
||||||
[0x75, 0x00],
|
|
||||||
[0x80, 0x42],
|
|
||||||
[0x81, 0x44],
|
|
||||||
[0x82, 0x04],
|
|
||||||
[0x83, 0x20],
|
|
||||||
[0x84, 0x20],
|
|
||||||
[0x85, 0x00],
|
|
||||||
[0x86, 0x10],
|
|
||||||
[0x87, 0x00],
|
|
||||||
[0x88, 0x05],
|
|
||||||
[0x89, 0x18],
|
|
||||||
[0x8A, 0x10],
|
|
||||||
[0x8B, 0x01],
|
|
||||||
[0x8C, 0x37],
|
|
||||||
[0x8D, 0x00],
|
|
||||||
[0x8E, 0xF0],
|
|
||||||
[0x8F, 0x81],
|
|
||||||
[0x90, 0x06],
|
|
||||||
[0x91, 0x06],
|
|
||||||
[0x92, 0x1E],
|
|
||||||
[0x93, 0x0D],
|
|
||||||
[0x94, 0x0A],
|
|
||||||
[0x95, 0x0A],
|
|
||||||
[0x96, 0x0C],
|
|
||||||
[0x97, 0x05],
|
|
||||||
[0x98, 0x0A],
|
|
||||||
[0x99, 0x41],
|
|
||||||
[0x9A, 0x14],
|
|
||||||
[0x9B, 0x0A],
|
|
||||||
[0x9C, 0x3F],
|
|
||||||
[0x9D, 0x33],
|
|
||||||
[0x9E, 0xAE],
|
|
||||||
[0x9F, 0xF9],
|
|
||||||
[0xA0, 0x48],
|
|
||||||
[0xA1, 0x13],
|
|
||||||
[0xA2, 0x10],
|
|
||||||
[0xA3, 0x08],
|
|
||||||
[0xA4, 0x30],
|
|
||||||
[0xA5, 0x19],
|
|
||||||
[0xA6, 0x10],
|
|
||||||
[0xA7, 0x08],
|
|
||||||
[0xA8, 0x24],
|
|
||||||
[0xA9, 0x04],
|
|
||||||
[0xAA, 0x1E],
|
|
||||||
[0xAB, 0x1E],
|
|
||||||
[0xCC, 0x19],
|
|
||||||
[0xCD, 0x0B],
|
|
||||||
[0xCE, 0x13],
|
|
||||||
[0xCF, 0x64],
|
|
||||||
[0xD0, 0x21],
|
|
||||||
[0xD1, 0x0F],
|
|
||||||
[0xD2, 0x88],
|
|
||||||
[0xE0, 0x01],
|
|
||||||
[0xE1, 0x04],
|
|
||||||
[0xE2, 0x41],
|
|
||||||
[0xE3, 0xD6],
|
|
||||||
[0xE4, 0x00],
|
|
||||||
[0xE5, 0x0C],
|
|
||||||
[0xE6, 0x0A],
|
|
||||||
[0xE7, 0x00],
|
|
||||||
[0xE8, 0x00],
|
|
||||||
[0xE9, 0x00],
|
|
||||||
[0xEE, 0x07],
|
|
||||||
[0xEF, 0x01],
|
|
||||||
[0x00, 0x1E],
|
|
||||||
[0x01, 0x1E],
|
|
||||||
[0x02, 0x0F],
|
|
||||||
[0x03, 0x10],
|
|
||||||
[0x04, 0x02],
|
|
||||||
[0x05, 0x00],
|
|
||||||
[0x06, 0xB0],
|
|
||||||
[0x07, 0x04],
|
|
||||||
[0x08, 0x0D],
|
|
||||||
[0x09, 0x0E],
|
|
||||||
[0x0A, 0x9C],
|
|
||||||
[0x0B, 0x04],
|
|
||||||
[0x0C, 0x05],
|
|
||||||
[0x0D, 0x0F],
|
|
||||||
[0x0E, 0x02],
|
|
||||||
[0x0F, 0x12],
|
|
||||||
[0x10, 0x02],
|
|
||||||
[0x11, 0x02],
|
|
||||||
[0x12, 0x00],
|
|
||||||
[0x13, 0x01],
|
|
||||||
[0x14, 0x05],
|
|
||||||
[0x15, 0x07],
|
|
||||||
[0x16, 0x05],
|
|
||||||
[0x17, 0x07],
|
|
||||||
[0x18, 0x01],
|
|
||||||
[0x19, 0x04],
|
|
||||||
[0x1A, 0x05],
|
|
||||||
[0x1B, 0x0C],
|
|
||||||
[0x1C, 0x2A],
|
|
||||||
[0x1D, 0x01],
|
|
||||||
[0x1E, 0x00],
|
|
||||||
[0x21, 0x00],
|
|
||||||
[0x22, 0x00],
|
|
||||||
[0x23, 0x00],
|
|
||||||
[0x25, 0x01],
|
|
||||||
[0x26, 0x00],
|
|
||||||
[0x27, 0x39],
|
|
||||||
[0x28, 0x7F],
|
|
||||||
[0x29, 0x08],
|
|
||||||
[0x30, 0x03],
|
|
||||||
[0x31, 0x00],
|
|
||||||
[0x32, 0x1A],
|
|
||||||
[0x33, 0x1A],
|
|
||||||
[0x34, 0x07],
|
|
||||||
[0x35, 0x07],
|
|
||||||
[0x36, 0x01],
|
|
||||||
[0x37, 0xFF],
|
|
||||||
[0x38, 0x36],
|
|
||||||
[0x39, 0x07],
|
|
||||||
[0x3A, 0x00],
|
|
||||||
[0x3E, 0xFF],
|
|
||||||
[0x3F, 0x00],
|
|
||||||
[0x40, 0x77],
|
|
||||||
[0x41, 0x40],
|
|
||||||
[0x42, 0x00],
|
|
||||||
[0x43, 0x30],
|
|
||||||
[0x44, 0xA0],
|
|
||||||
[0x45, 0x5C],
|
|
||||||
[0x46, 0x00],
|
|
||||||
[0x47, 0x00],
|
|
||||||
[0x48, 0x58],
|
|
||||||
[0x4A, 0x1E],
|
|
||||||
[0x4B, 0x1E],
|
|
||||||
[0x4C, 0x00],
|
|
||||||
[0x4D, 0x00],
|
|
||||||
[0x4E, 0xA0],
|
|
||||||
[0x4F, 0x80],
|
|
||||||
[0x50, 0x00],
|
|
||||||
[0x51, 0x00],
|
|
||||||
[0x52, 0x00],
|
|
||||||
[0x53, 0x00],
|
|
||||||
[0x54, 0x00],
|
|
||||||
[0x57, 0x80],
|
|
||||||
[0x59, 0x10],
|
|
||||||
[0x5A, 0x08],
|
|
||||||
[0x5B, 0x94],
|
|
||||||
[0x5C, 0xE8],
|
|
||||||
[0x5D, 0x08],
|
|
||||||
[0x5E, 0x3D],
|
|
||||||
[0x5F, 0x99],
|
|
||||||
[0x60, 0x45],
|
|
||||||
[0x61, 0x40],
|
|
||||||
[0x63, 0x2D],
|
|
||||||
[0x64, 0x02],
|
|
||||||
[0x65, 0x96],
|
|
||||||
[0x66, 0x00],
|
|
||||||
[0x67, 0x97],
|
|
||||||
[0x68, 0x01],
|
|
||||||
[0x69, 0xCD],
|
|
||||||
[0x6A, 0x01],
|
|
||||||
[0x6B, 0xB0],
|
|
||||||
[0x6C, 0x04],
|
|
||||||
[0x6D, 0x2C],
|
|
||||||
[0x6E, 0x01],
|
|
||||||
[0x6F, 0x32],
|
|
||||||
[0x71, 0x00],
|
|
||||||
[0x72, 0x01],
|
|
||||||
[0x73, 0x35],
|
|
||||||
[0x74, 0x00],
|
|
||||||
[0x75, 0x33],
|
|
||||||
[0x76, 0x31],
|
|
||||||
[0x77, 0x01],
|
|
||||||
[0x7C, 0x84],
|
|
||||||
[0x7D, 0x03],
|
|
||||||
[0x7E, 0x01]
|
|
||||||
];
|
|
||||||
|
|
||||||
//Enable debug message
|
|
||||||
const debug = 0;
|
|
||||||
|
|
||||||
let pi = -1;
|
|
||||||
let i2c_hand = -1;
|
|
||||||
//Initialize the sensors
|
|
||||||
exports.init = async (i2c_bus, i2c_addr) => {
|
|
||||||
if (pi < 0) pi = await pig._pigpio_start('', '');
|
|
||||||
if (i2c_hand < 0) await pig._i2c_close(pi, i2c_hand);
|
|
||||||
i2c_hand = await pig._i2c_open(pi, i2c_bus, i2c_addr);
|
|
||||||
if (debug)
|
|
||||||
console.log("pi" + pi + "i2c_hand" + i2c_hand);
|
|
||||||
|
|
||||||
await sleep(.001);
|
|
||||||
await paj7620SelectBank(BANK0);
|
|
||||||
await paj7620SelectBank(BANK0);
|
|
||||||
|
|
||||||
let data0 = (await paj7620ReadReg(0, 1))[0];
|
|
||||||
let data1 = (await paj7620ReadReg(1, 1))[0];
|
|
||||||
if (debug)
|
|
||||||
console.log("data0:" + data0 + ", data1:" + data1);
|
|
||||||
if (data0 != 0x20) //or data1 <> 0x76
|
|
||||||
console.log("Error with sensor");
|
|
||||||
//return 0xff
|
|
||||||
if (data0 == 0x20)
|
|
||||||
console.log("wake-up finish.");
|
|
||||||
|
|
||||||
for (let i = 0; i < initRegisterArray.length; i += 1)
|
|
||||||
await paj7620WriteReg(initRegisterArray[i][0], initRegisterArray[i][1]);
|
|
||||||
|
|
||||||
await paj7620SelectBank(BANK0);
|
|
||||||
|
|
||||||
console.log("Paj7620 initialize register finished.");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write a byte to a register on the Gesture sensor
|
|
||||||
const paj7620WriteReg = async (addr, cmd) =>
|
|
||||||
await pig._i2c_write_word_data(pi, i2c_hand, addr, cmd);
|
|
||||||
|
|
||||||
//Select a register bank on the Gesture Sensor
|
|
||||||
const paj7620SelectBank = async bank => {
|
|
||||||
if (bank == BANK0)
|
|
||||||
await paj7620WriteReg(PAJ7620_REGITER_BANK_SEL, PAJ7620_BANK0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Read a block of bytes of length "qty" starting at address "addr" from the Gesture sensor
|
|
||||||
const paj7620ReadReg = async (addr, qty) => {
|
|
||||||
return await pig._i2c_read_i2c_block_data(pi, i2c_hand, addr, qty);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return a vlaue from the gestire sensor which can be used in a program
|
|
||||||
// 0:nothing
|
|
||||||
// 1:Forward
|
|
||||||
// 2:Backward
|
|
||||||
// 3:Right
|
|
||||||
// 4:Left
|
|
||||||
// 5:Up
|
|
||||||
// 6:Down
|
|
||||||
// 7:Clockwise
|
|
||||||
// 8:anti-clockwise
|
|
||||||
// 9:wave
|
|
||||||
exports.return_gesture = async () => {
|
|
||||||
|
|
||||||
let data = (await paj7620ReadReg(0x43, 1))[0];
|
|
||||||
if (data == GES_RIGHT_FLAG) {
|
|
||||||
await sleep(GES_ENTRY_TIME);
|
|
||||||
data = (await paj7620ReadReg(0x43, 1))[0];
|
|
||||||
if (data == GES_FORWARD_FLAG) {
|
|
||||||
return 1;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
else if (data == GES_BACKWARD_FLAG) {
|
|
||||||
return 2;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (data == GES_LEFT_FLAG) {
|
|
||||||
await sleep(GES_ENTRY_TIME);
|
|
||||||
data = (await paj7620ReadReg(0x43, 1))[0];
|
|
||||||
if (data == GES_FORWARD_FLAG) {
|
|
||||||
return 1;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
else if (data == GES_BACKWARD_FLAG) {
|
|
||||||
return 2;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (data == GES_UP_FLAG) {
|
|
||||||
await sleep(GES_ENTRY_TIME);
|
|
||||||
data = (await paj7620ReadReg(0x43, 1))[0];
|
|
||||||
if (data == GES_FORWARD_FLAG) {
|
|
||||||
return 1;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
else if (data == GES_BACKWARD_FLAG) {
|
|
||||||
return 2;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (data == GES_DOWN_FLAG) {
|
|
||||||
await sleep(GES_ENTRY_TIME);
|
|
||||||
data = (await paj7620ReadReg(0x43, 1))[0];
|
|
||||||
if (data == GES_FORWARD_FLAG) {
|
|
||||||
return 1;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
else if (data == GES_BACKWARD_FLAG) {
|
|
||||||
return 2;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
else if (data == GES_FORWARD_FLAG) {
|
|
||||||
return 1;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (data == GES_BACKWARD_FLAG) {
|
|
||||||
return 2;
|
|
||||||
// await sleep(GES_QUIT_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (data == GES_CLOCKWISE_FLAG)
|
|
||||||
return 7;
|
|
||||||
|
|
||||||
else if (data == GES_COUNT_CLOCKWISE_FLAG)
|
|
||||||
return 8;
|
|
||||||
|
|
||||||
else {
|
|
||||||
let data1 = (await paj7620ReadReg(0x44, 1))[0];
|
|
||||||
if (data1 == GES_WAVE_FLAG)
|
|
||||||
return 9;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.stop = async () => {
|
|
||||||
if (i2c_hand >= 0) {
|
|
||||||
await pig._i2c_close(pi, i2c_hand);
|
|
||||||
i2c_hand = -1;
|
|
||||||
}
|
|
||||||
if (pi >= 0) {
|
|
||||||
await pig._pigpio_stop(pi);
|
|
||||||
pi = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This code was ported from "Grove - Gesture Sensor v1.0 Python library and examples": https://github.com/DexterInd/GrovePi/tree/master/Software/Python/grove_gesture_sensor
|
|
||||||
*/
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@ocogeclub/paj7620",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"main": "PAJ7620.js",
|
|
||||||
"private": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@ocogeclub/pigpio": "file:../pigpio"
|
|
||||||
}
|
|
||||||
}
|
|
2385
package-lock.json
generated
2385
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -25,15 +25,13 @@
|
|||||||
"@electron-forge/cli": "^6.0.0-beta.63",
|
"@electron-forge/cli": "^6.0.0-beta.63",
|
||||||
"@electron-forge/maker-deb": "^6.0.0-beta.63",
|
"@electron-forge/maker-deb": "^6.0.0-beta.63",
|
||||||
"@electron-forge/maker-rpm": "^6.0.0-beta.63",
|
"@electron-forge/maker-rpm": "^6.0.0-beta.63",
|
||||||
"@electron-forge/maker-squirrel": "^6.0.0-beta.33",
|
"@electron-forge/maker-squirrel": "6.0.0-beta.33",
|
||||||
"@electron-forge/maker-zip": "^6.0.0-beta.63",
|
"@electron-forge/maker-zip": "^6.0.0-beta.63",
|
||||||
"electron": "^17.0.0",
|
"electron": "^17.0.0",
|
||||||
"electron-rebuild": "^3.2.7"
|
"electron-rebuild": "^3.2.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ocogeclub/amg8833": "file:local_modules/@ocogeclub/amg8833",
|
"@ocogeclub/amg8833": "file:local_modules/@ocogeclub/amg8833",
|
||||||
"@ocogeclub/bme280": "file:local_modules/@ocogeclub/bme280",
|
|
||||||
"@ocogeclub/paj7620": "file:local_modules/@ocogeclub/paj7620",
|
|
||||||
"@ocogeclub/pigpio": "file:local_modules/@ocogeclub/pigpio",
|
"@ocogeclub/pigpio": "file:local_modules/@ocogeclub/pigpio",
|
||||||
"@tensorflow-models/blazeface": "^0.0.7",
|
"@tensorflow-models/blazeface": "^0.0.7",
|
||||||
"@tensorflow-models/knn-classifier": "^1.2.2",
|
"@tensorflow-models/knn-classifier": "^1.2.2",
|
||||||
|
276
ugj_blocks.js
276
ugj_blocks.js
@ -1003,284 +1003,8 @@ Blockly.Python['ugj_i2c_write_device'] = function (block) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** センサー */
|
/** センサー */
|
||||||
/********* */
|
|
||||||
/** BME280 */
|
|
||||||
/********* */
|
|
||||||
Blockly.Blocks['ugj_bme280'] = {
|
|
||||||
init: function () {
|
|
||||||
this.appendDummyInput()
|
|
||||||
.appendField("BME280(アドレス")
|
|
||||||
.appendField(new Blockly.FieldDropdown([["0x76", "0x76"], ["0x77", "0x77"]]), "addr")
|
|
||||||
.appendField(")の計測値を取得");
|
|
||||||
this.setInputsInline(true);
|
|
||||||
this.setPreviousStatement(true, null);
|
|
||||||
this.setNextStatement(true, null);
|
|
||||||
this.setStyle('sensor_blocks');
|
|
||||||
this.setTooltip("環境センサーBME280で、気温(摂氏)、湿度(%)、気圧(hPa)を計測します。計測結果は計測値ブロックで参照します。");
|
|
||||||
this.setHelpUrl("");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_bme280'] = function (block) {
|
|
||||||
var dropdown_addr = block.getFieldValue('addr');
|
|
||||||
Blockly.JavaScript.provideFunction_(
|
|
||||||
'require_bme280', [`const _bme280 = require('@ocogeclub/bme280');`]
|
|
||||||
);
|
|
||||||
var code = `const options = {
|
|
||||||
i2cBusNo: ${elutil.i2c_bus},
|
|
||||||
i2cAddress: ${dropdown_addr}
|
|
||||||
};
|
|
||||||
await _bme280.init(options);
|
|
||||||
let _thp = await _bme280.readSensorData();
|
|
||||||
let _bmedata = [];
|
|
||||||
_bmedata[0] = Math.round(_thp.temperature_C * 10) / 10;
|
|
||||||
_bmedata[1] = Math.round(_thp.humidity * 10) / 10;
|
|
||||||
_bmedata[2] = Math.round(_thp.pressure_hPa);
|
|
||||||
await _bme280.cancel();
|
|
||||||
`;
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
Blockly.Blocks['ugj_bme280_data'] = {
|
|
||||||
init: function () {
|
|
||||||
this.appendDummyInput()
|
|
||||||
.appendField(new Blockly.FieldDropdown([["気温", "0"], ["湿度", "1"], ["気圧", "2"]]), "thp");
|
|
||||||
this.setInputsInline(true);
|
|
||||||
this.setOutput(true, null);
|
|
||||||
this.setStyle('sensor_blocks');
|
|
||||||
this.setTooltip("BME280 の計測値を返します。");
|
|
||||||
this.setHelpUrl("");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_bme280_data'] = function (block) {
|
|
||||||
var dropdown_thp = block.getFieldValue('thp');
|
|
||||||
var code = `_bmedata[${dropdown_thp}]`;
|
|
||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
|
||||||
};
|
|
||||||
|
|
||||||
/********** */
|
|
||||||
/** PAJ7620 */
|
|
||||||
/********** */
|
|
||||||
var ugjGestureInitDefinition = {
|
|
||||||
"type": "ugj_gesture_init",
|
|
||||||
"message0": "%{BKY_UGJ_GESTURE_INIT_TITLE}",
|
|
||||||
"args0": [
|
|
||||||
{
|
|
||||||
"type": "input_value",
|
|
||||||
"name": "i2c_addr",
|
|
||||||
"check": "Number"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"inputsInline": true,
|
|
||||||
"previousStatement": null,
|
|
||||||
"nextStatement": null,
|
|
||||||
"tooltip": "%{BKY_UGJ_GESTURE_INIT_TOOLTIP}",
|
|
||||||
"helpUrl": "",
|
|
||||||
"style": "sensor_blocks"
|
|
||||||
};
|
|
||||||
Blockly.Blocks['ugj_gesture_init'] = {
|
|
||||||
init: function () {
|
|
||||||
this.jsonInit(ugjGestureInitDefinition);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_gesture_init'] = function (block) {
|
|
||||||
var value_i2c_addr = Blockly.JavaScript.valueToCode(block, 'i2c_addr', Blockly.JavaScript.ORDER_ATOMIC);
|
|
||||||
Blockly.JavaScript.provideFunction_(
|
|
||||||
'require_paj7620', [`const _paj7620 = require('@ocogeclub/paj7620');`]
|
|
||||||
);
|
|
||||||
var code = `await _paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr});
|
|
||||||
`;
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
Blockly.Python['ugj_gesture_init'] = function (block) {
|
|
||||||
var value_i2c_addr = Blockly.Python.valueToCode(block, 'i2c_addr', Blockly.Python.ORDER_ATOMIC);
|
|
||||||
// TODO: Assemble Python into code variable.
|
|
||||||
var code = '...\n';
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
|
|
||||||
/****************** */
|
|
||||||
/** Gesture Read ** */
|
|
||||||
/****************** */
|
|
||||||
var ugjGestureReadDefinition = {
|
|
||||||
"type": "ugj_gesture_read",
|
|
||||||
"message0": "%{BKY_UGJ_GESTURE_READ_TITLE}",
|
|
||||||
"inputsInline": true,
|
|
||||||
"output": "Number",
|
|
||||||
"tooltip": "%{BKY_UGJ_GESTURE_READ_TOOLTIP}",
|
|
||||||
"helpUrl": "https://ocoge.club/sensors/paj7620.html",
|
|
||||||
"style": "sensor_blocks"
|
|
||||||
};
|
|
||||||
Blockly.Blocks['ugj_gesture_read'] = {
|
|
||||||
init: function () {
|
|
||||||
this.jsonInit(ugjGestureReadDefinition);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_gesture_read'] = function (block) {
|
|
||||||
var code = 'await _paj7620.return_gesture()';
|
|
||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
|
||||||
};
|
|
||||||
Blockly.Python['ugj_gesture_read'] = function (block) {
|
|
||||||
// TODO: Assemble Python into code variable.
|
|
||||||
var code = '...';
|
|
||||||
// TODO: Change ORDER_NONE to the correct strength.
|
|
||||||
return [code, Blockly.Python.ORDER_NONE];
|
|
||||||
};
|
|
||||||
/****************** */
|
|
||||||
/** Gesture Stop ** */
|
|
||||||
/****************** */
|
|
||||||
var ugjGestureStopDefinition = {
|
|
||||||
"type": "ugj_gesture_stop",
|
|
||||||
"message0": "%{BKY_UGJ_GESTURE_STOP_TITLE}",
|
|
||||||
"inputsInline": true,
|
|
||||||
"previousStatement": null,
|
|
||||||
"nextStatement": null,
|
|
||||||
"tooltip": "%{BKY_UGJ_GESTURE_STOP_TOOLTIP}",
|
|
||||||
"helpUrl": "",
|
|
||||||
"style": "sensor_blocks"
|
|
||||||
};
|
|
||||||
Blockly.Blocks['ugj_gesture_stop'] = {
|
|
||||||
init: function () {
|
|
||||||
this.jsonInit(ugjGestureStopDefinition);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_gesture_stop'] = function (block) {
|
|
||||||
var code = 'await _paj7620.stop();\n';
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
Blockly.Python['ugj_gesture_stop'] = function (block) {
|
|
||||||
// TODO: Assemble Python into code variable.
|
|
||||||
var code = '...\n';
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
|
|
||||||
/******************* */
|
|
||||||
/** Init Grid-Eye ** */
|
|
||||||
/******************* */
|
|
||||||
var ugjGridEyeInitDefinition = {
|
|
||||||
"type": "ugj_grideye_init",
|
|
||||||
"message0": "%{BKY_UGJ_GRIDEYE_INIT_TITLE}",
|
|
||||||
"args0": [
|
|
||||||
{
|
|
||||||
"type": "field_dropdown",
|
|
||||||
"name": "addr",
|
|
||||||
"options": [
|
|
||||||
[
|
|
||||||
"0x68",
|
|
||||||
"0x68"
|
|
||||||
],
|
|
||||||
[
|
|
||||||
"0x69",
|
|
||||||
"0x69"
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"inputsInline": true,
|
|
||||||
"previousStatement": null,
|
|
||||||
"nextStatement": null,
|
|
||||||
"tooltip": "%{BKY_UGJ_GRIDEYE_INIT_TOOLTIP}",
|
|
||||||
"helpUrl": "",
|
|
||||||
"style": "sensor_blocks"
|
|
||||||
};
|
|
||||||
Blockly.Blocks['ugj_grideye_init'] = {
|
|
||||||
init: function () {
|
|
||||||
this.jsonInit(ugjGridEyeInitDefinition);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_grideye_init'] = function (block) {
|
|
||||||
var dropdown_addr = block.getFieldValue('addr');
|
|
||||||
Blockly.JavaScript.provideFunction_(
|
|
||||||
'require_amg8833', [`const _amg8833 = require('@ocogeclub/amg8833');`]
|
|
||||||
);
|
|
||||||
var code = `await _amg8833.init(${elutil.i2c_bus}, ${dropdown_addr});\n`;
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
Blockly.Python['ugj_grideye_init'] = function (block) {
|
|
||||||
var dropdown_addr = block.getFieldValue('addr');
|
|
||||||
// TODO: Assemble Python into code variable.
|
|
||||||
var code = '...\n';
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
/********************** */
|
|
||||||
/** Grid-Eye 本体温度 ** */
|
|
||||||
/********************** */
|
|
||||||
var ugjGridEyeThermistorDefinition = {
|
|
||||||
"type": "ugj_grideye_thermistor",
|
|
||||||
"message0": "%{BKY_UGJ_GRIDEYE_THERMISTOR_TITLE}",
|
|
||||||
"output": "Number",
|
|
||||||
"tooltip": "%{BKY_UGJ_GRIDEYE_THERMISTOR_TOOLTIP}",
|
|
||||||
"helpUrl": "",
|
|
||||||
"style": "sensor_blocks"
|
|
||||||
};
|
|
||||||
Blockly.Blocks['ugj_grideye_thermistor'] = {
|
|
||||||
init: function () {
|
|
||||||
this.jsonInit(ugjGridEyeThermistorDefinition);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_grideye_thermistor'] = function (block) {
|
|
||||||
var code = `await _amg8833.read_thermistor()`;
|
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
|
||||||
};
|
|
||||||
Blockly.Python['ugj_grideye_thermistor'] = function (block) {
|
|
||||||
// TODO: Assemble Python into code variable.
|
|
||||||
var code = '...';
|
|
||||||
// TODO: Change ORDER_NONE to the correct strength.
|
|
||||||
return [code, Blockly.Python.ORDER_NONE];
|
|
||||||
};
|
|
||||||
|
|
||||||
/**************************** */
|
|
||||||
/** Read Temperature Array ** */
|
|
||||||
/**************************** */
|
|
||||||
var ugjGridEyeReadDefinition = {
|
|
||||||
"type": "ugj_grideye_read",
|
|
||||||
"message0": "%{BKY_UGJ_GRIDEYE_READ_TITLE}",
|
|
||||||
"inputsInline": true,
|
|
||||||
"output": "Array",
|
|
||||||
"tooltip": "%{BKY_UGJ_GRIDEYE_READ_TOOLTIP}",
|
|
||||||
"helpUrl": "",
|
|
||||||
"style": "sensor_blocks"
|
|
||||||
};
|
|
||||||
Blockly.Blocks['ugj_grideye_read'] = {
|
|
||||||
init: function () {
|
|
||||||
this.jsonInit(ugjGridEyeReadDefinition);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_grideye_read'] = function (block) {
|
|
||||||
var code = 'await _amg8833.read_temp_array()';
|
|
||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
|
||||||
};
|
|
||||||
Blockly.Python['ugj_grideye_read'] = function (block) {
|
|
||||||
// TODO: Assemble Python into code variable.
|
|
||||||
var code = '...';
|
|
||||||
// TODO: Change ORDER_NONE to the correct strength.
|
|
||||||
return [code, Blockly.Python.ORDER_NONE];
|
|
||||||
};
|
|
||||||
/******************* */
|
|
||||||
/** Stop Grid-Eye ** */
|
|
||||||
/******************* */
|
|
||||||
var ugjGridEyeStopDefinition = {
|
|
||||||
"type": "ugj_grideye_stop",
|
|
||||||
"message0": "%{BKY_UGJ_GRIDEYE_STOP_TITLE}",
|
|
||||||
"inputsInline": true,
|
|
||||||
"previousStatement": null,
|
|
||||||
"nextStatement": null,
|
|
||||||
"tooltip": "%{BKY_UGJ_GRIDEYE_STOP_TOOLTIP}",
|
|
||||||
"helpUrl": "",
|
|
||||||
"style": "sensor_blocks"
|
|
||||||
};
|
|
||||||
Blockly.Blocks['ugj_grideye_stop'] = {
|
|
||||||
init: function () {
|
|
||||||
this.jsonInit(ugjGridEyeStopDefinition);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Blockly.JavaScript['ugj_grideye_stop'] = function (block) {
|
|
||||||
var code = 'await _amg8833.stop();\n';
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
Blockly.Python['ugj_grideye_stop'] = function (block) {
|
|
||||||
// TODO: Assemble Python into code variable.
|
|
||||||
var code = '...\n';
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Multimedia *****************************************************************************************************/
|
/** Multimedia *****************************************************************************************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user