UART mode rework (#341)
This commit is contained in:
214
menu.cpp
214
menu.cpp
@@ -118,8 +118,13 @@ enum MENU
|
||||
|
||||
MENU_UART1,
|
||||
MENU_UART2,
|
||||
MENU_UART3,
|
||||
MENU_UART4,
|
||||
MENU_BAUD1,
|
||||
MENU_BAUD2,
|
||||
MENU_BAUD3,
|
||||
MENU_BAUD4,
|
||||
|
||||
MENU_SFONT_FILE_SELECTED,
|
||||
|
||||
MENU_COEFF_FILE_SELECTED,
|
||||
@@ -203,9 +208,11 @@ const char *config_button_turbo_choice_msg[] = { "A only", "B only", "A & B" };
|
||||
const char *joy_button_map[] = { "RIGHT", "LEFT", "DOWN", "UP", "BUTTON A", "BUTTON B", "BUTTON X", "BUTTON Y", "BUTTON L", "BUTTON R", "SELECT", "START", "KBD TOGGLE", "MENU", " Analog X: Tilt RIGHT", " Analog Y: Tilt DOWN", " Mouse emu X: Tilt RIGHT", " Mouse emu Y: Tilt DOWN" };
|
||||
const char *joy_ana_map[] = { " DPAD test: Press RIGHT", " DPAD test: Press DOWN", " Stick 1 Test: Tilt RIGHT", " Stick 1 Test: Tilt DOWN", " Stick 2 Test: Tilt RIGHT", " Stick 2 Test: Tilt DOWN" };
|
||||
const char *config_stereo_msg[] = { "0%", "25%", "50%", "100%" };
|
||||
const char *config_uart_msg[] = { " None", " PPP", " Console", " MIDI", " Midilink" };
|
||||
const char *config_midilink_msg[] = { " MIDI Local", "MIDI Remote", " MFP UART", "" };
|
||||
//const char *config_uart_baud[] = { "110", "300", "600", "1200", "2400", "9600", "14400", "19200", "31250/MIDI", "38400", "57600", "115200"};
|
||||
//const char *config_uart_msg[] = { " None", " PPP", " Console", " MIDI", " Midilink" };
|
||||
const char *config_uart_msg[] = { " None", " PPP", " Console", " MIDI", " Modem", " UDP", " USBSER"};
|
||||
const char *config_midilink_mode[] = {"FSYNTH", " MUNT", " USB", " UDP"};
|
||||
//const char *config_midilink_msg[] = { " MIDI Local", "MIDI Remote", " MFP UART", "" };
|
||||
const char *config_uart_baud[] = { "110", "300", "600", "1200", "2400", "9600", "14400", "19200", "31250/MIDI", "38400", "57600", "115200"};
|
||||
const char *config_scaler_msg[] = { "Internal","Custom" };
|
||||
const char *config_afilter_msg[] = { "Internal","Custom" };
|
||||
const char *config_gamma_msg[] = { "Off","On" };
|
||||
@@ -2413,12 +2420,11 @@ void HandleUI(void)
|
||||
case 4:
|
||||
{
|
||||
menustate = MENU_UART1;
|
||||
|
||||
struct stat filestat;
|
||||
//struct stat filestat;
|
||||
int mode = GetUARTMode();
|
||||
|
||||
//jump straght to Softsynth selection if enabled
|
||||
menusub = ((mode != 3 && mode != 4) || !stat("/dev/midi", &filestat)) ? 0 : 2;
|
||||
//menusub = ((mode != 3 && mode != 4) || !stat("/dev/midi", &filestat)) ? 0 : 2;
|
||||
menusub = (mode == 3 && GetMidiLinkMode() == 0)?3:0;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2678,18 +2684,17 @@ void HandleUI(void)
|
||||
menustate = MENU_UART2;
|
||||
parentstate = MENU_UART1;
|
||||
|
||||
struct stat filestat;
|
||||
int hasmidi = !stat("/dev/midi1", &filestat);
|
||||
int mode = GetUARTMode();
|
||||
int midilink = GetMidiLinkMode();
|
||||
int dis = (mode != 3 && mode != 4) || hasmidi;
|
||||
|
||||
//int dis = (mode != 3 && mode != 4) || hasmidi;
|
||||
int dis = (mode != 3);
|
||||
m = 0;
|
||||
OsdWrite(m++);
|
||||
sprintf(s, " Connection: %s", config_uart_msg[(is_st() && mode ==3) ? 4 : mode]);
|
||||
sprintf(s, " Connection: %s", config_uart_msg[mode]);
|
||||
OsdWrite(m++, s, menusub == 0, 0);
|
||||
OsdWrite(m++);
|
||||
|
||||
/*
|
||||
if (is_st())
|
||||
{
|
||||
sprintf(s, " MidiLink: %s", config_midilink_msg[(midilink>>1) & 3]);
|
||||
@@ -2698,8 +2703,12 @@ void HandleUI(void)
|
||||
{
|
||||
sprintf(s, " MidiLink: %s", (midilink & 2) ? "Remote" : " Local");
|
||||
}
|
||||
*/
|
||||
|
||||
sprintf(s, " MidiLink: %s", (midilink > 2) ? "Remote" : " Local");
|
||||
OsdWrite(m++, s, menusub == 1, dis);
|
||||
sprintf(s, " Type: %s", (midilink & 6) ? ((midilink & 1) ? " UDP" : " TCP") : ((midilink & 1) ? " MUNT" : "FluidSynth"));
|
||||
|
||||
sprintf(s, " Type: %s", config_midilink_mode[midilink]);
|
||||
OsdWrite(m++, s, menusub == 2, dis);
|
||||
|
||||
OsdWrite(m++);
|
||||
@@ -2707,7 +2716,8 @@ void HandleUI(void)
|
||||
OsdWrite(m++);
|
||||
|
||||
strcpy(s, " Baud \x16");
|
||||
sprintf(s + 6, "(%s)", GetUARTbaud_label(GetUARTMode()));
|
||||
|
||||
sprintf(s + 6, "(%s)", (mode < 4)?GetUARTbaud_label(GetUARTMode()):GetMidiLinkBAUD());
|
||||
s[strlen(s)] = ' ';
|
||||
OsdWrite(m++, s, menusub == 4, !mode);
|
||||
|
||||
@@ -2734,6 +2744,7 @@ void HandleUI(void)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
/*
|
||||
uint mode = GetUARTMode();
|
||||
do
|
||||
{
|
||||
@@ -2742,33 +2753,40 @@ void HandleUI(void)
|
||||
|
||||
SetUARTMode(mode);
|
||||
menustate = MENU_UART1;
|
||||
*/
|
||||
menusub = GetUARTMode();
|
||||
menustate = MENU_UART3;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case 2:
|
||||
if (!m)
|
||||
#define MIDILINK_LOCAL (midilink <= 2)
|
||||
if (!m)
|
||||
{
|
||||
int mode = GetUARTMode();
|
||||
if (!is_st() || menusub == 2)
|
||||
int midilink = GetMidiLinkMode();
|
||||
if (menusub == 1)
|
||||
{
|
||||
SetMidiLinkMode(GetMidiLinkMode() ^ ((menusub == 1) ? 2 : 1));
|
||||
if(MIDILINK_LOCAL)
|
||||
midilink = 3;
|
||||
else
|
||||
midilink = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int type = GetMidiLinkMode();
|
||||
if (minus)
|
||||
{
|
||||
type -= 2;
|
||||
if (type < 0) type = (type & 1) | 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
type += 2;
|
||||
if (type >= 6) type &= 1;
|
||||
}
|
||||
SetMidiLinkMode(type);
|
||||
int max = MIDILINK_LOCAL?2:sizeof(config_midilink_mode) / 4 - 1;
|
||||
int min = MIDILINK_LOCAL?0:3;
|
||||
if (select || plus) midilink++;
|
||||
if (minus) midilink--;
|
||||
struct stat filestat;
|
||||
if (midilink == 2 &&
|
||||
stat("/dev/midi1", &filestat) &&
|
||||
stat("/dev/ttyUSB0", &filestat)) midilink = min;
|
||||
if (midilink > max) midilink = min;
|
||||
if (midilink < min) midilink = max;
|
||||
}
|
||||
SetMidiLinkMode(midilink);
|
||||
int mode = GetUARTMode();
|
||||
SetUARTMode(0);
|
||||
SetUARTMode(mode);
|
||||
menustate = MENU_UART1;
|
||||
@@ -2779,7 +2797,7 @@ void HandleUI(void)
|
||||
{
|
||||
if(GetUARTMode() == 3 && GetMidiLinkMode() == 0)
|
||||
{
|
||||
sprintf(Selected_tmp, "linux/soundfonts");
|
||||
sprintf(Selected_tmp, GetMidiLinkSoundfont());
|
||||
SelectFile(Selected_tmp, "SF2", SCANO_DIR | SCANO_TXT, MENU_SFONT_FILE_SELECTED, MENU_UART1);
|
||||
}
|
||||
}
|
||||
@@ -2787,11 +2805,30 @@ void HandleUI(void)
|
||||
case 4:
|
||||
if (select)
|
||||
{
|
||||
if(GetUARTMode())
|
||||
{
|
||||
menusub = 0;
|
||||
menustate = MENU_BAUD1;
|
||||
menusub = GetUARTbaud_idx(GetUARTMode());
|
||||
switch (GetUARTMode())
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
menusub = 0;
|
||||
for (uint8_t i = 0; i < sizeof(config_uart_baud) / 4; i++)
|
||||
{
|
||||
char baudStr[sizeof("31250/MIDI")]; //sizeof largest char[]
|
||||
strcpy(baudStr, config_uart_baud[i]);
|
||||
char * tmp = strchr(baudStr, '/');
|
||||
if(tmp) *tmp = 0x00; //Remove "/MIDI";
|
||||
if(!strcmp(GetMidiLinkBAUD(), baudStr))
|
||||
menusub = i;
|
||||
}
|
||||
menustate = MENU_BAUD3;
|
||||
break;
|
||||
default:
|
||||
menusub = 0;
|
||||
menustate = MENU_BAUD1;
|
||||
menusub = GetUARTbaud_idx(GetUARTMode());
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -2825,14 +2862,63 @@ void HandleUI(void)
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_UART3:
|
||||
{
|
||||
helptext_idx = 0;
|
||||
menumask = 0x00;
|
||||
OsdSetTitle("UART MODE");
|
||||
menustate = MENU_UART4;
|
||||
parentstate = MENU_UART3;
|
||||
struct stat filestat;
|
||||
uint8_t usbser = stat("/dev/ttyUSB0", &filestat)?false:true;
|
||||
uint8_t max = (sizeof(config_uart_msg) / 4) - (usbser?1:2);
|
||||
for (uint8_t i = 0; i < 15; i++)
|
||||
{
|
||||
if (i <= max)
|
||||
{
|
||||
menumask |= 1 << i;
|
||||
const char * uart_msg = config_uart_msg[i];
|
||||
while (*uart_msg == ' ') {uart_msg++;}//skip spaces
|
||||
sprintf(s, " %s", uart_msg);
|
||||
OsdWrite(i, s, menusub == i, 0);
|
||||
|
||||
}
|
||||
else
|
||||
OsdWrite(i);
|
||||
}
|
||||
menumask |= 1 << (max+1);
|
||||
OsdWrite(15, STD_EXIT, menusub == max + (uint)1);
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_UART4:
|
||||
{
|
||||
if (menu)
|
||||
{
|
||||
menustate = MENU_UART1;
|
||||
menusub = 1;
|
||||
break;
|
||||
}
|
||||
else if (select)
|
||||
{
|
||||
struct stat filestat;
|
||||
uint8_t usbser = stat("/dev/ttyUSB0", &filestat)?false:true;
|
||||
uint8_t max = (sizeof(config_uart_msg) / 4) - (usbser?1:2);
|
||||
if(menusub <= max)
|
||||
SetUARTMode(menusub);
|
||||
menusub = 0;
|
||||
menustate = MENU_UART1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MENU_SFONT_FILE_SELECTED:
|
||||
{
|
||||
printf("MENU_SFONT_FILE_SELECTED --> '%s'\n", selPath);
|
||||
sprintf(Selected_tmp, "/sbin/mlinkutil FSSFONT /media/fat/\"%s\"", selPath);
|
||||
system(Selected_tmp);
|
||||
AdjustDirectory(selPath);
|
||||
//keep file select OSD
|
||||
menustate = MENU_FILE_SELECT1; //MENU_UART1;
|
||||
// MENU_FILE_SELECT1 to file select OSD
|
||||
menustate = MENU_UART1; //MENU_FILE_SELECT1;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2908,7 +2994,59 @@ void HandleUI(void)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_BAUD3:
|
||||
{
|
||||
helptext_idx = 0;
|
||||
menumask = 0x00;
|
||||
OsdSetTitle("UART BAUD");
|
||||
menustate = MENU_BAUD4;
|
||||
parentstate = MENU_BAUD3;
|
||||
uint8_t max = sizeof(config_uart_baud) / 4 -1;
|
||||
for (unsigned int i = 0; i < 15; i++)
|
||||
{
|
||||
if (i <= max)
|
||||
{
|
||||
menumask |= 1 << i;
|
||||
sprintf(s, " %s", config_uart_baud[i]);
|
||||
|
||||
OsdWrite(i, s, menusub == i, 0);
|
||||
}
|
||||
else
|
||||
OsdWrite(i);
|
||||
}
|
||||
menumask |= 1 << (max+1);
|
||||
OsdWrite(15, STD_EXIT, menusub == max + (uint)1);
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_BAUD4:
|
||||
{
|
||||
if (menu)
|
||||
{
|
||||
menustate = MENU_UART1;
|
||||
menusub = 4;
|
||||
break;
|
||||
}
|
||||
|
||||
if (select)
|
||||
{
|
||||
unsigned int max = sizeof(config_uart_baud) / 4 - 1;
|
||||
if(menusub <= max)
|
||||
{
|
||||
char baudStr[sizeof("31250/MIDI")];
|
||||
strcpy(baudStr, config_uart_baud[menusub]);
|
||||
char * tmp = strchr(baudStr, '/');
|
||||
if(tmp) *tmp = 0x00; //Remove "/MIDI";
|
||||
sprintf(s, "/sbin/mlinkutil BAUD %s", baudStr);
|
||||
system(s);
|
||||
}
|
||||
menusub = 4;
|
||||
menustate = MENU_UART1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_COEFF_FILE_SELECTED:
|
||||
{
|
||||
char *p = strcasestr(selPath, COEFF_DIR"/");
|
||||
|
||||
71
user_io.cpp
71
user_io.cpp
@@ -670,6 +670,7 @@ void MakeFile(const char * filename, const char * data)
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
||||
static void set_uart_alt()
|
||||
{
|
||||
if (is_st())
|
||||
@@ -684,6 +685,9 @@ int GetUARTMode()
|
||||
if (!stat("/tmp/uartmode1", &filestat)) return 1;
|
||||
if (!stat("/tmp/uartmode2", &filestat)) return 2;
|
||||
if (!stat("/tmp/uartmode3", &filestat)) return 3;
|
||||
if (!stat("/tmp/uartmode4", &filestat)) return 4;
|
||||
if (!stat("/tmp/uartmode5", &filestat)) return 5;
|
||||
if (!stat("/tmp/uartmode6", &filestat)) return 6;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -693,7 +697,8 @@ void SetUARTMode(int mode)
|
||||
uint32_t baud = GetUARTbaud(mode);
|
||||
|
||||
spi_uio_cmd_cont(UIO_SET_UART);
|
||||
spi_w(mode);
|
||||
//spi_w(mode);
|
||||
spi_w(mode==4||mode==5?1:mode);
|
||||
spi_w(baud);
|
||||
spi_w(baud>>16);
|
||||
DisableIO();
|
||||
@@ -738,6 +743,47 @@ int GetUARTbaud_idx(int mode)
|
||||
return (mode >= 3) ? midi_speed_idx : uart_speed_idx;
|
||||
}
|
||||
|
||||
char * GetMidiLinkBAUD()
|
||||
{
|
||||
FILE * file;
|
||||
static char mLinkBAUD[10];
|
||||
mLinkBAUD[0] = 0x00;
|
||||
char fileName[] = "/tmp/ML_BAUD";
|
||||
file = fopen(fileName, "r");
|
||||
if (file)
|
||||
{
|
||||
fgets((char *) &mLinkBAUD, sizeof(mLinkBAUD), file);
|
||||
fclose(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ERROR: GetMidiLinkBAUD : Unable to open --> '%s'\n", fileName);
|
||||
}
|
||||
return mLinkBAUD;
|
||||
}
|
||||
|
||||
char * GetMidiLinkSoundfont()
|
||||
{
|
||||
FILE * file;
|
||||
static char mLinkSoundfont[255];
|
||||
char fileName[] = "/tmp/ML_SOUNDFONT";
|
||||
char strip[] = "/media/fat/";
|
||||
file = fopen(fileName, "r");
|
||||
if (file)
|
||||
{
|
||||
fgets((char *) &mLinkSoundfont, sizeof(mLinkSoundfont), file);
|
||||
fclose(file);
|
||||
if(0 == strncmp(strip, mLinkSoundfont, sizeof(strip)-1))
|
||||
return &mLinkSoundfont[sizeof(strip)-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ERROR: GetMidiLinkSoundfont : Unable to open --> '%s'\n", fileName);
|
||||
sprintf(mLinkSoundfont, "linux/soundfonts");
|
||||
}
|
||||
return mLinkSoundfont;
|
||||
}
|
||||
|
||||
uint32_t ValidateUARTbaud(int mode, uint32_t baud)
|
||||
{
|
||||
uint32_t *bauds = GetUARTbauds(mode);
|
||||
@@ -760,13 +806,13 @@ uint32_t ValidateUARTbaud(int mode, uint32_t baud)
|
||||
|
||||
int GetMidiLinkMode()
|
||||
{
|
||||
struct stat filestat;
|
||||
if (!stat("/tmp/ML_FSYNTH", &filestat)) return 0;
|
||||
if (!stat("/tmp/ML_MUNT", &filestat)) return 1;
|
||||
if (!stat("/tmp/ML_TCP", &filestat)) return 2;
|
||||
if (!stat("/tmp/ML_UDP", &filestat)) return 3;
|
||||
if (!stat("/tmp/ML_TCP_ALT", &filestat)) return 4;
|
||||
if (!stat("/tmp/ML_UDP_ALT", &filestat)) return 5;
|
||||
struct stat filestat;
|
||||
if (!stat("/tmp/ML_FSYNTH", &filestat)) return 0;
|
||||
if (!stat("/tmp/ML_MUNT", &filestat)) return 1;
|
||||
if (!stat("/tmp/ML_USBMIDI", &filestat)) return 2;
|
||||
if (!stat("/tmp/ML_UDP", &filestat)) return 3;
|
||||
//if (!stat("/tmp/ML_TCP_ALT", &filestat)) return 4;
|
||||
//if (!stat("/tmp/ML_UDP_ALT", &filestat)) return 5;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -775,17 +821,18 @@ void SetMidiLinkMode(int mode)
|
||||
remove("/tmp/ML_FSYNTH");
|
||||
remove("/tmp/ML_MUNT");
|
||||
remove("/tmp/ML_UDP");
|
||||
remove("/tmp/ML_TCP");
|
||||
remove("/tmp/ML_USBMIDI");
|
||||
remove("/tmp/ML_UDP_ALT");
|
||||
remove("/tmp/ML_TCP_ALT");
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 0: MakeFile("/tmp/ML_FSYNTH", ""); break;
|
||||
case 1: MakeFile("/tmp/ML_MUNT", ""); break;
|
||||
case 2: MakeFile("/tmp/ML_TCP", ""); break;
|
||||
case 2: MakeFile("/tmp/ML_USBMIDI", ""); break;
|
||||
case 3: MakeFile("/tmp/ML_UDP", ""); break;
|
||||
case 4: MakeFile("/tmp/ML_TCP_ALT", ""); break;
|
||||
case 5: MakeFile("/tmp/ML_UDP_ALT", ""); break;
|
||||
//case 3: MakeFile("/tmp/ML_TCP_ALT", ""); break;
|
||||
//case 4: MakeFile("/tmp/ML_UDP_ALT", ""); break;
|
||||
}
|
||||
set_uart_alt();
|
||||
}
|
||||
|
||||
@@ -258,7 +258,8 @@ char* GetUARTbaud_label(int mode);
|
||||
char* GetUARTbaud_label(int mode, int idx);
|
||||
int GetUARTbaud_idx(int mode);
|
||||
uint32_t ValidateUARTbaud(int mode, uint32_t baud);
|
||||
|
||||
char * GetMidiLinkBAUD();
|
||||
char * GetMidiLinkSoundfont();
|
||||
void user_io_store_filename(char *filename);
|
||||
int user_io_use_cheats();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user