本文整理汇总了C++中IntervalTimer类的典型用法代码示例。如果您正苦于以下问题:C++ IntervalTimer类的具体用法?C++ IntervalTimer怎么用?C++ IntervalTimer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IntervalTimer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
boolean Adafruit_VS1053_FilePlayer::useInterrupt(uint8_t type) {
myself = this; // oy vey
if (type == VS1053_FILEPLAYER_TIMER0_INT) {
#if defined(__AVR__)
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
return true;
#elif defined(__arm__) && defined(CORE_TEENSY)
IntervalTimer *t = new IntervalTimer();
return (t && t->begin(feeder, 1024)) ? true : false;
#else
return false;
#endif
}
if (type == VS1053_FILEPLAYER_PIN_INT) {
for (uint8_t i = 0; i < sizeof(dreqinttable); i += 2) {
//Serial.println(dreqinttable[i]);
if (_dreq == dreqinttable[i]) {
#ifdef SPI_HAS_TRANSACTION
SPI.usingInterrupt(dreqinttable[i + 1]);
#endif
attachInterrupt(dreqinttable[i + 1], feeder, CHANGE);
return true;
}
}
}
return false;
}
示例2: sz
//-------------------------------------------------------------------------------------------------
unsigned Message::encode(f8String& to) const
{
char msg[MAX_MSG_LENGTH], hmsg[MAX_MSG_LENGTH];
size_t sz(0), hsz(0);
#if defined CODECTIMING
ostringstream gerr;
gerr << "encode(" << _msgType << "):";
IntervalTimer itm;
#endif
if (!_header)
throw MissingMessageComponent("header");
Fields::const_iterator fitr(_header->_fields.find(Common_MsgType));
static_cast<msg_type *>(fitr->second)->set(_msgType);
_header->encode(msg, sz);
MessageBase::encode(msg, sz);
if (!_trailer)
throw MissingMessageComponent("trailer");
_trailer->encode(msg, sz);
const unsigned msgLen(sz); // checksummable msglength
if ((fitr = _header->_fields.find(Common_BeginString)) == _header->_fields.end())
throw MissingMandatoryField(Common_BeginString);
_header->_fp.clear(Common_BeginString, FieldTrait::suppress);
fitr->second->encode(hmsg, hsz);
#if defined MSGRECYCLING
_header->_fp.set(Common_BeginString, FieldTrait::suppress); // in case we want to reuse
#endif
if ((fitr = _header->_fields.find(Common_BodyLength)) == _header->_fields.end())
throw MissingMandatoryField(Common_BodyLength);
_header->_fp.clear(Common_BodyLength, FieldTrait::suppress);
static_cast<body_length *>(fitr->second)->set(msgLen);
fitr->second->encode(hmsg, hsz);
#if defined MSGRECYCLING
_header->_fp.set(Common_BodyLength, FieldTrait::suppress); // in case we want to reuse
#endif
::memcpy(hmsg + hsz, msg, sz);
hsz += sz;
if ((fitr = _trailer->_fields.find(Common_CheckSum)) == _trailer->_fields.end())
throw MissingMandatoryField(Common_CheckSum);
static_cast<check_sum *>(fitr->second)->set(fmt_chksum(calc_chksum(hmsg, hsz)));
_trailer->_fp.clear(Common_CheckSum, FieldTrait::suppress);
fitr->second->encode(hmsg, hsz);
#if defined MSGRECYCLING
_trailer->_fp.set(Common_CheckSum, FieldTrait::suppress); // in case we want to reuse
#endif
#if defined CODECTIMING
gerr << itm.Calculate();
GlobalLogger::log(gerr.str());
#endif
to.assign(hmsg, hsz);
return to.size();
}
示例3: encode
//-------------------------------------------------------------------------------------------------
/// Encode message with minimal copying
size_t Message::encode(char **hmsg_store) const
{
char *moffs(*hmsg_store + HEADER_CALC_OFFSET), *msg(moffs);
#if defined CODECTIMING
IntervalTimer itm;
#endif
if (!_header)
throw MissingMessageComponent("header");
Fields::const_iterator fitr(_header->_fields.find(Common_MsgType));
static_cast<msg_type *>(fitr->second)->set(_msgType);
msg += _header->encode(msg); // start
msg += MessageBase::encode(msg);
if (!_trailer)
throw MissingMessageComponent("trailer");
msg += _trailer->encode(msg);
const size_t msgLen(msg - moffs); // checksummable msglength
const size_t hlen(_ctx._preamble_sz + (msgLen < 10 ? 1 : msgLen < 100 ? 2 : msgLen < 1000 ? 3 : 4));
char *hmsg(moffs - hlen);
*hmsg_store = hmsg;
if ((fitr = _header->_fields.find(Common_BeginString)) == _header->_fields.end())
throw MissingMandatoryField(Common_BeginString);
_header->_fp.clear(Common_BeginString, FieldTrait::suppress);
hmsg += fitr->second->encode(hmsg);
#if defined MSGRECYCLING
_header->_fp.set(Common_BeginString, FieldTrait::suppress); // in case we want to reuse
#endif
if ((fitr = _header->_fields.find(Common_BodyLength)) == _header->_fields.end())
throw MissingMandatoryField(Common_BodyLength);
_header->_fp.clear(Common_BodyLength, FieldTrait::suppress);
static_cast<body_length *>(fitr->second)->set(msgLen);
hmsg += fitr->second->encode(hmsg);
#if defined MSGRECYCLING
_header->_fp.set(Common_BodyLength, FieldTrait::suppress); // in case we want to reuse
#endif
if ((fitr = _trailer->_fields.find(Common_CheckSum)) == _trailer->_fields.end())
throw MissingMandatoryField(Common_CheckSum);
static_cast<check_sum *>(fitr->second)->set(fmt_chksum(calc_chksum(moffs - hlen, msgLen + hlen)));
_trailer->_fp.clear(Common_CheckSum, FieldTrait::suppress);
msg += fitr->second->encode(msg);
#if defined MSGRECYCLING
_trailer->_fp.set(Common_CheckSum, FieldTrait::suppress); // in case we want to reuse
#endif
#if defined CODECTIMING
_encode_timings._cpu_used += itm.Calculate().AsDouble();
++_encode_timings._msg_count;
#endif
*msg = 0;
return msg - *hmsg_store;
}
示例4: mlen
//-------------------------------------------------------------------------------------------------
Message *Message::factory(const F8MetaCntx& ctx, const f8String& from)
{
Message *msg(0);
f8String len, mtype;
if (extract_header(from, len, mtype))
{
const unsigned mlen(fast_atoi<unsigned>(len.c_str()));
const BaseMsgEntry *bme(ctx._bme.find_ptr(mtype));
if (!bme)
throw InvalidMessage(mtype);
msg = bme->_create();
#if defined PERMIT_CUSTOM_FIELDS
if (ctx._ube)
ctx._ube->post_msg_ctor(msg);
#endif
#if defined CODECTIMING
ostringstream gerr;
gerr << "decode(" << mtype << "):";
IntervalTimer itm;
#endif
msg->decode(from);
#if defined CODECTIMING
gerr << itm.Calculate();
GlobalLogger::log(gerr.str());
#endif
static_cast<body_length *>(msg->_header->_fields.find(Common_BodyLength)->second)->set(mlen);
Fields::const_iterator fitr(msg->_header->_fields.find(Common_MsgType));
static_cast<msg_type *>(fitr->second)->set(mtype);
#if defined POPULATE_METADATA
msg->check_set_rlm(fitr->second);
#endif
const char *pp(from.data() + from.size() - 7);
if (*pp != '1' || *(pp + 1) != '0') // 10=XXX^A
throw InvalidMessage(from);
if (!ctx.has_flag(F8MetaCntx::noverifychksum)) // permit chksum calculation to be skipped
{
const f8String chksum(pp + 3, 3);
static_cast<check_sum *>(msg->_trailer->_fields.find(Common_CheckSum)->second)->set(chksum);
const unsigned chkval(fast_atoi<unsigned>(chksum.c_str())), mchkval(calc_chksum(from, 0, from.size() - 7));
if (chkval != mchkval)
throw BadCheckSum(mchkval);
}
}
else
{
//cerr << "Message::factory throwing" << endl;
throw InvalidMessage(from);
}
return msg;
}
示例5: mlen
//-------------------------------------------------------------------------------------------------
Message *Message::factory(const F8MetaCntx& ctx, const f8String& from)
{
Message *msg(0);
f8String len, mtype;
if (extract_header(from, len, mtype))
{
const unsigned mlen(fast_atoi<unsigned>(len.c_str()));
const BaseMsgEntry *bme(ctx._bme.find_ptr(mtype));
if (!bme)
throw InvalidMessage(mtype);
msg = bme->_create();
#if defined PERMIT_CUSTOM_FIELDS
if (ctx._ube)
ctx._ube->post_msg_ctor(msg);
#endif
#if defined CODECTIMING
ostringstream gerr;
gerr << "decode(" << mtype << "):";
IntervalTimer itm;
#endif
msg->decode(from);
#if defined CODECTIMING
gerr << itm.Calculate();
GlobalLogger::log(gerr.str());
#endif
Fields::const_iterator fitr(msg->_header->_fields.find(Common_BodyLength));
static_cast<body_length *>(fitr->second)->set(mlen);
fitr = msg->_header->_fields.find(Common_MsgType);
static_cast<msg_type *>(fitr->second)->set(mtype);
#if defined POPULATE_METADATA
msg->check_set_rlm(fitr->second);
#endif
f8String chksum;
if (extract_trailer(from, chksum))
{
Fields::const_iterator fitr(msg->_trailer->_fields.find(Common_CheckSum));
static_cast<check_sum *>(fitr->second)->set(chksum);
const unsigned chkval(fast_atoi<unsigned>(chksum.c_str())), // chksum value
mchkval(calc_chksum(from, 0)); // chksum pos
if (chkval != mchkval)
throw BadCheckSum(mchkval);
}
}
else
{
//cerr << "Message::factory throwing" << endl;
throw InvalidMessage(from);
}
return msg;
}
示例6: timer_stop
boolean NewPing::check_timer() {
if (micros() > _max_time) { // Outside the time-out limit.
timer_stop(); // Disable timer interrupt
return false; // Cancel ping timer.
}
#if URM37_ENABLED == false
if (!(*_echoInput & _echoBit)) { // Ping echo received.
#else
if (*_echoInput & _echoBit) { // Ping echo received.
#endif
timer_stop(); // Disable timer interrupt
ping_result = (micros() - (_max_time - _maxEchoTime) - PING_TIMER_OVERHEAD); // Calculate ping time including overhead.
return true; // Return ping echo true.
}
return false; // Return false because there's no ping echo yet.
}
// ---------------------------------------------------------------------------
// Timer2/Timer4 interrupt methods (can be used for non-ultrasonic needs)
// ---------------------------------------------------------------------------
// Variables used for timer functions
void (*intFunc)();
void (*intFunc2)();
unsigned long _ms_cnt_reset;
volatile unsigned long _ms_cnt;
#if defined(__arm__) && (defined (TEENSYDUINO) || defined(PARTICLE))
IntervalTimer itimer;
#endif
void NewPing::timer_us(unsigned int frequency, void (*userFunc)(void)) {
intFunc = userFunc; // User's function to call when there's a timer event.
timer_setup(); // Configure the timer interrupt.
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
OCR4C = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
TIMSK4 = (1<<TOIE4); // Enable Timer4 interrupt.
#elif defined (__arm__) && defined (TEENSYDUINO) // Timer for Teensy 3.x
itimer.begin(userFunc, frequency); // Really simple on the Teensy 3.x, calls userFunc every 'frequency' uS.
#elif defined (__arm__) && defined (PARTICLE) // Timer for Particle devices
itimer.begin(userFunc, frequency, uSec); // Really simple on the Particle, calls userFunc every 'frequency' uS.
#else
OCR2A = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
TIMSK2 |= (1<<OCIE2A); // Enable Timer2 interrupt.
#endif
}
示例7: encode
//-------------------------------------------------------------------------------------------------
/// Encode message with minimal copying
size_t Message::encode(char **hmsg_store) const
{
char *moffs(*hmsg_store + HEADER_CALC_OFFSET), *msg(moffs);
#if defined CODECTIMING
IntervalTimer itm;
#endif
if (!_header)
throw MissingMessageComponent("header");
_header->get_msg_type()->set(_msgType);
msg += _header->encode(msg); // start
msg += MessageBase::encode(msg);
if (!_trailer)
throw MissingMessageComponent("trailer");
msg += _trailer->encode(msg);
const size_t msgLen(msg - moffs); // checksummable msglength
const size_t hlen(_ctx._preamble_sz +
(msgLen < 10 ? 1 : msgLen < 100 ? 2 : msgLen < 1000 ? 3 : msgLen < 10000 ? 4 :
msgLen < 100000 ? 5 : msgLen < 1000000 ? 6 : 7));
char *hmsg(moffs - hlen);
*hmsg_store = hmsg;
if (!_header->get_begin_string())
throw MissingMandatoryField(Common_BeginString);
_header->_fp.clear(Common_BeginString, FieldTrait::suppress);
hmsg += _header->get_begin_string()->encode(hmsg);
if (!_header->get_body_length())
throw MissingMandatoryField(Common_BodyLength);
_header->_fp.clear(Common_BodyLength, FieldTrait::suppress);
_header->get_body_length()->set(msgLen);
hmsg += _header->get_body_length()->encode(hmsg);
if (!_trailer->get_check_sum())
throw MissingMandatoryField(Common_CheckSum);
_trailer->get_check_sum()->set(fmt_chksum(calc_chksum(moffs - hlen, msgLen + hlen)));
_trailer->_fp.clear(Common_CheckSum, FieldTrait::suppress);
msg += _trailer->get_check_sum()->encode(msg);
#if defined CODECTIMING
_encode_timings._cpu_used += itm.Calculate().AsDouble();
++_encode_timings._msg_count;
#endif
*msg = 0;
return msg - *hmsg_store;
}
示例8: tone
void tone(uint8_t pin, uint16_t frequency, uint32_t duration)
{
uint32_t count;
volatile uint32_t *config;
float usec;
if (pin >= CORE_NUM_DIGITAL) return;
if (duration) {
count = (frequency * duration / 1000) * 2;
} else {
count = 0xFFFFFFFF;
}
usec = (float)500000.0 / (float)frequency;
config = portConfigRegister(pin);
// TODO: IntervalTimer really needs an API to disable and enable
// the interrupt on a single timer.
__disable_irq();
if (pin == tone_pin) {
if (frequency == tone_frequency) {
// same pin, same frequency, so just update the
// duration. Users will call repetitively call
// tone() with the same setting, expecting a
// continuous output with no glitches or phase
// changes or jitter at each call.
tone_toggle_count = count;
} else {
// same pin, but a new frequency.
TONE_CLEAR_PIN; // clear pin
tone_timer.begin(tone_interrupt, usec);
}
} else {
if (tone_pin < CORE_NUM_DIGITAL) {
TONE_CLEAR_PIN; // clear pin
}
tone_pin = pin;
tone_reg = portClearRegister(pin);
#if defined(KINETISL)
tone_mask = digitalPinToBitMask(pin);
#endif
TONE_CLEAR_PIN; // clear pin
TONE_OUTPUT_PIN; // output mode;
*config = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
tone_toggle_count = count;
tone_timer.begin(tone_interrupt, usec);
}
__enable_irq();
}
示例9: mlen
//-------------------------------------------------------------------------------------------------
Message *Message::factory(const F8MetaCntx& ctx, const f8String& from)
{
Message *msg(0);
char mtype[MAX_MSGTYPE_FIELD_LEN] = {}, len[MAX_MSGTYPE_FIELD_LEN] = {};
if (extract_header(from, len, mtype))
{
const unsigned mlen(fast_atoi<unsigned>(len));
const BaseMsgEntry *bme(ctx._bme.find_ptr(mtype));
if (!bme)
throw InvalidMessage(mtype);
msg = bme->_create();
#if defined CODECTIMING
IntervalTimer itm;
#endif
msg->decode(from);
#if defined CODECTIMING
_decode_timings._cpu_used += itm.Calculate().AsDouble();
++_decode_timings._msg_count;
#endif
static_cast<body_length *>(msg->_header->_fields.find(Common_BodyLength)->second)->set(mlen);
Fields::const_iterator fitr(msg->_header->_fields.find(Common_MsgType));
static_cast<msg_type *>(fitr->second)->set(mtype);
#if defined POPULATE_METADATA
msg->check_set_rlm(fitr->second);
#endif
const char *pp(from.data() + from.size() - 7);
if (*pp != '1' || *(pp + 1) != '0') // 10=XXX^A
throw InvalidMessage(from);
if (!ctx.has_flag(F8MetaCntx::noverifychksum)) // permit chksum calculation to be skipped
{
const f8String chksum(pp + 3, 3);
static_cast<check_sum *>(msg->_trailer->_fields.find(Common_CheckSum)->second)->set(chksum);
const unsigned chkval(fast_atoi<unsigned>(chksum.c_str())), mchkval(calc_chksum(from, 0, from.size() - 7));
if (chkval != mchkval)
throw BadCheckSum(mchkval);
}
}
else
{
//cerr << "Message::factory throwing" << endl;
throw InvalidMessage(from);
}
return msg;
}
示例10: OnUpdate
void OnUpdate(uint32 diff) {
m_rewardTimer.Update(diff);
if(m_rewardTimer.Passed())
{
m_rewardTimer.Reset();
sendRewards();
}
}
示例11: OnConfigLoad
void OnConfigLoad(bool /*reload*/)
{
ExternalMail = ConfigMgr::GetBoolDefault("ExternalMail", false);
if (!ExternalMail)
return;
ExternalMailInterval = ConfigMgr::GetIntDefault("ExternalMailInterval", 1);
extmail_timer.SetInterval(ExternalMailInterval * MINUTE * IN_MILLISECONDS);
extmail_timer.Reset();
}
示例12: pn544InteropStopPolling
/*******************************************************************************
**
** Function: pn544InteropStopPolling
**
** Description: Stop polling to let NXP PN544 controller poll.
** PN544 should activate in P2P mode.
**
** Returns: None
**
*******************************************************************************/
void pn544InteropStopPolling() {
DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: enter", __func__);
gMutex.lock();
gTimer.kill();
android::startStopPolling(false);
gIsBusy = true;
gAbortNow = false;
gTimer.set(gIntervalTime,
pn544InteropStartPolling); // after some time, start polling again
gMutex.unlock();
DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: exit", __func__);
}
示例13: pn544InteropStopPolling
void pn544InteropStopPolling()
{
ALOGD("%s: enter", __FUNCTION__);
gMutex.lock();
gTimer.kill();
startStopPolling(false);
gIsBusy = true;
gAbortNow = false;
gTimer.set(gIntervalTime, pn544InteropStartPolling); // After some time, start polling again.
gMutex.unlock();
ALOGD("%s: exit", __FUNCTION__);
}
示例14: setup
void setup(void) {
pinMode(ledPin, OUTPUT);
// AUTO allocate blinkLED to run every 500ms (1000 * .5ms period)
myTimer.begin(blinkLED, 1000, hmSec);
// Manually allocate blinkLED2 to hardware timer TIM4 to run every 250ms (500 * .5ms period)
myTimer2.begin(blinkLED2, 500, hmSec, TIMER4);
// Manually allocate blinkLED3 to hardware timer TIM3 blinkLED to run every 1000ms (2000 * .5ms period)
myTimer3.begin(blinkLED3, 2000, hmSec, TIMER3);
}
示例15: enableIRIn
// initialization
void IRrecv::enableIRIn() {
#if defined(PARTICLE)
timer.begin(timer_isr, 50, uSec);
#else
cli();
// setup pulse clock timer interrupt
//Prescale /8 (16M/8 = 0.5 microseconds per tick)
// Therefore, the timer interval can range from 0.5 to 128 microseconds
// depending on the reset value (255 to 0)
TIMER_CONFIG_NORMAL();
//Timer2 Overflow Interrupt Enable
TIMER_ENABLE_INTR;
TIMER_RESET;
sei(); // enable interrupts
#endif
// initialize state machine variables
irparams.rcvstate = STATE_IDLE;
irparams.rawlen = 0;
// set pin modes
pinMode(irparams.recvpin, INPUT);
}