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::string bitstring(std::bitset<8>(b).to_string());
47 std::reverse(bitstring.begin(), bitstring.end());
49 std::stringstream str;
52 str <<
"0x" << std::setfill (
'0') << std::setw(2) << std::hex << (int) b << std::dec;
56 std::string ViewMonitor::fancyAnalogString(uint16_t& v)
58 std::stringstream str;
59 double volt = round(v * 100.0 * 5.0 / 1023.0) / 100.0;
61 str << std::setfill (
'0') << std::setw(4) << (int) v <<
" " << std::fixed << std::setprecision(2) << volt <<
" V ";
64 uint8_t p = round(v * 40.0 / 1023.0);
65 for(uint8_t i = 0; i < p; i++)
67 for(uint8_t i = 0; i < 40 - p; i++)
69 str <<
"]" << std::endl;
74 void ViewMonitor::worker()
84 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
87 std::this_thread::sleep_for(std::chrono::milliseconds(100));
94 for(uint8_t i = 0; i <
sizeof(adc) /
sizeof(adc[0]); i++)
98 std::stringstream str;
101 for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
108 str <<
"Digitale Enigaenge:" << std::endl;
109 str <<
"Binaere Eingabe 0: " << fancyDigitalString(be0) << std::endl;
110 str <<
"Binaere Eingabe 1: " << fancyDigitalString(be1) << std::endl;
111 str <<
"Dip Schalter (S7): " << fancyDigitalString(dsw) << std::endl;
114 for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
121 str <<
"Analoge Eingaenge:" << std::endl;
122 for(uint8_t i = 0; i <
sizeof(adc) /
sizeof(adc[0]); i++)
124 str <<
"Kanal " << std::to_string((
int) i) <<
": ";
125 str << fancyAnalogString(adc[i]) << std::endl;
133 std::cout <<
"DriverException: " << ex.what() << std::endl;
144 B15F::abort(
"Die Verbindung ist unterbrochen worden. Wurde ein Stecker gezogen? :D");