مؤقت#

مقدمة#

يتم استخدام فئة المؤقت timer للحفاظ على الوقت والتفاعل مع مؤقت مستقل عن مؤقت الدماغ.

مُنشئ الفئة#

timer();

مُدمِّر الفئة#

يقوم بتدمير الكائن timer وتحرير الموارد المرتبطة به.

~timer();

حدود#

لا يقبل هذا المُنشئ أي معلمات.

أمثلة#

// Create a timer instance
timer myTimer = timer();

الدوال الأعضاء#

تتضمن فئة المؤقت timer:

  • reset — Resets the timer to zero.

  • value — Returns the elapsed time since the timer started.

  • event — يستدعي دالة بعد عدد محدد من المللي ثانية، مع وسائط اختيارية.

قبل استدعاء أي من الدوال الأعضاء للمؤقت timer يجب إنشاء مثيل للمؤقت timer كما هو موضح أدناه:

/* This constructor is required to use a 
custom timer. Replace the values
as needed. */

// Create a timer instance
timer myTimer = timer();

/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */

// Create the Brain to use Brain.Timer
brain Brain = brain();

reset#

يضبط المؤقت على الصفر.

Available Functions
void reset();

Parameters

لا تقبل هذه الدالة أي معلمات.

Return Values

هذه الدالة لا تُرجع قيمة.

Examples
while (true) {
  // Clear the timer every time the screen is pressed
  if (Brain.Screen.pressing()) {
    myTimer.reset();
  }
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Time: %.2f", myTimer.value());
  wait(50, msec);
}

value#

يُعيد القيمة الحالية للمؤقت.

Available Functions
double value();

Parameters

لا تقبل هذه الدالة أي معلمات.

Return Values

عدد مزدوج يمثل مقدار الوقت المنقضي بالثواني.

Notes
  • يبدأ المؤقت بالعد عند إنشائه.

  • Calling reset resets the timer value to zero.

Examples
// Display the timer as it ticks up
while (true) {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Time: %.2f", myTimer.value());

  wait(50, msec);
}

event#

يسجل دالة رد نداء ليتم تنفيذها بعد تأخير محدد.

Available Functions

1 — يسجل دالة رد نداء ليتم تشغيلها بعد تأخير محدد ويمرر قيمة محددة من قبل المستخدم إلى دالة رد النداء.

static void event(
    void (*callback)(void *),
    uint32_t value );

2 — يسجل دالة رد نداء ليتم تشغيلها بعد تأخير محدد.

static void event(
    void (*callback)(void),
    uint32_t value );

Parameters

المعلمة

يكتب

وصف

callback

void (*)(void *)

دالة سيتم استدعاؤها بعد التأخير المحدد وتستقبل وسيطًا محددًا من قبل المستخدم.

callback

void (*)(void)

دالة سيتم استدعاؤها بعد التأخير المحدد.

value

uint32_t

التأخير، بالمللي ثانية، قبل تنفيذ دالة الاستدعاء.

Return Values

هذه الدالة لا تُرجع قيمة.

Notes
  • تقوم هذه الوظيفة بجدولة عملية رد نداء لمرة واحدة؛ فهي لا تتكرر تلقائيًا.

  • يجب أن تُرجع دالة الاستدعاء القيمة void.

  • قد يتم جدولة عدة فعاليات في نفس الوقت.

Examples

عرّف الدالة (خارج النطاق int main())

// Create a function to turn the screen orange
void turnOrange() {
  Brain.Screen.clearScreen(orange);
}

قم بتسجيل الدالة داخل int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  timer myTimer = timer();
  // Call turnOrange after 2 seconds
  myTimer.event(turnOrange, 2000);
}