In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces WeChat Mini Programs's position alarm in the actual combat how to achieve the monitoring point state transfer function, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Approaching the monitoring point.
EnterAlarmCheck: function (distance, accuracy) {
If (this.state = = 'ready') {
/ / 500m
If (distance
< 500) { this.checkBuffer.push(1) } else { this.checkBuffer.push(-1) } if (this.checkBuffer.length >CHECK_BUFFER_SIZE) {
This.checkBuffer.shift ()
}
Var sum = this.checkBuffer.reduce (function (xQuery y) {return x + y}, 0)
If (sum = = CHECK_BUFFER_SIZE) {
This.setState ('armed')
}
} else if (this.state = = 'armed') {
/ / 100m
If (distance
< 100) { this.checkBuffer.push(1) } else if (distance >500) {
This.checkBuffer.push (- 1)
}
If (this.checkBuffer.length > CHECK_BUFFER_SIZE) {
This.checkBuffer.shift ()
}
Var sum = this.checkBuffer.reduce (function (x, y) {return x + y}, 0)
If (sum = = CHECK_BUFFER_SIZE) {
This.setState ('fired')
} else if (sum = =-CHECK_BUFFER_SIZE) {
This.setState ('ready')
}
} else if (this.state = = 'fired') {/ / fired
This.checkBuffer.push (1)
If (this.checkBuffer.length = = 10) {
This.setState ('accepted')
}
} else {
If (distance > 100) {
This.checkBuffer.push (1)
} else {
This.checkBuffer.push (- 1)
}
If (this.checkBuffer.length > CHECK_BUFFER_SIZE) {
This.checkBuffer.shift ()
}
Var sum = this.checkBuffer.reduce (function (x, y) {return x + y}, 0)
If (sum = = CHECK_BUFFER_SIZE) {
This.setState ('ready')
}
}
}
Supplementary explanation
Perhaps the most difficult thing to understand in the code is not the state transition itself, but the use of arrays. Here is a brief explanation.
Push: add elements at the end of the data
Shift: removes an element from the beginning of an array
Reduce: the function itself provides the result of the last operation and operates on each element one by one, which is used as the sum of all the elements of the array.
Looking back, I believe the program is easy to understand.
The latest state diagram
In the process of realizing the state transition, the state diagram has also been modified appropriately, and the following is the latest state diagram.
On WeChat Mini Programs actual combat location alarm how to achieve the monitoring point state transfer function is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.