Пример #1
0
int8_t Timer::every(unsigned long period, void (*callback)(), int repeatCount)
{
	int8_t i = findFreeEventIndex();
	if (i == -1) return -1;

	_events[i].eventType = EVENT_EVERY;
	_events[i].period = period;
	_events[i].repeatCount = repeatCount;
	_events[i].callback = callback;
	_events[i].lastEventTime = millis();
	_events[i].count = 0;
	return i;
}
Пример #2
0
Файл: mpu.c Проект: Liwsh/Robot
/*
 *加载循环事件
 */
int8_t every(unsigned long period, void (*callback)(), int repeatCount) {
	int8_t i = findFreeEventIndex();
	if (i == -1)
		return -1;
	events[i].eventType = EVENT_EVERY;
	events[i].period = period;
	events[i].repeatCount = repeatCount;
	events[i].callback = callback;
	gettimeofday(&tv1, &tz);
	events[i].lastEventTime = tv1.tv_sec*1000 + tv1.tv_usec / 1000;
	events[i].count = 0;
	return i;
}
Пример #3
0
int8_t Timer::oscillate(uint8_t pin, unsigned long period, uint8_t startingValue, int repeatCount)
{
	int8_t i = findFreeEventIndex();
	if (i == NO_TIMER_AVAILABLE) return NO_TIMER_AVAILABLE;

	_events[i].eventType = EVENT_OSCILLATE;
	_events[i].pin = pin;
	_events[i].period = period;
	_events[i].pinState = startingValue;
	digitalWrite(pin, startingValue);
	_events[i].repeatCount = repeatCount * 2; // full cycles not transitions
	_events[i].lastEventTime = millis();
	_events[i].count = 0;
	return i;
}
int8_t RTCTimer::every(uint32_t period, void (*callback)(uint32_t now),
    int repeatCount)
{
  int8_t i = findFreeEventIndex();
  if (i == -1)
    return -1;

  _events[i]._eventType = RTCEvent::RTCEvent_Every;
  _events[i]._period = period;
  _events[i]._repeatCount = repeatCount;
  _events[i]._callback = callback;
  _events[i]._lastEventTime = _now ? _now() : 0;
  _events[i]._count = 0;

  return i;
}