uint8_t exec_pause() { uint8_t running; running = exec_runningM0(); if (running) exec_stopM0(); return running; }
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; } }