コード例 #1
0
ファイル: sd_cmds.c プロジェクト: petegleeson/engg4810-t20
FRESULT writeSampleInfoToFile(char * filename, unsigned short mode, unsigned short loop) {
    FRESULT fresult;
    FIL file;
    char info[10];
    uint16_t bytesWrote = 0, len = 10;

    /* open */

    if ((fresult = f_open(&file, configFile, FA_OPEN_EXISTING | FA_WRITE)) != FR_OK) {
    	DEBUG_PRINT("Error opening file %s\n", StringFromFresult(fresult));
    	return fresult;
    }

    /* write */
    sprintf(info, "%2s %d %d\n", filename, mode, loop);
	fresult = f_write(&file, &info[0], len, &bytesWrote);
	/* check for errors */
	if(fresult != FR_OK) {
		DEBUG_PRINT("An error occurred while writing %s\n", StringFromFresult(fresult));
		return fresult;
	}

	/* close */

    if ((fresult = f_close(&file)) != FR_OK) {
		DEBUG_PRINT("An error occurred while closing %s\n", StringFromFresult(fresult));
    	return fresult;
    }
    return fresult;
}
コード例 #2
0
ファイル: sd_cmds.c プロジェクト: petegleeson/engg4810-t20
FRESULT writeTransferInfoToFile(unsigned short fx1, unsigned short fx2, unsigned short tempo) {
    FRESULT fresult;
    FIL file;
    //char * info = "boo\n";
    char info[10];
    uint16_t bytesWrote = 0, len = 10;

    /* open */

    if ((fresult = f_open(&file, configFile, FA_CREATE_ALWAYS | FA_WRITE)) != FR_OK) {
    	DEBUG_PRINT("Error opening file %s\n", StringFromFresult(fresult));
    	return fresult;
    }

    /* write */
    sprintf(info, "%d %d %d\n", fx1, fx2, tempo);
	fresult = f_write(&file, info, len, &bytesWrote);
	/* check for errors */
	if(fresult != FR_OK) {
		DEBUG_PRINT("An error occurred while writing %s\n", StringFromFresult(fresult));
		return fresult;
	}

	/* close */

    if ((fresult = f_close(&file)) != FR_OK) {
		DEBUG_PRINT("An error occurred while closing %s\n", StringFromFresult(fresult));
    	return fresult;
    }

    return fresult;
}
コード例 #3
0
ファイル: usb_host_msc.c プロジェクト: bli19/unesp_mdt
//*****************************************************************************
//
// The "Up" button widget callback function.
//
// This function is called whenever someone presses the "Up" button.
//
//*****************************************************************************
void
OnBtnUp(tWidget *pWidget)
{
    uint32_t ui32Reason;
    FRESULT fresult;

    //
    // Change up one directory.
    //
    fresult = ChangeToDirectory("..", &ui32Reason);

    if(fresult != FR_OK)
    {
        //
        // Update the status display to show the error.
        //
        PrintfStatus("Error changing directory.");
        PrintfStatus((char *)StringFromFresult(fresult));
    }
    else
    {
        //
        // Update the directory name and the list box contents.
        //
        WidgetPaint((tWidget *)&g_sPWD);
        PopulateFileListBox(true);

        //
        // If we are now in the root directory, hide the "Up" button.
        //
        if((strlen(g_cCwdBuf) == 1) && (g_cCwdBuf[0] == '/'))
        {
            WidgetRemove((tWidget *)&g_sUpBtn);
        }
        else
        {
            WidgetAdd((tWidget *)&g_sUpBackground, (tWidget *)&g_sUpBtn);
        }

        //
        // Disable the CD button since re-populating the list removes the
        // selection.
        //
        WidgetRemove((tWidget *)&g_sCDBtn);

        //
        // Tell the user what happened.
        //
        PrintfStatus("Changed to %s", g_cCwdBuf);

        //
        // Repaint the buttons.
        //
        WidgetPaint((tWidget *)&g_sUpBackground);
        WidgetPaint((tWidget *)&g_sCDBackground);
    }
}
コード例 #4
0
//*****************************************************************************
//
// Frees a font and cleans up once an application has finished using it.
//
// This function releases all resources allocated during a previous call to
// FATFontWrapperLoad().  The caller must not make any further use of the
// font following this call unless another call to FATFontWrapperLoad() is
// made.
//
// \return None.
//
//*****************************************************************************
void FATFontWrapperUnload(uint8_t *pui8FontID)
{
    tFontFile *psFont;
    FRESULT iFResult;

    //
    // Parameter sanity check.
    //
    ASSERT(pui8FontID);

    //
    // Get a pointer to our instance data.
    //
    psFont = (tFontFile *)pui8FontID;

    //
    // Make sure a font is already open.  If not, just return.
    //
    if(!psFont->bInUse)
    {
        return;
    }

    //
    // Close the font file.
    //
    UARTprintf("Unloading font... \n");
    iFResult = f_close(&psFont->sFile);
    if(iFResult != FR_OK)
    {
        UARTprintf("Error %s (%d) from f_close.\n", StringFromFresult(iFResult),
                   iFResult);
    }

    //
    // Clean up our instance data.
    //
    psFont->bInUse = false;
    psFont->ui32CurrentGlyph = 0;
}
コード例 #5
0
ファイル: fatwrapper.c プロジェクト: VENGEL/StellarisWare
//*****************************************************************************
//
// Frees a font and cleans up once an application has finished using it.
//
// This function releases all resources allocated during a previous call to
// FATFontWrapperLoad().  The caller must not make any further use of the
// font following this call unless another call to FATFontWrapperLoad() is
// made.
//
// \return None.
//
//*****************************************************************************
void FATFontWrapperUnload(unsigned char *pucFontId)
{
    tFontFile *pFont;
    FRESULT fresult;

    //
    // Parameter sanity check.
    //
    ASSERT(pucFontId);

    //
    // Get a pointer to our instance data.
    //
    pFont = (tFontFile *)pucFontId;

    //
    // Make sure a font is already open.  If not, just return.
    //
    if(!pFont->bInUse)
    {
        return;
    }

    //
    // Close the font file.
    //
    UARTprintf("Unloading font... \n");
    fresult = f_close(&pFont->sFile);
    if(fresult != FR_OK)
    {
        UARTprintf("Error %s (%d) from f_close.\n", StringFromFresult(fresult),
                   fresult);
    }

    //
    // Clean up our instance data.
    //
    pFont->bInUse = false;
    pFont->ulCurrentGlyph = 0;
}
コード例 #6
0
//*****************************************************************************
//
// Prepares the FAT file system font wrapper for use.
//
// This function must be called before any attempt to use a font stored on the
// FAT file system.  It initializes FATfs for use.
//
// \return Returns \b true on success or \b false on failure.
//
//*****************************************************************************
bool
FATFontWrapperInit(void)
{
    FRESULT iFResult;

    //
    // Mount the file system, using logical disk 0.
    //
    iFResult = f_mount(0, &g_sFatFs);
    if(iFResult != FR_OK)
    {
        //
        // We failed to mount the volume.  Tell the user and return an error.
        //
        UARTprintf("f_mount error: %s (%d)\n", StringFromFresult(iFResult),
                iFResult);
        return(false);
    }

    //
    // All is well so tell the caller.
    //
    return(true);
}
コード例 #7
0
//*****************************************************************************
//
// Prepares a font in the FATfs file system for use by the graphics library.
//
// This function must be called to prepare a font for use by the graphics
// library.  It opens the font file whose name is passed and reads the
// header information.  The value returned should be written into the
// pui8FontID field of the tFontWrapper structure that will be passed to
// graphics library.
//
// This is a very simple (and slow) implementation.  More complex wrappers
// may also initialize a glyph cache here.
//
// \return On success, returns a non-zero pointer identifying the font.  On
// error, zero is returned.
//
//*****************************************************************************
uint8_t *
FATFontWrapperLoad(char *pcFilename)
{
    FRESULT iFResult;
    UINT uiRead, uiToRead;

    UARTprintf("Attempting to load font %s from FAT file system.\n",
               pcFilename);

    //
    // Make sure a font is not already open.
    //
    if(g_sFontFile.bInUse)
    {
        //
        // Oops - someone tried to load a new font without unloading the
        // previous one.
        //
        UARTprintf("Another font is already loaded!\n");
        return(0);
    }

    //
    // Try to open the file whose name we've been given.
    //
    iFResult = f_open(&g_sFontFile.sFile, pcFilename, FA_READ);
    if(iFResult != FR_OK)
    {
        //
        // We can't open the file.  Either the file doesn't exist or there is
        // no SDCard installed.  Regardless, return an error.
        //
        UARTprintf("Error %s (%d) from f_open.\n", StringFromFresult(iFResult),
                   iFResult);
        return(0);
    }

    //
    // We opened the file successfully.  Does it seem to contain a valid
    // font?  Read the header and see.
    //
    iFResult = f_read(&g_sFontFile.sFile, &g_sFontFile.sFontHeader,
                      sizeof(tFontWide), &uiRead);
    if((iFResult == FR_OK) && (uiRead == sizeof(tFontWide)))
    {
        //
        // We read the font header.  Is the format correct? We only support
        // wide fonts via wrappers.
        //
        if((g_sFontFile.sFontHeader.ui8Format != FONT_FMT_WIDE_UNCOMPRESSED) &&
           (g_sFontFile.sFontHeader.ui8Format != FONT_FMT_WIDE_PIXEL_RLE))
        {
            //
            // This is not a supported font format.
            //
            UARTprintf("Unrecognized font format. Failing "
                       "FATFontWrapperLoad.\n");
            f_close(&g_sFontFile.sFile);
            return(0);
        }

        //
        // The format seems to be correct so read as many block headers as we
        // have storage for.
        //
        uiToRead = ((g_sFontFile.sFontHeader.ui16NumBlocks > MAX_FONT_BLOCKS) ?
                    MAX_FONT_BLOCKS * sizeof(tFontBlock) :
                    (g_sFontFile.sFontHeader.ui16NumBlocks *
                     sizeof(tFontBlock)));

        iFResult = f_read(&g_sFontFile.sFile, &g_sFontFile.psBlocks, uiToRead,
                          &uiRead);
        if((iFResult == FR_OK) && (uiRead == uiToRead))
        {
            //
            // All is well.  Tell the caller the font was opened successfully.
            //
            UARTprintf("Font %s opened successfully.\n", pcFilename);
            g_sFontFile.bInUse = true;
            return((uint8_t *)&g_sFontFile);
        }
        else
        {
            UARTprintf("Error %s (%d) reading block headers. Read %d, exp %d "
                       "bytes.\n", StringFromFresult(iFResult), iFResult,
                       uiRead, uiToRead);
            f_close(&g_sFontFile.sFile);
            return(0);
        }
    }
    else
    {
        //
        // We received an error while reading the file header so fail the call.
        //
        UARTprintf("Error %s (%d) reading font header.\n",
                   StringFromFresult(iFResult), iFResult);
        f_close(&g_sFontFile.sFile);
        return(0);
    }
}
コード例 #8
0
//
// Main - It performs initialization, then runs a command processing loop to
//        read commands from the console.
//
int
main(void)
{
    int nStatus;
    FRESULT fresult;

    //
    // Set the clocking to run from the PLL at 50MHz
    //
    SysCtlClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(10) |
                   SYSCTL_SYSDIV(2));
    SysCtlAuxClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE |
                      SYSCTL_IMULT(12) | SYSCTL_SYSDIV(2));        //60 MHz

#ifdef _FLASH
//
// Copy time critical code and Flash setup code to RAM
// This includes the following functions:  InitFlash_Bank0();
// The  RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart
// symbols are created by the linker. Refer to the device .cmd file.
//
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);

//
// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
//
    InitFlash_Bank0();
#endif

    //
    // Initialize interrupt controller and vector table
    //
    InitPieCtrl();
    InitPieVectTable();

    //
    // Set the system tick to fire 100 times per second.
    //
    SysTickInit();
    SysTickPeriodSet(SysCtlClockGet(SYSTEM_CLOCK_SPEED) / 100);
    SysTickIntRegister(SysTickHandler);
    SysTickIntEnable();
    SysTickEnable();

    //
    // Enable Interrupts
    //
    IntMasterEnable();

    //
    // Configure UART0 for debug output.
    //
    ConfigureUART();

    //
    // Print hello message to user.
    //
    UARTprintf("\n\nSD Card Example Program\n");
    UARTprintf("Type \'help\' for help.\n");

    //
    // Mount the file system, using logical disk 0.
    //
    fresult = f_mount(0, &g_sFatFs);
    if(fresult != FR_OK)
    {
        UARTprintf("f_mount error: %s\n", StringFromFresult(fresult));
        return(1);
    }

    //
    // Enter an (almost) infinite loop for reading and processing commands from
    // the user.
    //
    while(1)
    {
        //
        // Print a prompt to the console.  Show the CWD.
        //
        UARTprintf("\n%s> ", g_cCwdBuf);

        //
        // Get a line of text from the user.
        //
        UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        nStatus = CmdLineProcess(g_cCmdBuf);

        //
        // Handle the case of bad command.
        //
        if(nStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("Bad command!\n");
        }
        //
        // Handle the case of too many arguments.
        //
        else if(nStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("Too many arguments for command processor!\n");
        }

        //
        // Otherwise the command was executed.  Print the error
        // code if one was returned.
        //
        else if(nStatus != 0)
        {
            UARTprintf("Command returned error code %s\n",
                       StringFromFresult((FRESULT)nStatus));
        }
    }
}
コード例 #9
0
ファイル: usb_host_hub.c プロジェクト: AlexGeControl/tiva-c
//*****************************************************************************
//
// The main application loop.
//
//*****************************************************************************
int
main(void)
{
    int32_t i32Status, i32Idx;
    uint32_t ui32SysClock, ui32PLLRate;
#ifdef USE_ULPI
    uint32_t ui32Setting;
#endif

    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Set the part pin out appropriately for this device.
    //
    PinoutSet();

#ifdef USE_ULPI
    //
    // Switch the USB ULPI Pins over.
    //
    USBULPIPinoutSet();

    //
    // Enable USB ULPI with high speed support.
    //
    ui32Setting = USBLIB_FEATURE_ULPI_HS;
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting);

    //
    // Setting the PLL frequency to zero tells the USB library to use the
    // external USB clock.
    //
    ui32PLLRate = 0;
#else
    //
    // Save the PLL rate used by this application.
    //
    ui32PLLRate = 480000000;
#endif

    //
    // Initialize the hub port status.
    //
    for(i32Idx = 0; i32Idx < NUM_HUB_STATUS; i32Idx++)
    {
        g_psHubStatus[i32Idx].bConnected = false;
    }

    //
    // Enable Clocking to the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Initialize the USB stack mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeHost, 0);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Open the Keyboard interface.
    //
    KeyboardOpen();
    MSCOpen(ui32SysClock);

    //
    // Open a hub instance and provide it with the memory required to hold
    // configuration descriptors for each attached device.
    //
    USBHHubOpen(HubCallback);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Tell the USB library the CPU clock and the PLL frequency.
    //
    USBOTGFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock);
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Initialize the USB controller for Host mode.
    //
    USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool));

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "usb-host-hub");

    //
    // Calculate the number of characters that will fit on a line.
    // Make sure to leave a small border for the text box.
    //
    g_ui32CharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 16) /
                         GrFontMaxWidthGet(g_psFontFixed6x8);

    //
    // Calculate the number of lines per usable text screen.  This requires
    // taking off space for the top and bottom banners and adding a small bit
    // for a border.
    //
    g_ui32LinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                           (2*(DISPLAY_BANNER_HEIGHT + 1)))/
                           GrFontHeightGet(g_psFontFixed6x8);

    //
    // Initial update of the screen.
    //
    UpdateStatus(0);
    UpdateStatus(1);
    UpdateStatus(2);
    UpdateStatus(3);

    g_ui32CmdIdx = 0;
    g_ui32CurrentLine = 0;

    //
    // Initialize the file system.
    //
    FileInit();

    //
    // The main loop for the application.
    //
    while(1)
    {
        //
        // Print a prompt to the console.  Show the CWD.
        //
        WriteString("> ");

        //
        // Is there a command waiting to be processed?
        //
        while((g_ui32Flags & FLAG_CMD_READY) == 0)
        {
            //
            // Call the YSB library to let non-interrupt code run.
            //
            USBHCDMain();

            //
            // Call the keyboard and mass storage main routines.
            //
            KeyboardMain();
            MSCMain();
        }

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32Status = CmdLineProcess(g_pcCmdBuf);

        //
        // Handle the case of bad command.
        //
        if(i32Status == CMDLINE_BAD_CMD)
        {
            WriteString("Bad command!\n");
        }
        //
        // Handle the case of too many arguments.
        //
        else if(i32Status == CMDLINE_TOO_MANY_ARGS)
        {
            WriteString("Too many arguments for command processor!\n");
        }
        //
        // Otherwise the command was executed.  Print the error
        // code if one was returned.
        //
        else if(i32Status != 0)
        {
            WriteString("Command returned error code\n");
            WriteString((char *)StringFromFresult((FRESULT)i32Status));
            WriteString("\n");
        }

        //
        // Reset the command flag and the command index.
        //
        g_ui32Flags &= ~FLAG_CMD_READY;
        g_ui32CmdIdx = 0;
    }
}
コード例 #10
0
//*****************************************************************************
//
// This function is called to read the contents of the current directory from
// the USB stick and populate a set of menu items, one for each file in the
// directory.  A subdirectory within the directory counts as a file item.
//
// This function returns the number of file items that were found, or 0 if
// there is any error detected.
//
//*****************************************************************************
static uint32_t
PopulateFileList(uint32_t ui32Level)
{
    uint32_t ui32ItemCount;
    FRESULT fresult;

    //
    // Open the current directory for access.
    //
    fresult = f_opendir(&g_sDirObject, g_pcCwdBuf);

    //
    // Check for error and return if there is a problem.
    //
    if(fresult != FR_OK)
    {
        //
        // Ensure that the error is reported.
        //
        g_pcStatusLines[0] = "Error from";
        g_pcStatusLines[1] = "USB disk";
        g_pcStatusLines[2] = (char *)StringFromFresult(fresult);
        ShowStatusScreen(g_pcStatusLines, 3);
        return(0);
    }

    //
    // Initialize the count of files in this directory
    //
    ui32ItemCount = 0;

    //
    // Enter loop to enumerate through all directory entries.
    //
    for(;;)
    {
        //
        // Read an entry from the directory.
        //
        fresult = f_readdir(&g_sDirObject, &g_sFileInfo);

        //
        // Check for error and return if there is a problem.
        //
        if(fresult != FR_OK)
        {
            g_pcStatusLines[0] = "Error from";
            g_pcStatusLines[1] = "USB disk";
            g_pcStatusLines[2] = (char *)StringFromFresult(fresult);
            ShowStatusScreen(g_pcStatusLines, 3);
            return(0);
        }

        //
        // If the file name is blank, then this is the end of the
        // listing.
        //
        if(!g_sFileInfo.fname[0])
        {
            break;
        }

        //
        // Add the information to a menu item
        //
        if(ui32ItemCount < MAX_FILES_PER_MENU)
        {
            tSlideMenuItem *pMenuItem;

            //
            // Get a pointer to the current menu item.  Use the directory
            // level to determine which of the two sets of menu items to use.
            // (ui32Level & 1].  This lets us alternate between the current
            // set of menu items and the new set (up or down the tree).
            //
            pMenuItem = &g_psFileMenuItems[ui32Level & 1][ui32ItemCount];

            //
            // Add the file name to the menu item
            //
            usnprintf(g_pcFileNames[ui32Level & 1][ui32ItemCount],
                      MAX_FILENAME_STRING_LEN, "%s", g_sFileInfo.fname);
            pMenuItem->pcText = g_pcFileNames[ui32Level & 1][ui32ItemCount];

            //
            // If this is a directory, then add the next level menu so that
            // when displayed it will be showed with a submenu option
            // (next level down in directory tree).  Otherwise it is a file
            // so clear the child menu so that there is no submenu option
            // shown.
            //
            pMenuItem->psChildMenu = (g_sFileInfo.fattrib & AM_DIR) ?
                                    &g_psFileMenus[ui32Level + 1] : 0;

            //
            // Move to the next entry in the item array we use to populate the
            // list box.
            //
            ui32ItemCount++;
        }
    }

    //
    // Made it to here, return the count of files that were populated.
    //
    return(ui32ItemCount);
}
コード例 #11
0
ファイル: usb_host_msc.c プロジェクト: bli19/unesp_mdt
//*****************************************************************************
//
// This function is called to read the contents of the current directory on
// the SD card and fill the listbox containing the names of all files and
// directories.
//
//*****************************************************************************
static int
PopulateFileListBox(bool bRepaint)
{
    uint32_t ui32ItemCount;
    FRESULT fresult;

    //
    // Empty the list box on the display.
    //
    ListBoxClear(&g_sDirList);

    //
    // Make sure the list box will be redrawn next time the message queue
    // is processed.
    //
    if(bRepaint)
    {
        WidgetPaint((tWidget *)&g_sDirList);
    }

    //
    // Open the current directory for access.
    //
    fresult = f_opendir(&g_sDirObject, g_cCwdBuf);

    //
    // Check for error and return if there is a problem.
    //
    if(fresult != FR_OK)
    {
        //
        // Ensure that the error is reported.
        //
        PrintfStatus("Error from USB disk:");
        PrintfStatus((char *)StringFromFresult(fresult));
        return(fresult);
    }

    ui32ItemCount = 0;

    //
    // Enter loop to enumerate through all directory entries.
    //
    for(;;)
    {
        //
        // Read an entry from the directory.
        //
        fresult = f_readdir(&g_sDirObject, &g_sFileInfo);

        //
        // Check for error and return if there is a problem.
        //
        if(fresult != FR_OK)
        {
            PrintfStatus("Error from USB disk:");
            PrintfStatus((char *)StringFromFresult(fresult));
            return(fresult);
        }

        //
        // If the file name is blank, then this is the end of the
        // listing.
        //
        if(!g_sFileInfo.fname[0])
        {
            break;
        }

        //
        // Add the information as a line in the listbox widget.
        //
        if(ui32ItemCount < NUM_LIST_STRINGS)
        {
            usnprintf(g_pcFilenames[ui32ItemCount], MAX_FILENAME_STRING_LEN,
                      "(%c) %s", (g_sFileInfo.fattrib & AM_DIR) ? 'D' : 'F',
                      g_sFileInfo.fname);
            ListBoxTextAdd(&g_sDirList, g_pcFilenames[ui32ItemCount]);
        }

        //
        // Move to the next entry in the item array we use to populate the
        // list box.
        //
        ui32ItemCount++;
    }

    //
    // Made it to here, return with no errors.
    //
    return(0);
}
コード例 #12
0
ファイル: usb_host_msc.c プロジェクト: bli19/unesp_mdt
//*****************************************************************************
//
// The "CD" button widget callback function.
//
// This function is called whenever someone presses the "CD" button.
//
//*****************************************************************************
void
OnBtnCD(tWidget *pWidget)
{
    int16_t i16Selected;
    uint32_t ui32Reason;
    FRESULT fresult;
    //
    // Get the current selection from the list box.
    //
    i16Selected = ListBoxSelectionGet(&g_sDirList);

    //
    // Is there any selection?
    //
    if(i16Selected == -1)
    {
        return;
    }
    else
    {
        //
        // Is the selection a directory name?
        //
        if(g_pcFilenames[i16Selected][1] == 'D')
        {
            //
            // Yes - change to the new directory.
            //
            fresult = ChangeToDirectory(&g_pcFilenames[i16Selected][4],
                                        &ui32Reason);

            if(fresult != FR_OK)
            {
                //
                // Update the status display to show the error.
                //
                PrintfStatus("Error changing directory.");
                PrintfStatus((char *)StringFromFresult(fresult));
            }
            else
            {
                //
                // Tell the user what happened.
                //
                PrintfStatus("Changed to %s", g_cCwdBuf);

                //
                // Update the directory name and the list box contents.
                //
                PopulateFileListBox(true);
                WidgetPaint((tWidget *)&g_sPWD);

                //
                // Enable the "Up" button and disable the "CD" button.
                //
                WidgetAdd((tWidget *)&g_sUpBackground, (tWidget *)&g_sUpBtn);
                WidgetRemove((tWidget *)&g_sCDBtn);

                //
                // Make sure the buttons are repainted correctly.
                //
                WidgetPaint((tWidget *)&g_sUpBtn);
                WidgetPaint((tWidget *)&g_sCDBackground);
            }
        }
    }
}