[fix] lgpioモジュールの変なコードを修正、自作 BME280.js を利用したブロックを追加、その他細かな修正

This commit is contained in:
ocogeclub 2021-09-18 23:29:06 +09:00
parent ba1fadf4c2
commit a16f58b2a9
92 changed files with 1339 additions and 1073 deletions

4
.gitignore vendored
View File

@ -4,4 +4,6 @@ bin/
build/
*.zip
push.sh
n
n
*.bak
*.old

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"python.formatting.provider": "black"
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -13,7 +13,7 @@
'use strict';Blockly.Blocks.colour={};Blockly.Constants={};Blockly.Constants.Colour={};Blockly.Constants.Colour.HUE=20;
Blockly.defineBlocksWithJsonArray([{type:"colour_picker",message0:"%1",args0:[{type:"field_colour",name:"COLOUR",colour:"#ff0000"}],output:"Colour",helpUrl:"%{BKY_COLOUR_PICKER_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_PICKER_TOOLTIP}",extensions:["parent_tooltip_when_inline"]},{type:"colour_random",message0:"%{BKY_COLOUR_RANDOM_TITLE}",output:"Colour",helpUrl:"%{BKY_COLOUR_RANDOM_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_RANDOM_TOOLTIP}"},{type:"colour_rgb",message0:"%{BKY_COLOUR_RGB_TITLE} %{BKY_COLOUR_RGB_RED} %1 %{BKY_COLOUR_RGB_GREEN} %2 %{BKY_COLOUR_RGB_BLUE} %3",
args0:[{type:"input_value",name:"RED",check:"Number",align:"RIGHT"},{type:"input_value",name:"GREEN",check:"Number",align:"RIGHT"},{type:"input_value",name:"BLUE",check:"Number",align:"RIGHT"}],output:"Colour",helpUrl:"%{BKY_COLOUR_RGB_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_RGB_TOOLTIP}"},{type:"colour_blend",message0:"%{BKY_COLOUR_BLEND_TITLE} %{BKY_COLOUR_BLEND_COLOUR1} %1 %{BKY_COLOUR_BLEND_COLOUR2} %2 %{BKY_COLOUR_BLEND_RATIO} %3",args0:[{type:"input_value",name:"COLOUR1",check:"Colour",
align:"RIGHT"},{type:"input_value",name:"COLOUR2",check:"Colour",align:"RIGHT"},{type:"input_value",name:"RATIO",check:"Number",align:"RIGHT"}],output:"Colour",helpUrl:"%{BKY_COLOUR_BLEND_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_BLEND_TOOLTIP}"}]);Blockly.Blocks.lists={};Blockly.Constants.Lists={};Blockly.Constants.Lists.HUE=260;
align:"RIGHT"},{type:"input_value",name:"COLOUR2",check:"Colour",align:"RIGHT"},{type:"input_value",name:"RATIO",check:"Number",align:"RIGHT"}],output:"Colour",helpUrl:"%{BKY_COLOUR_BLEND_HELPURL}",style:"colour_blocks",tooltip:"%{BKY_COLOUR_BLEND_TOOLTIP}"}]);Blockly.Constants.Lists={};Blockly.Constants.Lists.HUE=260;
Blockly.defineBlocksWithJsonArray([{type:"lists_create_empty",message0:"%{BKY_LISTS_CREATE_EMPTY_TITLE}",output:"Array",style:"list_blocks",tooltip:"%{BKY_LISTS_CREATE_EMPTY_TOOLTIP}",helpUrl:"%{BKY_LISTS_CREATE_EMPTY_HELPURL}"},{type:"lists_repeat",message0:"%{BKY_LISTS_REPEAT_TITLE}",args0:[{type:"input_value",name:"ITEM"},{type:"input_value",name:"NUM",check:"Number"}],output:"Array",style:"list_blocks",tooltip:"%{BKY_LISTS_REPEAT_TOOLTIP}",helpUrl:"%{BKY_LISTS_REPEAT_HELPURL}"},{type:"lists_reverse",
message0:"%{BKY_LISTS_REVERSE_MESSAGE0}",args0:[{type:"input_value",name:"LIST",check:"Array"}],output:"Array",inputsInline:!0,style:"list_blocks",tooltip:"%{BKY_LISTS_REVERSE_TOOLTIP}",helpUrl:"%{BKY_LISTS_REVERSE_HELPURL}"},{type:"lists_isEmpty",message0:"%{BKY_LISTS_ISEMPTY_TITLE}",args0:[{type:"input_value",name:"VALUE",check:["String","Array"]}],output:"Boolean",style:"list_blocks",tooltip:"%{BKY_LISTS_ISEMPTY_TOOLTIP}",helpUrl:"%{BKY_LISTS_ISEMPTY_HELPURL}"},{type:"lists_length",message0:"%{BKY_LISTS_LENGTH_TITLE}",
args0:[{type:"input_value",name:"VALUE",check:["String","Array"]}],output:"Number",style:"list_blocks",tooltip:"%{BKY_LISTS_LENGTH_TOOLTIP}",helpUrl:"%{BKY_LISTS_LENGTH_HELPURL}"}]);

File diff suppressed because one or more lines are too long

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -0,0 +1,46 @@
/**
* @license
* Copyright 2018 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Gulp script to build Blockly for Node & NPM.
* Run this script by calling "npm install" in this directory.
*/
var gulp = require('gulp');
var typings = require('./scripts/gulpfiles/typings');
var buildTasks = require('./scripts/gulpfiles/build_tasks');
var packageTasks = require('./scripts/gulpfiles/package_tasks');
var gitTasks = require('./scripts/gulpfiles/git_tasks');
var licenseTasks = require('./scripts/gulpfiles/license_tasks');
var appengineTasks = require('./scripts/gulpfiles/appengine_tasks');
var releaseTasks = require('./scripts/gulpfiles/release_tasks');
var cleanupTasks = require('./scripts/gulpfiles/cleanup_tasks');
module.exports = {
deployDemos: appengineTasks.deployDemos,
default: buildTasks.build,
build: buildTasks.build,
buildCore: buildTasks.core,
buildBlocks: buildTasks.blocks,
buildLangfiles: buildTasks.langfiles,
buildUncompressed: buildTasks.uncompressed,
buildCompressed: buildTasks.compressed,
buildGenerators: buildTasks.generators,
buildAdvancedCompilationTest: buildTasks.advancedCompilationTest,
gitSyncDevelop: gitTasks.syncDevelop,
gitSyncMaster: gitTasks.syncMaster,
gitCreateRC: gitTasks.createRC,
gitUpdateGithubPages: gitTasks.updateGithubPages,
typings: gulp.series(typings.typings, typings.msgTypings),
package: packageTasks.package,
checkLicenses: licenseTasks.checkLicenses,
recompile: releaseTasks.recompile,
prepareDemos: appengineTasks.prepareDemos,
publish: releaseTasks.publish,
publishBeta: releaseTasks.publishBeta,
sortRequires: cleanupTasks.sortRequires,
};

View File

@ -16,14 +16,13 @@ Blockly.JavaScript.ORDER_AWAIT=4.8;Blockly.JavaScript.ORDER_EXPONENTIATION=5;Blo
Blockly.JavaScript.ORDER_BITWISE_XOR=11;Blockly.JavaScript.ORDER_BITWISE_OR=12;Blockly.JavaScript.ORDER_LOGICAL_AND=13;Blockly.JavaScript.ORDER_LOGICAL_OR=14;Blockly.JavaScript.ORDER_CONDITIONAL=15;Blockly.JavaScript.ORDER_ASSIGNMENT=16;Blockly.JavaScript.ORDER_YIELD=17;Blockly.JavaScript.ORDER_COMMA=18;Blockly.JavaScript.ORDER_NONE=99;
Blockly.JavaScript.ORDER_OVERRIDES=[[Blockly.JavaScript.ORDER_FUNCTION_CALL,Blockly.JavaScript.ORDER_MEMBER],[Blockly.JavaScript.ORDER_FUNCTION_CALL,Blockly.JavaScript.ORDER_FUNCTION_CALL],[Blockly.JavaScript.ORDER_MEMBER,Blockly.JavaScript.ORDER_MEMBER],[Blockly.JavaScript.ORDER_MEMBER,Blockly.JavaScript.ORDER_FUNCTION_CALL],[Blockly.JavaScript.ORDER_LOGICAL_NOT,Blockly.JavaScript.ORDER_LOGICAL_NOT],[Blockly.JavaScript.ORDER_MULTIPLICATION,Blockly.JavaScript.ORDER_MULTIPLICATION],[Blockly.JavaScript.ORDER_ADDITION,
Blockly.JavaScript.ORDER_ADDITION],[Blockly.JavaScript.ORDER_LOGICAL_AND,Blockly.JavaScript.ORDER_LOGICAL_AND],[Blockly.JavaScript.ORDER_LOGICAL_OR,Blockly.JavaScript.ORDER_LOGICAL_OR]];Blockly.JavaScript.isInitialized=!1;
Blockly.JavaScript.init=function(a){Blockly.JavaScript.definitions_=Object.create(null);Blockly.JavaScript.functionNames_=Object.create(null);Blockly.JavaScript.variableDB_?Blockly.JavaScript.variableDB_.reset():Blockly.JavaScript.variableDB_=new Blockly.Names(Blockly.JavaScript.RESERVED_WORDS_);Blockly.JavaScript.variableDB_.setVariableMap(a.getVariableMap());for(var b=[],c=Blockly.Variables.allDeveloperVariables(a),d=0;d<c.length;d++)b.push(Blockly.JavaScript.variableDB_.getName(c[d],Blockly.Names.DEVELOPER_VARIABLE_TYPE));
a=Blockly.Variables.allUsedVarModels(a);for(d=0;d<a.length;d++)b.push(Blockly.JavaScript.variableDB_.getName(a[d].getId(),Blockly.VARIABLE_CATEGORY_NAME));b.length&&(Blockly.JavaScript.definitions_.variables="var "+b.join(", ")+";");this.isInitialized=!0};
Blockly.JavaScript.finish=function(a){var b=[],c;for(c in Blockly.JavaScript.definitions_)b.push(Blockly.JavaScript.definitions_[c]);delete Blockly.JavaScript.definitions_;delete Blockly.JavaScript.functionNames_;Blockly.JavaScript.variableDB_.reset();return b.join("\n\n")+"\n\n\n"+a};Blockly.JavaScript.scrubNakedValue=function(a){return a+";\n"};Blockly.JavaScript.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/'/g,"\\'");return"'"+a+"'"};
Blockly.JavaScript.multiline_quote_=function(a){return a.split(/\n/g).map(Blockly.JavaScript.quote_).join(" + '\\n' +\n")};
Blockly.JavaScript.scrub_=function(a,b,c){var d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();e&&(e=Blockly.utils.string.wrap(e,Blockly.JavaScript.COMMENT_WRAP-3),d+=Blockly.JavaScript.prefixLines(e+"\n","// "));for(var f=0;f<a.inputList.length;f++)a.inputList[f].type==Blockly.inputTypes.VALUE&&(e=a.inputList[f].connection.targetBlock())&&(e=Blockly.JavaScript.allNestedComments(e))&&(d+=Blockly.JavaScript.prefixLines(e,"// "))}a=a.nextConnection&&a.nextConnection.targetBlock();
c=c?"":Blockly.JavaScript.blockToCode(a);return d+b+c};
Blockly.JavaScript.getAdjusted=function(a,b,c,d,e){c=c||0;e=e||Blockly.JavaScript.ORDER_NONE;a.workspace.options.oneBasedIndex&&c--;var f=a.workspace.options.oneBasedIndex?"1":"0";a=0<c?Blockly.JavaScript.valueToCode(a,b,Blockly.JavaScript.ORDER_ADDITION)||f:0>c?Blockly.JavaScript.valueToCode(a,b,Blockly.JavaScript.ORDER_SUBTRACTION)||f:d?Blockly.JavaScript.valueToCode(a,b,Blockly.JavaScript.ORDER_UNARY_NEGATION)||f:Blockly.JavaScript.valueToCode(a,b,e)||f;if(Blockly.isNumber(a))a=Number(a)+c,d&&
(a=-a);else{if(0<c){a=a+" + "+c;var g=Blockly.JavaScript.ORDER_ADDITION}else 0>c&&(a=a+" - "+-c,g=Blockly.JavaScript.ORDER_SUBTRACTION);d&&(a=c?"-("+a+")":"-"+a,g=Blockly.JavaScript.ORDER_UNARY_NEGATION);g=Math.floor(g);e=Math.floor(e);g&&e>=g&&(a="("+a+")")}return a};Blockly.JavaScript.colour={};Blockly.JavaScript.colour_picker=function(a){return[Blockly.JavaScript.quote_(a.getFieldValue("COLOUR")),Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.colour_random=function(a){return[Blockly.JavaScript.provideFunction_("colourRandom",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"() {"," var num = Math.floor(Math.random() * Math.pow(2, 24));"," return '#' + ('00000' + num.toString(16)).substr(-6);","}"])+"()",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.init=function(a){Object.getPrototypeOf(this).init.call(this);this.nameDB_?this.nameDB_.reset():this.nameDB_=new Blockly.Names(this.RESERVED_WORDS_);this.nameDB_.setVariableMap(a.getVariableMap());this.nameDB_.populateVariables(a);this.nameDB_.populateProcedures(a);for(var b=[],c=Blockly.Variables.allDeveloperVariables(a),d=0;d<c.length;d++)b.push(this.nameDB_.getName(c[d],Blockly.Names.DEVELOPER_VARIABLE_TYPE));a=Blockly.Variables.allUsedVarModels(a);for(d=0;d<a.length;d++)b.push(this.nameDB_.getName(a[d].getId(),
Blockly.VARIABLE_CATEGORY_NAME));b.length&&(this.definitions_.variables="var "+b.join(", ")+";");this.isInitialized=!0};Blockly.JavaScript.finish=function(a){var b=Blockly.utils.object.values(this.definitions_);a=Object.getPrototypeOf(this).finish.call(this,a);this.isInitialized=!1;this.nameDB_.reset();return b.join("\n\n")+"\n\n\n"+a};Blockly.JavaScript.scrubNakedValue=function(a){return a+";\n"};
Blockly.JavaScript.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/'/g,"\\'");return"'"+a+"'"};Blockly.JavaScript.multiline_quote_=function(a){return a.split(/\n/g).map(this.quote_).join(" + '\\n' +\n")};
Blockly.JavaScript.scrub_=function(a,b,c){var d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();e&&(e=Blockly.utils.string.wrap(e,this.COMMENT_WRAP-3),d+=this.prefixLines(e+"\n","// "));for(var f=0;f<a.inputList.length;f++)a.inputList[f].type==Blockly.inputTypes.VALUE&&(e=a.inputList[f].connection.targetBlock())&&(e=this.allNestedComments(e))&&(d+=this.prefixLines(e,"// "))}a=a.nextConnection&&a.nextConnection.targetBlock();c=c?"":this.blockToCode(a);return d+
b+c};
Blockly.JavaScript.getAdjusted=function(a,b,c,d,e){c=c||0;e=e||this.ORDER_NONE;a.workspace.options.oneBasedIndex&&c--;var f=a.workspace.options.oneBasedIndex?"1":"0";a=0<c?this.valueToCode(a,b,this.ORDER_ADDITION)||f:0>c?this.valueToCode(a,b,this.ORDER_SUBTRACTION)||f:d?this.valueToCode(a,b,this.ORDER_UNARY_NEGATION)||f:this.valueToCode(a,b,e)||f;if(Blockly.isNumber(a))a=Number(a)+c,d&&(a=-a);else{if(0<c){a=a+" + "+c;var g=this.ORDER_ADDITION}else 0>c&&(a=a+" - "+-c,g=this.ORDER_SUBTRACTION);d&&(a=
c?"-("+a+")":"-"+a,g=this.ORDER_UNARY_NEGATION);g=Math.floor(g);e=Math.floor(e);g&&e>=g&&(a="("+a+")")}return a};Blockly.JavaScript.colour={};Blockly.JavaScript.colour_picker=function(a){return[Blockly.JavaScript.quote_(a.getFieldValue("COLOUR")),Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.colour_random=function(a){return[Blockly.JavaScript.provideFunction_("colourRandom",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"() {"," var num = Math.floor(Math.random() * Math.pow(2, 24));"," return '#' + ('00000' + num.toString(16)).substr(-6);","}"])+"()",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.colour_rgb=function(a){var b=Blockly.JavaScript.valueToCode(a,"RED",Blockly.JavaScript.ORDER_NONE)||0,c=Blockly.JavaScript.valueToCode(a,"GREEN",Blockly.JavaScript.ORDER_NONE)||0;a=Blockly.JavaScript.valueToCode(a,"BLUE",Blockly.JavaScript.ORDER_NONE)||0;return[Blockly.JavaScript.provideFunction_("colourRgb",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(r, g, b) {"," r = Math.max(Math.min(Number(r), 100), 0) * 2.55;"," g = Math.max(Math.min(Number(g), 100), 0) * 2.55;",
" b = Math.max(Math.min(Number(b), 100), 0) * 2.55;"," r = ('0' + (Math.round(r) || 0).toString(16)).slice(-2);"," g = ('0' + (Math.round(g) || 0).toString(16)).slice(-2);"," b = ('0' + (Math.round(b) || 0).toString(16)).slice(-2);"," return '#' + r + g + b;","}"])+"("+b+", "+c+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.colour_blend=function(a){var b=Blockly.JavaScript.valueToCode(a,"COLOUR1",Blockly.JavaScript.ORDER_NONE)||"'#000000'",c=Blockly.JavaScript.valueToCode(a,"COLOUR2",Blockly.JavaScript.ORDER_NONE)||"'#000000'";a=Blockly.JavaScript.valueToCode(a,"RATIO",Blockly.JavaScript.ORDER_NONE)||.5;return[Blockly.JavaScript.provideFunction_("colourBlend",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(c1, c2, ratio) {"," ratio = Math.max(Math.min(Number(ratio), 1), 0);"," var r1 = parseInt(c1.substring(1, 3), 16);",
@ -36,9 +35,9 @@ Blockly.JavaScript.lists_getIndex=function(a){var b=a.getFieldValue("MODE")||"GE
if("GET_REMOVE"==b)return[d+".pop()",Blockly.JavaScript.ORDER_MEMBER];if("REMOVE"==b)return d+".pop();\n";break;case "FROM_START":a=Blockly.JavaScript.getAdjusted(a,"AT");if("GET"==b)return[d+"["+a+"]",Blockly.JavaScript.ORDER_MEMBER];if("GET_REMOVE"==b)return[d+".splice("+a+", 1)[0]",Blockly.JavaScript.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+".splice("+a+", 1);\n";break;case "FROM_END":a=Blockly.JavaScript.getAdjusted(a,"AT",1,!0);if("GET"==b)return[d+".slice("+a+")[0]",Blockly.JavaScript.ORDER_FUNCTION_CALL];
if("GET_REMOVE"==b)return[d+".splice("+a+", 1)[0]",Blockly.JavaScript.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+".splice("+a+", 1);";break;case "RANDOM":d=Blockly.JavaScript.provideFunction_("listsGetRandomItem",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(list, remove) {"," var x = Math.floor(Math.random() * list.length);"," if (remove) {"," return list.splice(x, 1)[0];"," } else {"," return list[x];"," }","}"])+"("+d+", "+("GET"!=b)+")";if("GET"==b||"GET_REMOVE"==b)return[d,
Blockly.JavaScript.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+";\n"}throw Error("Unhandled combination (lists_getIndex).");};
Blockly.JavaScript.lists_setIndex=function(a){function b(){if(c.match(/^\w+$/))return"";var g=Blockly.JavaScript.variableDB_.getDistinctName("tmpList",Blockly.VARIABLE_CATEGORY_NAME),h="var "+g+" = "+c+";\n";c=g;return h}var c=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_MEMBER)||"[]",d=a.getFieldValue("MODE")||"GET",e=a.getFieldValue("WHERE")||"FROM_START",f=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_ASSIGNMENT)||"null";switch(e){case "FIRST":if("SET"==d)return c+
Blockly.JavaScript.lists_setIndex=function(a){function b(){if(c.match(/^\w+$/))return"";var g=Blockly.JavaScript.nameDB_.getDistinctName("tmpList",Blockly.VARIABLE_CATEGORY_NAME),h="var "+g+" = "+c+";\n";c=g;return h}var c=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_MEMBER)||"[]",d=a.getFieldValue("MODE")||"GET",e=a.getFieldValue("WHERE")||"FROM_START",f=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_ASSIGNMENT)||"null";switch(e){case "FIRST":if("SET"==d)return c+
"[0] = "+f+";\n";if("INSERT"==d)return c+".unshift("+f+");\n";break;case "LAST":if("SET"==d)return a=b(),a+(c+"["+c+".length - 1] = "+f+";\n");if("INSERT"==d)return c+".push("+f+");\n";break;case "FROM_START":e=Blockly.JavaScript.getAdjusted(a,"AT");if("SET"==d)return c+"["+e+"] = "+f+";\n";if("INSERT"==d)return c+".splice("+e+", 0, "+f+");\n";break;case "FROM_END":e=Blockly.JavaScript.getAdjusted(a,"AT",1,!1,Blockly.JavaScript.ORDER_SUBTRACTION);a=b();if("SET"==d)return a+(c+"["+c+".length - "+e+
"] = "+f+";\n");if("INSERT"==d)return a+(c+".splice("+c+".length - "+e+", 0, "+f+");\n");break;case "RANDOM":a=b();e=Blockly.JavaScript.variableDB_.getDistinctName("tmpX",Blockly.VARIABLE_CATEGORY_NAME);a+="var "+e+" = Math.floor(Math.random() * "+c+".length);\n";if("SET"==d)return a+(c+"["+e+"] = "+f+";\n");if("INSERT"==d)return a+(c+".splice("+e+", 0, "+f+");\n")}throw Error("Unhandled combination (lists_setIndex).");};
"] = "+f+";\n");if("INSERT"==d)return a+(c+".splice("+c+".length - "+e+", 0, "+f+");\n");break;case "RANDOM":a=b();e=Blockly.JavaScript.nameDB_.getDistinctName("tmpX",Blockly.VARIABLE_CATEGORY_NAME);a+="var "+e+" = Math.floor(Math.random() * "+c+".length);\n";if("SET"==d)return a+(c+"["+e+"] = "+f+";\n");if("INSERT"==d)return a+(c+".splice("+e+", 0, "+f+");\n")}throw Error("Unhandled combination (lists_setIndex).");};
Blockly.JavaScript.lists.getIndex_=function(a,b,c){return"FIRST"==b?"0":"FROM_END"==b?a+".length - 1 - "+c:"LAST"==b?a+".length - 1":c};
Blockly.JavaScript.lists_getSublist=function(a){var b=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_MEMBER)||"[]",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2");if("FIRST"==c&&"LAST"==d)b+=".slice(0)";else if(b.match(/^\w+$/)||"FROM_END"!=c&&"FROM_START"==d){switch(c){case "FROM_START":var e=Blockly.JavaScript.getAdjusted(a,"AT1");break;case "FROM_END":e=Blockly.JavaScript.getAdjusted(a,"AT1",1,!1,Blockly.JavaScript.ORDER_SUBTRACTION);e=b+".length - "+e;break;case "FIRST":e=
"0";break;default:throw Error("Unhandled option (lists_getSublist).");}switch(d){case "FROM_START":a=Blockly.JavaScript.getAdjusted(a,"AT2",1);break;case "FROM_END":a=Blockly.JavaScript.getAdjusted(a,"AT2",0,!1,Blockly.JavaScript.ORDER_SUBTRACTION);a=b+".length - "+a;break;case "LAST":a=b+".length";break;default:throw Error("Unhandled option (lists_getSublist).");}b=b+".slice("+e+", "+a+")"}else{e=Blockly.JavaScript.getAdjusted(a,"AT1");a=Blockly.JavaScript.getAdjusted(a,"AT2");var f=Blockly.JavaScript.lists.getIndex_,
@ -54,13 +53,13 @@ Blockly.JavaScript.logic_compare=function(a){var b={EQ:"==",NEQ:"!=",LT:"<",LTE:
Blockly.JavaScript.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"&&":"||",c="&&"==b?Blockly.JavaScript.ORDER_LOGICAL_AND:Blockly.JavaScript.ORDER_LOGICAL_OR,d=Blockly.JavaScript.valueToCode(a,"A",c);a=Blockly.JavaScript.valueToCode(a,"B",c);if(d||a){var e="&&"==b?"true":"false";d||(d=e);a||(a=e)}else a=d="false";return[d+" "+b+" "+a,c]};
Blockly.JavaScript.logic_negate=function(a){var b=Blockly.JavaScript.ORDER_LOGICAL_NOT;return["!"+(Blockly.JavaScript.valueToCode(a,"BOOL",b)||"true"),b]};Blockly.JavaScript.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"true":"false",Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.logic_null=function(a){return["null",Blockly.JavaScript.ORDER_ATOMIC]};
Blockly.JavaScript.logic_ternary=function(a){var b=Blockly.JavaScript.valueToCode(a,"IF",Blockly.JavaScript.ORDER_CONDITIONAL)||"false",c=Blockly.JavaScript.valueToCode(a,"THEN",Blockly.JavaScript.ORDER_CONDITIONAL)||"null";a=Blockly.JavaScript.valueToCode(a,"ELSE",Blockly.JavaScript.ORDER_CONDITIONAL)||"null";return[b+" ? "+c+" : "+a,Blockly.JavaScript.ORDER_CONDITIONAL]};Blockly.JavaScript.loops={};
Blockly.JavaScript.controls_repeat_ext=function(a){var b=a.getField("TIMES")?String(Number(a.getFieldValue("TIMES"))):Blockly.JavaScript.valueToCode(a,"TIMES",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",c=Blockly.JavaScript.statementToCode(a,"DO");c=Blockly.JavaScript.addLoopTrap(c,a);a="";var d=Blockly.JavaScript.variableDB_.getDistinctName("count",Blockly.VARIABLE_CATEGORY_NAME),e=b;b.match(/^\w+$/)||Blockly.isNumber(b)||(e=Blockly.JavaScript.variableDB_.getDistinctName("repeat_end",Blockly.VARIABLE_CATEGORY_NAME),
Blockly.JavaScript.controls_repeat_ext=function(a){var b=a.getField("TIMES")?String(Number(a.getFieldValue("TIMES"))):Blockly.JavaScript.valueToCode(a,"TIMES",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",c=Blockly.JavaScript.statementToCode(a,"DO");c=Blockly.JavaScript.addLoopTrap(c,a);a="";var d=Blockly.JavaScript.nameDB_.getDistinctName("count",Blockly.VARIABLE_CATEGORY_NAME),e=b;b.match(/^\w+$/)||Blockly.isNumber(b)||(e=Blockly.JavaScript.nameDB_.getDistinctName("repeat_end",Blockly.VARIABLE_CATEGORY_NAME),
a+="var "+e+" = "+b+";\n");return a+("for (var "+d+" = 0; "+d+" < "+e+"; "+d+"++) {\n"+c+"}\n")};Blockly.JavaScript.controls_repeat=Blockly.JavaScript.controls_repeat_ext;
Blockly.JavaScript.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.JavaScript.valueToCode(a,"BOOL",b?Blockly.JavaScript.ORDER_LOGICAL_NOT:Blockly.JavaScript.ORDER_NONE)||"false",d=Blockly.JavaScript.statementToCode(a,"DO");d=Blockly.JavaScript.addLoopTrap(d,a);b&&(c="!"+c);return"while ("+c+") {\n"+d+"}\n"};
Blockly.JavaScript.controls_for=function(a){var b=Blockly.JavaScript.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),c=Blockly.JavaScript.valueToCode(a,"FROM",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",d=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",e=Blockly.JavaScript.valueToCode(a,"BY",Blockly.JavaScript.ORDER_ASSIGNMENT)||"1",f=Blockly.JavaScript.statementToCode(a,"DO");f=Blockly.JavaScript.addLoopTrap(f,a);if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&
Blockly.isNumber(e)){var g=Number(c)<=Number(d);a="for ("+b+" = "+c+"; "+b+(g?" <= ":" >= ")+d+"; "+b;b=Math.abs(Number(e));a=(1==b?a+(g?"++":"--"):a+((g?" += ":" -= ")+b))+(") {\n"+f+"}\n")}else a="",g=c,c.match(/^\w+$/)||Blockly.isNumber(c)||(g=Blockly.JavaScript.variableDB_.getDistinctName(b+"_start",Blockly.VARIABLE_CATEGORY_NAME),a+="var "+g+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.JavaScript.variableDB_.getDistinctName(b+"_end",Blockly.VARIABLE_CATEGORY_NAME),a+=
"var "+c+" = "+d+";\n"),d=Blockly.JavaScript.variableDB_.getDistinctName(b+"_inc",Blockly.VARIABLE_CATEGORY_NAME),a+="var "+d+" = ",a=Blockly.isNumber(e)?a+(Math.abs(e)+";\n"):a+("Math.abs("+e+");\n"),a=a+("if ("+g+" > "+c+") {\n")+(Blockly.JavaScript.INDENT+d+" = -"+d+";\n"),a+="}\n",a+="for ("+b+" = "+g+"; "+d+" >= 0 ? "+b+" <= "+c+" : "+b+" >= "+c+"; "+b+" += "+d+") {\n"+f+"}\n";return a};
Blockly.JavaScript.controls_forEach=function(a){var b=Blockly.JavaScript.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),c=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_ASSIGNMENT)||"[]",d=Blockly.JavaScript.statementToCode(a,"DO");d=Blockly.JavaScript.addLoopTrap(d,a);a="";var e=c;c.match(/^\w+$/)||(e=Blockly.JavaScript.variableDB_.getDistinctName(b+"_list",Blockly.VARIABLE_CATEGORY_NAME),a+="var "+e+" = "+c+";\n");c=Blockly.JavaScript.variableDB_.getDistinctName(b+
Blockly.JavaScript.controls_for=function(a){var b=Blockly.JavaScript.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),c=Blockly.JavaScript.valueToCode(a,"FROM",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",d=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0",e=Blockly.JavaScript.valueToCode(a,"BY",Blockly.JavaScript.ORDER_ASSIGNMENT)||"1",f=Blockly.JavaScript.statementToCode(a,"DO");f=Blockly.JavaScript.addLoopTrap(f,a);if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&
Blockly.isNumber(e)){var g=Number(c)<=Number(d);a="for ("+b+" = "+c+"; "+b+(g?" <= ":" >= ")+d+"; "+b;b=Math.abs(Number(e));a=(1==b?a+(g?"++":"--"):a+((g?" += ":" -= ")+b))+(") {\n"+f+"}\n")}else a="",g=c,c.match(/^\w+$/)||Blockly.isNumber(c)||(g=Blockly.JavaScript.nameDB_.getDistinctName(b+"_start",Blockly.VARIABLE_CATEGORY_NAME),a+="var "+g+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.JavaScript.nameDB_.getDistinctName(b+"_end",Blockly.VARIABLE_CATEGORY_NAME),a+="var "+c+
" = "+d+";\n"),d=Blockly.JavaScript.nameDB_.getDistinctName(b+"_inc",Blockly.VARIABLE_CATEGORY_NAME),a+="var "+d+" = ",a=Blockly.isNumber(e)?a+(Math.abs(e)+";\n"):a+("Math.abs("+e+");\n"),a=a+("if ("+g+" > "+c+") {\n")+(Blockly.JavaScript.INDENT+d+" = -"+d+";\n"),a+="}\n",a+="for ("+b+" = "+g+"; "+d+" >= 0 ? "+b+" <= "+c+" : "+b+" >= "+c+"; "+b+" += "+d+") {\n"+f+"}\n";return a};
Blockly.JavaScript.controls_forEach=function(a){var b=Blockly.JavaScript.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),c=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_ASSIGNMENT)||"[]",d=Blockly.JavaScript.statementToCode(a,"DO");d=Blockly.JavaScript.addLoopTrap(d,a);a="";var e=c;c.match(/^\w+$/)||(e=Blockly.JavaScript.nameDB_.getDistinctName(b+"_list",Blockly.VARIABLE_CATEGORY_NAME),a+="var "+e+" = "+c+";\n");c=Blockly.JavaScript.nameDB_.getDistinctName(b+
"_index",Blockly.VARIABLE_CATEGORY_NAME);d=Blockly.JavaScript.INDENT+b+" = "+e+"["+c+"];\n"+d;return a+("for (var "+c+" in "+e+") {\n"+d+"}\n")};
Blockly.JavaScript.controls_flow_statements=function(a){var b="";Blockly.JavaScript.STATEMENT_PREFIX&&(b+=Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_PREFIX,a));Blockly.JavaScript.STATEMENT_SUFFIX&&(b+=Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_SUFFIX,a));if(Blockly.JavaScript.STATEMENT_PREFIX){var c=Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(a);c&&!c.suppressPrefixSuffix&&(b+=Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_PREFIX,
c))}switch(a.getFieldValue("FLOW")){case "BREAK":return b+"break;\n";case "CONTINUE":return b+"continue;\n"}throw Error("Unknown flow statement.");};Blockly.JavaScript.math={};Blockly.JavaScript.math_number=function(a){a=Number(a.getFieldValue("NUM"));return[a,0<=a?Blockly.JavaScript.ORDER_ATOMIC:Blockly.JavaScript.ORDER_UNARY_NEGATION]};
@ -71,8 +70,8 @@ a+")";break;case "LN":c="Math.log("+a+")";break;case "EXP":c="Math.exp("+a+")";b
Blockly.JavaScript.math_constant=function(a){return{PI:["Math.PI",Blockly.JavaScript.ORDER_MEMBER],E:["Math.E",Blockly.JavaScript.ORDER_MEMBER],GOLDEN_RATIO:["(1 + Math.sqrt(5)) / 2",Blockly.JavaScript.ORDER_DIVISION],SQRT2:["Math.SQRT2",Blockly.JavaScript.ORDER_MEMBER],SQRT1_2:["Math.SQRT1_2",Blockly.JavaScript.ORDER_MEMBER],INFINITY:["Infinity",Blockly.JavaScript.ORDER_ATOMIC]}[a.getFieldValue("CONSTANT")]};
Blockly.JavaScript.math_number_property=function(a){var b=Blockly.JavaScript.valueToCode(a,"NUMBER_TO_CHECK",Blockly.JavaScript.ORDER_MODULUS)||"0",c=a.getFieldValue("PROPERTY");if("PRIME"==c)return[Blockly.JavaScript.provideFunction_("mathIsPrime",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(n) {"," // https://en.wikipedia.org/wiki/Primality_test#Naive_methods"," if (n == 2 || n == 3) {"," return true;"," }"," // False if n is NaN, negative, is 1, or not whole."," // And false if n is divisible by 2 or 3.",
" if (isNaN(n) || n <= 1 || n % 1 != 0 || n % 2 == 0 || n % 3 == 0) {"," return false;"," }"," // Check all the numbers of form 6k +/- 1, up to sqrt(n)."," for (var x = 6; x <= Math.sqrt(n) + 1; x += 6) {"," if (n % (x - 1) == 0 || n % (x + 1) == 0) {"," return false;"," }"," }"," return true;","}"])+"("+b+")",Blockly.JavaScript.ORDER_FUNCTION_CALL];switch(c){case "EVEN":var d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":d=b+" % 1 == 0";break;case "POSITIVE":d=
b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.JavaScript.valueToCode(a,"DIVISOR",Blockly.JavaScript.ORDER_MODULUS)||"0",d=b+" % "+a+" == 0"}return[d,Blockly.JavaScript.ORDER_EQUALITY]};
Blockly.JavaScript.math_change=function(a){var b=Blockly.JavaScript.valueToCode(a,"DELTA",Blockly.JavaScript.ORDER_ADDITION)||"0";a=Blockly.JavaScript.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME);return a+" = (typeof "+a+" == 'number' ? "+a+" : 0) + "+b+";\n"};Blockly.JavaScript.math_round=Blockly.JavaScript.math_single;Blockly.JavaScript.math_trig=Blockly.JavaScript.math_single;
b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.JavaScript.valueToCode(a,"DIVISOR",Blockly.JavaScript.ORDER_MODULUS)||"0",d=b+" % "+a+" == 0"}return[d,Blockly.JavaScript.ORDER_EQUALITY]};Blockly.JavaScript.math_change=function(a){var b=Blockly.JavaScript.valueToCode(a,"DELTA",Blockly.JavaScript.ORDER_ADDITION)||"0";a=Blockly.JavaScript.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME);return a+" = (typeof "+a+" == 'number' ? "+a+" : 0) + "+b+";\n"};
Blockly.JavaScript.math_round=Blockly.JavaScript.math_single;Blockly.JavaScript.math_trig=Blockly.JavaScript.math_single;
Blockly.JavaScript.math_on_list=function(a){var b=a.getFieldValue("OP");switch(b){case "SUM":a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_MEMBER)||"[]";a+=".reduce(function(x, y) {return x + y;})";break;case "MIN":a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a="Math.min.apply(null, "+a+")";break;case "MAX":a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a="Math.max.apply(null, "+a+")";break;case "AVERAGE":b=Blockly.JavaScript.provideFunction_("mathMean",
["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(myList) {"," return myList.reduce(function(x, y) {return x + y;}) / myList.length;","}"]);a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a=b+"("+a+")";break;case "MEDIAN":b=Blockly.JavaScript.provideFunction_("mathMedian",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(myList) {"," var localList = myList.filter(function (x) {return typeof x == 'number';});"," if (!localList.length) return null;",
" localList.sort(function(a, b) {return b - a;});"," if (localList.length % 2 == 0) {"," return (localList[localList.length / 2 - 1] + localList[localList.length / 2]) / 2;"," } else {"," return localList[(localList.length - 1) / 2];"," }","}"]);a=Blockly.JavaScript.valueToCode(a,"LIST",Blockly.JavaScript.ORDER_NONE)||"[]";a=b+"("+a+")";break;case "MODE":b=Blockly.JavaScript.provideFunction_("mathModes",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(values) {"," var modes = [];",
@ -83,16 +82,16 @@ Blockly.JavaScript.math_on_list=function(a){var b=a.getFieldValue("OP");switch(b
Blockly.JavaScript.math_constrain=function(a){var b=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_NONE)||"0",c=Blockly.JavaScript.valueToCode(a,"LOW",Blockly.JavaScript.ORDER_NONE)||"0";a=Blockly.JavaScript.valueToCode(a,"HIGH",Blockly.JavaScript.ORDER_NONE)||"Infinity";return["Math.min(Math.max("+b+", "+c+"), "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.math_random_int=function(a){var b=Blockly.JavaScript.valueToCode(a,"FROM",Blockly.JavaScript.ORDER_NONE)||"0";a=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_NONE)||"0";return[Blockly.JavaScript.provideFunction_("mathRandomInt",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(a, b) {"," if (a > b) {"," // Swap a and b to ensure a is smaller."," var c = a;"," a = b;"," b = c;"," }"," return Math.floor(Math.random() * (b - a + 1) + a);",
"}"])+"("+b+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.math_random_float=function(a){return["Math.random()",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.math_atan2=function(a){var b=Blockly.JavaScript.valueToCode(a,"X",Blockly.JavaScript.ORDER_NONE)||"0";return["Math.atan2("+(Blockly.JavaScript.valueToCode(a,"Y",Blockly.JavaScript.ORDER_NONE)||"0")+", "+b+") / Math.PI * 180",Blockly.JavaScript.ORDER_DIVISION]};Blockly.JavaScript.procedures={};
Blockly.JavaScript.procedures_defreturn=function(a){var b=Blockly.JavaScript.variableDB_.getName(a.getFieldValue("NAME"),Blockly.PROCEDURE_CATEGORY_NAME),c="";Blockly.JavaScript.STATEMENT_PREFIX&&(c+=Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_PREFIX,a));Blockly.JavaScript.STATEMENT_SUFFIX&&(c+=Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_SUFFIX,a));c&&(c=Blockly.JavaScript.prefixLines(c,Blockly.JavaScript.INDENT));var d="";Blockly.JavaScript.INFINITE_LOOP_TRAP&&(d=Blockly.JavaScript.prefixLines(Blockly.JavaScript.injectId(Blockly.JavaScript.INFINITE_LOOP_TRAP,
a),Blockly.JavaScript.INDENT));var e=Blockly.JavaScript.statementToCode(a,"STACK"),f=Blockly.JavaScript.valueToCode(a,"RETURN",Blockly.JavaScript.ORDER_NONE)||"",g="";e&&f&&(g=c);f&&(f=Blockly.JavaScript.INDENT+"return "+f+";\n");for(var h=[],l=a.getVars(),k=0;k<l.length;k++)h[k]=Blockly.JavaScript.variableDB_.getName(l[k],Blockly.VARIABLE_CATEGORY_NAME);c="function "+b+"("+h.join(", ")+") {\n"+c+d+e+g+f+"}";c=Blockly.JavaScript.scrub_(a,c);Blockly.JavaScript.definitions_["%"+b]=c;return null};
Blockly.JavaScript.procedures_defnoreturn=Blockly.JavaScript.procedures_defreturn;Blockly.JavaScript.procedures_callreturn=function(a){for(var b=Blockly.JavaScript.variableDB_.getName(a.getFieldValue("NAME"),Blockly.PROCEDURE_CATEGORY_NAME),c=[],d=a.getVars(),e=0;e<d.length;e++)c[e]=Blockly.JavaScript.valueToCode(a,"ARG"+e,Blockly.JavaScript.ORDER_NONE)||"null";return[b+"("+c.join(", ")+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.procedures_defreturn=function(a){var b=Blockly.JavaScript.nameDB_.getName(a.getFieldValue("NAME"),Blockly.PROCEDURE_CATEGORY_NAME),c="";Blockly.JavaScript.STATEMENT_PREFIX&&(c+=Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_PREFIX,a));Blockly.JavaScript.STATEMENT_SUFFIX&&(c+=Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_SUFFIX,a));c&&(c=Blockly.JavaScript.prefixLines(c,Blockly.JavaScript.INDENT));var d="";Blockly.JavaScript.INFINITE_LOOP_TRAP&&(d=Blockly.JavaScript.prefixLines(Blockly.JavaScript.injectId(Blockly.JavaScript.INFINITE_LOOP_TRAP,
a),Blockly.JavaScript.INDENT));var e=Blockly.JavaScript.statementToCode(a,"STACK"),f=Blockly.JavaScript.valueToCode(a,"RETURN",Blockly.JavaScript.ORDER_NONE)||"",g="";e&&f&&(g=c);f&&(f=Blockly.JavaScript.INDENT+"return "+f+";\n");for(var h=[],l=a.getVars(),k=0;k<l.length;k++)h[k]=Blockly.JavaScript.nameDB_.getName(l[k],Blockly.VARIABLE_CATEGORY_NAME);c="function "+b+"("+h.join(", ")+") {\n"+c+d+e+g+f+"}";c=Blockly.JavaScript.scrub_(a,c);Blockly.JavaScript.definitions_["%"+b]=c;return null};
Blockly.JavaScript.procedures_defnoreturn=Blockly.JavaScript.procedures_defreturn;Blockly.JavaScript.procedures_callreturn=function(a){for(var b=Blockly.JavaScript.nameDB_.getName(a.getFieldValue("NAME"),Blockly.PROCEDURE_CATEGORY_NAME),c=[],d=a.getVars(),e=0;e<d.length;e++)c[e]=Blockly.JavaScript.valueToCode(a,"ARG"+e,Blockly.JavaScript.ORDER_NONE)||"null";return[b+"("+c.join(", ")+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.procedures_callnoreturn=function(a){return Blockly.JavaScript.procedures_callreturn(a)[0]+";\n"};
Blockly.JavaScript.procedures_ifreturn=function(a){var b="if ("+(Blockly.JavaScript.valueToCode(a,"CONDITION",Blockly.JavaScript.ORDER_NONE)||"false")+") {\n";Blockly.JavaScript.STATEMENT_SUFFIX&&(b+=Blockly.JavaScript.prefixLines(Blockly.JavaScript.injectId(Blockly.JavaScript.STATEMENT_SUFFIX,a),Blockly.JavaScript.INDENT));a.hasReturnValue_?(a=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_NONE)||"null",b+=Blockly.JavaScript.INDENT+"return "+a+";\n"):b+=Blockly.JavaScript.INDENT+
"return;\n";return b+"}\n"};Blockly.JavaScript.texts={};Blockly.JavaScript.text=function(a){return[Blockly.JavaScript.quote_(a.getFieldValue("TEXT")),Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.text_multiline=function(a){a=Blockly.JavaScript.multiline_quote_(a.getFieldValue("TEXT"));var b=-1!=a.indexOf("+")?Blockly.JavaScript.ORDER_ADDITION:Blockly.JavaScript.ORDER_ATOMIC;return[a,b]};
Blockly.JavaScript.text.forceString_=function(a){return Blockly.JavaScript.text.forceString_.strRegExp.test(a)?[a,Blockly.JavaScript.ORDER_ATOMIC]:["String("+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.text.forceString_.strRegExp=/^\s*'([^']|\\')*'\s*$/;
Blockly.JavaScript.text_join=function(a){switch(a.itemCount_){case 0:return["''",Blockly.JavaScript.ORDER_ATOMIC];case 1:return a=Blockly.JavaScript.valueToCode(a,"ADD0",Blockly.JavaScript.ORDER_NONE)||"''",Blockly.JavaScript.text.forceString_(a);case 2:var b=Blockly.JavaScript.valueToCode(a,"ADD0",Blockly.JavaScript.ORDER_NONE)||"''";a=Blockly.JavaScript.valueToCode(a,"ADD1",Blockly.JavaScript.ORDER_NONE)||"''";a=Blockly.JavaScript.text.forceString_(b)[0]+" + "+Blockly.JavaScript.text.forceString_(a)[0];
return[a,Blockly.JavaScript.ORDER_ADDITION];default:b=Array(a.itemCount_);for(var c=0;c<a.itemCount_;c++)b[c]=Blockly.JavaScript.valueToCode(a,"ADD"+c,Blockly.JavaScript.ORDER_NONE)||"''";a="["+b.join(",")+"].join('')";return[a,Blockly.JavaScript.ORDER_FUNCTION_CALL]}};
Blockly.JavaScript.text_append=function(a){var b=Blockly.JavaScript.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME);a=Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''";return b+" += "+Blockly.JavaScript.text.forceString_(a)[0]+";\n"};Blockly.JavaScript.text_length=function(a){return[(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"''")+".length",Blockly.JavaScript.ORDER_MEMBER]};
Blockly.JavaScript.text_append=function(a){var b=Blockly.JavaScript.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME);a=Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''";return b+" += "+Blockly.JavaScript.text.forceString_(a)[0]+";\n"};Blockly.JavaScript.text_length=function(a){return[(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"''")+".length",Blockly.JavaScript.ORDER_MEMBER]};
Blockly.JavaScript.text_isEmpty=function(a){return["!"+(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"''")+".length",Blockly.JavaScript.ORDER_LOGICAL_NOT]};
Blockly.JavaScript.text_indexOf=function(a){var b="FIRST"==a.getFieldValue("END")?"indexOf":"lastIndexOf",c=Blockly.JavaScript.valueToCode(a,"FIND",Blockly.JavaScript.ORDER_NONE)||"''";b=(Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_MEMBER)||"''")+"."+b+"("+c+")";return a.workspace.options.oneBasedIndex?[b+" + 1",Blockly.JavaScript.ORDER_ADDITION]:[b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.text_charAt=function(a){var b=a.getFieldValue("WHERE")||"FROM_START",c=Blockly.JavaScript.valueToCode(a,"VALUE","RANDOM"==b?Blockly.JavaScript.ORDER_NONE:Blockly.JavaScript.ORDER_MEMBER)||"''";switch(b){case "FIRST":return[c+".charAt(0)",Blockly.JavaScript.ORDER_FUNCTION_CALL];case "LAST":return[c+".slice(-1)",Blockly.JavaScript.ORDER_FUNCTION_CALL];case "FROM_START":return a=Blockly.JavaScript.getAdjusted(a,"AT"),[c+".charAt("+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL];case "FROM_END":return a=
@ -107,7 +106,7 @@ Blockly.JavaScript.text_changeCase=function(a){var b={UPPERCASE:".toUpperCase()"
Blockly.JavaScript.text_prompt_ext=function(a){var b="window.prompt("+(a.getField("TEXT")?Blockly.JavaScript.quote_(a.getFieldValue("TEXT")):Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''")+")";"NUMBER"==a.getFieldValue("TYPE")&&(b="Number("+b+")");return[b,Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.text_prompt=Blockly.JavaScript.text_prompt_ext;
Blockly.JavaScript.text_count=function(a){var b=Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''";a=Blockly.JavaScript.valueToCode(a,"SUB",Blockly.JavaScript.ORDER_NONE)||"''";return[Blockly.JavaScript.provideFunction_("textCount",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(haystack, needle) {"," if (needle.length === 0) {"," return haystack.length + 1;"," } else {"," return haystack.split(needle).length - 1;"," }","}"])+"("+b+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};
Blockly.JavaScript.text_replace=function(a){var b=Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_NONE)||"''",c=Blockly.JavaScript.valueToCode(a,"FROM",Blockly.JavaScript.ORDER_NONE)||"''";a=Blockly.JavaScript.valueToCode(a,"TO",Blockly.JavaScript.ORDER_NONE)||"''";return[Blockly.JavaScript.provideFunction_("textReplace",["function "+Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_+"(haystack, needle, replacement) {",' needle = needle.replace(/([-()\\[\\]{}+?*.$\\^|,:#<!\\\\])/g,"\\\\$1")',
' .replace(/\\x08/g,"\\\\x08");'," return haystack.replace(new RegExp(needle, 'g'), replacement);","}"])+"("+b+", "+c+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.text_reverse=function(a){return[(Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_MEMBER)||"''")+".split('').reverse().join('')",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.variables={};Blockly.JavaScript.variables_get=function(a){return[Blockly.JavaScript.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.variables_set=function(a){var b=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0";return Blockly.JavaScript.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME)+" = "+b+";\n"};Blockly.JavaScript.variablesDynamic={};Blockly.JavaScript.variables_get_dynamic=Blockly.JavaScript.variables_get;Blockly.JavaScript.variables_set_dynamic=Blockly.JavaScript.variables_set;
' .replace(/\\x08/g,"\\\\x08");'," return haystack.replace(new RegExp(needle, 'g'), replacement);","}"])+"("+b+", "+c+", "+a+")",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.text_reverse=function(a){return[(Blockly.JavaScript.valueToCode(a,"TEXT",Blockly.JavaScript.ORDER_MEMBER)||"''")+".split('').reverse().join('')",Blockly.JavaScript.ORDER_FUNCTION_CALL]};Blockly.JavaScript.variables={};Blockly.JavaScript.variables_get=function(a){return[Blockly.JavaScript.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),Blockly.JavaScript.ORDER_ATOMIC]};Blockly.JavaScript.variables_set=function(a){var b=Blockly.JavaScript.valueToCode(a,"VALUE",Blockly.JavaScript.ORDER_ASSIGNMENT)||"0";return Blockly.JavaScript.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME)+" = "+b+";\n"};Blockly.JavaScript.variablesDynamic={};Blockly.JavaScript.variables_get_dynamic=Blockly.JavaScript.variables_get;Blockly.JavaScript.variables_set_dynamic=Blockly.JavaScript.variables_set;
return Blockly.JavaScript;
}));

File diff suppressed because one or more lines are too long

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es5"
},
"include": [
"core/**/**/*",
"typings/blockly.d.ts"
],
"exclude": [
"node_modules"
]
}

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -24,7 +24,7 @@ Blockly.Msg["COLOUR_RGB_BLUE"] = "青";
Blockly.Msg["COLOUR_RGB_GREEN"] = "緑";
Blockly.Msg["COLOUR_RGB_HELPURL"] = "http://www.december.com/html/spec/colorper.html";
Blockly.Msg["COLOUR_RGB_RED"] = "赤";
Blockly.Msg["COLOUR_RGB_TITLE"] = "色";
Blockly.Msg["COLOUR_RGB_TITLE"] = "色:";
Blockly.Msg["COLOUR_RGB_TOOLTIP"] = "赤、緑、および青の指定された量で色を作成します。すべての値は 0 100 の間でなければなりません。";
Blockly.Msg["CONTROLS_FLOW_STATEMENTS_HELPURL"] = "https://github.com/google/blockly/wiki/Loops#loop-termination-blocks"; // untranslated
Blockly.Msg["CONTROLS_FLOW_STATEMENTS_OPERATOR_BREAK"] = "ループから抜け出す";
@ -203,7 +203,7 @@ Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_DIVIDE"] = "2 つの数の商を返しま
Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_MINUS"] = "2 つの数の差を返します。";
Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_MULTIPLY"] = "2 つの数の積を返します。";
Blockly.Msg["MATH_ARITHMETIC_TOOLTIP_POWER"] = "最初の数を2 番目の値で累乗した結果を返します。";
Blockly.Msg["MATH_ATAN2_HELPURL"] = "https://en.wikipedia.org/wiki/Atan2"; // untranslated
Blockly.Msg["MATH_ATAN2_HELPURL"] = "https://en.wikipedia.org/wiki/Atan2";
Blockly.Msg["MATH_ATAN2_TITLE"] = "X:%1 Y:%2のaran2";
Blockly.Msg["MATH_ATAN2_TOOLTIP"] = "点 (X, Y) の逆関数を -180 度から 180度まで返します。";
Blockly.Msg["MATH_CHANGE_HELPURL"] = "https://ja.wikipedia.org/wiki/加法";
@ -286,7 +286,7 @@ Blockly.Msg["NEW_COLOUR_VARIABLE"] = "色の変数を作る...";
Blockly.Msg["NEW_NUMBER_VARIABLE"] = "数の変数を作る...";
Blockly.Msg["NEW_STRING_VARIABLE"] = "文字列の変数を作る...";
Blockly.Msg["NEW_VARIABLE"] = "変数の作成…";
Blockly.Msg["NEW_VARIABLE_TITLE"] = "新しい変数の名前";
Blockly.Msg["NEW_VARIABLE_TITLE"] = "新しい変数の名前:";
Blockly.Msg["NEW_VARIABLE_TYPE_TITLE"] = "新しい変数の型:";
Blockly.Msg["ORDINAL_NUMBER_SUFFIX"] = ""; // untranslated
Blockly.Msg["PROCEDURES_ALLOW_STATEMENTS"] = "ステートメントを許可";

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -1,7 +1,7 @@
{
"@metadata": {
"author": "Ellen Spertus <ellen.spertus@gmail.com>",
"lastupdated": "2021-03-25 09:26:05.766290",
"lastupdated": "2021-07-01 14:44:40.033432",
"locale": "en",
"messagedocumentation" : "qqq"
},

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -9,6 +9,7 @@
"Oda",
"Omotecho",
"Otokoume",
"RYU N",
"Sgk",
"Shirayuki",
"Suiato",
@ -48,7 +49,7 @@
"NEW_NUMBER_VARIABLE": "数の変数を作る...",
"NEW_COLOUR_VARIABLE": "色の変数を作る...",
"NEW_VARIABLE_TYPE_TITLE": "新しい変数の型:",
"NEW_VARIABLE_TITLE": "新しい変数の名前",
"NEW_VARIABLE_TITLE": "新しい変数の名前:",
"VARIABLE_ALREADY_EXISTS": "変数名 '%1' は既に存在しています。",
"VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE": "'%2' 型の '%1' という名前の変数が既に存在します。",
"DELETE_VARIABLE_CONFIRMATION": "%1か所で使われている変数 '%2' を削除しますか?",
@ -59,7 +60,7 @@
"COLOUR_RANDOM_TITLE": "ランダムな色",
"COLOUR_RANDOM_TOOLTIP": "ランダムに色を選ぶ。",
"COLOUR_RGB_HELPURL": "http://www.december.com/html/spec/colorper.html",
"COLOUR_RGB_TITLE": "色",
"COLOUR_RGB_TITLE": "色:",
"COLOUR_RGB_RED": "赤",
"COLOUR_RGB_GREEN": "緑",
"COLOUR_RGB_BLUE": "青",
@ -216,6 +217,7 @@
"MATH_RANDOM_FLOAT_HELPURL": "https://en.wikipedia.org/wiki/Random_number_generation",
"MATH_RANDOM_FLOAT_TITLE_RANDOM": "1未満の正の乱数",
"MATH_RANDOM_FLOAT_TOOLTIP": "0.0以上で1.0未満の範囲の乱数を返します。",
"MATH_ATAN2_HELPURL": "https://en.wikipedia.org/wiki/Atan2",
"MATH_ATAN2_TITLE": "X:%1 Y:%2のaran2",
"MATH_ATAN2_TOOLTIP": "点 (X, Y) の逆関数を -180 度から 180度まで返します。",
"TEXT_TEXT_HELPURL": "https://ja.wikipedia.org/wiki/文字列",

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -8,8 +8,8 @@
* @fileoverview English strings.
* @author fraser@google.com (Neil Fraser)
*
* After modifying this file, either run "build.py" from the parent directory,
* or run (from this directory):
* After modifying this file, either run "npm run build:langfiles" from the
* parent directory, or run (from this directory):
* ../scripts/i18n/js_to_json.py
* to regenerate json/{en,qqq,synonyms}.json.
*

View File

@ -1,3 +0,0 @@
[ZoneTransfer]
ZoneId=3
ReferrerUrl=F:\Downloads\blockly-5.20210325.1.zip

View File

@ -15,12 +15,12 @@ Blockly.Python.ORDER_ATOMIC=0;Blockly.Python.ORDER_COLLECTION=1;Blockly.Python.O
Blockly.Python.ORDER_RELATIONAL=11;Blockly.Python.ORDER_LOGICAL_NOT=12;Blockly.Python.ORDER_LOGICAL_AND=13;Blockly.Python.ORDER_LOGICAL_OR=14;Blockly.Python.ORDER_CONDITIONAL=15;Blockly.Python.ORDER_LAMBDA=16;Blockly.Python.ORDER_NONE=99;
Blockly.Python.ORDER_OVERRIDES=[[Blockly.Python.ORDER_FUNCTION_CALL,Blockly.Python.ORDER_MEMBER],[Blockly.Python.ORDER_FUNCTION_CALL,Blockly.Python.ORDER_FUNCTION_CALL],[Blockly.Python.ORDER_MEMBER,Blockly.Python.ORDER_MEMBER],[Blockly.Python.ORDER_MEMBER,Blockly.Python.ORDER_FUNCTION_CALL],[Blockly.Python.ORDER_LOGICAL_NOT,Blockly.Python.ORDER_LOGICAL_NOT],[Blockly.Python.ORDER_LOGICAL_AND,Blockly.Python.ORDER_LOGICAL_AND],[Blockly.Python.ORDER_LOGICAL_OR,Blockly.Python.ORDER_LOGICAL_OR]];
Blockly.Python.isInitialized=!1;
Blockly.Python.init=function(a){Blockly.Python.PASS=this.INDENT+"pass\n";Blockly.Python.definitions_=Object.create(null);Blockly.Python.functionNames_=Object.create(null);Blockly.Python.variableDB_?Blockly.Python.variableDB_.reset():Blockly.Python.variableDB_=new Blockly.Names(Blockly.Python.RESERVED_WORDS_);Blockly.Python.variableDB_.setVariableMap(a.getVariableMap());for(var b=[],c=Blockly.Variables.allDeveloperVariables(a),d=0;d<c.length;d++)b.push(Blockly.Python.variableDB_.getName(c[d],Blockly.Names.DEVELOPER_VARIABLE_TYPE)+
" = None");a=Blockly.Variables.allUsedVarModels(a);for(d=0;d<a.length;d++)b.push(Blockly.Python.variableDB_.getName(a[d].getId(),Blockly.VARIABLE_CATEGORY_NAME)+" = None");Blockly.Python.definitions_.variables=b.join("\n");this.isInitialized=!0};
Blockly.Python.finish=function(a){var b=[],c=[],d;for(d in Blockly.Python.definitions_){var e=Blockly.Python.definitions_[d];e.match(/^(from\s+\S+\s+)?import\s+\S+/)?b.push(e):c.push(e)}delete Blockly.Python.definitions_;delete Blockly.Python.functionNames_;Blockly.Python.variableDB_.reset();return(b.join("\n")+"\n\n"+c.join("\n\n")).replace(/\n\n+/g,"\n\n").replace(/\n*$/,"\n\n\n")+a};Blockly.Python.scrubNakedValue=function(a){return a+"\n"};
Blockly.Python.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n");var b="'";-1!==a.indexOf("'")&&(-1===a.indexOf('"')?b='"':a=a.replace(/'/g,"\\'"));return b+a+b};Blockly.Python.multiline_quote_=function(a){return a.split(/\n/g).map(Blockly.Python.quote_).join(" + '\\n' + \n")};
Blockly.Python.scrub_=function(a,b,c){var d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();e&&(e=Blockly.utils.string.wrap(e,Blockly.Python.COMMENT_WRAP-3),d+=Blockly.Python.prefixLines(e+"\n","# "));for(var f=0;f<a.inputList.length;f++)a.inputList[f].type==Blockly.INPUT_VALUE&&(e=a.inputList[f].connection.targetBlock())&&(e=Blockly.Python.allNestedComments(e))&&(d+=Blockly.Python.prefixLines(e,"# "))}a=a.nextConnection&&a.nextConnection.targetBlock();c=
c?"":Blockly.Python.blockToCode(a);return d+b+c};Blockly.Python.getAdjustedInt=function(a,b,c,d){c=c||0;a.workspace.options.oneBasedIndex&&c--;var e=a.workspace.options.oneBasedIndex?"1":"0";a=Blockly.Python.valueToCode(a,b,c?Blockly.Python.ORDER_ADDITIVE:Blockly.Python.ORDER_NONE)||e;Blockly.isNumber(a)?(a=parseInt(a,10)+c,d&&(a=-a)):(a=0<c?"int("+a+" + "+c+")":0>c?"int("+a+" - "+-c+")":"int("+a+")",d&&(a="-"+a));return a};Blockly.Python.colour={};Blockly.Python.colour_picker=function(a){return[Blockly.Python.quote_(a.getFieldValue("COLOUR")),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.colour_random=function(a){Blockly.Python.definitions_.import_random="import random";return["'#%06x' % random.randint(0, 2**24 - 1)",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.init=function(a){Object.getPrototypeOf(this).init.call(this);this.PASS=this.INDENT+"pass\n";this.nameDB_?this.nameDB_.reset():this.nameDB_=new Blockly.Names(this.RESERVED_WORDS_);this.nameDB_.setVariableMap(a.getVariableMap());this.nameDB_.populateVariables(a);this.nameDB_.populateProcedures(a);for(var b=[],c=Blockly.Variables.allDeveloperVariables(a),d=0;d<c.length;d++)b.push(this.nameDB_.getName(c[d],Blockly.Names.DEVELOPER_VARIABLE_TYPE)+" = None");a=Blockly.Variables.allUsedVarModels(a);
for(d=0;d<a.length;d++)b.push(this.nameDB_.getName(a[d].getId(),Blockly.VARIABLE_CATEGORY_NAME)+" = None");this.definitions_.variables=b.join("\n");this.isInitialized=!0};
Blockly.Python.finish=function(a){var b=[],c=[],d;for(d in this.definitions_){var e=this.definitions_[d];e.match(/^(from\s+\S+\s+)?import\s+\S+/)?b.push(e):c.push(e)}a=Object.getPrototypeOf(this).finish.call(this,a);this.isInitialized=!1;this.nameDB_.reset();return(b.join("\n")+"\n\n"+c.join("\n\n")).replace(/\n\n+/g,"\n\n").replace(/\n*$/,"\n\n\n")+a};Blockly.Python.scrubNakedValue=function(a){return a+"\n"};
Blockly.Python.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n");var b="'";-1!==a.indexOf("'")&&(-1===a.indexOf('"')?b='"':a=a.replace(/'/g,"\\'"));return b+a+b};Blockly.Python.multiline_quote_=function(a){return a.split(/\n/g).map(this.quote_).join(" + '\\n' + \n")};
Blockly.Python.scrub_=function(a,b,c){var d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();e&&(e=Blockly.utils.string.wrap(e,this.COMMENT_WRAP-3),d+=this.prefixLines(e+"\n","# "));for(var f=0;f<a.inputList.length;f++)a.inputList[f].type==Blockly.inputTypes.VALUE&&(e=a.inputList[f].connection.targetBlock())&&(e=this.allNestedComments(e))&&(d+=this.prefixLines(e,"# "))}a=a.nextConnection&&a.nextConnection.targetBlock();c=c?"":this.blockToCode(a);return d+b+
c};Blockly.Python.getAdjustedInt=function(a,b,c,d){c=c||0;a.workspace.options.oneBasedIndex&&c--;var e=a.workspace.options.oneBasedIndex?"1":"0";a=this.valueToCode(a,b,c?this.ORDER_ADDITIVE:this.ORDER_NONE)||e;Blockly.isNumber(a)?(a=parseInt(a,10)+c,d&&(a=-a)):(a=0<c?"int("+a+" + "+c+")":0>c?"int("+a+" - "+-c+")":"int("+a+")",d&&(a="-"+a));return a};Blockly.Python.colour={};Blockly.Python.colour_picker=function(a){return[Blockly.Python.quote_(a.getFieldValue("COLOUR")),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.colour_random=function(a){Blockly.Python.definitions_.import_random="import random";return["'#%06x' % random.randint(0, 2**24 - 1)",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.colour_rgb=function(a){var b=Blockly.Python.provideFunction_("colour_rgb",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(r, g, b):"," r = round(min(100, max(0, r)) * 2.55)"," g = round(min(100, max(0, g)) * 2.55)"," b = round(min(100, max(0, b)) * 2.55)"," return '#%02x%02x%02x' % (r, g, b)"]),c=Blockly.Python.valueToCode(a,"RED",Blockly.Python.ORDER_NONE)||0,d=Blockly.Python.valueToCode(a,"GREEN",Blockly.Python.ORDER_NONE)||0;a=Blockly.Python.valueToCode(a,"BLUE",Blockly.Python.ORDER_NONE)||
0;return[b+"("+c+", "+d+", "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.colour_blend=function(a){var b=Blockly.Python.provideFunction_("colour_blend",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(colour1, colour2, ratio):"," r1, r2 = int(colour1[1:3], 16), int(colour2[1:3], 16)"," g1, g2 = int(colour1[3:5], 16), int(colour2[3:5], 16)"," b1, b2 = int(colour1[5:7], 16), int(colour2[5:7], 16)"," ratio = min(1, max(0, ratio))"," r = round(r1 * (1 - ratio) + r2 * ratio)"," g = round(g1 * (1 - ratio) + g2 * ratio)"," b = round(b1 * (1 - ratio) + b2 * ratio)",
@ -34,7 +34,7 @@ b)return[d+".pop()",Blockly.Python.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+
Blockly.Python.ORDER_FUNCTION_CALL];if("REMOVE"==b)return d+".pop("+a+")\n";break;case "RANDOM":Blockly.Python.definitions_.import_random="import random";if("GET"==b)return["random.choice("+d+")",Blockly.Python.ORDER_FUNCTION_CALL];d=Blockly.Python.provideFunction_("lists_remove_random_item",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(myList):"," x = int(random.random() * len(myList))"," return myList.pop(x)"])+"("+d+")";if("GET_REMOVE"==b)return[d,Blockly.Python.ORDER_FUNCTION_CALL];if("REMOVE"==
b)return d+"\n"}throw Error("Unhandled combination (lists_getIndex).");};
Blockly.Python.lists_setIndex=function(a){var b=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_MEMBER)||"[]",c=a.getFieldValue("MODE")||"GET",d=a.getFieldValue("WHERE")||"FROM_START",e=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"None";switch(d){case "FIRST":if("SET"==c)return b+"[0] = "+e+"\n";if("INSERT"==c)return b+".insert(0, "+e+")\n";break;case "LAST":if("SET"==c)return b+"[-1] = "+e+"\n";if("INSERT"==c)return b+".append("+e+")\n";break;case "FROM_START":a=Blockly.Python.getAdjustedInt(a,
"AT");if("SET"==c)return b+"["+a+"] = "+e+"\n";if("INSERT"==c)return b+".insert("+a+", "+e+")\n";break;case "FROM_END":a=Blockly.Python.getAdjustedInt(a,"AT",1,!0);if("SET"==c)return b+"["+a+"] = "+e+"\n";if("INSERT"==c)return b+".insert("+a+", "+e+")\n";break;case "RANDOM":Blockly.Python.definitions_.import_random="import random";b.match(/^\w+$/)?a="":(a=Blockly.Python.variableDB_.getDistinctName("tmp_list",Blockly.VARIABLE_CATEGORY_NAME),d=a+" = "+b+"\n",b=a,a=d);d=Blockly.Python.variableDB_.getDistinctName("tmp_x",
"AT");if("SET"==c)return b+"["+a+"] = "+e+"\n";if("INSERT"==c)return b+".insert("+a+", "+e+")\n";break;case "FROM_END":a=Blockly.Python.getAdjustedInt(a,"AT",1,!0);if("SET"==c)return b+"["+a+"] = "+e+"\n";if("INSERT"==c)return b+".insert("+a+", "+e+")\n";break;case "RANDOM":Blockly.Python.definitions_.import_random="import random";b.match(/^\w+$/)?a="":(a=Blockly.Python.nameDB_.getDistinctName("tmp_list",Blockly.VARIABLE_CATEGORY_NAME),d=a+" = "+b+"\n",b=a,a=d);d=Blockly.Python.nameDB_.getDistinctName("tmp_x",
Blockly.VARIABLE_CATEGORY_NAME);a+=d+" = int(random.random() * len("+b+"))\n";if("SET"==c)return a+(b+"["+d+"] = "+e+"\n");if("INSERT"==c)return a+(b+".insert("+d+", "+e+")\n")}throw Error("Unhandled combination (lists_setIndex).");};
Blockly.Python.lists_getSublist=function(a){var b=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_MEMBER)||"[]",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2");switch(c){case "FROM_START":c=Blockly.Python.getAdjustedInt(a,"AT1");"0"==c&&(c="");break;case "FROM_END":c=Blockly.Python.getAdjustedInt(a,"AT1",1,!0);break;case "FIRST":c="";break;default:throw Error("Unhandled option (lists_getSublist)");}switch(d){case "FROM_START":a=Blockly.Python.getAdjustedInt(a,"AT2",1);break;case "FROM_END":a=
Blockly.Python.getAdjustedInt(a,"AT2",0,!0);Blockly.isNumber(String(a))?"0"==a&&(a=""):(Blockly.Python.definitions_.import_sys="import sys",a+=" or sys.maxsize");break;case "LAST":a="";break;default:throw Error("Unhandled option (lists_getSublist)");}return[b+"["+c+" : "+a+"]",Blockly.Python.ORDER_MEMBER]};
@ -47,12 +47,12 @@ b));if(a.getInput("ELSE")||Blockly.Python.STATEMENT_SUFFIX)e=Blockly.Python.stat
Blockly.Python.logic_compare=function(a){var b={EQ:"==",NEQ:"!=",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getFieldValue("OP")],c=Blockly.Python.ORDER_RELATIONAL,d=Blockly.Python.valueToCode(a,"A",c)||"0";a=Blockly.Python.valueToCode(a,"B",c)||"0";return[d+" "+b+" "+a,c]};
Blockly.Python.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"and":"or",c="and"==b?Blockly.Python.ORDER_LOGICAL_AND:Blockly.Python.ORDER_LOGICAL_OR,d=Blockly.Python.valueToCode(a,"A",c);a=Blockly.Python.valueToCode(a,"B",c);if(d||a){var e="and"==b?"True":"False";d||(d=e);a||(a=e)}else a=d="False";return[d+" "+b+" "+a,c]};Blockly.Python.logic_negate=function(a){return["not "+(Blockly.Python.valueToCode(a,"BOOL",Blockly.Python.ORDER_LOGICAL_NOT)||"True"),Blockly.Python.ORDER_LOGICAL_NOT]};
Blockly.Python.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"True":"False",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.logic_null=function(a){return["None",Blockly.Python.ORDER_ATOMIC]};
Blockly.Python.logic_ternary=function(a){var b=Blockly.Python.valueToCode(a,"IF",Blockly.Python.ORDER_CONDITIONAL)||"False",c=Blockly.Python.valueToCode(a,"THEN",Blockly.Python.ORDER_CONDITIONAL)||"None";a=Blockly.Python.valueToCode(a,"ELSE",Blockly.Python.ORDER_CONDITIONAL)||"None";return[c+" if "+b+" else "+a,Blockly.Python.ORDER_CONDITIONAL]};Blockly.Python.loops={};Blockly.Python.controls_repeat_ext=function(a){var b=a.getField("TIMES")?String(parseInt(a.getFieldValue("TIMES"),10)):Blockly.Python.valueToCode(a,"TIMES",Blockly.Python.ORDER_NONE)||"0";b=Blockly.isNumber(b)?parseInt(b,10):"int("+b+")";var c=Blockly.Python.statementToCode(a,"DO");c=Blockly.Python.addLoopTrap(c,a)||Blockly.Python.PASS;return"for "+Blockly.Python.variableDB_.getDistinctName("count",Blockly.VARIABLE_CATEGORY_NAME)+" in range("+b+"):\n"+c};
Blockly.Python.logic_ternary=function(a){var b=Blockly.Python.valueToCode(a,"IF",Blockly.Python.ORDER_CONDITIONAL)||"False",c=Blockly.Python.valueToCode(a,"THEN",Blockly.Python.ORDER_CONDITIONAL)||"None";a=Blockly.Python.valueToCode(a,"ELSE",Blockly.Python.ORDER_CONDITIONAL)||"None";return[c+" if "+b+" else "+a,Blockly.Python.ORDER_CONDITIONAL]};Blockly.Python.loops={};Blockly.Python.controls_repeat_ext=function(a){var b=a.getField("TIMES")?String(parseInt(a.getFieldValue("TIMES"),10)):Blockly.Python.valueToCode(a,"TIMES",Blockly.Python.ORDER_NONE)||"0";b=Blockly.isNumber(b)?parseInt(b,10):"int("+b+")";var c=Blockly.Python.statementToCode(a,"DO");c=Blockly.Python.addLoopTrap(c,a)||Blockly.Python.PASS;return"for "+Blockly.Python.nameDB_.getDistinctName("count",Blockly.VARIABLE_CATEGORY_NAME)+" in range("+b+"):\n"+c};
Blockly.Python.controls_repeat=Blockly.Python.controls_repeat_ext;Blockly.Python.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Python.valueToCode(a,"BOOL",b?Blockly.Python.ORDER_LOGICAL_NOT:Blockly.Python.ORDER_NONE)||"False",d=Blockly.Python.statementToCode(a,"DO");d=Blockly.Python.addLoopTrap(d,a)||Blockly.Python.PASS;b&&(c="not "+c);return"while "+c+":\n"+d};
Blockly.Python.controls_for=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),c=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"0",d=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"0",e=Blockly.Python.valueToCode(a,"BY",Blockly.Python.ORDER_NONE)||"1",f=Blockly.Python.statementToCode(a,"DO");f=Blockly.Python.addLoopTrap(f,a)||Blockly.Python.PASS;var n="",k=function(){return Blockly.Python.provideFunction_("upRange",
Blockly.Python.controls_for=function(a){var b=Blockly.Python.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),c=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"0",d=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"0",e=Blockly.Python.valueToCode(a,"BY",Blockly.Python.ORDER_NONE)||"1",f=Blockly.Python.statementToCode(a,"DO");f=Blockly.Python.addLoopTrap(f,a)||Blockly.Python.PASS;var n="",k=function(){return Blockly.Python.provideFunction_("upRange",
["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(start, stop, step):"," while start <= stop:"," yield start"," start += abs(step)"])},h=function(){return Blockly.Python.provideFunction_("downRange",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(start, stop, step):"," while start >= stop:"," yield start"," start -= abs(step)"])};a=function(g,l,p){return"("+g+" <= "+l+") and "+k()+"("+g+", "+l+", "+p+") or "+h()+"("+g+", "+l+", "+p+")"};if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&
Blockly.isNumber(e))c=Number(c),d=Number(d),e=Math.abs(Number(e)),0===c%1&&0===d%1&&0===e%1?(c<=d?(d++,a=0==c&&1==e?d:c+", "+d,1!=e&&(a+=", "+e)):(d--,a=c+", "+d+", -"+e),a="range("+a+")"):(a=c<d?k():h(),a+="("+c+", "+d+", "+e+")");else{var m=function(g,l){Blockly.isNumber(g)?g=Number(g):g.match(/^\w+$/)?g="float("+g+")":(l=Blockly.Python.variableDB_.getDistinctName(b+l,Blockly.VARIABLE_CATEGORY_NAME),n+=l+" = float("+g+")\n",g=l);return g};c=m(c,"_start");d=m(d,"_end");e=m(e,"_inc");"number"==typeof c&&
"number"==typeof d?(a=c<d?k():h(),a+="("+c+", "+d+", "+e+")"):a=a(c,d,e)}return n+="for "+b+" in "+a+":\n"+f};Blockly.Python.controls_forEach=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),c=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_RELATIONAL)||"[]",d=Blockly.Python.statementToCode(a,"DO");d=Blockly.Python.addLoopTrap(d,a)||Blockly.Python.PASS;return"for "+b+" in "+c+":\n"+d};
Blockly.isNumber(e))c=Number(c),d=Number(d),e=Math.abs(Number(e)),0===c%1&&0===d%1&&0===e%1?(c<=d?(d++,a=0==c&&1==e?d:c+", "+d,1!=e&&(a+=", "+e)):(d--,a=c+", "+d+", -"+e),a="range("+a+")"):(a=c<d?k():h(),a+="("+c+", "+d+", "+e+")");else{var m=function(g,l){Blockly.isNumber(g)?g=Number(g):g.match(/^\w+$/)?g="float("+g+")":(l=Blockly.Python.nameDB_.getDistinctName(b+l,Blockly.VARIABLE_CATEGORY_NAME),n+=l+" = float("+g+")\n",g=l);return g};c=m(c,"_start");d=m(d,"_end");e=m(e,"_inc");"number"==typeof c&&
"number"==typeof d?(a=c<d?k():h(),a+="("+c+", "+d+", "+e+")"):a=a(c,d,e)}return n+="for "+b+" in "+a+":\n"+f};Blockly.Python.controls_forEach=function(a){var b=Blockly.Python.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),c=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_RELATIONAL)||"[]",d=Blockly.Python.statementToCode(a,"DO");d=Blockly.Python.addLoopTrap(d,a)||Blockly.Python.PASS;return"for "+b+" in "+c+":\n"+d};
Blockly.Python.controls_flow_statements=function(a){var b="";Blockly.Python.STATEMENT_PREFIX&&(b+=Blockly.Python.injectId(Blockly.Python.STATEMENT_PREFIX,a));Blockly.Python.STATEMENT_SUFFIX&&(b+=Blockly.Python.injectId(Blockly.Python.STATEMENT_SUFFIX,a));if(Blockly.Python.STATEMENT_PREFIX){var c=Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN.getSurroundLoop(a);c&&!c.suppressPrefixSuffix&&(b+=Blockly.Python.injectId(Blockly.Python.STATEMENT_PREFIX,c))}switch(a.getFieldValue("FLOW")){case "BREAK":return b+
"break\n";case "CONTINUE":return b+"continue\n"}throw Error("Unknown flow statement.");};Blockly.Python.math={};Blockly.Python.addReservedWords("math,random,Number");Blockly.Python.math_number=function(a){a=Number(a.getFieldValue("NUM"));if(Infinity==a){a='float("inf")';var b=Blockly.Python.ORDER_FUNCTION_CALL}else-Infinity==a?(a='-float("inf")',b=Blockly.Python.ORDER_UNARY_SIGN):b=0>a?Blockly.Python.ORDER_UNARY_SIGN:Blockly.Python.ORDER_ATOMIC;return[a,b]};
Blockly.Python.math_arithmetic=function(a){var b={ADD:[" + ",Blockly.Python.ORDER_ADDITIVE],MINUS:[" - ",Blockly.Python.ORDER_ADDITIVE],MULTIPLY:[" * ",Blockly.Python.ORDER_MULTIPLICATIVE],DIVIDE:[" / ",Blockly.Python.ORDER_MULTIPLICATIVE],POWER:[" ** ",Blockly.Python.ORDER_EXPONENTIATION]}[a.getFieldValue("OP")],c=b[0];b=b[1];var d=Blockly.Python.valueToCode(a,"A",b)||"0";a=Blockly.Python.valueToCode(a,"B",b)||"0";return[d+c+a,b]};
@ -63,7 +63,7 @@ Blockly.Python.math_constant=function(a){var b={PI:["math.pi",Blockly.Python.ORD
Blockly.Python.math_number_property=function(a){var b=Blockly.Python.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Python.ORDER_MULTIPLICATIVE)||"0",c=a.getFieldValue("PROPERTY");if("PRIME"==c)return Blockly.Python.definitions_.import_math="import math",Blockly.Python.definitions_.from_numbers_import_Number="from numbers import Number",[Blockly.Python.provideFunction_("math_isPrime",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(n):"," # https://en.wikipedia.org/wiki/Primality_test#Naive_methods",
" # If n is not a number but a string, try parsing it."," if not isinstance(n, Number):"," try:"," n = float(n)"," except:"," return False"," if n == 2 or n == 3:"," return True"," # False if n is negative, is 1, or not whole, or if n is divisible by 2 or 3."," if n <= 1 or n % 1 != 0 or n % 2 == 0 or n % 3 == 0:"," return False"," # Check all the numbers of form 6k +/- 1, up to sqrt(n)."," for x in range(6, int(math.sqrt(n)) + 2, 6):"," if n % (x - 1) == 0 or n % (x + 1) == 0:",
" return False"," return True"])+"("+b+")",Blockly.Python.ORDER_FUNCTION_CALL];switch(c){case "EVEN":var d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":d=b+" % 1 == 0";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.Python.valueToCode(a,"DIVISOR",Blockly.Python.ORDER_MULTIPLICATIVE);if(!a||"0"==a)return["False",Blockly.Python.ORDER_ATOMIC];d=b+" % "+a+" == 0"}return[d,Blockly.Python.ORDER_RELATIONAL]};
Blockly.Python.math_change=function(a){Blockly.Python.definitions_.from_numbers_import_Number="from numbers import Number";var b=Blockly.Python.valueToCode(a,"DELTA",Blockly.Python.ORDER_ADDITIVE)||"0";a=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME);return a+" = ("+a+" if isinstance("+a+", Number) else 0) + "+b+"\n"};Blockly.Python.math_round=Blockly.Python.math_single;Blockly.Python.math_trig=Blockly.Python.math_single;
Blockly.Python.math_change=function(a){Blockly.Python.definitions_.from_numbers_import_Number="from numbers import Number";var b=Blockly.Python.valueToCode(a,"DELTA",Blockly.Python.ORDER_ADDITIVE)||"0";a=Blockly.Python.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME);return a+" = ("+a+" if isinstance("+a+", Number) else 0) + "+b+"\n"};Blockly.Python.math_round=Blockly.Python.math_single;Blockly.Python.math_trig=Blockly.Python.math_single;
Blockly.Python.math_on_list=function(a){var b=a.getFieldValue("OP");a=Blockly.Python.valueToCode(a,"LIST",Blockly.Python.ORDER_NONE)||"[]";switch(b){case "SUM":b="sum("+a+")";break;case "MIN":b="min("+a+")";break;case "MAX":b="max("+a+")";break;case "AVERAGE":Blockly.Python.definitions_.from_numbers_import_Number="from numbers import Number";b=Blockly.Python.provideFunction_("math_mean",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(myList):"," localList = [e for e in myList if isinstance(e, Number)]",
" if not localList: return"," return float(sum(localList)) / len(localList)"]);b=b+"("+a+")";break;case "MEDIAN":Blockly.Python.definitions_.from_numbers_import_Number="from numbers import Number";b=Blockly.Python.provideFunction_("math_median",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(myList):"," localList = sorted([e for e in myList if isinstance(e, Number)])"," if not localList: return"," if len(localList) % 2 == 0:"," return (localList[len(localList) // 2 - 1] + localList[len(localList) // 2]) / 2.0",
" else:"," return localList[(len(localList) - 1) // 2]"]);b=b+"("+a+")";break;case "MODE":b=Blockly.Python.provideFunction_("math_modes",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(some_list):"," modes = []"," # Using a lists of [item, count] to keep count rather than dict",' # to avoid "unhashable" errors when the counted item is itself a list or dict.'," counts = []"," maxCount = 1"," for item in some_list:"," found = False"," for count in counts:"," if count[0] == item:",
@ -73,15 +73,15 @@ Blockly.Python.math_modulo=function(a){var b=Blockly.Python.valueToCode(a,"DIVID
Blockly.Python.math_constrain=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"0",c=Blockly.Python.valueToCode(a,"LOW",Blockly.Python.ORDER_NONE)||"0";a=Blockly.Python.valueToCode(a,"HIGH",Blockly.Python.ORDER_NONE)||"float('inf')";return["min(max("+b+", "+c+"), "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.math_random_int=function(a){Blockly.Python.definitions_.import_random="import random";var b=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"0";a=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"0";return["random.randint("+b+", "+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};Blockly.Python.math_random_float=function(a){Blockly.Python.definitions_.import_random="import random";return["random.random()",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.math_atan2=function(a){Blockly.Python.definitions_.import_math="import math";var b=Blockly.Python.valueToCode(a,"X",Blockly.Python.ORDER_NONE)||"0";return["math.atan2("+(Blockly.Python.valueToCode(a,"Y",Blockly.Python.ORDER_NONE)||"0")+", "+b+") / math.pi * 180",Blockly.Python.ORDER_MULTIPLICATIVE]};Blockly.Python.procedures={};
Blockly.Python.procedures_defreturn=function(a){for(var b=[],c,d=a.workspace,e=Blockly.Variables.allUsedVarModels(d)||[],f=0;c=e[f];f++)c=c.name,-1==a.getVars().indexOf(c)&&b.push(Blockly.Python.variableDB_.getName(c,Blockly.VARIABLE_CATEGORY_NAME));e=Blockly.Variables.allDeveloperVariables(d);for(f=0;f<e.length;f++)b.push(Blockly.Python.variableDB_.getName(e[f],Blockly.Names.DEVELOPER_VARIABLE_TYPE));b=b.length?Blockly.Python.INDENT+"global "+b.join(", ")+"\n":"";d=Blockly.Python.variableDB_.getName(a.getFieldValue("NAME"),Blockly.PROCEDURE_CATEGORY_NAME);
c="";Blockly.Python.STATEMENT_PREFIX&&(c+=Blockly.Python.injectId(Blockly.Python.STATEMENT_PREFIX,a));Blockly.Python.STATEMENT_SUFFIX&&(c+=Blockly.Python.injectId(Blockly.Python.STATEMENT_SUFFIX,a));c&&(c=Blockly.Python.prefixLines(c,Blockly.Python.INDENT));var n="";Blockly.Python.INFINITE_LOOP_TRAP&&(n=Blockly.Python.prefixLines(Blockly.Python.injectId(Blockly.Python.INFINITE_LOOP_TRAP,a),Blockly.Python.INDENT));var k=Blockly.Python.statementToCode(a,"STACK"),h=Blockly.Python.valueToCode(a,"RETURN",
Blockly.Python.ORDER_NONE)||"",m="";k&&h&&(m=c);h?h=Blockly.Python.INDENT+"return "+h+"\n":k||(k=Blockly.Python.PASS);var g=[];e=a.getVars();for(f=0;f<e.length;f++)g[f]=Blockly.Python.variableDB_.getName(e[f],Blockly.VARIABLE_CATEGORY_NAME);b="def "+d+"("+g.join(", ")+"):\n"+b+c+n+k+m+h;b=Blockly.Python.scrub_(a,b);Blockly.Python.definitions_["%"+d]=b;return null};Blockly.Python.procedures_defnoreturn=Blockly.Python.procedures_defreturn;
Blockly.Python.procedures_callreturn=function(a){for(var b=Blockly.Python.variableDB_.getName(a.getFieldValue("NAME"),Blockly.PROCEDURE_CATEGORY_NAME),c=[],d=a.getVars(),e=0;e<d.length;e++)c[e]=Blockly.Python.valueToCode(a,"ARG"+e,Blockly.Python.ORDER_NONE)||"None";return[b+"("+c.join(", ")+")",Blockly.Python.ORDER_FUNCTION_CALL]};Blockly.Python.procedures_callnoreturn=function(a){return Blockly.Python.procedures_callreturn(a)[0]+"\n"};
Blockly.Python.procedures_defreturn=function(a){for(var b=[],c=a.workspace,d=Blockly.Variables.allUsedVarModels(c)||[],e=0,f;f=d[e];e++)f=f.name,-1==a.getVars().indexOf(f)&&b.push(Blockly.Python.nameDB_.getName(f,Blockly.VARIABLE_CATEGORY_NAME));d=Blockly.Variables.allDeveloperVariables(c);for(e=0;e<d.length;e++)b.push(Blockly.Python.nameDB_.getName(d[e],Blockly.Names.DEVELOPER_VARIABLE_TYPE));b=b.length?Blockly.Python.INDENT+"global "+b.join(", ")+"\n":"";c=Blockly.Python.nameDB_.getName(a.getFieldValue("NAME"),Blockly.PROCEDURE_CATEGORY_NAME);
f="";Blockly.Python.STATEMENT_PREFIX&&(f+=Blockly.Python.injectId(Blockly.Python.STATEMENT_PREFIX,a));Blockly.Python.STATEMENT_SUFFIX&&(f+=Blockly.Python.injectId(Blockly.Python.STATEMENT_SUFFIX,a));f&&(f=Blockly.Python.prefixLines(f,Blockly.Python.INDENT));var n="";Blockly.Python.INFINITE_LOOP_TRAP&&(n=Blockly.Python.prefixLines(Blockly.Python.injectId(Blockly.Python.INFINITE_LOOP_TRAP,a),Blockly.Python.INDENT));var k=Blockly.Python.statementToCode(a,"STACK"),h=Blockly.Python.valueToCode(a,"RETURN",
Blockly.Python.ORDER_NONE)||"",m="";k&&h&&(m=f);h?h=Blockly.Python.INDENT+"return "+h+"\n":k||(k=Blockly.Python.PASS);var g=[];d=a.getVars();for(e=0;e<d.length;e++)g[e]=Blockly.Python.nameDB_.getName(d[e],Blockly.VARIABLE_CATEGORY_NAME);b="def "+c+"("+g.join(", ")+"):\n"+b+f+n+k+m+h;b=Blockly.Python.scrub_(a,b);Blockly.Python.definitions_["%"+c]=b;return null};Blockly.Python.procedures_defnoreturn=Blockly.Python.procedures_defreturn;
Blockly.Python.procedures_callreturn=function(a){for(var b=Blockly.Python.nameDB_.getName(a.getFieldValue("NAME"),Blockly.PROCEDURE_CATEGORY_NAME),c=[],d=a.getVars(),e=0;e<d.length;e++)c[e]=Blockly.Python.valueToCode(a,"ARG"+e,Blockly.Python.ORDER_NONE)||"None";return[b+"("+c.join(", ")+")",Blockly.Python.ORDER_FUNCTION_CALL]};Blockly.Python.procedures_callnoreturn=function(a){return Blockly.Python.procedures_callreturn(a)[0]+"\n"};
Blockly.Python.procedures_ifreturn=function(a){var b="if "+(Blockly.Python.valueToCode(a,"CONDITION",Blockly.Python.ORDER_NONE)||"False")+":\n";Blockly.Python.STATEMENT_SUFFIX&&(b+=Blockly.Python.prefixLines(Blockly.Python.injectId(Blockly.Python.STATEMENT_SUFFIX,a),Blockly.Python.INDENT));a.hasReturnValue_?(a=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"None",b+=Blockly.Python.INDENT+"return "+a+"\n"):b+=Blockly.Python.INDENT+"return\n";return b};Blockly.Python.texts={};Blockly.Python.text=function(a){return[Blockly.Python.quote_(a.getFieldValue("TEXT")),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.text_multiline=function(a){a=Blockly.Python.multiline_quote_(a.getFieldValue("TEXT"));var b=-1!=a.indexOf("+")?Blockly.Python.ORDER_ADDITIVE:Blockly.Python.ORDER_ATOMIC;return[a,b]};Blockly.Python.text.forceString_=function(a){return Blockly.Python.text.forceString_.strRegExp.test(a)?[a,Blockly.Python.ORDER_ATOMIC]:["str("+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.text.forceString_.strRegExp=/^\s*'([^']|\\')*'\s*$/;
Blockly.Python.text_join=function(a){switch(a.itemCount_){case 0:return["''",Blockly.Python.ORDER_ATOMIC];case 1:return a=Blockly.Python.valueToCode(a,"ADD0",Blockly.Python.ORDER_NONE)||"''",Blockly.Python.text.forceString_(a);case 2:var b=Blockly.Python.valueToCode(a,"ADD0",Blockly.Python.ORDER_NONE)||"''";a=Blockly.Python.valueToCode(a,"ADD1",Blockly.Python.ORDER_NONE)||"''";a=Blockly.Python.text.forceString_(b)[0]+" + "+Blockly.Python.text.forceString_(a)[0];return[a,Blockly.Python.ORDER_ADDITIVE];
default:b=[];for(var c=0;c<a.itemCount_;c++)b[c]=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_NONE)||"''";a=Blockly.Python.variableDB_.getDistinctName("x",Blockly.VARIABLE_CATEGORY_NAME);a="''.join([str("+a+") for "+a+" in ["+b.join(", ")+"]])";return[a,Blockly.Python.ORDER_FUNCTION_CALL]}};
Blockly.Python.text_append=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME);a=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_NONE)||"''";return b+" = str("+b+") + "+Blockly.Python.text.forceString_(a)[0]+"\n"};Blockly.Python.text_length=function(a){return["len("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"''")+")",Blockly.Python.ORDER_FUNCTION_CALL]};
default:b=[];for(var c=0;c<a.itemCount_;c++)b[c]=Blockly.Python.valueToCode(a,"ADD"+c,Blockly.Python.ORDER_NONE)||"''";a=Blockly.Python.nameDB_.getDistinctName("x",Blockly.VARIABLE_CATEGORY_NAME);a="''.join([str("+a+") for "+a+" in ["+b.join(", ")+"]])";return[a,Blockly.Python.ORDER_FUNCTION_CALL]}};
Blockly.Python.text_append=function(a){var b=Blockly.Python.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME);a=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_NONE)||"''";return b+" = str("+b+") + "+Blockly.Python.text.forceString_(a)[0]+"\n"};Blockly.Python.text_length=function(a){return["len("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"''")+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.text_isEmpty=function(a){return["not len("+(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"''")+")",Blockly.Python.ORDER_LOGICAL_NOT]};
Blockly.Python.text_indexOf=function(a){var b="FIRST"==a.getFieldValue("END")?"find":"rfind",c=Blockly.Python.valueToCode(a,"FIND",Blockly.Python.ORDER_NONE)||"''";b=(Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_MEMBER)||"''")+"."+b+"("+c+")";return a.workspace.options.oneBasedIndex?[b+" + 1",Blockly.Python.ORDER_ADDITIVE]:[b,Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.text_charAt=function(a){var b=a.getFieldValue("WHERE")||"FROM_START",c=Blockly.Python.valueToCode(a,"VALUE","RANDOM"==b?Blockly.Python.ORDER_NONE:Blockly.Python.ORDER_MEMBER)||"''";switch(b){case "FIRST":return[c+"[0]",Blockly.Python.ORDER_MEMBER];case "LAST":return[c+"[-1]",Blockly.Python.ORDER_MEMBER];case "FROM_START":return a=Blockly.Python.getAdjustedInt(a,"AT"),[c+"["+a+"]",Blockly.Python.ORDER_MEMBER];case "FROM_END":return a=Blockly.Python.getAdjustedInt(a,"AT",1,!0),[c+"["+
@ -92,7 +92,7 @@ Blockly.Python.text_changeCase=function(a){var b={UPPERCASE:".upper()",LOWERCASE
Blockly.Python.text_print=function(a){return"print("+(Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_NONE)||"''")+")\n"};
Blockly.Python.text_prompt_ext=function(a){var b=Blockly.Python.provideFunction_("text_prompt",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(msg):"," try:"," return raw_input(msg)"," except NameError:"," return input(msg)"]),c=a.getField("TEXT")?Blockly.Python.quote_(a.getFieldValue("TEXT")):Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_NONE)||"''";b=b+"("+c+")";"NUMBER"==a.getFieldValue("TYPE")&&(b="float("+b+")");return[b,Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.text_prompt=Blockly.Python.text_prompt_ext;Blockly.Python.text_count=function(a){var b=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_MEMBER)||"''";a=Blockly.Python.valueToCode(a,"SUB",Blockly.Python.ORDER_NONE)||"''";return[b+".count("+a+")",Blockly.Python.ORDER_FUNCTION_CALL]};
Blockly.Python.text_replace=function(a){var b=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_MEMBER)||"''",c=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"''";a=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"''";return[b+".replace("+c+", "+a+")",Blockly.Python.ORDER_MEMBER]};Blockly.Python.text_reverse=function(a){return[(Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_MEMBER)||"''")+"[::-1]",Blockly.Python.ORDER_MEMBER]};Blockly.Python.variables={};Blockly.Python.variables_get=function(a){return[Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.variables_set=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"0";return Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME)+" = "+b+"\n"};Blockly.Python.variablesDynamic={};Blockly.Python.variables_get_dynamic=Blockly.Python.variables_get;Blockly.Python.variables_set_dynamic=Blockly.Python.variables_set;
Blockly.Python.text_replace=function(a){var b=Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_MEMBER)||"''",c=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"''";a=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"''";return[b+".replace("+c+", "+a+")",Blockly.Python.ORDER_MEMBER]};Blockly.Python.text_reverse=function(a){return[(Blockly.Python.valueToCode(a,"TEXT",Blockly.Python.ORDER_MEMBER)||"''")+"[::-1]",Blockly.Python.ORDER_MEMBER]};Blockly.Python.variables={};Blockly.Python.variables_get=function(a){return[Blockly.Python.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME),Blockly.Python.ORDER_ATOMIC]};Blockly.Python.variables_set=function(a){var b=Blockly.Python.valueToCode(a,"VALUE",Blockly.Python.ORDER_NONE)||"0";return Blockly.Python.nameDB_.getName(a.getFieldValue("VAR"),Blockly.VARIABLE_CATEGORY_NAME)+" = "+b+"\n"};Blockly.Python.variablesDynamic={};Blockly.Python.variables_get_dynamic=Blockly.Python.variables_get;Blockly.Python.variables_set_dynamic=Blockly.Python.variables_set;
return Blockly.Python;
}));

File diff suppressed because one or more lines are too long

View File

@ -1,2 +0,0 @@
[ZoneTransfer]
ZoneId=3

View File

@ -1,2 +0,0 @@
[ZoneTransfer]
ZoneId=3

View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="./scripts/prettify_desert.css">
<link rel="stylesheet" href="./lib/prettify_desert.css">
</link>
<link rel="stylesheet" href="./fonts/css/all.min.css">
</link>
@ -103,8 +103,8 @@
<field name="MODE">WHILE</field>
</block>
<block type="ugj_control_for">
<field name="index" id="wcdXljeguV+HoJ=u4|_8">番号</field>
<field name="crease">increase</field>
<field name="index" id="[0Dv+s57IrE5bItrMx6V">番号</field>
<field name="crease">+</field>
<value name="from">
<shadow type="math_number">
<field name="NUM">1</field>
@ -421,14 +421,6 @@
</value>
</block>
<block type="ugj_i2c_close"></block>
<block type="ugj_i2c_write_byte">
<value name="byte_val">
<shadow type="math_number">
<field name="NUM">0</field>
</shadow>
</value>
</block>
<block type="ugj_i2c_read_byte"></block>
<block type="ugj_i2c_write_byte_data">
<value name="reg">
<shadow type="math_number">
@ -448,7 +440,43 @@
</shadow>
</value>
</block>
<block type="ugj_i2c_read_device">
<value name="count">
<shadow type="math_number">
<field name="NUM">1</field>
</shadow>
</value>
</block>
<block type="ugj_i2c_write_device">
<value name="data">
<shadow type="text_join">
<mutation items="2"></mutation>
<value name="ADD0">
<shadow type="text">
<field name="TEXT">ohayo-.</field>
</shadow>
</value>
<value name="ADD1">
<shadow type="ugj_text_cr"></shadow>
</value>
</shadow>
</value>
</block>
<label text="センサー" web-line="4.0" web-line-width="200"></label>
<block type="ugj_bme280">
<field name="temp" id="4iysIXd|f$Jj$9hZ(R_H">気温</field>
<field name="hum" id="IT?JH;IRcsGP.8I%aEgw">湿度</field>
<field name="pres" id="I^GLkF^Z3#x2F0ho%J[?">気圧</field>
<value name="address">
<shadow type="ugj_hextodec">
<value name="hex">
<shadow type="text">
<field name="TEXT">76</field>
</shadow>
</value>
</shadow>
</value>
</block>
<label text="Extra" web-line="4.0" web-line-width="200"></label>
<label text="_" web-line="4.0" web-line-width="200"></label>
</category>
@ -593,11 +621,11 @@
</value>
</block>
<block type="ugj_network_sendmail">
<value name="from">
<!-- <value name="from">
<shadow type="text">
<field name="TEXT">from@ocoge.club</field>
</shadow>
</value>
</value> -->
<value name="to">
<shadow type="text">
<field name="TEXT">to@example.com</field>
@ -673,7 +701,7 @@
<block type="ugj_blackboard_write">
<field name="style">normal</field>
<field name="line">new</field>
<field name="cursor">FALSE</field>
<!-- <field name="cursor">FALSE</field> -->
<value name="text">
<shadow type="text">
<field name="TEXT">コンニチワ!</field>
@ -937,11 +965,12 @@
<script src="./google-blockly/python_compressed.js"></script>
<script src="./google-blockly/blocks_compressed.js"></script>
<script src="./google-blockly/msg/js/ja.js"></script>
<script src="./scripts/custom-dialog.js"></script>
<script src="./lib/custom-dialog.js"></script>
<script src="./ugj_const.js"></script>
<script src="./ugj_blocks.js"></script>
<script src="./ugj_script.js"></script>
<script src="./scripts/beautify.min.js"></script>
<script src="./scripts/prettify.js"></script>
<script src="./lib/beautify.min.js"></script>
<script src="./lib/prettify.js"></script>
<script src="./.shared/skyway_key.js"></script>
</body>

View File

@ -5,7 +5,7 @@ NODEJS=14.17.0
# install lgpio (and python3)
sudo apt update
sudo apt install python3 swig python3-dev python3-setuptools -y
sudo apt install build-essential python3 swig python3-dev python3-setuptools -y
wget http://abyz.me.uk/lg/lg.zip
unzip lg.zip
rm lg.zip

13
lib/test.py Normal file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import sys
for i in range(10, 0, -1):
print(i, flush=True) # flush=True を指定することで、バッファが無効になる
# print i # python2.x
# sys.stdout.flush() # python2.x
time.sleep(1)
print("終了 - Python test")
# print '終了 - Python test' # python2.x

View File

@ -0,0 +1,270 @@
'use strict';
// const { strictEqual } = require('assert');
class BME280 {
constructor(options) {
this.pi = require('@ocogeclub/lgpio');
this.i2cBusNo = (options && options.hasOwnProperty('i2cBusNo')) ? options.i2cBusNo : 1;
this.i2cAddress = (options && options.hasOwnProperty('i2cAddress')) ? options.i2cAddress : BME280.BME280_DEFAULT_I2C_ADDRESS();
this.i2cHand = this.pi.i2c_open(this.i2cBusNo, this.i2cAddress);
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;
}
init() {
let r;
r = this.pi.i2c_write_byte_data(this.i2cHand, this.REGISTER_CHIPID, 0);
if (r < 0) return r;
let chipId = this.pi.i2c_read_byte_data(this.i2cHand, this.REGISTER_CHIPID);
if (chipId !== BME280.CHIP_ID_BME280() &&
chipId !== BME280.CHIP_ID1_BMP280() &&
chipId !== BME280.CHIP_ID2_BMP280() &&
chipId !== BME280.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()}`);
this.loadCalibration((err) => {
if (err) {
return err;
}
// Humidity 16x oversampling
//
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 = 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()
//
reset() {
const POWER_ON_RESET_CMD = 0xB6;
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.
//
cancel() {
if (this.i2cHand >= 0) {
this.pi.i2c_close(this.i2cHand);
this.i2cHand = 0;
}
}
readSensorData() {
if (!this.cal) {
return 'You must first call bme280.init()';
}
// Grab temperature, humidity, and pressure in a single read
//
let [count, 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 = BME280.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 = BME280.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 = BME280.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
};
}
loadCalibration(callback) {
let [count, 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 = 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: BME280.uint16(buffer[1], buffer[0]),
dig_T2: BME280.int16(buffer[3], buffer[2]),
dig_T3: BME280.int16(buffer[5], buffer[4]),
dig_P1: BME280.uint16(buffer[7], buffer[6]),
dig_P2: BME280.int16(buffer[9], buffer[8]),
dig_P3: BME280.int16(buffer[11], buffer[10]),
dig_P4: BME280.int16(buffer[13], buffer[12]),
dig_P5: BME280.int16(buffer[15], buffer[14]),
dig_P6: BME280.int16(buffer[17], buffer[16]),
dig_P7: BME280.int16(buffer[19], buffer[18]),
dig_P8: BME280.int16(buffer[21], buffer[20]),
dig_P9: BME280.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));
callback();
}
}
static BME280_DEFAULT_I2C_ADDRESS() {
return 0x77;
}
static CHIP_ID1_BMP280() {
return 0x56;
}
static CHIP_ID2_BMP280() {
return 0x57;
}
static CHIP_ID3_BMP280() {
return 0x58;
}
static CHIP_ID_BME280() {
return 0x60;
}
static int16(msb, lsb) {
let val = BME280.uint16(msb, lsb);
return val > 32767 ? (val - 65536) : val;
}
static uint16(msb, lsb) {
return msb << 8 | lsb;
}
static uint20(msb, lsb, xlsb) {
return ((msb << 8 | lsb) << 8 | xlsb) >> 4;
}
static convertCelciusToFahrenheit(c) {
return c * 9 / 5 + 32;
}
static convertHectopascalToInchesOfMercury(hPa) {
return hPa * 0.02952998751;
}
static convertMetersToFeet(m) {
return m * 3.28084;
}
static 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);
}
static 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)));
}
static 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;
}
}
module.exports = BME280;
/*
* This code was forked from skylarstein's bme280-sensor: https://github.com/skylarstein/bme280-sensor
*/

View File

@ -0,0 +1,10 @@
{
"name": "@ocogeclub/bme280",
"version": "0.0.1",
"main": "BME280.js",
"private": true,
"license": "MIT",
"dependencies": {
"@ocogeclub/lgpio": "file:../lgpio"
}
}

View File

@ -0,0 +1,12 @@
{
"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"],
}
]
}

View File

@ -0,0 +1,8 @@
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;

View File

@ -9,7 +9,7 @@
using namespace Napi;
// gpiochipデバイスを開く
Value gpiochipOpen(const CallbackInfo& info)
Value gpiochipOpen(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 1)
@ -23,12 +23,12 @@ Value gpiochipOpen(const CallbackInfo& info)
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
return env.Null();
}
unsigned int gpioDev = info[0].As<Number>().DoubleValue();
int gpioDev = info[0].As<Number>().Int32Value();
return Number::New(env, lgGpiochipOpen(gpioDev));
}
// gpiochipデバイスを閉じる
Value gpiochipClose(const CallbackInfo& info)
Value gpiochipClose(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 1)
@ -42,12 +42,12 @@ Value gpiochipClose(const CallbackInfo& info)
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
return Number::New(env, lgGpiochipClose(handle));
}
// GPIO のモードを出力にする(ことを要求?)
Value gpioClaimOutput(const CallbackInfo& info)
Value gpioClaimOutput(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -62,16 +62,15 @@ Value gpioClaimOutput(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int gpio = info[1].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
int gpio = info[1].As<Number>().Int32Value();
return Number::New(env,
lgGpioClaimOutput(handle, 0, gpio, 0)
);
lgGpioClaimOutput(handle, 0, gpio, 0));
}
// GPIO のモードを入力にする(ことを要求?)
Value gpioClaimInput(const CallbackInfo& info)
Value gpioClaimInput(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 3)
@ -86,17 +85,16 @@ Value gpioClaimInput(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int gpio = info[1].As<Number>().DoubleValue();
unsigned int lflag = info[2].As<Number>().DoubleValue();
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)
);
lgGpioClaimInput(handle, lflag, gpio));
}
// GPIOの電圧を読む
Value gpioRead(const CallbackInfo& info)
Value gpioRead(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -111,16 +109,15 @@ Value gpioRead(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int gpio = info[1].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
int gpio = info[1].As<Number>().Int32Value();
return Number::New(env,
lgGpioRead(handle, gpio)
);
lgGpioRead(handle, gpio));
}
// GPIO の電圧をセットする
Value gpioWrite(const CallbackInfo& info)
Value gpioWrite(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 3)
@ -135,18 +132,16 @@ Value gpioWrite(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int gpio = info[1].As<Number>().DoubleValue();
unsigned int level = info[2].As<Number>().DoubleValue();
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)
);
lgGpioWrite(handle, gpio, level));
}
// サーボパルス幅をセットする
Value txServo(const CallbackInfo& info)
Value txServo(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 3)
@ -161,17 +156,16 @@ Value txServo(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int gpio = info[1].As<Number>().DoubleValue();
unsigned int pulseWidth = info[2].As<Number>().DoubleValue();
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)
);
lgTxServo(handle, gpio, pulseWidth, 50, 0, 0));
}
// PWMを設定して出力
Value txPwm(const CallbackInfo& info)
Value txPwm(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 4)
@ -186,18 +180,17 @@ Value txPwm(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int gpio = info[1].As<Number>().DoubleValue();
unsigned int pwmFrequency = info[2].As<Number>().DoubleValue();
unsigned int pwmDutyCycle = info[3].As<Number>().DoubleValue();
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)
);
lgTxPwm(handle, gpio, pwmFrequency, pwmDutyCycle, 0, 0));
}
// シリアルポートを開く
Value serialOpen(const CallbackInfo& info)
Value serialOpen(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -213,19 +206,18 @@ Value serialOpen(const CallbackInfo& info)
}
std::string tty = info[0].As<String>().Utf8Value();
// char *c = new char[ser_tty.size()+1];
// std::strcpy(c, ser_tty.c_str());
// char *c = new char[tty.size()+1];
// std::strcpy(c, tty.c_str());
// &ser_tty[0] で参照できるらしいけど危険?
unsigned int baud = info[1].As<Number>().DoubleValue();
int baud = info[1].As<Number>().Int32Value();
return Number::New(env,
lgSerialOpen(&tty[0], baud, 0)
);
lgSerialOpen(tty.c_str(), baud, 0));
}
// シリアルポートを閉じる
Value serialClose(const CallbackInfo& info)
Value serialClose(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 1)
@ -240,15 +232,14 @@ Value serialClose(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
return Number::New(env,
lgSerialClose(handle)
);
lgSerialClose(handle));
}
// シリアルデバイスからデータを受け取る
Value SerialRead(const CallbackInfo& info)
Value SerialRead(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -263,21 +254,25 @@ Value SerialRead(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int count = info[1].As<Number>().DoubleValue();
char rxBuf[count+1];
for (unsigned int i = 0; i <= count; i++)
{
rxBuf[i] = 0;
}
lgSerialRead(handle, rxBuf, count);
return String::New(env,
rxBuf
);
int handle = info[0].As<Number>().Int32Value();
int count = info[1].As<Number>().Int32Value();
// char rxBuf[count + 1];
// int32_t resultCount = lgSerialRead(handle, rxBuf, count);
// Buffer<char> resultBuf = Buffer<char>::Copy(env, rxBuf, count);
auto rxBuf = Buffer<char>::New(env, count);
int rxCount = lgSerialRead(handle, rxBuf.Data(), count);
Array returnArr = Array::New(env);
int i = 0;
returnArr[i] = Number::New(env, rxCount);
returnArr[++i] = rxBuf;
return returnArr;
}
// シリアルデバイスにバイト列を送る(data: string)
Value serialWrite(const CallbackInfo& info)
// シリアルデバイスにバイト列を送る(data: buffer)
Value serialWrite(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -286,24 +281,23 @@ Value serialWrite(const CallbackInfo& info)
.ThrowAsJavaScriptException();
return env.Null();
}
if (!info[0].IsNumber() || !info[1].IsString())
if (!info[0].IsNumber() || !info[1].IsBuffer())
{
TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
std::string txBuf = info[1].As<String>().Utf8Value();
int handle = info[0].As<Number>().Int32Value();
auto txBuf = info[1].As<Buffer<char>>();
unsigned int count = txBuf.length();
int count = txBuf.Length();
return Number::New(env,
lgSerialWrite(handle, &txBuf[0], count)
);
lgSerialWrite(handle, txBuf.Data(), count));
}
// I2Cバスアドレスのデバイスのハンドルを返す
Value i2cOpen(const CallbackInfo& info)
Value i2cOpen(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -318,16 +312,15 @@ Value i2cOpen(const CallbackInfo& info)
return env.Null();
}
unsigned int i2cDev = info[0].As<Number>().DoubleValue();
unsigned int i2cAddr = info[1].As<Number>().DoubleValue();
int i2cDev = info[0].As<Number>().Int32Value();
int i2cAddr = info[1].As<Number>().Int32Value();
return Number::New(env,
lgI2cOpen(i2cDev, i2cAddr, 0)
);
lgI2cOpen(i2cDev, i2cAddr, 0));
}
// オープン済みI2Cハンドルを閉じる
Value i2cClose(const CallbackInfo& info)
Value i2cClose(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 1)
@ -342,15 +335,14 @@ Value i2cClose(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
return Number::New(env,
lgI2cClose(handle)
);
lgI2cClose(handle));
}
// デバイスに1バイトを送る
Value i2cWriteByte(const CallbackInfo& info)
Value i2cWriteByte(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -365,15 +357,14 @@ Value i2cWriteByte(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int byteVal = info[1].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
int byteVal = info[1].As<Number>().Int32Value();
return Number::New(env,
lgI2cWriteByte(handle, byteVal)
);
}
lgI2cWriteByte(handle, byteVal));
}
// デバイスから1バイトを受け取る
Value i2cReadByte(const CallbackInfo& info)
Value i2cReadByte(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 1)
@ -388,16 +379,14 @@ Value i2cReadByte(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
return Number::New(env,
lgI2cReadByte(handle)
);
}
lgI2cReadByte(handle));
}
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタに1バイトを書き込む
Value i2cWriteByteData(const CallbackInfo& info)
Value i2cWriteByteData(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 3)
@ -412,17 +401,16 @@ Value i2cWriteByteData(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int i2cReg = info[1].As<Number>().DoubleValue();
unsigned int byteVal = info[2].As<Number>().DoubleValue();
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)
);
lgI2cWriteByteData(handle, i2cReg, byteVal));
}
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタから1バイトを読み込む
Value i2cReadByteData(const CallbackInfo& info)
Value i2cReadByteData(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -437,16 +425,46 @@ Value i2cReadByteData(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int i2cReg = info[1].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
int i2cReg = info[1].As<Number>().Int32Value();
return Number::New(env,
lgI2cReadByteData(handle, i2cReg)
);
lgI2cReadByteData(handle, i2cReg));
}
/*
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタからcountバイトを読み込む。countは132。
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();
auto rxBuf = Buffer<char>::New(env, count);
int rxCount = lgI2cReadI2CBlockData(handle, i2cReg, rxBuf.Data(), count);
Array returnArr = Array::New(env);
int i = 0;
returnArr[i] = Number::New(env, rxCount);
returnArr[++i] = rxBuf;
return returnArr;
}
// I2Cハンドルに関連付けられているデバイスの指定されたレジスタから単一の16ビットワードを読み取る
Value I2cReadWordData(const CallbackInfo& info)
Value I2cReadWordData(const CallbackInfo &info)
{
Env env = info.Env();
if (info.Length() < 2)
@ -461,14 +479,68 @@ Value I2cReadWordData(const CallbackInfo& info)
return env.Null();
}
unsigned int handle = info[0].As<Number>().DoubleValue();
unsigned int i2c_reg = info[1].As<Number>().DoubleValue();
int handle = info[0].As<Number>().Int32Value();
int i2cReg = info[1].As<Number>().Int32Value();
return Number::New(env,
i2c_read_word_data(pi, handle, i2c_reg)
);
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();
auto rxBuf = Buffer<char>::New(env, count);
int rxCount = lgI2cReadDevice(handle, rxBuf.Data(), count);
auto returnArr = Array::New(env);
int i = 0;
returnArr[i] = Number::New(env, rxCount);
returnArr[++i] = rxBuf;
return returnArr;
}
// 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)
{
@ -490,10 +562,12 @@ Init(Env env, Object exports)
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_word_data"), Function::New(env, I2cReadWordData));
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( ocoge_lgpio, Init )
NODE_API_MODULE(lgpio, Init)

View File

@ -1,5 +1,5 @@
{
"name": "ocoge_lgpio",
"name": "@ocogeclub/lgpio",
"version": "0.0.1",
"main": "index.js",
"private": true,
@ -8,4 +8,4 @@
"bindings": "^1.5.0",
"node-addon-api": "^1.7.1"
}
}
}

View File

@ -1,10 +0,0 @@
{ "targets":
[ { "target_name" : "ocoge_lgpio"
, "sources" : [ "ocoge_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" ]
}
]
}

View File

@ -1,8 +0,0 @@
module.exports = require('bindings')('ocoge_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;

17
package-lock.json generated
View File

@ -80,6 +80,16 @@
}
}
},
"@ocogeclub/bme280": {
"version": "file:local_modules/@ocogeclub/bme280"
},
"@ocogeclub/lgpio": {
"version": "file:local_modules/@ocogeclub/lgpio",
"requires": {
"bindings": "^1.5.0",
"node-addon-api": "^1.7.1"
}
},
"@sindresorhus/is": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
@ -1618,13 +1628,6 @@
"dev": true,
"optional": true
},
"ocoge_lgpio": {
"version": "file:local_modules/ocoge_lgpio",
"requires": {
"bindings": "^1.5.0",
"node-addon-api": "^1.7.1"
}
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",

View File

@ -24,8 +24,9 @@
},
"dependencies": {
"@electron/remote": "^1.2.1",
"@ocogeclub/bme280": "file:local_modules/@ocogeclub/bme280",
"@ocogeclub/lgpio": "file:local_modules/@ocogeclub/lgpio",
"axios": "^0.21.1",
"nodemailer": "^6.6.0",
"ocoge_lgpio": "file:local_modules/ocoge_lgpio"
"nodemailer": "^6.6.0"
}
}

View File

@ -1,272 +0,0 @@
#!/usr/bin/env python
import time
AUX_SPI=256
# Sampling
OVER_SAMPLE_1 = 1
OVER_SAMPLE_2 = 2
OVER_SAMPLE_4 = 3
OVER_SAMPLE_8 = 4
OVER_SAMPLE_16 = 5
class sensor:
"""
A class to read the BME280 pressure, humidity, and temperature sensor._
"""
# BME280 Registers
_calib00 = 0x88
_T1 = 0x88 - _calib00
_T2 = 0x8A - _calib00
_T3 = 0x8C - _calib00
_P1 = 0x8E - _calib00
_P2 = 0x90 - _calib00
_P3 = 0x92 - _calib00
_P4 = 0x94 - _calib00
_P5 = 0x96 - _calib00
_P6 = 0x98 - _calib00
_P7 = 0x9A - _calib00
_P8 = 0x9C - _calib00
_P9 = 0x9E - _calib00
_H1 = 0xA1 - _calib00
_chip_id = 0xD0
_reset = 0xE0
_calib26 = 0xE1
_H2 = 0xE1 - _calib26
_H3 = 0xE3 - _calib26
_xE4 = 0xE4 - _calib26
_xE5 = 0xE5 - _calib26
_xE6 = 0xE6 - _calib26
_H6 = 0xE7 - _calib26
_ctrl_hum = 0xF2
_status = 0xF3
_ctrl_meas = 0xF4
_config = 0xF5
_rawdata = 0xF7
_p_msb = 0xF7 - _rawdata
_p_lsb = 0xF8 - _rawdata
_p_xlsb = 0xF9 - _rawdata
_t_msb = 0xFA - _rawdata
_t_lsb = 0xFB - _rawdata
_t_xlsb = 0xFC - _rawdata
_h_msb = 0xFD - _rawdata
_h_lsb = 0xFE - _rawdata
_os_ms = [0, 1, 2, 4, 8, 16]
def __init__(self, pi, sampling=OVER_SAMPLE_1,
bus=1, address=0x76,
channel=0, baud=10000000, flags=0):
self.pi = pi
self.sampling = sampling
self.h = pi.i2c_open(bus, address)
self._load_calibration()
self.measure_delay = self._measurement_time(sampling, sampling, sampling)
self.t_fine = 0.0
def _measurement_time(self, os_temp, os_press, os_hum):
ms = ( (1.25 + 2.3 * sensor._os_ms[os_temp]) +
(0.575 + 2.3 * sensor._os_ms[os_press]) +
(0.575 + 2.3 * sensor._os_ms[os_hum]) )
return (ms/1000.0)
def _u16(self, _calib, off):
return (_calib[off] | (_calib[off+1]<<8))
def _s16(self, _calib, off):
v = self._u16(_calib, off)
if v > 32767:
v -= 65536
return v
def _u8(self, _calib, off):
return _calib[off]
def _s8(self, _calib, off):
v = self._u8(_calib,off)
if v > 127:
v -= 256
return v
def _write_registers(self, data):
self.pi.i2c_write_device(self.h, data)
def _read_registers(self, reg, count):
return self.pi.i2c_read_i2c_block_data(self.h, reg, count)
def _load_calibration(self):
c, d1 = self._read_registers(sensor._calib00, 26)
self.T1 = self._u16(d1, sensor._T1)
self.T2 = self._s16(d1, sensor._T2)
self.T3 = self._s16(d1, sensor._T3)
self.P1 = self._u16(d1, sensor._P1)
self.P2 = self._s16(d1, sensor._P2)
self.P3 = self._s16(d1, sensor._P3)
self.P4 = self._s16(d1, sensor._P4)
self.P5 = self._s16(d1, sensor._P5)
self.P6 = self._s16(d1, sensor._P6)
self.P7 = self._s16(d1, sensor._P7)
self.P8 = self._s16(d1, sensor._P8)
self.P9 = self._s16(d1, sensor._P9)
self.H1 = self._u8(d1, sensor._H1)
c, d2 = self._read_registers(sensor._calib26, 7)
self.H2 = self._s16(d2, sensor._H2)
self.H3 = self._u8(d2, sensor._H3)
t = self._u8(d2, sensor._xE5)
t_l = t & 15
t_h = (t >> 4) & 15
self.H4 = (self._u8(d2, sensor._xE4) << 4) | t_l
if self.H4 > 2047:
self.H4 -= 4096
self.H5 = (self._u8(d2, sensor._xE6) << 4) | t_h
if self.H5 > 2047:
self.H5 -= 4096
self.H6 = self._s8(d2, sensor._H6)
def _read_raw_data(self):
# Set oversampling rate and force reading.
self._write_registers(
[sensor._ctrl_hum, self.sampling,
sensor._ctrl_meas, self.sampling << 5 | self.sampling << 2 | 1])
# Measurement delay.
time.sleep(self.measure_delay)
# Grab reading.
c, d = self._read_registers(sensor._rawdata, 8)
msb = self._u8(d, sensor._t_msb)
lsb = self._u8(d, sensor._t_lsb)
xlsb = self._u8(d, sensor._t_xlsb)
raw_t = ((msb << 16) | (lsb << 8) | xlsb) >> 4
msb = self._u8(d, sensor._p_msb)
lsb = self._u8(d, sensor._p_lsb)
xlsb = self._u8(d, sensor._p_xlsb)
raw_p = ((msb << 16) | (lsb << 8) | xlsb) >> 4
msb = self._u8(d, sensor._h_msb)
lsb = self._u8(d, sensor._h_lsb)
raw_h = (msb << 8) | lsb
return raw_t, raw_p, raw_h
def read_data(self):
"""
Returns the temperature, pressure, and humidity as a tuple.
Each value is a float.
The temperature is returned in degrees centigrade. The
pressure is returned in Pascals. The humidity is returned
as the relative humidity between 0 and 100%.
"""
raw_t, raw_p, raw_h = self._read_raw_data()
var1 = (raw_t/16384.0 - (self.T1)/1024.0) * float(self.T2)
var2 = (((raw_t)/131072.0 - (self.T1)/8192.0) *
((raw_t)/131072.0 - (self.T1)/8192.0)) * (self.T3)
self.t_fine = var1 + var2
t = (var1 + var2) / 5120.0
var1 = (self.t_fine/2.0) - 64000.0
var2 = var1 * var1 * self.P6 / 32768.0
var2 = var2 + (var1 * self.P5 * 2.0)
var2 = (var2/4.0)+(self.P4 * 65536.0)
var1 = ((self.P3 * var1 * var1 / 524288.0) + (self.P2 * var1)) / 524288.0
var1 = (1.0 + var1 / 32768.0)*self.P1
if var1 != 0.0:
p = 1048576.0 - raw_p
p = (p - (var2 / 4096.0)) * 6250.0 / var1
var1 = self.P9 * p * p / 2147483648.0
var2 = p * self.P8 / 32768.0
p = p + (var1 + var2 + self.P7) / 16.0
else:
p = 0
h = self.t_fine - 76800.0
h = ( (raw_h - ((self.H4) * 64.0 + (self.H5) / 16384.0 * h)) *
((self.H2) / 65536.0 * (1.0 + (self.H6) / 67108864.0 * h *
(1.0 + (self.H3) / 67108864.0 * h))))
h = h * (1.0 - self.H1 * h / 524288.0)
if h > 100.0:
h = 100.0
elif h < 0.0:
h = 0.0
return t, p, h
def cancel(self):
"""
Cancels the sensor and releases resources.
"""
if self.h is not None:
self.pi.i2c_close(self.h)
self.h = None
if __name__ == "__main__":
# import time
import BME280
import pigpio
pi = pigpio.pi()
if not pi.connected:
exit(0)
s = BME280.sensor(pi)
t, p, h = s.read_data()
print("h={:.2f} p={:.1f} t={:.2f}".format(h, p/100.0, t), flush=True)
# stop = time.time() + 60
# while stop > time.time():
# t, p, h = s.read_data()
# print("h={:.2f} p={:.1f} t={:.2f}".format(h, p/100.0, t))
# time.sleep(0.9)
s.cancel()
pi.stop()

View File

@ -1,14 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import sys
for i in range(10,0,-1):
# print (i, flush=True) # flush=True を指定することで、バッファが無効になる
print i
sys.stdout.flush() # python2.x
time.sleep(1)
# print ('終了 - Python test')
print '終了 - Python test'

View File

@ -1,5 +1,3 @@
const ugj_const = require('./ugj_const');
/** Fix Basic Blocks ****************************************************************************************/
var ugjConsrolForDefinition = {
"type": "ugj_control_for",
@ -8,7 +6,7 @@ var ugjConsrolForDefinition = {
{
"type": "field_variable",
"name": "index",
"variable": "番号"
"variable": "%{BKY_UGJ_CONTROL_FOR_INDEX}"
},
{
"type": "input_dummy"
@ -28,6 +26,20 @@ var ugjConsrolForDefinition = {
"name": "by",
"check": "Number"
},
{
"type": "field_dropdown",
"name": "crease",
"options": [
[
"%{BKY_UGJ_CONTROL_FOR_INCREASE}",
"+"
],
[
"%{BKY_UGJ_CONTROL_FOR_DECREASE}",
"-"
]
]
},
{
"type": "input_dummy"
},
@ -39,26 +51,27 @@ var ugjConsrolForDefinition = {
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"style": "loop_blocks",
"tooltip": "%{BKY_UGJ_CONTROL_FOR_TOOLTIP}",
"helpUrl": ""
}
"helpUrl": "",
"style": "loop_blocks"
};
Blockly.Blocks['ugj_control_for'] = {
init: function () {
this.jsonInit(ugjConsrolForDefinition);
}
};
Blockly.JavaScript['ugj_control_for'] = function (block) {
var variable_index = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('index'), Blockly.Variables.NAME_TYPE);
var variable_index = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('index'), Blockly.Variables.NAME_TYPE);
var value_from = Blockly.JavaScript.valueToCode(block, 'from', Blockly.JavaScript.ORDER_ATOMIC);
var value_to = Blockly.JavaScript.valueToCode(block, 'to', Blockly.JavaScript.ORDER_ATOMIC);
var value_by = Blockly.JavaScript.valueToCode(block, 'by', Blockly.JavaScript.ORDER_NONE);
var value_by = Blockly.JavaScript.valueToCode(block, 'by', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_crease = block.getFieldValue('crease');
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
let daishou, tasuhiku;
if (value_from < value_to) { daishou = '<'; tasuhiku = '+'; }
else { daishou = '>'; tasuhiku = '-'; }
let daishou;
if (dropdown_crease == '+') { daishou = '<'; }
else { daishou = '>'; }
var code = [
`for (${variable_index} = ${value_from}; ${variable_index} ${daishou}= ${value_to}; ${variable_index} ${tasuhiku}= ${Math.abs(value_by)}) {`,
`for (${variable_index} = ${value_from}; ${variable_index} ${daishou}= ${value_to}; ${variable_index} ${dropdown_crease}= ${Math.abs(value_by)}) {`,
statements_do,
`}`,
''
@ -66,13 +79,14 @@ Blockly.JavaScript['ugj_control_for'] = function (block) {
return code;
};
Blockly.Python['ugj_control_for'] = function (block) {
var variable_index = Blockly.Python.variableDB_.getName(block.getFieldValue('index'), Blockly.Variables.NAME_TYPE);
var variable_index = Blockly.Python.nameDB_.getName(block.getFieldValue('index'), Blockly.Variables.NAME_TYPE);
var value_from = Blockly.Python.valueToCode(block, 'from', Blockly.Python.ORDER_ATOMIC);
var value_to = Blockly.Python.valueToCode(block, 'to', Blockly.Python.ORDER_ATOMIC);
var value_by = Blockly.Python.valueToCode(block, 'by', Blockly.Python.ORDER_NONE);
var value_by = Blockly.Python.valueToCode(block, 'by', Blockly.Python.ORDER_ATOMIC);
var dropdown_crease = block.getFieldValue('crease');
var statements_do = Blockly.Python.statementToCode(block, 'do');
if (statements_do === '') statements_do = ' pass';
if (value_from < value_to) { value_by = Math.abs(value_by); value_to++; }
if (dropdown_crease == '+') { value_by = Math.abs(value_by); value_to++; }
else { value_by = Math.abs(value_by) * (-1); value_to--; }
var code = [
`for ${variable_index} in range(${value_from}, ${value_to}, ${value_by}) :`,
@ -118,7 +132,7 @@ Blockly.Blocks['ugj_controls_forEach'] = {
};
Blockly.JavaScript['ugj_controls_forEach'] = function (block) {
var value_list = Blockly.JavaScript.valueToCode(block, 'list', Blockly.JavaScript.ORDER_ATOMIC);
var variable_item = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE);
var variable_item = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
`for (let i_index in ${value_list}) {`,
@ -131,7 +145,7 @@ Blockly.JavaScript['ugj_controls_forEach'] = function (block) {
};
Blockly.Python['ugj_controls_forEach'] = function (block) {
var value_list = Blockly.Python.valueToCode(block, 'list', Blockly.Python.ORDER_ATOMIC);
var variable_item = Blockly.Python.variableDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE);
var variable_item = Blockly.Python.nameDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.Python.statementToCode(block, 'do');
if (value_list === '') value_list = '[]';
if (statements_do === '') statements_do = ' pass';
@ -165,12 +179,12 @@ Blockly.Blocks['ugj_codechar'] = {
this.jsonInit(ugjCodecharDefinition);
}
};
Blockly.JavaScript['ugj_codechar'] = function(block) {
Blockly.JavaScript['ugj_codechar'] = function (block) {
var value_code = Blockly.JavaScript.valueToCode(block, 'code', Blockly.JavaScript.ORDER_ATOMIC);
var code = `String.fromCharCode(${value_code})`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
Blockly.Python['ugj_codechar'] = function(block) {
Blockly.Python['ugj_codechar'] = function (block) {
var value_code = Blockly.Python.valueToCode(block, 'code', Blockly.Python.ORDER_ATOMIC);
var code = `chr(${value_code})`;
return [code, Blockly.Python.ORDER_NONE];
@ -197,12 +211,12 @@ Blockly.Blocks['ugj_charcode'] = {
this.jsonInit(ugjCharcodeDefinition);
}
};
Blockly.JavaScript['ugj_charcode'] = function(block) {
Blockly.JavaScript['ugj_charcode'] = function (block) {
var value_char = Blockly.JavaScript.valueToCode(block, 'char', Blockly.JavaScript.ORDER_ATOMIC);
var code = `${value_char}.charCodeAt(0)`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
Blockly.Python['ugj_charcode'] = function(block) {
Blockly.Python['ugj_charcode'] = function (block) {
var value_char = Blockly.Python.valueToCode(block, 'char', Blockly.Python.ORDER_ATOMIC);
var code = `ord(${value_char})`;
return [code, Blockly.Python.ORDER_NONE];
@ -235,7 +249,7 @@ Blockly.JavaScript['ugj_hextodec'] = function (block) {
var code = `parseInt (${value_hex}, 16)`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
Blockly.Python['ugj_hextodec'] = function(block) {
Blockly.Python['ugj_hextodec'] = function (block) {
var value_hex = Blockly.Python.valueToCode(block, 'hex', Blockly.Python.ORDER_ATOMIC);
var code = `int(${value_hex}, 16)`;
return [code, Blockly.Python.ORDER_NONE];
@ -262,12 +276,12 @@ Blockly.Blocks['ugj_dectohex'] = {
this.jsonInit(ugjDectohexDefinition);
}
};
Blockly.JavaScript['ugj_dectohex'] = function(block) {
Blockly.JavaScript['ugj_dectohex'] = function (block) {
var value_dec = Blockly.JavaScript.valueToCode(block, 'dec', Blockly.JavaScript.ORDER_ATOMIC);
var code = `'0x' + (${value_dec}).toString(16).toUpperCase()`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
Blockly.Python['ugj_dectohex'] = function(block) {
Blockly.Python['ugj_dectohex'] = function (block) {
var value_dec = Blockly.Python.valueToCode(block, 'dec', Blockly.Python.ORDER_ATOMIC);
var code = `'0x' + format(${value_dec}, 'X')`;
return [code, Blockly.Python.ORDER_NONE];
@ -293,15 +307,15 @@ Blockly.Blocks['ugj_gpiochip_open'] = {
};
Blockly.JavaScript['ugj_gpiochip_open'] = function (block) {
Blockly.JavaScript.provideFunction_(
'require_oclg', [`const pi = require('ocoge_lgpio');\n`]
)
'require_oclg', [`const pi = require('@ocogeclub/lgpio');`]
);
var code = `var lgHand = pi.gpiochip_open(0);\n`; //
return code;
};
Blockly.Python['ugj_gpiochip_open'] = function (block) {
Blockly.Python.provideFunction_(
'import_lgpio', ['import lgpio as pi']
)
);
var code = `lgHand = pi.gpiochip_open(0)\n`; //
return code;
};
@ -589,14 +603,14 @@ Blockly.Blocks['ugj_tx_pwm'] = {
this.jsonInit(ugjTxPwmDefinition);
}
};
Blockly.JavaScript['ugj_tx_pwm'] = function(block) {
Blockly.JavaScript['ugj_tx_pwm'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var value_pwm_frequency = Blockly.JavaScript.valueToCode(block, 'pwm_frequency', Blockly.JavaScript.ORDER_ATOMIC);
var value_pwm_duty_cycle = Blockly.JavaScript.valueToCode(block, 'pwm_duty_cycle', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.tx_pwm(lgHand, ${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle});\n`;
return code;
};
Blockly.Python['ugj_tx_pwm'] = function(block) {
Blockly.Python['ugj_tx_pwm'] = function (block) {
var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC);
var value_pwm_frequency = Blockly.Python.valueToCode(block, 'pwm_frequency', Blockly.Python.ORDER_ATOMIC);
var value_pwm_duty_cycle = Blockly.Python.valueToCode(block, 'pwm_duty_cycle', Blockly.Python.ORDER_ATOMIC);
@ -649,12 +663,18 @@ Blockly.Blocks['ugj_serial_open'] = {
Blockly.JavaScript['ugj_serial_open'] = function (block) {
var value_tty = Blockly.JavaScript.valueToCode(block, 'tty', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_baud = block.getFieldValue('baud');
Blockly.JavaScript.provideFunction_(
'require_oclg', [`const pi = require('@ocogeclub/lgpio');`]
);
var code = `let ser_hand = pi.serial_open(${value_tty}, ${dropdown_baud}, 0);\n`;
return code;
};
Blockly.Python['ugj_serial_open'] = function (block) {
var value_tty = Blockly.Python.valueToCode(block, 'tty', Blockly.Python.ORDER_ATOMIC);
var dropdown_baud = block.getFieldValue('baud');
Blockly.Python.provideFunction_(
'import_lgpio', ['import lgpio as pi']
);
var code = `ser_hand = pi.serial_open(${value_tty}, ${dropdown_baud}, 0)\n`;
return code;
};
@ -712,12 +732,12 @@ Blockly.Blocks['ugj_serial_write'] = {
};
Blockly.JavaScript['ugj_serial_write'] = function (block) {
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.serial_write(ser_hand, ${value_data});\n`;
var code = `pi.serial_write(ser_hand, Buffer.from(${value_data}));\n`;
return code;
};
Blockly.Python['ugj_serial_write'] = function (block) {
var value_data = Blockly.Python.valueToCode(block, 'data', Blockly.Python.ORDER_ATOMIC);
var code = `pi.serial_write(ser_hand, ${value_data})\n`;
var code = `pi.serial_write(ser_hand, ${value_data}.encode())\n`;
return code;
};
@ -747,13 +767,31 @@ Blockly.Blocks['ugj_serial_read'] = {
};
Blockly.JavaScript['ugj_serial_read'] = function (block) {
var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.serial_read(ser_hand, ${value_count})\n`;
return [code, Blockly.JavaScript.ORDER_NONE];
var functionName = Blockly.JavaScript.provideFunction_(
'ugj_serial_read',
[
'const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = ser_hand => {',
`[count, data] = pi.serial_read(ser_hand, ${value_count});`,
`return data.toString('utf8', 0, count);`,
'}'
]
);
var code = `${functionName}(ser_hand)`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
Blockly.Python['ugj_serial_read'] = function (block) {
var value_count = Blockly.Python.valueToCode(block, 'count', Blockly.Python.ORDER_ATOMIC);
var code = `pi.serial_read(ser_hand, ${value_count})\n`;
return [code, Blockly.Python.ORDER_NONE];
var functionName = Blockly.Python.provideFunction_(
'ugj_serial_read',
[
'def ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '(ser_hand) :',
` (count, data) = pi.serial_read(ser_hand, ${value_count})`,
` return data[0:count].decode()`,
''
]
);
var code = `${functionName}(ser_hand)`;
return [code, Blockly.Python.ORDER_ATOMIC];
};
/********************* */
@ -783,11 +821,17 @@ Blockly.Blocks['ugj_i2c_open'] = {
};
Blockly.JavaScript['ugj_i2c_open'] = function (block) {
var value_i2c_address = Blockly.JavaScript.valueToCode(block, 'i2c_address', Blockly.JavaScript.ORDER_ATOMIC);
Blockly.JavaScript.provideFunction_(
'require_oclg', [`const pi = require('@ocogeclub/lgpio');`]
);
var code = `let i2c_hand = pi.i2c_open(1, ${value_i2c_address});\n`;
return code;
};
Blockly.Python['ugj_i2c_open'] = function (block) {
var value_i2c_address = Blockly.Python.valueToCode(block, 'i2c_address', Blockly.Python.ORDER_ATOMIC);
Blockly.Python.provideFunction_(
'import_lgpio', ['import lgpio as pi']
);
var code = `i2c_hand = pi.i2c_open(1, ${value_i2c_address})\n`;
return code;
};
@ -818,68 +862,6 @@ Blockly.Python['ugj_i2c_close'] = function (block) {
return code;
};
/**************************************** */
/** Sends a single byte to the device. ** */
/**************************************** */
var ugjI2cWriteByteDefinition = {
"type": "ugj_i2c_write_byte",
"message0": "%{BKY_I2C_WRITE_BYTE_TITLE}",
"args0": [
{
"type": "input_value",
"name": "byte_val",
"check": "Number"
}
],
"previousStatement": null,
"nextStatement": null,
"tooltip": "%{BKY_I2C_WRITE_BYTE_TOOLTIP}",
"helpUrl": "",
"style": "gpio_blocks"
};
Blockly.Blocks['ugj_i2c_write_byte'] = {
init: function () {
this.jsonInit(ugjI2cWriteByteDefinition);
}
};
Blockly.JavaScript['ugj_i2c_write_byte'] = function(block) {
var value_byte_val = Blockly.JavaScript.valueToCode(block, 'byte_val', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.i2c_write_byte(i2c_hand, ${value_byte_val});\n`;
return code;
};
Blockly.Python['ugj_i2c_write_byte'] = function(block) {
var value_byte_val = Blockly.Python.valueToCode(block, 'byte_val', Blockly.Python.ORDER_ATOMIC);
var code = `pi.i2c_write_byte(i2c_hand, ${value_byte_val});\n`;
return code;
};
/*************************************** */
/** Reads a single byte from the device. */
/*************************************** */
var ugjI2cReadByteDefinition = {
"type": "ugj_i2c_read_byte",
"message0": "%{BKY_I2C_READ_BYTE_TITLE}",
"inputsInline": true,
"output": "Number",
"tooltip": "%{BKY_I2C_READ_BYTE_TOOLTIP}",
"helpUrl": "",
"style": "gpio_blocks"
};
Blockly.Blocks['ugj_i2c_read_byte'] = {
init: function () {
this.jsonInit(ugjI2cReadByteDefinition);
}
};
Blockly.JavaScript['ugj_i2c_read_byte'] = function(block) {
var code = `pi.i2c_read_byte(i2c_hand)`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
Blockly.Python['ugj_i2c_read_byte'] = function(block) {
var code = `pi.i2c_read_byte(i2c_hand)`;
return [code, Blockly.Python.ORDER_NONE];
};
/****************************************************************** */
/** Writes a single byte to the specified register of the device ** */
/****************************************************************** */
@ -950,14 +932,186 @@ Blockly.Blocks['ugj_i2c_read_byte_data'] = {
Blockly.JavaScript['ugj_i2c_read_byte_data'] = function (block) {
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.i2c_read_byte_data(i2c_hand, ${value_reg})\n`;
return [code, Blockly.JavaScript.ORDER_NONE];
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
Blockly.Python['ugj_i2c_read_byte_data'] = function (block) {
var value_reg = Blockly.Python.valueToCode(block, 'reg', Blockly.Python.ORDER_ATOMIC);
var code = `pi.i2c_read_byte_data(i2c_hand, ${value_reg})\n`;
return [code, Blockly.Python.ORDER_NONE];
return [code, Blockly.Python.ORDER_ATOMIC];
};
/************************************************************************** */
/** Returns count bytes read from the raw device associated with handle. ** */
/************************************************************************** */
var ugjI2cReadDeviceDefinition = {
"type": "ugj_i2c_read_device",
"message0": "%{BKY_I2C_READ_DEVICE_TITLE}",
"args0": [
{
"type": "input_value",
"name": "count",
"check": "Number"
}
],
"inputsInline": true,
"output": null,
"tooltip": "%{BKY_I2C_READ_DEVICE_TOOLTIP}",
"helpUrl": "",
"style": "gpio_blocks"
};
Blockly.Blocks['ugj_i2c_read_device'] = {
init: function () {
this.jsonInit(ugjI2cReadDeviceDefinition);
}
};
Blockly.JavaScript['ugj_i2c_read_device'] = function (block) {
var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC);
var functionName = Blockly.JavaScript.provideFunction_(
'ugj_i2c_read_device',
[
'const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = i2c_hand => {',
`[count, data] = pi.i2c_read_device(i2c_hand, ${value_count});`,
`return data.toString('utf8', 0, count);`,
'}'
]
);
var code = `${functionName}(i2c_hand)`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
Blockly.Python['ugj_i2c_read_device'] = function (block) {
var value_count = Blockly.Python.valueToCode(block, 'count', Blockly.Python.ORDER_ATOMIC);
var functionName = Blockly.Python.provideFunction_(
'ugj_i2c_read_device',
[
'def ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '(i2c_hand) :',
` (count, data) = pi.i2c_read_device(i2c_hand, ${value_count})`,
` return data[0:count].decode()`,
''
]
);
var code = `${functionName}(i2c_hand)`;
return [code, Blockly.Python.ORDER_ATOMIC];
};
/********************************************** */
/** Writes the data bytes to the raw device. ** */
/********************************************** */
var ugjI2cWriteDeviceDefinition = {
"type": "ugj_i2c_write_device",
"message0": "%{BKY_I2C_WRITE_DEVICE_TITLE}",
"args0": [
{
"type": "input_value",
"name": "data",
"check": "String"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"tooltip": "%{BKY_I2C_WRITE_DEVICE_TOOLTIP}",
"helpUrl": "",
"style": "gpio_blocks"
};
Blockly.Blocks['ugj_i2c_write_device'] = {
init: function () {
this.jsonInit(ugjI2cWriteDeviceDefinition);
}
};
Blockly.JavaScript['ugj_i2c_write_device'] = function (block) {
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
var code = `pi.i2c_write_device(i2c_hand, Buffer.from(${value_data}))\n`;
return code;
};
Blockly.Python['ugj_i2c_write_device'] = function (block) {
var value_data = Blockly.Python.valueToCode(block, 'data', Blockly.Python.ORDER_ATOMIC);
var code = `pi.i2c_write_device(i2c_hand, ${value_data}.encode())\n`;
return code;
};
/** センサー */
/********* */
/** BME280 */
/********* */
var ugjBme280Definition = {
"type": "ugj_bme280",
"message0": "%{BKY_UGJ_BME280_TITLE}",
"args0": [
{
"type": "input_value",
"name": "address",
"check": "Number"
},
{
"type": "field_variable",
"name": "temp",
"variable": "%{BKY_UGJ_BME280_READ_TEMP}"
},
{
"type": "field_variable",
"name": "hum",
"variable": "%{BKY_UGJ_BME280_READ_HUM}"
},
{
"type": "field_variable",
"name": "pres",
"variable": "%{BKY_UGJ_BME280_READ_PRES}"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"tooltip": "%{BKY_UGJ_BME280_TOOLTIP}",
"helpUrl": "",
"style": "gpio_blocks"
};
Blockly.Blocks['ugj_bme280'] = {
init: function () {
this.jsonInit(ugjBme280Definition);
}
};
Blockly.JavaScript['ugj_bme280'] = function (block) {
var value_address = Blockly.JavaScript.valueToCode(block, 'address', Blockly.JavaScript.ORDER_ATOMIC);
var variable_temp = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('temp'), Blockly.Variables.NAME_TYPE);
var variable_hum = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('hum'), Blockly.Variables.NAME_TYPE);
var variable_pres = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('pres'), Blockly.Variables.NAME_TYPE);
Blockly.JavaScript.provideFunction_(
'require_bme280', [`const BME280 = require('@ocogeclub/bme280');`]
);
var code = [
`const options = {`,
` i2cBusNo: 1,`,
` i2cAddress: ${value_address}`,
`};`,
`const bme280 = new BME280(options);`,
`bme280.init();`,
`let thp = bme280.readSensorData();`,
`${variable_temp} = Math.round(thp.temperature_C * 10) / 10;`,
`${variable_hum} = Math.round(thp.humidity * 10) / 10;`,
`${variable_pres} = Math.round(thp.pressure_hPa);`,
`bme280.cancel();`,
``
].join('\n');
return code;
};
Blockly.Python['ugj_bme280'] = function (block) {
var value_address = Blockly.Python.valueToCode(block, 'address', Blockly.Python.ORDER_ATOMIC);
var variable_temp = Blockly.Python.nameDB_.getName(block.getFieldValue('temp'), Blockly.Variables.NAME_TYPE);
var variable_hum = Blockly.Python.nameDB_.getName(block.getFieldValue('hum'), Blockly.Variables.NAME_TYPE);
var variable_pres = Blockly.Python.nameDB_.getName(block.getFieldValue('pres'), Blockly.Variables.NAME_TYPE);
Blockly.Python.provideFunction_(
'import_bme280', [`import BME280`]
);
var code = [
`bme280 = BME280.sensor()`,
`temp, pres, hum = bme280.read_data()`,
`${variable_temp} = round(temp, 1)`,
`${variable_hum} = round(hum, 1)`,
`${variable_pres} = round(pres/100);`,
`bme280.cancel()`,
``
].join('\n');
return code;
};
/** Multimedia *****************************************************************************************************/
@ -975,7 +1129,7 @@ Blockly.Blocks['ugj_library_tensorflow'] = {
}
};
Blockly.JavaScript['ugj_library_tensorflow'] = function (block) {
var code = `'./scripts/tensorflow.min.js'`;
var code = `'${ugj_const.library_path}tensorflow.min.js'`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
/********************** */
@ -1021,7 +1175,7 @@ Blockly.Blocks['ugj_tfpredict_loadmodel'] = {
};
Blockly.JavaScript['ugj_tfpredict_loadmodel'] = function (block) {
var code = [
"const model = await tf.loadModel('./scripts/sign_language_vgg16/model.json');",
`const model = await tf.loadModel('${ugj_const.library_path}sign_language_vgg16/model.json');`,
"const CLASSES = {0:'zero', 1:'one', 2:'two', 3:'three', 4:'four',5:'five', 6:'six', 7:'seven', 8:'eight', 9:'nine'};",
""
].join('\n');
@ -1042,7 +1196,7 @@ Blockly.Blocks['ugj_tfpredict_predict'] = {
}
};
Blockly.JavaScript['ugj_tfpredict_predict'] = function (block) {
var variable_result = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('result'), Blockly.Variables.NAME_TYPE);
var variable_result = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('result'), Blockly.Variables.NAME_TYPE);
var code = [
"context.drawImage(video, 0, 0, video.width, video.height);",
"let tensor = tf.fromPixels(canvas).resizeNearestNeighbor([100,100]).toFloat();",
@ -1083,7 +1237,7 @@ Blockly.Blocks['ugj_face_library'] = {
}
};
Blockly.JavaScript['ugj_face_library'] = function (block) {
var code = `'./scripts/face-api.js'`;
var code = `'${ugj_const.library_path}face-api.js'`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
Blockly.Blocks['ugj_face_init'] = {
@ -1150,13 +1304,13 @@ Blockly.Blocks['ugj_face_detect'] = {
}
};
Blockly.JavaScript['ugj_face_detect'] = function (block) {
var variable_x = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('x'), Blockly.Variables.NAME_TYPE);
var variable_y = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('y'), Blockly.Variables.NAME_TYPE);
var variable_w = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('w'), Blockly.Variables.NAME_TYPE);
var variable_h = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('h'), Blockly.Variables.NAME_TYPE);
var variable_x = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('x'), Blockly.Variables.NAME_TYPE);
var variable_y = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('y'), Blockly.Variables.NAME_TYPE);
var variable_w = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('w'), Blockly.Variables.NAME_TYPE);
var variable_h = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('h'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
"await faceapi.loadTinyFaceDetectorModel('./scripts/models/');",
`await faceapi.loadTinyFaceDetectorModel('${ugj_const.library_path}models/');`,
"const options = new faceapi.TinyFaceDetectorOptions({ inputSize: 128, scoreThreshold : 0.3 });",
"videoEl.onplay = onPlay;",
"async function onPlay() {",
@ -1210,7 +1364,7 @@ Blockly.JavaScript['ugj_face_drawrect'] = function (block) {
Blockly.Blocks['ugj_canvas_say'] = {
init: function () {
this.appendValueInput("say")
.setCheck("String");
.setCheck(null);
this.appendValueInput("sec")
.setCheck("Number")
.appendField("と");
@ -1228,11 +1382,17 @@ Blockly.JavaScript['ugj_canvas_say'] = function (block) {
var value_say = Blockly.JavaScript.valueToCode(block, 'say', Blockly.JavaScript.ORDER_ATOMIC);
var value_sec = Blockly.JavaScript.valueToCode(block, 'sec', Blockly.JavaScript.ORDER_ATOMIC);
var code = [
`ugj_fukidashi(${value_say}, ${value_sec});`,
`ugj_fukidashi(String(${value_say}), ${value_sec});`,
''
].join('\n');
return code;
};
Blockly.Python['ugj_canvas_say'] = function (block) {
var value_say = Blockly.Python.valueToCode(block, 'say', Blockly.Python.ORDER_ATOMIC);
var value_sec = Blockly.Python.valueToCode(block, 'sec', Blockly.Python.ORDER_ATOMIC);
var code = `print(${value_say})\n`;
return code;
};
/*************************** */
/** Canvas Initialization ** */
@ -1507,7 +1667,7 @@ Blockly.Blocks['ugj_event_key'] = {
}
};
Blockly.JavaScript['ugj_event_key'] = function (block) {
var variable_key = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('key'), Blockly.Variables.NAME_TYPE);
var variable_key = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('key'), Blockly.Variables.NAME_TYPE);
var dropdown_updown = block.getFieldValue('updown');
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
@ -1574,7 +1734,7 @@ Blockly.Blocks['ugj_multimedia_webspeech_recognition'] = {
}
};
Blockly.JavaScript['ugj_multimedia_webspeech_recognition'] = function (block) {
var variable_transcript = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('transcript'), Blockly.Variables.NAME_TYPE);
var variable_transcript = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('transcript'), Blockly.Variables.NAME_TYPE);
var dropdown_continuous = block.getFieldValue('continuous');
var checkbox_interim = block.getFieldValue('interim') == 'TRUE';
var statements_isfinal_do = Blockly.JavaScript.statementToCode(block, 'isFinal_do');
@ -1644,8 +1804,11 @@ Blockly.JavaScript['ugj_socket'] = function (block) {
var value_host = Blockly.JavaScript.valueToCode(block, 'host', Blockly.JavaScript.ORDER_ATOMIC);
var value_port = Blockly.JavaScript.valueToCode(block, 'port', Blockly.JavaScript.ORDER_ATOMIC);
var statements_connect = Blockly.JavaScript.statementToCode(block, 'connect');
var variable_data = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var statements_data = Blockly.JavaScript.statementToCode(block, 'data');
Blockly.JavaScript.provideFunction_(
'require_net', [`const net = require('net');`]
);
var code = [
`var client = net.connect(${value_port}, ${value_host});`,
`client.on('connect', async ()=>{`,
@ -1711,9 +1874,12 @@ Blockly.Blocks['ugj_network_httpserver'] = {
}
};
Blockly.JavaScript['ugj_network_httpserver'] = function (block) {
var variable_url = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('URL'), Blockly.Variables.NAME_TYPE);
var variable_url = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('URL'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var value_response = Blockly.JavaScript.valueToCode(block, 'response', Blockly.JavaScript.ORDER_ATOMIC);
Blockly.JavaScript.provideFunction_(
'require_http', [`const http = require('http');`]
);
var code = [
`let req, res;`,
`http.createServer(async (req, res) => {`,
@ -1752,6 +1918,7 @@ Blockly.JavaScript['ugj_network_axios_geturl'] = function (block) {
var functionName = Blockly.JavaScript.provideFunction_(
'getUrl',
[
`const axios = require('axios');`,
'const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = async url => {',
'let res, ret;',
'try {',
@ -1797,6 +1964,9 @@ Blockly.JavaScript['ugj_network_sendmail'] = function (block) {
var value_to = Blockly.JavaScript.valueToCode(block, 'to', Blockly.JavaScript.ORDER_ATOMIC);
var value_subject = Blockly.JavaScript.valueToCode(block, 'subject', Blockly.JavaScript.ORDER_ATOMIC);
var value_text = Blockly.JavaScript.valueToCode(block, 'text', Blockly.JavaScript.ORDER_ATOMIC);
Blockly.JavaScript.provideFunction_(
'require_sendmail', [`const nodemailer = require('nodemailer');`]
);
var code = [
`let smtp = nodemailer.createTransport({`,
`host: '192.168.0.201',`,
@ -1839,7 +2009,7 @@ Blockly.Blocks['ugj_library_skyway'] = {
}
};
Blockly.JavaScript['ugj_library_skyway'] = function (block) {
var code = `'./scripts/skyway.js'`;
var code = `'${ugj_const.library_path}skyway.js'`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
@ -1921,7 +2091,7 @@ Blockly.Blocks['ugj_skyway_newpeer'] = {
}
};
Blockly.JavaScript['ugj_skyway_newpeer'] = function (block) {
var variable_my_id = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('my_id'), Blockly.Variables.NAME_TYPE);
var variable_my_id = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('my_id'), Blockly.Variables.NAME_TYPE);
// var text_name = block.getFieldValue('NAME');
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
@ -1991,7 +2161,7 @@ Blockly.Blocks['ugj_skyway_events'] = {
}
};
Blockly.JavaScript['ugj_skyway_events'] = function (block) {
var variable_remote_id = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('remote_id'), Blockly.Variables.NAME_TYPE);
var variable_remote_id = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('remote_id'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
"const setupCallEventHandlers = call => call.on('stream', stream => remoteVideo.srcObject = stream);",
@ -2048,7 +2218,7 @@ Blockly.Blocks['ugj_skyway_eventdata'] = {
}
};
Blockly.JavaScript['ugj_skyway_eventdata'] = function (block) {
var variable_data = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
" connect.on('data', data => {",
@ -2077,7 +2247,7 @@ Blockly.Blocks['ugj_skyway_eventsend'] = {
}
};
Blockly.JavaScript['ugj_skyway_eventsend'] = function (block) {
var variable_data = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
" const onSendMsg = () => {",
@ -2118,6 +2288,9 @@ Blockly.JavaScript['ugj_file_readsync'] = function (block) {
var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC);
var dropdown_encoding = block.getFieldValue('encoding');
let filepath = ugj_const.doc_root + value_filename.replace(/\'/g, '');
Blockly.JavaScript.provideFunction_(
'require_fs', [`const fs = require('fs');`]
);
var code = `fs.readFileSync('${filepath}', '${dropdown_encoding}')`;
return [code, Blockly.JavaScript.ORDER_ATOMIC];
};
@ -2226,7 +2399,7 @@ Blockly.Blocks['ugj_event_answer'] = {
};
Blockly.JavaScript['ugj_event_answer'] = function (block) {
var value_question = Blockly.JavaScript.valueToCode(block, 'question', Blockly.JavaScript.ORDER_ATOMIC);
var variable_answer = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('answer'), Blockly.Variables.NAME_TYPE);
var variable_answer = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('answer'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
`ugj_fukidashi(${value_question}, 0);`,
@ -2273,7 +2446,7 @@ Blockly.Blocks['ugj_spawnsync'] = {
};
Blockly.JavaScript['ugj_spawnsync'] = function (block) {
var value_childprocess = Blockly.JavaScript.valueToCode(block, 'childprocess', Blockly.JavaScript.ORDER_NONE);
var variable_data = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var code = `${variable_data} = require('child_process').spawnSync(${value_childprocess}).stdout.toString();\n`;
// var code = `${variable_data} = require('child_process').execFileSync(${value_childprocess});\n`;
return code;
@ -2303,7 +2476,7 @@ Blockly.Blocks['ugj_spawn'] = {
};
Blockly.JavaScript['ugj_spawn'] = function (block) {
var value_childprocess = Blockly.JavaScript.valueToCode(block, 'childprocess', Blockly.JavaScript.ORDER_NONE);
var variable_data = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
`let child = require('child_process').spawn(${value_childprocess});`,
@ -2336,7 +2509,7 @@ Blockly.Blocks['ugj_child_gesture'] = {
}
};
Blockly.JavaScript['ugj_child_gesture'] = function (block) {
var code = `'python3', ['./scripts/gesture.py']`;
var code = `'python3', ['${ugj_const.library_path}gesture.py']`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
@ -2357,7 +2530,7 @@ Blockly.Blocks['aquestalk_pi'] = {
};
Blockly.JavaScript['aquestalk_pi'] = function (block) {
var value_talk = Blockly.JavaScript.valueToCode(block, 'talk', Blockly.JavaScript.ORDER_ATOMIC);
var code = `'./bin/aquestalkpi/AquesTalkPi -g 50 ' + ${value_talk} + ' | aplay', { shell: true }`;
var code = `'${ugj_const.executable_path}aquestalkpi/AquesTalkPi -g 50 ' + ${value_talk} + ' | aplay', { shell: true }`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
@ -2384,7 +2557,7 @@ Blockly.JavaScript['ugj_child_openjtalk'] = function (block) {
// 'fixText',
// ['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = text => {return text;}']
// );
var code = `'echo ' + ${value_talk} + ' | ./bin/open_jtalk/open_jtalk -m ./bin/open_jtalk/htsvoices/${dropdown_voice}.htsvoice -x ./bin/open_jtalk/open_jtalk_dic_utf_8-1.11 -ow /dev/stdout | aplay --quiet', { shell: true }`;
var code = `'echo ' + ${value_talk} + ' | ${ugj_const.executable_path}open_jtalk/open_jtalk -m ${ugj_const.executable_path}open_jtalk/htsvoices/${dropdown_voice}.htsvoice -x ${ugj_const.executable_path}open_jtalk/open_jtalk_dic_utf_8-1.11 -ow /dev/stdout | aplay --quiet', { shell: true }`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
@ -2416,7 +2589,7 @@ Blockly.JavaScript['ugj_child_oledtext'] = function (block) {
var value_line2 = Blockly.JavaScript.valueToCode(block, 'line2', Blockly.JavaScript.ORDER_ATOMIC);
var value_line3 = Blockly.JavaScript.valueToCode(block, 'line3', Blockly.JavaScript.ORDER_ATOMIC);
var value_line4 = Blockly.JavaScript.valueToCode(block, 'line4', Blockly.JavaScript.ORDER_ATOMIC);
var code = `'python', ['./scripts/oled.py', ${value_line1}, ${value_line2}, ${value_line3}, ${value_line4}]`;
var code = `'python', ['${ugj_const.library_path}oled.py', ${value_line1}, ${value_line2}, ${value_line3}, ${value_line4}]`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
// fswebcam
@ -2455,7 +2628,7 @@ Blockly.Blocks['ugj_child_julius'] = {
}
};
Blockly.JavaScript['ugj_child_julius'] = function (block) {
var code = "'./bin/julius/julius-simple', ['-C', './bin/julius/dictation-kit-4.5/assistant.jconf', '-C', './bin/julius/dictation-kit-4.5/am-gmm.jconf', '-quiet']";
var code = `'${ugj_const.executable_path}julius/julius-simple', ['-C', '${ugj_const.executable_path}julius/dictation-kit-4.5/assistant.jconf', '-C', '${ugj_const.executable_path}julius/dictation-kit-4.5/am-gmm.jconf', '-quiet']`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
// irrp.py - pigpioによる赤外線リモコンの学習
@ -2476,7 +2649,7 @@ Blockly.Blocks['ugj_child_irrecord'] = {
};
Blockly.JavaScript['ugj_child_irrecord'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var code = `'python3', ['./scripts/irrp.py', '-r', '-g', '${value_gpio}', 'signal', '--post', '130']`;
var code = `'python3', ['${ugj_const.library_path}irrp.py', '-r', '-g', '${value_gpio}', 'signal', '--post', '130']`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
// 送信
@ -2501,7 +2674,7 @@ Blockly.Blocks['ugj_child_irplayback'] = {
Blockly.JavaScript['ugj_child_irplayback'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
var value_signal = Blockly.JavaScript.valueToCode(block, 'signal', Blockly.JavaScript.ORDER_ATOMIC);//.replace('{','\\{').replace('}','\\}').replace(/"/g,'\\"').replace(/ /g,'\\ ')
var code = `'python3', ['./scripts/irrp.py', '-p', '-g', '${value_gpio}', '--irdata', ${value_signal}, 'signal']`;
var code = `'python3', ['${ugj_const.library_path}irrp.py', '-p', '-g', '${value_gpio}', '--irdata', ${value_signal}, 'signal']`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
// ハッシュ生成
@ -2523,7 +2696,7 @@ Blockly.Blocks['ugj_child_irrcvr'] = {
Blockly.JavaScript['ugj_child_irrcvr'] = function (block) {
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
// var code = `'python3', ['./scripts/irrcvr.py', '-g', '${value_gpio}']`;
var code = `'./bin/ir_hash/ir_hash', ['${value_gpio}']`;
var code = `'${ugj_const.executable_path}ir_hash/ir_hash', ['${value_gpio}']`;
return [code, Blockly.JavaScript.ORDER_NONE];
};
@ -2559,7 +2732,7 @@ Blockly.Blocks['ugj_child_testpy'] = {
};
Blockly.JavaScript['ugj_child_testpy'] = function (block) {
// TODO: Assemble JavaScript into code variable.
var code = "'py', ['-2', 'test.py']";
var code = "'python3', ['test.py']";
// TODO: Change ORDER_NONE to the correct strength.
return [code, Blockly.JavaScript.ORDER_NONE];
};
@ -2741,7 +2914,7 @@ Blockly.JavaScript['ugj_sleep'] = function (block) {
var code = `await ${functionName}(${value_sec}*1000);\n`;
return code;
};
Blockly.Python['ugj_sleep'] = function(block) {
Blockly.Python['ugj_sleep'] = function (block) {
var value_sec = Blockly.Python.valueToCode(block, 'sec', Blockly.Python.ORDER_ATOMIC);
Blockly.Python.provideFunction_(
'import_sleep', ['from time import sleep']
@ -2969,7 +3142,7 @@ Blockly.JavaScript['ugj_control_button'] = function (block) {
var value_textcolor = Blockly.JavaScript.valueToCode(block, 'textcolor', Blockly.JavaScript.ORDER_ATOMIC);
var value_bgcolor = Blockly.JavaScript.valueToCode(block, 'bgcolor', Blockly.JavaScript.ORDER_ATOMIC);
var value_title = Blockly.JavaScript.valueToCode(block, 'title', Blockly.JavaScript.ORDER_ATOMIC);
var variable_title = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('title'), Blockly.Variables.NAME_TYPE);
var variable_title = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('title'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
var code = [
`( async () => {`,
@ -3035,7 +3208,7 @@ Blockly.Blocks['ugj_network_fetch'] = {
};
Blockly.JavaScript['ugj_network_fetch'] = function (block) {
var value_url = Blockly.JavaScript.valueToCode(block, 'url', Blockly.JavaScript.ORDER_ATOMIC);
var variable_response = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('response'), Blockly.Variables.NAME_TYPE);
var variable_response = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('response'), Blockly.Variables.NAME_TYPE);
var statements_do = Blockly.JavaScript.statementToCode(block, 'do'); var code = [
`fetch(${value_url})`,
` .then(response => {`,

View File

@ -1,3 +1,7 @@
module.exports.doc_root = '/home/pi/Documents/ocoge_docs/';
module.exports.app_name = 'ocoge';
module.exports.mascot_path = '/home/pi/Applications/ocoge/img/';
const ugj_const = {
doc_root: '/home/pi/Documents/ocoge_docs/',
app_name: 'ocoge',
mascot_path: './img/',
library_path: './lib/',
executable_path: './bin/'
};

View File

@ -5,7 +5,7 @@
// Require
const fs = require('fs');
const path = require("path");
const ugj_const = require('./ugj_const');
// const ugj_const = require('./ugj_const');
const mainWin = require('@electron/remote').getCurrentWindow();
const dialog = require('@electron/remote').dialog;
@ -14,7 +14,7 @@ const clipboard = require('electron').clipboard;
var saveFilepath = null;
var wsChanged = false;
var mascotFilePath = ugj_const.mascot_path + 'cogechee.png';
var mascotFilePath = ugj_const.mascot_path + 'tamachee.png';
// 0で数値の桁合わせ
// NUM=値 LEN=桁数

View File

@ -67,7 +67,7 @@ Blockly.Msg["LOGIC_BOOLEAN_FALSE"] = "偽";
Blockly.Msg["LOGIC_BOOLEAN_TOOLTIP"] = "真 または 偽 を返します。";
Blockly.Msg["LOGIC_BOOLEAN_TRUE"] = "真";
// ローカライズ対応の準備
Blockly.Msg["UGJ_CONTROL_FOR_TITLE"] = "%1 %2 を %3 から %4 まで %5 ずつ増や(減ら)して %6 %7";
Blockly.Msg["UGJ_CONTROL_FOR_TITLE"] = "%1 %2 を %3 から %4 まで %5 ずつ %6 %7 %8";
Blockly.Msg["UGJ_CONTROL_FOR_INDEX"] = "番号";
Blockly.Msg["UGJ_CONTROL_FOR_INCREASE"] = "増やして";
Blockly.Msg["UGJ_CONTROL_FOR_DECREASE"] = "減らして";
@ -113,6 +113,16 @@ Blockly.Msg["I2C_WRITE_BYTE_DATA_TITLE"] = "レジスタ %1 に %2 を書き込
Blockly.Msg["I2C_WRITE_BYTE_DATA_TOOLTIP"] = "デバイスの指定されたレジスタに1バイトを書き込みます。";
Blockly.Msg["I2C_READ_BYTE_DATA_TITLE"] = "レジスタ %1 の値";
Blockly.Msg["I2C_READ_BYTE_DATA_TOOLTIP"] = "デバイスの指定されたレジスタから1バイトを読み込みます。";
Blockly.Msg["I2C_READ_DEVICE_TITLE"] = "i2cデバイスから %1 バイト受け取る";
Blockly.Msg["I2C_READ_DEVICE_TOOLTIP"] = "デバイスから指定したバイト数のデータを受け取ります。データが指定の長さより短いこともあります。";
Blockly.Msg["I2C_WRITE_DEVICE_TITLE"] = "i2c デバイスに %1 を送信";
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_CODECHAR_TITLE"] = "コード %1 の文字";
Blockly.Msg["UGJ_CODECHAR_TOOLTIP"] = "文字コードを文字に変換します。";
@ -315,37 +325,9 @@ const ugj_createCode = (args) => {
window.alert('Python 非対応のブロックが使用されています。\n' + e.message);
}
code = Blockly.Python.workspaceToCode(workspace);
// 追加モジュールのrequire 本当は import
requires = [
// ['_gpio_', false, `import pigpio\n`]
]
}
else { // Javascript コード出力
code = Blockly.JavaScript.workspaceToCode(workspace);
// 追加モジュールのrequire
requires = [
// ['_gpio_', false, `const pi = require('ocoge_pigpiod');\n`],
['_axios_', false, `const axios = require('axios');\n`],
['_sendmail', false, `const nodemailer = require('nodemailer');\n`],
['_cloudspeech_', false, `const speech = require('@google-cloud/speech');\nconst recorder = require('node-record-lpcm16');\n`],
['_httpserver', false, `const http = require('http');\n`],
['_file_', false, `const fs = require('fs');\n`],
// ['_bme280', false, `const BME280 = require('bme280-sensor');`],
['_dht', false, `const dht = require("node-dht-sensor").promises;`],
['_socket_', false, `const net = require('net');`]
];
}
// import/require の要不要をワークスペース内の全てのブロックに対してチェック
let blockArray = workspace.getAllBlocks();
blockArray.forEach(value => {
for (var i = 0, l = requires.length; i < l; i++) {
if (value.type.indexOf(requires[i][0]) >= 0) requires[i][1] = true;
}
});
for (var i = 0, l = requires.length; i < l; i++) {
if (requires[i][1]) code = requires[i][2] + code;
}
if (ext == 'py') { //Python
@ -407,10 +389,11 @@ const ugj_showCode = () => {
}
const export_cb = () => {
code = ugj_createCode({ 'ext': ext, 'async': true, 'beautify': true });
// blackboardWrite()とwindow.alert()をconsole.log()に書き換え、
// blackboardWrite()とwindow.alert()、fukidashi()をconsole.log()に書き換え、
// document... と ugj_... と elec... をコメントアウト(ブラウザ関連部分の追放という意味では不完全なので注意)
// あと正規表現もいい加減
if (chkbox_cli.checked && ext == 'js')
code = code.replace(/const appendDiv[^#]*\/\/#/gm, 'const blackboardWrite = text => console.log(text);').replace('window.alert', 'console.log').replace(/(^(?=.*document.)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*ugj_)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*elec.)[^;]*;)/gm, '/* $1 */');
code = code.replace(/const appendDiv[^#]*\/\/#/gm, 'const blackboardWrite = text => console.log(text);').replace('window.alert', 'console.log').replace(/ugj_fukidashi(.*), \d+(\);)/gm, 'console.log$1$2').replace(/(^(?=.*document.)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*ugj_)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*elec.)[^;]*;)/gm, '/* $1 */');
if (elec.saveFile(code, ext) === false) {
alert('保存できませんでした。');
}
@ -654,7 +637,7 @@ if (typeof require == 'function') {
elec.setWsChanged = () => { ; }
// マスコット
elec.getMascotFilePath = () => './img/cogechee.png';
elec.getMascotFilePath = () => './img/tamachee.png';
//ワークスペースのダウンロード
elec.saveWsFile = xml_text => {