/*---------------------------------------------------------------------------* * Routine: DR_Save *---------------------------------------------------------------------------* * Description: * Save the currently shown image to the flash drive. * Inputs: * const T_choice *aChoice -- Choice object selected for this action. *---------------------------------------------------------------------------*/ static void DR_Save(const T_choice *aChoice) { T_uezError error; T_uezError errorUSB, errorSD; T_uezFile file; INT_32 winX, winY; T_pixelColor *raster; TUInt32 num; TUInt16 x, y; // Draw line around choice while saving swim_set_fill_transparent(&G_drWin, 1); swim_set_pen_color(&G_drWin, YELLOW); swim_put_box( &G_drWin, aChoice->iLeft, aChoice->iTop, aChoice->iRight, aChoice->iBottom); // Try to save to the USB drive error = errorUSB = UEZFileOpen("0:IMAGE.RAW", FILE_FLAG_WRITE, &file); // If an error, try to save to the SD Card if (error != UEZ_ERROR_NONE) error = errorSD = UEZFileOpen("1:IMAGE.RAW", FILE_FLAG_WRITE, &file); else errorSD = UEZ_ERROR_UNKNOWN; // Any errors? if (error == UEZ_ERROR_NONE) { raster = (T_pixelColor *)LOAD_SPACE; for (y=0; y<DR_IMAGE_HEIGHT; y++) { for (x=0; x<DR_IMAGE_WIDTH; x++) { winX = x + DR_IMAGE_LEFT+1; winY = y + DR_IMAGE_TOP+1; swim_get_physical_xy(&G_drWin, &winX, &winY); swim_driver_get_raster(&G_drWin, winX, winY, (COLOR_T *)raster, 1); // get pixel color raster++; } } // Save image error = UEZFileWrite( file, LOAD_SPACE, DR_IMAGE_WIDTH*DR_IMAGE_HEIGHT*sizeof(T_pixelColor), &num); if ((error != UEZ_ERROR_NONE) && (num != DR_IMAGE_WIDTH*DR_IMAGE_HEIGHT*sizeof(T_pixelColor))) { BeepError(); } UEZFileClose(file); } else { // Had an error, report it SUICopyFast32(FRAME(1), FRAME(0), FRAME_SIZE); BeepError(); swim_set_fill_transparent(&G_drWin, 0); swim_set_fill_color(&G_drWin, BLACK); swim_set_pen_color(&G_drWin, YELLOW); swim_put_box( &G_drWin, DR_IMAGE_LEFT, DR_IMAGE_TOP, DR_IMAGE_RIGHT, DR_IMAGE_TOP+16); if (errorUSB == UEZ_ERROR_NOT_FOUND) { if (errorSD == UEZ_ERROR_NOT_READY) { swim_put_text_xy( &G_drWin, "Could not write image to USB Drive", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } else if (errorSD == UEZ_ERROR_NOT_FOUND) { swim_put_text_xy( &G_drWin, "Could not write to USB Drive or SD Card", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } else { swim_put_text_xy( &G_drWin, "Could not write to USB Drive", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } } else if (errorUSB == UEZ_ERROR_NOT_READY) { if (errorSD == UEZ_ERROR_NOT_READY) { swim_put_text_xy( &G_drWin, "No USB Drive or SDCard found!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } else if (errorSD == UEZ_ERROR_NOT_FOUND) { swim_put_text_xy( &G_drWin, "Could not write to SD Card!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } else { swim_put_text_xy( &G_drWin, "Could not write to SD Card!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } } else { swim_put_text_xy( &G_drWin, "Write error!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } swim_set_fill_transparent(&G_drWin, 1); UEZTaskDelay(2000); SUICopyFast32(FRAME(0), FRAME(1), FRAME_SIZE); } swim_set_fill_transparent(&G_drWin, 1); swim_set_pen_color(&G_drWin, BLACK); swim_put_box( &G_drWin, aChoice->iLeft, aChoice->iTop, aChoice->iRight, aChoice->iBottom); }
void ErrorOK(const char *qtf) { BeepError(); Prompt(Ctrl::GetAppName(), CtrlImg::error(), qtf, t_("OK")); }
/*---------------------------------------------------------------------------* * Routine: DR_Load *---------------------------------------------------------------------------* * Description: * Load an image from the flash drive and show. * Inputs: * const T_choice *aChoice -- Choice object selected for this action. *---------------------------------------------------------------------------*/ static void DR_Load(const T_choice *aChoice) { T_uezError error; T_uezError errorUSB, errorSD; T_uezFile file; INT_32 winX, winY; TUInt32 num; TUInt16 x, y; // Draw line around choice while loading swim_set_fill_transparent(&G_drWin, 1); swim_set_pen_color(&G_drWin, YELLOW); swim_put_box( &G_drWin, aChoice->iLeft, aChoice->iTop, aChoice->iRight, aChoice->iBottom); // Try to load from the USB drive error = errorUSB = UEZFileOpen("0:IMAGE.RAW", FILE_FLAG_READ_ONLY, &file); // If an error, try to load from the SD Card if (error != UEZ_ERROR_NONE) error = errorSD = UEZFileOpen("1:IMAGE.RAW", FILE_FLAG_READ_ONLY, &file); else errorSD = UEZ_ERROR_UNKNOWN; // Continue if no errors if (error == UEZ_ERROR_NONE) { error = UEZFileRead( file, LOAD_SPACE, DR_IMAGE_WIDTH*DR_IMAGE_HEIGHT*sizeof(T_pixelColor), &num); UEZFileClose(file); if ((error != UEZ_ERROR_NONE) && (num != DR_IMAGE_WIDTH*DR_IMAGE_HEIGHT*sizeof(T_pixelColor))) { BeepError(); } else { T_pixelColor *raster = (T_pixelColor *)LOAD_SPACE; for (y=0; y<DR_IMAGE_HEIGHT; y++) { for (x=0; x<DR_IMAGE_WIDTH; x++) { winX = x + DR_IMAGE_LEFT+1; winY = y + DR_IMAGE_TOP+1; swim_get_physical_xy(&G_drWin, &winX, &winY); swim_driver_put_pixel(&G_drWin, winX, winY, raster[x]); } raster += DR_IMAGE_WIDTH; } } } if (error) { // Had an error, report it SUICopyFast32(FRAME(1), FRAME(0), FRAME_SIZE); BeepError(); swim_set_fill_transparent(&G_drWin, 0); swim_set_fill_color(&G_drWin, BLACK); swim_set_pen_color(&G_drWin, YELLOW); swim_put_box( &G_drWin, DR_IMAGE_LEFT, DR_IMAGE_TOP, DR_IMAGE_RIGHT, DR_IMAGE_TOP+16); if (errorUSB == UEZ_ERROR_NOT_FOUND) { if (errorSD == UEZ_ERROR_NOT_READY) { swim_put_text_xy( &G_drWin, "Image file not found on USB Drive!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } else if (errorSD == UEZ_ERROR_NOT_FOUND) { swim_put_text_xy( &G_drWin, #if UEZ_DEFAULT_LCD_RES_QVGA // Shorter string on QVGA screens "Image file not found on USB or SD Card!", #else "Image file not found on USB Drive or SD Card!", #endif DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } else { swim_put_text_xy( &G_drWin, "Image file not found on USB Drive!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } } else if (errorUSB == UEZ_ERROR_NOT_READY) { if (errorSD == UEZ_ERROR_NOT_READY) { swim_put_text_xy( &G_drWin, "No USB Drive or SD Card found!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } else if (errorSD == UEZ_ERROR_NOT_FOUND) { swim_put_text_xy( &G_drWin, "Image file not found on SD Card!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } else { swim_put_text_xy( &G_drWin, "No USB Drive or SD Card found!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } } else { swim_put_text_xy( &G_drWin, "Read error!", DR_IMAGE_LEFT+2, DR_IMAGE_TOP+2); } swim_set_fill_transparent(&G_drWin, 1); UEZTaskDelay(2000); SUICopyFast32(FRAME(0), FRAME(1), FRAME_SIZE); } swim_set_fill_transparent(&G_drWin, 1); swim_set_pen_color(&G_drWin, BLACK); swim_put_box( &G_drWin, aChoice->iLeft, aChoice->iTop, aChoice->iRight, aChoice->iBottom); }
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; } }