📄 display.c
字号:
#include <string.h>#include "printf.h"#include "as31glue.h"#include "parse.h" // for event codes#include "stricmp.h"#include "sta013.h"#include "main.h"#include "rand.h"#include "treedir.h"#include "display.h"#define VOL_TIMEOUT 50#define SCREEN_TIMEOUT 80typedef enum { MAINSCREEN, AUDIOSCREEN, TREEDIRSCREEN, EPARAMSCREEN, SCREEN_MAX = 3} screen_t;typedef enum { CONTROL0, CONTROL1, CONTROL2, CONTROL3, CONTROL4, CONTROL5, CONTROL6, CONTROL7, CONTROL8, CONTROL9, CONTROL_MAX = 9} control_t;static code unsigned char play_mode_description[MODE_MAX+1][11] = { " Dir Only ", " Dir Rand ", " Seqntial ", " Plst Rand", " All Rand "};#define DISPLAY_WIDTH 24#define FILEBUF_MAX 256#define PLAYBUF_MAX 256simm_id current_filename;simm_id current_playlistname;xdata unsigned char fxwrap; // Position inside filebufxdata unsigned char fxscroll; // Scroll ?xdata unsigned char filebuf[FILEBUF_MAX];xdata unsigned char fdisplaybuf[DISPLAY_WIDTH + 1];xdata unsigned char filebuf_len;xdata unsigned char pxwrap; // Position inside playbufstatic bit pxscroll; // Scroll ?xdata unsigned char playbuf[PLAYBUF_MAX];xdata unsigned char pdisplaybuf[DISPLAY_WIDTH + 1];xdata unsigned char playbuf_len;xdata struct id3_tag_struct id3_tag;// TODO: Remove this once display bug is fixedxdata update_counter;screen_t current_screen;control_t current_control;// display versionxdata unsigned char lcd_version;#define LCD_VERSION_BETA 0x6A#define LCD_VERSION_1 0x82//--------------------------------------------------------------------// lcd_update_2nd_line//// Called when timer 0 expires.// Displays fdisplaybuf on the second line of the display, then// scrolls fdisplaybuf to the left, and grabs the next// character from filebuf.//void lcd_update_2nd_line(const unsigned char refresh){ xdata unsigned char font; if (current_control == CONTROL3) font = 33; // bold else font = 32; // normal if (lcd_version == LCD_VERSION_BETA) { if (fxscroll == 0) { // not scrolling so just display it printf("\\[\\B !\\C%c%s\\C \\]\r\n", (char) font, filebuf); } else { printf("\\[\\B !\\C%c%s\\C \\]\r\n", (char) font, fdisplaybuf); // shift buffer & insert new char fxwrap++; memcpy(fdisplaybuf, fdisplaybuf+1, DISPLAY_WIDTH - 1); if(fxwrap < filebuf_len) { fdisplaybuf[DISPLAY_WIDTH-1] = filebuf[fxwrap]; } else if (fxwrap < filebuf_len + 4) { fdisplaybuf[DISPLAY_WIDTH-1] = ' '; } else { fxwrap = 0; fdisplaybuf[DISPLAY_WIDTH-1] = filebuf[0]; } } // TODO: Remove this once display bug is fixed if((update_counter++)>10) { update_counter=0; lcd_change_menu(0); } } else { // ensure font is correct upon refresh (selection might have changed) if (refresh != 0) { if (fxscroll != 0) { printf("\\K2!1\\K1!%c", (char) font); } else { printf("\\[\\B !\\C%c%s\\C \\]\r\n", (char) font, filebuf); } } }}//--------------------------------------------------------------------//// lcd_display_filename//// Takes long file name. Strips last 4 characters if// they are ".m3u". Pads with a few spaces and// fills to DISPLAY_WIDTH characters if shorter than that.//void lcd_display_filename(){ xdata unsigned char* source; xdata unsigned char* dest; if (current_filename == 0) { return; } // make local copy (filename will be invalid on exit) // check length & truncate. convert '_' to ' '. source = addr7(current_filename); dest = filebuf; filebuf_len = 0; while(*source != '\0') { filebuf_len++; if (filebuf_len >= FILEBUF_MAX) { break; } else if (*source == '_') { *dest = ' '; } else { *dest = *source; } source++; dest++; } *dest = '\0'; // .mp3 and .MP3 if (filebuf_len > 4 && str_is_dot_mp3(filebuf + filebuf_len - 4)) { filebuf_len -= 4; *(filebuf + filebuf_len) = '\0'; } if (filebuf_len <= DISPLAY_WIDTH) { // pad with maximum number of spaces memset(filebuf + filebuf_len, ' ', DISPLAY_WIDTH); filebuf[DISPLAY_WIDTH] = '\0'; fxscroll = 0; } else { // init scroll buffer memcpy(fdisplaybuf, filebuf, DISPLAY_WIDTH); fdisplaybuf[DISPLAY_WIDTH] = '\0'; fxscroll = 1; } if (lcd_version == LCD_VERSION_BETA) { fxwrap = 23; lcd_update_2nd_line(0); } else { if (fxscroll == 0) { // scrolling off and force display of new string print("\\K2!0"); lcd_update_2nd_line(1); } else { xdata unsigned char font; if (current_control == CONTROL3) font = 33; // bold else font = 32; // normal // just fill scrolling buffer and let the display do the work printf("\\[\\K1!%c\\K3!1%s \\K3!0\\K2!1\\]", (char) font, filebuf); } }}//--------------------------------------------------------------------void lcd_set_filename(simm_id name){ current_filename = name; if (current_screen == MAINSCREEN || current_screen == AUDIOSCREEN) { lcd_display_filename(); }}//--------------------------------------------------------------------//// lcd_update_3rd_line//// Called when timer 0 expires.// Displays pdisplaybuf on the third line of the display, then// scrolls pdisplaybuf to the left, and grabs the next// character from playbuf.//void lcd_update_3rd_line(const unsigned char refresh){ xdata unsigned char font; if (current_control == CONTROL4) font = 33; // bold else font = 32; // normal if (lcd_version == LCD_VERSION_BETA) { if (pxscroll == 0) { // not scrolling so just display it printf("\\[\\B \"\\C%c%s\\C \\]\r\n", (char) font, playbuf); } else { printf("\\[\\B \"\\C%c%s\\C \\]\r\n", (char) font, pdisplaybuf); // shift buffer & insert new char pxwrap++; memcpy(pdisplaybuf, pdisplaybuf+1, DISPLAY_WIDTH - 1); if(pxwrap < playbuf_len) { pdisplaybuf[DISPLAY_WIDTH-1] = playbuf[pxwrap]; } else if (pxwrap < playbuf_len + 4) { pdisplaybuf[DISPLAY_WIDTH-1] = ' '; } else { pxwrap = 0; pdisplaybuf[DISPLAY_WIDTH-1] = playbuf[0]; } } } else { // ensure font is correct upon refresh (selection might have changed) if (refresh != 0) { if (pxscroll != 0) { printf("\\K2\"1\\K1\"%c", (char) font); } else { printf("\\[\\B \"\\C%c%s\\C \\]\r\n", (char) font, playbuf); } } }}//--------------------------------------------------------------------//// lcd_display_playlist_name//// Takes long file name. Strips last 4 characters if// they are ".m3u". Pads with a few spaces and// fills to DISPLAY_WIDTH characters if shorter than that.//void lcd_display_playlistname(){ xdata unsigned char* source; xdata unsigned char* dest; if (current_playlistname == 0) { return; } // make local copy (pl_name will be invalid on exit) // check length & truncate. convert '_' to ' '. source = addr7(current_playlistname); dest = playbuf; playbuf_len = 0; while(*source != '\0') { playbuf_len++; if (playbuf_len >= PLAYBUF_MAX) { break; } else if (*source == '_') { *dest = ' '; } else { *dest = *source; } source++; dest++; } *dest = '\0'; // .m3u and .M3U if (playbuf_len > 4 && str_is_dot_m3u(playbuf + playbuf_len - 4)) { playbuf_len -= 4; *(playbuf + playbuf_len) = '\0'; } if (playbuf_len <= DISPLAY_WIDTH) { // pad with maximum number of spaces memset(playbuf + playbuf_len, ' ', DISPLAY_WIDTH); playbuf[DISPLAY_WIDTH] = '\0'; pxscroll = 0; } else { // init scroll buffer memcpy(pdisplaybuf, playbuf, DISPLAY_WIDTH); pdisplaybuf[DISPLAY_WIDTH] = '\0'; pxscroll = 1; } if (lcd_version == LCD_VERSION_BETA) { pxwrap = 23; lcd_update_3rd_line(0); } else { if (pxscroll == 0) { // scrolling off and force display of new string print("\\K2\"0"); lcd_update_3rd_line(1); } else { xdata unsigned char font; if (current_control == CONTROL4) font = 33; // bold else font = 32; // normal // just fill scrolling buffer and let the display do the work printf("\\[\\K1\"%c\\K3\"1%s \\K3\"0\\K2\"1\\]", (char) font, playbuf); } }}//--------------------------------------------------------------------void lcd_set_playlistname(simm_id name){ current_playlistname = name; if (current_screen == MAINSCREEN || current_screen == AUDIOSCREEN) { lcd_display_playlistname(); }}//--------------------------------------------------------------------// called on expiry of timer 2void lcd_timer_callback(){ if (lcd_version == LCD_VERSION_BETA) { if (current_screen == MAINSCREEN || current_screen == AUDIOSCREEN) { lcd_update_2nd_line(0); lcd_update_3rd_line(0); } } else { if (lcd_version != LCD_VERSION_1) { print("***** WARNING: Invalid LCD Version\r\n"); } }}//--------------------------------------------------------------------void lcd_display_id3_struct() { id3_tag.title[DISPLAY_WIDTH] = 0; id3_tag.artist[DISPLAY_WIDTH] = 0; id3_tag.album[DISPLAY_WIDTH] = 0; // Display ID3 data // use display clear line functions with version 1 displays if (current_screen == MAINSCREEN) { printf("\\L#\\L$\\L%%\\[\\B #%s\\B $%s\\B %%%s\\]\r\n", id3_tag.title, id3_tag.artist, id3_tag.album); }}//--------------------------------------------------------------------void lcd_display_id3_init(){ // reset id3 data at the start of each new track and when no id3 data present id3_tag.title[0] = 0; id3_tag.artist[0] = 0; id3_tag.album[0] = 0; // force display update lcd_display_id3_struct();}//--------------------------------------------------------------------void lcd_update_time() { xdata unsigned char s[6]; xdata unsigned char min; xdata unsigned int sec; static xdata unsigned int prevsec = 0xffffffff; // Now get the elapsed time to display. Subtract the number of frames played when // this song started (updated in main.c when the song changes) from the current number // of frames played back. Multiply that by the number of milliseconds per from for the // current sample rate (defined in the playback struct in display.c). Then divide the whole // mess by 1000 to get seconds. Break it up to seconds & minutes, then output. // -ZSB 12-Aug-2001 3:33 PM sec = ((GetFrameCount() - songStartFrameCount) * playback.ms_per_frame) / 1000;#if 0 if (sec != prevsec)#endif { prevsec = sec; min = sec / 60; sec = sec % 60; if(min < 10) { s[0] = '0'; } else { s[0] = (min / 10) + '0'; } s[1] = (min % 10) + '0'; s[2] = ':'; if(sec < 10) { s[3] = '0'; } else { s[3] = (sec / 10) + '0'; } s[4] = (sec % 10) + '0'; s[5] = 0; printf("\\[\\B3 %s\\]\r\n",s); }}//--------------------------------------------------------------------//// lcd_navigation//// Display navigation element on the screen at coordinates (x,y).// If this_control is the active one then display in bold.//void lcd_navigation(unsigned char x, unsigned char y, const unsigned char *navtext, unsigned char this_control){ if(this_control==current_control) { printf("\\[\\B%c%c\\C!%s\\C \\]\r\n",(char)(x+32),(char)(y+32),navtext); } else { printf("\\[\\B%c%c\\C %s\\C \\]\r\n",(char)(x+32),(char)(y+32),navtext); }}//--------------------------------------------------------------------void lcd_update_top_line(void) { if (current_screen == MAINSCREEN || current_screen == AUDIOSCREEN) { if (playing) { lcd_navigation(0,0,"Playing ",CONTROL1); } else { lcd_navigation(0,0,"Paused ",CONTROL1); } lcd_navigation(8, 0, play_mode_description[play_mode], CONTROL2); }}//--------------------------------------------------------------------//// lcd_bar_set//// Displays a bargraph on a line of// the display.//// The sta013 expects a 2s compliment number from// -12 to 12 corresponding to a boost of// -18dB to 18dB.//void lcd_bar_set(param_t param){ xdata unsigned char bar_position; xdata unsigned char display_line; xdata unsigned char font; switch(param) { case PARAM_TREBLE: lcd_navigation(0, 4, "Tr:", CONTROL5);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -