/* * Runs the user operator control code. This function will be started in its own task with the * default priority and stack size whenever the robot is enabled via the Field Management System * or the VEX Competition Switch in the operator control mode. If the robot is disabled or * communications is lost, the operator control task will be stopped by the kernel. Re-enabling * the robot will restart the task, not resume it from where it left off. * * If no VEX Competition Switch or Field Management system is plugged in, the VEX Cortex will * run the operator control task. Be warned that this will also occur if the VEX Cortex is * tethered directly to a computer via the USB A to A cable without any VEX Joystick attached. * * Code running in this task can take almost any action, as the VEX Joystick is available and * the scheduler is operational. However, proper use of delay() or taskDelayUntil() is highly * recommended to give other tasks (including system tasks such as updating LCDs) time to run. * * This task should never exit; it should end with some kind of infinite loop, even if empty. */ void operatorControl() { bool *lcdBacklight = initLcdVals(); taskResume(catTask); while (1) { // Joystick control of drive checkDrive(); // Tower and intake control (Y-cabled into ports 3 and 8) setTowerAndIntake(); // Manual catapult control setCatapultMotors(); // Perform battery checks and update LCD showBatteryOnLcd(uart1 ); // Show potentiometer values on second LCD showPotVals(uart2, 1); // Toggle backlight using buttons bool newBacklight = checkBacklight(uart1, lcdBacklight[0]); bool newSecondBacklight = checkBacklight(uart2, lcdBacklight[1]); lcdBacklight[0] = newBacklight; lcdBacklight[1] = newSecondBacklight; // Delay 20 ms to concede to other tasks delay(20); } }
void perMain() { #if defined(PCBSKY9X) && !defined(REVA) calcConsumption(); #endif checkSpeakerVolume(); checkEeprom(); sdMountPoll(); writeLogs(); handleUsbConnection(); checkTrainerSettings(); checkBattery(); uint8_t evt = getEvent(false); if (evt && (g_eeGeneral.backlightMode & e_backlight_mode_keys)) backlightOn(); // on keypress turn the light on checkBacklight(); #if defined(NAVIGATION_STICKS) uint8_t sticks_evt = getSticksNavigationEvent(); if (sticks_evt) evt = sticks_evt; #endif #if defined(USB_MASS_STORAGE) if (usbPlugged()) { // disable access to menus lcd_clear(); menuMainView(0); lcdRefresh(); return; } #endif #if defined(LUA) uint32_t t0 = get_tmr10ms(); static uint32_t lastLuaTime = 0; uint16_t interval = (lastLuaTime == 0 ? 0 : (t0 - lastLuaTime)); lastLuaTime = t0; if (interval > maxLuaInterval) { maxLuaInterval = interval; } // run Lua scripts that don't use LCD (to use CPU time while LCD DMA is running) luaTask(0, RUN_MIX_SCRIPT | RUN_FUNC_SCRIPT | RUN_TELEM_BG_SCRIPT, false); // wait for LCD DMA to finish before continuing, because code from this point // is allowed to change the contents of LCD buffer // // WARNING: make sure no code above this line does any change to the LCD display buffer! // lcdRefreshWait(); // draw LCD from menus or from Lua script // run Lua scripts that use LCD bool standaloneScriptWasRun = luaTask(evt, RUN_STNDAL_SCRIPT, true); bool refreshScreen = true; if (!standaloneScriptWasRun) { refreshScreen = !luaTask(evt, RUN_TELEM_FG_SCRIPT, true); } t0 = get_tmr10ms() - t0; if (t0 > maxLuaDuration) { maxLuaDuration = t0; } if (!standaloneScriptWasRun) #else lcdRefreshWait(); // WARNING: make sure no code above this line does any change to the LCD display buffer! const bool refreshScreen = true; #endif { // normal GUI from menus const char *warn = s_warning; uint8_t menu = s_menu_count; if (refreshScreen) { lcd_clear(); } if (menuEvent) { m_posVert = menuEvent == EVT_ENTRY_UP ? g_menuPos[g_menuStackPtr] : 0; m_posHorz = 0; evt = menuEvent; menuEvent = 0; AUDIO_MENUS(); } g_menuStack[g_menuStackPtr]((warn || menu) ? 0 : evt); if (warn) DISPLAY_WARNING(evt); if (menu) { const char * result = displayMenu(evt); if (result) { menuHandler(result); putEvent(EVT_MENU_UP); } } drawStatusLine(); } lcdRefresh(); #if defined(REV9E) && !defined(SIMU) topLcdRefreshStart(); setTopFirstTimer(getValue(MIXSRC_FIRST_TIMER+g_model.topLcdTimer)); setTopSecondTimer(g_eeGeneral.globalTimer + sessionTimer); setTopRssi(TELEMETRY_RSSI()); setTopBatteryValue(g_vbat100mV); setTopBatteryState(GET_TXBATT_BARS(), IS_TXBATT_WARNING()); topLcdRefreshEnd(); #endif #if defined(REV9E) && !defined(SIMU) bluetoothWakeup(); #endif #if defined(PCBTARANIS) if (requestScreenshot) { requestScreenshot = false; writeScreenshot(); } #endif }