on xenial help sign in
even better velocity calc
76cbe21Nick Dedekind
qml/Panel/PanelVelocityCalculator.qml+9−12
@@ -32,17 +32,21 @@ Item {
32 }
32 }
33
33
34 function update() {
34 function update() {
35+ var previouslyStopped = stopLateralChanges;
36+
35 calc.trackedPosition = trackedValue;
37 calc.trackedPosition = trackedValue;
36 stopLateralChanges = Math.abs(calc.calculate()) > velocityThreshold;
38 stopLateralChanges = Math.abs(calc.calculate()) > velocityThreshold;
37− }
38
39
39− onTrackedValueChanged: {
40− update(); // initial calculation
41− if (root.stopLateralChanges) { // only start timer if we're above the threshold.
40+ if (stopLateralChanges) { // only start timer if we're above the threshold.
42 velocityTimer.start();
41 velocityTimer.start();
42+ } else if (previouslyStopped) { // if we have previously been stopped, then trigger the signal
43+ velocityTimer.stop();
44+ velocityThresholdTriggered();
43 }
45 }
44 }
46 }
45
47
48+ onTrackedValueChanged: update();
49+
46 AxisVelocityCalculator {
50 AxisVelocityCalculator {
47 id: calc
51 id: calc
48 }
52 }
@@ -50,13 +54,6 @@ Item {
50 Timer {
54 Timer {
51 id: velocityTimer
55 id: velocityTimer
52 interval: 50
56 interval: 50
53− onTriggered: {
57+ onTriggered: update();
54− update();
55− if (root.stopLateralChanges) {
56− velocityTimer.start();
57− } else {
58− velocityThresholdTriggered();
59− }
60− }
61 }
58 }
62}
59}