add_blocks_for_trigger_and_fix_bugs
This commit is contained in:
@@ -603,6 +603,35 @@ Blockly.Blocks['get_trigger_times'] = {
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['trigger_triggered'] = {
|
||||
init: function() {
|
||||
this.setColour(lineChart_HUE);
|
||||
this.appendDummyInput().appendField(Blockly.MIXLY_MICROBIT_JS_CURRENT);
|
||||
this.appendValueInput("name").setCheck("String");
|
||||
this.appendDummyInput().appendField(Blockly.TRIGGER_TRIGGERED);
|
||||
this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS+"value");
|
||||
this.setInputsInline(true);
|
||||
this.appendStatementInput('DO0').appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip("");
|
||||
},
|
||||
getVars:function(){
|
||||
return ["time","value"];
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['get_trigger_triggers'] = {
|
||||
init: function() {
|
||||
this.setColour(lineChart_HUE);
|
||||
this.appendDummyInput().appendField(Blockly.MIXLY_MICROBIT_PY_STORAGE_GET);
|
||||
this.appendValueInput("name").setCheck("String");
|
||||
this.appendDummyInput().appendField(Blockly.GET_TRIGGER_TRIGGERS);
|
||||
this.setOutput(true, null);
|
||||
this.setTooltip("");
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['lineChart_send'] = {
|
||||
init: function() {
|
||||
this.appendDummyInput().appendField(Blockly.TO);
|
||||
@@ -2128,6 +2157,19 @@ Blockly.JavaScript.get_trigger_times=function(block) {
|
||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.JavaScript.trigger_triggered=function(block) {
|
||||
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var code="MixIO.getInstance("+name+",MixIO.typeTags.TRIGGER)\n"+".bind(MixIO.eventTags.TRIGGER_TRIGGERED, function(event,value){\n"
|
||||
+Blockly.JavaScript.statementToCode(block, "DO0" )+"\n"+"})\n"
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.JavaScript.get_trigger_triggers=function(block) {
|
||||
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var code="MixIO.getInstance("+name+",MixIO.typeTags.TRIGGER).getTriggerTimes()"
|
||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||
};
|
||||
|
||||
Blockly.JavaScript.lineChart_send=function(block) {
|
||||
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
var message = Blockly.JavaScript.valueToCode(this, 'message', Blockly.JavaScript.ORDER_ATOMIC);
|
||||
@@ -3112,6 +3154,9 @@ Blockly.LINECHART_LATEST_MESSAGE="折线图表的最新一条消息";
|
||||
Blockly.TIMER_TRIGGERED="定时触发器触发时";
|
||||
Blockly.GET_TRIGGER_TIMES="定时触发器的触发次数"
|
||||
|
||||
Blockly.TRIGGER_TRIGGERED="条件触发器触发时";
|
||||
Blockly.GET_TRIGGER_TRIGGERS="条件触发器的触发次数"
|
||||
|
||||
Blockly.BARCHART_RECIEVED="柱状图收到消息时";
|
||||
Blockly.BARCHART_SEND_MESSAGE="柱状图发送消息";
|
||||
Blockly.CLEAR_BARCHART="柱状图表清空";
|
||||
|
||||
@@ -675,7 +675,25 @@
|
||||
</block>
|
||||
</category>
|
||||
<category name="条件触发器" colour="#4e73df" css-icon="customIcon fa fa-code-fork">
|
||||
|
||||
<block type="trigger_triggered">
|
||||
<value name="name">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">name</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="message">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">message</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="get_trigger_triggers">
|
||||
<value name="name">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">name</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<category name="蓝牙转发器" colour="#4e73df" css-icon="customIcon fa fa-bluetooth-b">
|
||||
</category>
|
||||
|
||||
13
js/MixIO.js
13
js/MixIO.js
@@ -80,13 +80,14 @@ var MixIO = {
|
||||
DASHBOARD: 11,
|
||||
DATA_MAP: 12,
|
||||
WEATHER: 13,
|
||||
TIMER: 14
|
||||
TIMER: 14,
|
||||
TRIGGER: 15
|
||||
},
|
||||
|
||||
oldTags: ["input_button", "input_slider", "input_keyboard", "input_controller", "input_rgb", "output_bulb", "output_text",
|
||||
"output_chart", "output_bar", "table", "output_dashboard", "output_map", "input_weather", "timer"
|
||||
"output_chart", "output_bar", "table", "output_dashboard", "output_map", "input_weather", "timer", "trigger"
|
||||
],
|
||||
zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器"],
|
||||
zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器"],
|
||||
|
||||
/*合法的MixIO事件种类*/
|
||||
eventTags: {
|
||||
@@ -124,7 +125,9 @@ var MixIO = {
|
||||
WEATHER_SYNCED: "1311", //气象仪更新数据
|
||||
WEATHER_SENT: "1312", //气象仪发送数据
|
||||
|
||||
TIMER_TRIGGERED: "1411"
|
||||
TIMER_TRIGGERED: "1411",
|
||||
|
||||
TRIGGER_TRIGGERED: "1511"
|
||||
|
||||
},
|
||||
|
||||
@@ -332,7 +335,7 @@ var MixIO = {
|
||||
instance.getData = function(type) {
|
||||
return sepMsgs[type]
|
||||
}
|
||||
} else if (type === MixIO.typeTags.TIMER){
|
||||
} else if (type === MixIO.typeTags.TIMER || type === MixIO.typeTags.TRIGGER){
|
||||
instance.getTriggerTimes = function(){
|
||||
try{
|
||||
return parseInt(instance.attr('user-times'))
|
||||
|
||||
@@ -800,7 +800,7 @@ function view_project(projectName, projectType) {
|
||||
}
|
||||
|
||||
var modald = showmodaltext("<div style='text-align:center'><i class='fa fa-spin fa-cog' style='font-size:2rem;color:#4e73df'></i><p style='margin-top:6px;margin-bottom:0;color:#4e73df;font-size:1rem;font-weight:bold'>" + JSLang[lang].downloading + "</p></div>")
|
||||
$.post('getProject', { 'projectName': projectName }, function(res) {
|
||||
$.post('getProject', { 'projectName': projectName }, async function(res) {
|
||||
console.log(JSON.parse(res))
|
||||
modald.close().remove()
|
||||
if (res == 0) {
|
||||
@@ -1162,7 +1162,7 @@ function view_project(projectName, projectType) {
|
||||
'input_mic': add_mic,
|
||||
'tinydb': add_tinydb,
|
||||
}
|
||||
toolkits[un.attr('user-type')](un.attr('user-title'), un.attr('user-topic'), un.attr('user-content'), un.attr('style'), titleHidden)
|
||||
await toolkits[un.attr('user-type')](un.attr('user-title'), un.attr('user-topic'), un.attr('user-content'), un.attr('style'), titleHidden)
|
||||
}
|
||||
var topicOuterDiv = $("<div style='width:100%;display:flex;align-items:center;'></div>")
|
||||
var topicDiv = $("<div style='z-index:1000;margin:0;display:flex;flex-direction:row;align-items:center;justify-content:center;margin-bottom:20px;width:320px;background-color:white;border-radius:0 0 40px 0;padding-left:10px;padding-right:10px;padding-top:5px;padding-bottom:10px;box-shadow:0 .15rem 1.75rem 0 rgba(58,59,69,.15)!important;flex-wrap:wrap'></div>")
|
||||
|
||||
@@ -2675,6 +2675,9 @@ async function add_trigger(user_title, user_topic, user_content, user_style, tit
|
||||
return true
|
||||
}
|
||||
MixIO.triggers[title.text()] = function() {
|
||||
// Aug 2025
|
||||
var localTime = 0
|
||||
title.parent().parent().attr('user-times', localTime)
|
||||
MixIO.onMessage(function(topic1, message) {
|
||||
var message = String(message)
|
||||
if (topic1 == topic.text()) {
|
||||
@@ -2685,6 +2688,9 @@ async function add_trigger(user_title, user_topic, user_content, user_style, tit
|
||||
itemdiv.removeClass("triggered")
|
||||
}, 150)
|
||||
MixIO.publish(dstTopic, dstMessage)
|
||||
localTime = localTime + 1
|
||||
title.parent().parent().attr('user-times', localTime)
|
||||
itemdiv.trigger(MixIO.eventTags.TRIGGER_TRIGGERED, dstMessage)
|
||||
} else {
|
||||
itemdiv.addClass("imtriggered")
|
||||
setTimeout(function() {
|
||||
@@ -2698,6 +2704,9 @@ async function add_trigger(user_title, user_topic, user_content, user_style, tit
|
||||
itemdiv.removeClass("triggered")
|
||||
}, 150)
|
||||
MixIO.publish(dstTopic, dstMessage)
|
||||
localTime = localTime + 1
|
||||
title.parent().parent().attr('user-times', localTime)
|
||||
itemdiv.trigger(MixIO.eventTags.TRIGGER_TRIGGERED, dstMessage)
|
||||
} else {
|
||||
itemdiv.addClass("imtriggered")
|
||||
setTimeout(function() {
|
||||
@@ -2711,6 +2720,9 @@ async function add_trigger(user_title, user_topic, user_content, user_style, tit
|
||||
itemdiv.removeClass("triggered")
|
||||
}, 150)
|
||||
MixIO.publish(dstTopic, dstMessage)
|
||||
localTime = localTime + 1
|
||||
title.parent().parent().attr('user-times', localTime)
|
||||
itemdiv.trigger(MixIO.eventTags.TRIGGER_TRIGGERED, dstMessage)
|
||||
} else {
|
||||
itemdiv.addClass("imtriggered")
|
||||
setTimeout(function() {
|
||||
|
||||
Reference in New Issue
Block a user