void GraphicsKeyboard(BYTE key, int x, int y)
{
	// Process keyboard input.
	if (key == ESC)
	{
		ProgramExit();
	}
}
示例#2
0
void NestedCommandLineApp::doRun(const std::vector<std::string>& args) {
  if (programName_.empty()) {
    programName_ = guessProgramName();
  }
  auto parsed = parseNestedCommandLine(args, globalOptions_);
  po::variables_map vm;
  po::store(parsed.options, vm);
  if (vm.count("help")) {
    std::vector<std::string> helpArgs;
    if (parsed.command) {
      helpArgs.push_back(*parsed.command);
    }
    displayHelp(vm, helpArgs);
    return;
  }

  if (vm.count("version")) {
    printf("%s %s\n", programName_.c_str(), version_.c_str());
    return;
  }

  if (!parsed.command) {
    throw ProgramExit(
        1,
        folly::sformat("Command not specified. Run `{} help' for help.",
                       programName_));
  }

  auto& p = findCommand(*parsed.command);
  auto& cmd = p.first;
  auto& info = p.second;

  auto cmdOptions =
    po::command_line_parser(parsed.rest).options(info.options).run();
  po::store(cmdOptions, vm);
  po::notify(vm);

  auto cmdArgs = po::collect_unrecognized(cmdOptions.options,
                                          po::include_positional);

  if (initFunction_) {
    initFunction_(cmd, vm, cmdArgs);
  }

  info.command(vm, cmdArgs);
}
示例#3
0
void NestedCommandLineApp::doRun(const std::vector<std::string>& args) {
  if (programName_.empty()) {
    programName_ = guessProgramName();
  }

  bool not_clean = false;
  std::vector<std::string> cleanArgs;
  std::vector<std::string> endArgs;

  for (auto& na : args) {
    if (na == "--") {
      not_clean = true;
    } else if (not_clean) {
      endArgs.push_back(na);
    } else {
      cleanArgs.push_back(na);
    }
  }

  auto parsed = parseNestedCommandLine(cleanArgs, globalOptions_);
  po::variables_map vm;
  po::store(parsed.options, vm);
  if (vm.count(kHelpCommand.str())) {
    std::vector<std::string> helpArgs;
    if (parsed.command) {
      helpArgs.push_back(*parsed.command);
    }
    displayHelp(vm, helpArgs);
    return;
  }

  if (vm.count(kVersionCommand.str())) {
    displayVersion();
    return;
  }

  if (!parsed.command) {
    throw ProgramExit(
        1,
        folly::sformat(
            "Command not specified. Run '{} {}' for help.",
            programName_,
            kHelpCommand));
  }

  auto& p = findCommand(*parsed.command);
  auto& cmd = p.first;
  auto& info = p.second;

  auto cmdOptions =
      po::command_line_parser(parsed.rest).options(info.options).run();

  po::store(cmdOptions, vm);
  po::notify(vm);

  auto cmdArgs =
      po::collect_unrecognized(cmdOptions.options, po::include_positional);

  cmdArgs.insert(cmdArgs.end(), endArgs.begin(), endArgs.end());

  if (initFunction_) {
    initFunction_(cmd, vm, cmdArgs);
  }

  info.command(vm, cmdArgs);
}
void StateProcess(void)
{
	double d;

	// Check that robot is in a safe state.
	if (!ROBOT_Safe(ROBOT_ID))
	{
		printf("Robot not safe.\n");
		ProgramExit();
	}

	// Special processing while a trial is running.
	if (TrialRunning)
	{
		if (!RobotActive())
		{
			// If robot is not active, abort current trial.
			ErrorRobotInactive();
			TrialAbort();
			MissTrial();
		}
		else
			if (FrameData.Full())
			{
				// Abort current trail if frame data is full.
				ErrorFrameDataFull();
				TrialAbort();
				MissTrial();
			}
	}

	// Some states are processing in the LoopTask.
	if (StateLoopTask[State])
	{
		return;
	}

	// State processing.
	switch (State)
	{
	case STATE_INITIALIZE:
		// Initialization state.
		if (TargetTestFlag)
		{
			break;
		}

		ExperimentTimer.Reset();
		StateNext(STATE_SETUP);
		break;

	case STATE_SETUP:


		// Setup details of next trial, but only when robot stationary and active.


		if (RobotNotMoving() && RobotActive())
		{
			printf("Dynamic learning: before Trialsetup i am here=====!!!!\n");
			TrialSetup();
			StateNext(STATE_HOME);
		}
		break;

	case STATE_HOME:
		// Start trial when robot in home position (and stationary and active).
		if (RobotNotMoving() && RobotHome() && RobotActive())
		{
			StateNext(STATE_START);
			break;
		}
		break;

	case STATE_START:
		// Start trial.
		TrialStart();
		StateNext(STATE_DELAY);
		break;

	case STATE_DELAY:
		// Delay period before go signal.
		if (StateTimer.ExpiredSeconds(TrialDelay))
		{
			StateNext(STATE_GO);
			break;
		}

		if (MovementStarted())
		{
			ErrorMoveTooSoon();
			TrialAbort();
			MissTrial();
		}
		break;

	case STATE_GO:
		// Wait until graphics state matches.
		if (State != StateGraphics)
		{
			break;
		}

		StateNext(STATE_TARGETWAIT);
		break;

	case STATE_TARGETWAIT:
		// Wait for estimated target display delay.
		if (GraphicsTargetTimer.ExpiredSeconds(GRAPHICS_DisplayDelayTarget(TargetPosition)))
		{
			// Target should be displayed now (within a few milliseconds).
			TriggerOn();
			MovementReactionTimer.Reset();
			BeepGo();
			StateNext(STATE_MOVEWAIT);
		}
		break;

	case STATE_MOVEWAIT:
		// Process in the robot forces function (LoopTask)
		break;

	case STATE_MOVING:
		// Process in the robot forces function (LoopTask)
		break;

	case STATE_FINISH:
		// Trial has finished so stop trial.
		TrialStop();

		// Save the data for this trial.
		if (!TrialSave())
		{
			printf("Cannot save Trial %d.\n", Trial);
			StateNext(STATE_EXIT);
			break;
		}

		// Catch too-slow trials.
		if (MovementDurationTime >= MovementDurationTimeOut)
		{
			ErrorMoveTimeOut();
			BeepError();
			InterTrialDelayTimer.Reset();
		}

		// Go to next trial, if there is one.
		if (TrialNext())
		{
			StateNext(STATE_INTERTRIAL);
		}
		else
		{
			StateNext(STATE_EXIT);
		}
		break;

	case STATE_INTERTRIAL:
		// Wait for the intertrial delay to expire.
		if (!InterTrialDelayTimer.ExpiredSeconds(InterTrialDelay))
		{
			break;
		}

		MessageClear();

		// Optional rest between blocks of trials.
		if (RestTrials != 0)
		{
			// Rest every X number of trials.
			if ((Trial % RestTrials) == 0)
			{
				StateNext(STATE_REST);
				break;
			}
		}

		StateNext(STATE_SETUP);
		break;

	case STATE_EXIT:
		ProgramExit();
		break;

	case STATE_TIMEOUT:
		switch (StateLast) // Which state had the timeout?
		{
		case STATE_MOVEWAIT:
			ErrorMoveWaitTimeOut();
			break;

		case STATE_MOVING:
			ErrorMoveTimeOut();
			break;

		default:
			ErrorMessage(STR_stringf("%s TimeOut", StateText[StateLast]));
			break;
		}

		TrialAbort(); // Abort the current trial.
		MissTrial();  // Generate miss trial.
		break;

	case STATE_ERROR:
		if (StateTimer.ExpiredSeconds(ErrorWait))
		{
			ErrorResume();
		}
		break;

	case STATE_REST:
		if (StateTimer.ExpiredSeconds(RestWait))
		{
			StateNext(STATE_SETUP);
		}
		break;
	}
}