از 27 مارس 2025، توصیه می کنیم از android-latest-release
به جای aosp-main
برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
حالت های گزارش
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
حسگرها میتوانند رویدادها را به روشهای مختلفی به نام حالتهای گزارش تولید کنند. هر نوع حسگر دارای یک و تنها یک حالت گزارش دهی است. چهار حالت گزارش دهی وجود دارد.
مستمر
رویدادها با نرخ ثابتی که توسط پارامتر sampling_period_ns
ارسال شده به تابع batch
تعریف شده است، تولید می شوند. سنسورهای نمونه ای که از حالت گزارش دهی پیوسته استفاده می کنند، شتاب سنج ها و ژیروسکوپ ها هستند.
در حال تغییر
رویدادها تنها در صورتی ایجاد می شوند که مقادیر اندازه گیری شده تغییر کرده باشند. فعال کردن سنسور در سطح HAL (فراخوانی activate(..., enable=1)
روی آن) نیز یک رویداد را راهاندازی میکند، به این معنی که HAL باید بلافاصله یک رویداد را هنگامی که یک حسگر در حال تغییر فعال میشود، بازگرداند. نمونههایی از سنسورهایی که از حالت گزارش در حال تغییر استفاده میکنند، سنسورهای گام شمار، مجاورت و ضربان قلب هستند.
پارامتر sampling_period_ns
که به تابع batch
ارسال میشود برای تنظیم حداقل زمان بین رویدادهای متوالی استفاده میشود، به این معنی که تا زمانی که sampling_period_ns
نانوثانیهها از آخرین رویداد سپری نشده باشد، رویدادی نباید تولید شود، حتی اگر مقدار از آن زمان تغییر کرده باشد. اگر مقدار تغییر کرد، به محض سپری شدن sampling_period_ns
از آخرین رویداد، یک رویداد باید ایجاد شود.
برای مثال، فرض کنید:
- گام شمار را با
sampling_period_ns = 10 * 10^9
(10 ثانیه) فعال می کنیم. - ۵۵ ثانیه راه می رویم، سپس یک دقیقه بی حرکت می ایستیم.
- رویدادها تقریباً هر 10 ثانیه در طول دقیقه اول (شامل زمان
t=0
به دلیل فعال شدن سنسور و t=60
ثانیه)، در مجموع هفت رویداد ایجاد میشوند. هیچ رویدادی در دقیقه دوم ایجاد نمیشود زیرا مقدار تعداد گامها بعد از t=60
ثانیه تغییر نکرده است.
تک شات
به محض تشخیص یک رویداد، سنسور خود را غیرفعال می کند و سپس یک رویداد واحد را از طریق HAL ارسال می کند. برای اجتناب از شرایط مسابقه، سفارش مهم است. (قبل از گزارش رویداد از طریق HAL، سنسور باید غیرفعال شود). تا زمانی که حسگر دوباره فعال نشود رویداد دیگری ارسال نمی شود. حرکت قابل توجه نمونه ای از این نوع حسگرها است.
سنسورهای تک شات گاهی اوقات به عنوان سنسورهای ماشه شناخته می شوند.
پارامترهای sampling_period_ns
و max_report_latency_ns
که به تابع batch
منتقل می شوند نادیده گرفته می شوند. رویدادهای رویدادهای تک شات را نمی توان در FIFO های سخت افزاری ذخیره کرد. رویدادها باید به محض ایجاد گزارش شوند.
ویژه
برای جزئیات مربوط به زمان ایجاد رویدادها ، توضیحات نوع سنسور جداگانه را ببینید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]