From 1d208f6d0caeb14761459838502d865f0e9d7db6 Mon Sep 17 00:00:00 2001
From: unknown <1371033826@qq.com>
Date: Tue, 2 Sep 2025 17:14:01 +0800
Subject: [PATCH] add_face_blocks
---
blockly/iot/IOT_Blocks.js | 27 +++++++++++++++++++++++++++
ejs/projects.ejs | 10 +++++++++-
js/MixIO.js | 11 +++++++----
js/widgets.js | 7 +++++++
4 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/blockly/iot/IOT_Blocks.js b/blockly/iot/IOT_Blocks.js
index f8fbda7..a93c54c 100644
--- a/blockly/iot/IOT_Blocks.js
+++ b/blockly/iot/IOT_Blocks.js
@@ -1037,6 +1037,25 @@ Blockly.Blocks['datamap_recieved'] = {
}
};
+Blockly.Blocks['face_recognized'] = {
+ init: function() {
+ this.setColour(datamap_HUE);
+ this.appendDummyInput().appendField(Blockly.MIXLY_MICROBIT_JS_CURRENT);
+ this.appendValueInput("name").setCheck("String");
+ this.appendDummyInput().appendField(Blockly.FACE_RECOGNIZED);
+ this.appendDummyInput().appendField(Blockly.Msg.PROCEDURES_CALL_BEFORE_PARAMS+"id, status, faceName, isMouthOpen, faceProbability, happy, sad, angry, surprised, disgusted, fearful");
+ this.setInputsInline(true);
+ this.appendStatementInput('DO0').appendField(Blockly.Msg.CONTROLS_REPEAT_INPUT_DO);
+ this.setPreviousStatement(true);
+ this.setNextStatement(true);
+ this.setTooltip("");
+ },
+ getVars:function(){
+ return ["clientid","long","lat","message"];
+ }
+};
+
+
Blockly.Blocks['datamap_send'] = {
init: function() {
this.appendDummyInput().appendField(Blockly.TO);
@@ -2500,6 +2519,13 @@ Blockly.JavaScript.datamap_recieved=function(block) {
return code;
};
+Blockly.JavaScript.face_recognized =function(block) {
+ var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
+ var code="MixIO.getInstance("+name+",MixIO.typeTags.FACE)\n"+".bind(MixIO.eventTags.FACE_RECOGNIZED, function(event,id,status,faceName,isMouthOpen,faceProbability,happy,sad,angry,surprised,disgusted,fearful){\n"
+ +Blockly.JavaScript.statementToCode(block, "DO0" )+"\n"+"})\n"
+ return code;
+};
+
Blockly.JavaScript.datamap_send=function(block) {
var name = Blockly.JavaScript.valueToCode(this, 'name', Blockly.JavaScript.ORDER_ATOMIC);
var long = Blockly.JavaScript.valueToCode(this, 'long', Blockly.JavaScript.ORDER_ATOMIC);
@@ -3412,6 +3438,7 @@ Blockly.DATAMAP_LAT="纬度";
Blockly.DATAMAP_SEND_MESSAGE="发送消息列表";
Blockly.CLEAR_DATAMAP="数据地图清空";
Blockly.CLEAR_PIXEL="点阵屏清空画布";
+Blockly.FACE_RECOGNIZED = "人脸识别组件识别到人脸时"
Blockly.WS_UPDATED="气象仪更新数据时";
Blockly.WS_SEND="气象仪发送数据时";
diff --git a/ejs/projects.ejs b/ejs/projects.ejs
index 23988fd..3a5679c 100644
--- a/ejs/projects.ejs
+++ b/ejs/projects.ejs
@@ -1090,7 +1090,15 @@
-
+
+
+
+
+ name
+
+
+
+
diff --git a/js/MixIO.js b/js/MixIO.js
index 8d25054..2742113 100644
--- a/js/MixIO.js
+++ b/js/MixIO.js
@@ -86,13 +86,14 @@ var MixIO = {
CAMERA: 17,
MIC: 18,
SELECT: 19,
- PIXEL: 20
+ PIXEL: 20,
+ FACE: 21
},
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", "ble", "camera", "input_mic", "tinydb", "pixel"
+ "output_chart", "output_bar", "table", "output_dashboard", "output_map", "input_weather", "timer", "trigger", "ble", "camera", "input_mic", "tinydb", "pixel", "face"
],
- zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器", "蓝牙转发器", "摄像头", "语音识别", "下拉选项", "点阵屏"],
+ zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器", "蓝牙转发器", "摄像头", "语音识别", "下拉选项", "点阵屏", "人脸识别"],
/*合法的MixIO事件种类*/
eventTags: {
@@ -140,7 +141,9 @@ var MixIO = {
MIC_SENT: "1811",
- SELECT_SENT: "1911"
+ SELECT_SENT: "1911",
+
+ FACE_RECOGNIZED: "2111"
},
diff --git a/js/widgets.js b/js/widgets.js
index 4ebfa91..094747a 100644
--- a/js/widgets.js
+++ b/js/widgets.js
@@ -6631,10 +6631,17 @@ function add_face(user_title, user_topic, user_content, user_style, title_style)
}
if(!lastPublishTime || new Date().getTime() - lastFacePublishTime >= interval)
{
+ // Aug 2025
if(min_index == -1)
+ {
publish(user_topic, JSON.stringify({id: min_index, status: (min_index==-1?0:1), name: "Unknown", isMouthOpen: isMouthOpen, faceProbability: resizedDetections[0].detection.score.toFixed(3), happy: resizedDetections[0].expressions.happy.toFixed(3), sad: resizedDetections[0].expressions.sad.toFixed(3), angry: resizedDetections[0].expressions.angry.toFixed(3), surprised: resizedDetections[0].expressions.surprised.toFixed(3), disgusted: resizedDetections[0].expressions.disgusted.toFixed(3), fearful: resizedDetections[0].expressions.fearful.toFixed(3)}))
+ itemdiv.trigger(MixIO.eventTags.FACE_RECOGNIZED, [min_index, (min_index==-1?0:1), "Unknown", isMouthOpen, resizedDetections[0].detection.score.toFixed(3), resizedDetections[0].expressions.happy.toFixed(3), resizedDetections[0].expressions.sad.toFixed(3), resizedDetections[0].expressions.angry.toFixed(3), resizedDetections[0].expressions.surprised.toFixed(3), resizedDetections[0].expressions.disgusted.toFixed(3), resizedDetections[0].expressions.fearful.toFixed(3)])
+ }
else
+ {
publish(user_topic, JSON.stringify({id: min_index, status: (min_index==-1?0:1), name: user_data[min_index]["name"], isMouthOpen: isMouthOpen, faceProbability: resizedDetections[0].detection.score.toFixed(3), happy: resizedDetections[0].expressions.happy.toFixed(3), sad: resizedDetections[0].expressions.sad.toFixed(3), angry: resizedDetections[0].expressions.angry.toFixed(3), surprised: resizedDetections[0].expressions.surprised.toFixed(3), disgusted: resizedDetections[0].expressions.disgusted.toFixed(3), fearful: resizedDetections[0].expressions.fearful.toFixed(3)}))
+ itemdiv.trigger(MixIO.eventTags.FACE_RECOGNIZED, [min_index, (min_index==-1?0:1), user_data[min_index]["name"], isMouthOpen, resizedDetections[0].detection.score.toFixed(3), resizedDetections[0].expressions.happy.toFixed(3), resizedDetections[0].expressions.sad.toFixed(3), resizedDetections[0].expressions.angry.toFixed(3), resizedDetections[0].expressions.surprised.toFixed(3), resizedDetections[0].expressions.disgusted.toFixed(3), resizedDetections[0].expressions.fearful.toFixed(3)])
+ }
lastFacePublishTime = new Date().getTime()
}
}