void MultiStateImageButton::OnActivate() { // only iterate through states once widget is selected. if (m_isSelected) StateNext(); else { m_isSelected = true; onSelect.emit(); } onClick.emit(this); }
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; } }
BOOL TrialList(void) { int item, i; BOOL ok = TRUE; TotalTrials = 0; // Single or multiple configuration file paradigm? if (ConfigFiles == 1) { TotalTrials = Trials; ConfigIndex = 0; } else { // Loop over configuration files, counting the number of trials. for (ok = TRUE, ConfigIndex = 1; (ok && (ConfigIndex < ConfigFiles)); ConfigIndex++) { if (!ConfigLoad(ConfigFile[ConfigIndex])) { ok = FALSE; continue; } TotalTrials += Trials; printf("%d %s Trials=%d TotalTrials=%d\n", ConfigIndex, ConfigFile[ConfigIndex], Trials, TotalTrials); } ConfigIndex = 1; } if ((TotalTrials == 0) || !ok) { return(FALSE); } // Set rows of TrialData to the number of trials. TrialData.SetRows(TotalTrials); printf("Making list of %d trials (ESCape to abort)...\n", TotalTrials); TotalTrials = 0; TotalNullTrials = 0; TotalExposureTrials = 0; TotalCatchTrials = 0; // Loop over configuration files, appending each to growing trial list. for (ok = TRUE; (ok && (ConfigIndex < ConfigFiles)); ConfigIndex++) { if (ConfigIndex > 0) { if (!ConfigLoad(ConfigFile[ConfigIndex])) { ok = FALSE; continue; } } // Create subset of trials for this configuration file. if (!TrialListSubset()) { ok = FALSE; continue; } TotalTrials += Trials; TotalNullTrials += NullTrial; TotalExposureTrials += ExposureTrial; TotalCatchTrials += CatchTrial; printf("%d %s Trials=%d TotalTrials=%d\n", ConfigIndex, ConfigFile[ConfigIndex], Trials, TotalTrials); } if (!ok) { return(FALSE); } printf("%d Total Trials, %d Null, %d Exposure, %d Catch.\n", TotalTrials, TotalNullTrials, TotalExposureTrials, TotalCatchTrials); // Total number of trails. Trials = TotalTrials; // Save trial list to file. ok = DATAFILE_Save(TrialListFile, TrialData); printf("%s %s Trials=%d.\n", TrialListFile, STR_OkFailed(ok), TrialData.GetRows()); // Reset trial number, etc. Trial = 1; TrialSetup(); ExperimentTimer.Reset(); StateNext(STATE_INITIALIZE); return(TRUE); }