static void RunUI(Port &port, OperationEnvironment &env) { WriteMenu(); while (true) { fprintf(stdout, "> "); char in[20]; if (fgets(in, 20, stdin) == NULL || strlen(in) == 0) { fprintf(stdout, "Invalid input\n"); continue; } switch (in[0]) { case '?': case 'h': case 'H': WriteMenu(); break; case '1': SetMC(port, env); break; case '2': SetBallast(port, env); break; case '3': SetBugs(port, env); break; case '4': SetAltitudeOffset(port, env); break; case '5': SetQNH(port, env); break; case '6': SetVolume(port, env); break; case 'p': case 'P': SetPolar(port, env); break; case 'f': case 'F': SetFilters(port, env); break; case 's': case 'S': SetSCSettings(port, env); break; case 'q': case 'Q': fprintf(stdout, "Closing LX1600 Utils ...\n"); return; default: fprintf(stdout, "Invalid input\n"); break; } } }
static void RunUI(FlarmDevice &flarm, OperationEnvironment &env) { WriteMenu(); while (true) { fprintf(stdout, "> "); char in[20]; if (fgets(in, 20, stdin) == NULL || strlen(in) == 0) { fprintf(stdout, "Invalid input\n"); continue; } switch (in[0]) { case '?': case 'h': case 'H': WriteMenu(); break; case '1': ChangePilot(flarm, env); break; case '2': ChangeCoPilot(flarm, env); break; case '3': ChangePlaneType(flarm, env); break; case '4': ChangeRegistration(flarm, env); break; case '5': ChangeCompetitionId(flarm, env); break; case '6': ChangeCompetitionClass(flarm, env); break; case '7': ChangeRange(flarm, env); break; case '8': ChangeBaudRate(flarm, env); break; case 'r': case 'R': fprintf(stdout, "Restarting the FLARM ...\n"); flarm.Restart(env); break; case 's': case 'S': if (strlen(in) < 2 || (in[1] != '+' && in[1] != '-')) { fprintf(stdout, "Invalid input\n"); break; } fprintf(stdout, "Changing stealth mode setting ...\n"); if (flarm.SetStealthMode(in[1] == '+', env)) { if (in[1] == '+') fprintf(stdout, "Stealth mode enabled\n"); else fprintf(stdout, "Stealth mode disabled\n"); } else fprintf(stdout, "Operation failed!\n"); break; case 'q': case 'Q': fprintf(stdout, "Closing Flarm Utils ...\n"); return; default: fprintf(stdout, "Invalid input\n"); break; } } }
int main(void) { init(); // Arduino Serial.begin(9600); Serial.println("Premi H per il MENU di aiuto\n"); // on my MicroSD Module the power comes from a digital pin // I activate it at all times // pinMode(MEM_PW, OUTPUT); // digitalWrite(MEM_PW, HIGH); // // configure the serial port to command the card and read data while (true) { // Arduino expects one of a series of one-byte commands // you can get some help by sending an 'H' over the serial port if (Serial.available() > 0) { int result = 0; inSerByte = Serial.read(); switch (inSerByte) { case 'H': WriteMenu(); result = 3; // special output for help message break; case 'L': result = SD.ls("hola.txt"); break; case 'R': result = SD.cat("hola.txt"); break; case 'W': result = SD.write("hola.txt"); result = SD.write("hola1.txt"); result = SD.write("hola2.txt"); result = SD.write("hola3.txt"); break; case 'A': result = SD.append("hola.txt"); break; case 'P': result = SD.println("hola.txt","\nhola caracola"); break; case 'D': result = SD.del("hola.txt"); break; default: result = 2; // value for unknown operation break; } // print a status message for the last issued command // for help (result == 3) won't print anything if (result == 1) SD.printEvent(ERROR, "hola.txt"); else if (result == 2) SD.printEvent(WARNING, "unknown command"); else if (result == 0) SD.printEvent(SUCCESS, "hola.txt"); } } return 0; }