Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the function of state transfer of monitoring points by WeChat Mini Programs's position alarm in actual combat

Shulou Source: shulou.com Published: 2022-06-01 20:34:13 09月21日 Update

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.

Tags: Status elements monitoring points programs monitoring arrays locations actual combat alarms content more help functions good appropriate code interests functions boys buddies Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn Docker Microsoft Shulou Tech Info