Beispiel #1
0
void Button::pointerMotion(Event& event)
	{
	/* Check if the new pointer position is still inside the button: */
	if(event.getTargetWidget()==this)
		{
		/* Arm the button: */
		setArmed(true);
		}
	else
		{
		/* Disarm the button: */
		setArmed(false);
		}
	}
RocketSystem::RocketSystem(
    Accelerometer& accel,
    optional<Accelerometer *> accelH,
    optional<Barometer *> bar,
    optional<Geiger *> ggr,
    optional<GPS *> gps,
    Gyroscope& gyr,
    optional<Magnetometer *> mag,
    WorldEstimator& estimator, InputSource& inputSource,
    MotorMapper& motorMapper, Communicator& communicator, Logger& logger,
    Platform& platform)
  : VehicleSystem(communicator), MessageListener(communicator),
    params(params),
    accel(accel), accelH(accelH), bar(bar), ggr(ggr), gps(gps), gyr(gyr), mag(mag),
    estimator(estimator), inputSource(inputSource),
    motorMapper(motorMapper), platform(platform),
    systemStream(communicator, 10),
    logger(logger),
    state(RocketState::DISARMED) {
  // Disarm by default. A set_arm_state_message_t message is required to enable
  // the control pipeline.
  setArmed(false);
  gyr.setAxisConfig(unit_config::GYR_AXES);
  accel.setAxisConfig(unit_config::ACC_AXES);
  (*accelH)->setAxisConfig(unit_config::ACCH_AXES);
  gyr.setOffsets(unit_config::GYR_OFFSETS);
  accel.setOffsets(unit_config::ACC_OFFSETS);
  (*accelH)->setOffsets(unit_config::ACCH_OFFSETS);
}
void Button::mousePressed(MouseEventDetails* const e)
{
    if(getEnabled())
    {
        if(e->getButton()==MouseEventDetails::BUTTON1){
            this->setActive(true);
            setArmed(true);

            if(getParentWindow() != NULL && getParentWindow()->getParentDrawingSurface()!=NULL&& getParentWindow()->getParentDrawingSurface()->getEventProducer() != NULL)
            {
                _ArmedMouseReleasedConnection.disconnect();
                _ArmedMouseReleasedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectMouseReleased(boost::bind(&Button::handleArmedMouseReleased, this, _1));

                if(getEnableActionOnMouseDownTime())
                {
                    produceMousePressedActionPerformed();
                    resetArmed();
                    _ArmedUpdateEventConnection.disconnect();
                    _ArmedUpdateEventConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectUpdate(boost::bind(&Button::handleArmedUpdate, this, _1));
                }
            }
        }
    }
    Component::mousePressed(e);
}
void OnsetMeterView::onButtonEvent(ofxDatGuiButtonEvent e) {
    MeterView::onButtonEvent(e);
    if (e.target->getLabel() == MTR_ARM){
        setArmed(e.enabled);
    } else if(e.target->getLabel() == MTR_RESET){
        onsets->reset();
    }
}
Beispiel #5
0
void Button::pointerButtonUp(Event& event)
	{
	/* Select if the event is for us: */
	if(event.getTargetWidget()==this)
		select();
	
	/* Disarm the button: */
	setArmed(false);
	}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CommandButton::cursorExited( void )
{
	// only clear ourselves if we have do not have a containing menu
	// only stay armed if we have a sub menu
	// the buttons only unarm themselves when another button is armed instead
	if ( !getParentMenu() || !GetSubMenu() )
	{
		setArmed( false );
	}
}
Beispiel #7
0
void DropdownButton::pointerButtonUp(Event& event)
	{
	/* "Repair" the incoming event: */
	event.overrideTargetWidget(foundChild);
	
	/* Disarm the armed child: */
	if(armedChild!=0)
		{
		armedChild->pointerButtonUp(event);
		armedChild=0;
		}
	
	setArmed(false);
	}
Beispiel #8
0
void DropdownButton::pointerButtonDown(Event& event)
	{
	/* "Repair" the incoming event: */
	event.overrideTargetWidget(foundChild);
	
	/* Arm the button: */
	setArmed(true);
	
	/* Find a potential event recipient in the popup: */
	if(popup->findRecipient(event))
		{
		armedChild=event.getTargetWidget();
		armedChild->pointerButtonDown(event);
		}
	else
		armedChild=0;
	}
void Button::mouseReleased(MouseEventDetails* const e)
{    
    if(getEnabled())
    {
        if(e->getButton() == MouseEventDetails::BUTTON1 && getArmed())
        {
            this->setActive(false);

            produceActionPerformed();
            setArmed(false);

            //Consume the event
            e->consume();
            return;
        }
    }
    Component::mouseReleased(e);
}
//-----------------------------------------------------------------------------
// Purpose: Highlights the current button, and all it's parent menus
//-----------------------------------------------------------------------------
void CommandButton::cursorEntered( void )
{
	// unarm all the other buttons in this menu
	CCommandMenu *containingMenu = getParentMenu();
	if ( containingMenu )
	{
		containingMenu->ClearButtonsOfArmedState();

		// make all our higher buttons armed
		CCommandMenu *pCParent = containingMenu->GetParentMenu();
		if ( pCParent )
		{
			CommandButton *pParentButton = pCParent->FindButtonWithSubmenu( containingMenu );

			pParentButton->cursorEntered();
		}
	}

	// arm ourselves
	setArmed( true );
}
Beispiel #11
0
void Button::handleArmedMouseReleased(MouseEventDetails* const e)
{
    if(e->getButton() == MouseEventDetails::BUTTON1)
    {
        _ArmedMouseReleasedConnection.disconnect();
        if(getEnableActionOnMouseDownTime())
        {
            _ArmedUpdateEventConnection.disconnect();
        }
        if(getParentWindow() &&
           getParentWindow()->getParentDrawingSurface())
        {
            Pnt2f MousePos = ViewportToDrawingSurface(e->getLocation(), getParentWindow()->getParentDrawingSurface(), e->getViewport());
            //If the Mouse is not within the button
            if(!isContained(MousePos))
            {
                setArmed(false);
            }
        }
    }
}
Beispiel #12
0
/****************************************************************************
 Function
    RunDisarmFSM

 Parameters
   ES_Event : the event to process

 Returns
   ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise

 Description
   The state machine for the overall disarming process - state machine for
	 keypad, etc. are elsewhere
 Notes

****************************************************************************/
ES_Event RunDisarmFSM( ES_Event ThisEvent )
{
  ES_Event ReturnEvent;
  ReturnEvent.EventType = ES_NO_EVENT; // assume no errors
	
	// initial state: all the LEDs are off.
	static char LEDs[8] = {OFF, OFF, OFF, OFF, OFF, OFF , OFF, OFF}; 
	static bool tower_rotate_direction = true;
	
  switch ( CurrentState )
  {
    case Armed :
			switch ( ThisEvent.EventType ) {
				case ES_INIT :
					// intializing timer to be at 2mS rate (for 60 second count down)
					ES_Timer_Init(ES_Timer_RATE_2mS);	
				
					printf("Arming...\r\n");
					// sets the armed line to +5V
					setArmed(); 
					printf(" Setting all tower LEDS off...\r\n");
					LEDShiftRegInit();
					// all LEDs are off when armed
					setLED (LEDs); 
				
					printf(" Generating random passwords...\r\n");
				  // generate random password for keyboard input
					randomizePasswords();
					printArmedMessage();
				
					printf(" Lowering flag...\r\n");
				  // lower the flag when armed
					lowerFlag();
					printf(" Locking the keys\r\n");
					// lock the key when armed
					lockKeys();
		
					printf(" Setting tower to 0...\r\n\r\n");
					// the tower doesn't lean when armed
					setTowerToZero();
					printf("STATE: Armed\r\n\r\n");
					
					rotateTowerLeft();
					ES_Timer_InitTimer(PANIC_TIMER, 350);
					// demonstrate panic and start timing
					ES_Timer_StartTimer(PANIC_TIMER);

					break;
        
				case THREE_HANDS_ON :
					
					printf("EVENT: Three hands detected.\r\n");
				
					printf(" Setting Tower Tier 1 LED on...\r\n");
					LEDs[Tier1] = ON;
					// light up the LED for bottom layer to show success in task 1
					setLED(LEDs);
				
					printf(" Begin printing LCD passcode...\r\n");
					resetLCDmessage();
					printLCDmessage();
					// sends out a message every 2 seconds (2mS timer rate)
					ES_Timer_InitTimer(MESSAGE_TIMER, 1000);
					ES_Timer_StartTimer(MESSAGE_TIMER);

					printf(" Starting 60s disarm timer...\r\n");
					//the timer can only go up to 32000
					ES_Timer_InitTimer(DISARM_TIMER, 30000);
					ES_Timer_StartTimer(DISARM_TIMER);
					//begins to run the timing motor
					unwindTimingMotor(); 
				
					// grabs current time to store for rewinding the timer motor
					startTime = ES_Timer_GetTime();

					ES_Event ThisEvent;
					ThisEvent.EventType = PLAY_TRACK;
					// play sound track 01
					ThisEvent.EventParam = 1; 					
					PostAdafruitAudioService(ThisEvent);
					
					printf(" Transitioning to Stage 1...\r\n\r\n");
					CurrentState = Stage1;
					printf("STATE: Stage1\r\n\r\n");
					break;
	
				case ES_TIMEOUT :
					// if panic timer expires
					if (ThisEvent.EventParam == PANIC_TIMER) {
						if (tower_rotate_direction) {
							tower_rotate_direction = false;
							rotateTowerRight();
						} else {
							tower_rotate_direction = true;
							rotateTowerLeft();
						}
						ES_Timer_InitTimer(PANIC_TIMER, 350);
						ES_Timer_StartTimer(PANIC_TIMER);
					}
					// if timing motor rewind timer expires
					if (ThisEvent.EventParam == REWIND_TIMER) {
						// stop timing motor when the ball reaches the top
						stopTimingMotor();
					}

				default:
					;
			}
		break;

    case Stage1 :
      switch ( ThisEvent.EventType )
      {
				case ES_TIMEOUT :
					if (ThisEvent.EventParam == DISARM_TIMER) {
						// if the disarm timer expires
						printf("EVENT: Time has run out!\r\n");
						printTimeUp();
						// gets the time when the game ended
						endTime = ES_Timer_GetTime(); 
						// calculate how much rewinding needs to be done
						ES_Timer_InitTimer(REWIND_TIMER, (endTime-startTime)/2);
						ES_Timer_StartTimer(REWIND_TIMER);
						// begins rewinding the clock motor
						rewindTimingMotor(); 
						
						ThisEvent.EventType = ES_INIT;
						PostDisarmFSM(ThisEvent);
						// go back to armed state
						CurrentState = Armed;
					}
					// if vibration timer expires
					if (ThisEvent.EventParam == VIBRATION_TIMER) {
						printf(" Turning off vibration pulse...\r\n\r\n");
						vibrationMotorOff();
					}
					// if message timer expires
					if (ThisEvent.EventParam == MESSAGE_TIMER) {
						printf("EVENT: Printing out the next message...\r\n");
						printLCDmessage();
						ES_Timer_InitTimer(MESSAGE_TIMER, 1000);
						ES_Timer_StartTimer(MESSAGE_TIMER);
					}
        break;
					
				// one or more hands have been released
				case THREE_HANDS_OFF :
					printf("EVENT: One or more hands have been released.\r\n");
					printf(" Clearing the LCD screen\r\n");
					printArmedMessage();
					printf(" Setting Tower Tier 1 LED off...\r\n");
					// task 1 is not completed 
					LEDs[Tier1] = OFF;
					// turn off the LED for bottom layer
				  setLED(LEDs);
				
					printf(" Transitioning to Stage1_Stagnated...\r\n\r\n");
					CurrentState = Stage1_Stagnated;
					printf("STATE: Stage1_Stagnated\r\n\r\n");
        break;
				
				// if the user entered the correct password
				case CORRECT_PASSWORD_ENTERED :
					printf("EVENT: The correct password has been entered.\r\n");
					printf(" Unlocking the keys\r\n");
					// unlock the key and move to task 3
					unlockKeys();
					printAuthorizedMessage();
				
					printf(" Setting Tower Tier 2 LED on...\r\n");
					LEDs[Tier2] = ON;
					// turn on LED on the second tier to show success
				  setLED(LEDs);
				
					printf(" Playing audio: Wahoo!...\r\n");
				  ES_Event ThisEvent;
					ThisEvent.EventType = PLAY_TRACK;
					// play sound track 01
					ThisEvent.EventParam = 1; 					
					PostAdafruitAudioService(ThisEvent);	
					printf(" Transitioning to Stage2...\r\n\r\n");
					// set the current state to state 2
					CurrentState = Stage2;
					printf("STATE: Stage2\r\n\r\n");
          break;
				
				// if the user entered incorrect password
				case INCORRECT_PASSWORD_ENTERED :
					printf("EVENT: The incorrect password has been entered.\r\n");
					printIncorrectMessage();
					ES_Timer_InitTimer(MESSAGE_TIMER, 1000);
					ES_Timer_StartTimer(MESSAGE_TIMER);
					printf(" Generating vibration pulse...\r\n");
          break;

        default :
            ; 
      }
      break;
		
		case Stage1_Stagnated :
      switch ( ThisEvent.EventType )
      {
        case ES_TIMEOUT :
					// if disarm timer expires
          if (ThisEvent.EventParam == DISARM_TIMER) {
						printf("EVENT: Time has run out!\r\n");
						printTimeUp();
						endTime = ES_Timer_GetTime();
						// calculate how much rewinding needs to be done
						ES_Timer_InitTimer(REWIND_TIMER, (endTime-startTime)/2);
						ES_Timer_StartTimer(REWIND_TIMER);
						// begins rewinding the timing motor
						rewindTimingMotor(); 
						
						ThisEvent.EventType = ES_INIT;
						PostDisarmFSM(ThisEvent);
						// go back to armed state
						CurrentState = Armed;
					}
          break;
				
				// if all three tape sensors are covered
				case THREE_HANDS_ON :
					printf("EVENT: Three hands detected.\r\n");
				
					printf(" Setting Tower Tier 1 LED on...\r\n");
					LEDs[Tier1] = ON;
					// light up the LED for bottom layer to show success in task 1
					setLED(LEDs);
				
					printf(" Begin printing LCD passcode...\r\n");
					resetLCDmessage();
					printLCDmessage();
					// print message from LCD
					ES_Timer_InitTimer(MESSAGE_TIMER, 1000);
					ES_Timer_StartTimer(MESSAGE_TIMER);
				
					// play feedback audio wahoo
					ES_Event ThisEvent;
					ThisEvent.EventType = PLAY_TRACK;
					// play sound track 01
					ThisEvent.EventParam = 1; 					
					PostAdafruitAudioService(ThisEvent);

					printf(" Transitioning to Stage1...\r\n\r\n");
					// set current stage to stage 1
					CurrentState = Stage1;
					printf("STATE: Stage1\r\n\r\n");
          break;

        default :
            ; 
      }
      break;
			
		case Stage2 :
      switch ( ThisEvent.EventType )
      {
        case ES_TIMEOUT :
					// if the disarm timer expires
          if (ThisEvent.EventParam == DISARM_TIMER) {
						printf("EVENT: Time has run out!\r\n");
						printTimeUp();
						// gets the time when the game ended
						endTime = ES_Timer_GetTime();
						// calculate how much rewinding needs to be done
						ES_Timer_InitTimer(REWIND_TIMER, (endTime-startTime)/2);
						ES_Timer_StartTimer(REWIND_TIMER);
						// begins rewinding the clock moto
						rewindTimingMotor(); r
						
						ThisEvent.EventType = ES_INIT;
						PostDisarmFSM(ThisEvent);
						CurrentState = Armed;
          }
					break;
					
				// if the key is inserted
				case KEY_INSERTED:
					printf("EVENT: Key has been inserted.\r\n");
				
					printf(" Setting Tower Tier 3 LED on...\r\n");
					LEDs[Tier3] = ON;
					// light up LED on tier 3 to show successful completion of task 3
					setLED(LEDs);
				
					printf(" Setting Dial LED on...\r\n");
					LEDs[pot] = ON;
					setLED(LEDs);
				
					printf(" Playing audio: Wahoo!...\r\n");
					ES_Event ThisEvent;
					ThisEvent.EventType = PLAY_TRACK;
					// play sound track 01
					ThisEvent.EventParam = 1; 					
					PostAdafruitAudioService(ThisEvent);
				
					printf("Initializing the pot value...\r\n");
					setPotZero();
					printf(" Transitioning to Stage3...\r\n\r\n");
					// set current state to state 3
					CurrentState = Stage3;
					printf("STATE: Stage3\r\n\r\n");
          break;

        default :
            ; 
      }
      break;			

		case Stage3 :
      switch ( ThisEvent.EventType )
      {
        case ES_TIMEOUT :
					// if the disarm timer expires
					if (ThisEvent.EventParam == DISARM_TIMER) {  
						printf("EVENT: Time has run out!\r\n");
						printTimeUp();
						endTime = ES_Timer_GetTime();
						// calculate how much rewinding needs to be done
						ES_Timer_InitTimer(REWIND_TIMER, (endTime-startTime)/2);
						ES_Timer_StartTimer(REWIND_TIMER);
						// begins rewinding the clock motor
						rewindTimingMotor(); 
						
						ThisEvent.EventType = ES_INIT;
						PostDisarmFSM(ThisEvent);
						// set current state to armed
						CurrentState = Armed;
					}
					if (ThisEvent.EventParam == FAST_LEDS) {  
						printf("EVENT: \r\n");
						ThisEvent.EventType = CORRECT_VALUE_DIALED;
						PostDisarmFSM(ThisEvent);
					}
          break;
				
				// if the pot is dialed to correct value 
				case CORRECT_VALUE_DIALED :
					printf("EVENT: The correct pot value has been dialed.\r\n");
					// Sets the armed line to 0V
					setUnarmed(); 
					printf(" Setting Tower Tier 4-6 LED on with delay...\r\n");
					
					ES_Timer_InitTimer(FAST_LEDS, 150);
					static int i = Tier4;
					if (i<=Tier6){
						printf("\n\r looping for LED i + %d\n\r", i);
						// turn on all the remaining LEDs one by one
						LEDs[i] = 0;
						setLED(LEDs);
						ES_Timer_StartTimer(FAST_LEDS);
						i++;
						break;
					}
					printf(" Raising the flag...\r\n");
					// raise flag to show hope and joy
					raiseFlag();
					printf(" Playing audio: victory song...\r\n");
					ES_Event ThisEvent;
					ThisEvent.EventType = PLAY_TRACK;
					// play sound track 03
					ThisEvent.EventParam = 3; 					
					PostAdafruitAudioService(ThisEvent);	
					printf(" Starting 30s post-disarm timer...\r\n");
					ES_Timer_InitTimer(POST_DISARM_TIMER, 30000);
					printf(" Raising ball and feather...\r\n");
					// stop falling ball
					stopTimingMotor();
					// get the time when the disarment ends and rearm DDM
					endTime = ES_Timer_GetTime();
					ES_Timer_InitTimer(REWIND_TIMER, (endTime-startTime)/2);
					ES_Timer_StartTimer(REWIND_TIMER);
					// begins rewinding the clock motor
					rewindTimingMotor(); 
					
					printf(" Transitioning to Stage4...\r\n\r\n");
					// set current stage to stage 4
					CurrentState = Stage4;
					printf("STATE: Stage4\r\n\r\n");
          break;

        default :
            ; 
      }
      break;	

		case Stage4 :
      switch ( ThisEvent.EventType )
      {
        case ES_TIMEOUT :
					// if timer expires after successful disarment
					if (ThisEvent.EventParam == POST_DISARM_TIMER) {
						printf("EVENT: Post-disarm timer expired.\r\n");
						ThisEvent.EventType = ES_INIT;
						PostDisarmFSM(ThisEvent);
						// set current state to armed
						CurrentState = Armed;
					}
					// if rewind timer expires
					if (ThisEvent.EventParam == REWIND_TIMER) {
						// stop timing motor rewinding
						stopTimingMotor();
					}
          break;

        default :
            ; 
      }
      break;	

    default :
      ;
  }
  return ReturnEvent;
}
Beispiel #13
0
void Button::pointerButtonDown(Event&)
	{
	/* Arm the button: */
	setArmed(true);
	}
void RocketSystem::on(const protocol::message::set_arm_state_message_t& m) {
  if (state == RocketState::DISARMED) {
    return;
  }
  setArmed(m.armed);
}