Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: device/generic_sensor/android/java/src/org/chromium/device/sensors/PlatformSensor.java

Issue 2465363004: [Sensors] Consider maximum supported frequency (Closed)
Patch Set: Comment from Tim Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | device/generic_sensor/android/junit/src/org/chromium/device/sensors/PlatformSensorAndProviderTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.device.sensors; 5 package org.chromium.device.sensors;
6 6
7 import android.hardware.Sensor; 7 import android.hardware.Sensor;
8 import android.hardware.SensorEvent; 8 import android.hardware.SensorEvent;
9 import android.hardware.SensorEventListener; 9 import android.hardware.SensorEventListener;
10 import android.os.Build; 10 import android.os.Build;
11 11
12 import org.chromium.base.annotations.CalledByNative; 12 import org.chromium.base.annotations.CalledByNative;
13 import org.chromium.base.annotations.JNINamespace; 13 import org.chromium.base.annotations.JNINamespace;
14 import org.chromium.device.mojom.ReportingMode; 14 import org.chromium.device.mojom.ReportingMode;
15 15
16 import java.util.List; 16 import java.util.List;
17 17
18 /** 18 /**
19 * Implementation of PlatformSensor that uses Android Sensor Framework. Lifetime is controlled by 19 * Implementation of PlatformSensor that uses Android Sensor Framework. Lifetime is controlled by
20 * the device::PlatformSensorAndroid. 20 * the device::PlatformSensorAndroid.
21 */ 21 */
22 @JNINamespace("device") 22 @JNINamespace("device")
23 public class PlatformSensor implements SensorEventListener { 23 public class PlatformSensor implements SensorEventListener {
24 private static final double MICROSECONDS_IN_SECOND = 1000000; 24 private static final double MICROSECONDS_IN_SECOND = 1000000;
25 private static final double SECONDS_IN_MICROSECOND = 0.000001d;
25 private static final double SECONDS_IN_NANOSECOND = 0.000000001d; 26 private static final double SECONDS_IN_NANOSECOND = 0.000000001d;
26 27
27 /** 28 /**
28 * The SENSOR_FREQUENCY_NORMAL is defined as 5Hz which corresponds to a poll ing delay 29 * The SENSOR_FREQUENCY_NORMAL is defined as 5Hz which corresponds to a poll ing delay
29 * @see android.hardware.SensorManager.SENSOR_DELAY_NORMAL value that is def ined as 200000 30 * @see android.hardware.SensorManager.SENSOR_DELAY_NORMAL value that is def ined as 200000
30 * microseconds. 31 * microseconds.
31 */ 32 */
32 private static final double SENSOR_FREQUENCY_NORMAL = 5.0d; 33 private static final double SENSOR_FREQUENCY_NORMAL = 5.0d;
33 34
34 /** 35 /**
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 * Returns default configuration supported by the sensor. Currently only fre quency is supported. 118 * Returns default configuration supported by the sensor. Currently only fre quency is supported.
118 * 119 *
119 * @return double frequency. 120 * @return double frequency.
120 */ 121 */
121 @CalledByNative 122 @CalledByNative
122 protected double getDefaultConfiguration() { 123 protected double getDefaultConfiguration() {
123 return SENSOR_FREQUENCY_NORMAL; 124 return SENSOR_FREQUENCY_NORMAL;
124 } 125 }
125 126
126 /** 127 /**
128 * Returns maximum sampling frequency supported by the sensor.
129 *
130 * @return double frequency in Hz.
131 */
132 @CalledByNative
133 protected double getMaximumSupportedFrequency() {
134 if (mMinDelayUsec == 0) return getDefaultConfiguration();
135 return 1 / (mMinDelayUsec * SECONDS_IN_MICROSECOND);
136 }
137
138 /**
127 * Requests sensor to start polling for data. 139 * Requests sensor to start polling for data.
128 * 140 *
129 * @return boolean true if successful, false otherwise. 141 * @return boolean true if successful, false otherwise.
130 */ 142 */
131 @CalledByNative 143 @CalledByNative
132 protected boolean startSensor(double frequency) { 144 protected boolean startSensor(double frequency) {
133 // If we already polling hw with same frequency, do not restart the sens or. 145 // If we already polling hw with same frequency, do not restart the sens or.
134 if (mCurrentPollingFrequency == frequency) return true; 146 if (mCurrentPollingFrequency == frequency) return true;
135 147
136 // Unregister old listener if polling frequency has changed. 148 // Unregister old listener if polling frequency has changed.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 break; 231 break;
220 default: 232 default:
221 updateSensorReading(timestamp, event.values[0], event.values[1], event.values[2]); 233 updateSensorReading(timestamp, event.values[0], event.values[1], event.values[2]);
222 } 234 }
223 } 235 }
224 236
225 private native void nativeNotifyPlatformSensorError(long nativePlatformSenso rAndroid); 237 private native void nativeNotifyPlatformSensorError(long nativePlatformSenso rAndroid);
226 private native void nativeUpdatePlatformSensorReading(long nativePlatformSen sorAndroid, 238 private native void nativeUpdatePlatformSensorReading(long nativePlatformSen sorAndroid,
227 double timestamp, double value1, double value2, double value3); 239 double timestamp, double value1, double value2, double value3);
228 } 240 }
OLDNEW
« no previous file with comments | « no previous file | device/generic_sensor/android/junit/src/org/chromium/device/sensors/PlatformSensorAndProviderTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698