This commit is contained in:
Eason010212
2025-09-06 23:56:15 +08:00
5 changed files with 419 additions and 27 deletions

View File

@@ -83,13 +83,19 @@ var MixIO = {
TIMER: 14,
TRIGGER: 15,
BLE: 16,
CAMERA: 17
CAMERA: 17,
MIC: 18,
SELECT: 19,
PIXEL: 20,
FACE: 21,
BEEP: 22,
QR: 23
},
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"
"output_chart", "output_bar", "table", "output_dashboard", "output_map", "input_weather", "timer", "trigger", "ble", "camera", "input_mic", "tinydb", "pixel", "face", "ocr", "qr"
],
zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器", "蓝牙转发器", "摄像头"],
zhcnTags: ["按键/开关", "滑杆", "文本输入", "摇杆手柄", "RGB色盘", "指示灯", "文本显示屏", "折线图表", "柱状图表", "数据表格", "仪表盘", "数据地图", "实时气象仪", "定时触发器", "条件触发器", "蓝牙转发器", "摄像头", "语音识别", "下拉选项", "点阵屏", "人脸识别", "蜂鸣器", "二维码识别"],
/*合法的MixIO事件种类*/
eventTags: {
@@ -133,7 +139,17 @@ var MixIO = {
BLUETOOTH_TRIGGERED: "1611",
CAMERA_SENT: "1711"
CAMERA_SENT: "1711",
MIC_SENT: "1811",
SELECT_SENT: "1911",
FACE_RECOGNIZED: "2111",
BEEP_RECEIVED: "2211",
QR_RECOGNIZED: "2311"
},
@@ -173,9 +189,13 @@ var MixIO = {
WEATHER_SYNC: "1321", //更新气象仪数据
WEATHER_SEND: "1322", //发送气象仪数据
TRIGGER_TIMER: "1411",
TRIGGER_TIMER: "1421",
BLUETOOTH_SENT: "1611"
BLUETOOTH_SENT: "1621",
SELECT_SEND: "1921",
PIXEL_SWITCH: "2021"
},
publish: function(topic, message) {
// if message undefined
@@ -245,6 +265,10 @@ var MixIO = {
instance.getText = function() {
return instance.attr('user-content')
}
} else if (type === MixIO.typeTags.SELECT) {
instance.getOptions = function() {
return instance.attr('user-content').split(",")
}
} else if (type === MixIO.typeTags.RGB_PICKER) {
//获取RGB色盘当前颜色
instance.getColor = function() {
@@ -356,6 +380,14 @@ var MixIO = {
instance.getBluetoothStatus = function() {
return instance.attr('user-content')
}
} else if (type === MixIO.typeTags.PIXEL){
instance.clearPixel = function() {
MixIO.publish(instance.attr('user-topic'), "cls")
}
} else if (type === MixIO.typeTags.BEEP){
instance.beep = function() {
MixIO.publish(instance.attr('user-topic'), 1)
}
}
return instance
},

View File

@@ -304,6 +304,7 @@ async function run_project() {
logicFunction()
}
} catch (e) {
console.log(e)
MixIO.log(e)
showtext(JSLang[lang].logicError)
isRunning = false;

View File

@@ -207,22 +207,37 @@ function add_pixel(user_title, user_topic, user_content, user_style, title_style
var bottomDiv = $('<div style="width:100%;margin-top:15px;display:flex;flex-direction:row;align-items:center;justify-content:space-around"/>')
var confirmEdit = $('<a class="btn btn-primary btn-circle" style="margin-right:10px;box-shadow:1px 1px 5px #4e73df;"><i class="fa fa-check"></i></a>')
bottomDiv.append(confirmEdit)
// Aug 2025
itemdiv.bind(MixIO.actionTags.PIXEL_SWITCH, function(event, x, y, status) {
var color = "#EEEEEE"
if(status)
color = "#4E73DF"
itemdiv.find('.pixelrow').eq(x).find('.pixel').eq(y).css('background-color', color)
})
client.on('message', function(topic1, message1) {
if (isAlive && isRunning)
if (topic1.split("/")[(isMixly ? 3 : 2)] == topic.text()) {
// Aug 2025
var content = message1.toString()
var pixels = content.split(',')
for (var i = 0; i < pixels.length; i++) {
var pixel = pixels[i].split('-')
var x = parseInt(pixel[0])
var y = parseInt(pixel[1])
var color = pixel[2]
if(color == '0')
color = '#EEEEEE'
else if(color == '1')
color = '#4E73DF'
var pixel = itemdiv.find('.pixelrow').eq(x).find('.pixel').eq(y)
pixel.css('background-color', color)
if(content == "cls")
{
itemdiv.find('.pixelrow').find('.pixel').css('background-color', "#EEEEEE")
}
else
{
var pixels = content.split(',')
for (var i = 0; i < pixels.length; i++) {
var pixel = pixels[i].split('-')
var x = parseInt(pixel[0])
var y = parseInt(pixel[1])
var color = pixel[2]
if(color == '0')
color = '#EEEEEE'
else if(color == '1')
color = '#4E73DF'
var pixel = itemdiv.find('.pixelrow').eq(x).find('.pixel').eq(y)
pixel.css('background-color', color)
}
}
}
})
@@ -1303,10 +1318,12 @@ function add_tinydb(user_title, user_topic, user_content, user_style, title_styl
sendIcon.bind('mouseup', function(event) {
event.stopPropagation()
})
// Aug 2025
if (window.screen.width > 800)
sendIcon.bind('click', function(event) {
event.stopPropagation()
publish(topic.text(), messDiv.val())
itemdiv.trigger(MixIO.eventTags.SELECT_SENT, messDiv.val())
sendIcon.removeClass("btn-primary")
sendIcon.addClass("btn-success")
sendIcon.children().removeClass('fa-paper-plane')
@@ -1322,6 +1339,7 @@ function add_tinydb(user_title, user_topic, user_content, user_style, title_styl
sendIcon.bind('touchend', function(event) {
event.stopPropagation()
publish(topic.text(), messDiv.val())
itemdiv.trigger(MixIO.eventTags.SELECT_SENT, messDiv.val())
sendIcon.removeClass("btn-primary")
sendIcon.addClass("btn-success")
sendIcon.children().removeClass('fa-paper-plane')
@@ -1335,7 +1353,8 @@ function add_tinydb(user_title, user_topic, user_content, user_style, title_styl
})
contents.push(keyDiv)
var itemdiv = add_block(3, 1, contents, attrs)
itemdiv.bind(MixIO.actionTags.KEYBOARD_SEND, function(event, message) {
// Aug 2025
itemdiv.bind(MixIO.actionTags.SELECT_SEND, function(event, message) {
messDiv.val(message)
publish(topic.text(), messDiv.val())
sendIcon.removeClass("btn-primary")
@@ -1526,6 +1545,7 @@ function add_mic(user_title, user_topic, user_content, user_style, title_style)
sendIcon.bind('mouseup', function(event) {
event.stopPropagation()
})
// Aug 2025
if (window.screen.width > 800)
sendIcon.bind('click', function(event) {
event.stopPropagation()
@@ -1558,6 +1578,7 @@ function add_mic(user_title, user_topic, user_content, user_style, title_style)
sendIcon.children().addClass("fa-microphone")
recognition.stop();
publish(topic.text(), messDiv.val())
itemdiv.trigger(MixIO.eventTags.MIC_SENT, messDiv.val())
isRecording = false
}
})
@@ -1594,6 +1615,7 @@ function add_mic(user_title, user_topic, user_content, user_style, title_style)
sendIcon.children().addClass("fa-microphone")
recognition.stop();
publish(topic.text(), messDiv.val())
itemdiv.trigger(MixIO.eventTags.MIC_SENT, messDiv.val())
isRecording = false
}
})
@@ -6615,10 +6637,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()
}
}
@@ -6980,6 +7009,8 @@ function add_ocr(user_title, user_topic, user_content, user_style, title_style)
bell_icon.css("color", "#e74a3b")
itemdiv.css("box-shadow", "#e74a3b 1px 1px 10px")
}
// Aug 2025
itemdiv.trigger(MixIO.eventTags.BEEP_RECEIVED);
setTimeout(function(){
bell_icon.css("color", "#858796")
itemdiv.css("box-shadow", "")
@@ -7135,7 +7166,11 @@ function add_qr(user_title, user_topic, user_content, user_style, title_style) {
{
bottomDiv11.text(code.data)
if(isRunning && isAlive)
{
publish(user_topic, code.data)
// Aug 2025
itemdiv.trigger(MixIO.eventTags.QR_RECOGNIZED, [code.data]);
}
}
else
{
@@ -7148,11 +7183,14 @@ function add_qr(user_title, user_topic, user_content, user_style, title_style) {
readers: ["code_128_reader", "ean_reader", "ean_8_reader", "code_39_reader", "code_39_vin_reader", "codabar_reader", "upc_reader", "upc_e_reader", "i2of5_reader", "2of5_reader", "code_93_reader"] // 指定条形码格式
}
}, function(result){
console.log(result)
if (result && result.codeResult) {
bottomDiv11.text(result.codeResult.code);
if(isRunning && isAlive)
{
publish(user_topic, result.codeResult.code)
// Aug 2025
itemdiv.trigger(MixIO.eventTags.QR_RECOGNIZED, [result.codeResult.code]);
}
}
else
bottomDiv11.text("无二维码或条形码")