Ejemplo n.º 1
0
void ArcadeMode::updateTimer(float delta) {
    if(board->getLowestRow() > nextRowToTouch) {
        EventCustom event("GameWin");
        auto eventDispatcher = Director::getInstance()->getEventDispatcher();
        eventDispatcher->dispatchEvent(&event);
        stopTimer();
        board->stopAllActions();
        return;
    }
    board->moveRows(1, moveSpeed);
    board->addRow();
    moveSpeed = fmax(ARCADE_MODE_MINIMUM_SPEED, moveSpeed - ARCADE_MODE_SPEED_UP_FACTOR);
    stopTimer();
    resumeTimer();
}
Ejemplo n.º 2
0
void pcmRX::pollForMusic(){

  if(!playing){
      int steps = 1;
      //testDataRates2();
    if(steps == 1){
            radi.powerUp();  // << VERY important step for some reason
            delay(5);
            if( txSelX(4,5) ){
              if( tmpArr[0] == 1 && tmpArr[1] == 2 && tmpArr[2] == 3 ){
                steps = 2;  //togLed();//txSelX(5,5); //txSelX(5,50);
              }else{txSelX(5,0); }
            }
    }
    if(steps == 2){
             Serial.println("S2");
             if ( txSel(3,5)){
              radi.read(&intData,sizeof(intData));
              if(intData < 8000 || intData > 22100){Serial.print("st2 "); /*delay(200);Serial.println(intData);*/ return;}
              //Serial.println("strt");
              whichBuff = 0;
              loadSingleBuffer(0); loadSingleBuffer(1);
              buffEmpty[0] = 0; buffEmpty[1] = 0; intCount = 0;
              SAMPLE_RATE = intData;
              if(intData > 20000){SAMPLE_RATE = 20000;}
              //Serial.println("playing");

//              if(timerTracker){  timerTracker=0; startTimer();
//              }else{resumeTimer();}
              if(!playing){ startTimer();
              }else{resumeTimer();}

            }else{ Serial.println("pl2");}
}

  }

}
Ejemplo n.º 3
0
int uthread_suspend(int tid)
{
	blockTimer();
	if(tid == 0)
	{
		std::cerr<< BLOCK_ERR_MAIN <<std::endl;
		resumeTimer();
		return FAILURE;
	}
	if(gThreads.count(tid) == 0)
	{
        std::cerr << BLOCK_ERR << " Thread does not exist." << std::endl;
        resumeTimer();
        return FAILURE;
	}
	Thread* tmp = gThreads[tid];
	if(tmp->getState() == BLOCKED )
	{
//		no effect
		resumeTimer();
		return SUCCESS;
	}
	if(tmp->getState() == RUNNING )
	{
//		make scheduling decision (move to next thread)
		switchThreads(BLOCKED);
		resumeTimer();
		return SUCCESS;
	}
	if(tmp->getState() == READY )
	{
//		move to gBlocked + update state in thread
		gReady.remove(tid);
		gBlocked[tid] = tmp;
		tmp->setState(BLOCKED);
		resumeTimer();
		return SUCCESS;
	}
	std::cerr << BLOCK_ERR << std::endl;
	resumeTimer();
	return FAILURE;
}
Ejemplo n.º 4
0
	void runNode(void *data) {
		MoveNode *currNode = (MoveNode *)data;
		MoveNode *currChild = currNode->child;

		if (currNode->nodeId == NULL) {
			return;
		}

		for (int i = 0; i < pairMap[currNode->nPairId].numSensors; i++) {
			Sensor *sensor = &pairMap[currNode->nPairId].sensors[i];
			// createSensor(sensor);
			/*if (sensor->type == SHAFT_ENCODER) {
				sensor->enc = encoderInit(sensor->port, sensor->port + 1, false);
			}*/
			startSensor(sensor);
			sensor = NULL;
		}

		signed char *saveState = NULL;

		printDebug("Started node.");
		// printf("Started node %d.\n\r", currNode->nodeId);
		// printf("Node's child: %d\n\r", currChild->nodeId);
		int nextPoint = 0;
		setMotorSpeeds(currNode, nextPoint);
		nextPoint++;
		while (nextPoint < currNode->numPoints) {
			// printf("DEBUG: %d\n\r", nextPoint);
			while (joystickGetDigital(1, 5, JOY_UP)) { // pause
				if (saveState == NULL) {
					saveState = malloc(pairMap[currNode->nPairId].numPorts * sizeof(*(saveState)));
					if (saveState == NULL) {
						return; // break completely
					}
					for (int i = 0; i < pairMap[currNode->nPairId].numPorts; i++) {
						saveState[i] = motorGet(pairMap[currNode->nPairId].motorPorts[i]);
						motorStop(pairMap[currNode->nPairId].motorPorts[i]);
					}
					for (int i = 0; i < pairMap[currNode->nPairId].numSensors; i++) {
						if (pairMap[currNode->nPairId].sensors[i].type == TIME) {
							pauseTimer(pairMap[currNode->nPairId].sensors[i].port, true);
						}
					}
					printDebug("Paused!");
				}

				if (joystickGetDigital(1, 8, JOY_DOWN)) { // stop it entirely
					printDebug("Stopping!");
					for (int i = 0; i < pairMap[currNode->nPairId].numSensors; i++) {
						if (pairMap[currNode->nPairId].sensors[i].type == TIME) {
							resumeTimer(pairMap[currNode->nPairId].sensors[i].port, true);
						}
					}
					free(saveState);
					saveState = NULL;
					return;
				}
				delay(20);
			}

			if (outOfMemory) {
				return;
			}

			if (saveState != NULL) {
				for (int i = 0; i < pairMap[currNode->nPairId].numPorts; i++) {
					motorSet(pairMap[currNode->nPairId].motorPorts[i], saveState[i]);
				}

				for (int i = 0; i < pairMap[currNode->nPairId].numSensors; i++) {
					if (pairMap[currNode->nPairId].sensors[i].type == TIME) {
						resumeTimer(pairMap[currNode->nPairId].sensors[i].port, true);
					}
				}
				free(saveState);
				saveState = NULL;
			}

			if (reachedPoint(currNode, currNode->points[nextPoint].endSensorVal, currNode->points[nextPoint - 1].endSensorVal)) {
				setMotorSpeeds(currNode, nextPoint);
				nextPoint++;
			}

			if (currChild != NULL) {
				// printf("DEBUG: %d %d %d\n\r", currChild->nodeId, nextPoint, currChild->startPoint);
				if (nextPoint + 1 >= currChild->startPoint && needToStart(currNode, currChild)) {
					void *param = (void *)currChild;
					taskCreate(runNode, TASK_DEFAULT_STACK_SIZE / 2, param, TASK_PRIORITY_DEFAULT);
					currChild = currChild->sibling;
				}
			}
			delay(5);
		}

		printDebug("Finished node.");
		// printf("Finished node %d.", currNode->nodeId);
		if (findParent(currNode)->nodeId == rootNode->nodeId) {
			while (inMotion()) {
				delay(20);
			}
			if (currNode->sibling != NULL) {
				delay(currNode->sibling->startVal[0]);
				runNode(currNode->sibling);
			} else {
				printDebug("Done.");
				delay(500);
			}
		}
	}
Ejemplo n.º 5
0
int uthread_terminate(int tid)
{
	blockTimer();
	if(tid == 0)//if true: exits program
	{
//		terminate all threads:
		std::map<int, Thread*>::iterator threadIt;
		for (threadIt = gThreads.begin(); threadIt != gThreads.end(); ++threadIt)
		{
			Thread* tmp;
			switch(threadIt->second->getState() )
			{
			case(READY) :
					gReady.remove(threadIt->second->getID() );
					tmp = gThreads[threadIt->second->getID() ];
					gThreads.erase(threadIt);
					delete tmp;
					break;
			case(RUNNING) :
					gThreads.erase(threadIt);
//					gRunning = NULL;
					break;
			case(BLOCKED) :
					gBlocked.erase(threadIt->second->getID() );
					tmp = gThreads[threadIt->second->getID() ];
					gThreads.erase(threadIt);
					delete tmp;
					break;
			default :
				break;
			}

		}
		delete gRunning;
		gRunning = NULL;
		resumeTimer();
		exit(0);
	}
	if(gThreads.count(tid) == 0) //if true: thread doesn't exist
	{
		std::cerr<< TERMINATE_ERR << std::endl;
		resumeTimer();
		return FAILURE;
	}
	if(gThreads[tid]->getState() == RUNNING)//if true: deletes thread +  jumps to next thread
	{
		switchThreads(TERMINATED);
	}
//	if in ready or blocked: remove from lists (gReady/gBlocked + gThreads), and delete thread
	Thread* tmp = gThreads[tid];
	if (tmp->getState() == READY )
	{
		gReady.remove(tid);
	}
	if (tmp->getState() == BLOCKED)
	{
		gBlocked.erase(tid);
	}
	gThreads.erase(tid);
	gAvailableID.push(tid);
	delete tmp;
	resumeTimer();
	return SUCCESS;
}