void TestModeTouchscreen(T_uezDevice aLCD, T_uezDevice aTS, T_uezQueue aQueue) { T_pixelColor *pixels; T_uezInputEvent inputEvent; // We are busy doing calibration G_mmTestModeTouchscreenCalibrationBusy = ETrue; // Flush the queue by reading all the events up til this point while(UEZQueueReceive(aQueue, &inputEvent, 0) == UEZ_ERROR_NONE) {} UEZLCDGetFrame(aLCD, 0, (void **)&pixels); G_mmTestModeColor = RGB(0, 0, 0); IClearScreen0(aLCD); TestModeTouchscreenProcedure(pixels, aTS); IClearScreen(aLCD); // Flush the queue by reading all the events up til this point while(UEZQueueReceive(aQueue, &inputEvent, 0) == UEZ_ERROR_NONE) {} // Done doing calibration G_mmTestModeTouchscreenCalibrationBusy = EFalse; }
/********************************************************************* * * _TouchTask * * Function description: * Handle touch screen input * */ static U32 _TouchTask(T_uezTask aMyTask, void *aParameters) { T_uezInputEvent inputEvent; GUI_PID_STATE State = { 0 }; (void)aMyTask; (void)aParameters; while (1) { if (_RequestExit == 1) { _RequestExit = 0; break; } // // Wait for 100ms for a new touch event to occur. Else skip over to give the // task a chance to respond to an exit request. // if (UEZQueueReceive(_hTSQueue, &inputEvent, 100) == UEZ_ERROR_NONE) { if (inputEvent.iEvent.iXY.iAction == XY_ACTION_PRESS_AND_HOLD) { State.x = inputEvent.iEvent.iXY.iX; State.y = inputEvent.iEvent.iXY.iY; State.Pressed = 1; } else { State.x = -1; State.y = -1; State.Pressed = 0; } GUI_PID_StoreState(&State); } } return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: Serial_GenericHalfDuplex_Read *---------------------------------------------------------------------------* * Description: * Read data from the serial port. If an infinite amount of time is * given, the serial port will wait until data arrives. If a value * of 0 is given for the timeout, then the serial data is read * only if data is available. The timeout is the timeout between * successive characters, not the complete transfer. * Inputs: * void *aWorkspace -- This serial GenericHalfDuplex workspace * TUInt8 *aData -- Place to store data * TUInt32 aNumBytes -- Number of bytes to read. * TUInt32 *aNumBytesRead -- Number of bytes actually read. If * timeout occurs, this value is less than * aNumBytes. * Outputs: * T_uezError -- Error code. UEZ_ERROR_TIMEOUT is returned * if timeout occurs trying to read * the full amount and not enough data is * provided. UEZ_ERROR_NONE is reported if * all data is returned. *---------------------------------------------------------------------------*/ T_uezError Serial_GenericHalfDuplex_Read( void *aWorkspace, TUInt8 *aData, TUInt32 aNumBytes, TUInt32 *aNumBytesRead, TUInt32 aTimeout) { // Decrement use count. Are we done? T_Serial_GenericHalfDuplex_Workspace *p = (T_Serial_GenericHalfDuplex_Workspace *)aWorkspace; T_uezError error = UEZ_ERROR_NONE; TUInt32 i; for (i=0; i<aNumBytes; i++) { // Keep trying to receive bytes error = UEZQueueReceive(p->iQueueReceive, aData, aTimeout); if (error) break; aData++; } // Report how many bytes we did get if (aNumBytesRead) *aNumBytesRead = i; // Report final error return error; }
/*-------------------------------------------------------------------------* * Function: GenericBulkBulkIn *-------------------------------------------------------------------------* * Description: * The PC is requesting data to be sent back to it. Pull data * output of the fifo and send it back up to the maximum size * packet. * Inputs: * TUInt8 aEndpoint -- Endpoint with interrupt * T_USBEndpointStatus aStatus -- Current status of this endpoint *-------------------------------------------------------------------------*/ void GenericBulkBulkIn( void *aWorkspace, TUInt8 aEndpoint, T_USBEndpointStatus aStatus) { TInt16 i, length; TUInt8 c; PARAM_NOT_USED(aWorkspace); PARAM_NOT_USED(aStatus); // Pull out data up to the maximum size of a packet memset(G_GenBulkBuffer, 0xFF, sizeof(G_GenBulkBuffer)); for (i=0; i<(GENERIC_BULK_MAX_PACKET_SIZE-1); i++) { // Only process if we have data if (UEZQueueReceive(G_GenBulkFifoOut, &G_GenBulkBuffer[i+1], 0) != UEZ_ERROR_NONE) break; } length = i; G_GenBulkBuffer[0] = length; // Send what we have back (first byte is the length of the rest of the bytes) (*G_ghDevice)->Write(G_ghDevice, aEndpoint, G_GenBulkBuffer, sizeof(G_GenBulkBuffer)); // Check to see if there is more in the queue and if not // report we are empty (if we have a callback) if (G_callbacks.iGenBulkEmptyOutput) { if (UEZQueuePeek(G_GenBulkFifoOut, &c, 0) == UEZ_ERROR_TIMEOUT) { G_callbacks.iGenBulkEmptyOutput(G_callbacks.iCallbackWorkspace); } } }
/*---------------------------------------------------------------------------* * Task: CalibrateMode *---------------------------------------------------------------------------* * Description: * Put the device in forced calibration mode since the user chose * this choice. * Inputs: * const T_choice *p_choice -- Choice activated for this mode *---------------------------------------------------------------------------*/ void TestMode(void) { T_uezDevice ts; T_uezDevice lcd; T_pixelColor *pixels; T_uezQueue queue; TUInt32 cmd; if (UEZQueueCreate(1, sizeof(TUInt32), &G_mmTestModeQueue) == UEZ_ERROR_NONE) { // Setup queue to receive touchscreen events if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { // Open the LCD and get the pixel buffer if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE) { UEZLCDGetFrame(lcd, 0, (void **)&pixels); TestModeScreen(); G_mmTestModeRunning = ETrue; while (1) { UEZQueueReceive(G_mmTestModeQueue, &cmd, UEZ_TIMEOUT_INFINITE); if (cmd == 0) { break; } else { switch (cmd) { case TEST_MODE_TOUCHSCREEN: // Draw targets for test pattern TestModeTouchscreen(lcd, ts, queue); break; case TEST_MODE_LCD: // Draw test pattern TestModeLCD(lcd); break; case TEST_MODE_PING: // Ping does nothing break; case TEST_MODE_FILL_COLOR: TestModeFillColor(lcd); break; case TEST_MODE_ALIGNMENT_BORDER: TestModeAlignmentBorder(lcd); break; default: break; } } } } UEZTSClose(ts, queue); } UEZQueueDelete(queue); } G_mmTestModeRunning = EFalse; UEZQueueDelete(G_mmTestModeQueue); } }
/*---------------------------------------------------------------------------* * Routine: VideoPlayerSelect *---------------------------------------------------------------------------* * Description: * Setup the video player, drawing the video player load screen. Load * images onto the screen and then go into video player scroll mode or * report an error. * Inputs: * const T_choice *aChoice -- Choice used to get here. *---------------------------------------------------------------------------*/ void VideoPlayerSelection(const T_choice *aChoice) { T_uezDevice lcd; T_uezQueue queue; T_uezDevice ts; T_uezInputEvent inputEvent; #if ENABLE_UEZ_BUTTON T_uezDevice keypadDevice; #endif G_ws = UEZMemAlloc(sizeof(T_VideoPlayerSelectWorkspace)); if (!G_ws) return; memset(G_ws, 0, sizeof(*G_ws)); if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { #if ENABLE_UEZ_BUTTON UEZKeypadOpen("BBKeypad", &keypadDevice, &queue); #endif #if UEZ_REGISTER UEZQueueSetName(queue, "VideoSelection", "\0"); #endif // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE) { G_ws->iLCD = lcd; G_ws->iDriveError = AudioPlayerSelectionLoad(1); VideoPlayerSelectScreen(lcd); VideoPlayerSelectChoices(); VideoPlayerSelectDraw(); // Sit here in a loop until we are done while (!G_ws->iExit) { //Wait till we get a touchscreen event if (UEZQueueReceive(queue, &inputEvent, UEZ_TIMEOUT_INFINITE)==UEZ_ERROR_NONE) { ChoicesUpdate(&G_win, G_ws->iChoices, queue, 500); } } UEZLCDClose(lcd); } UEZTSClose(ts, queue); } #if ENABLE_UEZ_BUTTON UEZKeypadClose(keypadDevice, &queue); #endif UEZQueueDelete(queue); } UEZMemFree(G_ws); }
void IWaitTouchscreen(void) { T_uezInputEvent inputEvent; T_uezDevice ts; T_uezQueue queue; if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue) == UEZ_ERROR_NONE) { // Wait first for the screen NOT to be touched while (1) { if (UEZQueueReceive(queue, &inputEvent, 10) != UEZ_ERROR_NONE) { if (inputEvent.iEvent.iXY.iAction == XY_ACTION_RELEASE) break; } } // Wait first for the screen to be touched while (1) { if (UEZQueueReceive(queue, &inputEvent, 10) != UEZ_ERROR_NONE) { if (inputEvent.iEvent.iXY.iAction == XY_ACTION_PRESS_AND_HOLD) break; } } // Wait first for the screen NOT to be touched while (1) { if (UEZQueueReceive(queue, &inputEvent, 10) != UEZ_ERROR_NONE) { if (inputEvent.iEvent.iXY.iAction == XY_ACTION_RELEASE) break; } } UEZTSClose(ts, queue); } UEZQueueDelete(queue); } }
void AudioPlayerMode(const T_choice *aChoice) { T_uezDevice lcd; T_uezQueue queue; T_uezDevice ts; T_uezInputEvent inputEvent; UEZSemaphoreCreateCounting(&G_AudioSemaphore, 10, 1); G_ws = UEZMemAlloc(sizeof(T_AudioPlayerWorkspace)); if (!G_ws) return; memset(G_ws, 0, sizeof(*G_ws)); if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { #if UEZ_REGISTER UEZQueueSetName(queue, "AudioPlayer", "\0"); #endif // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE) { G_ws->iLCD = lcd; G_ws->iDriveError = AudioPlayerLoadDirectory(); AudioPlayerScreen(lcd); AudioPlayerChoices(); AudioPlayerDraw(); // Sit here in a loop until we are done while (!G_ws->iExit) { //Wait till we get a touchscreen event if (UEZQueueReceive(queue, &inputEvent, UEZ_TIMEOUT_INFINITE)==UEZ_ERROR_NONE) { ChoicesUpdate(&G_win, G_ws->iChoices, queue, 500); } } UEZLCDClose(lcd); } UEZTSClose(ts, queue); } UEZQueueDelete(queue); } UEZMemFree(G_ws); }
/*---------------------------------------------------------------------------* * Routine: ChoicesUpdate *---------------------------------------------------------------------------* * Description: * Wait for a touchscreen event or timeout. Check the event and change * the state of the choices. * Inputs: * SWIM_WINDOW_T *aWin -- Window to draw within * const T_choice *aChoices -- Choices to use * T_uezQueue aTouchQueue -- Touchscreen queue * TUInt32 aTimeout -- Time to wait for touchscreen event * Outputs: * const T_choice * -- Last choice selected or 0 for none. *---------------------------------------------------------------------------*/ const T_choice *ChoicesUpdate( SWIM_WINDOW_T *aWin, const T_choice *aChoices, T_uezQueue aInputEventQueue, TUInt32 aTimeout) { T_uezInputEvent inputEvent; if (UEZQueueReceive(aInputEventQueue, &inputEvent, aTimeout) == UEZ_ERROR_NONE) { return ChoicesUpdateByReading(aWin, aChoices, &inputEvent); } else { return 0; } }
/*-------------------------------------------------------------------------* * Function: GenericBulkGet *-------------------------------------------------------------------------* * Description: * Try to get a character from the virtual comm driver. * If no characters are available, returns -1. Does not block. * Inputs: * TUInt32 aTimeout -- Time to wait for a character to appear * Outputs: * TInt32 -- Character from buffer, or -1 *-------------------------------------------------------------------------*/ TInt32 GenericBulkGet(TUInt32 aTimeout) { TUInt8 c; // Try to get data, but don't block T_uezError error; error = UEZQueueReceive(G_GenBulkFifoIn, &c, aTimeout); // If error, report none if (error == UEZ_ERROR_NONE) { return (TInt32)c; } else { return -1; } }
/*---------------------------------------------------------------------------*/ static TUInt32 ImageLoadTask(T_uezTask aMyTask, void *aParams) { TBool run = ETrue; T_uezFile file; char filename[50]; TUInt8 i = 1; T_ImageMessage QueueMessage; //create the queue to receive messages about //loading images from the SC card UEZQueueCreate(1, sizeof(TUInt32), &G_ImageLoadQueue); UEZSemaphoreCreateBinary(&G_LoadingSemaphore); //find how many images are on the SC card //file names only allows 99 files while(i <= 99){ sprintf(filename, IMAGE_NAME_DIR IMAGE_NAME_BASE "%02d" IMAGE_EXT, i); if (UEZFileOpen(filename, FILE_FLAG_READ_ONLY, &file) == UEZ_ERROR_NONE){ i++; UEZFileClose(file); } else { G_NumImagesOnCard = i-1; break; } } if(G_NumImagesOnCard == 0){ //nothing to do. no images found on card return 1; } //load the images to the SD Card while(run){ UEZQueueReceive(G_ImageLoadQueue, (void*)&QueueMessage, UEZ_TIMEOUT_INFINITE); switch(QueueMessage){ case IMAGE_INITILIZE: //the current image has already been loaded //so load the next and previous images UEZSemaphoreGrab(G_LoadingSemaphore, UEZ_TIMEOUT_INFINITE); sprintf(filename, IMAGE_NAME_DIR IMAGE_NAME_BASE "%02d" IMAGE_EXT, G_CurrentImage_Number + 1); if (UEZFileOpen(filename, FILE_FLAG_READ_ONLY, &file) == UEZ_ERROR_NONE){ UEZFileRead(file, G_NextImage, IMAGE_BUFFER_SIZE,&read); UEZFileClose(file); } sprintf(filename, IMAGE_NAME_DIR IMAGE_NAME_BASE "%02d" IMAGE_EXT, G_NumImagesOnCard); if (UEZFileOpen(filename, FILE_FLAG_READ_ONLY, &file) == UEZ_ERROR_NONE){ UEZFileRead(file, G_PreviousImage, IMAGE_BUFFER_SIZE,&read); UEZFileClose(file); } UEZSemaphoreRelease(G_LoadingSemaphore); break; case IMAGE_ADVANCED: UEZSemaphoreGrab(G_LoadingSemaphore, UEZ_TIMEOUT_INFINITE); if( G_CurrentImage_Number < G_NumImagesOnCard){ sprintf(filename, IMAGE_NAME_DIR IMAGE_NAME_BASE "%02d" IMAGE_EXT, G_CurrentImage_Number + 1); } else { sprintf(filename, IMAGE_NAME_DIR IMAGE_NAME_BASE "%02d" IMAGE_EXT, 1); } if (UEZFileOpen(filename, FILE_FLAG_READ_ONLY, &file) == UEZ_ERROR_NONE){ UEZFileRead(file, G_NextImage, IMAGE_BUFFER_SIZE,&read); UEZFileClose(file); } UEZSemaphoreRelease(G_LoadingSemaphore); break; case IMAGE_REVERSED: UEZSemaphoreGrab(G_LoadingSemaphore, UEZ_TIMEOUT_INFINITE); if (G_CurrentImage_Number > 1){ sprintf(filename, IMAGE_NAME_DIR IMAGE_NAME_BASE "%02d" IMAGE_EXT, G_CurrentImage_Number - 1); } else { sprintf(filename, IMAGE_NAME_DIR IMAGE_NAME_BASE "%02d" IMAGE_EXT, G_NumImagesOnCard); } if (UEZFileOpen(filename, FILE_FLAG_READ_ONLY, &file) == UEZ_ERROR_NONE){ UEZFileRead(file, G_PreviousImage, IMAGE_BUFFER_SIZE,&read); UEZFileClose(file); } UEZSemaphoreRelease(G_LoadingSemaphore); break; default: break; } } return 0; }
/*---------------------------------------------------------------------------* * Routine: DrawMode *---------------------------------------------------------------------------* * Description: * Put the processor in the draw mode 'application' or 'demo'. * Buttons are shown to load, save, exit, and change the current color. * The user can then draw in the designated area a small picture using * the current color. * Inputs: * const T_choice *aChoice -- Choice object selected for this action. *---------------------------------------------------------------------------*/ void DrawMode(const T_choice *aChoice) { T_uezDevice lcd; T_uezDevice ts; static T_uezQueue queue = (TUInt32)NULL; INT_32 winX, winY; T_pixelColor *pixels; T_uezInputEvent inputEvent; TBool isDrawing = EFalse; INT_32 lastWinX, lastWinY; G_drExit = EFalse; #ifdef NO_DYNAMIC_MEMORY_ALLOC if (NULL == queue) { if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) != UEZ_ERROR_NONE) { queue = NULL; } } if (NULL != queue) { /* Register the queue so that the IAR Stateviewer Plugin knows about it. */ UEZQueueAddToRegistry( queue, "Draw TS" ); #else if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { #endif // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { // Open the LCD and get the pixel buffer if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE) { UEZLCDGetFrame(lcd, 0, (void **)&pixels); // Put the draw screen up DR_Screen(lcd); DR_DrawColor(); while (!G_drExit) { // Wait forever until we receive a touchscreen event // NOTE: UEZTSGetReading() can also be used, but it doesn't wait. if (UEZQueueReceive(queue, &inputEvent, UEZ_TIMEOUT_INFINITE)==UEZ_ERROR_NONE) { winX = inputEvent.iEvent.iXY.iX; winY = inputEvent.iEvent.iXY.iY; swim_get_virtual_xy(&G_drWin, &winX, &winY); // Are we in the drawing area? if ((winX > DR_IMAGE_LEFT) && (winX < DR_IMAGE_RIGHT) && (winY > DR_IMAGE_TOP) && (winY < DR_IMAGE_BOTTOM)) { // Pen down or up? if (inputEvent.iEvent.iXY.iAction == XY_ACTION_PRESS_AND_HOLD) { UEZLCDScreensaverWake(); if (G_drColor == BLACK) { // Draw a 3x3 block in the area swim_set_pen_color(&G_drWin, G_drColor); if (isDrawing) { DrawBlockLine(lastWinX, lastWinY, winX, winY); } else { DrawBlockPixel(winX, winY); } } else { // Draw a dot swim_set_pen_color(&G_drWin, G_drColor); if (isDrawing) { swim_put_line(&G_drWin, lastWinX, lastWinY, winX, winY); } else { swim_put_pixel(&G_drWin, winX, winY); } } isDrawing = ETrue; lastWinX = winX; lastWinY = winY; } else { // No longer drawing isDrawing = EFalse; } } else { ChoicesUpdateByReading(&G_drWin, G_drChoices, &inputEvent); if (inputEvent.iEvent.iXY.iAction == XY_ACTION_RELEASE) isDrawing = EFalse; } } } UEZLCDClose(lcd); } UEZTSClose(ts, queue); } #ifndef NO_DYNAMIC_MEMORY_ALLOC UEZQueueDelete(queue); #endif } }
void BrightnessControlMode(const T_choice *aChoice) { T_uezDevice ts; static T_uezQueue queue = NULL; static T_brightnessControlWorkspace *G_ws = NULL; INT_32 winX, winY; T_uezInputEvent inputEvent; #if ENABLE_UEZ_BUTTON T_uezDevice keypadDevice; #endif #if UEZ_ENABLE_LIGHT_SENSOR TUInt32 levelCurrent = 1, levelPrevious = 0; T_uezDevice ls; DEVICE_LightSensor **p; T_uezError error; char levelText[30]; TBool lightSensorActive = EFalse; if( UEZDeviceTableFind("Light Sensor", &ls) == UEZ_ERROR_NONE) { if(UEZDeviceTableGetWorkspace(ls, (T_uezDeviceWorkspace **)&p) == UEZ_ERROR_NONE) { if((*p)->Open((void *)p, "I2C1") == UEZ_ERROR_NONE) { lightSensorActive = ETrue; } } } #endif #ifdef NO_DYNAMIC_MEMORY_ALLOC if (NULL == G_ws) { G_ws = UEZMemAlloc(sizeof(*G_ws)); } #else G_ws = UEZMemAlloc(sizeof(*G_ws)); #endif #if UEZ_ENABLE_LIGHT_SENSOR UEZTaskSuspend(G_lightSensorTask); #endif if (!G_ws) return; memset(G_ws, 0, sizeof(*G_ws)); G_ws->iExit = EFalse; G_ws->iNeedUpdate = ETrue; #ifdef NO_DYNAMIC_MEMORY_ALLOC if (NULL == queue) { if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) != UEZ_ERROR_NONE) { queue = NULL; } } if (NULL != queue) { /* Register the queue so that the IAR Stateviewer Plugin knows about it. */ UEZQueueAddToRegistry( queue, "Brightness TS" ); #else if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { #if UEZ_REGISTER UEZQueueSetName(queue, "Brightness", "\0"); #endif #endif #if ENABLE_UEZ_BUTTON UEZKeypadOpen("BBKeypad", &keypadDevice, &queue); #endif // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { // Open the LCD and get the pixel buffer if (UEZLCDOpen("LCD", &G_ws->iLCD) == UEZ_ERROR_NONE) { UEZLCDGetBacklightLevel(G_ws->iLCD, &G_ws->iLevel, &G_ws->iNumLevels); // Put the screen up BCMScreen(G_ws); // Sit here in a loop until we are done while (!G_ws->iExit) { // Do choices and updates if (UEZQueueReceive(queue, &inputEvent, 500)==UEZ_ERROR_NONE) { winX = inputEvent.iEvent.iXY.iX; winY = inputEvent.iEvent.iXY.iY; swim_get_virtual_xy(&G_win, &winX, &winY); if (inputEvent.iEvent.iXY.iAction == XY_ACTION_PRESS_AND_HOLD) { // Are we in the panel? if ((winY >= G_ws->iRSlidePanel.iTop) && (winY <= G_ws->iRSlidePanel.iBottom) && (winX >= G_ws->iRSlidePanel.iLeft) && (winX <= G_ws->iRSlidePanel.iRight)) { // Inside the panel and touching the screen, let's map this to an intensity // of 0-255 if(winY > G_ws->iRGroove.iBottom) G_ws->iLevel = 0; else { G_ws->iLevel = (G_ws->iRGroove.iBottom - winY)*(G_ws->iNumLevels)/ (1+G_ws->iRGroove.iBottom-G_ws->iRGroove.iTop); } UEZLCDSetBacklightLevel(G_ws->iLCD, G_ws->iLevel); G_ws->iNeedUpdate = ETrue; } } ChoicesUpdateByReading(&G_win, G_ws->iChoices, &inputEvent); #if UEZ_ENABLE_LIGHT_SENSOR if (lightSensorActive) { levelCurrent = (*p)->GetLevel((void *)p); if(levelCurrent == 0xFFFFFFFF) { //ligh sensor no longer resonding lightSensorActive = EFalse; break; } if( levelCurrent != levelPrevious) { swim_set_font(&G_win, &APP_DEMO_DEFAULT_FONT); swim_set_fill_color(&G_win, BLACK); swim_set_pen_color(&G_win, BLACK); sprintf(levelText, "Ambient Light Level: %04d lux\0", levelCurrent); //erase old text swim_put_box(&G_win, (UEZ_LCD_DISPLAY_WIDTH/2) - (swim_get_text_line_width(&G_win, levelText) /2),//x1 BCM_SLIDE_PANEL_OUTER_PADDING,//y1 (UEZ_LCD_DISPLAY_WIDTH/2) + (swim_get_text_line_width(&G_win, levelText) /2),//x2 BCM_SLIDE_PANEL_OUTER_PADDING + swim_get_font_height(&G_win));//y2 //put new text swim_set_pen_color(&G_win, YELLOW); swim_put_text_xy(&G_win, levelText, (UEZ_LCD_DISPLAY_WIDTH/2) - (swim_get_text_line_width(&G_win, levelText) /2),//x (BCM_SLIDE_PANEL_OUTER_PADDING));//y levelPrevious = levelCurrent; } } #endif } if (G_ws->iNeedUpdate) { BCMUpdate(G_ws); G_ws->iNeedUpdate = EFalse; } } UEZLCDClose(G_ws->iLCD); } UEZTSClose(ts, queue); } #if ENABLE_UEZ_BUTTON UEZKeypadClose(keypadDevice, &queue); #endif #ifndef NO_DYNAMIC_MEMORY_ALLOC UEZQueueDelete(queue); #endif #if UEZ_ENABLE_LIGHT_SENSOR (*p)->Close((void *)p); UEZTaskResume(G_lightSensorTask); #endif } /* <<< WHIS >>> Potential memory leak in FreeRTOS version as G_ws is not free'd. */ }
/*---------------------------------------------------------------------------* * Routine: MultiSlideshowMode *---------------------------------------------------------------------------* * Description: * Setup the slideshow, drawing the slideshow load screen. Load * images onto the screen and then go into slideshow scroll mode or * report an error. * Inputs: * const T_choice *aChoice -- Choice used to get here. *---------------------------------------------------------------------------*/ void MultiSlideshowMode(const T_choice *aChoice) { T_uezDevice lcd; // T_uezError error; // T_uezFile file; TUInt32 drive; T_uezError driveError[2]; T_uezQueue queue; T_uezDevice ts; T_uezInputEvent inputEvent; #if ENABLE_UEZ_BUTTON T_uezDevice keypadDevice; #endif G_ws = UEZMemAlloc(sizeof(T_MSMWorkspace)); if (!G_ws) return; memset(G_ws, 0, sizeof(*G_ws)); if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) { #if ENABLE_UEZ_BUTTON UEZKeypadOpen("BBKeypad", &keypadDevice, &queue); #endif #if UEZ_REGISTER UEZQueueSetName(queue, "MultiSlideShow", "\0"); #endif // Open up the touchscreen and pass in the queue to receive events if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE) { if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE) { G_ws->iLCD = lcd; // Is there old slideshows available? driveError[SLIDESHOW_FLASH_DRIVE] = OldSlideshowCheckAvailable(SLIDESHOW_FLASH_DRIVE); driveError[SLIDESHOW_SDCARD_DRIVE] = OldSlideshowCheckAvailable(SLIDESHOW_SDCARD_DRIVE); if (driveError[SLIDESHOW_FLASH_DRIVE] == UEZ_ERROR_NONE) { drive = SLIDESHOW_FLASH_DRIVE; } else if (driveError[SLIDESHOW_SDCARD_DRIVE] == UEZ_ERROR_NONE) { drive = SLIDESHOW_SDCARD_DRIVE; } else { drive = SLIDESHOW_DRIVE_NONE; } if (drive == SLIDESHOW_DRIVE_NONE) { // MultiSlideshow is not loaded, load the slideshow list // Determine on which drives the slideshow is located //check for INI File on both drives driveError[SLIDESHOW_FLASH_DRIVE] = MultiSlideshowCheckAvailableINI(SLIDESHOW_FLASH_DRIVE); driveError[SLIDESHOW_SDCARD_DRIVE] = MultiSlideshowCheckAvailableINI(SLIDESHOW_SDCARD_DRIVE); //if INI if(!driveError[SLIDESHOW_FLASH_DRIVE] || !driveError[SLIDESHOW_SDCARD_DRIVE]) { if ((driveError[SLIDESHOW_FLASH_DRIVE] == UEZ_ERROR_NONE) || (driveError[SLIDESHOW_SDCARD_DRIVE] == UEZ_ERROR_NOT_READY)) drive = SLIDESHOW_FLASH_DRIVE; else drive = SLIDESHOW_SDCARD_DRIVE; G_ws->iDrive = drive; // Load the directory if the drive is active G_ws->iSlideshowList.iCount = 0; if (driveError[drive] == UEZ_ERROR_NONE) driveError[drive] = IMSLoadDirectoryINI(drive); G_ws->iDriveError = driveError[drive]; } else { driveError[SLIDESHOW_FLASH_DRIVE] = MultiSlideshowCheckAvailable(SLIDESHOW_FLASH_DRIVE); driveError[SLIDESHOW_SDCARD_DRIVE] = MultiSlideshowCheckAvailable(SLIDESHOW_SDCARD_DRIVE); // Choose the flash drive if available, otherwise use SDCard if ((driveError[SLIDESHOW_FLASH_DRIVE] == UEZ_ERROR_NONE) || (driveError[SLIDESHOW_SDCARD_DRIVE] == UEZ_ERROR_NOT_READY)) drive = SLIDESHOW_FLASH_DRIVE; else drive = SLIDESHOW_SDCARD_DRIVE; G_ws->iDrive = drive; // Load the directory if the drive is active G_ws->iSlideshowList.iCount = 0; if (driveError[drive] == UEZ_ERROR_NONE) driveError[drive] = IMSLoadDirectory(drive); G_ws->iDriveError = driveError[drive]; } // Put the screen (with options) MultiSlideshowScreen(lcd); MSMSetupChoices(); MSMDraw(); // Sit here in a loop until we are done while (!G_ws->iExit) { //Wait till we get a touchscreen event if (UEZQueueReceive(queue, &inputEvent, UEZ_TIMEOUT_INFINITE)==UEZ_ERROR_NONE) { ChoicesUpdate(&G_win, G_ws->iChoices, queue, 500); } } } else { // Got an old slideshow to show T_slideshowDefinition def; def.iDrive = drive; def.iName[0] = '\0'; def.iDirectory[0] = '\0'; SingleSlideshowMode(&def); } UEZLCDClose(lcd); } UEZTSClose(ts, queue); } #if ENABLE_UEZ_BUTTON UEZKeypadClose(keypadDevice, &queue); #endif UEZQueueDelete(queue); } UEZMemFree(G_ws); }
/*---------------------------------------------------------------------------* * Routine: ChoicesUpdateContinuously *---------------------------------------------------------------------------* * Description: * Wait for a touchscreen event or timeout. Check the event and change * the state of the choices. Choices are chosen continuously as they * are pressed reporting events every call. * Inputs: * SWIM_WINDOW_T *aWin -- Window to draw within * const T_choice *aChoices -- Choices to use * T_uezQueue aTouchQueue -- Touchscreen queue * TUInt32 aTimeout -- Time to wait for touchscreen event * Outputs: * const T_choice * -- Last choice selected or 0 for none. *---------------------------------------------------------------------------*/ const T_choice *ChoicesUpdateContinuously( SWIM_WINDOW_T *aWin, const T_choice *aChoices, T_uezQueue aInputEventQueue, TUInt32 aTimeout) { T_uezInputEvent inputEvent; INT_32 winX, winY; static const T_choice *p_lastChoice = 0; const T_choice *p_choice = 0; const T_choice *p_choiceCalled = 0; if (UEZQueueReceive(aInputEventQueue, &inputEvent, aTimeout) == UEZ_ERROR_NONE) { winX = inputEvent.iEvent.iXY.iX; winY = inputEvent.iEvent.iXY.iY; swim_get_virtual_xy(aWin, &winX, &winY); // Is this a touching event? if (inputEvent.iEvent.iXY.iAction == XY_ACTION_PRESS_AND_HOLD) { // We are touching the screen. // Is this a different position than before? // Determine which choice we are in p_choice = IFindChoice(aChoices, winX, winY); if (p_choice != p_lastChoice) { if (p_lastChoice) { // Un-invert the last choice (draw black square) swim_set_fill_color(aWin, G_settings.iUnselectColor); swim_set_pen_color(aWin, G_settings.iUnselectColor); swim_set_fill_transparent(aWin, 1); swim_put_box(aWin, p_lastChoice->iLeft, p_lastChoice->iTop, p_lastChoice->iRight, p_lastChoice->iBottom); swim_set_fill_transparent(aWin, 0); } if (p_choice) { // Invert the new choice swim_set_pen_color(aWin, G_settings.iSelectColor); swim_set_fill_transparent(aWin, 1); swim_put_box(aWin, p_choice->iLeft, p_choice->iTop, p_choice->iRight, p_choice->iBottom); swim_set_fill_transparent(aWin, 0); } p_lastChoice = p_choice; p_choice = 0; } // Act like we just released the same spot // Determine which choice we are in p_choice = p_lastChoice; if (p_choice) { // Same as when we pressed // Do the action if (p_choice->iAction) { const T_choice *p_prevChoice = p_lastChoice; p_lastChoice = 0; // ButtonClick(); p_choiceCalled = p_choice; p_choice->iAction(p_choice); // Un-invert the last choice swim_set_fill_transparent(aWin, 1); swim_set_pen_color(aWin, G_settings.iUnselectColor); swim_put_box(aWin, p_prevChoice->iLeft, p_prevChoice->iTop, p_prevChoice->iRight, p_prevChoice->iBottom); swim_set_fill_transparent(aWin, 0); p_lastChoice = 0; } } } else { // The screen is no longer being touched. // Nothing being touched p_lastChoice = 0; return 0; } } else { return 0; } return p_choiceCalled; }