mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-05 18:20:33 -08:00
add snippet 'sensor-reading'
This commit is contained in:
parent
5a39941fac
commit
22c92da97c
3 changed files with 56 additions and 0 deletions
23
snippets/sensor-reading/qml/main.qml
Normal file
23
snippets/sensor-reading/qml/main.qml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import QtQuick 2.15
|
||||
import QtSensors 5.15
|
||||
|
||||
Rectangle {
|
||||
width: 300
|
||||
height: 500
|
||||
|
||||
Accelerometer {
|
||||
id: accel
|
||||
active: true
|
||||
accelerationMode: Accelerometer.User // exclude gravity
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
interval: 50
|
||||
repeat: true
|
||||
running: true
|
||||
|
||||
onTriggered: Lisp.call("qml-user:accel-changed",
|
||||
accel.reading.x, accel.reading.y, accel.reading.z)
|
||||
}
|
||||
}
|
||||
5
snippets/sensor-reading/readme.md
Normal file
5
snippets/sensor-reading/readme.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Description
|
||||
-----------
|
||||
|
||||
Shows how to read sensor data with a timer, plus a trivial low-pass filter.
|
||||
|
||||
28
snippets/sensor-reading/run.lisp
Normal file
28
snippets/sensor-reading/run.lisp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
(in-package :qml-user)
|
||||
|
||||
;;; low-pass filter
|
||||
|
||||
(defun make-low-pass-filter (&optional (alpha 0.02))
|
||||
(let ((a alpha)
|
||||
filtered)
|
||||
(lambda (value)
|
||||
(setf filtered (if filtered
|
||||
(+ (* value a)
|
||||
(* filtered (- 1.0 a)))
|
||||
value)))))
|
||||
|
||||
(defvar *accel-x* (make-low-pass-filter))
|
||||
(defvar *accel-y* (make-low-pass-filter))
|
||||
(defvar *accel-z* (make-low-pass-filter))
|
||||
|
||||
;;; sensor data
|
||||
|
||||
(defun hr (x)
|
||||
"Human readable."
|
||||
(floor (+ 0.5 (* 1000 x))))
|
||||
|
||||
(defun accel-changed (x y z)
|
||||
(qlog :x (hr (funcall *accel-x* x)))
|
||||
(qlog :y (hr (funcall *accel-y* y)))
|
||||
(qlog :z (hr (funcall *accel-z* z))))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue