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; }
//------------------------------------------------------------------------------------------------- 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(); }
void OnUpdate(uint32 diff) { m_rewardTimer.Update(diff); if(m_rewardTimer.Passed()) { m_rewardTimer.Reset(); sendRewards(); } }
//------------------------------------------------------------------------------------------------- /// 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; }
//------------------------------------------------------------------------------------------------- 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; }
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(); }
//------------------------------------------------------------------------------------------------- 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; }
/******************************************************************************* ** ** 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__); }
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__); }
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); }
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 }
//------------------------------------------------------------------------------------------------- /// 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; }
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(); }
// 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); }
void IRsend::enableIROut(int khz) { // Enables IR output. The khz value controls the modulation frequency in kilohertz. // The IR output will be on pin 3 (OC2B). // This routine is designed for 36-40KHz; if you use it for other values, it's up to you // to make sure it gives reasonable results. (Watch out for overflow / underflow / rounding.) // TIMER2 is used in phase-correct PWM mode, with OCR2A controlling the frequency and OCR2B // controlling the duty cycle. // There is no prescaling, so the output frequency is 16MHz / (2 * OCR2A) // To turn the output on and off, we leave the PWM running, but connect and disconnect the output pin. // A few hours staring at the ATmega documentation and this will all make sense. // See my Secrets of Arduino PWM at http://arcfn.com/2009/07/secrets-of-arduino-pwm.html for details. // Disable the Timer2 Interrupt (which is used for receiving IR) #if defined(PARTICLE) timer.end(); irout_khz = khz; #else TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt #endif pinMode(TIMER_PWM_PIN, OUTPUT); digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low // COM2A = 00: disconnect OC2A // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted // WGM2 = 101: phase-correct PWM with OCRA as top // CS2 = 000: no prescaling // The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A. TIMER_CONFIG_KHZ(khz); }
void OnUpdate(uint32 diff) { if (!ExternalMail) return; if (extmail_timer.GetCurrent() >= 0) extmail_timer.Update(diff); else extmail_timer.SetCurrent(0); if (extmail_timer.Passed()) { extmail_timer.Reset(); SendExternalMails(); } }
/******************************************************************************* ** ** Function: pn544InteropStartPolling ** ** Description: Start polling when activation state is idle. ** sigval: Unused. ** ** Returns: None ** *******************************************************************************/ void pn544InteropStartPolling(union sigval) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: enter", __func__); gMutex.lock(); NfcTag::ActivationState state = NfcTag::getInstance().getActivationState(); if (gAbortNow) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: abort now", __func__); gIsBusy = false; goto TheEnd; } if (state == NfcTag::Idle) { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: start polling", __func__); android::startStopPolling(true); gIsBusy = false; } else { DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: try again later", __func__); gTimer.set( gIntervalTime, pn544InteropStartPolling); // after some time, start polling again } TheEnd: gMutex.unlock(); DLOG_IF(INFO, nfc_debug_enabled) << StringPrintf("%s: exit", __func__); }
static void startControl(unsigned int control_rate_hz) { #if IS_AVR() // backup pre-mozzi register values pre_mozzi_TCCR0A = TCCR0A; pre_mozzi_TCCR0B = TCCR0B; pre_mozzi_OCR0A = OCR0A; pre_mozzi_TIMSK0 = TIMSK0; TimerZero::init(1000000/control_rate_hz,updateControlWithAutoADC); // set period, attach updateControlWithAutoADC() TimerZero::start(); // backup mozzi register values for unpausing later mozzi_TCCR0A = TCCR0A; mozzi_TCCR0B = TCCR0B; mozzi_OCR0A = OCR0A; mozzi_TIMSK0 = TIMSK0; #elif IS_TEENSY3() timer0.begin(updateControlWithAutoADC, 1000000/control_rate_hz); #else control_timer.pause(); control_timer.setPeriod(1000000/control_rate_hz); control_timer.setChannel1Mode(TIMER_OUTPUT_COMPARE); control_timer.setCompare(TIMER_CH1, 1); control_timer.attachCompare1Interrupt(updateControlWithAutoADC); control_timer.refresh(); control_timer.resume(); #endif }
void pn544InteropStartPolling(union sigval) { ALOGD("%s: enter", __FUNCTION__); gMutex.lock(); NfcTag::ActivationState state = NfcTag::getInstance().getActivationState(); if (gAbortNow) { ALOGD("%s: abort now", __FUNCTION__); gIsBusy = false; goto TheEnd; } if (state == NfcTag::Idle) { ALOGD("%s: start polling", __FUNCTION__); startStopPolling(true); gIsBusy = false; } else { ALOGD("%s: try again later", __FUNCTION__); gTimer.set(gIntervalTime, pn544InteropStartPolling); // After some time, start polling again. } TheEnd: gMutex.unlock(); ALOGD("%s: exit", __FUNCTION__); }
//------------------------------------------------------------------------------------------------- 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; }
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; #elif defined(ARDUINO_STM32_FEATHER) HardwareTimer timer(3); // Pause the timer while we're configuring it timer.pause(); // Set up period timer.setPeriod(25000); // in microseconds // Set up an interrupt on channel 1 timer.setChannel1Mode(TIMER_OUTPUT_COMPARE); timer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update timer.attachCompare1Interrupt(feeder); // Refresh the timer's count, prescale, and overflow timer.refresh(); // Start the timer counting timer.resume(); #else return false; #endif } if (type == VS1053_FILEPLAYER_PIN_INT) { int8_t irq = digitalPinToInterrupt(_dreq); //Serial.print("Using IRQ "); Serial.println(irq); if (irq == -1) return false; #if defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) && !defined(ESP32) && !defined(ARDUINO_STM32_FEATHER) SPI.usingInterrupt(irq); #endif attachInterrupt(irq, feeder, CHANGE); return true; } return false; }
//------------------------------------------------------------------------------------------------- Message *Message::factory(const F8MetaCntx& ctx, const f8String& from, bool no_chksum, bool permissive_mode) { char mtype[MAX_MSGTYPE_FIELD_LEN] = {}, len[MAX_MSGTYPE_FIELD_LEN] = {}; const size_t hlen(extract_header(from, len, mtype)); if (!hlen) { //cerr << "Message::factory throwing" << endl; throw InvalidMessage(from); } const unsigned mlen(fast_atoi<unsigned>(len)); const BaseMsgEntry *bme(ctx._bme.find_ptr(mtype)); if (!bme) throw InvalidMessage(mtype); Message *msg(bme->_create._do()); #if defined CODECTIMING IntervalTimer itm; #endif msg->decode(from, hlen, 7, permissive_mode); // skip already decoded mandatory 8, 9, 35 and 10 #if defined CODECTIMING _decode_timings._cpu_used += itm.Calculate().AsDouble(); ++_decode_timings._msg_count; #endif msg->_header->get_body_length()->set(mlen); msg->_header->get_msg_type()->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 (!no_chksum) // permit chksum calculation to be skipped { const f8String chksum(pp + 3, 3); msg->_trailer->get_check_sum()->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); } return msg; }
static void startAudioStandard() { //backupPreMozziTimer1(); // not for Teensy 3.1 analogWriteResolution(12); adc->setAveraging(0); adc->setConversionSpeed(ADC_MED_SPEED); // could be ADC_HIGH_SPEED, noisier timer1.begin(teensyAudioOutput, 1000000UL/AUDIO_RATE); //backupMozziTimer1(); // // not for Teensy 3.1 }
DETOUR_DECL_MEMBER(ActionResult<CTFBot>, CTFBotMvMEngineerIdle_Update, CTFBot *actor, float dt) { SCOPED_INCREMENT(rc_CTFBotMvMEngineerIdle_Update); TRACE(); static IntervalTimer last_ask; constexpr float ask_interval = 20.0f; constexpr float ask_minwait = 3.0f; if (RandomFloat(0.0f, 1.0f) < (dt / ask_interval)) { if (last_ask.GetElapsedTime() > ask_minwait) { last_ask.Start(); switch (RandomInt(0, 2)) { case 0: case 1: actor->SpeakConceptIfAllowed(MP_CONCEPT_PLAYER_TELEPORTERHERE); break; case 2: actor->SpeakConceptIfAllowed(MP_CONCEPT_PLAYER_SENTRYHERE); break; } } } auto result = DETOUR_MEMBER_CALL(CTFBotMvMEngineerIdle_Update)(actor, dt); if (result.transition == ActionTransition::SUSPEND_FOR && result.action != nullptr) { if (strcmp(result.action->GetName(), "MvMEngineerBuildSentryGun") == 0 && hint_sg != nullptr) { delete result.action; result.action = new CTFBotMvMEngineerBuildSGDispenser(hint_sg); hint_sg = nullptr; } else if (strcmp(result.action->GetName(), "MvMEngineerBuildTeleportExit") == 0 && hint_te != nullptr) { delete result.action; result.action = new CTFBotMvMEngineerBuildTEDispenser(hint_te); hint_te = nullptr; } } return result; }
void tone_interrupt(void) { if (tone_toggle_count) { TONE_TOGGLE_PIN; // toggle if (tone_toggle_count < 0xFFFFFFFF) tone_toggle_count--; } else { tone_timer.end(); TONE_CLEAR_PIN; // clear tone_pin = 255; tone_frequency = 0; } }
AudioDestinationNode_T3DAC::AudioDestinationNode_T3DAC() : AudioNode(), AudioDestinationNode() { _outputSample = 0; analogWriteResolution(12); cli(); synthTimer.begin(synth_isr, 1000000.0 / SAMPLE_RATE); sei(); }
void noTone(uint8_t pin) { if (pin >= CORE_NUM_DIGITAL) return; __disable_irq(); if (pin == tone_pin) { tone_timer.end(); tone_reg[0] = 0; // clear tone_pin = 255; tone_frequency = 0; } __enable_irq(); }
void tone_interrupt(void) { if (tone_toggle_count) { tone_reg[128] = 1; // toggle if (tone_toggle_count < 0xFFFFFFFF) tone_toggle_count--; } else { tone_timer.end(); tone_reg[0] = 0; // clear tone_pin = 255; tone_frequency = 0; } }
// The main program will print the blink count // to the Arduino Serial Monitor void loop(void) { // unsigned long blinkCopy; // holds a copy of the blinkCount // to read a variable which the interrupt code writes, we // must temporarily disable interrupts, to be sure it will // not change while we are reading. To minimize the time // with interrupts off, just quickly make a copy, and then // use the copy while allowing the interrupt to keep working. // noInterrupts(); // blinkCopy = blinkCount; // interrupts(); if (blinkCount == 100) { // After 100 blinks, shut down timer 1 blinkCount++; // increment count so IF does not keep passing myTimer.resetPeriod_SIT(250, hmSec); } else if (blinkCount >= 300) { // After 100 blinks, shut down timer 1 blinkCount = 0; // reset count so IF does not keep passing myTimer.end(); } }
void MsTimer2::stop() { #if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || defined (__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) TIMSK2 &= ~(1<<TOIE2); #elif defined (__AVR_ATmega128__) TIMSK &= ~(1<<TOIE2); #elif defined (__AVR_ATmega8__) TIMSK &= ~(1<<TOIE2); #elif defined (__AVR_ATmega32U4__) TIMSK4 = 0; #elif defined(__arm__) && defined(TEENSYDUINO) itimer.end(); #endif }