我正在从硬件传感器读取原始加速度,并计算每秒读取传感器的次数。
下面是我正在做的非常基本的例子。我在// Holds all windows
private windows!: [string,BrowserWindow][];
/**
* Creates a browser window and returns it.
* Note: The window will auto .show() when returned
*
* @param windowView View name to be loaded
* @param windowOptions BrowserWindow options
*/
public createWindow(windowView:string, windowOptions?:BrowserWindowConstructorOptions): BrowserWindow {
// Instantiates the BrowserWindow
let window = new BrowserWindow(windowOptions)
// Loads the view into the BrowserWindow
window.loadFile(this.VIEWS_PATH + '/' + windowView + this.VIEWS_EXTENSION)
// Adds view and window to BrowserWindow tupple array for futher use
this.windows.push([windowView, window])
// Closes and deletes this specific BrowserWindow from the BrowserWindow tupple array
window.on('close', (event) => {
console.log('deleted', event.sender.id)
this.deleteWindow(undefined, event.sender.id)
})
return window
}
中获得了传感器,并在/**
* Creates a browser window and returns it.
* Note: The window will auto .show() when returned
*
* @param windowView View name to be loaded
* @param windowOptions BrowserWindow options
*/
createWindow(windowView, windowOptions) {
// Instantiates the BrowserWindow
let window = new electron_1.BrowserWindow(windowOptions);
// Loads the view into the BrowserWindow
window.loadFile(this.VIEWS_PATH + '/' + windowView + this.VIEWS_EXTENSION);
// Adds view and window to BrowserWindow tupple array for futher use
this.windows.push([windowView, window]);
// Closes and deletes this specific BrowserWindow from the BrowserWindow tupple array
window.on('close', (event) => {
console.log('deleted', event.sender.id);
this.deleteWindow(undefined, event.sender.id);
});
return window;
}
中注册了一个侦听器,在这里我选择了首选的轮询速率,在这种情况下为onCreate()
(我知道这只是一个建议,可以通过以下方式进行更改操作系统)。在onResume()
中,我检查事件是否确实来自加速度计。在这里,我有一个小片段,用于计数和记录每秒的样本数量。
这是我不了解的部分:在Galaxy S10(Android 9.0)上,无论选择哪种轮询速率,我每秒都能获得6个样本。在其他设备(例如Huawei Honor,Galaxy S5)上,使用SENSOR_DELAY_FASTEST
可以得到每秒50个样本,而使用onSensorChanged()
可以得到更快的速度。
有什么办法可以影响我呢?每秒6个样本对我的应用来说太低了。
我已经在我的设备上关闭了此应用的应用优化。这没有解决我的问题。值得注意的是,陀螺仪在此设备上每秒更新100次。
SENSOR_DELAY_GAME