/** * This idle function allows progressive scanning of visibility etc */ bool GlueMapWindow::Idle() { if (!render_projection.IsValid()) return false; if (idle_robin == unsigned(-1)) { /* draw the first frame as quickly as possible, so the user can start interacting with XCSoar immediately */ idle_robin = 2; return true; } if (!IsUserIdle(2500)) /* don't hold back the UI thread while the user is interacting */ return true; PeriodClock clock; clock.Update(); bool still_dirty; bool topography_dirty = true; /* scan topography in every Idle() call */ bool terrain_dirty = true; bool weather_dirty = true; do { idle_robin = (idle_robin + 1) % 3; switch (idle_robin) { case 0: topography_dirty = UpdateTopography(1) > 0; break; case 1: terrain_dirty = UpdateTerrain(); break; case 2: weather_dirty = UpdateWeather(); break; } still_dirty = terrain_dirty || topography_dirty || weather_dirty; } while (!clock.Check(700) && /* stop after 700ms */ #ifndef ENABLE_OPENGL !draw_thread->IsTriggered() && #endif IsUserIdle(2500) && still_dirty); return still_dirty; }
void ProcessTimer() { CommonProcessTimer(); if (!is_simulator()) { // now check GPS status devTick(CommonInterface::Calculated()); // also service replay logger if (replay && replay->Update()) { if (CommonInterface::MovementDetected()) replay->Stop(); } ConnectionProcessTimer(); } else { static PeriodClock m_clock; if (m_clock.Elapsed() < 0) m_clock.Update(); if (replay && replay->Update()) { m_clock.Update(); } else if (m_clock.Elapsed() >= 1000) { m_clock.Update(); device_blackboard->ProcessSimulation(); } } #ifdef HAVE_TRACKING if (tracking != NULL && CommonInterface::Basic().gps.real) { tracking->SetSettings(CommonInterface::GetComputerSettings().tracking); tracking->OnTimer(CommonInterface::Basic(), CommonInterface::Calculated()); } #endif }
void WorkerThread::Run() { PeriodClock clock; while (true) { /* wait for work */ event_trigger.Wait(); /* got the "stop" trigger? */ if (delay > 0 ? WaitForStopped(delay) : CheckStoppedOrSuspended()) break; /* reset the trigger here, because our client might have called Trigger() a few more times while we were suspended in CheckStoppedOrSuspended() */ event_trigger.Reset(); if (IsCommandPending()) { /* just in case we got another suspend/stop command after CheckStoppedOrSuspended() returned and before the trigger got reset: restore the trigger and skip this iteration, to fix the race condition */ event_trigger.Signal(); continue; } /* do the actual work */ if (period_min > 0) clock.Update(); Tick(); unsigned idle = idle_min; if (period_min > 0) { unsigned elapsed = clock.Elapsed(); if (elapsed + idle < period_min) idle = period_min - elapsed; } if (idle > 0 && WaitForStopped(idle)) break; } }
void Message::Initialize(RECT rc) { startTime.Update(); block_ref = 0; hidden = true; nvisible = 0; rcmsg = rc; // default; message window can be full size of screen WndMsg.Create(&MainWindow, rc); // change message font for different resolutions // Caution, remember to set font also in Resize.. WndMsg.SetFont(ScreenLandscape ? LK8InfoBigFont : MapWindowBoldFont); WndMsg.SetTextColor(LKColor(0x00,0x00,0x00)); WndMsg.SetBkColor(LKColor(0xFF,0xFF,0xFF)); }
bool FlarmDevice::Receive(const char *prefix, char *buffer, size_t length, unsigned timeout_ms) { assert(!in_binary_mode); assert(prefix != NULL); PeriodClock timeout; timeout.Update(); if (!port.ExpectString(prefix, timeout_ms)) return false; char *p = (char *)buffer, *end = p + length; while (p < end) { if (timeout.Check(timeout_ms)) return false; // Read single character from port int c = port.GetChar(); // On failure try again until timed out if (c == -1) continue; // Break on line break or checksum if (c == '*' || c == '\n') { *p = '\0'; break; } // Skip carriage return if (c == '\r') continue; // Write received character to buffer *p = c; p++; } return true; }
/** * This idle function allows progressive scanning of visibility etc */ bool GlueMapWindow::Idle() { if (!render_projection.IsValid()) return false; if (skip_idle) { /* draw the first frame as quickly as possible, so the user can start interacting with XCSoar immediately */ skip_idle = false; return true; } /* hack: update RASP weather maps as quickly as possible; they only ever need to be updated after the user has selected a new map, so this is not a UI latency problem (quite contrary, don't let the user wait until he sees the new map) */ UpdateWeather(); if (!IsUserIdle(2500)) /* don't hold back the UI thread while the user is interacting */ return true; PeriodClock clock; clock.Update(); bool still_dirty; do { still_dirty = UpdateWeather() || UpdateTerrain(); } while (!clock.Check(700) && /* stop after 700ms */ #ifndef ENABLE_OPENGL !draw_thread->IsTriggered() && #endif IsUserIdle(2500) && still_dirty); return still_dirty; }
static bool TryConnect(Port &port, char *user_data, size_t max_user_data, OperationEnvironment &env) { port.Write('\x02'); // send IO Mode command unsigned user_size = 0; bool started = false; PeriodClock clock; clock.Update(); int i; while ((i = port.GetChar()) != EOF && !clock.Check(8000) && !env.IsCancelled()) { char ch = (char)i; if (!started && ch == '-') started = true; if (started) { if (ch == 0x13) { port.Write('\x16'); user_data[user_size] = 0; // found end of file return true; } else { if (user_size < max_user_data - 1) { user_data[user_size] = ch; user_size++; } } } } return false; }
/** * Acts as if the user had just interacted with XCSoar. */ void ResetUserIdle() { user_idle_clock.Update(); }