summaryrefslogtreecommitdiffhomepage
path: root/UI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'UI.cpp')
-rw-r--r--UI.cpp35
1 files changed, 33 insertions, 2 deletions
diff --git a/UI.cpp b/UI.cpp
index e1d33c9..f9b2512 100644
--- a/UI.cpp
+++ b/UI.cpp
@@ -8,13 +8,35 @@
#include <fmt/format.h>
+using namespace std::chrono_literals;
+
+UI::UI(): m_main_loops{}, m_main_loops_checkpoint{}, m_main_loops_timestamp{}
+{
+}
+
+int UI::get_main_loops_per_second()
+{
+ // calculate result
+ std::chrono::time_point<clock_type> now = clock_type::now();
+ uint64_t diff_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_main_loops_timestamp).count();
+ uint64_t loops_per_second = (diff_ms == 0 || m_main_loops_checkpoint == 0) ? 0 : ((m_main_loops - m_main_loops_checkpoint) * 1000 / diff_ms);
+
+ // update state
+ m_main_loops_timestamp = now;
+ m_main_loops_checkpoint = m_main_loops;
+
+ return loops_per_second;
+}
+
void UI::draw()
{
std::vector<int> cpuloads = get_cpu_loads();
+ int main_loops_per_second = get_main_loops_per_second();
std::cout << std::endl;
std::cout << "- -- BPM +" << std::endl;
std::cout << "Mode: Click __/__ (Clock Internal)" << std::endl;
+ std::cout << std::endl;
std::cout << "Status:" << std::endl;
std::cout << " Alive/not alive" << std::endl;
@@ -28,6 +50,15 @@ void UI::draw()
std::cout << " Notes/Channels: -- -- -- ... (Choose)" << std::endl;
std::cout << " Timestamp: ------" << std::endl;
std::cout << " Active sensing: ---" << std::endl;
- std::cout << " Clock: ____" << std::endl;
- std::cout << " Click: ____" << std::endl;
+ std::cout << " Clock: ____ BPM" << std::endl;
+ std::cout << " Click: ____ BPM" << std::endl;
+
+ std::cout << fmt::format(" Main loops/s: {}", main_loops_per_second) << std::endl;
}
+
+void UI::count_main_loops()
+{
+ ++m_main_loops;
+ //std::cout << "DEBUG:" << m_main_loops << std::endl;
+}
+