Ejemplo n.º 1
0
    void AudioRenderer::SetClock(IReferenceClock* pClock)
    {
        CAutoLock objectLock(this);

        m_graphClock = pClock;

        if (m_graphClock && !IsEqualObject(m_graphClock, m_myClock.GetOwner()))
        {
            if (!m_externalClock)
                ClearDevice();

            m_externalClock = true;
        }
        else
        {
            if (m_externalClock)
                ClearDevice();

            m_externalClock = false;
        }
    }
Ejemplo n.º 2
0
    bool AudioRenderer::PushToDevice(DspChunk& chunk, CAMEvent* pFilledEvent)
    {
        bool firstIteration = true;
        uint32_t sleepDuration = 0;
        while (!chunk.IsEmpty())
        {
            // The device buffer is full or almost full at the beginning of the second and subsequent iterations.
            // Sleep until the buffer may have significant amount of free space. Unless interrupted.
            if (!firstIteration && m_flush.Wait(sleepDuration))
                return false;

            firstIteration = false;

            CAutoLock objectLock(this);

            assert(m_state != State_Stopped);

            if (m_device)
            {
                try
                {
                    m_device->Push(chunk, pFilledEvent);
                    sleepDuration = (m_device->IsRealtime() ? 50 : m_device->GetBufferDuration() / 4);
                }
                catch (HRESULT)
                {
                    ClearDevice();
                    sleepDuration = 0;
                }
            }
            else
            {
                // The code below emulates null audio device.

                if (pFilledEvent)
                    pFilledEvent->Set();

                sleepDuration = 1;

                // Loop until the graph time passes the current sample end.
                REFERENCE_TIME graphTime;
                if (m_state == State_Running &&
                    SUCCEEDED(m_graphClock->GetTime(&graphTime)) &&
                    graphTime > m_startTime + m_sampleCorrection.GetLastFrameEnd() + m_sampleCorrection.GetTimeDivergence())
                {
                    break;
                }
            }
        }

        return true;
    }
/*******************************************************************************
 * FUNCTION: vCreateWallpaperPage
 *
 * PARAMETERS:
 * ~ void
 *
 * RETURN:
 * ~ void
 *
 * DESCRIPTIONS:
 * Create the page to show the wallpaper.
 *
 *******************************************************************************/
void vCreateWallpaperPage (void)
{
    // Clear the GOL objects and screen.
    GOLFree();
    SetColor(BLACK);
    ClearDevice();

    // Create the wallpaper image.
    PictCreate( GID_IMG_WALLPAPPER,
                0,         0,
                GetMaxX(), GetMaxY(),
                PICT_DRAW, 1, "/Theme/Wallpaper.bmp", pxDefaultScheme );
}
Ejemplo n.º 4
0
/***************************************************
* Function       : CreateError
* Parameters     : none
* Return         : none
* Description    : Creates a Error screen
***************************************************/
void CreateError(char* string)
{
    // Blue Screen Error
    SetColor(119);
    ClearDevice();
    SetColor(-1);


    // Flash Error Message
    if(string == NULL)
        {OutTextXY(0, 0, "Runtime Error.");}
    else
        {OutTextXY(0,0, string);}
}
Ejemplo n.º 5
0
    void AudioRenderer::CheckDeviceSettings()
    {
        CAutoLock objectLock(this);

        UINT32 newSettingsSerial = m_settings->GetSerial();
        uint32_t newDefaultDeviceSerial = m_deviceManager.GetDefaultDeviceSerial();

        if (m_device && (m_deviceSettingsSerial != newSettingsSerial ||
                         m_defaultDeviceSerial != newDefaultDeviceSerial))
        {
            bool settingsDeviceDefault;
            std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> settingsDeviceId;
            BOOL settingsDeviceExclusive;
            UINT32 settingsDeviceBuffer;

            {
                LPWSTR pDeviceId = nullptr;

                if (FAILED(m_settings->GetOuputDevice(&pDeviceId, &settingsDeviceExclusive, &settingsDeviceBuffer)))
                    return;

                settingsDeviceDefault = (!pDeviceId || !*pDeviceId);
                settingsDeviceId.reset(pDeviceId);

                m_deviceSettingsSerial = newSettingsSerial;
            }

            std::unique_ptr<WCHAR, CoTaskMemFreeDeleter> systemDeviceId;;

            if (settingsDeviceDefault)
            {
                systemDeviceId = m_deviceManager.GetDefaultDeviceId();

                if (!systemDeviceId)
                    return;
            }

            m_defaultDeviceSerial = newDefaultDeviceSerial;

            if ((m_device->IsExclusive() != !!settingsDeviceExclusive) ||
                (m_device->GetBufferDuration() != settingsDeviceBuffer) ||
                (!settingsDeviceDefault && *m_device->GetId() != settingsDeviceId.get()) ||
                (settingsDeviceDefault && *m_device->GetId() != systemDeviceId.get()))
            {
                ClearDevice();
                assert(!m_device);
            }
        }
    }
Ejemplo n.º 6
0
void CreateDemo(void)
{
	GOLFree();
	SetColor(GFX_SCHEMEDEFAULT.CommonBkColor);
	ClearDevice();

	BtnCreate(ID_BUTTON,
		GetMaxX() * 1 / 4,
		GetMaxY() * 1 / 3,
		GetMaxX() * 3 / 4,
		GetMaxY() * 2 / 3,
		0, BTN_DRAW, NULL, "Button", NULL);

	showDecoration = FALSE;
	showDecorationPrev = TRUE; // force redraw
}
Ejemplo n.º 7
0
// µð¹ÙÀ̽º Àç »ý¼º
bool cInitD3D::ReCreateDevice()
{
	// ¸®¼Ò½º ºä Ŭ¸®¾î
	ClearResourceView();

	// µð¹ÙÀ̽º Ŭ¸®¾î
	ClearDevice();

	// µð¹ÙÀ̽º »ý¼º
	if (!InitDirect3D())
		return false;

	// È­¸é À籸¼º
	OnResize();

	return true;
}
Ejemplo n.º 8
0
    void AudioRenderer::NewSegment(double rate)
    {
        CAutoLock objectLock(this);

        if (m_rate != rate)
        {
            m_rate = rate;

            if (m_device)
                (m_device->GetEnd() > 0) ? ClearDevice() : InitializeProcessors();
        }

        m_startClockOffset = 0;

        m_clockCorrection += m_sampleCorrection.GetLastFrameEnd();

        m_sampleCorrection.NewSegment(m_rate);
    }
Ejemplo n.º 9
0
/************************************************************************
 Function: void CreateMultiFontsDemo(void)
                                                                       
 Overview: Creates the Multi-Font demo screen.
  		                                         
 Input: none
                                                                       
 Output: none
************************************************************************/
void CreateMultiFontsDemo(void)
{
    SHORT           i, j;

    // we need this since Static cannot have an uninitialized pointer to text
    // plus we need the static text area but we are only using it as a place
    // holder for the text that we will overwrite on the static text area
    static XCHAR    spaceChar[2] = {0x20,0};

    GOLFree();                          // free memory for the objects in the previous linked list and start new list
    SetColor(SCREEN_BACKGROUND_COLOR);
    ClearDevice();

    // draw the small squares
    SetColor(RGB565CONVERT(0x4C, 0x8E, 0xFF));
    for(j = 5; j <= GetMaxY(); j += 16)
    {
        for(i = 5; i <= GetMaxX(); i += 16)
        {
            WAIT_UNTIL_FINISH(Bar(i, j, i + 3, j + 3));
        }
    }

    InitHWData();

    FontScheme2 = GOLCreateScheme();    // create alternative style scheme
    FontScheme2->pFont = pHWData->pHWFont;
    FontScheme2->Color0 = RGB565CONVERT(0xFF, 0xBB, 0x4C);
    FontScheme2->Color1 = RGB565CONVERT(0xFF, 0xBB, 0x4C);

    StCreate
    (
        ID_STXT,
        STXXPOS,
        STXYPOS,
        STXXPOS + STXWIDTH,
        STXYPOS + STXHEIGHT,
        ST_DRAW | ST_FRAME,
        (void *) &spaceChar,
        FontScheme2
    );

    CreateCtrlButtons(ExitStr, LeftArrowStr, NULL, RightArrowStr);
}
Ejemplo n.º 10
0
/************************************************************************
 Function: void DisplayErrorInfo(void)
                                                                       
 Overview: Display the error information when decoding an unsupported 
 		   image or thumb drive was removed when decoding.
 		                                          
 Input: none
                                                                       
 Output: none
************************************************************************/
void DisplayErrorInfo(void)
{
    WORD    TextX, TextY, TextHeight;
    SetFont((void *) &GOLFontDefault);
    TextHeight = GetTextHeight((void *) &GOLFontDefault);

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);
    TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)JPEGUnsupportedStr, (void *) &GOLFontDefault)) / 2;
    TextY = (IMG_SCREEN_HEIGHT - 3 * TextHeight) / 2;
    WAIT_UNTIL_FINISH(OutTextXY(TextX, TextY, (XCHAR *)JPEGUnsupportedStr));
    TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)JPEGImageStr, (void *) &GOLFontDefault)) / 2;
    WAIT_UNTIL_FINISH(OutTextXY(TextX, TextY + TextHeight, (XCHAR *)JPEGImageStr));
    TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)JPEGFormatStr, (void *) &GOLFontDefault)) / 2;
    WAIT_UNTIL_FINISH(OutTextXY(TextX, TextY + 2 * TextHeight, (XCHAR *)JPEGFormatStr));

    DelayMs(800);
}
Ejemplo n.º 11
0
void InitializeScreen( void )
{
    GOLFree();
    SetColor(BLACK);        // set color to BLACK
    ClearDevice();          // set screen to all BLACK

    PictCreate(     ID_ICON,                    // ID
                    0,0,15,15,                  // dimension
                    PICT_DRAW,                  // will be dislayed, has frame
                    1,                          // scale factor is x1
                    &iconMicrochip,             // bitmap
                    NULL );                     // default GOL scheme

    StCreate(       ID_TITLE,
                    16, 0, GetMaxX()-11, GetTextHeight( (void *)&FONTDEFAULT )-1,
                    ST_DRAW,
                    pageInformation.title,
                    NULL );

    previousTick = tick; 
}
void TPrinter::SetDevice(Pchar ADevice, Pchar ADriver, Pchar APort)
{
  char DriverName[80];
  DEVMODE StubDevMode;

  if (Equal(Device, ADevice) && Equal(Driver, ADriver) &&
    Equal(Port, APort))
        return;
  ClearDevice();
  if (ADevice == NULL)
    GetDefaultPrinter();
  else {
    Device = newstrdup(ADevice);
    Driver = newstrdup(ADriver);
    Port = newstrdup(APort);
  }
  Status = PS_OK;
  strncpy(DriverName, Driver, sizeof(DriverName) - 1);
  strncat(DriverName, ".DRV", sizeof(DriverName) - strlen(DriverName) - 1);
  DeviceModule = LoadLibrary(DriverName);
        if ((int)DeviceModule < 32)
        Status = PS_INVALIDDEVICE;
  else {
    // Grab the DevMode procedures
    ExtDeviceMode = (LPFNDEVMODE) GetProcAddress(DeviceModule, "ExtDeviceMode");
    DeviceMode = (PTDeviceModeFcn) GetProcAddress(DeviceModule, "DeviceMode");
    if ((DeviceMode == NULL) && (ExtDeviceMode == NULL))
      Status = PS_INVALIDDEVICE;
    if (ExtDeviceMode != NULL) {
      // Get default printer settings
      DevSettingSize = ExtDeviceMode(0, DeviceModule, &StubDevMode,
        Device, Port, &StubDevMode, NULL, 0);
      DevSettings = (PDEVMODE) new char[DevSettingSize];
      ExtDeviceMode(0, DeviceModule, DevSettings, Device, Port,
        DevSettings, NULL, DM_OUT_BUFFER);
    }
    else
      DevSettings = NULL;  // Cannot use local settings
  }
}
Ejemplo n.º 13
0
void CreateSetprog(void)
{
	GOLFree();
	SetColor(BLUE_LIGHT);
	ClearDevice();

	BtnCreate(Setprog_OBJ_BUTTON_0,7,46,116,117,10,BTN_DRAW,(void*)prog_images[0],NULL,defscheme);
	BtnCreate(Setprog_OBJ_BUTTON_1,125,46,234,117,10,BTN_DRAW,(void*)prog_images[1],NULL,defscheme);
	BtnCreate(Setprog_OBJ_BUTTON_2,7,124,116,195,10,BTN_DRAW,(void*)prog_images[2],NULL,defscheme);
	BtnCreate(Setprog_OBJ_BUTTON_3,125,124,234,195,10,BTN_DRAW,(void*)prog_images[3],NULL,defscheme);
	BtnCreate(Setprog_OBJ_BUTTON_4,7,201,116,272,10,BTN_DRAW,(void*)prog_images[4],NULL,defscheme);
	BtnCreate(Setprog_OBJ_BUTTON_5,125,201,234,272,10,BTN_DRAW,(void*)prog_images[5],NULL,defscheme);

	 
	BtnCreate(Setprog_OBJ_BUTTON_7,5,277,66,313,5,BTN_DRAW,NULL,(XCHAR*)EXIT_OBJ_BUTTON_text,botbar);
//	BtnCreate(Setprog_OBJ_BUTTON_8,92,277,152,313,5,BTN_DRAW,NULL,(XCHAR*)Setprog_OBJ_BUTTON_8_text,botbar);
//	BtnCreate(Setprog_OBJ_BUTTON_9,170,277,230,313,5,BTN_DRAW,NULL,(XCHAR*)Setprog_OBJ_BUTTON_9_text,botbar);


	StCreate(Setprog_OBJ_STATICTEXT_0,1,0,238,30,ST_DRAW|ST_CENTER_ALIGN,(XCHAR*)Setprog_OBJ_STATICTEXT_0_text,topbar);

}
TPrinter::~TPrinter()
{
  ClearDevice();
}
Ejemplo n.º 15
0
    /************************************************************************
 Function: WORD CreateJPEGDemo(void)
                                                                       
 Overview: Creates the JPEG demo screen.
  		                                         
 Input: none
                                                                       
 Output: Return 0 when memory is not enough for objects of the demo.
************************************************************************/
    WORD CreateJPEGDemo(void)
{
    BYTE    TextHeight;
    WORD    TextX;

    // Free memory for the objects in the previous linked list and start new list to display
    // the files seen on the media
    GOLFree();

    // initialize the image decoder
    ImageDecoderInit();

    // initialize the screen	
    SetColor(WHITE);
    ClearDevice();

    SetFont((void *) &GOLFontDefault);
    TextHeight = GetTextHeight((void *) &GOLFontDefault);

    SetColor(BRIGHTRED);
    TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)ImageDisplayStr, (void *) &GOLFontDefault)) / 2;
    WAIT_UNTIL_FINISH(OutTextXY(TextX, 1 * TextHeight, (XCHAR *)ImageDisplayStr));

    SetColor(BLACK);
    TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)DetectingStr, (void *) &GOLFontDefault)) / 2;
    WAIT_UNTIL_FINISH(OutTextXY(TextX, 3 * TextHeight, (XCHAR *)DetectingStr));
    TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)ThumbDriveStr, (void *) &GOLFontDefault)) / 2;
    WAIT_UNTIL_FINISH(OutTextXY(TextX, 4 * TextHeight, (XCHAR *)ThumbDriveStr));
    TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)PleaseWaitStr, (void *) &GOLFontDefault)) / 2;
    WAIT_UNTIL_FINISH(OutTextXY(TextX, 6 * TextHeight, (XCHAR *)PleaseWaitStr));

        #if defined(ENABLE_SD_MSD_DEMO)
    MDD_SDSPI_InitIO();
        #endif
    MonitorDriveMedia();

    if(mediaPresent == 0)
    {

        // erase the last line
        SetColor(WHITE);
        TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)PleaseWaitStr, (void *) &GOLFontDefault)) / 2;
        WAIT_UNTIL_FINISH(OutTextXY(TextX, 6 * TextHeight, (XCHAR *)PleaseWaitStr));

        // replace it with these
        SetColor(BRIGHTRED);
        TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)Exiting1Str, (void *) &GOLFontDefault)) / 2;
        WAIT_UNTIL_FINISH(OutTextXY(TextX, 6 * TextHeight, (XCHAR *)Exiting1Str));

        TextX = (IMG_SCREEN_WIDTH - GetTextWidth((XCHAR *)Exiting2Str, (void *) &GOLFontDefault)) / 2;
        WAIT_UNTIL_FINISH(OutTextXY(TextX, 7 * TextHeight, (XCHAR *)Exiting2Str));
        DelayMs(1000);
        return (0);
    }

    blImageOnScreen = 0;
    blTextOnScreen = 0;
    pSave = NULL;
    blSlideShowOn = 0;
    NextSlide = 0xFF;

    // create the listbox, slider and buttons that will emulate a
    // list box with controls.
    pListBox = LbCreate
        (
            ID_JPGLISTBOX,
            LBJPGXPOS,
            LBJPGYPOS,
            LBJPGXPOS + LBJPGWIDTH,
            LBJPGYPOS + LBJPGHEIGHT,
            LB_DRAW | LB_SINGLE_SEL,
            pJPGItemList,
            NULL
        );

    if(pListBox == NULL)
        return (0);

    pSlider = SldCreate
        (
            ID_SLD4LB,
            SLD4LBXPOS,
            SLD4LBYPOS,
            SLD4LBXPOS + SLD4LBWIDTH,
            SLD4LBYPOS + SLD4LBHEIGHT,
            SLD_DRAW | SLD_VERTICAL | SLD_SCROLLBAR,
            2,
            1,
            1,  // these are temporary fill items will set to proper values
            NULL
        );
    if(pSlider == NULL)
        return (0);

    pBtnUp = BtnCreate
        (
            ID_BTNUP4LB,
            BTNUP4LBXPOS,
            BTNUP4LBYPOS,
            BTNUP4LBXPOS + BTNUP4LBWIDTH,
            BTNUP4LBYPOS + BTNUP4LBHEIGHT,
            0,
            BTN_DRAW,
            NULL,
            (XCHAR *)JpegUpArrowStr,
            NULL
        );

    if(pBtnUp == NULL)
        return (0);

    pBtnDn = BtnCreate
        (
            ID_BTNDN4LB,
            BTNDN4LBXPOS,
            BTNDN4LBYPOS,
            BTNDN4LBXPOS + BTNDN4LBWIDTH,
            BTNDN4LBYPOS + BTNDN4LBHEIGHT,
            0,
            BTN_DRAW,
            NULL,
            (XCHAR *)JpegDownArrowStr,
            NULL
        );

    if(pBtnUp == NULL)
        return (0);

    // create the control buttons at the bottom of the screen
    CreateCtrlButtons(ExitStr, NULL, NULL, RightArrowStr);

    // fill the list box with the file names of images in the media
    FillNewElements();

    // set the first item to be focused
    LbSetFocusedItem(pListBox, 0);

    // successful creation of the JPEG demo screen
    return (1);
}
Ejemplo n.º 16
0
/*****************************************
 *int main (void)
 *****************************************/
int main (void)
{
    InitializeHardware();
    HardwareButtonInit();
    InitAllLEDs();
    
#ifdef USE_BISTABLE_DISPLAY_GOL_AUTO_REFRESH     
	GFX_DRIVER_AutoUpdPart();		// Turn on widget auto update, partial update for less flashing
#endif
    
    InitTick();
	GOLInit();

    SetColor(WHITE);
    ClearDevice();

	// Set proper display rotation
#if(DISP_ORIENTATION == 90)
    GFX_DRIVER_InitRotmode(ROTATE_90);
#else
#error "This PICTail display orientation must be 90."
#endif
       
	// make sure that the correct hex file is loaded
    CheckExternalFlashHex();

	// Create cursor in GFX_CURSOR_LAYER with Alpha Color = 0xA
	GFX_DRIVER_CreateLayer( GFX_CURSOR_LAYER, GFX_LAYER_TRANS_EN | 0xA, GetX(), GetY(), GetX() + 31, GetY() + 31 );
	GFX_DRIVER_ActivateLayer( GFX_CURSOR_LAYER );
	PutImage(0, 0, (void *)&mouse_cursor_icon_270, IMAGE_NORMAL); 
	GFX_DRIVER_ActivateLayer( GFX_MAIN_LAYER );
	
	// Start demo screen 
	demoScreens = DEMO_INTRO_SCREEN_CREATE;
	
    while(1)
	{
        GOLDraw();
#ifndef USE_BISTABLE_DISPLAY_GOL_AUTO_REFRESH
	#if defined( ONE_CYCLE_DRAWING	) 
		// The screen drawing starts and completes during one while(1) cycle loop in main().
		// This Demo is one cycle drawing application.
        if ( GFX_DRIVER_IsUpdateRequested() || (g_UPDATE_FLAGS == GFX_UPDATE_AS_IT_DRAWS) )
        {
	    	GFX_DRIVER_UpdateEpd( g_UPDATE_FLAGS, 0, 0, GetMaxX(), GetMaxY() ); 
	    	g_UPDATE_FLAGS = GFX_UPDATE_NO_FLASH | GFX_WAIT_IMAGE_DISPLAYED;   
	    }
	#else
		// This way can be used when drawing may take few or more cycles of while(1) loop in main().
		// See "tick.c" file for details.
        if ( g_UpdateNow || (g_UPDATE_FLAGS == GFX_UPDATE_AS_IT_DRAWS) )
        {
	        g_UpdateNow = 0;
	    	GFX_DRIVER_UpdateEpd( g_UPDATE_FLAGS, 0, 0, GetMaxX(), GetMaxY() ); 
	    	g_UPDATE_FLAGS = GFX_UPDATE_NO_FLASH | GFX_WAIT_IMAGE_DISPLAYED;   
	    }	
	#endif
#endif		 
	}	

    return (-1);
}
Ejemplo n.º 17
0
/***************************************************************
 * void CheckExternalFlashHex(void)
 ***************************************************************/
void CheckExternalFlashHex(void)
{
    typedef struct 
    {
        UINT32 mchpSignature;
        UINT32 mchpCRCData;
    } CRC_CHECK; 

    CRC_CHECK externalCRC, expectedCRC;   
    WORD textHeight;
    void *pFont;
    XCHAR *pStr = NULL;
    BOOL  setProgram = FALSE;
    
    XCHAR   msgStr1[] = {'P','r','o','g','r','a','m',' ','E','x','t','e','r','n','a','l',' ','D','a','t','a',0};
    XCHAR   msgStr2[] = {'E','x','t','e','r','n','a','l',' ','d','a','t','a',' ','i','n','v','a','l','i','d','.',0};
    XCHAR   msgStr3[] = {'P','l','e','a','s','e',' ','s','e','n','d',' ','d','a','t','a',' ','u','s','i','n','g',0};
    XCHAR   msgStr4[] = {'"','E','x','t','e','r','n','a','l',' ','M','e','m','o','r','y',0};
    XCHAR   msgStr5[] = {'P','r','o','g','r','a','m','m','e','r','"',' ','u','t','i','l','i','t','y',0};
    XCHAR   msgStr6[] = {'N','o','w',' ','w','a','i','t','i','n','g',' ','f','o','r',' ','d','a','t','a',0};
    XCHAR   msgStr7[] = {'v','i','a',' ','U','A','R','T','.','.','.',0};

    pFont = (void*) &FONTDEFAULT;
    SetFont(pFont);
    textHeight = GetTextHeight(pFont);

    // check if the CRC matches the data stored in the external flash memory
    expectedCRC.mchpCRCData = GRC_CRC32_EXTERNAL_MARKER;
    expectedCRC.mchpSignature = 0x5048434D;                // this is "MCHP"

    // check if programming is prompted     
    if(btnS2 == HW_BUTTON_PRESS)
    {
        pStr = msgStr1;
        setProgram = TRUE;
	} 

    if (setProgram == FALSE)
    {
        ReadArray(GRC_CRC32_EXTERNAL_ADDR, (BYTE *)&externalCRC, 8);
    
        if  ((expectedCRC.mchpCRCData != externalCRC.mchpCRCData) || \
             (expectedCRC.mchpSignature != externalCRC.mchpSignature))
        {
            // expected and read CRC does not match, proceed to programming flash first
            // run the flash programming 
            pStr = msgStr2;
            setProgram = TRUE;
        }
    }
    
    if (setProgram == TRUE)
    {
        SetColor(WHITE);
        ClearDevice();
        SetColor(BLACK);
        OutTextXY(10,10                 , pStr);
        OutTextXY(10,10 + (textHeight*2), msgStr3);
        OutTextXY(10,10 + (textHeight*3), msgStr4);
        OutTextXY(10,10 + (textHeight*4), msgStr5);
        OutTextXY(10,10 + (textHeight*5), msgStr6);
        OutTextXY(10,10 + (textHeight*6), msgStr7);

#ifndef USE_BISTABLE_DISPLAY_GOL_AUTO_REFRESH
	#if defined( ONE_CYCLE_DRAWING	) 
		// The screen drawing starts and completes during one while(1) cycle loop in main().
		// This Demo is one cycle drawing application.
        if ( GFX_DRIVER_IsUpdateRequested() || (g_UPDATE_FLAGS == GFX_UPDATE_AS_IT_DRAWS) )
        {
	    	GFX_DRIVER_UpdateEpd( g_UPDATE_FLAGS, 0, 0, GetMaxX(), GetMaxY() ); 
	    	g_UPDATE_FLAGS = GFX_UPDATE_NO_FLASH | GFX_WAIT_IMAGE_DISPLAYED;   
	    }
	#else
		// This way can be used when drawing may take few or more cycles of while(1) loop in main().
		// See "tick.c" file for details.
        if ( g_UpdateNow || (g_UPDATE_FLAGS == GFX_UPDATE_AS_IT_DRAWS) )
        {
	        g_UpdateNow = 0;
	    	GFX_DRIVER_UpdateEpd( g_UPDATE_FLAGS, 0, 0, GetMaxX(), GetMaxY() ); 
	    	g_UPDATE_FLAGS = GFX_UPDATE_NO_FLASH | GFX_WAIT_IMAGE_DISPLAYED;   
	    }	
	#endif
#endif		 
        // Call the external flash programming routine
        ProgramFlash();

        // check if UART is still busy sending replies to the host
        while(U2STAbits.TRMT);
        DelayMs(10);

        // Force Reset to force the checking of the flash memory if programming was a success
        Reset();
    }
}	
/*********************************************************************
* Function:  void TouchCalibration()
*
* PreCondition: InitGraph() must be called before
*
* Input: none
*
* Output: none
*
* Side Effects: none
*
* Overview: calibrates touch screen
*
* Note: none
*
********************************************************************/
void TouchCalibration(){
static const XCHAR scr1StrLn1[] = {'I','M','P','O','R','T','A','N','T','.',0};
static const XCHAR scr1StrLn2[] = {'N','o','w',' ','t','o','u','c','h',' ','s','c','r','e','e','n',' ','c','a','l','i','b','r','a','t','i','o','n',0};
static const XCHAR scr1StrLn3[] = {'w','i','l','l',' ','b','e',' ','p','e','r','f','o','m','e','d','.','T','o','u','c','h',' ','p','o','i','n','t','s',0};
static const XCHAR scr1StrLn4[] = {'E','X','A','C','T','L','Y',' ','a','t',' ','t','h','e',' ','p','o','s','i','t','i','o','n','s',0};
static const XCHAR scr1StrLn5[] = {'s','h','o','w','n',' ','b','y',' ','a','r','r','o','w','s','.',0};
static const XCHAR scr1StrLn6[] = {'T','o','u','c','h',' ','s','c','r','e','e','n',' ','t','o',' ','c','o','n','t','i','n','u','e','.',0};

static const XCHAR scr2StrLn1[] = {'H','o','l','d',' ','S','3',' ','b','u','t','t','o','n',' ','a','n','d',0};
static const XCHAR scr2StrLn2[] = {'p','r','e','s','s',' ','M','C','L','R',' ','r','e','s','e','t','(','S','1',')',0};
static const XCHAR scr2StrLn3[] = {'t','o',' ','R','E','P','E','A','T',' ','t','h','e',' ','c','a','l','i','b','r','a','t','i','o','n',0};
static const XCHAR scr2StrLn4[] = {'p','r','o','c','e','d','u','r','e','.',0};


SHORT counter;
SHORT x,y;
WORD  ax[3],ay[3];

SHORT textHeight;

    SetFont((void*)&GOLFontDefault);
    textHeight = GetTextHeight((void*)&GOLFontDefault);

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);
    OutTextXY(0,0*textHeight, (XCHAR*)scr1StrLn1);
    SetColor(BLACK);
    OutTextXY(0,1*textHeight, (XCHAR*)scr1StrLn2);
    OutTextXY(0,2*textHeight, (XCHAR*)scr1StrLn3);
    OutTextXY(0,3*textHeight, (XCHAR*)scr1StrLn4);
    OutTextXY(0,4*textHeight, (XCHAR*)scr1StrLn5);
    SetColor(BRIGHTRED);
    OutTextXY(0,6*textHeight, (XCHAR*)scr1StrLn6);

    // Wait for touch
    do{
        x=ADCGetX(); y=ADCGetY();
    }while((y==-1)||(x==-1));

    Beep();

    DelayMs(500);

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);

#ifdef SWAP_X_AND_Y

    Line(GetMaxX()-5,5,GetMaxX()-5,15);
    Line(GetMaxX()-4,5,GetMaxX()-4,15);
    Line(GetMaxX()-6,5,GetMaxX()-6,15);

    Line(GetMaxX()-5,5,GetMaxX()-15,5);
    Line(GetMaxX()-5,4,GetMaxX()-15,4);
    Line(GetMaxX()-5,6,GetMaxX()-15,6);

    Line(GetMaxX()-5,6,GetMaxX()-15,16);
    Line(GetMaxX()-5,4,GetMaxX()-15,14);
    Line(GetMaxX()-5,5,GetMaxX()-15,15);

#else

    Line(5,5,5,15);
    Line(4,5,4,15);
    Line(6,5,6,15);

    Line(5,5,15,5);
    Line(5,4,15,4);
    Line(5,6,15,6);

    Line(5,6,15,16);
    Line(5,4,15,14);
    Line(5,5,15,15);

#endif

    TouchGetCalPoints(ax, ay);

#if (GRAPHICS_PICTAIL_VERSION == 1)
    // Get max X and min Y
    _calXMax = 0;
    _calYMin = 0xFFFF;
    for(counter=0; counter<3; counter++){
        if(_calXMax < ax[counter])
            _calXMax = ax[counter];

        if(_calYMin > ay[counter])
            _calYMin = ay[counter];
    }
#elif (GRAPHICS_PICTAIL_VERSION == 2)
    // Get min X and max Y
    _calYMax = 0;
    _calXMin = 0xFFFF;
    for(counter=0; counter<3; counter++){
        if(_calYMax < ay[counter])
            _calYMax = ay[counter];

        if(_calXMin > ax[counter])
            _calXMin = ax[counter];
    }
#endif

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);

#ifdef SWAP_X_AND_Y

    Line(5,5,5,15);
    Line(4,5,4,15);
    Line(6,5,6,15);

    Line(5,5,15,5);
    Line(5,4,15,4);
    Line(5,6,15,6);

    Line(5,6,15,16);
    Line(5,4,15,14);
    Line(5,5,15,15);

#else

    Line(5,GetMaxY()-5,5,GetMaxY()-15);
    Line(4,GetMaxY()-5,4,GetMaxY()-15);
    Line(6,GetMaxY()-5,6,GetMaxY()-15);

    Line(5,GetMaxY()-5,15,GetMaxY()-5);
    Line(5,GetMaxY()-4,15,GetMaxY()-4);
    Line(5,GetMaxY()-6,15,GetMaxY()-6);

    Line(5,GetMaxY()-6,15,GetMaxY()-16);
    Line(5,GetMaxY()-4,15,GetMaxY()-14);
    Line(5,GetMaxY()-5,15,GetMaxY()-15);

#endif

    TouchGetCalPoints(ax, ay);

#if (GRAPHICS_PICTAIL_VERSION == 1)
    // Get max Y
    _calYMax = 0;
    for(counter=0; counter<3; counter++){
        if(_calYMax < ay[counter])
            _calYMax = ay[counter];
    }
#elif (GRAPHICS_PICTAIL_VERSION == 2)
    // Get min Y
    _calYMin = 0xffff;
    for(counter=0; counter<3; counter++){
        if(_calYMin > ay[counter])
            _calYMin = ay[counter];
    }
#endif

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);    


#ifdef SWAP_X_AND_Y

    Line(GetMaxX()/2-5,GetMaxY()-5,GetMaxX()/2-5,GetMaxY()-15);
    Line(GetMaxX()/2-4,GetMaxY()-5,GetMaxX()/2-4,GetMaxY()-15);
    Line(GetMaxX()/2-6,GetMaxY()-5,GetMaxX()/2-6,GetMaxY()-15);

    Line(GetMaxX()/2-5,GetMaxY()-5,GetMaxX()/2-15,GetMaxY()-5);
    Line(GetMaxX()/2-5,GetMaxY()-4,GetMaxX()/2-15,GetMaxY()-4);
    Line(GetMaxX()/2-5,GetMaxY()-6,GetMaxX()/2-15,GetMaxY()-6);

    Line(GetMaxX()/2-5,GetMaxY()-6,GetMaxX()/2-15,GetMaxY()-16);
    Line(GetMaxX()/2-5,GetMaxY()-4,GetMaxX()/2-15,GetMaxY()-14);
    Line(GetMaxX()/2-5,GetMaxY()-5,GetMaxX()/2-15,GetMaxY()-15);

#else

    Line(GetMaxX()-5,GetMaxY()/2-5,GetMaxX()-5,GetMaxY()/2-15);
    Line(GetMaxX()-4,GetMaxY()/2-5,GetMaxX()-4,GetMaxY()/2-15);
    Line(GetMaxX()-6,GetMaxY()/2-5,GetMaxX()-6,GetMaxY()/2-15);

    Line(GetMaxX()-5,GetMaxY()/2-5,GetMaxX()-15,GetMaxY()/2-5);
    Line(GetMaxX()-5,GetMaxY()/2-4,GetMaxX()-15,GetMaxY()/2-4);
    Line(GetMaxX()-5,GetMaxY()/2-6,GetMaxX()-15,GetMaxY()/2-6);

    Line(GetMaxX()-5,GetMaxY()/2-6,GetMaxX()-15,GetMaxY()/2-16);
    Line(GetMaxX()-5,GetMaxY()/2-4,GetMaxX()-15,GetMaxY()/2-14);
    Line(GetMaxX()-5,GetMaxY()/2-5,GetMaxX()-15,GetMaxY()/2-15);

#endif

    TouchGetCalPoints(ax, ay);

#if (GRAPHICS_PICTAIL_VERSION == 1)
    // Get min X
    _calXMin = 0xFFFF;
    for(counter=0; counter<3; counter++){
        if(_calXMin > ax[counter])
            _calXMin = ax[counter];
    }
#elif (GRAPHICS_PICTAIL_VERSION == 2)
    // Get max X
    _calXMax = 0;
    for(counter=0; counter<3; counter++){
        if(_calXMax < ax[counter])
            _calXMax = ax[counter];
    }
#endif


    SetColor(WHITE);
    ClearDevice();

    SetColor(BLACK);
    OutTextXY(10,1*textHeight,(XCHAR*)scr2StrLn1);
    OutTextXY(10,2*textHeight,(XCHAR*)scr2StrLn2);
    OutTextXY(10,3*textHeight,(XCHAR*)scr2StrLn3);
    OutTextXY(10,4*textHeight,(XCHAR*)scr2StrLn4);
    SetColor(BRIGHTRED);
    OutTextXY(10,6*textHeight,(XCHAR*)scr1StrLn6);

    // Wait for touch
    do{
        x=ADCGetX(); y=ADCGetY();
    }while((y==-1)||(x==-1));

    Beep();

    DelayMs(500);

    SetColor(BLACK);
    ClearDevice();

}
Ejemplo n.º 19
0
/////////////////////////////////////////////////////////////////////////////
// Function: WORD CreateAN1227(void)
// Input: None
// Output: Returns non-zero if the objects are created 
//         returns 0 when one of the objects was not created.
// Overview: Creates the AN1227 Demo screen.
/////////////////////////////////////////////////////////////////////////////
WORD CreateAN1227(void)
{

    SetColor(BLACK);
    ClearDevice();

    // HardwareButtonInit() to initialize the hardware buttons
    // should be called prior to the call to this function.
    
    /**
     * Carriage Return button
     * Explorer 16 + GFX PICTail    - S3 (8 bit PMP)
     * Explorer 16 + GFX PICTail    - S5 (16 bit PMP)
     * Starter Kit + GFX PICTail    - S0 (8 bit PMP)
     * Multimedia Expansion Board   - Fire Button
     * DA210 Developement Board     - S1
     * NOTE:    Starter Kit + GFX PICTail will switches are shared
     *          with the 16 bit PMP data bus.
     **/
    previousKey1State = GetHWButtonCR();  // previous state equals the current state
    /**
     * Change Focus button
     * Explorer 16 + GFX PICTail    - S6 (8 bit PMP)
     * Starter Kit + GFX PICTail    - S1 or S2 (8 bit PMP)
     * Multimedia Expansion Board   - left or right
     * DA210 Developement Board     - S2 or S3
     **/
    previousKey2State = GetHWButtonFocus(); // previous state equals the current state

    // create button widgets
    if (!BtnCreate (
        BUTTON1_ID,             // button unique ID
        BTN_X_START, 40,        // left, top corner coordinates
        BTN_X_END, 90,          // right, bottom corner
        0,                      // corner radius is zero, it’s a square button
        BTN_DRAW,               // will be dislayed after creation
        NULL,                   // no bitmap
        (XCHAR*)ReleaseStr,     // text for released state
        NULL                    // default color scheme is used
    ))
        return 0;

    if (!BtnCreate (
        BUTTON2_ID,             // button unique ID
        BTN_X_START, 100,       // left, top corner coordinates
        BTN_X_END, 150,         // right, bottom corner
        0,                      // corner radius is zero, it’s a square button
        BTN_DRAW,               // will be dislayed after creation
        NULL,                   // no bitmap
        (XCHAR*)Button2Str,     // text
        NULL                    // default color scheme is used
    ))
        return 0;

    if (!BtnCreate (
        BUTTON3_ID,             // button unique ID
        BTN_X_START, 160,       // left, top corner coordinates
        BTN_X_END, 210,         // right, bottom corner
        0,                      // corner radius is zero, it’s a square button
        BTN_DRAW |
        BTN_DISABLED,           // will be dislayed and disabled after creation
        NULL,                   // no bitmap
        (XCHAR*)DisabledStr,    // text
        NULL                    // default color scheme is used
    ))
        return 0;

    pFocusedObj = NULL;                 // there are no widgets in focus
    
    return (1);
}       
Ejemplo n.º 20
0
void PerformBoardTest( void )
{
    static int  elapsedSeconds = 0;
    static void *picture;
    
    
    RTCCProcessEvents();

    if (previousSecond != _time_str[11])
    {
        switch ( elapsedSeconds )
        {
            case 0:
                // We will test to see if we are plugged into the PC as a
                // device (on the right side of the board) or if the debugger
                // side is plugged in (on the left side of the board).  If
                // we are plugged in as a device, we will receive SOF tokens,
                // which sets the SOF interrupt.
                picture = &intro;
             
                // Turn on the USB module in device mode.  First, disable all
                // USB interrupts, since we are just doing a local test.  Then
                // enable the module in default device mode and turn on the 
                // power.  We will let the module take care of pulling up the
                // correct lines.  Note that the interrupt flags in U1IR are
                // cleared by writing a "1" to each flag.
                U1IE                    = 0;
                U1IR                    = 0xFF;
                U1CONbits.USBEN         = 1;
                U1PWRCbits.USBPWR       = 1;
            
                // Fall through
                
            case 2:
                GOLFree();
                SetColor( WHITE );
                ClearDevice();          
                break;
            
            case 1:
            case 3:
                GOLFree();
                SetColor( BLACK );
                ClearDevice();          
                break;

            case 4:
                // See if we are plugged into the PC as a device.  If so, we
                // will display a slightly different picture.
                if (U1IRbits.SOFIF)
                {
                    // We are receiving SOF tokens, so we must be plugged 
                    // into a host.
                    picture = &introDevice;
                }

                // Disable and power off the USB module.
                U1CONbits.USBEN         = 1;
                U1PWRCbits.USBPWR       = 0;
                    
                // Display the selected graphic.
                PictCreate(     ID_ICON,                    // ID
                                0,0,GetMaxX(),GetMaxY(),    // dimension
                                PICT_DRAW,                  // will be dislayed, has frame
                                1,                          // scale factor is x1
                                picture,                    // bitmap
                                NULL );                     // default GOL scheme
                break;
                
            case 5:
                RGBTurnOnLED( RGB_SATURATION_MINIMUM, RGB_SATURATION_MINIMUM, RGB_SATURATION_MINIMUM );
                break;

            case 6: 
                // Red
                RGBSetRed( RGB_SATURATION_MAXIMUM );
                break;
                
            case 7:
                // Yellow
                RGBSetGreen( RGB_SATURATION_MAXIMUM );
                break;
                
            case 8:
                // Green
                RGBSetRed( RGB_SATURATION_MINIMUM );
                break;
                
            case 9:
                // Aqua
                RGBSetBlue( RGB_SATURATION_MAXIMUM );
                break;
                
            case 10:
                // Blue
                RGBSetGreen( RGB_SATURATION_MINIMUM );
                break;
                
            case 11:
                // Fuschia            
                RGBSetRed( RGB_SATURATION_MAXIMUM );
                break;
                
            case 12:
                // White
                RGBSetGreen( RGB_SATURATION_MAXIMUM );
                break;
                
            case 13:
                // Pause
                break;
                
            case 14:
                RGBTurnOffLED();
                screenState    = SCREEN_DISPLAY_MAIN;    
                previousSecond = ' ';
                elapsedSeconds = 0;
                return;
                break;
                            
        }
                   
        previousSecond = _time_str[11];
        elapsedSeconds ++;
    }
}
/*********************************************************************
* Function:  void TouchCalibration()
*
* PreCondition: InitGraph() must be called before
*
* Input: none
*
* Output: none
*
* Side Effects: none
*
* Overview: calibrates touch screen
*
* Note: none
*
********************************************************************/
void TouchCalibration(){
static const XCHAR scr1StrLn1[] = {'I','M','P','O','R','T','A','N','T','.',0};
static const XCHAR scr1StrLn2[] = {'N','o','w',' ','t','o','u','c','h',' ','s','c','r','e','e','n',' ','c','a','l','i','b','r','a','t','i','o','n',0};
static const XCHAR scr1StrLn3[] = {'w','i','l','l',' ','b','e',' ','p','e','r','f','o','m','e','d','.','T','o','u','c','h',' ','p','o','i','n','t','s',0};
static const XCHAR scr1StrLn4[] = {'E','X','A','C','T','L','Y',' ','a','t',' ','t','h','e',' ','p','o','s','i','t','i','o','n','s',0};
static const XCHAR scr1StrLn5[] = {'s','h','o','w','n',' ','b','y',' ','a','r','r','o','w','s','.',0};
static const XCHAR scr1StrLn6[] = {'T','o','u','c','h',' ','s','c','r','e','e','n',' ','t','o',' ','c','o','n','t','i','n','u','e','.',0};

static const XCHAR scr2StrLn1[] = {'H','o','l','d',' ','S','3',' ','b','u','t','t','o','n',' ','a','n','d',0};
static const XCHAR scr2StrLn2[] = {'p','r','e','s','s',' ','M','C','L','R',' ','r','e','s','e','t','(','S','1',')',0};
static const XCHAR scr2StrLn3[] = {'t','o',' ','R','E','P','E','A','T',' ','t','h','e',' ','c','a','l','i','b','r','a','t','i','o','n',0};
static const XCHAR scr2StrLn4[] = {'p','r','o','c','e','d','u','r','e','.',0};


SHORT x,y;

SHORT textHeight;

    SetFont((void*)&GOLFontDefault);
    textHeight = GetTextHeight((void*)&GOLFontDefault);

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);
    WAIT_UNTIL_FINISH(OutTextXY(0,0*textHeight, (XCHAR*)scr1StrLn1));
    SetColor(BLACK);
    WAIT_UNTIL_FINISH(OutTextXY(0,1*textHeight, (XCHAR*)scr1StrLn2));
    WAIT_UNTIL_FINISH(OutTextXY(0,2*textHeight, (XCHAR*)scr1StrLn3));
    WAIT_UNTIL_FINISH(OutTextXY(0,3*textHeight, (XCHAR*)scr1StrLn4));
    WAIT_UNTIL_FINISH(OutTextXY(0,4*textHeight, (XCHAR*)scr1StrLn5));
    SetColor(BRIGHTRED);
    WAIT_UNTIL_FINISH(OutTextXY(0,6*textHeight, (XCHAR*)scr1StrLn6));

    // Wait for touch
    do{
        x=ADCGetX(); y=ADCGetY();
    }while((y==-1)||(x==-1));

    Beep();

    DelayMs(500);

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);

#ifdef SWAP_X_AND_Y

    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,5,GetMaxX()-5,15));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-4,5,GetMaxX()-4,15));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-6,5,GetMaxX()-6,15));

    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,5,GetMaxX()-15,5));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,4,GetMaxX()-15,4));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,6,GetMaxX()-15,6));

    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,6,GetMaxX()-15,16));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,4,GetMaxX()-15,14));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,5,GetMaxX()-15,15));

#else

    WAIT_UNTIL_FINISH(Line(5,5,5,15));
    WAIT_UNTIL_FINISH(Line(4,5,4,15));
    WAIT_UNTIL_FINISH(Line(6,5,6,15));

    WAIT_UNTIL_FINISH(Line(5,5,15,5));
    WAIT_UNTIL_FINISH(Line(5,4,15,4));
    WAIT_UNTIL_FINISH(Line(5,6,15,6));

    WAIT_UNTIL_FINISH(Line(5,6,15,16));
    WAIT_UNTIL_FINISH(Line(5,4,15,14));
    WAIT_UNTIL_FINISH(Line(5,5,15,15));

#endif

    _calXMin = 0xFFFF;
    _calXMax = 0;
    _calYMin = 0xFFFF;
    _calYMax = 0;

    TouchGetCalPoints();

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);

#ifdef SWAP_X_AND_Y

    WAIT_UNTIL_FINISH(Line(5,5,5,15));
    WAIT_UNTIL_FINISH(Line(4,5,4,15));
    WAIT_UNTIL_FINISH(Line(6,5,6,15));

    WAIT_UNTIL_FINISH(Line(5,5,15,5));
    WAIT_UNTIL_FINISH(Line(5,4,15,4));
    WAIT_UNTIL_FINISH(Line(5,6,15,6));

    WAIT_UNTIL_FINISH(Line(5,6,15,16));
    WAIT_UNTIL_FINISH(Line(5,4,15,14));
    WAIT_UNTIL_FINISH(Line(5,5,15,15));

#else

    WAIT_UNTIL_FINISH(Line(5,GetMaxY()-5,5,GetMaxY()-15));
    WAIT_UNTIL_FINISH(Line(4,GetMaxY()-5,4,GetMaxY()-15));
    WAIT_UNTIL_FINISH(Line(6,GetMaxY()-5,6,GetMaxY()-15));

    WAIT_UNTIL_FINISH(Line(5,GetMaxY()-5,15,GetMaxY()-5));
    WAIT_UNTIL_FINISH(Line(5,GetMaxY()-4,15,GetMaxY()-4));
    WAIT_UNTIL_FINISH(Line(5,GetMaxY()-6,15,GetMaxY()-6));

    WAIT_UNTIL_FINISH(Line(5,GetMaxY()-6,15,GetMaxY()-16));
    WAIT_UNTIL_FINISH(Line(5,GetMaxY()-4,15,GetMaxY()-14));
    WAIT_UNTIL_FINISH(Line(5,GetMaxY()-5,15,GetMaxY()-15));

#endif

    TouchGetCalPoints();

    SetColor(WHITE);
    ClearDevice();

    SetColor(BRIGHTRED);    


#ifdef SWAP_X_AND_Y

    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-5,GetMaxY()-5,GetMaxX()/2-5,GetMaxY()-15));
    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-4,GetMaxY()-5,GetMaxX()/2-4,GetMaxY()-15));
    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-6,GetMaxY()-5,GetMaxX()/2-6,GetMaxY()-15));

    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-5,GetMaxY()-5,GetMaxX()/2-15,GetMaxY()-5));
    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-5,GetMaxY()-4,GetMaxX()/2-15,GetMaxY()-4));
    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-5,GetMaxY()-6,GetMaxX()/2-15,GetMaxY()-6));

    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-5,GetMaxY()-6,GetMaxX()/2-15,GetMaxY()-16));
    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-5,GetMaxY()-4,GetMaxX()/2-15,GetMaxY()-14));
    WAIT_UNTIL_FINISH(Line(GetMaxX()/2-5,GetMaxY()-5,GetMaxX()/2-15,GetMaxY()-15));

#else

    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,GetMaxY()/2-5,GetMaxX()-5,GetMaxY()/2-15));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-4,GetMaxY()/2-5,GetMaxX()-4,GetMaxY()/2-15));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-6,GetMaxY()/2-5,GetMaxX()-6,GetMaxY()/2-15));

    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,GetMaxY()/2-5,GetMaxX()-15,GetMaxY()/2-5));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,GetMaxY()/2-4,GetMaxX()-15,GetMaxY()/2-4));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,GetMaxY()/2-6,GetMaxX()-15,GetMaxY()/2-6));

    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,GetMaxY()/2-6,GetMaxX()-15,GetMaxY()/2-16));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,GetMaxY()/2-4,GetMaxX()-15,GetMaxY()/2-14));
    WAIT_UNTIL_FINISH(Line(GetMaxX()-5,GetMaxY()/2-5,GetMaxX()-15,GetMaxY()/2-15));

#endif

    TouchGetCalPoints();

    SetColor(WHITE);
    ClearDevice();

    SetColor(BLACK);
    WAIT_UNTIL_FINISH(OutTextXY(10,1*textHeight,(XCHAR*)scr2StrLn1));
    WAIT_UNTIL_FINISH(OutTextXY(10,2*textHeight,(XCHAR*)scr2StrLn2));
    WAIT_UNTIL_FINISH(OutTextXY(10,3*textHeight,(XCHAR*)scr2StrLn3));
    WAIT_UNTIL_FINISH(OutTextXY(10,4*textHeight,(XCHAR*)scr2StrLn4));
    SetColor(BRIGHTRED);
    WAIT_UNTIL_FINISH(OutTextXY(10,6*textHeight,(XCHAR*)scr1StrLn6));

    // Wait for touch
    do{
        x=ADCGetX(); y=ADCGetY();
    }while((y==-1)||(x==-1));

    Beep();

    DelayMs(500);

    SetColor(BLACK);
    ClearDevice();

}
Ejemplo n.º 22
0
/************************************************************************
 Function: WORD JPEGMsgCallback(WORD objMsg, OBJ_HEADER* pObj, 
 								GOL_MSG* pMsg)

 Overview: This function is called by GOLMsg() function when in this 
 		   particular demo each time the valid message is received for the 
  		   objects in the demo.
           
 Input: objMsg - translated message for the object,
        pObj - pointer to the object,
        pMsg - pointer to the non-translated, raw GOL message 

 Output: If the function returns non-zero the message will 
 		 be processed by the object directly affected by the message.
 		 Default action on the object based on the message will be 
 		 performed.
************************************************************************/
WORD JPEGMsgCallback(WORD objMsg, OBJ_HEADER *pObj, GOL_MSG *pMsg)
{
    LISTITEM    *pItemSel;

    // check if an image is being shown
    if((blImageOnScreen == 1) || (blSlideShowOn == 1))
    {

        // this is the routine to go back and show the list when an
        // image is being shown on the screen or the slide show is
        // currently ongoing
        if(pMsg->uiEvent == EVENT_RELEASE)
        {
            blImageOnScreen = 0;
            blSlideShowOn = 0;
            GOLRedrawRec(0, 0, GetMaxX(), GetMaxY());
        }

        return (0);
    }

    switch(GetObjID(pObj))
    {
        case ID_BUTTON_A:
            if(objMsg == BTN_MSG_RELEASED)
            {   // check if button is pressed
                // do not process if user moved the touch away from the button
                // returning 1 wil update the button
                if(pMsg->uiEvent == EVENT_MOVE)
                    return (1);
                screenState = CREATE_DEMOSELECTION;
            }

            return (1);

        case ID_BUTTON_D:
            if(objMsg == BTN_MSG_RELEASED)
            {   // check if button is pressed
                // do not process if user moved the touch away from the button
                // returning 1 wil update the button
                if(pMsg->uiEvent == EVENT_MOVE)
                    return (1);

                // enable the slide show
                blSlideShowOn = 1;
				// initialize the screen	
				SetColor(BLACK);
    			ClearDevice();

                ClrState(pObj, BTN_PRESSED);            // clear the pressed state, will be shown only when redrawn
                blSlideShowDelay = 0;                   // force slide show to immediately start
                return (0);
            }

            return (1);

        case ID_JPGLISTBOX:
            if(pMsg->uiEvent == EVENT_MOVE)
            {
                pMsg->uiEvent = EVENT_PRESS;            // change event for listbox

                // Process message by default
                LbMsgDefault(objMsg, (LISTBOX *)pObj, pMsg);

                // Set new list box position
                SldSetPos(pSlider, LbGetCount(pListBox) - LbGetFocusedItem(pListBox) - 1);
                SetState(pSlider, SLD_DRAW_THUMB);
                pMsg->uiEvent = EVENT_MOVE;             // restore event for listbox
            }
            else if(pMsg->uiEvent == EVENT_PRESS)
            {

                // call the message default processing of the list box to select the item
                LbMsgDefault(objMsg, (LISTBOX *)pObj, pMsg);
            }
            else if(pMsg->uiEvent == EVENT_RELEASE)
            {

                // check which item was selected and display appropriate screen
                pItemSel = LbGetSel(pListBox, NULL);    // get the selected item
                if(aFolderElement[pItemSel->data].blFolder == 1)
                {
                    if(FSchdir(aFolderElement[pItemSel->data].Name) == 0)
                    {
                        FillNewElements();
                        return (1);
                    }
                }
                else if(aFolderElement[pItemSel->data].blText == 0)
                {
                    IMG_FILE    *pImgFile = IMG_FOPEN(aFolderElement[pItemSel->data].Name, "rb");
                    if(pImgFile != NULL)
                    {
                        blImageOnScreen = 1;
                        // initialize the screen	
					    SetColor(BLACK);
    					ClearDevice();

                        if
                        (
                            ImageDecode
                                (
                                    pImgFile,
                                    aFolderElement[pItemSel->data].ImgType,
                                    0,
                                    0,
                                    IMG_SCREEN_WIDTH,
                                    IMG_SCREEN_HEIGHT,
                                    (IMG_DOWN_SCALE | IMG_ALIGN_CENTER),
                                    NULL,
                                    NULL
                                )
                        )
                        {
                            DisplayErrorInfo();
                        }

                        IMG_FCLOSE(pImgFile);
                    }
                }
            }

            // The message was processed. To avoid other objects processing the 
            // processed message reset the message.
            pMsg->uiEvent = EVENT_INVALID;
            return (0);

        case ID_SLD4LB:
        	
        	if((objMsg == SLD_MSG_INC) || (objMsg == SLD_MSG_DEC)) 
            {   // check slider was touched.

	            // Process message by default
	            SldMsgDefault(objMsg, (SLIDER *)pObj, pMsg);
	
	            // Set new list box position
	            if(LbGetFocusedItem(pListBox) != LbGetCount(pListBox) - SldGetPos(pSlider))
	            {
	                LbSetFocusedItem(pListBox, LbGetCount(pListBox) - SldGetPos(pSlider));
	                SetState(pListBox, LB_DRAW_ITEMS);
	            }
	            
	        }

            // The message was processed
            return (0);

        case ID_BTNUP4LB:                               // slider up button was pressed
            if(objMsg == BTN_MSG_RELEASED)
            {
				// check if we have reached the very first then stay there.
	            if (LbGetFocusedItem(pListBox) == 0)
	                LbSetFocusedItem(pListBox,0);
	            else    
                	LbSetFocusedItem(pListBox,LbGetFocusedItem(pListBox)-1);                
                SetState(pListBox, LB_DRAW_ITEMS);
                SldSetPos(pSlider, SldGetPos(pSlider) + 1);
                SetState(pSlider, SLD_DRAW_THUMB);
            }

            return (1);

        case ID_BTNDN4LB:                               // slider down button was pressed
            if(objMsg == BTN_MSG_RELEASED)
            {
	            // set all items to be not displayed
                pItemSel = pListBox->pItemList;
                while(pItemSel != NULL) {
                	pItemSel->status = 0;
                	pItemSel = pItemSel->pNextItem;
                }	
                LbSetFocusedItem(pListBox, LbGetFocusedItem(pListBox) + 1);
                SetState(pListBox, LB_DRAW_ITEMS);
                SldSetPos(pSlider, SldGetPos(pSlider) - 1);
                SetState(pSlider, SLD_DRAW_THUMB);
            }

            return (1);
    }

    return (1);
}
Ejemplo n.º 23
0
/************************************************************************
 Function: CreateCommonObjects()

 Overview: Creates the common objects present in all screens

 Input: none

 Output: none
************************************************************************/
void CreateCommonObjects(void)
{
    WORD timeStartX;
    WORD timeWidth, textHeight;

    SetColor(BACKGROUND_COLOR);
    ClearDevice();

    BtnCreate
    (
        ID_MCHPICON,
        MCHP_LOGO_STARTX, MCHP_LOGO_STARTY,
        MCHP_LOGO_STARTX + (MCHP_LOGO_WIDTH - 5),
        MCHP_LOGO_STARTY + (MCHP_LOGO_HEIGHT - 5),
        0, BTN_DRAW,
        (void *) &MICROCHIP_LOGO, NULL,
        pBatStyleScheme
    );

    PbCreate
    (
        ID_BATLEVEL,
        BAT_STARTX, BAT_STARTY,
        BAT_STARTX + BAT_WIDTH,
        BAT_STARTY + BAT_HEIGHT,
        PB_DRAW | PB_NOPROGRESS,
        GetBatteryLevel(),
        GetBatteryRange(),
        pBatStyleScheme
    );

    // calculate the positions of the date and time info
    strcpy(CurrentTimeStr, "Mon 10:10 AM ");

    timeWidth = GetTextWidth(CurrentTimeStr, (void *)&TIMEDATEFONT);
    textHeight = GetTextHeight((void *)&TIMEDATEFONT);

    timeStartX = BAT_STARTX - timeWidth - 5;

    StCreate
    (
        ID_TIME,
        timeStartX,
        DATE_TIME_STARTY,
        timeStartX + timeWidth,
        DATE_TIME_STARTY + textHeight,
        ST_DRAW,
        CurrentTimeStr,
        pTimeDateStyleScheme
    );

    // This is the battery primitives
    SetColor(TEXTCOLOR_UNPRESSED);
    // draw the outline first
    while(!Bar(	BAT_STARTX - 1, BAT_STARTY - 1,
                BAT_STARTX + BAT_WIDTH + 1, BAT_STARTY + BAT_HEIGHT + 1));
    // draw the battery head
    while(!Bar(	BAT_STARTX - 3, BAT_STARTY + ((BAT_HEIGHT>>1)-1),
                BAT_STARTX - 2, BAT_STARTY + ((BAT_HEIGHT>>1)+1)));

    UpdateTime(FORCE_UPDATE);
}
Ejemplo n.º 24
0
    int main(void)
{
    SHORT       width, height;	// variables to store the height and width of the 16-bit bitmap image
    SHORT       counter;		// loop control variable for each shape that controls how many shapes are printed and their scale
    SHORT  		triangle[] = {160,120,160,120,160,120,160,120};		// triangle polygon points (start triangle in center of LCD)
    
    #if defined(__dsPIC33F__) || defined(__PIC24H__)

    // Configure Oscillator to operate the device at 40Mhz
    // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
    // Fosc= 8M*40(2*2)=80Mhz for 8M input clock
    PLLFBD = 38;                    // M=40
    CLKDIVbits.PLLPOST = 0;         // N1=2
    CLKDIVbits.PLLPRE = 0;          // N2=2
    OSCTUN = 0;                     // Tune FRC oscillator, if FRC is used

    // Disable Watch Dog Timer
    RCONbits.SWDTEN = 0;

    // Clock switching to incorporate PLL
    __builtin_write_OSCCONH(0x03);  // Initiate Clock Switch to Primary

    // Oscillator with PLL (NOSC=0b011)
    __builtin_write_OSCCONL(0x01);  // Start clock switching
    while(OSCCONbits.COSC != 0b011);

    // Wait for Clock switch to occur	
    // Wait for PLL to lock
    while(OSCCONbits.LOCK != 1)
    { };
    #elif defined(__PIC32MX__)
    INTEnableSystemMultiVectoredInt();
    SYSTEMConfigPerformance(GetSystemClock());
    #ifdef MULTI_MEDIA_BOARD_DM00123
    CPLDInitialize();
    CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG);
    CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL);
    #endif
    #endif

    #if defined (PIC24FJ256DA210_DEV_BOARD)
    
    // _ANSG8 = 0; /* S1 */
    // _ANSE9 = 0; /* S2 */
    // _ANSB5 = 0; /* S3 */
        
    #else

    /////////////////////////////////////////////////////////////////////////////
    // ADC Explorer 16 Development Board Errata (work around 2)
    // RB15 should be output
    /////////////////////////////////////////////////////////////////////////////
    LATBbits.LATB15 = 0;
    TRISBbits.TRISB15 = 0;

    #endif

    /////////////////////////////////////////////////////////////////////////////
    #if defined(__dsPIC33FJ128GP804__) || defined(__PIC24HJ128GP504__)
    AD1PCFGL = 0xffff;
    #endif
    InitGraph();

    while(1)
    {
	    /* Display the Kettering Logo bit image with the Welcome to the ECE in the center 
	    /* The image was taken from a JPEG and converted to a 16-bit bitmap in order to meet 
	    /* the display requirement of 16-bits per pixel. This can be done by resaving the
	    /* JPEG as 16-bit bitmap in a image editing program and then converting it using
	    /* the graphics library resource converter. The LCD only supports 4-bit, 8-bit, and
	    /* 16-bits per pixel images 
	    */
	    width = GetImageWidth((void *) &kulogo);
		SetFont((void *) &Font25);
	    WAIT_UNTIL_FINISH(PutImage(45, 20 , (void *) &kulogo,  1)); // image location is relative to the top left corner of the image
        SetColor(WHITE);
        Bar(45, 110, width + 45, 135);	// Draw a bar over the image to place the text over.
        SetColor(BLUE);
        OutTextXY(65, 110, "WELCOME TO THE ECE");
        
        DelayMs(DEMODELAY);	// delay for 1 sec and clear the screen
        SetColor(BLACK);
        ClearDevice();

		/* Display multiple circles, starting at the center and increasing in size at 
        /* each draw until the LCD borders are met. Increasing the counter value will 
        /* expand the shape size more quickly. */
        for(counter = 0; counter < MIN(GetMaxX(), GetMaxY()) >> 1; counter += 14)
        {
	        SetColor(BLACK);	// refresh the screen
	        ClearDevice();	
	        SetColor(BRIGHTRED);
	        SetFont((void *) &Font25);		// draw the name of the shape in the center
	        OutTextXY(135, 110, "Circle");
            WAIT_UNTIL_FINISH(Circle(GetMaxX() >> 1, GetMaxY() >> 1, counter + 5));	// draw the shape
            DelayMs(50);	// display for 50 ms
        }

        DelayMs(DEMODELAY);	// delay for 1 sec and clear the screen
        SetColor(BLACK);
        ClearDevice();

		/* Display multiple rectangles, starting at the center and increasing in size at 
        /* each draw until the LCD borders are met. Increasing the counter value will 
        /* expand the shape size more quickly. */
        for(counter = 0; counter < MIN(GetMaxX() / 2, GetMaxY() / 2) >> 1; counter += 5)
        {	
	        SetColor(BLACK);	// refresh the screen
	        ClearDevice();	
	        SetColor(BRIGHTBLUE);
	        OutTextXY(120, 110, "Rectangle");	// draw the name of the shape in the center
            WAIT_UNTIL_FINISH
            (
                Rectangle
                    (
                        GetMaxX() / 2 - counter * 3 + 6,	// x value of top left corner of rectangle
                        GetMaxY() / 2 - counter * 2 - 8,	// y value of top left corner of rectangle
                        GetMaxX() / 2 + counter * 3 - 6,	// x value of bottom right corner of rectangle
                        GetMaxY() / 2 + counter * 2 + 8     // y value of bottom right corner of rectangle        
                    )
            );
            DelayMs(20); // Display for 20 ms
            
        }

        DelayMs(DEMODELAY); // delay for 1 sec and clear the screen
        SetColor(BLACK);
        ClearDevice();
        
        /* Display multiple triangles, starting at the center and increasing in size at 
        /* each draw until the LCD borders are met. Increasing the counter value will 
        /* expand the shape size more quickly. */
        int i;
		for(counter = 0; counter < MIN(GetMaxX() / 2, GetMaxY() / 2) >> 1; counter += 10)
		{
			SetColor(BLACK);	// refresh the screen
			ClearDevice();
			SetColor(GREEN);	// draw the name of the shape at the center
			OutTextXY(125, 110, "Triangle");
			
			//{160,120,160,120,160,120,160,120} start in center of screen
			triangle[1] = triangle[1] - counter * 2 - 20; 	 // top point y
			triangle[7] = triangle[1];				 		 // top point y (close triangle)
			triangle[2] = triangle[2] - counter * 2 - 58; 	 // left corner point x
			triangle[3] = triangle[3] + counter * 2 + 16;	 // left corner point y
			triangle[4] = triangle[4] + counter * 2 + 58; 	 // right corner point x
			triangle[5] = triangle[5] + counter * 2 + 16;	 // right corner point y
			
			DrawPoly(4, triangle);	// draw the triangle (4 points to enclose it)
			
			// reset each of the triangle points to the center to prevent over expansion
			for (i = 0; i < 8; i++)
				if (i % 2 == 0)
					triangle[i] = 160;
				else
					triangle[i] = 120;
				
			DelayMs(50);	// display for 50 ms
		}
		
       
		DelayMs(DEMODELAY); // delay for 1 sec and clear the screen
    	SetColor(BLACK);
    	ClearDevice();
        
    }
}
Ejemplo n.º 25
0
/***************************************************
* Function 	:    CreatelistTracesScreen
* Parameters 	:    none
* Return 	:    none
* Description	:    Creates GOL widgets used in screen - listTracesScreen
***************************************************/
void CreatelistTracesScreen(void)
{
    GOLFree();
    SetColor(50712);
    ClearDevice();

    if(defscheme != NULL) free(defscheme);

    defscheme = GOLCreateScheme();
    defscheme->Color0 = RGBConvert(72, 140, 248);
    defscheme->Color1 = RGBConvert(248, 184, 72);
    defscheme->TextColor0 = RGBConvert(248, 184, 72);
    defscheme->TextColor1 = RGBConvert(0, 0, 248);
    defscheme->EmbossDkColor = RGBConvert(24, 0, 224);
    defscheme->EmbossLtColor = RGBConvert(168, 216, 232);
    defscheme->TextColorDisabled = RGBConvert(184, 184, 184);
    defscheme->ColorDisabled = RGBConvert(208, 224, 240);
    defscheme->CommonBkColor = RGBConvert(208, 236, 240);
    defscheme->pFont = (void*)&Gentium_Plain_0_0_22;


    if(cardSpyScheme != NULL) free(cardSpyScheme);

    cardSpyScheme = GOLCreateScheme();
    cardSpyScheme->Color0 = RGBConvert(48, 48, 48);
    cardSpyScheme->Color1 = RGBConvert(152, 152, 152);
    cardSpyScheme->TextColor0 = RGBConvert(200, 204, 200);
    cardSpyScheme->TextColor1 = RGBConvert(96, 100, 96);
    cardSpyScheme->EmbossDkColor = RGBConvert(200, 204, 200);
    cardSpyScheme->EmbossLtColor = RGBConvert(200, 204, 200);
    cardSpyScheme->TextColorDisabled = RGBConvert(184, 184, 184);
    cardSpyScheme->ColorDisabled = RGBConvert(200, 204, 248);
    cardSpyScheme->CommonBkColor = RGBConvert(248, 252, 248);
    cardSpyScheme->pFont = (void*)&Ubuntu_Bold_0_0_18;

    WINDOW *plistTracesScreen_listTracesScreen;
    plistTracesScreen_listTracesScreen=WndCreate(listTracesScreen_listTracesScreen,0,0,319,239,24576,NULL, (XCHAR*)listTracesScreen_listTracesScreentext,cardSpyScheme);
    if(plistTracesScreen_listTracesScreen==NULL)
    {
        CreateError(0);
        while(1); //Fatal Error, Check for memory leak or heap size
    }

    LISTBOX *plistTracesScreen_tracesList;
    plistTracesScreen_tracesList=LbCreate(listTracesScreen_tracesList,147,54,302,174,16392,(XCHAR*)listTracesScreen_tracesListtext,cardSpyScheme);
    if(plistTracesScreen_tracesList==NULL)
    {
        CreateError(0);
        while(1); //Fatal Error, Check for memory leak or heap size
    }

    BUTTON *plistTracesScreen_replaceWithBackToHomeButton;
    plistTracesScreen_replaceWithBackToHomeButton=BtnCreate(recordScreen_backToHomeButton ,207,197,319,239,0,16384 , NULL , (XCHAR*)recordScreen_backToHomeButtontext,cardSpyScheme);
    if(plistTracesScreen_replaceWithBackToHomeButton==NULL)
    {
        CreateError(0);
        while(1); //Fatal Error, Check for memory leak or heap size
    }

    BUTTON *plistTracesScreen_viewTraceNumberButton;
    plistTracesScreen_viewTraceNumberButton=BtnCreate(listTracesScreen_viewTraceNumberButton,0,197,112,239,0,16384 , NULL , (XCHAR*)listTracesScreen_viewTraceNumberButtontext,cardSpyScheme);
    if(plistTracesScreen_viewTraceNumberButton==NULL)
    {
        CreateError(0);
        while(1); //Fatal Error, Check for memory leak or heap size
    }

}
Ejemplo n.º 26
0
    bool AudioRenderer::Finish(bool blockUntilEnd, CAMEvent* pFilledEvent)
    {
        DspChunk chunk;

        {
            CAutoLock objectLock(this);
            assert(m_state != State_Stopped);

            // No device - nothing to block on.
            if (!m_device)
                blockUntilEnd = false;

            try
            {
                // Apply dsp chain.
                if (m_device && !m_device->IsBitstream())
                {
                    auto f = [&](DspBase* pDsp)
                    {
                        pDsp->Finish(chunk);
                    };

                    EnumerateProcessors(f);

                    DspChunk::ToFormat(m_device->GetDspFormat(), chunk);
                }
            }
            catch (std::bad_alloc&)
            {
                chunk = DspChunk();
                assert(chunk.IsEmpty());
            }
        }

        auto doBlock = [&]
        {
            // Increase system timer resolution.
            TimePeriodHelper timePeriodHelper(1);

            for (;;)
            {
                REFERENCE_TIME remaining = 0;

                {
                    CAutoLock objectLock(this);

                    if (m_device)
                    {
                        try
                        {
                            remaining = m_device->Finish(pFilledEvent);
                        }
                        catch (HRESULT)
                        {
                            ClearDevice();
                        }
                    }
                }

                // The end of stream is reached.
                if (remaining <= 0)
                    return true;

                // Sleep until predicted end of stream.
                if (m_flush.Wait(std::max(1, (int32_t)(remaining / OneMillisecond))))
                    return false;
            }
        };

        // Send processed sample to the device, and block until the end of stream (if requested).
        return PushToDevice(chunk, pFilledEvent) && (!blockUntilEnd || doBlock());
    }