int main() { int isNormal; setVariables(); while (1) { calibrateInit(); displayCalibrate(); if(isCalibrated(&gAccRead)) { standbyInit(); countDown(); while(1) { if (resetFlag) break; sendReadySignal(); runTemp(&isNormal); if (isSafe && isNormal && hasEstablished) { initActive(); while(1) { int freq = calculateFreq(); runActive(freq); runTemp(&isNormal); if (resetFlag) break; if(isMayDay) { switchDisplayToMayDay(); break; } if(!isNormal || !isSafe || standbyFlag) { standbyFlag = 0; switchDisplayToStandby(); countDown(); break; } } if(resetFlag) { switchDisplayToCalibrate(); break; } if(isMayDay) { initMayDay(); runMayDay(); initLight(); switchDisplayToStandby(); countDown(); } } } } } }
void PopupMessage::dissolveMask() { if( m_stage == 1 ) { //repaint( false ); QPainter maskPainter(&m_mask); m_mask.fill(Qt::black); maskPainter.setBrush(Qt::white); maskPainter.setPen(Qt::white); maskPainter.drawRect( m_mask.rect() ); m_dissolveSize += m_dissolveDelta; if( m_dissolveSize > 0 ) { //maskPainter.setCompositionMode( Qt::EraseROP ); //FIXME: QRubberBand int x, y, s; const int size = 16; for (y = 0; y < height() + size; y += size) { x = width(); s = m_dissolveSize * x / 128; for ( ; x > size; x -= size, s -= 2 ) { if (s < 0) break; maskPainter.drawEllipse(x - s / 2, y - s / 2, s, s); } } } else if( m_dissolveSize < 0 ) { m_dissolveDelta = 1; killTimer( m_timerId ); if( m_timeout ) { m_timerId = startTimer( 40 ); m_stage = 2; } } setMask(m_mask); } else if ( m_stage == 2 ) { countDown(); } else { deleteLater(); } }
void PopupMessage::plainMask() { switch (m_stage) { case 1: { // Raise killTimer(m_timerId); if (m_timeout) { m_timerId = startTimer(40); m_stage = 2; } break; } case 2: { // Counter countDown(); break; } case 3: { // Lower/Remove deleteLater(); break; } } }
VariantObject* ObjectMemory::resize(PointersOTE* ote, MWORD newPointers, bool bRefCount) { ASSERT(!ObjectMemoryIsIntegerObject(ote) && ote->isPointers()); VariantObject* pObj = ote->m_location; const MWORD oldPointers = ote->pointersSize(); // If resizing the active process, then we don't do any ref. counting as refs from // the current stack are not counted (we used deferred ref. counting) if (bRefCount) { for (MWORD i=newPointers;i<oldPointers;i++) countDown(pObj->m_fields[i]); } // Reallocate the object to the new size (bigger or smaller) pObj = reinterpret_cast<VariantObject*>(basicResize(reinterpret_cast<POTE>(ote), SizeOfPointers(newPointers), 0)); if (pObj) { ASSERT(newPointers == ote->pointersSize()); newPointers = ote->pointersSize(); // Initialize any new pointers to Nil (indices must fit in a SmallInteger) const Oop nil = Oop(Pointers.Nil); for (MWORD i=oldPointers; i<newPointers; i++) pObj->m_fields[i] = nil; } return pObj; }
void PopupMessage::slideMask() { switch (m_stage) { case 1: { // Raise move(0, m_parent->y() - m_offset); m_offset++; if (m_offset > height()) { killTimer(m_timerId); if (m_timeout) { m_timerId = startTimer(40); m_stage = 2; } } break; } case 2: { // Fill in pause timer bar countDown(); break; } case 3: { // Lower m_offset--; move(0, m_parent->y() - m_offset); if (m_offset < 0) deleteLater(); } } }
//遊戲畫面 void MainWindow::gamePage() { gameStatus=true; ui->centralWidget->setObjectName("background"); ui->centralWidget->setStyleSheet("#background{border-image:url(:/img/images/bg.png);}"); musicSelect(); //設定打擊點圖片 hitPoint = new QLabel(this); hitPoint->setStyleSheet("border-image:url(:/img/images/hitpoint.png)"); hitPoint->setGeometry(130,140,55,55); hitPoint->show(); points(); //設定鼓圖片 drum = new QLabel(this); drum->setStyleSheet("border-image:url(:/img/images/mtaiko.png)"); drum->setGeometry(0,120,620,90); drum->show(); reddrum = new QLabel(this); reddrum->setStyleSheet("border-image:url(:/img/images/mtaikoflash_red.png)"); reddrum->setGeometry(12,104,100,100); reddrum->hide(); bluedrum = new QLabel(this); bluedrum->setStyleSheet("border-image:url(:/img/images/mtaikoflash_blue.png)"); bluedrum->setGeometry(7,104,111,103); bluedrum->hide(); riverTop(); countDown(); girl_chick(); taikokun(); scoreTab(); }
void countDown(int count) { std::cout << "push " << count << '\n'; if (count > 1) // termination condition countDown(count-1); std::cout << "pop " << count << '\n'; }
SendConfirmationDialog::SendConfirmationDialog(const QString &title, const QString &text, int _secDelay, QWidget *parent) : QMessageBox(QMessageBox::Question, title, text, QMessageBox::Yes | QMessageBox::Cancel, parent), secDelay(_secDelay) { setDefaultButton(QMessageBox::Cancel); yesButton = button(QMessageBox::Yes); updateYesButton(); connect(&countDownTimer, SIGNAL(timeout()), this, SLOT(countDown())); }
TEST(SpscRbConcurrentTest, shouldExchangeMessages) { AERON_DECL_ALIGNED(buffer_t spsc_buffer, 16); spsc_buffer.fill(0); aeron_spsc_rb_t rb; ASSERT_EQ(aeron_spsc_rb_init(&rb, spsc_buffer.data(), spsc_buffer.size()), 0); std::atomic<int> countDown(1); std::vector<std::thread> threads; size_t msgCount = 0; size_t counts = 0; threads.push_back(std::thread([&]() { AERON_DECL_ALIGNED(buffer_t buffer, 16); buffer.fill(0); countDown--; while (countDown > 0) { std::this_thread::yield(); } for (int m = 0; m < NUM_MESSAGES; m++) { int32_t *payload = (int32_t *)(buffer.data()); *payload = m; while (AERON_RB_SUCCESS != aeron_spsc_rb_write(&rb, MSG_TYPE_ID, buffer.data(), 4)) { std::this_thread::yield(); } } })); while (msgCount < NUM_MESSAGES) { const size_t readCount = aeron_spsc_rb_read( &rb, spsc_rb_concurrent_handler, &counts, std::numeric_limits<size_t>::max()); if (0 == readCount) { std::this_thread::yield(); } msgCount += readCount; } for (std::thread &thr: threads) { thr.join(); } }
void CThrowBomb::Throwed() { if (!throwed) { throwed = true; GET_MY(phys, TCompPhysics); auto fd = phys->getFilterData(); fd.word1 = PXM_NO_PLAYER; } float dist = simpleDist(initial_pos, transform->getPosition()); if (dist > 0.5f && checkNextState("impacted")) { rd->setActorFlag(PxActorFlag::eDISABLE_GRAVITY, false); rd->setRigidBodyFlag(PxRigidBodyFlag::eENABLE_CCD, true); } else { throwMovement(); } countDown(); }
void idleFunction() { long delta = get_delta_time(); //receivePackets loops through all packets. std::string incMsg; switch (gameData.get_game_state()) { case CHAT_SCREEN: incMsg = receivePackets_ChatScreen(); if (incMsg == "READY") { gameData.toggle_opponent_ready(); } else { if (incMsg.size() > 0) { messages.push_back("Friend: " + incMsg); glutPostRedisplay(); } } countDown((gameData.is_player_ready() && gameData.is_opponent_ready()), messages, gameData); // erase old messages that no longer fit. if (messages.size()*0.05 >= 1.49) { messages.pop_front(); glutPostRedisplay(); } break; case START_GAME: receivePackets_Game(gameData); decideOrder(gameData); //initialDraw(); gameData.set_game_state(GAME); glutPostRedisplay(); break; case GAME: receivePackets_Game(gameData); if (gameData.actions_remain()) gameData.next_action()(delta); drawApproach(delta); // animated card-draw; if (cardGrabbed && hoverCard->getY() > -0.5f && hoverCard->getY() < 0.0f) { hoverCard->moveTo(hoverCard->getX(), hoverCard->getY(), 1.24f - 1.24f*((0.5f + hoverCard->getY())/0.5f)); glutPostRedisplay(); } break; } incMsg = ""; }
void Countimer::run() { // timer is running only if is not completed or not stopped. if (_isCounterCompleted || _isStopped) return; if (millis() - _previousMillis >= _interval) { if (_countType == COUNT_DOWN) { countDown(); } else if (_countType == COUNT_UP) { countUp(); } else { _callback(); } _previousMillis = millis(); } }
TEST(SpscRbConcurrentTest, shouldProvideCcorrelationIds) { AERON_DECL_ALIGNED(buffer_t buffer, 16); buffer.fill(0); aeron_spsc_rb_t rb; ASSERT_EQ(aeron_spsc_rb_init(&rb, buffer.data(), buffer.size()), 0); std::atomic<int> countDown(2); std::vector<std::thread> threads; for (int i = 0; i < 2; i++) { threads.push_back(std::thread([&]() { countDown--; while (countDown > 0) { std::this_thread::yield(); } for (int m = 0; m < NUM_IDS_PER_THREAD; m++) { aeron_spsc_rb_next_correlation_id(&rb); } })); } for (std::thread &thr: threads) { thr.join(); } ASSERT_EQ(aeron_spsc_rb_next_correlation_id(&rb), NUM_IDS_PER_THREAD * 2); }
void CThrowBomb::Impacted() { countDown(); }
/*********************************************************** * * countDownInt * * * ***********************************************************/ unsigned int BulbRamp::countDownInt() { unsigned long longCount = countDown()/1000; unsigned int countInt = (unsigned int) longCount; return countInt; }
/*********************************************************** * * trigger * * * ***********************************************************/ boolean BulbRamp::trigger() { unsigned long remainTime; //don't allow zero time delta. Will crash the device if(option(BULB_DELTA) == 0) { incOption(BULB_DELTA,1); } //----------------Duration //if you set a duration limit, stop take pictures when it is reached if(elapsedDuration >= option(BULB_DURATION)) { if(focusActive == false && shutterActive == false) //don't abort if shutter is triggered { elapsedDuration = 0; //clear this for next time abortTrigger = true; return false; } } remainTime = countDown(); //get the remaining time to next shot //calulate the shutterPulseTime. int steps = option(BULB_DURATION) / option(BULB_DELTA); int stepSize = ( option(BULB_ENDEXP) - option(BULB_STARTEXP) ) / steps; shutterPulseTime_ = option(BULB_STARTEXP) + (stepSize * shotCounter_); #ifdef SERIAL_DEBUG Serial.print("pulseTime:"); Serial.println(shutterPulseTime_); #endif //-------------Delay if(delayFirstShot() == true) { return true; } shutter(false,false); //trigger shutter if shutterReady = true, set delay to false, false time unit seconds //----------Sleep if(batteryPower() == true) { if(focusActive == false && shutterActive == false) //don't sleep if shutter is triggered { sleep_->pwrDownMode(); //deepest sleep sleep_->sleepDelay(abortTrigger,remainTime,shotCounter_); remainTime = 0; } } //---------- Shutter if ((long) remainTime < 0 ) {remainTime = 0;} //check for unsigned underflow, by converting to signed if (remainTime <= 0) { //times up,take a shot delayCount = millis(); //start counting till delay is up startBttnTime = delayCount; //don't call millis twice, just use delayCount, reset startButtnTime focusReady = true; shutterReady = true; //set shutter ready, will activate shutter next time through loop IRReady = true; return shutterReady; } else { return false; } }
TEST(MpscQueueConcurrentTest, shouldExchangeMessages) { AERON_DECL_ALIGNED(aeron_mpsc_concurrent_array_queue_t q, 16); ASSERT_EQ(aeron_mpsc_concurrent_array_queue_init(&q, CAPACITY), 0); std::atomic<int> countDown(NUM_PUBLISHERS); std::atomic<unsigned int> publisherId(0); std::vector<std::thread> threads; size_t msgCount = 0; uint32_t counts[NUM_PUBLISHERS]; for (int i = 0; i < NUM_PUBLISHERS; i++) { counts[i] = 0; } for (int i = 0; i < NUM_PUBLISHERS; i++) { threads.push_back( std::thread( [&]() { uint32_t id = publisherId.fetch_add(1); countDown--; while (countDown > 0) { std::this_thread::yield(); // spin until we is ready } for (uint32_t m = 0; m < NUM_MESSAGES_PER_PUBLISHER; m++) { mpsc_concurrent_test_data_t *data = new mpsc_concurrent_test_data_t; data->id = id; data->num = m; while (AERON_OFFER_SUCCESS != aeron_mpsc_concurrent_array_queue_offer(&q, data)) { std::this_thread::yield(); } } })); } while (msgCount < (NUM_MESSAGES_PER_PUBLISHER * NUM_PUBLISHERS)) { const uint64_t drainCount = aeron_mpsc_concurrent_array_queue_drain(&q, mpsc_queue_concurrent_handler, counts, CAPACITY); if (0 == drainCount) { std::this_thread::yield(); } msgCount += drainCount; } // wait for all threads to finish for (std::thread &thr: threads) { thr.join(); } aeron_mpsc_concurrent_array_queue_close(&q); }
/*********************************************************** * * trigger * * * ***********************************************************/ boolean TimeLapse::trigger() { unsigned long remainTime; //don't allow zero time delta. Will crash the device if(option(TIME_DELTA) == 0) { incOption(TIME_DELTA,1); } //----------------NumShot //if you set a shot limit, stop take pictures when it is reached if(shotCounter_ >= option(TIME_NUMSHOTS) && option(TIME_NUMSHOTS) != 0) { if(focusActive == false && shutterActive == false) //don't abort if shutter is triggered { abortTrigger = true; return false; } } remainTime = countDown(); //get the remaining time to next shot //-------------Delay if(delayFirstShot() == true) { return true; } shutter(false,false); //trigger shutter if shutterReady = true, set delay to false, false time unit seconds //----------Sleep if(batteryPower() == true) { if(focusActive == false && shutterActive == false) //don't sleep if shutter is triggered { sleep_->pwrDownMode(); //deepest sleep sleep_->sleepDelay(abortTrigger,remainTime,shotCounter_); remainTime = 0; } } //---------- Shutter if ((long) remainTime < 0 ) {remainTime = 0;} //check for unsigned underflow, by converting to signed if (remainTime <= 0) { //times up,take a shot delayCount = millis(); //start counting till delay is up startBttnTime = delayCount; //don't call millis twice, just use delayCount, reset startButtnTime focusReady = true; shutterReady = true; //set shutter ready, will activate shutter next time through loop IRReady = true; return shutterReady; } else { return false; } }
bool Speaker::loop() { if(speakerPin == -1) return false; if(this->count != 0) { if(melody == SIREN) { int wait = 1; int time = 10; if(this->state == 0) this->state = 150; // start at freq 150 if(this->state <= 1800) // go up to 1800 { NewTone(speakerPin, this->state++, time); // Beep pin, freq, time sleep_milli(wait); } else if(this->state > 1800 && this->state < 1800 + 1800 - 150) // go down to 150 { NewTone(speakerPin, 1800 - (this->state - 1800), time); sleep_milli(wait); this->state++; } else { countDown(); } } else if(melody == MELODY1) { int melody[] = { NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; // stop the tone playing: noNewTone(speakerPin); int thisNote = state++; if(thisNote < 8) // number of notes { // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurations[thisNote]; NewTone(speakerPin, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; sleep_milli(pauseBetweenNotes); } else { countDown(); } } } return true; }
int main(void) { countDown(5); return 0; }
unsigned int TimeLapse::countDownInt() { unsigned long longCount = countDown()/1000; unsigned int countInt = (unsigned int) longCount; return countInt; }
// MANIPULATORS void Latch::arrive() { countDown(1); }
void Latch::arriveAndWait() { countDown(1); wait(); }
TEST(MpscRbConcurrentTest, shouldExchangeMessages) { AERON_DECL_ALIGNED(buffer_t mpsc_buffer, 16); mpsc_buffer.fill(0); aeron_mpsc_rb_t rb; ASSERT_EQ(aeron_mpsc_rb_init(&rb, mpsc_buffer.data(), mpsc_buffer.size()), 0); std::atomic<int> countDown(NUM_PUBLISHERS); std::atomic<unsigned int> publisherId(0); std::vector<std::thread> threads; size_t msgCount = 0; uint32_t counts[NUM_PUBLISHERS]; for (int i = 0; i < NUM_PUBLISHERS; i++) { counts[i] = 0; } for (int i = 0; i < NUM_PUBLISHERS; i++) { threads.push_back( std::thread( [&]() { AERON_DECL_ALIGNED(buffer_t buffer, 16); buffer.fill(0); uint32_t id = publisherId.fetch_add(1); countDown--; while (countDown > 0) { std::this_thread::yield(); } mpsc_concurrent_test_data_t *data = (mpsc_concurrent_test_data_t *)(buffer.data()); for (uint32_t m = 0; m < NUM_MESSAGES_PER_PUBLISHER; m++) { data->id = id; data->num = m; while (AERON_RB_SUCCESS != aeron_mpsc_rb_write( &rb, MSG_TYPE_ID, buffer.data(), sizeof(mpsc_concurrent_test_data_t))) { std::this_thread::yield(); } } })); } while (msgCount < (NUM_MESSAGES_PER_PUBLISHER * NUM_PUBLISHERS)) { const size_t readCount = aeron_mpsc_rb_read( &rb, mpsc_rb_concurrent_handler, counts, std::numeric_limits<size_t>::max()); if (0 == readCount) { std::this_thread::yield(); } msgCount += readCount; } for (std::thread &thr: threads) { thr.join(); } }
void main() { countDown(60*30);//Notify once in 30*60 seconds/30 minutes signal(SIGALRM,alrm); while(1); }
int main(void) { init(); // call the function above // Set/Reset Variables int upButtonFlag = FALSE; int downButtonFlag = FALSE; while(TRUE){ // Pressing UP_BUTTON (ACTIVE_LOW) if(UP_BUTTON == LOW && upButtonFlag == FALSE) { countUp(); upButtonFlag = TRUE; __delay_ms(100); } // Releasing UP_BUTTON if(UP_BUTTON == HIGH && upButtonFlag == TRUE) { upButtonFlag = FALSE; __delay_ms(100); } // Pressing DOWN_BUTTON (ACTIVE_LOW) if(DOWN_BUTTON == LOW && downButtonFlag == FALSE) { countDown(); downButtonFlag = TRUE; __delay_ms(100); } // Releasing DOWN_BUTTON if(DOWN_BUTTON == HIGH && downButtonFlag == TRUE) { downButtonFlag = FALSE; __delay_ms(100); } // Dispay Patterns if(count == 0) { zeroDisplay(); } if(count == 1) { oneDisplay(); } if(count == 2) { twoDisplay(); } if(count == 3) { threeDisplay(); } if(count == 4) { fourDisplay(); } if(count == 5) { fiveDisplay(); } if(count == 6) { sixDisplay(); } if(count == 7) { sevenDisplay(); } if(count == 8) { eightDisplay(); } if(count == 9) { nineDisplay(); } } }