예제 #1
0
// Update
void key_manager::update(){
  // Pressing them keys
  // You haven't won
  if(!switch_flicked){
    // Got a correct letter
    if((key_queue.size() > 0) && (!joystick_enabled && key[key_queue.at(0).getValue()] && keyIsPressed == false) || (joystick_enabled && joy[0].button[key_queue.at(0).getValue()].b && buttonIsPressed == false)){
      // Nice sound
      play_sample( sounds[1],255,125,1000,0);
      key_queue.erase( key_queue.begin());

      // Add key to queue
      if( joystick_enabled){
        key_data newKey(random(0,3));
        key_queue.push_back(newKey);
      }
      else{
        key_data newKey(random(KEY_LEFT, KEY_DOWN));
        key_queue.push_back(newKey);
      }

      // Increase speed
      if( stair::scrollSpeed < stair::maxScrollSpeed)
        stair::scrollSpeed += 0.8;
    }
    else if( (keyDown() && keyIsPressed == false) || (buttonDown() && buttonIsPressed == false)){
      if(stair::scrollSpeed > 0)
        stair::scrollSpeed /= 4;
      play_sample(sounds[0],255,125,1000,0);
    }
  }
  // Stop
  else{
    stair::scrollSpeed = 0;
  }

  // Prevents held keys
  if(!joystick_enabled){
    keyIsPressed = keyDown();
  }
  if(joystick_enabled){
    buttonIsPressed = buttonDown();
  }

  // Slow stairs down
  if( stair::scrollSpeed > 0.01)
    stair::scrollSpeed -= 0.02;
  else{
    stair::scrollSpeed = 0;
  }
}
예제 #2
0
void Region::cursorDown(Cursor* c) {
	if ( isButton() ) {
		NosuchDebug(1,"Region cursorDown depth=%f",c->curr_depth);
		if ( buttonTooDeep(c) ) {
			NosuchDebug("Ignoring cursor_down for button, too deep! (%.4f)",c->curr_depth);
		} else {
			NosuchDebug("REGION::BUTTONDOWN %s now=%.3f sid=%d/%s area=%.4f",
				name.c_str(),Palette::now/1000.0f,c->sidnum(),c->sidsource().c_str(),c->area());
			if ( c->area() < 0.0 ) {
				NosuchDebug("HEY!!!! area is negative!???");
			}
			buttonDown(name);
		}
	} else if ( Palette::selector_check && _graphicBehaviour->isSelectorDown() ) {
		NosuchDebug(1,"REGION::CURSORDOWN WITH GRAPHIC SELECTOR %s",c->DebugBrief().c_str());
		_graphicBehaviour->cursorDownWithSelector(c);
	} else if ( Palette::selector_check && _musicBehaviour->isSelectorDown() ) {
		NosuchDebug(1,"REGION::CURSORDOWN WITH MUSIC SELECTOR %s",c->DebugBrief().c_str());
		_musicBehaviour->cursorDownWithSelector(c);
	} else {
		NosuchDebug(2,"REGION::CURSORDOWN %s",c->DebugBrief().c_str());
		NosuchVector pos = c->curr_pos;
		palette->cursorDown(c);
		// NosuchDebug("cursorDown checking isSelectorDown() = %d",_graphicBehaviour->isSelectorDown());
		_graphicBehaviour->cursorDown(c);
		_musicBehaviour->cursorDown(c);
		palette->SetMostRecentCursorDown(c);
	}
}
예제 #3
0
	void GameInput::zoomOutView(int key, bool isdown)
	{
		if (isdown) {
			buttonDown(TriggerStart + UserInput::Trigger_ZoomOut, key, 0);
		} else {
			buttonUp(TriggerStart + UserInput::Trigger_ZoomOut, key, 0);
		}
	}
예제 #4
0
	void GameInput::toggleView(int key, bool isdown)
	{
		if (isdown) {
			buttonDown(TriggerStart + UserInput::Trigger_ToggleView, key, 0);
		} else {
			buttonUp(TriggerStart + UserInput::Trigger_ToggleView, key, 0);
		}
	}
예제 #5
0
	void GameInput::moveRush(int key, bool isdown)
	{
		if (isdown) {
			buttonDown(Rush, key, 0);
		} else {
			buttonUp(Rush, key, 0);
		}
	}
예제 #6
0
	void GameInput::moveRight(int key, bool isdown)
	{
		if (isdown) {
			buttonDown(MoveRight, key, 0);
		} else {
			buttonUp(MoveRight, key, 0);
		}
	}
예제 #7
0
	void GameInput::moveBackward(int key, bool isdown)
	{
		if (isdown) {
			buttonDown(MoveBackward, key, 0);
		} else {
			buttonUp(MoveBackward, key, 0);
		}
	}
예제 #8
0
파일: suffrage.cpp 프로젝트: seato/suffrage
/*
 * Summary:     Puts IXM in a "listening state".
 * Parameters:  None.
 * Return:      None.
 */
void
loop()
{
  for (u32 i = 0; i < 10; ++i)
    { // Button press debouncer for toggling the FAULTY flag
      delay(1);
      if (!buttonDown())
        i = 0;
    }

  faultToggle(); // Toggle the FAULTY flag!

  for (u32 i = 0; i < 10; ++i)
    {
      delay(1); // Button depress debouncer for toggling the FAULTY flag
      if (buttonDown())
        i = 0;
    }

  return;
}
예제 #9
0
void Region::processCursor(SpaceCursor* c, int downdragup) {
	if ( isButton() ) {
		DEBUGPRINT(("Region::processCursor BUTTON!"));
		switch ( downdragup ) {
		case CURSOR_DOWN: buttonDown(); break;
		case CURSOR_UP: buttonUp(); break;
		}
	} else {
		DEBUGPRINT(("Region::processCursor SURFACE!"));
		switch ( downdragup ) {
		case CURSOR_DOWN: cursorDown(c); break;
		case CURSOR_DRAG: cursorDrag(c); break;
		case CURSOR_UP: cursorUp(c); break;
		}
	}
}
예제 #10
0
void Region::cursorDown(SpaceCursor* c) {
	if ( isButton() ) {
		NosuchDebug(1,"Region cursorDown depth=%f",c->depth());
		if ( buttonTooDeep(c) ) {
			NosuchDebug("Ignoring cursor_down for button, too deep! (%.4f)",c->depth());
		} else {
			NosuchDebug("REGION::BUTTONDOWN %s now=%.3f sid=%d/%s area=%.4f",
				name.c_str(),Palette::now/1000.0f,c->sid,c->source.c_str(),c->area);
			if ( c->area < 0.0 ) {
				NosuchDebug("HEY!!!! area is negative!???");
			}
			buttonDown();
		}
	} else {
		_graphicBehaviour->cursorDown(c);
		_musicBehaviour->cursorDown(c);
		palette()->SetMostRecentSpaceCursorDown(c);
	}
}
UtlBoolean TaoPhoneComponentAdaptor::handleMessage(OsMsg& rMsg)
{
        UtlBoolean handled = FALSE;
        int msgType = ((TaoMessage&)rMsg).getMsgSubType();

        if( TaoMessage::REQUEST_PHONECOMPONENT == msgType)
        {
                switch (((TaoMessage&)rMsg).getCmd())
                {
                case TaoMessage::BUTTON_PRESS:
                        if (TAO_SUCCESS == buttonPress((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_UP:
                        if (TAO_SUCCESS == buttonUp((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_DOWN:
                        if (TAO_SUCCESS == buttonDown((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_GET_INFO:
                        if (TAO_SUCCESS == getButtonInfo((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_SET_INFO:
                        if (TAO_SUCCESS == setButtonInfo((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::BUTTON_GET_PHONELAMP:
                        if (TAO_SUCCESS == getAssociatedPhoneLamp((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::HOOKSWITCH_GET_STATE:
                        if (TAO_SUCCESS == getHookswState((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::HOOKSWITCH_SET_STATE:
                        if (TAO_SUCCESS == setHookswState((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::HOOKSWITCH_GET_CALL:
                        if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::LAMP_GET_MODE:
                        if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::LAMP_GET_SUPPORTED_MODES:
                        if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::LAMP_GET_BUTTON:
                        if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::LAMP_SET_MODE:
                        if (TAO_SUCCESS == setLampMode((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONEDISPALY --------------------------------- */
                case TaoMessage::DISPLAY_GET_DISPLAY:
                        if (TAO_SUCCESS == getDisplay((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_GET_ROWS:
                        if (TAO_SUCCESS == getDisplayRows((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_GET_COLS:
                        if (TAO_SUCCESS == getDisplayColumns((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_SET_DISPLAY:
                        if (TAO_SUCCESS == setDisplay((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_GET_CONTRAST:
                        if (TAO_SUCCESS == getDisplayContrast((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::DISPLAY_SET_CONTRAST:
                        if (TAO_SUCCESS == setDisplayContrast((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONEMIC --------------------------------- */
                case TaoMessage::MIC_GET_GAIN:
                        if (TAO_SUCCESS == getMicGain((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::MIC_SET_GAIN:
                        if (TAO_SUCCESS == setMicGain((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONERINGER --------------------------------- */
                case TaoMessage::RINGER_SET_INFO:
                        if (TAO_SUCCESS == setRingerInfo((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_SET_PATTERN:
                        if (TAO_SUCCESS == setRingerPattern((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_SET_VOLUME:
                        if (TAO_SUCCESS == setRingerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_INFO:
                        if (TAO_SUCCESS == getRingerInfo((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_PATTERN:
                        if (TAO_SUCCESS == getRingerPattern((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_VOLUME:
                        if (TAO_SUCCESS == getRingerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_MAX_PATTERN_INDEX:
                        if (TAO_SUCCESS == getMaxRingPatternIndex((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_GET_NUMBER_OF_RINGS:
                        if (TAO_SUCCESS == getNumberOfRings((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::RINGER_IS_ON:
                        if (TAO_SUCCESS == isRingerOn((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONESPEAKER --------------------------------- */
                case TaoMessage::SPEAKER_SET_VOLUME:
                        if (TAO_SUCCESS == setSpeakerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::SPEAKER_GET_VOLUME:
                        if (TAO_SUCCESS == getSpeakerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::SPEAKER_GET_NOMINAL_VOLUME:
                        if (TAO_SUCCESS == getSpeakerNominalVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONEEXTSPEAKER --------------------------------- */
                case TaoMessage::EXTSPEAKER_SET_VOLUME:
                        if (TAO_SUCCESS == setExtSpeakerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::EXTSPEAKER_GET_VOLUME:
                        if (TAO_SUCCESS == getExtSpeakerVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::EXTSPEAKER_GET_NOMINAL_VOLUME:
                        if (TAO_SUCCESS == getExtSpeakerNominalVolume((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
        /* ----------------------------- PHONEGROUP --------------------------------- */
                case TaoMessage::PHONEGROUP_ACTIVATE:
                        if (TAO_SUCCESS == activateGroup((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_DEACTIVATE:
                        if (TAO_SUCCESS == deactivateGroup((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_GET_COMPONENTS:
                        if (TAO_SUCCESS == getGroupComponents((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_GET_DESCRIPTION:
                        if (TAO_SUCCESS == getGroupDescription((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_GET_TYPE:
                        if (TAO_SUCCESS == getGroupType((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::PHONEGROUP_IS_ACTIVATED:
                        if (TAO_SUCCESS == isGroupActivated((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;
                case TaoMessage::COMPONENT_RESULT:
                        if (TAO_SUCCESS == returnResult((TaoMessage&)rMsg))
                        {
                                handled = TRUE;
                        }
                        break;

                default:
                  break;
                }
        }
        else if (TaoMessage::RESPONSE_PHONECOMPONENT == msgType)
        {
                if (TAO_SUCCESS == returnResult((TaoMessage&)rMsg))
                        handled = TRUE;
        }

        if (!handled)
        {
                TaoMessage*     pMsg = (TaoMessage*) &rMsg;

                pMsg->setArgCnt(1);
                pMsg->setArgList("-1");

                if (mpSvrTransport->postMessage(*pMsg))
                        handled = TRUE;
        }

        return handled;
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
	if ( ((char) key) == 'b') {
		buttonDown();
	}
}
//--------------------------------------------------------------
void testApp::draw(){
#ifdef DEBUG_PRINT 
	printf("draw()\n");
#endif
	/*
	if (logData) {
	freqOutThread.lock();
	bool outOn = freqOutThread.getCurrentOutState();
	float freq = freqOutThread.getCurrentFreq();
	freqOutThread.unlock();

	logger.lock();
	logger.push_back(myGetElapsedTimeMillis(), LoggerData::IS_ENTRAINMENT_ON, outOn);
	logger.push_back(myGetElapsedTimeMillis(), LoggerData::ENTRAINMENT_FREQ, freq);
	logger.unlock();
	}
	*/
	if (checkButtonPresses) {
		inputArduino.update();
		int input = inputArduino.getAnalog(0);
		if (input > 512) {
			buttonDown();
		} else {
			buttonUp();
		}
	}



	// Draw oscilloscope data
	if (showOscilloscope) {
		//if (++eegPlotCounter == rawTimeWindow) {
			scopeWin.plot();
		//	eegPlotCounter = 0;
		//}
	}


	experimentGovernor.update();

	//if (showInstructions) {
	//	instructionsPlayer.update();
	//}
	//if (showStimuli) {
	//	if (stimulusPlayer.update() <= 0) {
	//		//cout << "stimulus list complete \n";
	//	}
	//}


	if (showScreenEntrainment) {
		//freqOutThread.lock(); 
		freqOutThread.update();
		//freqOutThread.unlock();
	} else {
		ofSleepMillis(1);
		//sleep(1);
	}

	//cout << "time=" << myGetElapsedTimeMillis() << ", diff=" << myGetElapsedTimeMillis() - drawTime << "\n";
	drawTime = myGetElapsedTimeMillis();
}
예제 #14
0
int main() {
	initialize();
	UBRR0H = UBRRH_VALUE;
	UBRR0L = UBRRL_VALUE;

	UCSR0B = (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0);

	UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);


	// enable interrupts for the timer
	sei();

	/* Timer aufsetzen: nach 1 ms soll der Interrupt ausgelöst werden. */
	/* 8 bit counter (TIMER0) */
	/* normal mode */
	TCCR0A = 0;
	/* CLK/64 */
	TCCR0B = (1 << CS01) | (1 << CS00);
	/* timer ticks: 250 */
	TCNT0 = 5;
	TIMSK0 = (1 << TOIE0);
	TIFR0 = (1 << TOV0);

	adcInit();

	int16_t ii = 0;
	int16_t jj = 0;

	wdt_enable(WDTO_2S);

/*
	for(;;i++) {
		uart_bin(PINB);
		uart_puts(" ");
		uart_bin(PIND);
		uart_puts(" ");
		uart_hex16(i);
		uart_puts("\r\n");
		_delay_ms(1000);
		wdt_reset();
	}
*/

	uart_puts("Starting up\r\n"); 
	
	for (ii = 0; ii < 4; ii++) {
		positions[ii] = 0;
	}

	// Count the number of cycles the autofocus is stuck in mid-state
	uint8_t mid_state_counter = 0;

	// Count the number of successive movements in the same direction before increasing speed
	uint16_t movement_counter = 0;

	uint16_t current_delay = INITIAL_DELAY;

	enum movement{NONE, UP, DOWN, TILT_DOWN, TILT_UP, LEVEL, EMERGENCY} last_movement, movement;
	last_movement = NONE;
	movement = NONE;

	// Reset autofocus position

	/*
	   while(1) {  
	   adc_start_conversion(7);
	   const uint16_t autofocus_result = adc_wait();
	   uart_hex16(autofocus_result);
	   wdt_reset();
	   uart_puts("\r\n");
	   }
	// */

	uint8_t autofocus_hit_counter = 0;

	movement_counter = 0;
	current_delay = INITIAL_DELAY;
	
	initialize();
	adcInit();
	
	adc_start_conversion();
	uint16_t autofocus_result = adc_wait();

	uint16_t no_movement_counter = 0;
	
	autofocusPosition = 2*HEIGHT_LIMIT;

	for(ii = 0; ; ii++){
		wdt_reset();
		//*
		if (current_delay > 1) {
			for (jj = 0; jj < current_delay; jj++) {
				_delay_us(1);
			}
		}
		// */
		#ifdef DEBUG
		uart_hex16(current_delay);
		uart_puts("\r\n");
		#endif
		// True if autofocus endstop not yet hit.
		const bool autofocus_switch_clear = (autofocus_result <= OPEN_VALUE + INTERVAL_SIZE && autofocus_result >= OPEN_VALUE - INTERVAL_SIZE);
		bool autofocus_clear = true;

		if (!autofocus_switch_clear) {
			if (autofocus_hit_counter > 10) {
				autofocus_clear = false;
				if ((ii % 1024) == 0) {
					uart_puts("Autofocus hit at: ");
					printPositions();
					autofocusPosition = positions[0];
					uart_puts("\r\n");
				}
				if (autofocus_result < SHORT_CIRCUIT_VALUE) {
					uart_puts("Autofocus has short circuit, value is: ");
					uart_hex16(autofocus_result);
					uart_puts("\r\n");
				}
				else if (autofocus_result > CABLE_BROKEN_VALUE) {
					uart_puts("Autofocus cable is broken, value is: ");
					uart_hex16(autofocus_result);
					uart_puts("\r\n");
				}
				else if(autofocus_result > OPEN_VALUE + INTERVAL_SIZE && autofocus_result < CLOSED_VALUE - INTERVAL_SIZE) {
					if (mid_state_counter > 10) {
						uart_puts("Autofocus stuck in mid-state, value is: 0x");
						uart_hex16(autofocus_result);
						uart_puts("\r\n");
					}
					else {
						mid_state_counter++;
					}
				}
			}
			// Increment autofocus_hit_counter in order to detect series of hit autofocus.
			if (autofocus_hit_counter < 20) {
				autofocus_hit_counter++;
			}
		}
		else {
			mid_state_counter = 0;
			autofocus_hit_counter = 0;
		}
		movement = NONE;
		if (!buttonEmergency()) {
			if (buttonDown()) {
				if (!anyStopReached()) {
					stepAllDown();
					movement = DOWN;
				}
				_delay_us(2.08);
			}
			else if (buttonUp()) {
				if (!anyHeightLimitReached() && autofocus_clear) {
					stepAllUp();
					movement = UP;
				}
			}
			else if (buttonTiltFrontUp()) {
				if (!anyStopReached() && !anyHeightLimitReached() && (positions[3]-positions[1] < TILT_LIMIT) && autofocus_clear) {
					stepUp3();
					stepDown1();
					movement = TILT_UP;
				}
				_delay_us(0.96);
			}
			else if (buttonTiltFrontDown()) {
				if (!anyStopReached() && !anyHeightLimitReached() && (positions[1]-positions[3] < TILT_LIMIT) && autofocus_clear) {
					stepDown3();
					stepUp1();
					movement = TILT_DOWN;
				}
				_delay_us(1.52);
			}
			else if (buttonLevel()) {
				if (!anyStopReached() && autofocus_clear) {
					if (positions[1] > positions[3]+1) {
						stepDown1();
						stepUp3();
						movement = LEVEL;
						_delay_us(0.72);
					}
					else if (positions[1]+1 < positions[3]) {
						stepDown3();
						stepUp1();
						movement = LEVEL;
					}
				}
				_delay_us(2.22);
			}
			else if (buttonFocus()) {
				if ((positions[0] > (autofocusPosition - FOCUS_DISTANCE)) && !anyStopReached()) {
					stepAllDown();
					movement = DOWN;
				}
				else if ((positions[0] < (int32_t)(autofocusPosition - FOCUS_DISTANCE)) && autofocus_clear) {
					stepAllUp();
					movement = UP;
				}
				// Needed to fulfill the 2us hold constraint of the step pin
			}
		}
		if (movement == last_movement && movement != NONE) {
			if (movement_counter > 500) {
				current_delay--;
				if (current_delay < MIN_DELAY) {
					current_delay = MIN_DELAY;
				}
				movement_counter = 0;
			}
			movement_counter += current_delay;
		}
		else {
			current_delay = INITIAL_DELAY;
			movement_counter = 0;
		}

		// Do all the emergency stuff
		if (buttonEmergency()) {
			_delay_us(17);
			movement = EMERGENCY;
			if (buttonEmergency() && buttonFocus()) {
				gotoEndstops();
			}
			if (buttonUp()) {
				if (buttonTiltFrontDown()) {
					stepUp1();
				}
				if (buttonLevel()) {
					stepUp2();
				}
				if (buttonTiltFrontUp()) {
					stepUp3();
				}
			}
			if (buttonDown()) {
				if (buttonTiltFrontDown()) {
					stepDown1();
				}
				if (buttonLevel()) {
					stepDown2();
				}
				if (buttonTiltFrontUp()) {
					stepDown3();
				}
				
			}
			if (buttonLevel()) {
				int32_t maxPosition = max(positions[1], max(positions[2], positions[3]));
				if (positions[1] < maxPosition) {
					stepUp1();
				}
				if (positions[2] < maxPosition) {
					stepUp2();
				}
				if (positions[3] < maxPosition) {
					stepUp3();
				}
			}
			// In case of emergency, introduce a safe delay for the step hold time
			_delay_us(2);
		}

		last_movement = movement;
		if (movement == NONE) {
			no_movement_counter++;
			if (no_movement_counter > 2e3) {
				sleep();
				no_movement_counter = 0;
				printPositions();
				uart_puts("\r\n");
			}
		}
		else {
			no_movement_counter = 0;
			if (sleeping) {
				wakeup();
				_delay_ms(100);
			}
		}
		if(!(ADCSRA & (1<<ADSC))) {   // auf Abschluss der Konvertierung warten
			autofocus_result = ADCW;
			adc_start_conversion();
		}
		_delay_us(1.08);
		unsetStep1;
		unsetStep2;
		unsetStep3;
	}

}
예제 #15
0
void FakeMouse::click(int button) 
{
   buttonDown(button);
   usleep(100000);
   buttonUp(button);
}