/*! \brief main
 */
int main(void)
{
	//! temporary duty value
	uint8_t duty;
	//! temporary time counter
	uint32_t time_counter;
	
	init();
	startFan(potzRead());
	
    while (1)
    {
        duty = potzRead();
		if (duty < MIN_PWM_DUTY)
		{
			duty = MIN_PWM_DUTY;
		}
		
		// do not update power when starting
		if (g_fan.starting == FALSE)
		{
			setPower(duty);
		}
		
		// stalled rotor : power off, wait and restart
		if (g_fan.stall == TRUE)
		{
			// power off
			setPower(0);
			
			// reset time counter
			ATOMIC_BLOCK(ATOMIC_FORCEON)
			{
				g_time_counter = 0;
			}
			
			// wait until delay finished
			do
			{
				ATOMIC_BLOCK(ATOMIC_FORCEON)
				{
					time_counter = g_time_counter;
				}
			}
			while (time_counter <= STALL_RETRY_TIME);
	
			// start up the fan again
			startFan(duty);
		}
    }
Exemple #2
0
void onKeyPress(unsigned char key, int x, int y){
	switch (key){

	case 27:
		exit(0);
		break;
	case 'u':
		speedFanUp();
		break;
	case 'd':
		speedFanDown();
		break;
	case 's':
		if(!isOn){
			startFan();
		}else{
			stopFan();
		}
		break;
	}
}