/*---------------------------------------------------------------------------*
 * 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;
    }
}
示例#2
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
    }
}
示例#3
0
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. */
}