Files
CCU4-firmware/instr.ino
2023-09-11 18:04:36 +02:00

139 lines
4.3 KiB
C++

/* remark: the original idea was, that the instrument could be selected on the touch display.
* for this purpose, free racks have to be connected by a central server, which turned out to
* be error prone.
* The functionality is now reduced to the possibility to tell the connected server to disconnect
* und deselect the current rack.
*/
PAR_TEXT instrConnected[16] = ""; // connected instrument
PAR_TEXT instr[16] = ""; // possible values: "" (on init), "free": to be disconnected, "<instrument>" confirmed connection
PAR_TEXT instrRack[16] = " ";
enum {instr_startup = 240, instr_idle, instr_detach, instr_attach_yes, instr_attach_no, instr_disconnect, instr_detach_yes, instr_detach_no};
byte instrState = instr_startup;
boolean gohome = true; // go home when instr == instrConnected
word instrAdr = 0;
void InstrPars() {
ParText("cin", instr, true);
if (ParText("cic", instrConnected, false) == par_command) {
if (textequal(instrConnected, "free")) {
if (textequal(instr, "free")) {
ParSetText(instr, "");
instrState = instr_idle;
}
screen = m_instr;
gohome = false;
} else if (textequal(instr, instrConnected)) {
ParSetText(instr, "");
instrState = instr_idle;
screen = m_home;
gohome = false;
} else if (instrConnected[0] == 0) {
ParSetText(instr, "disconnected");
} else {
ParSetText(instr, instrConnected);
instrState = instr_idle;
screen = m_home;
gohome = false;
}
}
ParText("cir", instrRack, false);
}
void InstrStore(byte mode) {
eeStoreText((char *)instrRack, sizeof instrRack, mode);
}
void InstrButton() {
char label[10];
if (online) {
label[0] = ':'; // button without frame
textcopy(label + 1, sizeof label - 1, instrConnected);
DispButton(1, m_menu, m_menu, label);
} else {
DispButton(1, m_menu, m_menu, ":offline");
}
}
void InstrDisp() {
ConfigDispShort("instr");
if (!online) { // we are offline
if (time_ge(now, 5000) || instrState != instr_startup) {
DispTextRow(fmt_medium, 0, "offline");
if (instrRack[0] > ' ') {
DispTextRow(fmt_rsmall, "please","connect");
DispText("rack to LAN");
DispText("and choose");
DispTextRow(fmt_lsmall, "rack ", instrRack);
DispText("in sea");
}
} else {
DispText("starting up");
}
} else if (instrConnected[0] == 0) { // we are not connected
DispText("going");
DispText("offline");
} else { // we are connected to an instrument
if (instrState == instr_detach) {
DispText(" ");
DispText("detach from");
DispTextRow(fmt_medium, 0, instrConnected);
DispText("is this ok?");
DispButton(5, m_instr, instr_detach_yes, "yes");
DispButton(4, m_instr, instr_detach_no, "no");
} else {
if (instrState == instr_startup) { // startup
DispText("attached to");
DispTextRow(fmt_medium, 0, instrConnected);
DispText("is this ok?");
DispButton(5, m_instr, instr_attach_yes, "yes");
DispButton(4, m_instr, instr_attach_no, "no");
} else if (textequal(instr, "free")) {
DispText("disconnecting");
DispTextRow(fmt_medium, 0, instrConnected);
} else {
DispText("attached to");
DispTextRow(fmt_medium, 0, instrConnected);
DispButton(3, m_instr, instr_disconnect, "detach");
//DispButton(2, m_instr, instr_select, "select");
}
}
}
DispButton(1, m_menu, m_home, "home");
DispButton(0, m_menu, m_menu, "menu");
}
void InstrCmd(byte cmd) {
if (cmd == instr_attach_yes) {
ParSetText(instr, instrConnected);
instrState = instr_idle;
} else if (cmd == instr_attach_no) {
instrState = instr_detach;
gohome = false;
} else if (cmd == instr_disconnect) {
instrState = instr_detach;
return;
} else if (cmd == instr_detach_yes) {
ParSetText(instr, "free");
gohome = false;
instrState = instr_idle;
} else if (cmd == instr_detach_no) {
ParSetText(instr, "");
gohome = false;
instrState = instr_idle;
} else {
instrState = cmd;
}
if (textequal(instr, instrConnected)) {
if (gohome) {
ParSetText(instr, "");
if (!textequal(instrConnected, "free")) screen = m_home;
gohome = false;
}
instrState = instr_idle;
}
}