Mulai 27 Maret 2025, sebaiknya gunakan android-latest-release
, bukan aosp-main
, untuk mem-build dan berkontribusi pada AOSP. Untuk mengetahui informasi selengkapnya, lihat Perubahan pada AOSP.
Mode pelaporan
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Sensor dapat menghasilkan peristiwa dengan berbagai cara yang disebut mode pelaporan;
setiap jenis sensor memiliki satu dan hanya satu mode pelaporan yang terkait dengannya.
Ada empat mode pelaporan.
Berkelanjutan
Peristiwa dihasilkan dengan kecepatan konstan yang ditentukan oleh parameter sampling_period_ns
yang diteruskan ke fungsi batch
. Contoh sensor
yang menggunakan mode pelaporan berkelanjutan adalah
akselerometer
dan giroskop.
Saat berubah
Peristiwa hanya dibuat jika nilai yang diukur telah berubah.
Mengaktifkan sensor di tingkat HAL (memanggil
activate(..., enable=1)
di dalamnya) juga memicu peristiwa,
yang berarti HAL harus segera menampilkan peristiwa saat sensor saat perubahan
diaktifkan. Contoh sensor yang menggunakan mode pelaporan sesuai perubahan adalah
jenis sensor detak jantung, kedekatan, dan penghitung langkah.
Parameter
sampling_period_ns
yang diteruskan ke fungsi batch
digunakan untuk menetapkan
waktu minimum antara peristiwa berturut-turut, yang berarti peristiwa tidak boleh
dihasilkan hingga sampling_period_ns
nanodetik berlalu sejak
peristiwa terakhir, meskipun nilainya berubah sejak saat itu. Jika nilai berubah,
peristiwa harus dibuat segera setelah sampling_period_ns
berlalu sejak peristiwa terakhir.
Misalnya, anggaplah:
- Kita mengaktifkan penghitung langkah dengan
sampling_period_ns = 10 * 10^9
(10 detik).
- Kita berjalan selama 55 detik, lalu berdiri diam selama satu menit.
- Peristiwa dihasilkan sekitar setiap 10 detik selama menit pertama (termasuk pada waktu
t=0
karena aktivasi sensor, dan t=60
detik), dengan total tujuh peristiwa. Tidak ada peristiwa yang dihasilkan pada menit kedua karena nilai
jumlah langkah tidak berubah setelah t=60
detik.
One-shot
Setelah mendeteksi peristiwa, sensor akan menonaktifkan dirinya sendiri, lalu mengirim
satu peristiwa melalui HAL. Urutan penting untuk menghindari kondisi race.
(Sensor harus dinonaktifkan sebelum peristiwa dilaporkan melalui
HAL). Tidak ada peristiwa lain yang dikirim hingga sensor diaktifkan kembali.
Gerakan
yang signifikan adalah contoh jenis sensor ini.
Sensor one-shot terkadang disebut sebagai sensor pemicu.
Parameter sampling_period_ns
dan max_report_latency_ns
yang diteruskan ke fungsi batch
akan diabaikan. Peristiwa
dari peristiwa one-shot tidak dapat disimpan dalam FIFO hardware; peristiwa harus
dilaporkan segera setelah dibuat.
Khusus
Lihat setiap deskripsi jenis
sensor untuk mengetahui detail tentang kapan peristiwa dibuat.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 UTC."],[],[],null,["# Reporting modes\n\nSensors can generate events in different ways called reporting modes;\neach sensor type has one and only one reporting mode associated with it.\nFour reporting modes exist.\n\nContinuous\n----------\n\nEvents are generated at a constant rate defined by the\n[sampling_period_ns](/docs/core/interaction/sensors/batching#sampling_period_ns)\nparameter passed to the `batch` function. Example sensors\nusing the continuous reporting mode are\n[accelerometers](/docs/core/interaction/sensors/sensor-types#accelerometer)\nand [gyroscopes](/docs/core/interaction/sensors/sensor-types#gyroscope).\n\nOn-change\n---------\n\nEvents are generated only if the measured values have changed.\nActivating the sensor at the HAL level (calling\n`activate(..., enable=1)` on it) also triggers an event,\nmeaning the HAL must return an event immediately when an on-change sensor\nis activated. Example sensors using the on-change reporting mode are the\nstep counter, proximity, and heart rate sensor types.\n\nThe\n[sampling_period_ns](/docs/core/interaction/sensors/batching#sampling_period_ns)\nparameter passed to the `batch` function is used to set the\nminimum time between consecutive events, meaning an event shouldn't be\ngenerated until `sampling_period_ns` nanoseconds elapsed since\nthe last event, even if the value changed since then. If the value changed,\nan event must be generated as soon as `sampling_period_ns` has\nelapsed since the last event.\n\nFor example, suppose:\n\n- We activate the step counter with `sampling_period_ns = 10 * 10^9` (10 seconds).\n- We walk for 55 seconds, then stand still for one minute.\n- The events are generated about every 10 seconds during the first minute (including at time `t=0` because of the activation of the sensor, and `t=60` seconds), for a total of seven events. No event is generated in the second minute because the value of the step count didn't change after `t=60` seconds.\n\nOne-shot\n--------\n\nUpon detection of an event, the sensor deactivates itself and then sends\na single event through the HAL. Order matters to avoid race conditions.\n(The sensor must be deactivated before the event is reported through the\nHAL). No other event is sent until the sensor is reactivated.\n[Significant\nmotion](/docs/core/interaction/sensors/sensor-types#significant_motion) is an example of this kind of sensor.\n\nOne-shot sensors are sometimes referred to as trigger sensors.\n\nThe `sampling_period_ns` and `max_report_latency_ns`\nparameters passed to the `batch` function are ignored. Events\nfrom one-shot events cannot be stored in hardware FIFOs; the events must\nbe reported as soon as they are generated.\n\nSpecial\n-------\n\nSee the individual [sensor type\ndescriptions](/docs/core/interaction/sensors/sensor-types) for details on when the events are generated."]]