示例#1
0
bool Tasks::resolveTasks(Clock *clk, StepperMotor stepper) {
	if (this->list[0].time == clk->getTime()) {
		// already done once ? don't do it
		if (this->list[0].done)
			return (false);

		stepper.step(683);

		// decrease the food
		decreaseFoodLevel(0);

		// already done once, remember it
		this->list[0].done = true;
		return (true);

	} else if (this->list[1].time == clk->getTime()) {
		// already done once ? don't do it
		if (this->list[1].done)
			return (false);

		stepper.step(682);

		// decrease the food
		decreaseFoodLevel(1);

		// already done once, remember it
		this->list[1].done = true;
		return (true);

	} else if (this->list[2].time == clk->getTime()) {
		// already done once ? don't do it
		if (this->list[2].done)
			return (false);

		stepper.step(683);

		delay(10000);
		stepper.step(2048);

		// decrease the food
		decreaseFoodLevel(2);

		// already done once, remember it
		this->list[2].done = true;
		return (true);

	// no task to run ? reset the tokens
	} else {
		this->list[0].done = false;
		this->list[1].done = false;
		this->list[2].done = false;
	}

	// we didn't find a task to launch
	return (false);
}
// This thread function is a friend function of the class
void* threadedStep(void *value){
	StepperMotor *stepper = static_cast<StepperMotor*>(value);
	while(stepper->threadRunning){
		stepper->step();
		usleep(stepper->threadedStepPeriod * 1000);  // convert from ms to us
		if(stepper->threadedStepNumber>0) stepper->threadedStepNumber--;
		if(stepper->threadedStepNumber==0) stepper->threadRunning = false;
	}
	return 0;
}
示例#3
0
// This thread function is a friend function of the class
void* threadedStep(void *value){
	StepperMotor *stepper = static_cast<StepperMotor*>(value);
	while(stepper->threadRunning){
		if(stepper->gpio_LSW->getValue() == GPIO::LOW){
			//switch is tripped...should go right...
			stepper->setDirection(StepperMotor::DIRECTION::CLOCKWISE);
		}
		if(stepper->gpio_RSW->getValue() == GPIO::LOW){
			stepper->setDirection(StepperMotor::DIRECTION::ANTICLOCKWISE);
		}
		stepper->step();
		usleep(stepper->threadedStepPeriod * 1000);  // convert from ms to us
		if(stepper->threadedStepNumber>0) stepper->threadedStepNumber--;
		if(stepper->threadedStepNumber==0) stepper->threadRunning = false;
	}
	return 0;
}