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

📄 yampp3_usb.c

📁 老外个人做的MP3/优盘。使用ATMEL MEGA系列的MCU
💻 C
📖 第 1 页 / 共 5 页
字号:
				if (usb_play)
					usb_response(0);
				outptr = buffer1;			// play from buffer 1
			}

			fileplayed++;

			// check if we're done
			if (fileplayed >= filesize)
			{
				if (!usb_play)
				{
					isPlaying = 0;			// the end is near 
					if (info_flag == 4)		// if select song menu active
						set_event(EV_PLAY);	// exit the menu and play selected song
					else				// at normal condition
						next_song(0);		// play next song from current playlist
				}
				break;
			}
		}

		if (vol_decrease && (time_flag == 4 || time_flag == 8))	// If fast forward volume downed
		{
			vs1001_setvolume(volume,balance);		// Restore volume
			vol_decrease = 0;
		}

#ifndef GRAPH_LCD

// *****************************************************************************
//			 SCROLLING ON 2 LINES LCD's
// *****************************************************************************

#if (LCD_LINES == 2)

		// scrolling functions
		if ((scroll_time >= SCROLL_SPEED) && (info_flag < 3))
		{
			scroll_time = 0;
			u08 nTemp;

			//
			// scrolling playlist name, artist and song name on 2 lines LCD

			Vlcd_gotoxy(0, 0);
			for (nTemp = 0; nTemp < LCD_LINE_LENGTH; nTemp++)
#ifdef ALTERNATE_SCROLL
				Vlcd_putchar(scroll_line[scroll_pos + nTemp]);

			if (scroll_pos + LCD_LINE_LENGTH == scroll_length)
				scroll_dir -= 2;
			if (scroll_pos == 0)
				scroll_dir++;
			scroll_pos += (signed char)scroll_dir / 4;

#else //ALTERNATE_SCROLL
				Vlcd_putchar(scroll_line[(scroll_pos + nTemp) % scroll_length]);
			scroll_pos++;
#endif //ALTERNATE_SCROLL
		}

#endif //LCD_LINES == 2

// *****************************************************************************
//			 SCROLLING ON 4 LINES LCD's
// *****************************************************************************

#if (LCD_LINES == 4)

		// scrolling functions
		if ((scroll_time >= SCROLL_SPEED) && (info_flag < 3))
		{
			scroll_time = 0;
			u08 nTemp;

			// scrolling artist and name on 4 lines LCD

			if (scroll_length > LCD_LINE_LENGTH)
			{
				Vlcd_gotoxy(0, 1);
				for (nTemp = 0; nTemp <  LCD_LINE_LENGTH; nTemp++)
#ifdef ALTERNATE_SCROLL
					Vlcd_putchar(artistname[scroll_pos + nTemp]);

				if (scroll_pos + LCD_LINE_LENGTH == scroll_length)
					scroll_dir -= 2;

				if (scroll_pos == 0)
					scroll_dir++;

				scroll_pos += (signed char)scroll_dir / 4;

#else //ALTERNATE_SCROLL
					Vlcd_putchar(artistname[(scroll_pos + nTemp) % scroll_length]);

				scroll_pos++;
#endif //ALTERNATE_SCROLL
			}
			if (scroll_length_2 > LCD_LINE_LENGTH)
			{
				Vlcd_gotoxy(0, 2);
				for (nTemp = 0; nTemp < LCD_LINE_LENGTH; nTemp++)
#ifdef ALTERNATE_SCROLL
					Vlcd_putchar(titlename[scroll_pos_2 + nTemp]);

				if (scroll_pos_2 + LCD_LINE_LENGTH == scroll_length_2)
					scroll_dir_2 -= 2;

				if (scroll_pos_2 == 0)
					scroll_dir_2++;

				scroll_pos_2 += (signed char)scroll_dir_2 / 4;

#else //ALTERNATE_SCROLL
					Vlcd_putchar(titlename[(scroll_pos_2 + nTemp) % scroll_length_2]);

				scroll_pos_2++;
#endif //ALTERNATE_SCROLL

			}
		}

#endif //LCD_LINES == 4

// *****************************************************************************
//		 DISPLAY BAR AND TIME ON ALPHANUMERIC LCD's
// *****************************************************************************

		//
		// display bar function
		if ((s08)time_flag >= 5 && !info_flag)
		{
			u08 nSteps = (u08)((fileplayed * (LCD_STEPS-1)) / filesize);
			if(nSteps != OldSteps)					// progressbar need update ?
			{							// this check is for for CPU time saving
#ifdef SATTELITE
				Vlcd_bar(nSteps,LCD_STEPS);
#else
				static u08 data[] = { 0x10, 0x18, 0x1C, 0x1E, 0x1F };
				u08 i;
				u08 a = nSteps / 5;					// # of full bars
				Vlcd_command(0x40);

				lcd_data1f();					// full top line (frame outline)
				for (i = 0; i < 5; i++)				// value for current progress char (0)
				{
					Vlcd_data(data[nSteps % 5] | (a == (LCD_STEPS / 5) - 1));
				}
				lcd_data1f();					// full bottom line (frame outline)
				lcd_data00();					// cursor line

				Vlcd_gotoxy(0,LCD_LINES - 1);
	
				for (i = 0; i < a; i++)
					Vlcd_putchar(1);			// print full bars

				if (a <= (LCD_STEPS / 5) - 1)			// jman to fix display overwrite
				{
					Vlcd_putchar(0);	
					i++;
					for (; i< (LCD_STEPS / 5) - 1; i++)	// display progress bar outline
						Vlcd_putchar(2);	
					if(i < LCD_STEPS / 5)	
						Vlcd_putchar(3);		// end of progressbar
				}

#ifdef UART_PROGRESSBAR
				uart_progputs(PSTR("\r["));			// uart progressbar function
				for (i=0; i < LCD_STEPS - 2; i+=2)
					uart_putchar((i<nSteps) ? '*' : ' ');
				uart_putchar(']');
#endif
#endif // SATTELITE
				OldSteps = nSteps;
			}


			//
			// printing song time 

			u16 wPlayTime = playtime + addtime;
			if(wPlayTime != OldPlayTime)
			{
				OldPlayTime = wPlayTime;
				Vlcd_gotoxy(LCD_LINE_LENGTH - 6, LCD_LINES - 1);	// time display position
#ifdef UART_SONGTIME
				uprintf("%3u:%02u\b\b\b\b\b\b", wPlayTime / 60, wPlayTime % 60); // print time on UART
#endif

				if (timemode == 1)
				{
					wPlayTime = songtime - wPlayTime + 1;	// calculate time remain
					if ((s16)wPlayTime < 0)
						wPlayTime = 0;
				}
				lprintf("%3u:%02u", wPlayTime / 60, wPlayTime % 60); // print time on LCD

				if (timemode == 1)				// add a '-' sign to time remain
				{
					Vlcd_gotoxy(LCD_LINE_LENGTH - 6 + (wPlayTime < 600), LCD_LINES - 1);
					Vlcd_putchar('-');
				}

				if (bLoudness < 128 && vs1001_fw)
					vs1001_write(0x0D,bLoudness);		// Rewrite loudness settings
			}							// if VS1001 do selfreset

			if (menu_event == EV_IDLE && !info_flag)
				time_flag = 0;
		}

#endif // not GRAPH_LCD

// *****************************************************************************
//		 VISUALISATION ON GRAPHIC LCD
// *****************************************************************************

#ifdef GRAPH_LCD

		if ((scroll_time >= SCROLL_SPEED) && (info_flag < 3))
		{
			scroll_time = 0;
#if(LCD_TYPE == 7)
			u08 nTemp;
			if (scroll_length > LCD_LINE_LENGTH)
			{
				Vlcd_gotoxy(0, 1 + 1*(LCD_TYPE==8));
				for (nTemp = 0; nTemp <  LCD_LINE_LENGTH; nTemp++)
 #ifdef ALTERNATE_SCROLL
					Vlcd_putchar(artistname[scroll_pos + nTemp]);

				if (scroll_pos + LCD_LINE_LENGTH == scroll_length)
					scroll_dir -= 2;

				if (scroll_pos == 0)
					scroll_dir++;

				scroll_pos += (signed char)scroll_dir / 4;

 #else //ALTERNATE_SCROLL
					Vlcd_putchar(artistname[(scroll_pos + nTemp) % scroll_length]);

				scroll_pos++;
 #endif //ALTERNATE_SCROLL
			}
			if (scroll_length_2 > LCD_LINE_LENGTH)
			{
				Vlcd_gotoxy(0, 2 + 1*(LCD_TYPE==8));
				for (nTemp = 0; nTemp < LCD_LINE_LENGTH; nTemp++)
 #ifdef ALTERNATE_SCROLL
					Vlcd_putchar(titlename[scroll_pos_2 + nTemp]);

				if (scroll_pos_2 + LCD_LINE_LENGTH == scroll_length_2)
					scroll_dir_2 -= 2;

				if (scroll_pos_2 == 0)
					scroll_dir_2++;

				scroll_pos_2 += (signed char)scroll_dir_2 / 4;

 #else //ALTERNATE_SCROLL
					Vlcd_putchar(titlename[(scroll_pos_2 + nTemp) % scroll_length_2]);

				scroll_pos_2++;
 #endif //ALTERNATE_SCROLL
			}
#endif //(LCD_TYPE == 7)
		}

// *****************************************************************************
//		 DISPLAY BAR AND TIME ON GRAPHIC LCD
// *****************************************************************************

		if ((s08)time_flag >= 5 && info_flag < 3)
		{
#if(LCD_TYPE == 7)
 #define BARLEN (LCD_LINE_LENGTH*6)
#else
 #define BARLEN ((LCD_LINE_LENGTH-6)*6 - 2)
#endif
			u08 nSteps = (u08)((fileplayed * (BARLEN - 1)) / filesize);
			if(nSteps != OldSteps)					// progressbar need update ?
			{							// this check is for for CPU time saving
				Vlcd_gotoxy(0,4 + 1*(LCD_TYPE==8));
				Vlcd_bar(nSteps,BARLEN - 2);

				if(!info_flag)
					status_display();
#ifdef UART_PROGRESSBAR
				register u08 i;
				uart_progputs(PSTR("\r["));			// uart progressbar function
				for (i=0; i < BARLEN - 2; i+=3)
					uart_putchar((i<nSteps) ? '*' : ' ');
				uart_putchar(']');
#endif
				OldSteps = nSteps;
			}

			//
			// printing song time 
			u16 wPlayTime = playtime + addtime;

			if(wPlayTime != OldPlayTime)
			{
				OldPlayTime = wPlayTime;
				Vlcd_gotoxy(LCD_LINE_LENGTH - 6, LCD_LINES - 1);	// time display position
#ifdef UART_SONGTIME
				uprintf("%3u:%02u\b\b\b\b\b\b", wPlayTime / 60, wPlayTime % 60); // print time on UART
#endif

				if (timemode == 1)
				{
					wPlayTime = songtime - wPlayTime + 1;	// calculate time remain
					if ((s16)wPlayTime < 0)
						wPlayTime = 0;
				}
				lprintf("%3u:%02u", wPlayTime / 60, wPlayTime % 60); // print time on LCD

				if (timemode == 1)				// add a '-' sign to time remain
				{
					Vlcd_gotoxy(LCD_LINE_LENGTH - 6 + (wPlayTime < 600), LCD_LINES - 1);
					Vlcd_putchar('-');
				}

				if (bLoudness < 128 && vs1001_fw)
					vs1001_write(0x0D,bLoudness);		// Rewrite loudness settings
			}
									// if VS1001 do selfreset
			if (menu_event == EV_IDLE && !info_flag)
				time_flag = 0;
		}

#endif //GRAPH_LCD 

// ******************************   VISUALIZATION END   *********************************


	}//if (isPlaying)

	if(((s08)time_flag > 30) && (info_flag || menu_event))		// display overvrite timer ends
	{
		info_flag = 0;						// enable status updating
		lcd_frame();						// show progress bar and other data on 4 lines lcd
		menu_event = EV_IDLE;
		if(!isPlaying)
			set_event(EV_STOP);
	}

}

void start_playing(void)
{
	outptr = buffer1;
	isPlaying = 1;
	OldSteps = -1;
	updbuf = 0;
	vs1001_reset(0);
	LoudSet();
#ifdef OLD_VS1001
	wPlayT = 0;
#endif
}


void create_scroll_data(void)
{

#if (LCD_LINES == 2)
	strcat(scroll_line, " -> ");			// playlist name separator
	strcat(scroll_line, artistname);
	strcat(scroll_line, " - ");			// add artist separator
	strcat(scroll_line, titlename);
#ifndef ALTERNATE_SCROLL
	strcat(scroll_line, " >> ");			// add ' >> ' sign
#else
	scroll_dir = 0;
#endif
	scroll_pos = 0;
	scroll_length = 0;				// Calculate scroll length
	u08* src = scroll_line;
	while (*src++)
		scroll_length++;

#else // LCD_LINES == 4
	scroll_length = strlen(artistname);
	scroll_length_2 = strlen(titlename);

#if(LCD_TYPE != 8)
 #ifdef ALTERNATE_SCROLL
	scroll_dir = scroll_dir_2 = 0;
 #else
	if (scroll_length > LCD_LINE_LENGTH)
	{
		strcat(artistname, " >> ");		// add ' >> ' sign
		scroll_length += 4;		
	}
	if (scroll_length_2 > LCD_LINE_LENGTH)
	{
		strcat(titlename, " >> ");		// add ' >> ' sign
		scroll_length_2 += 4;
	}
 #endif // ifdef ALTERNATE_SCROLL

	scroll_pos = scroll_pos_2 = 0;
#endif // (LCD_TYPE != 8)
#endif // LCD_LINES 
}


void play_song(void)
{
	u08 *src;
	udiv_t divt;
	if(!info_flag)
	{
		Vlcd_clrscr();
		Vlcd_progputs(PSTR("Loading..."));
	}

	YADL_PLAY_LIST_ENTRY *pListEntry = get_pl_entry(curPlaylist);
	ListQty = pListEntry->entry_qty;
	if(curIndex >= ListQty)
		curIndex = 0;

	strcpy(scroll_line, pListEntry->name);			// playlist name
	u16 curSong = get_offset_entry(curIndex,curPlaylist);
	YADL_SONG_BASE_ENTRY *pEntry = get_song_entry(curSong);

	if(pEntry->state != YADL_STATE_READY)			// check for valid song entry
	{
		Vlcd_gotoxy(0,0);
		both_progputs(PSTR("\nSongBase Error !"));
		Send_state(STATE_ERROR);
		delayms(1000);
		set_event(EV_STOP);
		return;
	}

	Send_state(STATE_PLAYING);
	strcpy(artistname, pEntry->artist);
	strcpy(titlename, pEntry->title);

	src = titlename + strlen(titlename);
	*src++ = ' ';
	*src++ = '(';
	divt = udiv(pEntry->play_time, 600);
	u08 s = (u08)divt.quot % 10;
	if (s)
		*src++ = '0' + s;				// song time up to 99 min
	divt = udiv(divt.rem, 60);
	*src++ = '0' + (u08)divt.quot;
	*src++ = ':';
	divt = udiv(divt.rem, 10);
	*src++ = '0' + (u08)divt.quot;
	*src++ = '0' + (u08)divt.rem;			
	*src++ = ')';
	*src = 0;

	songtime = pEntry->play_time;				// get playing time of current song
	u16 br = pEntry->bitrate;				// get bitrate
	
	//
	// calc number of VS1001 blocks
	//
	filesize = pEntry->length / 32;				// calculation number of blocks
	fileplayed = 0;
	addtime = 0;						// for search time calculations

	//
	// preload buffers
	//
	init_load_sectors(pEntry->start);
	BackStepPos = 0;					// init cluster tabele counter
	Rev_Table[BackStepPos] = pEntry->start;			// save first cluster number of song to be played
	bitrate = (br & BITRATE_MASK);				// mask OPTIONS in bitrate

#ifdef SONGPOS_RESTORE

	union u32convert FatData;
	if ((curSong = eeprom_rw(EEPROM_STARTPOS)) != 0xffff)	// if eeprom has saved offset from begin of song
	{
		while(curSong--)
		{
			FatData.value = next_fat(MyCluster);	// skip number of clusters saved in EEPROM_STARTPOS
			if(FatData.bytes.byte4 != 0) break;	// protect for bad value in eeprom
			init_load_sectors(FatData.value);	// update cluster value
		}

		eeprom_ww(EEPROM_STARTPOS, 0xffff);		// clear offset in eeprom
	}

	// calculate new size of played data
	fileplayed = BackStepPos * (YADL_CLUSTERSIZE / 32);

	// calculation of playing time
	addtime = (u16)(fileplayed*32 / (bitrate * 125));

⌨️ 快捷键说明

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