README.md 5,1 КБ
Newer Older
Зарубин Виталий Викторович's avatar
Зарубин Виталий Викторович включено в состав коммита
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Sensors Info

The library allows access to sensor data.

### Features:

- Listen state sensor Accelerometer.
- Listen state sensor AmbientLight.
- Listen state sensor Compass.
- Listen state sensor Gyroscope.
- Listen state sensor Magnetometer.
- Listen state sensor Orientation.
- Listen state sensor Pressure.
- Listen state sensor Proximity.
- Listen state sensor Rotation.
- Listen state sensor Tap.
Зарубин Виталий Викторович's avatar
Зарубин Виталий Викторович включено в состав коммита
17

Зарубин Виталий Викторович's avatar
Зарубин Виталий Викторович включено в состав коммита
18
19
20
21
22
23
24
25
26
27
28
### Permissions

```
Permissions=Sensors
```

### Dependency

- `BuildRequires: pkgconfig(Qt5Sensors)`
- `QT += sensors`

Зарубин Виталий Викторович's avatar
Зарубин Виталий Викторович включено в состав коммита
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
### Example

```kotlin
var statesAccelerometer: MutableMap<ULong, AccelerometerState> = mutableMapOf()
var statesAmbientLight: MutableMap<ULong, AmbientLightSensorState> = mutableMapOf()
var statesCompass: MutableMap<ULong, CompassState> = mutableMapOf()
var statesGyroscope: MutableMap<ULong, GyroscopeState> = mutableMapOf()
var statesMagnetometer: MutableMap<ULong, MagnetometerState> = mutableMapOf()
var statesOrientation: MutableMap<ULong, OrientationState> = mutableMapOf()
var statesPressure: MutableMap<ULong, PressureState> = mutableMapOf()
var statesProximity: MutableMap<ULong, ProximityState> = mutableMapOf()
var statesRotation: MutableMap<ULong, RotationState> = mutableMapOf()
var statesTap: MutableMap<ULong, TapState> = mutableMapOf()

class AuroraSensorsInfo {

    // Accelerometer
    fun listenAccelerometer(): ULong {
        return SensorsInfo.accelerometer.listen { id, value ->
            statesAccelerometer.put(id, value)
        }
    }

    fun getStateAccelerometer(id: ULong): String {
        return statesAccelerometer[id]?.let { """
                x: ${it.x.toString().take(12)}
                y: ${it.y.toString().take(12)}
                z: ${it.z.toString().take(12)}
            """.trimIndent() } ?: "-"
    }

    // AmbientLight
    fun listenAmbientLight(): ULong {
        return SensorsInfo.ambientLight.listen { id, value ->
            statesAmbientLight.put(id, value)
        }
    }

    fun getStateAmbientLight(id: ULong): String {
        return statesAmbientLight[id]?.name ?: "-"
    }

    // Compass
    fun listenCompass(): ULong {
        return SensorsInfo.compass.listen { id, value ->
            statesCompass.put(id, value)
        }
    }

    fun getStateCompass(id: ULong): String {
        return statesCompass[id]?.let { """
                azimuth: ${it.azimuth.toString().take(12)}
                level: ${it.calibrationLevel.toString().take(12)}
            """.trimIndent() } ?: "-"
    }

    // Gyroscope
    fun listenGyroscope(): ULong {
        return SensorsInfo.gyroscope.listen { id, value ->
            statesGyroscope.put(id, value)
        }
    }

    fun getStateGyroscope(id: ULong): String {
        return statesGyroscope[id]?.let { """
                x: ${it.x.toString().take(12)}
                y: ${it.y.toString().take(12)}
                z: ${it.z.toString().take(12)}
            """.trimIndent() } ?: "-"
    }

    // Magnetometer
    fun listenMagnetometer(): ULong {
        return SensorsInfo.magnetometer.listen { id, value ->
            statesMagnetometer.put(id, value)
        }
    }

    fun getStateMagnetometer(id: ULong): String {
        return statesMagnetometer[id]?.let { """
                x: ${it.x.toString().take(12)}
                y: ${it.y.toString().take(12)}
                z: ${it.z.toString().take(12)}
            """.trimIndent() } ?: "-"
    }

    // Orientation
    fun listenOrientation(): ULong {
        return SensorsInfo.orientation.listen { id, value ->
            statesOrientation.put(id, value)
        }
    }

    fun getStateOrientation(id: ULong): String {
        return statesOrientation[id]?.name ?: "-"
    }

    // Pressure
    fun listenPressure(): ULong {
        return SensorsInfo.pressure.listen { id, value ->
            statesPressure.put(id, value)
        }
    }

    fun getStatePressure(id: ULong): String {
        return statesPressure[id]?.let { """
                pressure: ${it.pressure.toString().take(12)}
            """.trimIndent() } ?: "-"
    }

    // Proximity
    fun listenProximity(): ULong {
        return SensorsInfo.proximity.listen { id, value ->
            statesProximity.put(id, value)
        }
    }

    fun getStateProximity(id: ULong): String {
        return statesProximity[id]?.let { """
                isClose: ${it.isClose}
            """.trimIndent() } ?: "-"
    }

    // Rotation
    fun listenRotation(): ULong {
        return SensorsInfo.rotation.listen { id, value ->
            statesRotation.put(id, value)
        }
    }

    fun getStateRotation(id: ULong): String {
        return statesRotation[id]?.let { """
                x: ${it.x.toString().take(12)}
                y: ${it.y.toString().take(12)}
                z: ${it.z.toString().take(12)}
            """.trimIndent() } ?: "-"
    }

    // Tap
    fun listenTap(): ULong {
        return SensorsInfo.tap.listen { id, value ->
            statesTap.put(id, value)
        }
    }

    fun getStateTap(id: ULong): String {
        return statesTap[id]?.let { """
                direction: ${it.tapDirection.toString().take(12)}
                isDouble: ${it.isDoubleTap.toString().take(12)}
            """.trimIndent() } ?: "-"
    }
}
```