add_bluetooth_blocks
This commit is contained in:
@@ -632,6 +632,49 @@ Blockly.Blocks['get_trigger_triggers'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Blockly.Blocks['bluetooth_triggered'] = {
|
||||||
|
init: function() {
|
||||||
|
this.setColour(lineChart_HUE);
|
||||||
|
this.appendDummyInput().appendField(Blockly.MIXLY_MICROBIT_JS_CURRENT);
|
||||||
|
this.appendValueInput("name").setCheck("String");
|
||||||
|
this.appendDummyInput().appendField(Blockly.BLUETOOTH_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_bluetooth_status'] = {
|
||||||
|
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_BLUETOOTH_STATUS);
|
||||||
|
this.setOutput(true, null);
|
||||||
|
this.setTooltip("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Blockly.Blocks['bluetooth_sent'] = {
|
||||||
|
init: function() {
|
||||||
|
this.appendDummyInput().appendField(Blockly.TO);
|
||||||
|
this.appendValueInput("name").setCheck("String");
|
||||||
|
this.appendDummyInput().appendField(Blockly.BLUETOOTH_SENT);
|
||||||
|
this.appendValueInput("message").setCheck("String");
|
||||||
|
this.setInputsInline(true);
|
||||||
|
this.setPreviousStatement(true);
|
||||||
|
this.setNextStatement(true);
|
||||||
|
this.setColour(lineChart_HUE);
|
||||||
|
this.setTooltip('');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Blockly.Blocks['lineChart_send'] = {
|
Blockly.Blocks['lineChart_send'] = {
|
||||||
init: function() {
|
init: function() {
|
||||||
this.appendDummyInput().appendField(Blockly.TO);
|
this.appendDummyInput().appendField(Blockly.TO);
|
||||||
@@ -2170,6 +2213,26 @@ Blockly.JavaScript.get_trigger_triggers=function(block) {
|
|||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Blockly.JavaScript.bluetooth_triggered=function(block) {
|
||||||
|
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
|
var code="MixIO.getInstance("+name+",MixIO.typeTags.BLE)\n"+".bind(MixIO.eventTags.BLUETOOTH_TRIGGERED, function(event,value){\n"
|
||||||
|
+Blockly.JavaScript.statementToCode(block, "DO0" )+"\n"+"})\n"
|
||||||
|
return code;
|
||||||
|
};
|
||||||
|
|
||||||
|
Blockly.JavaScript.get_bluetooth_status=function(block) {
|
||||||
|
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
|
var code="MixIO.getInstance("+name+",MixIO.typeTags.BLE).getBluetoothStatus()"
|
||||||
|
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||||
|
};
|
||||||
|
|
||||||
|
Blockly.JavaScript.bluetooth_sent=function(block) {
|
||||||
|
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
|
var message = Blockly.JavaScript.valueToCode(this, 'message', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
|
var code="MixIO.getInstance("+name+",MixIO.typeTags.BLE)\n"+".trigger(MixIO.actionTags.BLUETOOTH_SENT,"+message+")\n"
|
||||||
|
return code;
|
||||||
|
};
|
||||||
|
|
||||||
Blockly.JavaScript.lineChart_send=function(block) {
|
Blockly.JavaScript.lineChart_send=function(block) {
|
||||||
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var message = Blockly.JavaScript.valueToCode(this, 'message', Blockly.JavaScript.ORDER_ATOMIC);
|
var message = Blockly.JavaScript.valueToCode(this, 'message', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
@@ -3157,6 +3220,10 @@ Blockly.GET_TRIGGER_TIMES="定时触发器的触发次数"
|
|||||||
Blockly.TRIGGER_TRIGGERED="条件触发器触发时";
|
Blockly.TRIGGER_TRIGGERED="条件触发器触发时";
|
||||||
Blockly.GET_TRIGGER_TRIGGERS="条件触发器的触发次数"
|
Blockly.GET_TRIGGER_TRIGGERS="条件触发器的触发次数"
|
||||||
|
|
||||||
|
Blockly.BLUETOOTH_TRIGGERED="蓝牙转发器收到消息时";
|
||||||
|
Blockly.GET_BLUETOOTH_STATUS="蓝牙转发器连接的设备";
|
||||||
|
Blockly.BLUETOOTH_SENT = "蓝牙转发器发送消息"
|
||||||
|
|
||||||
Blockly.BARCHART_RECIEVED="柱状图收到消息时";
|
Blockly.BARCHART_RECIEVED="柱状图收到消息时";
|
||||||
Blockly.BARCHART_SEND_MESSAGE="柱状图发送消息";
|
Blockly.BARCHART_SEND_MESSAGE="柱状图发送消息";
|
||||||
Blockly.CLEAR_BARCHART="柱状图表清空";
|
Blockly.CLEAR_BARCHART="柱状图表清空";
|
||||||
|
|||||||
@@ -696,6 +696,37 @@
|
|||||||
</block>
|
</block>
|
||||||
</category>
|
</category>
|
||||||
<category name="蓝牙转发器" colour="#4e73df" css-icon="customIcon fa fa-bluetooth-b">
|
<category name="蓝牙转发器" colour="#4e73df" css-icon="customIcon fa fa-bluetooth-b">
|
||||||
|
<block type="bluetooth_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_bluetooth_status">
|
||||||
|
<value name="name">
|
||||||
|
<shadow type="text">
|
||||||
|
<field name="TEXT">name</field>
|
||||||
|
</shadow>
|
||||||
|
</value>
|
||||||
|
</block>
|
||||||
|
<block type="bluetooth_sent">
|
||||||
|
<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>
|
||||||
</category>
|
</category>
|
||||||
<category name="折线图表" colour="#4e73df" css-icon="customIcon fa fa-area-chart">
|
<category name="折线图表" colour="#4e73df" css-icon="customIcon fa fa-area-chart">
|
||||||
<block type="lineChart_recieved">
|
<block type="lineChart_recieved">
|
||||||
@@ -931,7 +962,15 @@
|
|||||||
</value>
|
</value>
|
||||||
</block>
|
</block>
|
||||||
</category>
|
</category>
|
||||||
<category name="摄像头" colour="#4e73df" css-icon="customIcon fa fa-camera"></category>
|
<category name="摄像头" colour="#4e73df" css-icon="customIcon fa fa-camera">
|
||||||
|
<block type="camera_recognized">
|
||||||
|
<value name="name">
|
||||||
|
<shadow type="text">
|
||||||
|
<field name="TEXT">name</field>
|
||||||
|
</shadow>
|
||||||
|
</value>
|
||||||
|
</block>
|
||||||
|
</category>
|
||||||
<category name="语音识别" colour="#4e73df" css-icon="customIcon fa fa-microphone"></category>
|
<category name="语音识别" colour="#4e73df" css-icon="customIcon fa fa-microphone"></category>
|
||||||
<category name="下拉选项" colour="#4e73df" css-icon="customIcon fa fa-list"></category>
|
<category name="下拉选项" colour="#4e73df" css-icon="customIcon fa fa-list"></category>
|
||||||
<category name="文本输入" colour="#4e73df" css-icon="customIcon fa fa-i-cursor">
|
<category name="文本输入" colour="#4e73df" css-icon="customIcon fa fa-i-cursor">
|
||||||
|
|||||||
19
js/MixIO.js
19
js/MixIO.js
@@ -81,13 +81,14 @@ var MixIO = {
|
|||||||
DATA_MAP: 12,
|
DATA_MAP: 12,
|
||||||
WEATHER: 13,
|
WEATHER: 13,
|
||||||
TIMER: 14,
|
TIMER: 14,
|
||||||
TRIGGER: 15
|
TRIGGER: 15,
|
||||||
|
BLE: 16
|
||||||
},
|
},
|
||||||
|
|
||||||
oldTags: ["input_button", "input_slider", "input_keyboard", "input_controller", "input_rgb", "output_bulb", "output_text",
|
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", "trigger"
|
"output_chart", "output_bar", "table", "output_dashboard", "output_map", "input_weather", "timer", "trigger", "ble"
|
||||||
],
|
],
|
||||||
zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器"],
|
zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器", "蓝牙转发器"],
|
||||||
|
|
||||||
/*合法的MixIO事件种类*/
|
/*合法的MixIO事件种类*/
|
||||||
eventTags: {
|
eventTags: {
|
||||||
@@ -127,7 +128,9 @@ var MixIO = {
|
|||||||
|
|
||||||
TIMER_TRIGGERED: "1411",
|
TIMER_TRIGGERED: "1411",
|
||||||
|
|
||||||
TRIGGER_TRIGGERED: "1511"
|
TRIGGER_TRIGGERED: "1511",
|
||||||
|
|
||||||
|
BLUETOOTH_TRIGGERED: "1611"
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -167,7 +170,9 @@ var MixIO = {
|
|||||||
WEATHER_SYNC: "1321", //更新气象仪数据
|
WEATHER_SYNC: "1321", //更新气象仪数据
|
||||||
WEATHER_SEND: "1322", //发送气象仪数据
|
WEATHER_SEND: "1322", //发送气象仪数据
|
||||||
|
|
||||||
TRIGGER_TIMER: "1411"
|
TRIGGER_TIMER: "1411",
|
||||||
|
|
||||||
|
BLUETOOTH_SENT: "1611"
|
||||||
},
|
},
|
||||||
publish: function(topic, message) {
|
publish: function(topic, message) {
|
||||||
// if message undefined
|
// if message undefined
|
||||||
@@ -344,6 +349,10 @@ var MixIO = {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (type === MixIO.typeTags.BLE){
|
||||||
|
instance.getBluetoothStatus = function() {
|
||||||
|
return instance.attr('user-content')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return instance
|
return instance
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2021,6 +2021,8 @@ function add_ble(user_title, user_topic, user_content, user_style, title_style)
|
|||||||
if(isAlive)
|
if(isAlive)
|
||||||
{
|
{
|
||||||
publish(topic.text().split(",")[0], value)
|
publish(topic.text().split(",")[0], value)
|
||||||
|
// Aug 2025
|
||||||
|
itemdiv.trigger(MixIO.eventTags.BLUETOOTH_TRIGGERED, value)
|
||||||
ble_icon.css('color', '#1cc88a')
|
ble_icon.css('color', '#1cc88a')
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
ble_icon.css('color', '#4e73df')
|
ble_icon.css('color', '#4e73df')
|
||||||
@@ -2079,6 +2081,10 @@ function add_ble(user_title, user_topic, user_content, user_style, title_style)
|
|||||||
icon_div.append(ble_icon)
|
icon_div.append(ble_icon)
|
||||||
contents.push(icon_div)
|
contents.push(icon_div)
|
||||||
var itemdiv = add_block(1, 1, contents, attrs)
|
var itemdiv = add_block(1, 1, contents, attrs)
|
||||||
|
// Aug 2025
|
||||||
|
itemdiv.bind(MixIO.actionTags.BLUETOOTH_SENT, function(event, value) {
|
||||||
|
MixIO.publish(topic.text().split(",")[1], value)
|
||||||
|
})
|
||||||
bleconnect()
|
bleconnect()
|
||||||
|
|
||||||
var delete_on_click = function() {
|
var delete_on_click = function() {
|
||||||
@@ -5609,7 +5615,6 @@ function add_chart(user_title, user_topic, user_content, user_style, title_style
|
|||||||
var itemdiv = add_block(3, 3, contents, attrs)
|
var itemdiv = add_block(3, 3, contents, attrs)
|
||||||
itemdiv.addClass("moveDiv")
|
itemdiv.addClass("moveDiv")
|
||||||
itemdiv.bind(MixIO.actionTags.LINE_CHART_CHANGE, function(event, value) {
|
itemdiv.bind(MixIO.actionTags.LINE_CHART_CHANGE, function(event, value) {
|
||||||
console.log(value)
|
|
||||||
MixIO.publish(topic.text(), value)
|
MixIO.publish(topic.text(), value)
|
||||||
})
|
})
|
||||||
itemdiv.bind(MixIO.actionTags.LINE_CHART_CLEAR, function() {
|
itemdiv.bind(MixIO.actionTags.LINE_CHART_CLEAR, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user