forked from MapComplete/MapComplete
A11y: various improvements
This commit is contained in:
parent
0d4f2c9c36
commit
5fa2ddd9c1
23 changed files with 327 additions and 98 deletions
33
src/Sensors/Motion.ts
Normal file
33
src/Sensors/Motion.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { UIEventSource } from "../Logic/UIEventSource"
|
||||
|
||||
export default class Motion {
|
||||
public static singleton = new Motion()
|
||||
/**
|
||||
* In m/s²
|
||||
*/
|
||||
public maxAcc = new UIEventSource<number>(0)
|
||||
|
||||
public lastShakeEvent = new UIEventSource<Date>(undefined)
|
||||
|
||||
private isListening = false
|
||||
private constructor() {
|
||||
this.startListening()
|
||||
}
|
||||
|
||||
private onUpdate(eventData: DeviceMotionEvent) {
|
||||
const acc = eventData.acceleration
|
||||
this.maxAcc.setData(Math.max(acc.x, acc.y, acc.z))
|
||||
if (this.maxAcc.data > 22) {
|
||||
this.lastShakeEvent.setData(new Date())
|
||||
}
|
||||
}
|
||||
|
||||
startListening() {
|
||||
if (this.isListening) {
|
||||
return
|
||||
}
|
||||
this.isListening = true
|
||||
console.log("Listening to motion events", this)
|
||||
window.addEventListener("devicemotion", (e) => this.onUpdate(e))
|
||||
}
|
||||
}
|
|
@ -30,9 +30,13 @@ export class Orientation {
|
|||
*/
|
||||
public arrowDirection: UIEventSource<number> = new UIEventSource(undefined)
|
||||
private _measurementsStarted = false
|
||||
private _animateFakeMeasurements = false
|
||||
|
||||
constructor() {}
|
||||
constructor() {
|
||||
// this.fakeMeasurements(true)
|
||||
}
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
public fakeMeasurements(rotateAlpha: boolean = true) {
|
||||
console.log("Starting fake measurements of orientation sensors", {
|
||||
alpha: this.alpha,
|
||||
|
@ -41,10 +45,15 @@ export class Orientation {
|
|||
absolute: this.absolute,
|
||||
})
|
||||
this.alpha.setData(45)
|
||||
|
||||
if (rotateAlpha) {
|
||||
Stores.Chronic(25).addCallback((date) =>
|
||||
this.alpha.setData(-(date.getTime() / 10) % 360)
|
||||
)
|
||||
this._animateFakeMeasurements = true
|
||||
Stores.Chronic(25).addCallback((date) => {
|
||||
this.alpha.setData((date.getTime() / 100) % 360)
|
||||
if (!this._animateFakeMeasurements) {
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
this.beta.setData(20)
|
||||
this.gamma.setData(30)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue