修改蓝牙断开问题,增加剩料收集页面

This commit is contained in:
liuwu 2023-11-03 16:30:27 +08:00
parent c4e435b40b
commit d114d3a7b8
5 changed files with 431 additions and 82 deletions

288
html/config.html Normal file
View File

@ -0,0 +1,288 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="../css/mui_min.css">
<link href="../css/mui_picker_min.css" rel="stylesheet"/>
<link href="../css/mui_poppicker_css" rel="stylesheet"/>
<script src="../script/api.js"></script>
<script src="../script/mui.min.js"></script>
<script src="../script/mui.picker.min.js"></script>
<script src="../script/mui.poppicker.js"></script>
</head>
<style>
.head {
height: 10vh;
box-sizing: border-box;
border: 1px solid #a3caef;
}
.content{
height: 79vh;
box-sizing: border-box; border: 1px solid #a3caef;
}
.footer{
height: 10vh;
box-sizing: border-box; border: 1px solid #a3caef;
}
/*.content {*/
/* width: 100%;*/
/* height: 100vh;*/
/* box-sizing: border-box;*/
/* !* background-color: #007aff; *!*/
/* border: 1px solid #a3caef;*/
/*}*/
.form {
box-sizing: border-box;
border: 1px solid #a3caef;
margin: 10px;
padding: 10px;
}
input {
font-size: xx-large;
width: 300px;
box-sizing: border-box;
border: 1px solid #a3caef;
}
button {
border-radius: 20px;
}
.flex {
/*flex 布局*/
display: flex;
/*实现垂直居中*/
align-items: center;
/*实现水平居中*/
justify-content: center;
text-align: justify;
width: 100%;
}
.flex1 {
/*flex 布局*/
display: flex;
/*实现垂直居中*/
align-items: center;
/*实现水平居中*/
justify-content: flex-start;
text-align: justify;
width: 100%;
}
</style>
<body>
<div class="mui-row">
<div class="head flex mui-row">
<div class="mui-col-sm-3" style="display:flex;align-items: center;">
<button class="btnc mui-btn-inline mui-btn-danger" onclick="handleBackMain()">返回</button>
</div>
<div class="mui-col-sm-9" style="display:flex;justify-content: flex-end;">
<button class="btnc mui-btn-inline mui-btn-danger" onclick="closeApp()" type='button'>关闭系统</button>
</div>
</div>
<!--中间内容开始-->
<div class="mui-row content">
<div class="mui-col-sm-4">
<div class="mui-row form flex1">
<button class="mui-btn-inline mui-btn-info" style="font-size: large;" type='button'>绑定设备</button>
<button id='initsb' class="mui-btn-inline mui-btn-primary" style="font-size: large;" type='button'>
请选择设备
</button>
<button class="mui-btn-inline mui-btn-success" style="font-size: large;" onclick="initsb()">保存
</button>
</div>
<div class="mui-row form flex1">
<button class="mui-btn-inline mui-btn-info" style="font-size: large;" type='button'>默认页面</button>
<button id='initpage' class="mui-btn-inline mui-btn-primary" style="font-size: large;" type='button'>
请选择页面
</button>
<input id="indexPage" type="hidden" value="">
<button class="mui-btn-inline mui-btn-success" style="font-size: large;" onclick="initpage()">保存
</button>
</div>
</div>
<div class="mui-col-sm-4">
</div>
</div>
<div class="footer flex mui-row">
<div class="mui-col-sm-12 flex"style="width:100%;height:8vh;white-space: nowrap !important;overflow-x: scroll;" id="list">
</div>
</div>
</div>
<script>
var carListener = null;
var pageListener = null;
var userPicker;
var pagePicker;
var pickData = [];
var btnArray = ['取消', '<b style="font-weight:900">确认</b>'];
var pageData = []
pageData.push({value: "index", text: "首页"})
pageData.push({value: "index1", text: "装料页面"})
pageData.push({value: "collection", text: "剩料收集页面"})
pageData.push({value: "config", text: "设置页面"})
function init() {
}
var apiready = function apiready() {
initSbList()
init()
muiInitPage()
var indexPage = api.getPrefs({
sync: true,
key: 'initpage'
});
if (indexPage) {
pageData.forEach(p => {
if (indexPage === p.value) {
document.getElementById('initpage').innerHTML = p.text
}
})
}
}
//返回主页
function handleBackMain() {
api.closeWin();
}
function closeApp() {
mui.confirm('确认关闭TMR饲喂系统', '提示', btnArray, function (e) {
if (e.index == 0) {
} else {
api.closeWidget({
id: api.appId, //应用ID
retData: {name: 'closeWidget'},
silent: true
});
}
});
}
// 初始化设备查询
function initSbList() {
pickData = [];
api.ajax({
url: 'https://tmr.nxcyx.com/api/app/tmr/sbList?sourceCow=' + api.getPrefs({sync: true, key: 'sourceCow'}),
method: 'get',
timeout: 5
}, function (ret, err) {
if (ret) {
var initsb = api.getPrefs({
sync: true,
key: 'initsb'
});
ret.data.forEach(function (e) {
if (initsb === e.name) {
var json = {value: e.sbId, text: e.name};
pickData.push(json);
}
});
ret.data.forEach(function (e) {
if (initsb !== e.name) {
var json = {value: e.sbId, text: e.name};
pickData.push(json);
}
});
document.getElementById('initsb').innerHTML = pickData[0].text;
muiInit();
} else {
mui.alert("sbList:" + err.msg);
}
});
}
// 初始化设备下拉
function muiInit() {
(function ($, doc) {
$.init();
$.ready(function () {
/**
* 获取对象属性的值
* 主要用于过滤三级联动中,可能出现的最低级的数据不存在的情况,实际开发中需要注意这一点;
* @param {Object} obj 对象
* @param {String} param 属性名
*/
var _getParam = function _getParam(obj, param) {
return obj[param] || '';
};
if (userPicker) {
} else {
userPicker = new $.PopPicker();
var showUserPickerButton = doc.getElementById('initsb');
carListener = null;
carListener = showUserPickerButton.addEventListener('tap', function (event) {
userPicker.show(function (items) {
console.log('设备切换');
showUserPickerButton.innerHTML = items[0].text;
});
}, false);
}
userPicker.setData(pickData);
});
})(mui, document);
}
function muiInitPage() {
(function ($, doc) {
$.init();
$.ready(function () {
/**
* 获取对象属性的值
* 主要用于过滤三级联动中,可能出现的最低级的数据不存在的情况,实际开发中需要注意这一点;
* @param {Object} obj 对象
* @param {String} param 属性名
*/
var _getParam = function _getParam(obj, param) {
return obj[param] || '';
};
if (pagePicker) {
} else {
pagePicker = new $.PopPicker();
var showPagePickerButton = doc.getElementById('initpage');
pageListener = null;
pageListener = showPagePickerButton.addEventListener('tap', function (event) {
pagePicker.show(function (items) {
console.log('设备切换');
document.getElementById('indexPage').value = items[0].value;
showPagePickerButton.innerHTML = items[0].text;
});
}, false);
}
pagePicker.setData(pageData);
});
})(mui, document);
}
function initsb() {
// var value = document.getElementById('initsb').value;
var value = document.getElementById('initsb').innerHTML
if (value) {
api.setPrefs({
key: 'initsb',
value: value
});
mui.alert('绑定设备"' + value + '"成功');
}
}
function initpage() {
var value = document.getElementById('indexPage').value;
if (value) {
api.setPrefs({
key: 'initpage',
value: value
});
var name = document.getElementById('initpage').innerHTML;
mui.alert('默认页面"' + name + '"设置成功');
}
}
</script>
</body>
</html>

View File

@ -109,13 +109,15 @@
<div class="mui-row"> <div class="mui-row">
<!--头部信息开始--> <!--头部信息开始-->
<div class="head flex mui-row"> <div class="head flex mui-row">
<div class="mui-col-xs-5" style="display:flex;align-items: center;"> <div class="mui-col-xs-6" style="display:flex;align-items: center;">
<button class="btnc mui-btn-inline mui-btn-danger" onclick="handleBackMain()">返回</button>
<button id='showUserPicker' class="btnc mui-btn-inline mui-btn-primary" type='button'>请选择设备</button> <button id='showUserPicker' class="btnc mui-btn-inline mui-btn-primary" type='button'>请选择设备</button>
<text id='batchName' style="font-size: x-large;margin-left:15px;font-weight: 900;"></text> <text id='batchName' style="font-size: x-large;margin-left:15px;font-weight: 900;"></text>
<button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="refreshDayPlan()">更新计划</button> <button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="refreshDayPlan()">更新计划</button>
<!-- <button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="reloadPage()">刷新页面</button> --> <!-- <button class="btnc mui-btn-inline mui-btn-primary" type='button' onclick="reloadPage()">刷新页面</button> -->
</div> </div>
<div class="mui-col-xs-7" style="display:flex;justify-content: flex-end;"> <div class="mui-col-xs-6" style="display:flex;justify-content: flex-end;">
<button class="btnc mui-btn-inline mui-btn-danger" onclick="closeApp()" type='button'>关闭系统</button> <button class="btnc mui-btn-inline mui-btn-danger" onclick="closeApp()" type='button'>关闭系统</button>
<button id="driveName" class="btnc mui-btn-info" type="button" onclick="handleBackSys()">机车手</button> <button id="driveName" class="btnc mui-btn-info" type="button" onclick="handleBackSys()">机车手</button>
<button id='wifiDom' class="btnc mui-btn-inline mui-btn-info" <button id='wifiDom' class="btnc mui-btn-inline mui-btn-info"
@ -210,7 +212,7 @@
var textInterval = null; var textInterval = null;
var echartsType = ''; var echartsType = '';
var weightStatus = true; var weightStatus = true;
var IFlyVoice = null; // var IFlyVoice = null;
var text = ''; var text = '';
var speed = '30'; var speed = '30';
var zfk; var zfk;
@ -253,8 +255,8 @@
clearInterval(resultInterval); clearInterval(resultInterval);
clearInterval(totalInterval); clearInterval(totalInterval);
clearInterval(textInterval); clearInterval(textInterval);
IFlyVoice = api.require('IFlyVoice'); // IFlyVoice = api.require('IFlyVoice');
IFlyVoice.initSpeechSynthesizer(function (ret) { // IFlyVoice.initSpeechSynthesizer(function (ret) {
// textInterval = setInterval(function () { // textInterval = setInterval(function () {
// console.log(text); // console.log(text);
// if (text.length > 0) { // if (text.length > 0) {
@ -263,24 +265,22 @@
// speed = '30'; // speed = '30';
// } // }
// }, 2000); // }, 2000);
}); // });
initPage(); initPage();
setTimeout(function(){
initService() initService()
},1000) // api.addEventListener({
api.addEventListener({ // name: 'keyback'
name: 'keyback' // }, function (ret, err) {
}, function (ret, err) { // mui.confirm('确认关闭TMR饲喂系统', '提示', btnArray, function (e) {
mui.confirm('确认关闭TMR饲喂系统', '提示', btnArray, function (e) { // if (e.index == 0) {} else {
if (e.index == 0) {} else { // api.closeWidget({
api.closeWidget({ // id: api.appId, //应用ID
id: api.appId, //应用ID // retData: { name: 'closeWidget' },
retData: { name: 'closeWidget' }, // silent: true
silent: true // });
}); // }
} // });
}); // });
});
}; };
function rescan(){ function rescan(){
@ -637,7 +637,14 @@ function getDateStr(date) {
allow = json[0].allow; allow = json[0].allow;
// 计划 // 计划
_planSum = json[0].weight.toFixed(0); _planSum = json[0].weight.toFixed(0);
allowAuto = _planSum >= 100; renderUnload();
feedMyChart.setOption({
dataset: {
source: [[1, _feedNum]]
}
});
// 误差小于100必须校准才能自动跳转
allowAuto = false;
document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>'; document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
text = feedName + _planSum; text = feedName + _planSum;
batchName = e.className + e.trainNumber; batchName = e.className + e.trainNumber;
@ -709,12 +716,26 @@ function getDateStr(date) {
networkStatus = true; networkStatus = true;
api.hideProgress(); api.hideProgress();
document.getElementById('text').innerHTML = '设备初始化成功'; document.getElementById('text').innerHTML = '设备初始化成功';
sbId = ret.data[0].sbId; var initsb = api.getPrefs({
document.getElementById('showUserPicker').innerHTML = ret.data[0].name; sync: true,
key: 'initsb'
});
ret.data.forEach(function (e) { ret.data.forEach(function (e) {
if (initsb === e.name){
var json = { value: e.sbId, text: e.name }; var json = { value: e.sbId, text: e.name };
pickData.push(json); pickData.push(json);
}
}); });
ret.data.forEach(function (e) {
if (initsb !== e.name){
var json = { value: e.sbId, text: e.name };
pickData.push(json);
}
});
// sbId = ret.data[0].sbId;
// document.getElementById('showUserPicker').innerHTML = ret.data[0].name;
sbId = pickData[0].value;
document.getElementById('showUserPicker').innerHTML = pickData[0].text;
muiInit(); muiInit();
initTime(); initTime();
} else { } else {
@ -727,11 +748,16 @@ function getDateStr(date) {
} }
// 刷新页面 // 刷新页面
function reloadPage() { function reloadPage() {
mui.confirm('确认重新初始化页面么?', '提示', btnArray, function (e) { api.openWin({
if (e.index == 0) {} else { name: 'collection',
getWifiInfo(); reload:true,
} url:'../html/collection.html'
}); })
// mui.confirm('确认重新初始化页面么?', '提示', btnArray, function (e) {
// if (e.index == 0) {} else {
// getWifiInfo();
// }
// });
} }
var sid; var sid;
// 获取WiFi信息并刷新页面数据 // 获取WiFi信息并刷新页面数据

View File

@ -59,7 +59,7 @@ export default {
api.openWin({ api.openWin({
name: 'index', name: 'index',
reload:true, reload:true,
url:'../html/index1.html' url:'../html/index.html'
}) })
} }
}, },
@ -263,7 +263,7 @@ export default {
api.openWin({ api.openWin({
name: 'index', name: 'index',
reload:true, reload:true,
url:'../html/index1.html' url:'../html/index.html'
}) })
// if (ret.loginUser.sourceCow !=2 ) { // if (ret.loginUser.sourceCow !=2 ) {
// api.openWin({ // api.openWin({

View File

@ -3,7 +3,6 @@
function initManager(param) { function initManager(param) {
ble.initManager(param, function (ret) { ble.initManager(param, function (ret) {
if (ret.state === "poweredOn") { if (ret.state === "poweredOn") {
// console.log("初始化成功");
scan({clean: true}); scan({clean: true});
} else if (ret.state === 'poweredOff') { } else if (ret.state === 'poweredOff') {
api.hideProgress(); api.hideProgress();
@ -46,6 +45,7 @@ function scan(param) {
modal: true modal: true
}); });
}else { }else {
stopScan()
clearInterval(scanInter) clearInterval(scanInter)
getPeripheral(); getPeripheral();
} }
@ -53,6 +53,11 @@ function scan(param) {
} }
}); });
} }
function stopScan(){
ble.stopScan()
}
/*获取扫描结果*/ /*获取扫描结果*/
function getPeripheral() { function getPeripheral() {
ble.getPeripheral(function (ret) { ble.getPeripheral(function (ret) {
@ -126,12 +131,22 @@ function connect(param) {
document.getElementById('text').innerHTML = '设备已连接'; document.getElementById('text').innerHTML = '设备已连接';
text = '设备已连接'; text = '设备已连接';
console.log('主机端连接成功') console.log('主机端连接成功')
ble.setMtu({
peripheralUUID: param.peripheralUUID,
mtu:50
},function(ret){
if(ret.status){
initWeight(); initWeight();
discoverService({peripheralUUID: param.peripheralUUID}); discoverService({peripheralUUID: param.peripheralUUID});
}else{
mui.alert(ret.code)
}
});
}else { }else {
connetcedStatus = false connetcedStatus = false
connectTimes ++; connectTimes ++;
console.log('主机端连接失败'+connectTimes+' '+uuid) console.log('主机端连接失败'+connectTimes+' '+uuid)
addNotice(sbId + '主机端连接失败'+connectTimes+'次 '+uuid);
wifiDom.innerHTML = '连接失败'; wifiDom.innerHTML = '连接失败';
api.hideProgress(); api.hideProgress();
setTimeout(function (){ setTimeout(function (){
@ -173,10 +188,11 @@ var serviceUUID =''
var characteristicUUID ='' var characteristicUUID =''
// 蓝牙待发送消息列表 // 蓝牙待发送消息列表
var msgList = []; var msgList = [];
var timerMsgList = null;
// 清除消息定时任务 // 清除消息定时任务
clearInterval(timerMsgList) clearInterval(timerMsgList)
/*蓝牙消息发送定时任务150ms*/ /*蓝牙消息发送定时任务150ms*/
var timerMsgList = setInterval(function(){ timerMsgList = setInterval(function(){
// console.log(new Date().getSeconds()+ ' ' + new Date().getMilliseconds() +' ' + msgList.length) // console.log(new Date().getSeconds()+ ' ' + new Date().getMilliseconds() +' ' + msgList.length)
if (msgList.length > 0) { if (msgList.length > 0) {
// 发送报文 // 发送报文
@ -186,7 +202,8 @@ var timerMsgList = setInterval(function(){
peripheralUUID: peripheralUUID, peripheralUUID: peripheralUUID,
serviceUUID: serviceUUID, serviceUUID: serviceUUID,
characteristicUUID: characteristicUUID, characteristicUUID: characteristicUUID,
value: msg value: msg,
writeType:'withoutResponse'
}; };
if(connetcedStatus && peripheralUUID && serviceUUID && characteristicUUID){ if(connetcedStatus && peripheralUUID && serviceUUID && characteristicUUID){
writeValueForCharacteristic(param1, function (ret) { writeValueForCharacteristic(param1, function (ret) {
@ -195,6 +212,7 @@ var timerMsgList = setInterval(function(){
} }
} }
},150) },150)
// 未装料状态计数采集达到10次发送一次停止蜂鸣指令 // 未装料状态计数采集达到10次发送一次停止蜂鸣指令
var bleConunt=0; var bleConunt=0;
// 默认不自动跳转 // 默认不自动跳转
@ -212,6 +230,10 @@ function discoverService(param) {
serviceUUID: ret4, serviceUUID: ret4,
peripheralUUID: param.peripheralUUID peripheralUUID: param.peripheralUUID
}, function (ret5) { }, function (ret5) {
if(ret5.indexOf("0000ffe2")!==-1){
return false
}
console.log(ret5)
peripheralUUID = param.peripheralUUID; peripheralUUID = param.peripheralUUID;
serviceUUID =ret4; serviceUUID =ret4;
characteristicUUID =ret5; characteristicUUID =ret5;
@ -226,8 +248,15 @@ function discoverService(param) {
return false return false
} }
nowWeight = ret6; nowWeight = ret6;
getMess({
peripheralUUID: param.peripheralUUID,
serviceUUID: ret4,
characteristicUUID: ret5,
value: ret6
}, function (ret7) {
});
// 装料状态 // 装料状态
if(feedStatus){ if(feedStatus && allowAuto){
if (first) { if (first) {
first = false; first = false;
beforeWeight = nowWeight; beforeWeight = nowWeight;
@ -249,18 +278,18 @@ function discoverService(param) {
} }
serviceUUID = ret4; serviceUUID = ret4;
characteristicUUID = ret5; characteristicUUID = ret5;
// 组装led报文 // // 组装led报文
if (ledStatus && !isNaN(nowWeight)) { // if (ledStatus && !isNaN(nowWeight)) {
getMess({ // // getMess({
peripheralUUID: param.peripheralUUID, // // peripheralUUID: param.peripheralUUID,
serviceUUID: ret4, // // serviceUUID: ret4,
characteristicUUID: ret5, // // characteristicUUID: ret5,
value: ret6 // // value: ret6
}, function (ret7) { // // }, function (ret7) {
}); // // });
} // }
// 装料状态 // 装料状态
if(feedStatus){ if(feedStatus && allowAuto){
// 计划-饲喂 // 计划-饲喂
var feedErr = _planSum-_feedNum; var feedErr = _planSum-_feedNum;
if (isNaN(feedErr)) { if (isNaN(feedErr)) {
@ -293,7 +322,6 @@ function discoverService(param) {
} else if (0.1 < ration && ration <= 0.2) { } else if (0.1 < ration && ration <= 0.2) {
time = "05"; time = "05";
if (!statusEle || lastTime !== time) { if (!statusEle || lastTime !== time) {
console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
lastTime = time; lastTime = time;
ledStatus = false; ledStatus = false;
status = '间隔'; status = '间隔';
@ -308,7 +336,6 @@ function discoverService(param) {
} else if (0.05 < ration && ration <= 0.1) { } else if (0.05 < ration && ration <= 0.1) {
time = "03"; time = "03";
if (!statusEle || lastTime !== time) { if (!statusEle || lastTime !== time) {
console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
lastTime = time; lastTime = time;
ledStatus = false; ledStatus = false;
status = '间隔'; status = '间隔';
@ -323,7 +350,6 @@ function discoverService(param) {
} else if (0.02 < ration && ration <= 0.05) { } else if (0.02 < ration && ration <= 0.05) {
time = "01"; time = "01";
if (!statusEle || lastTime !== time) { if (!statusEle || lastTime !== time) {
console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
lastTime = time; lastTime = time;
ledStatus = false; ledStatus = false;
status = '间隔'; status = '间隔';
@ -337,7 +363,6 @@ function discoverService(param) {
} }
} else { } else {
if (status === '间隔' || status === '') { if (status === '间隔' || status === '') {
console.log(feedErr + ' ' + allow + ' ' + _feedNum + ' ' + _planSum);
ledStatus = false; ledStatus = false;
status = '长鸣'; status = '长鸣';
statusEle = true; statusEle = true;
@ -422,7 +447,6 @@ function StringToNum(hexx){
/*监听蓝牙数据,转换重量数据*/ /*监听蓝牙数据,转换重量数据*/
function setNotify(param, callback) { function setNotify(param, callback) {
ble.setNotify(param, function (ret) { ble.setNotify(param, function (ret) {
// console.log(JSON.stringify(ret))
var value = ret.characteristic.value; var value = ret.characteristic.value;
// if (ret && value.indexOf('ff01') !== -1) { // if (ret && value.indexOf('ff01') !== -1) {
if (ret && value.substr(0,4) === 'ff01') { if (ret && value.substr(0,4) === 'ff01') {
@ -434,11 +458,11 @@ function setNotify(param, callback) {
callback(wei); callback(wei);
}); });
} }
/*发送消息到蓝牙*/ /*发送消息到蓝牙*/
function writeValueForCharacteristic(param, callback) { function writeValueForCharacteristic(param, callback) {
if (param.value && connetcedStatus){ if (param.value && connetcedStatus){
ble.writeValueForCharacteristic(param, function (ret) { ble.writeValueForCharacteristic(param, function (ret) {
// console.log(JSON.stringify(ret));
if (ret.status) { if (ret.status) {
// console.log("发送成功"); // console.log("发送成功");
} else { } else {
@ -450,7 +474,7 @@ function writeValueForCharacteristic(param, callback) {
} }
var lastTime = new Date().getSeconds()*1000+ new Date().getMilliseconds(); var lastTime = new Date().getSeconds()*1000+ new Date().getMilliseconds();
// 接收重量数据计数 // 接收重量数据计数
var count = 0; var countLED = 0;
/*组装报文并发数*/ /*组装报文并发数*/
function getMess(param, callback) { function getMess(param, callback) {
var param1 = { var param1 = {
@ -509,22 +533,22 @@ function getMess(param, callback) {
param1.msg = newmsg + Math.abs(Number(_planSum - _feedNum)).toFixed(0) + 'kg'; param1.msg = newmsg + Math.abs(Number(_planSum - _feedNum)).toFixed(0) + 'kg';
} }
// param1.msg = newmsg + Math.abs(Number(param.value)).toFixed(0) + 'kg' // param1.msg = newmsg + Math.abs(Number(param.value)).toFixed(0) + 'kg'
console.log(param1.msg) // console.log(param1.msg)
//组装字符卡LED报文 //组装字符卡LED报文
zfk.getMsg(param1, function (ret, err) { zfk.getMsg(param1, function (ret, err) {
var str = ret.sendMsg; var str = ret.sendMsg;
str = str.replace(/\s+/g, ""); str = str.replace(/\s+/g, "");
var num = str.length / 2; var num = str.length / 2;
param.value = "FF0500" + num.toString(16) + str; param.value = "FF0500" + num.toString(16) + str;
count ++; countLED ++;
// 称重量数据3包取1包 // 称重量数据3包取1包
if (count >= 3){ if (countLED >= 3){
msgList.push(param.value); msgList.push(param.value);
// var ms = strToHex(sbId,4)+strToHex(classCode,2)+strToHex(trainNumber,2)+strToHex(feedIndex,2)+strToHex(_planSum,4)+strToHex(_feedNum,4)+strToHex(nowWeight,4); // var ms = strToHex(sbId,4)+strToHex(classCode,2)+strToHex(trainNumber,2)+strToHex(feedIndex,2)+strToHex(_planSum,4)+strToHex(_feedNum,4)+strToHex(nowWeight,4);
// var num1 = ms.length / 2; // var num1 = ms.length / 2;
// 同步刷新图表 // 同步刷新图表
// 饲喂状态刷新实时状态,否则不刷新装料信息 // 饲喂状态刷新实时状态,否则不刷新装料信息
if(feedStatus){ if(feedStatus && allowAuto){
renderUnload(); renderUnload();
feedMyChart.setOption({ feedMyChart.setOption({
dataset: { dataset: {
@ -538,7 +562,7 @@ function getMess(param, callback) {
source: [[1, nowWeight]] source: [[1, nowWeight]]
} }
}); });
count = 0 ; countLED = 0 ;
} }
}); });
} }

View File

@ -173,8 +173,14 @@ function submitData() {
document.querySelector('#feed_' + feedIndex).scrollIntoView(true); document.querySelector('#feed_' + feedIndex).scrollIntoView(true);
allow = feedList[feedIndex].allow; allow = feedList[feedIndex].allow;
_planSum = feedList[feedIndex].weight.toFixed(0); _planSum = feedList[feedIndex].weight.toFixed(0);
renderUnload();
feedMyChart.setOption({
dataset: {
source: [[1, _feedNum]]
}
});
// 误差小于100必须校准才能自动跳转 // 误差小于100必须校准才能自动跳转
allowAuto = _planSum >= 100; allowAuto = false;
text = feedName + _planSum; text = feedName + _planSum;
document.getElementById('nowFeed').innerHTML = '<font style="color:blue;margin-left:10px;">' + batchName + ',' + feedName + '</font>'; document.getElementById('nowFeed').innerHTML = '<font style="color:blue;margin-left:10px;">' + batchName + ',' + feedName + '</font>';
ledStatus = false; ledStatus = false;
@ -595,24 +601,30 @@ function hex2a(hexx) {
}return str; }return str;
} }
function speakTest(text, speed) { // function speakTest(text, speed) {
// IFlyVoice.stopSpeaking(); // // IFlyVoice.stopSpeaking();
IFlyVoice.startSynthetic({ // IFlyVoice.startSynthetic({
text: text, // text: text,
commonPath_Android: 'widget://res/aisound/common.jet', // commonPath_Android: 'widget://res/aisound/common.jet',
pronouncePath_Android: 'widget://res/aisound/xiaofeng.jet', // pronouncePath_Android: 'widget://res/aisound/xiaofeng.jet',
commonPath_iOS: 'widget://res/aisound/common.jet', // commonPath_iOS: 'widget://res/aisound/common.jet',
pronouncePath_iOS: 'widget://res/aisound/xiaofeng.jet', // pronouncePath_iOS: 'widget://res/aisound/xiaofeng.jet',
pronounceName: 'xiaofeng', // pronounceName: 'xiaofeng',
volume: '100', // volume: '100',
speed: speed // speed: speed
}, function (ret, err) { // }, function (ret, err) {
if (ret.status) { // if (ret.status) {
console.log('合成成功'); // console.log('合成成功');
} else {} // } else {}
// });
// }
function handleBackMain() {
mui.confirm('确认返回到首页?', '提示', btnArray, function (e) {
if (e.index == 0) {} else {
api.closeWin();
}
}); });
} }
function closeApp() { function closeApp() {
mui.confirm('确认关闭TMR饲喂系统', '提示', btnArray, function (e) { mui.confirm('确认关闭TMR饲喂系统', '提示', btnArray, function (e) {
if (e.index == 0) {} else { if (e.index == 0) {} else {
@ -656,7 +668,6 @@ var WeightDataFilter = function () {
this.dataBuffer.shift(); this.dataBuffer.shift();
} }
var filteredValue = this.getAverageValue(); var filteredValue = this.getAverageValue();
// console.log(filteredValue,Math.abs(filteredValue - this.lastValidValue),this.maxDeviation);
if (isNaN(this.lastValidValue) || Math.abs(filteredValue - this.lastValidValue) <= this.maxDeviation) { if (isNaN(this.lastValidValue) || Math.abs(filteredValue - this.lastValidValue) <= this.maxDeviation) {
this.lastValidValue = filteredValue; this.lastValidValue = filteredValue;
return filteredValue; return filteredValue;