⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp3pc.c

📁 Frank s MP3 Player Source Files
💻 C
📖 第 1 页 / 共 4 页
字号:
	default:
		// Nothing good already; we might have to do some work (padding with spaces)
		// Does filename end on this line? Number of filename characters = 96 - freespace. Return if it does.
		if ( (96 - freespace) < 25) return;
		// Is this the last character of a word? Check what the next character is; break if we're at word end
		if ((FINDFILE_RET_NAME[25]==' ')||(FINDFILE_RET_NAME[25]=='-')||(FINDFILE_RET_NAME[25]=='.')) break;
		// how far back is a space, hyphen or period?
		backcount = 1;											// it's at least 1 character back
		while (backcount < 24) {
			if (FINDFILE_RET_NAME[24-backcount] == ' ') break;	// break if we found a space
			if (FINDFILE_RET_NAME[24-backcount] == '-') break;	// break if we found a hyphen
			if (FINDFILE_RET_NAME[24-backcount] == '.') {
				backcount++;									// break if we found a period
				break;											// but add 1 because we want period on next line
			}
			backcount++;
		}													
		if (backcount > 22) break;								// if too far back then don't bother
		if (backcount > freespace) break;						// if insufficient free space then don't bother
		// otherwise we're able to pad with spaces
		freespace = freespace - backcount;
		tempptr = (u08*)&FINDFILE_RET_NAME[25-backcount];		// point to where we want to insert the spaces
		while (backcount) {										// insert the spaces
			InsertCharInString(tempptr, ' ');
			backcount--;
		}
		break;
	} // end switch
	} // end if (freespace)
	
	
	// PROCESS THE SECOND LINE  (characters 25 - 48)
	
	// Remove any spaces at the beginning of the line
	while (FINDFILE_RET_NAME[25] == ' ') {					// if first char is a space...
		DeleteCharFromString((u08*)&FINDFILE_RET_NAME[25]);	//   then remove it
		freespace++;										//   and we now have an extra place free in the string
	}

	// Now deal with the end of the line. This switch statement only inserts spaces, so don't bother even
	// executing it if there's no free space in the string buffer.
	if (freespace) {
	switch (FINDFILE_RET_NAME[48]) {
	case ' ': case '-':									// space or hyphen at end of line is good
		break;											
	case '.':											// if period at end of line, move it to the next line
		InsertCharInString((u08*)&FINDFILE_RET_NAME[48], ' ');
		freespace--;
		break;
	default:
		// Nothing good already; we might have to do some work (padding with spaces)
		// Does filename end on this line? Number of filename characters = 96 - freespace. Return if it does.
		if ( (96 - freespace) < 49) return;
		// Is this the last character of a word? Check what the next character is; break if we're at word end
		if ((FINDFILE_RET_NAME[49]==' ')||(FINDFILE_RET_NAME[49]=='-')||(FINDFILE_RET_NAME[49]=='.')) break;

		// how far back is a space, hyphen or period?
		backcount = 1;											// it's at least 1 character back
		while (backcount < 24) {
			if (FINDFILE_RET_NAME[48-backcount] == ' ') break;	// break if we found a space
			if (FINDFILE_RET_NAME[48-backcount] == '-') break;	// break if we found a hyphen
			if (FINDFILE_RET_NAME[48-backcount] == '.') {
				backcount++;									// break if we found a period
				break;											// but add 1 because we want period on next line
			}
			backcount++;
		}													
		if (backcount > 22) break;								// if too far back then don't bother
		if (backcount > freespace) break;						// if insufficient free space then don't bother
		// otherwise we're able to pad with spaces
		freespace = freespace - backcount;
		tempptr = (u08*)&FINDFILE_RET_NAME[49-backcount];		// point to where we want to insert the spaces
		while (backcount) {										// insert the spaces
			InsertCharInString(tempptr, ' ');
			backcount--;
		}
		break;
	} // end switch
	} // end if (freespace)
	
	
	// PROCESS THE THIRD LINE  (characters 49 - 72)
	
	// Remove any spaces at the beginning of the line
	while (FINDFILE_RET_NAME[49] == ' ') {					// if first char is a space...
		DeleteCharFromString((u08*)&FINDFILE_RET_NAME[49]);	//   then remove it
		freespace++;										//   and we now have an extra place free in the string
	}

	// Now deal with the end of the line. This switch statement only inserts spaces, so don't bother even
	// executing it if there's no free space in the string buffer.
	if (freespace) {
	switch (FINDFILE_RET_NAME[72]) {
	case ' ': case '-':									// space or hyphen at end of line is good
		break;											
	case '.':											// if period at end of line, move it to the next line
		InsertCharInString((u08*)&FINDFILE_RET_NAME[72], ' ');
		freespace--;
		break;
	default:
		// Nothing good already; we might have to do some work (padding with spaces)
		// Does filename end on this line? Number of filename characters = 96 - freespace. Return if it does.
		if ( (96 - freespace) < 73) return;
		// Is this the last character of a word? Check what the next character is; break if we're at word end
		if ((FINDFILE_RET_NAME[73]==' ')||(FINDFILE_RET_NAME[73]=='-')||(FINDFILE_RET_NAME[73]=='.')) break;

		// how far back is a space, hyphen or period?
		backcount = 1;											// it's at least 1 character back
		while (backcount < 24) {
			if (FINDFILE_RET_NAME[72-backcount] == ' ') break;	// break if we found a space
			if (FINDFILE_RET_NAME[72-backcount] == '-') break;	// break if we found a hyphen
			if (FINDFILE_RET_NAME[72-backcount] == '.') {
				backcount++;									// break if we found a period
				break;											// but add 1 because we want period on next line
			}
			backcount++;
		}													
		if (backcount > 22) break;								// if too far back then don't bother
		if (backcount > freespace) break;						// if insufficient free space then don't bother
		// otherwise we're able to pad with spaces
		freespace = freespace - backcount;
		tempptr = (u08*)&FINDFILE_RET_NAME[73-backcount];		// point to where we want to insert the spaces
		while (backcount) {										// insert the spaces
			InsertCharInString(tempptr, ' ');
			backcount--;
		}
		break;
	} // end switch
	} // end if (freespace)

	
	// PROCESS THE FOURTH LINE  (characters 73 - 96)
	// only thing we can do is remove leading spaces, as this is the last line.
	
	// Remove any spaces at the beginning of the line
	while (FINDFILE_RET_NAME[73] == ' ') {					// if first char is a space...
		DeleteCharFromString((u08*)&FINDFILE_RET_NAME[73]);	//   then remove it
		freespace++;										//   and we now have an extra place free in the string
	}

}






void InsertCharInString(u08 *location, u08 character)
// This routine inserts the provided character into a string, in the location
// pointed to by location. It functions by shifting all the characters in the
// string after & including "location" to the right, thereby leaving a space
// in the string that it inserts character. The null is also shifted to the right.
// It is the responsibility of the calling routine to ensure that doing this does
// not overflow the string buffer.
{

	u08		*tempptr;
	
	tempptr = location;
	
	// find the null indicating the end of the string
	while (*tempptr) tempptr++;
	
	// tempptr now pointing to the null. Move the null to the right & work backwards
	// through the string, moving chars to the right, until tempptr back to location
	while (tempptr != location) {
		*(tempptr+1) = *tempptr;
		tempptr--;
	}
	
	// tempptr now pointing to location
	// now we move the character in location to the right
	*(tempptr+1) = *tempptr;
	
	// now put character in location and we're finished
	*tempptr = character;
}



void DeleteCharFromString(u08 *location)
// The mate of the routine above, this function deletes the character in the string, from
// the location pointed to by location, and shifts the rest of the string to the left
// to fill the gap where the character used to be, including shifting the null at the
// end of the string. The end result of this is the string will have two nulls at its end.
{
	while (*location) {
		*location = *(location+1);
		location++;
	}
}




/****************************************************************************************
    
    CycleStepSize

    This routine "automatically" changes the value of the global variable StepSize.
    For a user perspective, holding down the NEXT button for an extended period causes
    StepSize to scroll through different values on the LCD display. Releasing the
    NEXT button results in StepSize changing to the value that was on-screen at that time.

    The possible values of StepSize are: 1-10-50-100-500-1000.  Also, the value 
    of StepSize must be less than the number of tracks in the current directory.

    This function only works if random mode is not enabled. If random mode is enabled
    then the value of StepSize is determined by the random variables, not by the user.

    This function works by keeping track of time since the NEXT button was depressed.
    Every 1000 ms it changes the value of stepsize. It rolls-over StepSize back to 1
    when it reaches the max value (1000). The variable StepSizeStartTime remembers the
    time; it is set to the current time when NEXT is first depressed (by the pushbutton
    UART 0 interrupt service routine) and then is periodically updated by this routine.
    
    This routine never really knows per-se when NEXT is released; it simply stops
    being called. This routine is called by HandleButtons repeatedly as long as the
    NEXT button remains depressed. Once NEXT is released HandleButtons no longer calls
    this routine, so whatever was the last set value of StepSize becomes the value
    that remains.
                     
****************************************************************************************/
void CycleStepSize (void)
{
   	u16		NumFiles;


    // Stop playing the current track (mute codec, stop reading track off drive, stop PlayControl state machine)
	MuteSTcodec();							        // quiet down the audio
	STREAMFILE_CMD = StreamFile_Cmd_Stop;			/* stop reading data off the drive */
	PC_Command = PC_Cmd_Pause;						/* tell PlayControl to stop doing anything for the moment */


    // If random mode switched on then just exit.
    if (PC_Flag_Mode)
        return;

    // Determine if enough time (1000 ms) has elapsed; exit if not
    if ( (Tick100ms-StepSizeStartTime) != 10 )
        return;

    // Execute here if sufficient time has elapsed; change StepSize value
    // and display it on the LCD
    StepSizeStartTime = Tick100ms;          // remember time so we'll know when next 1000ms expired

    switch (StepSize) {                     // change value of StepSize
	    case 1:
            StepSize=10;
            break;
        case 10:
            StepSize=50;
            break;
        case 50:
            StepSize=100;
            break;
        case 100:
            StepSize=500;
            break;
        case 500:
            StepSize=1000;
            break;
        default:
            StepSize=1;
            break;
    }

    // Insure new StepSize value is less than the number of tracks in the current directory
	NumFiles = (((u16)EEPROM_ReadC(StoreNumFilesH))<<8) + (u16)EEPROM_ReadC(StoreNumFilesL);
    if (StepSize >= NumFiles)
        StepSize = 1;

    // Display new StepSize on the LCD
    ClearLCDlines(3,4);                     // clear the 3rd-6th lines on the LCD display
    PositionLCDcursor(4,1);                 // put cursor at start of 4th line
    uart1_putwaitPROGstr(PSTR("Song Step = "));
    PrintASCIIword(StepSize, 1);            // Display new value of StepSize
}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -