1 #include "view_monitor.h" 3 ViewMonitor::ViewMonitor() : t_worker(&
ViewMonitor::worker, this)
7 call_t ViewMonitor::keypress(
int& key)
17 if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
19 size_t column = start_x + close_offset_x;
20 size_t row = start_y + close_offset_y;
21 size_t mouse_x =
event.x, mouse_y =
event.y;
22 if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
44 std::string ViewMonitor::fancyDigitalString(uint8_t& b)
46 std::stringstream str;
47 str << std::bitset<8>(b).to_string();
49 str <<
"0x" << std::setfill (
'0') << std::setw(2) << std::hex << (int) b << std::dec;
53 std::string ViewMonitor::fancyAnalogString(uint16_t& v)
55 std::stringstream str;
56 double volt = round(v * 100.0 * 5.0 / 1023.0) / 100.0;
58 str << std::setfill (
'0') << std::setw(4) << (int) v <<
" " << std::fixed << std::setprecision(2) << volt <<
" V ";
61 uint8_t p = round(v * 40.0 / 1023.0);
62 for(uint8_t i = 0; i < p; i++)
64 for(uint8_t i = 0; i < 40 - p; i++)
66 str <<
"]" << std::endl;
71 void ViewMonitor::worker()
78 std::this_thread::sleep_for(std::chrono::milliseconds(100));
84 for(uint8_t i = 0; i <
sizeof(adc) /
sizeof(adc[0]); i++)
88 std::stringstream str;
91 for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
98 str <<
"Digitale Enigaenge:" << std::endl;
99 str <<
"Binaere Eingabe 0: " << fancyDigitalString(be0) << std::endl;
100 str <<
"Binaere Eingabe 1: " << fancyDigitalString(be1) << std::endl;
101 str <<
"Dip Schalter (S7): " << fancyDigitalString(dsw) << std::endl;
104 for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
111 str <<
"Analoge Eingaenge:" << std::endl;
112 for(uint8_t i = 0; i <
sizeof(adc) /
sizeof(adc[0]); i++)
114 str <<
"Kanal " << std::to_string((
int) i) <<
": ";
115 str << fancyAnalogString(adc[i]) << std::endl;
123 std::cout <<
"DriverException: " << ex.what() << std::endl;