Beispiel #1
0
static void IDrawTwoDigits(T_timeDateWorkspace *G_ws, T_region *r, char *aDigits, T_pixelColor aColor)
{
    INT_32 x, y;
    INT_32 nextX;

    swim_set_fill_color(&G_win, BLACK);
    swim_set_pen_color(&G_win, BLACK);
    swim_set_fill_transparent(&G_win, 0);
    swim_set_xy(&G_win, r->iLeft+1, r->iTop+1);
    swim_set_pen_color(&G_win, aColor);
    if (aDigits[0] != ' ')
        swim_put_char(&G_win, aDigits[0]);
    swim_get_xy(&G_win, &x, &y);
    nextX = r->iLeft+1+G_ws->iBigDigitWidth-1;
    if (x < nextX) {
        swim_set_pen_color(&G_win, BLACK);
        swim_put_box(&G_win, x, y, nextX, y+G_ws->iBigDigitHeight-1);
    }
    swim_set_xy(&G_win, r->iLeft+1+G_ws->iBigDigitWidth, r->iTop+1);
    swim_set_pen_color(&G_win, aColor);
    if (aDigits[1] != ' ')
        swim_put_char(&G_win, aDigits[1]);
    swim_get_xy(&G_win, &x, &y);
    nextX = r->iLeft+1+2*G_ws->iBigDigitWidth-3;
    if (x < nextX) {
        swim_set_pen_color(&G_win, BLACK);
        swim_put_box(&G_win, x, y, nextX, y+G_ws->iBigDigitHeight-1);
    }
}
Beispiel #2
0
static void BCMUpdate(T_brightnessControlWorkspace *G_ws)
{
    T_region r;
    TUInt32 y;

    swim_set_font_transparency(&G_win, 1);
    r = G_ws->iRGroove;
    UEZLCDGetBacklightLevel(G_ws->iLCD, &G_ws->iLevel, &G_ws->iNumLevels);
    y = (G_ws->iLevel * (1+r.iBottom-r.iTop))/G_ws->iNumLevels;
    y = r.iBottom - y;
    if (y != G_ws->iKnobY) {
        if (G_ws->iKnobY) {
            // Erase the old one
            swim_set_fill_transparent(&G_win, 0);
            swim_set_pen_color(&G_win, BLACK);
            swim_set_fill_color(&G_win, BLACK);
            swim_put_box(
                &G_win,
                r.iLeft-15,
                G_ws->iKnobY-5,
                r.iRight+15,
                G_ws->iKnobY+5);
        }
        swim_set_fill_transparent(&G_win, 1);
        swim_set_pen_color(&G_win, YELLOW);
        swim_put_box(
            &G_win,
            r.iLeft,
            r.iTop,
            r.iRight,
            r.iBottom);
        G_ws->iKnobY = y;
        swim_set_fill_transparent(&G_win, 0);
        swim_set_pen_color(&G_win, YELLOW);
        swim_set_fill_color(&G_win, BLACK);
        swim_put_box(
            &G_win,
            r.iLeft-15,
            G_ws->iKnobY-5,
            r.iRight+15,
            G_ws->iKnobY+5);
    }
}
Beispiel #3
0
/*---------------------------------------------------------------------------*
 * Routine:  DR_DrawColor
 *---------------------------------------------------------------------------*
 * Description:
 *      Draw the currently selected color in the upper left.
 *---------------------------------------------------------------------------*/
static void DR_DrawColor(void)
{
    const T_choice * const p_lastChoice = &G_drChoices[0];

    swim_set_fill_color(
        &G_drWin,
        G_drColor);
    swim_set_pen_color(&G_drWin, YELLOW);
    swim_put_box(&G_drWin,
        p_lastChoice->iLeft,
        p_lastChoice->iTop,
        p_lastChoice->iRight,
        p_lastChoice->iBottom);
}
Beispiel #4
0
static void DrawScreenSaverBox(T_brightnessControlWorkspace *G_ws)
{
    if(G_ScreenSaverOn == EFalse) {
        swim_set_fill_color(&G_win, BLACK);
    } else {
        swim_set_fill_color(&G_win, YELLOW);
    }
    swim_set_pen_color(&G_win, YELLOW);
    swim_put_box(
        &G_win,
        G_ssOptionBox.iLeft+1,
        G_ssOptionBox.iTop+1,
        G_ssOptionBox.iRight-1,
        G_ssOptionBox.iBottom-1);
}
/*---------------------------------------------------------------------------*
 * Routine:  ChoicesDraw
 *---------------------------------------------------------------------------*
 * Description:
 *      Draw an array of choices on the window.
 * Inputs:
 *      SWIM_WINDOW_T *aWin       -- Window to draw upon
 *      const T_choice *aChoices  -- Choices to draw
 *---------------------------------------------------------------------------*/
void ChoicesDraw(SWIM_WINDOW_T *aWin, const T_choice *aChoices)
{
    INT_32 imageX, imageY;
    int c;
    const char *p;
    const T_choice *p_choice;
    TUInt32 width;

    SUISetDrawWindow(aWin);
    
    for (c = 0; aChoices[c].iText; c++) {
        p_choice = aChoices + c;
        if (p_choice->iDraw) {
            // Custom drawing algorithm
            p_choice->iDraw(p_choice);
        } else {
            // Draw the choices and texxt
            if (p_choice->iIcon) {
                imageX = p_choice->iLeft;
                imageY = p_choice->iTop;
                swim_get_physical_xy(aWin, &imageX, &imageY);
                SUIDrawIcon(p_choice->iIcon, imageX, imageY);
            } else {
#if 0
                swim_put_box(aWin,
                    p_choice->iLeft,
                    p_choice->iTop,
                    p_choice->iRight,
                    p_choice->iBottom);
#endif
            }

            // Calculate width of text
            width = 0;
            for (p = aChoices[c].iText; *p; p++)
                width += swim_get_font_char_width(aWin, *p);

            // Cut width in half
            width >>= 1;

            // Now draw centered below.
            swim_put_text_xy(aWin, aChoices[c].iText,
                ((aChoices[c].iLeft + aChoices[c].iRight) >> 1) - width,
                aChoices[c].iBottom + 2);
        }
    }
}
static void MSMDraw(void)
{
    static const char *noFiles = "< No SLIDES.TXT file found >";
    static const char *noDrive = "< No Drive Found >";
    static const char *noListINI = "< Show not found in SLIDES.INI file >";
    const char *p_msg = noFiles;
    TUInt32 width;
    TUInt16 fontHeight;
    T_region r1, r2;
    SUIHidePage0();

    swim_set_font(&G_win, &APP_DEMO_DEFAULT_FONT);
    fontHeight = swim_get_font_height(&G_win);
    swim_set_pen_color(&G_win, YELLOW);
    swim_set_fill_color(&G_win, BLACK);

    swim_put_box(&G_win,
          G_ws->iChoiceBox.iLeft,
          G_ws->iChoiceBox.iTop,
          G_ws->iChoiceBox.iRight,
          G_ws->iChoiceBox.iBottom);

    if (G_ws->iSlideshowList.iCount==0) {
        p_msg = noDrive;
        if (G_ws->iDriveError == UEZ_ERROR_READ_WRITE_ERROR)
            p_msg = noDrive;
        else if (G_ws->iDriveError == UEZ_ERROR_NOT_FOUND)
            p_msg = noFiles;
        else if (G_ws->iDriveError == UEZ_ERROR_EMPTY)
            p_msg = noListINI;

        width = swim_get_text_line_width(&G_win, p_msg);
        RegionCenterLeftRight(&G_ws->iChoiceBox, &r1, width);
        RegionCenterTopBottom(&r1, &r2, fontHeight);
        swim_put_text_xy(&G_win, p_msg, r2.iLeft, r2.iTop);
    }

    ChoicesDraw(&G_win, G_ws->iChoices);

    SUIShowPage0();
}
Beispiel #7
0
/*---------------------------------------------------------------------------*
 * Routine:  DR_Screen
 *---------------------------------------------------------------------------*
 * Description:
 *      Draw the DrawMode screen.
 * Inputs:
 *      T_uezDevice lcd           -- LCD screen to use.
 *---------------------------------------------------------------------------*/
void DR_Screen(T_uezDevice lcd)
{
    T_pixelColor *pixels;

    UEZLCDGetFrame(lcd, 0, (void **)&pixels);
    SUIHidePage0();
    swim_window_open(
        &G_drWin,
        DISPLAY_WIDTH,
        DISPLAY_HEIGHT,
        pixels,
        0,
        0,
        DISPLAY_WIDTH-1,
        DISPLAY_HEIGHT-1,
        2,
        YELLOW,
        RGB(0, 0, 0),
        RED);
    swim_set_font(&G_drWin, &APP_DEMO_DEFAULT_FONT);
    swim_set_title(&G_drWin, "uEZ(tm) Draw Demonstration", BLUE);
    swim_set_pen_color(&G_drWin, YELLOW);

    ChoicesDraw(&G_drWin, G_drChoices);

    // Now draw the drawing area
    swim_set_fill_color(
        &G_drWin,
        BLACK);
    swim_put_box(
        &G_drWin,
        DR_IMAGE_LEFT,
        DR_IMAGE_TOP,
        DR_IMAGE_RIGHT,
        DR_IMAGE_BOTTOM);

    SUIShowPage0();
}
static void VideoPlayerSelectDraw(void)
{
    static const char *noFiles = "< No audio files found >";
	static const char *noDrive = "< No SD card found >";
    const char *p_msg = noFiles;
    TUInt32 width;
    TUInt16 fontHeight;
    T_region r1, r2;
    SUIHidePage0();

    swim_set_font(&G_win, &APP_DEMO_DEFAULT_FONT);
    fontHeight = swim_get_font_height(&G_win);
    swim_set_pen_color(&G_win, YELLOW);
    swim_set_fill_color(&G_win, BLACK);

    swim_put_box(&G_win, 
          G_ws->iChoiceBox.iLeft,
          G_ws->iChoiceBox.iTop,
          G_ws->iChoiceBox.iRight,
          G_ws->iChoiceBox.iBottom);

    if (G_ws->iNumVideos==0) {
        p_msg = noDrive;
        if (G_ws->iDriveError == UEZ_ERROR_READ_WRITE_ERROR)
            p_msg = noDrive;
        else if (G_ws->iDriveError == UEZ_ERROR_NOT_FOUND)
            p_msg = noFiles;
        
        width = swim_get_text_line_width(&G_win, p_msg);
        RegionCenterLeftRight(&G_ws->iChoiceBox, &r1, width);
        RegionCenterTopBottom(&r1, &r2, fontHeight);
        swim_put_text_xy(&G_win, p_msg, r2.iLeft, r2.iTop);
    }

    ChoicesDraw(&G_win, G_ws->iChoices);

    SUIShowPage0();
}
Beispiel #9
0
/*---------------------------------------------------------------------------*
 * 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);
}
Beispiel #10
0
/*---------------------------------------------------------------------------*
 * 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);
}
Beispiel #11
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. */
}
Beispiel #12
0
static void BCMScreen(T_brightnessControlWorkspace *G_ws)
{
    T_pixelColor *pixels;
    T_region r;
    T_region rbottom;
    T_region rtemp;
    TUInt32 width;
    T_choice *p = G_ws->iChoices;
    TUInt32 padding;

    SUIHidePage0();

    UEZLCDGetFrame(G_ws->iLCD, 0, (void **)&pixels);
    swim_window_open(
        &G_win,
        DISPLAY_WIDTH,
        DISPLAY_HEIGHT,
        pixels,
        0,
        0,
        DISPLAY_WIDTH-1,
        DISPLAY_HEIGHT-1,
        2,
        YELLOW,
        RGB(0, 0, 0),
        RED);
    swim_set_font(&G_win, &APP_DEMO_DEFAULT_FONT);
    G_ws->iFontHeight = swim_get_font_height(&G_win);
    swim_set_title(&G_win, "uEZ(tm) Brightness Control", BLUE);
    swim_set_pen_color(&G_win, YELLOW);
    swim_set_fill_color(&G_win, BLACK);

    r.iLeft = 0;
    r.iTop = 0;
    r.iRight = G_win.xvsize;
    r.iBottom = G_win.yvsize;

    // Come off the edges
    RegionShrink(&r, SCREEN_EDGE_MIN_PADDING-2);

    // Add the back button
    RegionSplitFromBottom(&r, &rbottom, 4+G_ws->iFontHeight+2+EXIT_BUTTON_HEIGHT, 5);
    //RegionCenterLeftRight(&rbottom, &rtemp, EXIT_BUTTON_WIDTH);
    //rbottom = rtemp;

    rtemp = rbottom;
    RegionSplitFromLeft(&rtemp, &rbottom, EXIT_BUTTON_WIDTH, 5);

    RegionShrink(&rbottom, 1);
    p->iLeft = rbottom.iLeft;
    p->iRight = rbottom.iLeft+EXIT_BUTTON_WIDTH-1;
    p->iTop = rbottom.iTop;
    p->iBottom = rbottom.iTop+EXIT_BUTTON_HEIGHT-1;
    p->iText = "Exit";
    p->iAction = BCMExit;
    p->iIcon = G_exitIcon;
    p->iData = (void *)G_ws;
    p->iDraw = 0; // Use default
    p++;

    rbottom = rtemp;
    RegionCenterLeftRight(&rbottom, &rtemp, 100);
    RegionSplitFromBottom(&rtemp, &G_ssOptionBox, (rtemp.iBottom-rtemp.iTop)/2+6, 5); // location of screen saver option box
    //RegionSplitFromLeft(&rtemp, &G_ssOptionBox, (rtemp.iBottom-rtemp.iTop)/2 - swim_get_font_height(&G_win)/2, 5);
    G_ssOptionBox.iRight = G_ssOptionBox.iLeft+swim_get_font_height(&G_win)+16; // size of screen saver option box
    G_ssOptionBox.iBottom = G_ssOptionBox.iTop+swim_get_font_height(&G_win)+16;

    p->iLeft = G_ssOptionBox.iLeft;
    p->iRight = G_ssOptionBox.iRight;
    p->iTop = G_ssOptionBox.iTop;
    p->iBottom = G_ssOptionBox.iBottom;
    p->iText = "";
    p->iAction = BCMScreenSaverToggle;
    p->iIcon = 0;
    p->iData = (void *)G_ws;
    p->iDraw = 0; // Use default
    p++;

    // Determine the spacing between slider and RGB
    // Determine width used
    width = BCM_COLORS_WIDTH+BCM_SLIDE_PANEL_INNER_PADDING*2+BCM_SLIDE_PANEL_OUTER_PADDING*2+BCM_GROOVE_WIDTH;
    // Now subtract that from the full width available.
    width = (1+r.iRight-r.iLeft)-width;
    // Split it 3 ways to divide it evenly
    padding = width/3;

    // Now use this padding to take a chunk out of the left
    RegionSplitFromLeft(&r, &rtemp, 0, padding);
    // Now determine the region for the slider
    RegionSplitFromLeft(
        &r,
        &G_ws->iRSlidePanel,
        BCM_SLIDE_PANEL_INNER_PADDING*2+BCM_SLIDE_PANEL_OUTER_PADDING*2+BCM_GROOVE_WIDTH,
        padding);
    RegionCenterLeftRight(&G_ws->iRSlidePanel, &G_ws->iRGroove, BCM_GROOVE_WIDTH);
    RegionShrinkTopBottom(&G_ws->iRGroove, BCM_SLIDE_PANEL_INNER_PADDING);

    // Now place the colors on the right
    RegionSplitFromLeft(
        &r,
        &rtemp,
        BCM_COLORS_WIDTH,
        0);
    RegionCenterTopBottom(
        &rtemp,
        &G_ws->iRColors,
        BCM_COLORS_HEIGHT);

    swim_set_font(&G_win, &APP_DEMO_DEFAULT_FONT);

    swim_set_font_transparency(&G_win, 1);
    swim_set_fill_transparent(&G_win, 0);
    swim_set_pen_color(&G_win, YELLOW);
    r = G_ws->iRSlidePanel;
    swim_put_box(
        &G_win,
        r.iLeft,
        r.iTop,
        r.iRight,
        r.iBottom);
    r = G_ws->iRGroove;
    swim_put_box(
        &G_win,
        r.iLeft,
        r.iTop,
        r.iRight,
        r.iBottom);

    DrawScreenSaverBox(G_ws);

    swim_put_text_xy(&G_win, "Screen Saver On/Off",
                     G_ssOptionBox.iLeft+swim_get_font_height(&G_win)+22,//x
                     G_ssOptionBox.iTop+8);//y

    // Now do the RTC
    // Now draw the fields
    IPatternOfColors(G_ws);

    swim_set_pen_color(&G_win, YELLOW);
    ChoicesDraw(&G_win, G_ws->iChoices);

    SUIShowPage0();
}
/* Creates a title bar for the window */
void swim_set_title(SWIM_WINDOW_T *win,
					const CHAR *title,
					COLOR_T ttlbkcolor)
{
	COLOR_T savedf, savedp, savedb;
	int32_t savedt;

	/* Is present font height larger than window client height? */
	if ((swim_get_font_height(win) < (4 + win->yvsize)) &&
		(title != (CHAR *) 0)) {
		/* There is enough room for title bar, so continue */

		/* Save original colors and font transparentcy flag */
		savedf = win->fill;
		savedp = win->pen;
		savedb = win->bkg;
		savedt = win->tfont;

		/* Set fill color to background color (temporarily)
		   used with box function */
		win->fill = ttlbkcolor;
		win->bkg = ttlbkcolor;
		win->pen = win->bkg;

		/* Draw the background for the title bar */
		swim_put_box(win, 0, 0, win->xvsize,
					 (4 + swim_get_font_height(win) - 2));

		/* Reset text starting position for title string */
		win->xvpos = win->xpvmin + 2;
		win->yvpos = win->ypvmin + 1;

		/* Restore original pen color (used for text color) */
		win->pen = savedp;

		/* Restore the original colors */
		win->fill = savedf;
		win->bkg = savedb;

		/* Put string in title bar area (with transparent background) */
		win->tfont = 0;
		swim_put_text(win, title);
		win->tfont = savedt;

		/* Draw a line under the title bar, but before the
		   (new) client area */
		swim_put_line(win, 0,
					  (4 + swim_get_font_height(win) - 1),
					  win->xpvmax, (4 + swim_get_font_height(win) - 1));

		/* Adjust client height of window (virtual and physcal) */
		win->ypmin = win->ypmin + swim_get_font_height(win) + 4;
		win->ypvmin = win->ypvmin + swim_get_font_height(win) + 4;

		/* Resize y dimension */
		win->yvsize = win->yvsize - swim_get_font_height(win) + 4;

		/* Reset text starting position to new client area */
		win->xvpos = win->xpvmin;
		win->yvpos = win->ypvmin;
	}
}
/*---------------------------------------------------------------------------*
 * 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;
}
/*---------------------------------------------------------------------------*
 * Routine:  ChoicesUpdateByReading
 *---------------------------------------------------------------------------*
 * Description:
 *      An input event has been received.  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 *ChoicesUpdateByReading(
    SWIM_WINDOW_T *aWin,
    const T_choice *aChoices,
    T_uezInputEvent *p_inputEvent)
{
    INT_32 winX, winY;
    static TUInt16 lastX = 0, lastY = 0;
    static const T_choice *p_lastChoice = 0;
    static const T_choice *p_buttonChoice = 0;
    static const T_choice *p_nextButtonChoice = 0;
    const T_choice *p_choice = 0;
    const T_choice *p_choiceCalled = 0;

    winX = p_inputEvent->iEvent.iXY.iX;
    winY = p_inputEvent->iEvent.iXY.iY;
    swim_get_virtual_xy(aWin, &winX, &winY);

    // Is this a touching event?
    if(p_inputEvent->iType == INPUT_EVENT_TYPE_XY) {
        // Is this a press or hold event?
        if (p_inputEvent->iEvent.iXY.iAction == XY_ACTION_PRESS_AND_HOLD) {
            // We are touching the screen.
            // Is this a different position than before?
            if ((p_inputEvent->iEvent.iXY.iX != lastX) || (p_inputEvent->iEvent.iXY.iY != lastY)) {
                // Determine which choice we are in
                p_choice = IFindChoice(aChoices, winX, winY);
                if (p_choice != p_lastChoice) {
    #if HAPTIC_FEEDBACK              
                    hapticFeedback(DEFAULT_HAPTIC_TIME_MS);
    #endif                
                    if (p_lastChoice) {
                        // Un-invert the last choice 
                        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);
                    }
    
                    // Turn off button repeating when we leave focus
                    G_repeatOn = EFalse;
                    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);
    
                        // If the option we are over is repeating,
                        // turn on repeating.
                        if (p_choice->iFlags & SUI_FLAG_REPEAT)
                            G_repeatOn = ETrue;
                    }
                    p_lastChoice = p_choice;
                    p_choice = 0;
                }
            }
    
            // Are we allowed to repeat?
            if (G_repeatOn) {
                if (!G_repeating) {
                    G_repeating = ETrue;
                    G_repeatLastTouch = UEZTickCounterGet();
                    G_repeatTime = REPEAT_TIME_1; // first repeat is slow
                } else {
                    // Time to repeat?
                    if (UEZTickCounterGetDelta(G_repeatLastTouch) >= G_repeatTime) {
                        if (G_repeatTime == REPEAT_TIME_1)
                            G_repeatTime = REPEAT_TIME_2;
                        else if (G_repeatTime == REPEAT_TIME_2)
                            G_repeatTime = REPEAT_TIME_3;
                        G_repeatLastTouch = UEZTickCounterGet();
    
                        // Cause a repeat by signalling a non-touch event below
                        //p_reading->iFlags &= ~TSFLAG_PEN_DOWN;
                    }
                }
            }
        } else {
            // Really not touching?
            // Are we repeating?
            if (G_repeating) {
                // Stop that.
                G_repeating = EFalse;
            }
        }
    
        // Release event (real for faked above?)
        if (p_inputEvent->iEvent.iXY.iAction == XY_ACTION_RELEASE) {
            // The screen is no longer being touched.
            // 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;
                    p_choiceCalled = 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_choice->iAction(p_choice);
    
                    p_lastChoice = 0;
                }
            }
        }
    } else {
        
        
        // This is a button event
        if(p_inputEvent->iEvent.iButton.iAction == BUTTON_ACTION_PRESS) {
            
            if(p_buttonChoice == 0){
                p_buttonChoice = IFindChoiceTopLeft(aChoices);
            } else {
                // Un-invert the last choice 
                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_buttonChoice->iLeft, p_buttonChoice->iTop,
                    p_buttonChoice->iRight, p_buttonChoice->iBottom);
                swim_set_fill_transparent(aWin, 0);
                
                if(p_inputEvent->iEvent.iButton.iKey == KEY_ARROW_RIGHT) {
                    p_nextButtonChoice = IFindChoiceRight(aChoices, p_buttonChoice, 2);
                    if(p_nextButtonChoice == p_buttonChoice)
                        p_buttonChoice = IFindChoiceRight(aChoices, p_buttonChoice, 1);
                    else
                        p_buttonChoice = p_nextButtonChoice;
                } else if(p_inputEvent->iEvent.iButton.iKey == KEY_ARROW_LEFT) {
                    p_nextButtonChoice = IFindChoiceLeft(aChoices, p_buttonChoice, 2);
                    if(p_nextButtonChoice == p_buttonChoice)
                        p_buttonChoice = IFindChoiceLeft(aChoices, p_buttonChoice, 1);
                    else
                        p_buttonChoice = p_nextButtonChoice;
                } else if(p_inputEvent->iEvent.iButton.iKey == KEY_ARROW_UP) {
                    p_nextButtonChoice = IFindChoiceUp(aChoices, p_buttonChoice, 2);
                    if(p_nextButtonChoice == p_buttonChoice)
                        p_buttonChoice = IFindChoiceUp(aChoices, p_buttonChoice, 1);
                    else
                        p_buttonChoice = p_nextButtonChoice;
                } else if(p_inputEvent->iEvent.iButton.iKey == KEY_ARROW_DOWN) {
                    p_nextButtonChoice = IFindChoiceDown(aChoices, p_buttonChoice, 2);
                    if(p_nextButtonChoice == p_buttonChoice)
                        p_buttonChoice = IFindChoiceDown(aChoices, p_buttonChoice, 1);
                    else
                        p_buttonChoice = p_nextButtonChoice;
                } else if(p_inputEvent->iEvent.iButton.iKey == KEY_ENTER) {
                    p_choice = p_buttonChoice;
                    p_buttonChoice = 0;
                    p_choiceCalled = p_choice;
                    p_choice->iAction(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_buttonChoice->iLeft, p_buttonChoice->iTop,
                p_buttonChoice->iRight, p_buttonChoice->iBottom);
            swim_set_fill_transparent(aWin, 0);
            
        } else /* BUTTON_ACTION_RELEASE */{
        }
    }
    return p_choiceCalled;
}