修改样式,小于100的饲料不点击校准不自动跳转,班次完成一直显示饲喂完成,车内总重量实时显示,led屏幕一直显示班次完成

This commit is contained in:
liuwu 2023-11-01 10:48:09 +08:00
parent 03cfb549bb
commit ab1b5f183e
3 changed files with 178 additions and 135 deletions

View File

@ -496,10 +496,6 @@ function getDateStr(date) {
console.log('蓝牙'+JSON.stringify(items[0]));
showBlePickerButton.innerHTML = items[0].text;
uuid = items[0].value
api.setPrefs({
key: 'uuid',
value: uuid
});
connect({peripheralUUID: items[0].value});
});
}, false);
@ -621,7 +617,7 @@ function getDateStr(date) {
var json = [].concat(_toConsumableArray(e.feedJson), _toConsumableArray(e.cowshedJson));
feedList = json;
json.forEach(function (j, index) {
if (index == 0) {
if (index === 0) {
html += '<span id="feed_' + index + '" class="mui-badge mui-badge-purple" style="font-size: xx-large;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
} else {
html += '<span id="feed_' + index + '" class="mui-badge" style="font-size: xx-large;font-weight: 900;">' + UNICODE_CHARS[index + 1] + j.name + ':' + Number(j.weight).toFixed(0) + '</span>';
@ -641,6 +637,7 @@ function getDateStr(date) {
allow = json[0].allow;
// 计划
_planSum = json[0].weight.toFixed(0);
allowAuto = _planSum >= 100;
document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
text = feedName + _planSum;
batchName = e.className + e.trainNumber;

View File

@ -116,6 +116,11 @@ function connect(param) {
ble.connect(param, function (ret, err) {
if (ret.status) {
connetcedStatus = true
// 缓存蓝牙设备uuid方便自动连接
api.setPrefs({
key: 'uuid',
value: param.peripheralUUID
});
wifiDom.innerHTML = '已连接';
connectTimes = 0;
document.getElementById('text').innerHTML = '设备已连接';
@ -192,6 +197,8 @@ var timerMsgList = setInterval(function(){
},150)
// 未装料状态计数采集达到10次发送一次停止蜂鸣指令
var bleConunt=0;
// 默认不自动跳转
var allowAuto = false;
/*扫描蓝牙服务*/
function discoverService(param) {
ble.discoverService(param, function (ret) {
@ -214,15 +221,13 @@ function discoverService(param) {
serviceUUID: ret4,
characteristicUUID: ret5
}, function (ret6) {
if(!feedStatus){
return false
}
if (ret6 !== undefined) {
if (isNaN(ret6)) {
return false
}
nowWeight = ret6;
// console.log(ret6)
// 装料状态
if(feedStatus){
if (first) {
first = false;
beforeWeight = nowWeight;
@ -240,10 +245,10 @@ function discoverService(param) {
nowWeight: nowWeight
});
}
document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
}
serviceUUID = ret4;
characteristicUUID = ret5;
// console.log(_feedNum,_weightSum,_planSum);
document.getElementById('feedNum').innerHTML = '<font style="color:blue">:' + _planSum + '</font>/<font style="color:green">已装:' + _feedNum + '</font>';
// 组装led报文
if (ledStatus && !isNaN(nowWeight)) {
getMess({
@ -252,9 +257,10 @@ function discoverService(param) {
characteristicUUID: ret5,
value: ret6
}, function (ret7) {
// console.log(JSON.stringify(ret7))
});
}
// 装料状态
if(feedStatus){
// 计划-饲喂
var feedErr = _planSum-_feedNum;
if (isNaN(feedErr)) {
@ -351,8 +357,9 @@ function discoverService(param) {
}, 500)
}
}
// console.log(weightStabilization("weightStabilization"+nowWeight))
// 在误差范围内
if (feedErr <= allow) {
if (feedErr <= allow && allowAuto) {
// 重量稳定计数
var filteredValue = weightDataFilter.filter(nowWeight);
// 重量稳定自动跳转
@ -363,6 +370,7 @@ function discoverService(param) {
}
}
}
}
});
});
}
@ -483,7 +491,23 @@ function getMess(param, callback) {
} else {
newmsg = feedName + ttr;
}
// 不是装料状态班次饲喂完成显示
if(!feedStatus){
var newmsg = batchName+'次';
var msglen = newmsg.getByteLen();
var ttr = '';
if (msglen < 8) {
for (var i = 0; i < 8 - msglen; i++) {
newmsg = newmsg + ' ';
}
newmsg = newmsg + ttr;
} else {
newmsg = feedName + ttr;
}
param1.msg = newmsg + '饲喂完成';
}else{
param1.msg = newmsg + Math.abs(Number(_planSum - _feedNum)).toFixed(0) + 'kg';
}
// param1.msg = newmsg + Math.abs(Number(param.value)).toFixed(0) + 'kg'
// console.log(param1.msg)
//组装字符卡LED报文
@ -499,13 +523,16 @@ function getMess(param, callback) {
// 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;
// 同步刷新图表
// 饲喂状态刷新实时状态,否则不刷新装料信息
if(feedStatus){
renderUnload();
renderLoad();
feedMyChart.setOption({
dataset: {
source: [[1, _feedNum]]
}
});
}
renderLoad();
weightMyChart.setOption({
dataset: {
source: [[1, nowWeight]]
@ -559,3 +586,20 @@ function initWeight() {
document.getElementById('text').innerHTML = 'V' + api.appVersion;
api.setGlobalData({key: 'startTime', value: currTimeFn(new Date())});
}
var lastWeight = 0;
function weightStabilization(weight) {
// 计算当前重量与上一次记录的重量之间的差值
var diff = weight - lastWeight;
// 如果差值在一定范围内,则认为重量是稳定的
if (Math.abs(diff) < 2) {
weight = weight;
lastWeight = weight;
return true;
} else {
// 如果差值超过一定范围,则认为重量是不稳定的,重新开始计算
weight = 0;
lastWeight = weight;
return false;
}
}

View File

@ -172,6 +172,8 @@ function submitData() {
document.querySelector('#feed_' + feedIndex).scrollIntoView(true);
allow = feedList[feedIndex].allow;
_planSum = feedList[feedIndex].weight.toFixed(0);
// 误差小于100必须校准才能自动跳转
allowAuto = _planSum >= 100;
text = feedName + _planSum;
document.getElementById('nowFeed').innerHTML = '<font style="color:blue;margin-left:10px;">' + batchName + ',' + feedName + '</font>';
ledStatus = false;