Example #1
0
/*---------------------------------------------------------------------------*/
T_uezError UEZWAVChangeFile(char* newFile)
{
    T_uezError error;
    
    UEZTaskSuspend(G_playerTask);
    (*i2s)->Stop((void*)i2s);//UEZStopWAV();
    playStatus = EFalse;
    UEZFileClose(file);
    fileOpen = EFalse;
    error = UEZFileOpen(newFile, FILE_FLAG_READ_ONLY, &file);
    if(error != UEZ_ERROR_NONE)
        return error;
     fileOpen = ETrue;
    error = UEZFileRead(file, &throwAway, 44, &numBytesRead);
    readNextBlock(wav, &numBytesRead);
    readNextBlock(wav2, &numBytesRead2);
    read1 = 0;
    read2 = 0;
    index = 0;
    flag = ETrue;
    playStatus = ETrue;
    UEZTaskResume(G_playerTask);
    (*i2s)->Start((void*)i2s);
    return UEZ_ERROR_NONE;
}
Example #2
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. */
}