int32_t exec_runprogArg(const uint8_t &progNum, const int32_t &arg) { int32_t res = exec_runprog(progNum); if (res<0) return res; g_execArg = arg; return 0; }
void exec_select() { uint8_t prog, progs; // count number of progs for (progs=0; g_progTable[progs]; progs++); // select using button state machine prog = g_bMachine->selectProgram(progs); // set it up to run exec_runprog(prog); }
int32_t exec_runprogArg(const uint8_t &progNum, const int32_t &arg, Chirp *chirp) { int32_t res = exec_runprog(progNum, chirp); if (res<0) return res; if (chirp) g_execArgChirp = arg; if (g_programChirp>=0) // if PixyMon is setting program, it overrides g_execArg = g_execArgChirp; else g_execArg = arg; return 0; }
void exec_select() { uint8_t progs; prm_get("Startup program", &g_startupProgram, END); g_program = g_startupProgram; // count number of progs for (progs=0; g_progTable[progs]; progs++); // select using button state machine g_bMachine->selectProgram(progs, &g_program); exec_runprog(g_program); }
void exec_loop() { uint8_t state = 0; bool prevConnected = false; bool connected; exec_select(); while(1) { connected = g_chirpUsb->connected(); exec_periodic(); switch (state) { case 0: // setup state led_set(0); // turn off any stray led if ((*g_progTable[g_program]->setup)()<0) state = 3; // stop state else state = 1; // loop state break; case 1: // loop state if (g_override) { // need to stop M0 because it's using the same memory and can possibly interfere. // For example if we try to grab a raw frame while M0 is running (gathering RLS values) // M0 could overwrite the frame memory with RLS scratch data. exec_stopM0(); state = 2; // override state } else if (!g_run || (*g_progTable[g_program]->loop)()<0) state = 3; // stop state else if (prevConnected && !connected) // if we disconnect from pixymon, revert back to default program { exec_runprog(0); // run default program state = 0; // setup state } break; case 2: // override state if (!g_override) state = 0; // back to setup state break; case 3: // stop state // set variable to indicate we've stopped g_run = false; g_running = false; // stop M0 exec_stopM0(); state = 4; // wait for run state break; case 4: // wait for run state if (g_run) { exec_run(); state = 0; // back to setup state } else if (!connected || !USB_Configuration) // if we disconnect from pixy or unplug cable, revert back to default program { exec_runprog(0); // run default program state = 0; // back to setup state } break; default: state = 3; // stop state } prevConnected = connected; } }