int main() { int i, off=0, on=1, lports[]=LIGHT_PORTS, pcnt, w=40, m=5; float s; graphics_open(320,240); for(i=0;i<256;i+=5) { graphics_fill(i,i,i); graphics_update(); } SplashBG(320, 240); msleep(1000); graphics_close(); pcnt=NPORTS(lports); for(i=8;i<16;i++) { // change the digital ports to output set_digital_output(i,1); } srand(time(NULL)); // prime random number generation while(1) { table_lights(lports,pcnt,off); // shut off table lights setup(); // team setup (light calibration w/time out option) // setup done, including any time outs so proceed with judge's setup //get_shelf_positions(); // display orange/yellow block set up for judges - 2014 get_bgal_pod_positions(); // display left-right positions for Botgal & pod - 2015 set_a_button_text("QUIT"); set_b_button_text("-"); set_c_button_text("-"); graphics_close(); // close any open graphics graphics_open(3*w,62); display_clear(); display_printf(0,0,"************** BOTBALL 2015 **************"); display_printf(0,1," LIGHTS ON IN"); display_printf(0,2,"******************************************"); display_printf(0,9," Press QUIT to stop count down"); if (countdown_sd(5,1,BLUE,YELLOW,m,w)) continue; s=seconds(); // 2015 table_lights(lports,pcnt,on); // on for 115 seconds display_printf(0,1," GAME CLOCK - LIGHTS ON TILL 5"); if (countdown(120,11,GREEN,BLUE,m,w)) continue; // end 2015 /* // 2014 table_lights(lports,pcnt,on); // on for 15 seconds display_printf(0,1," GAME CLOCK - LIGHTS ON TILL 105"); if (countdown(120,106,GREEN,BLUE,m,w)) continue; table_lights(lports,pcnt,off); // of for 100 seconds display_printf(0,1," GAME CLOCK - LIGHTS OFF TILL 5"); if (countdown(105,11,LTBLUE,RED,m,w)) continue; // end 2014 */ if (countdown(10,6,LTORANGE,BLUE,m,w)) continue; display_printf(0,1," GAME CLOCK - LIGHTS BLINK TILL 0"); i=5+(seconds()-s); if (blinkdown(5,0,RED,YELLOW,m,w,lports,pcnt)) continue; display_printf(0,1," GAME CLOCK - %d ",i); display_printf(0,9," ***** GAME OVER! ***** "); table_lights(lports,pcnt,off); // shut off table lights msleep(5000); // pause display } return 0; }
int main() { auto f = [&]() resumable { countdown_t f1(countdown(10)); yield from f1; countdown_t f2(countdown(5)); return from f2; }; while (!is_terminal(f)) printf("%d\n", f()); }
bool Threading::Mutex::Acquire( const wxTimeSpan& timeout ) { #if wxUSE_GUI if( !wxThread::IsMain() || (wxTheApp == NULL) ) { return AcquireWithoutYield(timeout); } else if( _WaitGui_RecursionGuard( L"Mutex::TimedAcquire" ) ) { ScopedBusyCursor hourglass( Cursor_ReallyBusy ); return AcquireWithoutYield( timeout ); } else { //ScopedBusyCursor hourglass( Cursor_KindaBusy ); wxTimeSpan countdown( (timeout) ); do { if( AcquireWithoutYield( def_yieldgui_interval ) ) break; YieldToMain(); countdown -= def_yieldgui_interval; } while( countdown.GetMilliseconds() > 0 ); return countdown.GetMilliseconds() > 0; } #else return AcquireWithoutYield(); #endif }
int main(void) { setEnvironment(); setOutput(); setScoreboard(); while(1) { setRaceMode(); PLAYER ppp[numOfPlayers]; setPlayer(&ppp, 0, STARTING_POSITION_X, 18, '1', 65, 66, 67, 68); setPlayer(&ppp, 1, STARTING_POSITION_X, 20, '2', 119, 115, 100, 97); players = &ppp; redrawScreen(); splashScreen(); countdown(); setStartTime(&ppp); char c; while (!weHaveAWinner(&ppp)) { c = getc(stdin); checkMove(c, &ppp); } printWins(); checkeredFlag(); waitForEnter(); } return EXIT_SUCCESS; }
static void newRound(void) { endRound(); snake[0].yDir = snake[1].yDir = 0; snake[0].length = snake[1].length = 3; snake[0].hasTurned = snake[1].hasTurned = false; snake[0].xDir = 1; snake[0].body.x[0] = 2; snake[0].body.y[0] = 1; snake[0].body.x[1] = 1; snake[0].body.y[1] = 1; snake[0].body.x[2] = 1; snake[0].body.y[2] = 2; snake[1].xDir = -1; snake[1].body.x[0] = 5; snake[1].body.y[0] = 6; snake[1].body.x[1] = 6; snake[1].body.y[1] = 6; snake[1].body.x[2] = 6; snake[1].body.y[2] = 5; generateApple(); apple.on = false; secondSnakeOn = false; countdown(start, menu); }
int main (void) { /* center messages, etc. */ setupRects(); /* Basic setup */ startSDL(); /* load images */ loadImages(); /* blit them onto the screen */ showControls(); clearScreen(screen); /* go 3, 2, and 1 */ countdown(); /* put the paddle and the ball in the initial position */ initiateImages(); /* call game loop here, defined in gameloop.c, handover all the filled structs */ initGameloop(&mainPaddle, &mainBall, screen); int score = runGameloop(); printf("Score: %d\n", score); SDL_Quit(); return 0; }
void countdown(int n) { if (n == 0) { printf("0\n"); } else { printf("%d ", n); countdown(rest(n)); } }
static void *autoboot_thread(void *arg) { if (!countdown("boot", g_autoboot_delay_secs)) { tboot_ui_warn("Boot canceled, back to Pre-OS mode."); return NULL; } return (void *)start_default_kernel(); }
task main() { int timeToWait = requestTimeToWait(); initializeRobot(); waitForStart(); disableDiagnosticsDisplay(); //Initialize the gyro and turning GyroInit(g_Gyro, gyro, 0); PidTurnInit(g_PidTurn, leftDrive, rightDrive, MIN_TURN_POWER, g_Gyro, TURN_KP, TURN_TOLERANCE); countdown(timeToWait); //Start actual movement code moveForwardInches(60,43);//initial forwards turn(g_PidTurn,45,20); clearEncoders(); wait1Msec(50); const int totalTics = 6806;//total tics from before IR to end- CHANGED FOR LESSENED AMOUNT OF FORWARDS const int ticsToCenter = 3663;//tics from start to central beam const int ticsToSubtract = 1665;//failsafe, may still need testing //finding IR while(HTIRS2readACDir(IR) != 4 && (abs(nMotorEncoder[leftDrive]) < totalTics - ticsToSubtract)){ //finds the beacon zone 4 (rough) //nxtDisplayCenteredTextLine(5,"Direction:%d",HTIRS2readACDir(IR)); startBackward(27); } stopDrive(); wait1Msec(300); while(HTIRS2readACDir(IR) != 5 && (abs(nMotorEncoder[leftDrive]) < totalTics - ticsToSubtract)){ //slow down to look for basket (fine) startForward(15); } int currentPosition = abs(nMotorEncoder[leftDrive]); if (currentPosition > ticsToCenter)//check where we are moveForwardInchesNoReset(20, 6);//move forwards 5 inches (buckets 1 and 2) else moveForwardInchesNoReset(20, 3);//forwards 3 inches (buckets 3 and 4) stopDrive();//stops robot servo[dumper] = 30;//dumps the block motor[lift]= 50;//starts the lift up wait1Msec(700); motor[lift]= 0;//stops lift servo[dumper] = servoRestPosition;//resets servo int ticsToMove= totalTics - abs(nMotorEncoder[leftDrive]);//tics left after IR displayCenteredTextLine(0,"TTM: %d", ticsToMove); moveBackwardTics(90, ticsToMove); //move to end after IR turn(g_PidTurn, -87,40); //turn to go towards ramp moveForwardInches(90, 44, false, LEFTENCODER); //forwards to ramp turn(g_PidTurn, 95, 40); //turn to face ramp moveForwardInches(90, 45, false, LEFTENCODER);//onto ramp motor[lift]= -50;//starts the lift down wait1Msec(500); motor[lift]= 0;//stops lift while(true){} }
void addToAckWaitList(uint8_t indexAckWaitList, const char *pThingName, ShadowActions_t action, const char *pExtractedClientToken, fpActionCallback_t callback, void *pCallbackContext, uint32_t timeout_seconds) { AckWaitList[indexAckWaitList].callback = callback; strncpy(AckWaitList[indexAckWaitList].clientTokenID, pExtractedClientToken, MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE); strncpy(AckWaitList[indexAckWaitList].thingName, pThingName, MAX_SIZE_OF_THING_NAME); AckWaitList[indexAckWaitList].pCallbackContext = pCallbackContext; AckWaitList[indexAckWaitList].action = action; InitTimer(&(AckWaitList[indexAckWaitList].timer)); countdown(&(AckWaitList[indexAckWaitList].timer), timeout_seconds); AckWaitList[indexAckWaitList].isFree = false; }
void introScreen(){ GLCD.ClearScreen(BLACK); GLCD.DrawBitmap(icon, 32,0); //draw the bitmap at the given x,y position countdown(3); GLCD.ClearScreen(); GLCD.SelectFont(Arial_14); // you can also make your own fonts, see playground for details GLCD.CursorToXY(GLCD.Width/2 - 44, 3); GLCD.print("GLCD version "); GLCD.print(GLCD_VERSION, DEC); GLCD.DrawRoundRect(8,0,GLCD.Width-19,17, 5); // rounded rectangle around text area countdown(3); GLCD.ClearScreen(); scribble(5000); // run for 5 seconds moveBall(6000); // kick ball for 6 seconds GLCD.SelectFont(System5x7, BLACK); showCharacters((char*)"5x7 font:", System5x7); countdown(3); showCharacters((char*)"Arial_14:", Arial_14); countdown(3); textAreaDemo(); scrollingDemo(); }
//prints a live countdown relative to given date void printCountdown (State *s) { s->next = NULL; TDate *date = parse(s->argv[2]); if (!date) { printf("Could not parse date. Check formatting\n"); return; } TDate *now = currentDate(NULL); countdown (toJulian(now), toJulian(date)); }
IoT_Error_t subscribeToShadowActionAcks(const char *pThingName, ShadowActions_t action, bool isSticky) { IoT_Error_t ret_val = NONE_ERROR; MQTTSubscribeParams subParams = MQTTSubscribeParamsDefault; bool clearBothEntriesFromList = true; int16_t indexAcceptedSubList = 0; int16_t indexRejectedSubList = 0; indexAcceptedSubList = getNextFreeIndexOfSubscriptionList(); indexRejectedSubList = getNextFreeIndexOfSubscriptionList(); if (indexAcceptedSubList >= 0 && indexRejectedSubList >= 0) { topicNameFromThingAndAction(SubscriptionList[indexAcceptedSubList].Topic, pThingName, action, SHADOW_ACCEPTED); subParams.mHandler = AckStatusCallback; subParams.qos = QOS_0; subParams.pTopic = SubscriptionList[indexAcceptedSubList].Topic; ret_val = pMqttClient->subscribe(&subParams); if (ret_val == NONE_ERROR) { SubscriptionList[indexAcceptedSubList].count = 1; SubscriptionList[indexAcceptedSubList].isSticky = isSticky; topicNameFromThingAndAction(SubscriptionList[indexRejectedSubList].Topic, pThingName, action, SHADOW_REJECTED); subParams.pTopic = SubscriptionList[indexRejectedSubList].Topic; ret_val = pMqttClient->subscribe(&subParams); if (ret_val == NONE_ERROR) { SubscriptionList[indexRejectedSubList].count = 1; SubscriptionList[indexRejectedSubList].isSticky = isSticky; clearBothEntriesFromList = false; // wait for SUBSCRIBE_SETTLING_TIME seconds to let the subscription take effect Timer subSettlingtimer; InitTimer(&subSettlingtimer); countdown(&subSettlingtimer, SUBSCRIBE_SETTLING_TIME); while(!expired(&subSettlingtimer)); } } } if (clearBothEntriesFromList) { if (indexAcceptedSubList >= 0) { SubscriptionList[indexAcceptedSubList].isFree = true; } else if (indexRejectedSubList >= 0) { SubscriptionList[indexRejectedSubList].isFree = true; } if (SubscriptionList[indexAcceptedSubList].count == 1) { ret_val = pMqttClient->unsubscribe(SubscriptionList[indexAcceptedSubList].Topic); } } return ret_val; }
// method creates and manages the three needed processes // pipes are created and seconds are converted void processManager(int time) { int status; secondsToMinutes(time); pipe(pfd); // current time process switch(fork()) { case -1: printf("Error creating child process one."); exit(0); case 0: displayTime(); default: break; } // uptime program process switch(fork()) { case -1: printf("Error creating child process two."); exit(0) case 0: runUptimeProgram(); default: break; } // remaining time process switch(fork()) { case -1: printf("Error creating child process three."); exit(0); case 0: countdown(minutes, seconds); default: break; } //parent closes unued pipes close(pfd[0]; close(pf[1]); wait(&sttus); wait(&status); wait(&status); friendlyMessage(); return; }
void ResourceCache::LoadBombResources(const TiXmlHandle& hndl) { const Size size = mAppConfig.GetCellSize(); const auto len = mAppConfig.GetBombLifetime(); BombResource countdown(BombType::Countdown); countdown.SetFrames(len, LoadTextures(hndl, "Countdown", size)); BombResource remote(BombType::Remote); remote.SetFrames(len, LoadTextures(hndl, "Remote", size)); mBombRes.insert({ countdown.GetType(), countdown }); mBombRes.insert({ remote.GetType(), remote }); }
int MQTTConnect (Client *c, MQTTPacket_connectData *options) { Timer connect_timer; int rc = FAILURE; int len = 0; MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; InitTimer (&connect_timer); countdown_ms (&connect_timer, c->command_timeout_ms); if (c->isconnected) // don't send connect packet again if we are already connected goto exit; if (options == 0) options = &default_options; // set default options if none were supplied c->keepAliveInterval = options->keepAliveInterval; countdown (&c->ping_timer, c->keepAliveInterval); //-------------------------------------------------------------------- // Generate a MQTT "Connect" packet, and send it to the remote Broker //-------------------------------------------------------------------- len = MQTTSerialize_connect (c->buf, c->buf_size, options); if (len <= 0) goto exit; // supplied buffer is too small rc = sendPacket (c, len, &connect_timer); // send the connect packet if (rc != SUCCESS) goto exit; // there was a problem //-------------------------------------------------------------------- // Wait for and read in the MQTT "ConnAck" reply packet. //-------------------------------------------------------------------- // this will be a blocking call, wait for the connack if (waitfor(c, CONNACK, &connect_timer) == CONNACK) { unsigned char connack_rc = 255; char sessionPresent = 0; if (MQTTDeserialize_connack((unsigned char*) &sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1) rc = connack_rc; else rc = FAILURE; } else rc = FAILURE; exit: if (rc == SUCCESS) c->isconnected = 1; return rc; }
static void do_launch_program() { int num = 1; launch_cfg_t lc; /* * Control flow: * - Do the startup led blinks. * - Read the launch config switches. * - Store launch config * - Light the launch config leds. * - Wait for launch button to be pressed * - Do countdown * - Activate launch transistors per the launch config. */ do_startup_blinky(); g_launch_cfg = get_launch_cfg(); set_launch_cfg_leds(g_launch_cfg); while (1) { /* * poll for launch cfg change or launch button press */ lc = get_launch_cfg(); set_launch_cfg_leds(lc); /* * Is a human pressing the launch button? */ if ((PINC & (1 << PINC3)) == 0) { break; } delay_ms(300); } num = countdown(9, 900); if (!num) { do_launch(); num = countup(0, 900); } else { blink(num, 900); } }
int keepalive(Client* c) { int rc = FAILURE; if (c->keepAliveInterval == 0) { return SUCCESS; } if (expired(&c->ping_timer)) { if (!c->ping_outstanding) { // there is not a ping outstanding - send one Timer timer; InitTimer(&timer); countdown_ms(&timer, 2000); //STM: modified the value from 1000 to 2000 int len = MQTTSerialize_pingreq(c->buf, c->buf_size); INFO("-->keepalive"); rc = sendPacket(c, len, &timer); // send the ping packet DeInitTimer(&timer); //STM: added this line if (len > 0 && rc == SUCCESS) { c->ping_outstanding = 1; // start a timer to wait for PINGRESP from server countdown(&c->ping_timer, c->keepAliveInterval / 2); } else { rc = FAILURE; } } else { // timer expired while waiting for a ping - decide we are disconnected MQTTDisconnect(c); if (c->disconnectHandler != NULL) { c->disconnectHandler(); } } } else { rc = SUCCESS; } return rc; }
int MQTTConnect(Client* c, MQTTPacket_connectData* options) { Timer connect_timer; int rc = FAILURE; MQTTPacket_connectData default_options = MQTTPacket_connectData_initializer; int len = 0; InitTimer(&connect_timer); countdown_ms(&connect_timer, c->command_timeout_ms); if (c->isconnected) // don't send connect packet again if we are already connected goto exit; if (options == 0) options = &default_options; // set default options if none were supplied c->keepAliveInterval = options->keepAliveInterval; countdown(&c->ping_timer, c->keepAliveInterval); if ((len = MQTTSerialize_connect(c->buf, c->buf_size, options)) <= 0) goto exit; if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESS) // send the connect packet goto exit; // there was a problem // this will be a blocking call, wait for the connack if (waitfor(c, CONNACK, &connect_timer) == CONNACK) { unsigned char connack_rc = 255; char sessionPresent = 0; if (MQTTDeserialize_connack((unsigned char*)&sessionPresent, &connack_rc, c->readbuf, c->readbuf_size) == 1) rc = connack_rc; else rc = FAILURE; } else rc = FAILURE; exit: if (rc == SUCCESS) c->isconnected = 1; DeInitTimer(&connect_timer); //STM: added this line of code return rc; }
void KinectV2Classifier::update() { checkOscMessages(); if (toPredict || toRecord) { countdown(); } else { clock.update(); } if (skeleton != NULL) { if (capturing) { captureGesture(); } } }
task main() { int timeToWait = requestTimeToWait(); initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. GyroInit(g_Gyro, gyro, 0); PidTurnInit(g_PidTurn, leftDrive, rightDrive, MIN_TURN_POWER, g_Gyro, TURN_KP, TURN_TOLERANCE); //Align against bottom wall, with left edge of left wheels on left edge of third tile (6ft from right wall). countdown(timeToWait); moveForwardInches(80, 30, false, LEFTENCODER); //away from wall turn(g_PidTurn, 90); //turn to parallel with buckets moveBackwardInches(90,20,false,LEFTENCODER); while (true) {} }
int try_update_sw(Volume *vol, int use_countdown) { int ret = 0; char *update_location; /* Check if we've already been here */ if (g_update_location) return 0; update_location = detect_sw_update(vol); if (!update_location) return 0; if (use_countdown) { int countdown_complete; countdown_complete = countdown("SW update", g_autoboot_delay_secs); if (!countdown_complete) { tboot_ui_hidebar("SW update canceled."); free(update_location); return 0; } } ret = -1; pthread_mutex_lock(&action_mutex); tboot_ui_bouncebar("Performimg SW update..."); if (provisioning_checks(vol)) { free(update_location); } else { if (!g_update_pause) { apply_sw_update(update_location, 0); free(update_location); } else { /* Stash the location for later use with * 'fastboot continue' */ g_update_location = update_location; ret = 0; } } tboot_ui_hidebar(""); pthread_mutex_unlock(&action_mutex); return ret; }
//prints a live countdown relative to stored date void printCountdownStored (State *s) { s->next = NULL; FILE *in = fopen(makeFilePath(), "rb"); if (!in) { printf("No date stored. Try to store one by calling \"ctd -s [date]\"\n"); return; } double jdate; fread(&jdate, sizeof(double), 1, in); fclose(in); TDate *now = currentDate(NULL); double jnow = toJulian(now); countdown (jnow, jdate); }
task main() { int timeToWait = requestTimeToWait(); initializeRobot(); waitForStart(); // Wait for the beginning of autonomous phase. GyroInit(g_Gyro, gyro, 0); PidTurnInit(g_PidTurn, leftDrive, rightDrive, MIN_TURN_POWER, g_Gyro, TURN_KP, TURN_TOLERANCE); countdown(timeToWait); moveBackwardInches(80, 30, false, LEFTENCODER); turn(g_PidTurn, -90); moveBackwardInches(90,20,false,LEFTENCODER); while (true) {} }
int main(int argc, const char **argv) { int min = 3, rest = 60; if (argc < 3) { usage(); return 1; } min = atoi(argv[1]); rest = atoi(argv[2]); srand(time(NULL)); total_punches = 0; while (1) { countdown(min, rest); do_round(min); sleep(rest); } return 0; }
int main() { countdown(10); countdownEven(10); printf("%s %s a palindrome\n", "MADAM", isPalindrome("MADAM", strlen("MADAM")) ? "is" : "is not"); LinkedList a = {3, NULL}; LinkedList b = {-4, &a}; LinkedList c = {2, &b}; LinkedList d = {1, &c}; printf("Sum: %d\n", sum(&d)); printf("isAllPositive: %d\n", isAllPositive(&d)); printf( isAllPositiveLessReadableButShorterWithALongerFunctionName(&d) ? "All positive!\n" : "Not all positive!\n"); printList(&d); printf("\n"); printListReverse(&d); printf("\n"); //1 -> 2 -> -4 -> 3 -> //3 -> -4 -> 2 -> 1 -> // BinTree* bt1 = NULL; // BinTree bt = NULL; // can't assign NULL to struct BinTree jean = {"Jean", 24, NULL, NULL}; BinTree jeane = {"Jeane", 27, NULL, NULL}; BinTree icel = {"Icel", 10, NULL, NULL}; BinTree candace = {"Candace", 48, &jean, &jeane}; BinTree lovely = {"Lovely", 9, &icel, NULL}; BinTree honey = {"Honey", 40, &lovely, NULL}; BinTree jj = {"JJ", 3, &honey, &candace}; printf("Population: %d\n", pop(&jj)); printf("Max sales: %d\n", maxSales(&jj)); printf("Num levels: %d\n", numLevels(&jj)); return 0; }
void speed_check() { int i=0; while(1){ if(PORTE.PORT.BIT.B0 == 0){ countdown(); ENC_R=0; ENC_sub_R=0; now_ENC_R=0; ENC_L=0; ENC_sub_L=0; now_ENC_L=0; mot_STB(START_A); MOT_ctr_R1=1; MOT_ctr_R2=0; MOT_ctr_L1=0; MOT_ctr_L2=1; speed=100.0; speed_check_frag=1; while(1){ if(mot_count>=500) break; } mot_brake(); while(1){ if(PORTE.PORT.BIT.B0 == 0){ while(1){ for(i=0; i<1001; i++){ } } } else{} } } else{} } }
static void newRound(void) { endRound(); snake.xDir = 1; snake.yDir = 0; snake.length = 3; snake.hasTurned = false; snake.body.x[0] = 2; snake.body.y[0] = 3; snake.body.x[1] = 1; snake.body.y[1] = 3; snake.body.x[2] = 1; snake.body.y[2] = 4; generateApple(); apple.on = false; countdown(start, menu); }
int sendPacket(Client* c, int length, Timer* timer) { int rc = FAILURE, sent = 0; while (sent < length && !expired(timer)) { rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, left_ms(timer)); if (rc < 0) // there was an error writing the data break; sent += rc; } if (sent == length) { countdown(&c->ping_timer, c->keepAliveInterval); // record the fact that we have successfully sent the packet rc = SUCCESS; } else rc = FAILURE; return rc; }
void launch_diags(void) { int num; set_num(0); for (int i = 0; i < 3; i++) { LC0_HIGH; delay_ms(1000); LC0_LOW; delay_ms(500); } num = countdown(9, 900); g_launch_cfg = LC_ALL; do_launch(); while (1) {} }