int main(void) { pinIO(); serialSetupUSB(); timerSetup(); motorSetup(); encSetup(); //infinete loop in which we count while(1) { //currentVelocity = velocityGet(); moveForward(16); delay(10); moveBackward(16); } //remain here forever, never end the main function. return 0; //we should never really return }
void initIRQ(void){ SET_IRQ_VECTOR(ML13_interrupt, 0x3FF2); __asm(" CLI"); REG8(ML13_IRQ_Control)= 0x01; timerSetup(); puts("IRQ has been initiated"); }
void main(void) { char pinStatus = 0, TXon = 0, boxOpen = 0; long int runTime = 0; // /* device setup */ set32MHzXOSC(); timerSetup(TICKS_FREQ025, T1_PRE); timer4Setup(T4_PRE); // CSPT = 0xFF; // PICTL |= BIT7; P0DIR |= 0x8C; //P0 BIT2,3,7 are output, BIT1,4,5,6 are input if (P0 & BOX) P0 = RED_LED; else P0 = GREEN_LED; /* interrupt setup */ setT1int(); //TIMER1 interrupts setT4int(); //TIMER4 interrupts //void setP0int(); //Port 0 interrupts while(P0 & BOX); //wait for box to close before reading setup parameters T1_ovf_cnt = 0; //restart transmitting period after closing the box pinStatus = readPin(); setupTX(pinStatus); IEN0 |= BIT7; //enable global interrupts. T1CTL |= BIT0; //start timer1 in free running mode if (pinStatus == 0x02) runTime = 322; //total run time is approx. 3 hours else runTime = 18; //total run time is approx. 10 minutes while(T1_ovf_cnt < runTime) //stop program after XXX hours { while(!(P0 & BOX) && T1_ovf_cnt < runTime) //Box is closed { if (!TXon) { if (pinStatus == 0x22) freqSweep(FREQ2395, FREQ2507, 4); else startTX(); TXon = 1; } } stopTX(); TXon = 0; // if (P0 & BOX) boxOpen = 1; // else // { // while(P0 & BOX); //wait for box to close before reading setup parameters // } while (P0 & BOX) boxOpen = 1; if (boxOpen == 1) T1_ovf_cnt = 0; //restart transmitting period after closing the box pinStatus = readPin(); setupTX(pinStatus); if (pinStatus == 0x02) runTime = 645; //total run time is approx. 6 hours else runTime = 18; //total run time is approx. 10 minutes boxOpen = 0; } stopTX(); }
int main() { // line 25 setup(); timerSetup(); while(1) { standby(); } return 0; }
void main(void) { unsigned char stage_no = 1, stage_cnt = 0, T1_IF; set32MHzXOSC(); timerSetup(T1_TICKS, T1_PRE); /* selected output pin */ //P1SEL |= BIT7; //use P1_7 as peripheral function P1DIR |= (BIT1); //P1_1 direction to output P1 &= ~(BIT1| BIT0); //clear output clearIRQ(); while(1) { T1CTL |= BIT0; //start TIMER1 in free operation mode /* 10 seconds wait*/ for(int i=0;i<5;i++) { T1_IF = T1STAT & BIT5; //isolate TIMER1 IF while(!T1_IF) //wait for overflow IF { T1_IF = T1STAT & BIT5; } clearIRQ(); } T1CTL &= ~(BIT1 | BIT0); //stop TIMER1 T1CNTL = 0x00; //clear TIMER1 clearIRQ(); for(stage_cnt=0;stage_cnt<2*stage_no;stage_cnt++) { T1CTL |= BIT0; //start TIMER1 in free operation mode /* set output */ P1 ^= (BIT1 | BIT0); T1_IF = T1STAT & BIT5; //isolate TIMER1 IF while(!(T1STAT & BIT5)); //wait for overflow IF T1CTL &= ~(BIT1 | BIT0); //stop TIMER1 T1CNTL = 0x00; //clear TIMER1 clearIRQ(); } if(stage_no == 5) stage_no = 1; else stage_no++; T1CTL &= ~(BIT1 | BIT0); //stop TIMER1 T1CNTL = 0x00; //clear TIMER1 clearIRQ(); } }
int main(){ SystemInit(); setup(); adcSetup(); Init_Display(); timerSetup(); tempMeasure(); updateDegrees(); setupInterupts(5); lightMeasure(); pwmSetup(); setupInterupts(1000); PrintMenu(); *PWM_CDTYUPD = 1800; int input; while(nInterupts < 500){} while(1){ if(nInterupts >= 500){ tempMeasure(); nInterupts = 0; } updateDegrees(); Print(floatToChar, 33,1); //Skriv ut temperatur if(value > maxLimit){ Print("ALARM", 32, 3); Print("TOO HOT ", 32,4); } else if(value < lowLimit){ Print(" ALARM", 32, 3); Print("TOO COLD", 32,4); } else if(value >lowLimit || value<maxLimit){ Print(" ", 32, 3); Print(" ", 32, 4); } if(tempCount >= fastMode){ updateDegrees(); delay(60); if(tempFlag == 1){ tempCalc(); tempCount = 0; tempFlag = 0; } } input = readKeypad(); if(buttonPressed == 1){ buttonPressed = 0; menuCases(&input); } } }
void main(void) { WDTCTL = WDTPW | WDTHOLD; //stop watchdog timer LEDSetup(); buttonSetup(); timerSetup(); _BIS_SR(GIE); //global interrupts enabled while(1) { } }
/*Initialize class with user values.*/ StepperControl::StepperControl(int motorsCountE, int *enablePinE, int *invertEnableE, int *stepPinE, int *dirPinE, int *invertDirE, double *speedE, long *signalLengthE, long clockFrequencyE){ clockFrequency = clockFrequencyE; motorsCount = motorsCountE; repeatInLoop = idleFunc; enablePin = (int*)calloc(motorsCount, sizeof(int)); invertEnable = (int*)calloc(motorsCount, sizeof(int)); stepPin = (int*)calloc(motorsCount, sizeof(int)); dirPin = (int*)calloc(motorsCount, sizeof(int)); invertDir = (int*)calloc(motorsCount, sizeof(int)); speed = (double*)calloc(motorsCount, sizeof(double)); signalLength = (long*)calloc(motorsCount, sizeof(long)); //Time required for 1 full cycle, based on signalLength and speedE. movementTime = (long*)calloc(motorsCount, sizeof(long)); lowTime = (long*)calloc(motorsCount, sizeof(long)); highTime = (long*)calloc(motorsCount, sizeof(long)); stepStatus = (int*)calloc(motorsCount, sizeof(int)); nextStateChange = (unsigned long*)calloc(motorsCount, sizeof(unsigned long)); currentState = (uint8_t*)calloc(motorsCount, sizeof(uint8_t)); nextStep = (unsigned long*)calloc(motorsCount, sizeof(unsigned long)); individualStepsCounter = (unsigned long*)calloc(motorsCount, sizeof(unsigned long)); enabledMotors = (uint8_t*)calloc(motorsCount, sizeof(uint8_t)); memcpy(enablePin, enablePinE, motorsCount*sizeof(int)); memcpy(invertEnable, invertEnableE, motorsCount*sizeof(int)); memcpy(stepPin, stepPinE, motorsCount*sizeof(int)); memcpy(dirPin, dirPinE, motorsCount*sizeof(int)); memcpy(invertDir, invertDirE, motorsCount*sizeof(int)); memcpy(signalLength, signalLengthE, motorsCount*sizeof(long)); setSpeed(speedE); timerSetup(); for(int i = 0; i < motorsCount; i++){ stepStatus[i] = 0; pinMode(enablePin[i], OUTPUT); digitalWrite(enablePin[i], 1); pinMode(stepPin[i], OUTPUT); digitalWrite(stepPin[i], 0); pinMode(dirPin[i], OUTPUT); digitalWrite(dirPin[i], 0); } //Adding the function responsible for the movement to the interrupts. if(motorsCount > 0) StepperControl::attachInterrupt(interruptExec); }
/** * This helper function calculates the hour, min, sec * then sets the global variable, time, accordingly. * It then prints the result by calling printTime(); * @param c The char value choosing what action to take * it can be to just check / stop time. * or it can be to add / subtract time. */ void changeTime(char c){ //adding an hour if(c == 'h'){ time += 3600; } //subtracting an hour if(c == 'H'){ time -= 3600; } //adding a minute if(c == 'm'){ time += 60; } //subtracting a minute if(c == 'M'){ time -= 60; } //adding a second if(c == 's'){ time += 1; } //subtracting a second if(c == 'S'){ time -= 1; } //clearing the timer if(c == 'c'){ time = 0; } //starting/stopping the timer if(c == 'r'){ if(running == TRUE){ running = FALSE; alarm(0); } else{ running = TRUE; timerSetup(); } } printTime(FALSE); }
void main(void) { long int runTime = 0; char boxOpen = 0; /* device setup */ set32MHzXOSC(); timerSetup(TICKS_FREQ025, T1_PRE); timer4Setup(T4_PRE); // CSPT = 0xFF; // PICTL |= BIT7; P0DIR |= 0x8C; //P0 BIT2,3,7 are output, BIT1,4,5,6 are input // if (P0 & BOX) P0 = RED_LED; // else P0 = GREEN_LED; /* interrupt setup */ setT1int(); //TIMER1 interrupts setT4int(); //TIMER4 interrupts // setP0int(); //Port 0 interrupts // while(P0 & BOX); //wait for box to close before reading setup parameters T1_ovf_cnt = 0; //restart transmitting period after closing the box TXFreq = FREQ2400; IEN0 |= BIT7; //enable global interrupts. T1CTL |= BIT0; //start timer1 in free running mode runTime = 9; rfTXConfig(FREQ2455, OUTPUT_POWER); startTX(); while(T1_ovf_cnt < runTime) //stop program after 'runTime' no. of T1 overflow. { while ((P0 & BOX) && (T1_ovf_cnt < runTime)); stopTX(); while (P0 & BOX) boxOpen = 1; if (boxOpen == 1) T1_ovf_cnt = 0; //restart transmitting period after closing the box runTime = 9; //total run time is approx. 10 minutes boxOpen = 0; } stopTX(); }
/** The main thing. * @param argc count of command-line tokens. * @param argv array of command-line tokens. * @return 0 on success, 1-255 on failure. */ int main(int argc, char* argv[]){ if(argc != 2){ printf("usage: mytimer <seconds>\n"); return EXIT_FAILURE; } if(sscanf(argv[1], "%lf",&time) != 1){ printf("\"%s\" is not a number.\n", argv[1]); return EXIT_FAILURE; } if(time <= 0){ printf("Invalid time(%lf). Must be >= 0.\n",time); return EXIT_FAILURE; } running = TRUE; char c = 'z'; set_input_mode(); //setup the signal stuff timerSetup(); while(1){ read (STDIN_FILENO, &c, 1); if(c == 'q'){ fprintf(stdout,"\n"); fflush(stdout); return EXIT_SUCCESS; } if(c == 'h' || c == 'H' || c == 'm' || c == 'M' || c == 's' || c == 'S' || c == 'c' || c == 'r'){ changeTime(c); c = 'z'; } } return EXIT_SUCCESS; }
int main(void) { // _TRISD = 0; pinIO(); serialSetup(); pwmSetup(); setupA2D(); timerSetup(); //infinete loop in which we count while(1) { } //remain here forever, never end the main function. return 0; //we should never really return }
int main(void) { pinIO(); encSetup(); serialSetupUSB(); serialSetupP2P(); timerSetup(); pwmSetup(); setupA2D(); //infinete loop in which we count while(1) { //LED1LATCH = 1; } //remain here forever, never end the main function. return 0; //we should never really return }
pwmStatus pwmSetup(int id, int timer, float periodMs) { timerStatus err; //on vérifie si l'ID de la pwm est correcte if (id != PWM_1 && id != PWM_2 && id != PWM_3 && id != PWM_4) { return PWM_ID_ERROR; } //on vérifie si l'ID du timer est correcte if (timer != TIMER_2 && timer != TIMER_3) { return PWM_TID_ERROR; } //création du timer associé err = timerSetup(timer, periodMs); //on vérifie si la période est correcte if (err == TIMER_PERIOD_ERROR) { return PWM_PERIOD_ERROR; } *OCxRS[id - 1] = 0; // remise à zéro du rapport cyclique //activation de la PWM if (timer == TIMER_2) { *OCxCON[id - 1] = 0b0110; } else { *OCxCON[id - 1] = 0b1110; } //lancement du timer timerStart(timer); return PWM_SUCCESS; }
int main(void) { pinIO(); serialSetupUSB(); serialSetupP2P(); timerSetup(); //pwmSetup(); setupA2D(); motorSetup(); encSetup(); int motor1; //int motor1speed = 200; int motor2speed = 200; char targetVelocity1 = 0; char currentVelocity; float pop; char error = 0; //infinete loop in which we count while(1) { //currentVelocity = velocityGet(); motor1 = motorSet(39); motor1 = 200; //targetVelocity1 = 30; //error = targetVelocity1 - currentVelocity; //int test /* if (currentVelocity > targetVelocity1) { if(motor1speed > 0) { motor1speed -=2; } else { motor1speed = 0; } } else if (currentVelocity < targetVelocity1) { if(motor1speed < 798) { motor1speed +=2; } else { motor1speed = 798; } //motor1speed = 798*(float)(1-(float)(currentVelocity / targetVelocity1)); }*/ motor1Forward(motor1); motor2Forward(motor2speed); } //remain here forever, never end the main function. return 0; //we should never really return }
PtpClock * ptpdStartup(int argc, char **argv, Integer16 * ret, RunTimeOpts * rtOpts) { PtpClock * ptpClock; TimeInternal tmpTime; int i = 0; /* * Set the default mode for all newly created files - previously * this was not the case for log files. This adds consistency * and allows to use FILE* vs. fds everywhere */ umask(~DEFAULT_FILE_PERMS); /* get some entropy in... */ getTime(&tmpTime); srand(tmpTime.seconds ^ tmpTime.nanoseconds); /** * If a required setting, such as interface name, or a setting * requiring a range check is to be set via getopts_long, * the respective currentConfig dictionary entry should be set, * instead of just setting the rtOpts field. * * Config parameter evaluation priority order: * 1. Any dictionary keys set in the getopt_long loop * 2. CLI long section:key type options * 3. Any built-in config templates * 4. Any templates loaded from template file * 5. Config file (parsed last), merged with 2. and 3 - will be overwritten by CLI options * 6. Defaults and any rtOpts fields set in the getopt_long loop **/ /** * Load defaults. Any options set here and further inside loadCommandLineOptions() * by setting rtOpts fields, will be considered the defaults * for config file and section:key long options. */ loadDefaultSettings(rtOpts); /* initialise the config dictionary */ rtOpts->candidateConfig = dictionary_new(0); rtOpts->cliConfig = dictionary_new(0); /* parse all long section:key options and clean up argv for getopt */ loadCommandLineKeys(rtOpts->cliConfig,argc,argv); /* parse the normal short and long options, exit on error */ if (!loadCommandLineOptions(rtOpts, rtOpts->cliConfig, argc, argv, ret)) { goto fail; } /* Display startup info and argv if not called with -? or -H */ NOTIFY("%s version %s starting\n",USER_DESCRIPTION, USER_VERSION); dump_command_line_parameters(argc, argv); /* * we try to catch as many error conditions as possible, but before we call daemon(). * the exception is the lock file, as we get a new pid when we call daemon(), * so this is checked twice: once to read, second to read/write */ if(geteuid() != 0) { printf("Error: "PTPD_PROGNAME" daemon can only be run as root\n"); *ret = 1; goto fail; } /* Have we got a config file? */ if(strlen(rtOpts->configFile) > 0) { /* config file settings overwrite all others, except for empty strings */ INFO("Loading configuration file: %s\n",rtOpts->configFile); if(loadConfigFile(&rtOpts->candidateConfig, rtOpts)) { dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, 1, "from command line"); } else { *ret = 1; dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, 1, "from command line"); goto configcheck; } } else { dictionary_merge(rtOpts->cliConfig, rtOpts->candidateConfig, 1, 1, "from command line"); } /** * This is where the final checking of the candidate settings container happens. * A dictionary is returned with only the known options, explicitly set to defaults * if not present. NULL is returned on any config error - parameters missing, out of range, * etc. The getopt loop in loadCommandLineOptions() only sets keys verified here. */ if( ( rtOpts->currentConfig = parseConfig(CFGOP_PARSE, NULL, rtOpts->candidateConfig,rtOpts)) == NULL ) { *ret = 1; dictionary_del(&rtOpts->candidateConfig); goto configcheck; } /* we've been told to print the lock file and exit cleanly */ if(rtOpts->printLockFile) { printf("%s\n", rtOpts->lockFile); *ret = 0; goto fail; } /* we don't need the candidate config any more */ dictionary_del(&rtOpts->candidateConfig); /* Check network before going into background */ if(!testInterface(rtOpts->primaryIfaceName, rtOpts)) { ERROR("Error: Cannot use %s interface\n",rtOpts->primaryIfaceName); *ret = 1; goto configcheck; } if(rtOpts->backupIfaceEnabled && !testInterface(rtOpts->backupIfaceName, rtOpts)) { ERROR("Error: Cannot use %s interface as backup\n",rtOpts->backupIfaceName); *ret = 1; goto configcheck; } configcheck: /* * We've been told to check config only - clean exit before checking locks */ if(rtOpts->checkConfigOnly) { if(*ret != 0) { printf("Configuration has errors\n"); *ret = 1; } else printf("Configuration OK\n"); goto fail; } /* Previous errors - exit */ if(*ret !=0) goto fail; /* First lock check, just to be user-friendly to the operator */ if(!rtOpts->ignore_daemon_lock) { if(!writeLockFile(rtOpts)){ /* check and create Lock */ ERROR("Error: file lock failed (use -L or global:ignore_lock to ignore lock file)\n"); *ret = 3; goto fail; } /* check for potential conflicts when automatic lock files are used */ if(!checkOtherLocks(rtOpts)) { *ret = 3; goto fail; } } /* Manage log files: stats, log, status and quality file */ restartLogging(rtOpts); /* Allocate memory after we're done with other checks but before going into daemon */ ptpClock = (PtpClock *) calloc(1, sizeof(PtpClock)); if (!ptpClock) { PERROR("Error: Failed to allocate memory for protocol engine data"); *ret = 2; goto fail; } else { DBG("allocated %d bytes for protocol engine data\n", (int)sizeof(PtpClock)); ptpClock->foreign = (ForeignMasterRecord *) calloc(rtOpts->max_foreign_records, sizeof(ForeignMasterRecord)); if (!ptpClock->foreign) { PERROR("failed to allocate memory for foreign " "master data"); *ret = 2; free(ptpClock); goto fail; } else { DBG("allocated %d bytes for foreign master data\n", (int)(rtOpts->max_foreign_records * sizeof(ForeignMasterRecord))); } } if(rtOpts->statisticsLog.logEnabled) ptpClock->resetStatisticsLog = TRUE; /* Init to 0 net buffer */ memset(ptpClock->msgIbuf, 0, PACKET_SIZE); memset(ptpClock->msgObuf, 0, PACKET_SIZE); /* Init outgoing management message */ ptpClock->outgoingManageTmp.tlv = NULL; /* DAEMON */ #ifdef PTPD_NO_DAEMON if(!rtOpts->nonDaemon){ rtOpts->nonDaemon=TRUE; } #endif if(!rtOpts->nonDaemon){ /* * fork to daemon - nochdir non-zero to preserve the working directory: * allows relative paths to be used for log files, config files etc. * Always redirect stdout/err to /dev/null */ if (daemon(1,0) == -1) { PERROR("Failed to start as daemon"); *ret = 3; goto fail; } INFO(" Info: Now running as a daemon\n"); /* * Wait for the parent process to terminate, but not forever. * On some systems this happened after we tried re-acquiring * the lock, so the lock would fail. Hence, we wait. */ for (i = 0; i < 1000000; i++) { /* Once we've been reaped by init, parent PID will be 1 */ if(getppid() == 1) break; usleep(1); } } /* Second lock check, to replace the contents with our own new PID and re-acquire the advisory lock */ if(!rtOpts->nonDaemon && !rtOpts->ignore_daemon_lock){ /* check and create Lock */ if(!writeLockFile(rtOpts)){ ERROR("Error: file lock failed (use -L or global:ignore_lock to ignore lock file)\n"); *ret = 3; goto fail; } } #if (defined(linux) && defined(HAVE_SCHED_H)) || defined(HAVE_SYS_CPUSET_H) || defined(__QNXNTO__) /* Try binding to a single CPU core if configured to do so */ if(rtOpts->cpuNumber > -1) { if(setCpuAffinity(rtOpts->cpuNumber) < 0) { ERROR("Could not bind to CPU core %d\n", rtOpts->cpuNumber); } else { INFO("Successfully bound "PTPD_PROGNAME" to CPU core %d\n", rtOpts->cpuNumber); } } #endif /* set up timers */ if(!timerSetup(ptpClock->timers)) { PERROR("failed to set up event timers"); *ret = 2; free(ptpClock); goto fail; } /* establish signal handlers */ signal(SIGINT, catchSignals); signal(SIGTERM, catchSignals); signal(SIGHUP, catchSignals); signal(SIGUSR1, catchSignals); signal(SIGUSR2, catchSignals); #if defined PTPD_SNMP /* Start SNMP subsystem */ if (rtOpts->snmp_enabled) snmpInit(rtOpts, ptpClock); #endif NOTICE(USER_DESCRIPTION" started successfully on %s using \"%s\" preset (PID %d)\n", rtOpts->ifaceName, (getPtpPreset(rtOpts->selectedPreset,rtOpts)).presetName, getpid()); ptpClock->resetStatisticsLog = TRUE; #ifdef PTPD_STATISTICS outlierFilterSetup(&ptpClock->oFilterMS); outlierFilterSetup(&ptpClock->oFilterSM); ptpClock->oFilterMS.init(&ptpClock->oFilterMS,&rtOpts->oFilterMSConfig, "delayMS"); ptpClock->oFilterSM.init(&ptpClock->oFilterSM,&rtOpts->oFilterSMConfig, "delaySM"); if(rtOpts->filterMSOpts.enabled) { ptpClock->filterMS = createDoubleMovingStatFilter(&rtOpts->filterMSOpts,"delayMS"); } if(rtOpts->filterSMOpts.enabled) { ptpClock->filterSM = createDoubleMovingStatFilter(&rtOpts->filterSMOpts, "delaySM"); } #endif #ifdef PTPD_PCAP ptpClock->netPath.pcapEventSock = -1; ptpClock->netPath.pcapGeneralSock = -1; #endif /* PTPD_PCAP */ ptpClock->netPath.generalSock = -1; ptpClock->netPath.eventSock = -1; *ret = 0; return ptpClock; fail: dictionary_del(&rtOpts->cliConfig); dictionary_del(&rtOpts->candidateConfig); dictionary_del(&rtOpts->currentConfig); return 0; }
/** * @fn int main(void) * @brief Fonction main du programme. */ int main(void) { // Déclaration des variables locales. match oldMatchStatus = OVER; // Etat précédent duu match (pour les actions d'entrée) actionType choix; //<! Pointeur vers l'action en cours. positionInteger positionInitiale; //<! Position initiale du robot sur la table team equipe; //<! Equipe actuelle. // propIsObstacleType test; pllConfig(); // Configuration de la PLL de l'horloge interne pour tourner à 40MIPS assignSPIO(); // Assignation des pins du dSPIC. servoInit(4, TIMER_2, 10); // initialise 1 servo, utilisant le timer2 à 10ms timerSetup(TIMER_5, 50); TMR5 = 0; initAX12(); // Init de l'AX12 // Initialisation du CAN CanInitialisation(CN_LOGIQUE); propulsionInitCan(); CanDeclarationProduction(CN_LOGIQUE*0x10, &matchStatus, sizeof(matchStatus)); CanDeclarationProduction(CN_LOGIQUE*0x10, &mesureSharp, sizeof(mesureSharp)); ACTIVATE_CAN_INTERRUPTS = 1; //msTimerInit(); // Initialisation du timer des millisecondes, n'est utilisé que pour waitXms (TODO: enlever en mêm temps que waitXms) while(1) { if (getMatchTimerFlag()) { matchStatus = OVER; } // Machine d'état de la logique switch (matchStatus) { case INIT: // Etat initial, phase précédant le match if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); matchTimerInit(); // Initialisation du timer de match initServoClap(); initADC(); // RentrerAimant(); initBLE(); if (EnvoiSharpActif == 1){ timerStart(TIMER_5); IEC1bits.T5IE = 1; } } if (!GOUPILLE_OTEE) { matchStatus = PRE_MATCH; } break; case PRE_MATCH: // Le robot attend le début du match. On peut encore choisir la couleur /* if (detectionObstacleSharp().isObstacleDetected && cool){ // FermerPince(); } else{ // OuvrirPince(); }*/ if (radioGetRxBufferSpace() > 0){ radioGetChar(); } if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); } if (BOUTON_EQUIPE == JAUNE) { equipe = JAUNE; positionInitiale = positionInitialeJaune; //ordreActions = actionsJaune; nbActions = NB_ACTIONS_JAUNE; } else { equipe = VERT; positionInitiale = positionInitialeVert; //ordreActions = actionsVert; nbActions = NB_ACTIONS_VERT; } // TRANSITIONS if (GOUPILLE_OTEE) { // si la goupille est retirée, le match commence StartMatchTimer(); // on lance le timer de match (90s)) propulsionEnable(); // on active la propulsion // msTimerStart(); while(propulsionGetStatus() != STANDING); // on attend que l'ordre soit exécuté propulsionSetPosition(positionInitiale); // On initialise la position de la propulsion while(!compareXYAlpha(propulsionGetPosition(), positionInitiale)); // on attend que l'ordre soit exécuté choix = choixAction(); // Sélection de la prochaine action => c'est dans cette fonction qu'il faut mettre de l'IA matchStatus = ONGOING; } break; case ONGOING: // Le match est lancé if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); } infoAction = choix.ptr2Fct(choix.dest,choix.methode); if (canReceivedOrderFlag) { canReceivedOrderFlag = 0; if (canReceivedCommand == LOGI_SHARP_MESURE) { EnvoiSharpActif = canReceivedData[0]; } } // On met à jour la position de l'autre robot //propulsionAddObstacle(getAllyPos()); switch(infoAction.statut) { case ACTION_PAS_COMMENCEE: case ACTION_EN_COURS: // on attend la fin de l'action break; case ACTION_FINIE: case ACTION_REMISE: choix = choixAction(); // Sélection de la prochaine action => c'est dans cette fonction qu'il faut mettre de l'IA break; case ACTION_ERREUR: matchStatus = ERROR; default: break; } break; case OVER: if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); propulsionDisable(); } if (!GOUPILLE_OTEE) { matchStatus = INIT; } break; case ERROR: if (matchStatus != oldMatchStatus) { oldMatchStatus = matchStatus; CanEnvoiProduction(&matchStatus); } choix = gestionErreur(choix); matchStatus = ONGOING; break; default: matchStatus = ERROR; break; } } return 0; }
void MainWindow::init() { qDebug() << "[MainWindow]" << "[init] Beginning."; shown = false; progress = 0; if (fullscreen == true) { setWindowFlags(Qt::FramelessWindowHint); qDebug() << "[MainWindow]" << "[Constructor] Setting Qt::FramelessWindowHint"; } QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); QWebSettings::globalSettings()->setOfflineStoragePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); QWebSettings::globalSettings()->setAttribute(QWebSettings::PrintElementBackgrounds, true); QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); qDebug() << "[MainWindow]" << "[init] QWebSettings updated."; webView = new QWebView(); page = new SalorPage(this); page->main = this; page->setForwardUnsupportedContent(true); qDebug() << "[MainWindow]" << "[init] SalorPage instantiated and assigned."; webView->setPage(page); //networmanager //SalorNetwork* net = new SalorNetwork(this, networkManager); webView->page()->setNetworkAccessManager(networkManager); qDebug() << "[MainWindow]" << "[init] NetworkAccessManager for SalorPage set."; //cookiejar SalorCookieJar * jar = new SalorCookieJar(this); jar->customerScreenId = customerScreenId; jar->setup(); webView->page()->networkAccessManager()->setCookieJar(jar); qDebug() << "[MainWindow]" << "[init] SalorCookieJar instantiated and set."; //salorjsapi js = new SalorJsApi(this, networkManager); js->webView = webView; qDebug() << "[MainWindow]" << "[init] SalorJsApi instantiated and injected with networkManager and webView."; //diskcache QNetworkDiskCache *diskCache = new QNetworkDiskCache(this); diskCache->setCacheDirectory(PathCache); webView->page()->networkAccessManager()->setCache(diskCache); //optionsdialog optionsDialog = new OptionsDialog(this, networkManager); optionsDialog->customerScreenId = customerScreenId; // when go button on options dialog is pressed connect( optionsDialog, SIGNAL(navigateToUrl(QString)), this, SLOT(navigateToUrl(QString)) ); // when clear cache button on options dialog is pressed connect( optionsDialog, SIGNAL(clearCache()), webView->page()->networkAccessManager()->cache(), SLOT(clear()) ); connect( optionsDialog, SIGNAL(setPrinterCounter(int)), this, SLOT(setPrinterCounter(int)) ); connect( optionsDialog, SIGNAL(setPrinterNames()), this, SLOT(setPrinterNames()) ); qDebug() << "[MainWindow]" << "[init] OptionsDialog instantiated and signals connected."; // salorNotificator salorNotificator = new SalorNotificator(this, networkManager); qDebug() << "[MainWindow]" << "[Constructor] SalorNotificator instantiated."; salorNotificator->customerScreenId = customerScreenId; connect( salorNotificator, SIGNAL(onTcpPrintNotified()), this, SLOT(onTcpPrintNotified()) ); // when customer screen event is sent connect( salorNotificator, SIGNAL(navigateToUrl(QString)), this, SLOT(navigateToUrl(QString)) ); qDebug() << "[MainWindow]" << "[Constructor] onTcpPrintNotified connected."; //statusbar statusBar = new QStatusBar(this); //statusBar->setMaximumHeight(20); setStatusBar(statusBar); progressBar = new QProgressBar(); progressBar->setMinimum(0); progressBar->setMaximum(100); progressBar->setMaximumWidth(70); urlLabel = new QLabel("Location"); printCounterLabel = new QLabel(); closeButton = new QPushButton(); closeButton->setText("X"); statusBar->addPermanentWidget(urlLabel); statusBar->addPermanentWidget(progressBar); statusBar->addPermanentWidget(printCounterLabel); statusBar->addPermanentWidget(closeButton); qDebug() << "[MainWindow]" << "[init] Status bar created, widgets added."; setCentralWidget(webView); webView->show(); webView->load(to_url); connectSlots(); counterSetup(); timerSetup(); setPrinterNames(); qDebug() << "[MainWindow]" << "[init] Ending."; }