Raspberry Pi Weighting Control System
This project serves as a simple weighting control system, that was realized as a Bachelor Thesis
screen_definitions.cpp
Go to the documentation of this file.
1 #include "screen_definitions.h"
2 
3 #include <spdlog/spdlog.h>
4 
5 #include "gui_button.h"
6 #include "gui_combobox.h"
7 #include "gui_direct.h"
8 #include "gui_input.h"
9 #include "gui_label.h"
10 #include "gui_observer.h"
11 #include "gui_selectable.h"
12 #include "localisation.h"
13 #include "app_workspace.h"
14 #include "config_loader.h"
15 
16 // limit definitions moved to app_workspace.h so they can be used here and in app_workspace
17 
18 #define EMPTY_LINE elems.push_back(std::unique_ptr<gui_element>(new gui_direct(empty_line)));
19 #define SAME_LINE elems.push_back(std::unique_ptr<gui_element>(new gui_direct(same_line)));
20 #define INDENT elems.push_back(std::unique_ptr<gui_element>(new gui_direct(indent)));
21 #define UNINDENT elems.push_back(std::unique_ptr<gui_element>(new gui_direct(unindent)));
22 #define INSERT_ELEMENT(ELEMENT) elems.push_back(std::unique_ptr<gui_element>(ELEMENT));
23 
24 /*********************************************************************************************************************/
25 /* Local function definitions (used in screens) */
26 /*********************************************************************************************************************/
27 
28 gui_element* last_element(std::vector<std::unique_ptr<gui_element>> &elems);
29 void empty_line();
30 void same_line();
31 // void begin_child_window(); /** Creates a "subwindow" in current window. Used for scrollable region */
32 // void end_child_window();
35 
36 static float custom_indent = 20.0f; // for customizing identation if needed
40 void indent();
41 void unindent();
42 
43 // screen_1
44 void login_action();
45 void login_subuser();
46 void logout_action();
47 void logout_subuser();
48 
49 // screen_2
50 void start_hx_measuring();
51 void start_hx_continuous();
52 
53 // screen_3
56 
57 // screen_4
58 void unit_select_action();
59 
60 // screen_5
66 
67 // screen_6
68 void start_tare();
69 void start_calibration();
70 void apply_calibration();
71 void register_user();
72 
75 // leftovers - remove ?
76 void cb();
77 void draw_rect();
78 void render_line();
79 void render_vert();
80 
81 // actual debug
82 void empty_cb();
83 void callback_debug();
84 void int_test_label();
85 void float_test_label();
86 void text_test_label();
87 void text_wrap_debug();
88 
89 // db test calls
90 void invoke_sql_debug();
91 void test_user_login_sql();
92 void test_user_creds_sql();
97 void test_user_insert();
100 void update_rfids_debug();
101 
102 void hx_samples_debug();
103 void hx_timeout_debug();
104 
105 void test_errscr_1();
106 void test_errscr_2();
107 
108 
109 /*********************************************************************************************************************/
110 /* Implementation of header function definitions (screen definitions) */
111 /* */
112 /* Used GUI library uses "vertical" layout by default but offers options to specify position and width */
113 /* most widgets. Height is usually determined automatically from font size and settable vertical spacing. */
114 /* Through adding gui_elements to elems (vector of screen elements) a screen is defined with simplified API */
115 /* */
116 /* The way the library works is that "attributes" (like position/ width/ spacing...) are specified */
117 /* for the following elements. For example programmer using this API doesn't have to use constructor */
118 /* with position, but can specify position and other attributes in a function and call it through gui_direct */
119 /* and then add element like gui_label which will have attributes from previous gui_direct */
120 /*********************************************************************************************************************/
121 
122 gui_label *err_title = new gui_label("Changable error title");
123 gui_label *err_desc = new gui_label("Changable error description");
124 
125 void define_screen_0(std::vector<std::unique_ptr<gui_element>>& elems) {
126  elems.clear();
127 
128  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_0_ERR_TITLE_LABEL")))
129  INDENT
131  UNINDENT
132  EMPTY_LINE
133  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_0_ERR_DESC_LABEL")))
134  INDENT
136  UNINDENT
137 }
138 
139 void define_screen_1(std::vector<std::unique_ptr<gui_element>>& elems) {
140  elems.clear();
141 
142  // if (usr_wrk != nullptr) { //get_userspace() checks if user exists = is logged in
143  if (app_workspace::get_instance()->has_user()) {
144  user_workspace* usr_wrk = app_workspace::get_instance()->get_userspace();
145 
146  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_1_LOGGED_USERNAME")))
147  SAME_LINE
148  INSERT_ELEMENT(new gui_label(usr_wrk->get_username().c_str()))
149  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_1_LOGGED_ROLE")))
150  SAME_LINE
151  INSERT_ELEMENT(new gui_label(usr_wrk->get_role_string()))
152  EMPTY_LINE
153  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_1_LOGOUT_BTN"), logout_action, -1, -1, 460, 40))
154 
155  if (usr_wrk->get_role() >= 1) { // emp/ admin
156  if (usr_wrk->subuser.get() != nullptr) {
157  EMPTY_LINE
158  EMPTY_LINE
159  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_1_LOGGED_SUBUSERNAME")))
160  SAME_LINE
161  INSERT_ELEMENT(new gui_label(usr_wrk->subuser->username.c_str()))
162  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_1_LOGOUT_SUBUSER"),
163  logout_subuser, -1, -1, 460, 40))
164 
165  } else {
166  EMPTY_LINE
167  EMPTY_LINE
168  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_1_LOGIN_SUBUSER")))
169  INSERT_ELEMENT(new gui_input(IN_TEXT, (void*) &app_workspace::get_instance()->subusr_name,
170  sizeof(char) * DEF_BUFF_SIZE, -1 ,-1 ,-1, get_localized_text("SCREEN_1_USERNAME")))
171  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_1_LOGIN_SUBUSER_BTN"),
172  login_subuser, -1, -1, 460, 40)) // TDOO change action to login_subuser
173  }
174  }
175  } else {
176  EMPTY_LINE
177  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_1_LOGIN_W_RFID")))
178  EMPTY_LINE
180  EMPTY_LINE
182  sizeof(char) * DEF_BUFF_SIZE, -1 ,-1 ,-1, get_localized_text("SCREEN_1_USERNAME")))
184  sizeof(char) * DEF_BUFF_SIZE_SMALL, -1, -1, -1, get_localized_text("SCREEN_1_PASSWORD")))
185  EMPTY_LINE
186  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_1_LOGIN_BTN"), login_action, -1, -1, 460, 40))
187  }
188 }
189 
190 void define_screen_2(std::vector<std::unique_ptr<gui_element>>& elems) {
191  elems.clear();
192  app_workspace *app_wrk = app_workspace::get_instance().get();
193  user_workspace *usr_wrk = app_wrk->get_userspace();
194 
195  if (!app_wrk->has_user()) {
196  INSERT_ELEMENT(new gui_label(get_localized_text("GT_SCREEN_REQUIRE_USER")))
197  EMPTY_LINE
198  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_FUNCTION_DESC")))
199  return;
200  }
201 
202  if (app_wrk->hx_measuring) {
203  if (app_wrk->hx_not_finished_yet) {
204  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_WAITING_FOR_FINISH")))
205  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURING_CANCEL_ENTER")))
206  return;
207  }
208 
209  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURING")))
210  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURING_CANCEL_ENTER")))
211  EMPTY_LINE
212 
213  measurement *m = app_wrk->observed_measurement.get();
214  if (m != nullptr) {
215  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_X_VAL_MEDIAN"), -1, -1, 250))
216  SAME_LINE
217  INSERT_ELEMENT(new gui_label(m->x_val_med_str.c_str()))
218  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_X_VAL_AVARAGE"), -1, -1, 250))
219  SAME_LINE
220  INSERT_ELEMENT(new gui_label(m->x_val_avg_str.c_str()))
221  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEDIAN")))
222  SAME_LINE
223  INSERT_ELEMENT(new gui_label(m->all_val_med_str.c_str()))
224  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_AVARAGE")))
225  SAME_LINE
226  INSERT_ELEMENT(new gui_label(m->all_val_avg_str.c_str()))
227  }
228 
229  // if (app_workspace::get_instance()->hx_continuous) {
230  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURING")))
231  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURING_CANCEL_ENTER")))
232  // } else {
233  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURING")))
234  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURING_WAIT_PLEASE")))
235  // }
236  } else {
237  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_CHANGED_MEASURED_USER_TIP"), -1, -1, -1,
239  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURED_USER")))
240  SAME_LINE
241  INSERT_ELEMENT(new gui_label(usr_wrk != nullptr ?
242  usr_wrk->get_measured_username().c_str() :
243  get_localized_text("GT_USER_NO_LOGIN")))
244 
245  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEASURING_OPTIONS")))
246 
247  INDENT
248 
249  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_CB1_LABEL"), -1, -1, 160))
250  SAME_LINE
252  &(app_wrk->selected_hx_measure_opt), nullptr, 160, -1, 200))
254 
255  if (app_wrk->selected_hx_measure_opt == 0) {
256  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_SAMPLES_IN_LIMITS"), -1, -1, -1,
258  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_CB1_SAMPLES"), -1, -1, 160))
259  SAME_LINE
261  0, 160, -1, 200))
262  ((gui_input*) last_element(elems))->set_min_max(S2_MIN_SAMPLES_IN, S2_MAX_SAMPLES_IN); // WARNING! - if used after wrong element, application crashes on startup
263  } else if (app_wrk->selected_hx_measure_opt == 1) {
264  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_TIMEOUT_IN_LIMITS"), -1, -1, -1,
266  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_CB1_TIMEOUT"), -1, -1, 160))
267  SAME_LINE
269  0, 160, -1, 200))
270  ((gui_input*) last_element(elems))->set_min_max(S2_MIN_TIMEOUT_IN, S2_MAX_TIMEOUT_IN); // WARNING! - if used after wrong element, application crashes on startup
271  SAME_LINE
272  // INSERT_ELEMENT(new gui_label(get_localized_text("GT_SEC_UNIT")))
273  INSERT_ELEMENT(new gui_label(get_localized_text("GT_SEC_UNIT_BRTS")))
274  }
275 
276  UNINDENT
277 
278  EMPTY_LINE
279  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_2_START_MEASURING"),
280  start_hx_measuring, -1, -1, 460, 40))
282  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_2_START_CONTINOUS"),
283  start_hx_continuous, -1, -1, 460, 40))
284 
285  EMPTY_LINE
286  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_LAST_MEAS_RES")))
287  if ((app_wrk->has_user() && app_wrk->userspace->get_last_hx_measuring() != nullptr &&
288  app_wrk->userspace->get_last_hx_measuring()->values.size() > 0))
289  {
290  measurement *m = app_wrk->userspace->get_last_hx_measuring();
291  // m->init_value_strings(); // this should be init after measuring
292 
293  // allow unit selection on this screen? or statically one unit and unit selection on measuring detail
294  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_CB2_LABEL"), -1, -1, 160))
295  // SAME_LINE
296  // INSERT_ELEMENT(new gui_combobox(result_unit_opts, 2, &(app_wrk->selected_hx_result_unit),
297  // nullptr, 160, -1, 200))
298  // last_element(elems)->set_refresh_screen(&(app_wrk->refresh_current_screen));
299 
300  INDENT
301 
302  // raw_avg is actually the same as all_val_avg
303  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_RAW_AVG")))
304  // SAME_LINE
305  // INSERT_ELEMENT(new gui_label("result"))
306  // INSERT_ELEMENT(new gui_observer(OBS_FLOAT, &(m->raw_avg))); //gui_observer can serve as label for numerical values
307  // SAME_LINE
308 
309  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_X_VAL_MEDIAN"), -1, -1, 250))
310  SAME_LINE
311  INSERT_ELEMENT(new gui_label(m->x_val_med_str.c_str()))
312 
313  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_X_VAL_AVARAGE"), -1, -1, 250))
314  SAME_LINE
315  INSERT_ELEMENT(new gui_label(m->x_val_avg_str.c_str()))
316 
317  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEDIAN")))
318  SAME_LINE
319  INSERT_ELEMENT(new gui_label(m->all_val_med_str.c_str()))
320 
321  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_AVARAGE")))
322  SAME_LINE
323  INSERT_ELEMENT(new gui_label(m->all_val_avg_str.c_str()))
324 
325  UNINDENT
326 
327  } else {
328  INDENT
329  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_NO_LAST_RESULT")))
330  UNINDENT
331  }
332  }
333 }
334 
335 void define_screen_3(std::vector<std::unique_ptr<gui_element>>& elems) {
336  elems.clear();
337 
338  app_workspace *app_wrk = app_workspace::get_instance().get();
339 
340  if (app_workspace::get_instance()->has_user()) {
341  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_3_USER_MEASURINGS")))
342  SAME_LINE
343  INSERT_ELEMENT(new gui_label(app_workspace::get_instance()->userspace->get_measured_username().c_str()))
344 
345  std::vector<std::unique_ptr<measurement_header>> &headers =
346  app_workspace::get_instance()->userspace->get_user_measur_headers();
347 
348  if (headers.size() <= 0) {
349  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_3_MEASUREMENTS_EMPTY")))
350  } else {
351  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_3_FILTER_LABEL")))
352 
354  &(app_wrk->s3_selected_filter), nullptr, -1, -1, 250))
355  ((gui_combobox*) last_element(elems))->set_value_change_action(apply_meas_list_filter); // WARNING! - if used after wrong element, application crashes (due to conversion)
356  SAME_LINE
358  // set min filter value to 0, because measurement_number can only be unsigned
359  ((gui_input*) last_element(elems))->set_min_max(S3_MIN_FILTER_NUMBER); // WARNING! - if used after wrong element, application crashes on startup
360  ((gui_input*) last_element(elems))->set_value_change_action(apply_meas_list_filter); // WARNING! - if used after wrong element, application crashes (due to conversion)
361 
363 
364  if (app_wrk->s3_selected_filter == 0) { // Larger than
365  for (size_t i = 0; i < headers.size(); i++) {
366  measurement_header *h = headers.at(i).get();
367 
368  if (h->measurement_number > app_wrk->s3_filter_number) {
370  &(app_workspace::get_instance()->selected_measuring), open_measuring_detail));
371  }
372  }
373  } else if (app_wrk->s3_selected_filter == 1) { // smaller than
374  for (size_t i = 0; i < headers.size(); i++) {
375  measurement_header *h = headers.at(i).get();
376 
377  if (h->measurement_number < app_wrk->s3_filter_number) {
379  &(app_workspace::get_instance()->selected_measuring), open_measuring_detail));
380  }
381  }
382  } else {
383  for (size_t i = 0; i < headers.size(); i++) {
384  measurement_header *h = headers.at(i).get();
386  &(app_workspace::get_instance()->selected_measuring), open_measuring_detail));
387  }
388  }
389 
391  }
392  } else {
393  INSERT_ELEMENT(new gui_label(get_localized_text("GT_SCREEN_REQUIRE_USER")))
394  EMPTY_LINE
395  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_3_FUNCTION_DESC")))
396  }
397 }
398 
399 void define_screen_4(std::vector<std::unique_ptr<gui_element>>& elems) {
400  elems.clear();
401 
402  app_workspace* app_wrk = app_workspace::get_instance().get();
403  measurement* m = nullptr;
404 
405  if (app_wrk->has_user()) {
406  m = app_wrk->userspace->picked.get();
407  } else {
408  INSERT_ELEMENT(new gui_label(get_localized_text("GT_SCREEN_REQUIRE_USER")))
409  EMPTY_LINE
410  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_FUNCTION_DESCRIPTION")))
411  return;
412  }
413 
414  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_TITLE")))
415 
416  if (m == nullptr || m->id <= 0) {
417  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_NO_MEASUREMENT")))
418  } else {
419  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_UNITS_LAB"), -1, -1, 180))
420  SAME_LINE
422  &(app_wrk->selected_unit_option), nullptr, 160, -1, 200))
423  ((gui_combobox*) last_element(elems))->set_value_change_action(unit_select_action); // WARNING! - if used after wrong element, application crashes (due to conversion)
424 
425  // using gui_observer for numerical values, because label would require some buffer/ string
426 
427  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASUR_NUM_LAB"), -1, -1, 250))
428  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASUR_NUM_LAB")))
429  SAME_LINE
431 
432  if (m->continuous) {
433  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASUR_NUM_PARTS")))
434  SAME_LINE
436  }
437 
438  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASURED_LAB"), -1, -1, 250))
439  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASURED_LAB")))
440  SAME_LINE
441  INSERT_ELEMENT(new gui_label(m->measuree_uname.size() <= 0 ?
442  get_localized_text("GT_EMPTY_NULL_STRING") : m->measuree_uname.c_str()))
443 
444  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASURED_BY_LAB"), -1, -1, 250))
445  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASURED_BY_LAB")))
446  SAME_LINE
447  INSERT_ELEMENT(new gui_label(m->measurer_uname.size() <= 0 ?
448  get_localized_text("GT_EMPTY_NULL_STRING") : m->measurer_uname.c_str()))
449 
450 
451  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASURING_SECTION")))
452  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASURING_LEN_LAB"), -1, -1, 250))
453  INDENT
454  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_M_LENGTH"), -1, -1, 150))
455  SAME_LINE
456  INSERT_ELEMENT(new gui_label(m->length_str.c_str()))
457 
458  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASURING_START_LAB"), -1, -1, 250))
459  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_M_START"), -1, -1, 150))
460  SAME_LINE
461  INSERT_ELEMENT(new gui_label(m->start_str.c_str()))
462 
463  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_MEASURING_END_LAB"), -1, -1, 250))
464  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_M_END"), -1, -1, 150))
465  SAME_LINE
466  INSERT_ELEMENT(new gui_label(m->end_str.c_str()))
467  UNINDENT
468 
469  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_EVERY_X_VAL_SECTION")))
470  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_X_VAL_MEDIAN"), -1, -1, 250))
471  INDENT
472  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEDIAN"), -1, -1, 150))
473  SAME_LINE
474  INSERT_ELEMENT(new gui_label(m->x_val_med_str.c_str()))
475 
476  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_X_VAL_AVARAGE"), -1, -1, 250))
477  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_AVARAGE"), -1, -1, 150))
478  SAME_LINE
479  INSERT_ELEMENT(new gui_label(m->x_val_avg_str.c_str()))
480  UNINDENT
481 
482 
483  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_ALL_VAL_SECTION")))
484  INDENT
485  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_MEDIAN")))
486  SAME_LINE
487  INSERT_ELEMENT(new gui_label(m->all_val_med_str.c_str()))
488 
489  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_AVARAGE")))
490  SAME_LINE
491  INSERT_ELEMENT(new gui_label(m->all_val_avg_str.c_str()))
492  UNINDENT
493  }
494 }
495 
496 void define_screen_5(std::vector<std::unique_ptr<gui_element>>& elems) {
497  elems.clear();
498 
499  app_workspace* app_wrk = app_workspace::get_instance().get();
500 
501  if (app_wrk->s5_success_indicator >= 0) {
503  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_5_CALIBRATION_APPLIED")))
504  } else if (app_wrk->s5_success_indicator == S5_USER_CREATED) {
505  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_5_USER_CREATED")))
506  } else if (app_wrk->s5_success_indicator == S5_FINISHED_KB_DELAYS) {
507  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_5_FINISHED_TESTING_KB")))
508  }
509  }
510 
511  if (app_wrk->has_user()) {
512  if (app_wrk->userspace->get_user()->role <= 1) {
513  INSERT_ELEMENT(new gui_label(get_localized_text("GT_INSUFFICIENT_PERMISSION")))
514  EMPTY_LINE
515  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_5_ADMIN_SCREEN_ONLY")))
516  return;
517  }
518  } else {
519  INSERT_ELEMENT(new gui_label(get_localized_text("GT_SCREEN_REQUIRE_USER")))
520  EMPTY_LINE
521  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_5_FUNCTION_DESCRIPTION")))
522  return;
523  }
524 
525  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_5_CALIBRATE_HX"),
526  move_to_hx_calibration, -1, -1, 460, 40))
527  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_5_ADD_USER"),
528  move_to_user_addition, -1, -1, 460, 40))
529  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_5_TEST_HX_SAMPLES"),
530  move_to_hx_test_samp, -1, -1, 460, 40))
531  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_5_TEST_HX_TIMEOUT"),
532  move_to_hx_test_time, -1, -1, 460, 40))
533  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_5_TEST_KB_DELAYS"),
534  move_to_kb_delay_test, -1, -1, 460, 40))
535 }
536 
537 void define_screen_6(std::vector<std::unique_ptr<gui_element>>& elems) {
538  elems.clear();
539 
540  app_workspace* app_wrk = app_workspace::get_instance().get();
541 
542  if (app_wrk->has_user()) {
543  if (app_wrk->userspace->get_user()->role <= 1) {
544  INSERT_ELEMENT(new gui_label(get_localized_text("GT_INSUFFICIENT_PERMISSION")))
545  EMPTY_LINE
546  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_5_ADMIN_SCREEN_ONLY")))
547  return;
548  }
549  } else {
550  INSERT_ELEMENT(new gui_label(get_localized_text("GT_SCREEN_REQUIRE_USER")))
551  EMPTY_LINE
552  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_FUNCTION_DESCRIPTION")))
553  return;
554  }
555 
556  if (app_wrk->hx_measuring) {
557  if (app_wrk->s6_tare_complete) {
558  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_CALIBRATING")))
559  } else if (app_wrk->test_hx_testing) {
560  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_TESTING_IN_PROGRESS")))
561  } else {
562  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_TARING")))
563  }
564 
565  return;
566  }
567 
568  if (app_wrk->s5_screen_6_indicator == S5_TO_S6_CALIBRATION) { // calibration
569  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_REF_UNIT_LAB"), -1, -1, 220))
570  SAME_LINE
571  INSERT_ELEMENT(new gui_input(input_type::IN_INT, &(app_wrk->s6_ref_mass_in), 0, 220, -1, 200))
572 
573  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_4_UNITS_LAB"), -1, -1, 220))
574  SAME_LINE
576  &(app_wrk->s6_selected_unit_option), nullptr, 220, -1, 200))
577 
578  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_SAMPLES_LAB"), -1, -1, 220))
579  SAME_LINE
580  INSERT_ELEMENT(new gui_input(input_type::IN_INT, &(app_wrk->s6_samples_in), 0, 220, -1, 200))
581  ((gui_input*) last_element(elems))->set_min_max(S6_MIN_SAMPLES_IN, S6_MAX_SAMPLES_IN); // WARNING! - if used after wrong element, application crashes on startup
582 
583  EMPTY_LINE
584 
585  if (app_wrk->s6_tare_complete) {
586  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_CALIBRATION_REQ")))
587  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_6_START_CALIBRATION"),
588  start_calibration, -1, -1, 460, 40))
589  } else {
590  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_TARE_REQ")))
591  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_6_START_TARE"),
592  start_tare, -1, -1, 460, 40))
593  }
594 
595  if (app_wrk->s6_calibration_finished) {
596  EMPTY_LINE
597  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_REF_UNIT_LAB"), -1, -1, 240))
598  SAME_LINE
599  INSERT_ELEMENT(new gui_label(app_wrk->s6_ref_mass_str.c_str()))
600 
601  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_HX_REF_UNIT_LAB"), -1, -1, 240))
602  SAME_LINE
604 
605  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_HX_OFFSET_LAB"), -1, -1, 240))
606  SAME_LINE
608 
609  EMPTY_LINE
610  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_6_APPLY_CAL"),
611  apply_calibration, -1, -1, 460, 40))
612 
613  // EMPTY_LINE
614  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_MAKE_PERMANENT_LAB")))
615  }
616  } else if (app_wrk->s5_screen_6_indicator == S5_TO_S6_USERADD) { // user addition
617  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_ROLE"), -1, -1, 220))
618  SAME_LINE
620  &(app_wrk->s6_selected_role), nullptr, 220, -1, 200))
621 
622  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_USERNAME"), -1, -1, 220))
623  SAME_LINE
625 
626  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_PASSWORD"), -1, -1, 220))
627  SAME_LINE
629  DEF_BUFF_SIZE_SMALL, 220, -1, 200))
630 
631  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_RFID_IND"), -1, -1, 280))
632  SAME_LINE
634  get_localized_text("GT_YES") :
635  get_localized_text("GT_NO")), -1, -1, 220))
636 
637  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_DESCRIPTION"), -1, -1, 220))
638  SAME_LINE
640 
641  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_NAME"), -1, -1, 220))
642  SAME_LINE
643  INSERT_ELEMENT(new gui_input(input_type::IN_TEXT, &(app_wrk->s6_name_in), DEF_BUFF_SIZE, 220, -1, 200))
644 
645  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_LASTNAME"), -1, -1, 220))
646  SAME_LINE
648 
649  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_DOB"), -1, -1, 300))
650 
651  INDENT
652 
653  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_YEAR"), -1, -1, 220))
654  SAME_LINE
655  INSERT_ELEMENT(new gui_input(input_type::IN_INT, &(app_wrk->s6_year_in), 0, 220, -1, 200))
656  std::time_t ct_tmp = std::time(nullptr);
657  std::tm *current_time = std::localtime(&ct_tmp);
658  int year_max = current_time->tm_year + 1900; // tm_year is a year since 1900 (e.g: 122 = 2022)
659  ((gui_input*) last_element(elems))->set_min_max(YEAR_MIN, year_max); // WARNING! - if used after wrong element, application crashes on startup
660 
661 
662  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_MONTH"), -1, -1, 220))
663  SAME_LINE
665  &(app_wrk->s6_selected_month), nullptr, 220, -1, 200))
666 
667  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_USR_DAY"), -1, -1, 220))
668  SAME_LINE
669  INSERT_ELEMENT(new gui_input(input_type::IN_INT, &(app_wrk->s6_day_in), 0, 220, -1, 200))
670  ((gui_input*) last_element(elems))->set_min_max(DAY_MIN, DAY_MAX); // WARNING! - if used after wrong element, application crashes on startup
671 
672  UNINDENT
673 
674  EMPTY_LINE
675  INSERT_ELEMENT(new gui_button(get_localized_text("SCREEN_6_USR_ADD"),
676  register_user, -1, -1, 460, 40))
677  } else if (app_wrk->s5_screen_6_indicator == S5_TO_S6_HX_TEST_SAMPLES) { // testing hx with sample count
678  INSERT_ELEMENT(new gui_label(get_localized_text("GT_RESULTS")))
679  EMPTY_LINE
680 
681  for (int i = 0; i < (HX_TEST_CONST_IT_COUNT + HX_TEST_INC_IT_COUNT); i++) {
682  INSERT_ELEMENT(new gui_label(app_wrk->test_hx_samples_times[i].second.c_str()))
683  }
684  } else if (app_wrk->s5_screen_6_indicator == S5_TO_S6_HX_TEST_TIMEOUT) { // testing hx with timeout
685  INSERT_ELEMENT(new gui_label(get_localized_text("GT_RESULTS")))
686  EMPTY_LINE
687 
688  for (int i = 0; i < (HX_TEST_CONST_IT_COUNT + HX_TEST_INC_IT_COUNT); i++) {
689  INSERT_ELEMENT(new gui_label(app_wrk->test_hx_timeout_collected[i].second.c_str()))
690  }
691  } else if (app_wrk->s5_screen_6_indicator == S5_TO_S6_KB_DELAY_TEST) {
692  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_KB_TESTING_TIP1")))
693  EMPTY_LINE
694  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_KB_TESTING_TIP")))
695 
696  EMPTY_LINE
697  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_STOP_TESTING_HASH")))
698  EMPTY_LINE
699 
700  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_KB_DELAY_MS")))
701  SAME_LINE
703 
704  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_KB_DELAY_US")))
705  SAME_LINE
707  } else {
708  INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_6_WRONG_INDICATOR")))
709  }
710 }
711 
713 
714 void define_screen_1_debug(std::vector<std::unique_ptr<gui_element>>& elems) {
715  elems.clear();
716 
717  INSERT_ELEMENT(new gui_label("Inputs test", -1, -1, -1, app_workspace_ns::font_size::BIG_FONT))
718  INSERT_ELEMENT(new gui_label("Int input"))
719  // for non-text inputs "data_size" doesn't matter
721  INSERT_ELEMENT(new gui_label("Float input"))
722  // for non-text inputs "data_size" doesn't matter
724  INSERT_ELEMENT(new gui_label("Text input"))
726  INSERT_ELEMENT(new gui_label("Password input"))
728  EMPTY_LINE
732 
733  INSERT_ELEMENT(new gui_label("Following line is defined with absolute positions and width (that's why the position"
734  " is misaligned to other elements", -1, -1, -1, app_workspace_ns::font_size::SMALL_FONT))
735  INSERT_ELEMENT(new gui_label("Int input:", 20, 500, 200))
736  INSERT_ELEMENT(new gui_input(input_type::IN_INT, &(app_workspace::get_instance()->int_test), 0, 200, 500, 100))
737  INSERT_ELEMENT(new gui_label("This should be on next line", -1, -1, -1, app_workspace_ns::font_size::SMALL_FONT))
738  // newly added gui_observer -test
739  INSERT_ELEMENT(new gui_label("Int observable: ", -1, -1, -1, app_workspace_ns::font_size::SMALL_FONT))
740  SAME_LINE
741  INSERT_ELEMENT(new gui_observer(OBS_INT, &(app_workspace::get_instance()->int_test), -1, -1, -1,
743  INSERT_ELEMENT(new gui_label("Float observable: ", -1, -1, -1, app_workspace_ns::font_size::SMALL_FONT))
744  SAME_LINE
745  INSERT_ELEMENT(new gui_observer(OBS_FLOAT, &(app_workspace::get_instance()->float_test), -1, -1, -1,
747  INSERT_ELEMENT(new gui_label("String observable: ", -1, -1, -1, app_workspace_ns::font_size::SMALL_FONT))
748  SAME_LINE
751 
752  /* // testing const char* as parameter instead char[]
753  static const char* test = "Test string";
754  elems.push_back(std::unique_ptr<gui_element>(
755  new gui_observer(OBS_STRING, (void*) test)
756  ));
757  */
758 }
759 
760 
761 // variables used in debug callback in screen_2_debug
762 static bool cb_flag = false;
763 static int cb_cnt = 0;
764 
765 void define_screen_2_debug(std::vector<std::unique_ptr<gui_element>>& elems) {
766  elems.clear();
767 
768  static const char* first[] = {"One", "Two", "Three"};
769  static int selected_s2d = 0;
770  //static const char* second[] = {"Jedna", "Dva", "Tri"};
771 
772  INSERT_ELEMENT(new gui_label("Switched to screen 2"))
773  INSERT_ELEMENT(new gui_label("Select box test, button (callback) test, graph?",
775  EMPTY_LINE
776 
777  // elems.push_back(std::unique_ptr<gui_element>(
778  // new gui_combobox(second, 3, "Second combobox", -1, -1, 150, app_workspace_ns::font_size::SMALL_FONT)
779  // ));
780  INSERT_ELEMENT(new gui_combobox(first, 3, &selected_s2d))
781  // elems.push_back(std::unique_ptr<gui_element>(
782  // new gui_combobox(second, 3, "Second combobox", -1, -1, 200, app_workspace_ns::font_size::BIG_FONT)
783  // ));
784 
785  EMPTY_LINE
786  INSERT_ELEMENT(new gui_button("Test Button", callback_debug, -1, -1, 400, 50))
787  if (cb_flag) {
788  INSERT_ELEMENT(new gui_label("Press the button!"))
789  } else {
790  INSERT_ELEMENT(new gui_label("Great! press it again!"))
791  }
792 
793  static char at[32];
794  sprintf(at, "Callback counter: %d", cb_cnt);
795  INSERT_ELEMENT(new gui_label(at))
796 }
797 
798 void define_screen_3_debug(std::vector<std::unique_ptr<gui_element>>& elems) {
799  elems.clear();
800 
801  static char fake_in[128];
802  static int selected_s3d = 0;
803 
804  // following label doesnt work, why?
805  INSERT_ELEMENT(new gui_label("Label size TEST small", -1, -1, -1, app_workspace_ns::font_size::SMALL_FONT))
806  INSERT_ELEMENT(new gui_label("Label size TEST normal", -1, -1, -1, app_workspace_ns::font_size::NORMAL_FONT))
807  INSERT_ELEMENT(new gui_label("Label size TEST big", -1, -1, -1, app_workspace_ns::font_size::BIG_FONT))
808  EMPTY_LINE
809 
810  INSERT_ELEMENT(new gui_input(IN_TEXT, fake_in, 128, -1, -1, -1, "label", app_workspace_ns::font_size::SMALL_FONT))
811  INSERT_ELEMENT(new gui_input(IN_TEXT, fake_in, 128, -1, -1, -1, "label", app_workspace_ns::font_size::NORMAL_FONT))
812  INSERT_ELEMENT(new gui_input(IN_TEXT, fake_in, 128, -1, -1, -1, "label", app_workspace_ns::font_size::BIG_FONT))
813  EMPTY_LINE
814 
815  static const char* combo[] = {"Test", "Pokus"};
816 
817  INSERT_ELEMENT(new gui_combobox(combo, 2, &selected_s3d, "Combobox", -1, -1, 150,
819  INSERT_ELEMENT(new gui_combobox(combo, 2, &selected_s3d, "Combobox", -1, -1, 150,
821  INSERT_ELEMENT(new gui_combobox(combo, 2, &selected_s3d, "Combobox", -1, -1, 150,
823  EMPTY_LINE
827 }
828 
829 void define_screen_4_debug(std::vector<std::unique_ptr<gui_element>>& elems) {
830  elems.clear();
831 
832  // elems.push_back(std::unique_ptr<gui_element>(
833  // new gui_direct(render_line)
834  // ));
840  // elems.push_back(std::unique_ptr<gui_element>(
841  // new gui_direct(render_vert)
842  // ));
850 
851  static char in1[32], in2[32], in3[32], in4[32];
852  EMPTY_LINE
853  INSERT_ELEMENT(new gui_input(IN_TEXT, in1, 32, -1, -1, 50, "in 1"))
854  SAME_LINE
855  INSERT_ELEMENT(new gui_input(IN_TEXT, in2, 32, -1, -1, 50, "in 2"))
856  SAME_LINE
857  INSERT_ELEMENT(new gui_input(IN_TEXT, in3, 32, -1, -1, 50, "in 3"))
858  INSERT_ELEMENT(new gui_input(IN_TEXT, in4, 32, -1, -1, 50, "in 4"))
859 
860  // text wrapping bug fix test
861  // INSERT_ELEMENT(new gui_label(get_localized_text("SCREEN_2_SAMPLES_IN_LIMITS"), -1, -1, 100))
862  // INSERT_ELEMENT(new gui_direct(text_wrap_debug))
863 }
864 
865 void define_screen_5_debug(std::vector<std::unique_ptr<gui_element>>& elems) {
866  elems.clear();
867 
868  INSERT_ELEMENT(new gui_label("Test/ debug functions dont always have GUI. View logs for information",
870  INSERT_ELEMENT(new gui_button("Test db function", invoke_sql_debug, -1, -1, 460, 40))
871  INSERT_ELEMENT(new gui_button("HX samples scale", invoke_sql_debug, -1, -1, 460, 40))
872  INSERT_ELEMENT(new gui_button("HX timeout scale", invoke_sql_debug, -1, -1, 460, 40))
873  // INSERT_ELEMENT(new gui_label("Scale result: "))
874  // SAME_LINE
875 
876  INSERT_ELEMENT(new gui_button("Test sql 1", invoke_sql_debug, -1, -1, 460, 40))
877  INSERT_ELEMENT(new gui_button("Test login sql", test_user_login_sql, -1, -1, 460, 40))
878  INSERT_ELEMENT(new gui_button("Test creds sql", test_user_creds_sql, -1, -1, 460, 40))
879  INSERT_ELEMENT(new gui_button("Test headers sql", test_user_meas_header_sql, -1, -1, 460, 40))
880  INSERT_ELEMENT(new gui_button("Test increment sql", test_user_inc_measur_cnt, -1, -1, 460, 40))
881  INSERT_ELEMENT(new gui_button("Test uname ava sql", test_user_is_uname_avail, -1, -1, 460, 40))
882  INSERT_ELEMENT(new gui_button("Test rfid ava sql", test_user_is_rfid_avail, -1, -1, 460, 40))
883  // INSERT_ELEMENT(new gui_button("Err test 1", test_errscr_1, -1, -1, 460, 40))
884  // INSERT_ELEMENT(new gui_button("Err test 2", test_errscr_2, -1, -1, 460, 40))
885 
886  // INSERT_ELEMENT(new gui_button("Update user rfids", update_rfids_debug, -1, -1, 460, 40))
887  // INSERT_ELEMENT(new gui_button("Insert user tst", test_user_insert, -1, -1, 460, 40))
888  // INSERT_ELEMENT(new gui_button("Insert measur tst", test_measurement_insert, -1, -1, 460, 40))
889  INSERT_ELEMENT(new gui_button("Insert measur tst", test_measurement_query, -1, -1, 460, 40))
890 
891 }
892 
893 
894 /*********************************************************************************************************************/
895 /* Implementation of local function definitions */
896 /*********************************************************************************************************************/
897 
898 void empty_line() {
899  ImGui::NewLine();
900 }
901 
902 void same_line() {
903  ImGui::SameLine();
904 }
905 
907  ImGuiWindowFlags window_flags = ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_NavFlattened;
908  ImVec2 content_reg = ImGui::GetContentRegionAvail();
909  content_reg.y -= 20;
910  // ImGui::BeginChild("ScrollableRegion", content_reg, false, window_flags);
911  ImGui::BeginChildFrame(ImGui::GetID("ScrollableRegion"), content_reg, window_flags);
912 }
913 
915  ImGui::EndChildFrame();
916 }
917 
918 void login_action() {
919  app_workspace::get_instance()->log_in_user_cred();
920 }
921 
923  app_workspace::get_instance()->login_subuser();
924 }
925 
927  app_workspace::get_instance()->logoff_user();
928 }
929 
931  app_workspace::get_instance()->logout_subuser();
932 }
933 
934 gui_element* last_element(std::vector<std::unique_ptr<gui_element>> &elems) {
935  return elems.at(elems.size() - 1).get();
936 }
937 
938 void cb() {
939  /*
940  app_workspace::get_instance()->user_logged = !app_workspace::get_instance()->user_logged;
941  app_workspace::get_instance()->get_scr_mgr()->refresh_screen_elements(1);
942  */
943  printf("Test callback\n");
944 }
945 
946 void draw_rect() {
947  ImDrawList *wdl = ImGui::GetWindowDrawList();
948  //ImVec2 wpos = ImGui::GetWindowPos();
949  ImVec2 lis = ImGui::GetItemRectMin();
950  ImVec2 lie = ImGui::GetItemRectMax();
951  wdl->AddRect(lis, lie, IM_COL32(255, 0, 0, 255));
952  //wdl->AddRect(ImVec2(wpos.x + 200, wpos.y + 300),
953  // ImVec2(wpos.x + 350, wpos.y + 300 + (float) app_workspace_ns::font_size::NORMAL_FONT), IM_COL32(255, 0, 0, 255));
954 }
955 
957  ImGui::Text("Int test: %d", app_workspace::get_instance()->int_test);
958 }
959 
961  ImGui::Text("Int test: %f", app_workspace::get_instance()->float_test);
962 }
963 
965  ImGui::Text("Text test: %s", app_workspace::get_instance()->text_test);
966 }
967 
968 void render_line() {
969  ImDrawList *wdl = ImGui::GetWindowDrawList();
970  ImVec2 wpos = ImGui::GetWindowPos();
971  wdl->AddLine(ImVec2(wpos.x + 20, wpos.y + 50), ImVec2(wpos.x + 460, wpos.y + 50), IM_COL32(255, 0, 0, 255), 1.0f);
972 }
973 
974 void render_vert() {
975  ImDrawList *wdl = ImGui::GetWindowDrawList();
976  ImVec2 wpos = ImGui::GetWindowPos();
977  wdl->AddLine(ImVec2(wpos.x + 98, wpos.y + 50), ImVec2(wpos.x + 98, wpos.y + 74), IM_COL32(0, 0, 0, 255), 1.0f);
978 }
979 
980 void empty_cb() {
981  printf("empty callback was called\n");
982 }
983 
985  cb_flag = !cb_flag;
986  cb_cnt++;
987  app_workspace::get_instance()->get_scr_mgr()->refresh_screen_elements(2);
988 }
989 
991  /*
992  app_workspace *app_wrk = app_workspace::get_instance().get();
993  uint8_t fake_serial[10] = {0};
994  for (int i = 0; i < 5; i++) {
995  fake_serial[i] = '1' + i;
996  }
997  user_cont *usr = (user_cont*) calloc(1, sizeof(user_cont));
998  app_wrk->db_conn->query_user_data(usr, nullptr, fake_serial, 5);
999  */
1000 
1001 // app_workspace::get_instance()->db_conn->test_insert_with_binary();
1002  app_workspace::get_instance()->db_conn->test_select_with_binary();
1003 }
1004 
1006  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1007  user_cont *usr = (user_cont*) calloc(1, sizeof(user_cont));
1008 
1009  int rv = conn->query_user_data(usr, "test_emp");
1010  if (rv)
1011  spdlog::error("screen_definition.cpp - user login test: expected user to be initialized!");
1012  else
1013  usr->log_user_to_debug();
1014 }
1015 
1017  int rv;
1018  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1019  user_cred creds;
1020 
1021  char passwd_wrong[64] = "This is wrong password";
1022  char passwd_correct[64] = "9999"; // this password is used on desktop version (only) !!
1023 
1024  rv = conn->query_user_credentials(&creds, "wrong_uname");
1025  if (rv == 2) {
1026  spdlog::info("screen_definition.cpp - user cred test: wrong username works as expected.");
1027  } else {
1028  spdlog::error("screen_definition.cpp - user cred test: unexpected result for wrong username supplied.");
1029  }
1030 
1031  rv = conn->query_user_credentials(&creds, "test_emp");
1032  if (rv) {
1033  spdlog::error("screen_definition.cpp - user cred test: unexpected failure of correct username");
1034  } else {
1035  if (strcmp(creds.passwd, passwd_wrong)) {
1036  spdlog::info("screen_definition.cpp - user cred test: comparing wrong passwords if false as expected");
1037  } else {
1038  spdlog::error("screen_definition.cpp - user cred test: didnt expect true comparison with wrong password");
1039  }
1040  if (strcmp(creds.passwd, passwd_correct)) {
1041  spdlog::error("screen_definition.cpp - user cred test: correct passwd, false comparison");
1042  } else {
1043  spdlog::info("screen_definition.cpp - user cred test: correct password, ture comparison");
1044  }
1045  }
1046 }
1047 
1049  int rv;
1050  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1051  user_cont *usr = (user_cont*) calloc(1, sizeof(user_cont));
1052 
1053  rv = conn->query_user_data(usr, "test_pac");
1054  if (rv) {
1055  spdlog::error("screen_definition.cpp - user header fetch: failed to load user");
1056  return;
1057  }
1058 
1059  rv = conn->query_measurement_headers(usr);
1060  if (rv) {
1061  spdlog::error("screen_definition.cpp - user header fetch: failed to fetch measurement headers");
1062  return;
1063  }
1064 
1065  for (size_t i = 0; i < usr->measur_headers.size(); i++) {
1066  measurement_header *h = usr->measur_headers.at(i).get();
1067  char buf[64] = {0};
1068  strftime(buf, 64, "%Y-%m-%d %H:%M:%S", &(h->measuring_start));
1069  printf("screen_definition.cpp - user header fetch: header %ld (id: {%ld}), {%s}\n",
1070  h->measurement_number, h->id, buf);
1071  // spdlog::info("screen_definition.cpp - user header fetch: header {0} (id: {1}), {3}",
1072  // h->measurement_number, h->id);
1073  }
1074 }
1075 
1077  int rv;
1078  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1079 
1080  // 3 = test_adm
1081  rv = conn->increment_user_measurement_count(3);
1082  if (rv) {
1083  spdlog::error("screen_definition.cpp - failed to increment user measurement count");
1084  return;
1085  } else {
1086  spdlog::info("screen_definition.cpp - increment success. Please check db to verify");
1087  }
1088 }
1089 
1091  int rv;
1092  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1093 
1094  rv = conn->is_username_available("test_emp");
1095  if (rv == 3) {
1096  spdlog::info("screen_definition.cpp - uname availability test: taken");
1097  } else {
1098  spdlog::error("screen_definition.cpp - uname availability test: unexpected rv ({0})", rv);
1099  }
1100 
1101  rv = conn->is_username_available("asdfjlkzcjv");
1102  if (rv) {
1103  spdlog::error("screen_definition.cpp - uname availability test: unexpected rv ({0})", rv);
1104  } else {
1105  spdlog::info("screen_definition.cpp - uname availability test: available");
1106  }
1107 }
1108 
1110  uint8_t valid[4] = {70, 80, 150, 5};
1111  uint8_t exist[4] = {0x31, 0x32, 0x33, 0x34};
1112  int rv;
1113  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1114 
1115  rv = conn->is_rfid_serial_available(exist, 4);
1116  if (rv == 3) {
1117  spdlog::info("screen_definition.cpp - rfid availability test: taken");
1118  } else {
1119  spdlog::error("screen_definition.cpp - rfid availability test: unexpected rv ({0})", rv);
1120  }
1121 
1122  rv = conn->is_rfid_serial_available(valid, 4);
1123  if (rv) {
1124  spdlog::error("screen_definition.cpp - rfid availability test: unexpected rv ({0})", rv);
1125  } else {
1126  spdlog::info("screen_definition.cpp - rfid availability test: available");
1127  }
1128 }
1129 
1131  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1132  user_cont *usr = (user_cont*) calloc(1, sizeof(user_cont));
1133 
1134  usr->role = 2;
1135  usr->username = "admin";
1136  usr->name = "a";
1137  usr->lastname = "b";
1138  std::time_t time;
1139  std::time(&time);
1140  std::tm *dob = std::localtime(&time);
1141  usr->date_of_birth = *dob;
1142 
1143  int rv = conn->insert_user(usr, "heslo1");
1144  if (rv) {
1145  spdlog::error("screen_definition.cpp - user insert test 1: failed");
1146  }
1147 
1148  usr->role = 0;
1149  usr->username = "asdf";
1150  rv = conn->insert_user(usr, "");
1151  if (rv) {
1152  spdlog::error("screen_definition.cpp - user insert test 2: failed");
1153  }
1154  free(usr);
1155 }
1156 
1158  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1159  measurement *m = (measurement*) calloc(1, sizeof(measurement));
1160 
1161  std::vector<double> v{5.0, 128.782, 0, 1234.1, 123.0};
1162  m->values = v;
1163  m->x_val_med = 4.8;
1164  m->x_val_avg = 5.2;
1165  m->all_val_med = 8.7;
1166  m->all_val_avg = 8.5;
1167  m->measuree_id = 1;
1168  m->measurer_id = 1;
1169  m->measurement_number = 5;
1170  m->measuring_length = 899988123;
1171 
1172  std::time_t time;
1173  std::time(&time);
1174  std::tm *a = std::localtime(&time);
1175 
1176  m->measuring_start = *a;
1177  m->measuring_end = *a;
1178 
1179  int rv = conn->insert_measurement(m);
1180  if (rv) {
1181  spdlog::error("screen_definition.cpp - measurement insert: failed");
1182  }
1183 
1184  free(m);
1185 }
1186 
1188  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1189  measurement *m = new measurement();
1190 
1191  int rv = conn->query_measurement(m, 6);
1192  if (rv) {
1193  spdlog::error("screen_definition.cpp - measurement query: failed");
1194  }
1195 
1196  delete(m);
1197 }
1198 
1200  int rv;
1201  db_driver *conn = app_workspace::get_instance()->db_conn.get();
1202  uint8_t blue_tag[4] = {5, 27, 239, 190}; // read from debug
1203  uint8_t white_tag[4] = {192, 1, 15, 26}; // read from debug
1204 
1205  rv = conn->update_user_rfid(2, blue_tag, 4); // id = 2 - test employee
1206  if (rv) {
1207  spdlog::error("screen_definition.cpp - rfid update failure");
1208  } else {
1209  spdlog::info("screen_definition.cpp - rfid update success");
1210  }
1211 
1212  rv = conn->update_user_rfid(1, white_tag, 4); // id = 1 - test patient
1213  if (rv) {
1214  spdlog::error("screen_definition.cpp - rfid update failure");
1215  } else {
1216  spdlog::info("screen_definition.cpp - rfid update success");
1217  }
1218 }
1219 
1221 
1222 }
1223 
1225 
1226 }
1227 
1229  int width = 200;
1230  int x = -1;
1231  float wrap_width = (width + (x > -1 ? x : 0)) > 480 ? (480 - x - 10) : width;
1232  ImVec2 cpos = ImGui::GetCursorPos();
1233  ImGui::PushTextWrapPos(cpos.x + wrap_width);
1234  ImGui::Text("22 2 22222222222 22222 222222222222 222222222 22222222222 222 222222");
1235  ImGui::PopTextWrapPos();
1236 }
1237 
1238 void indent() {
1239  ImGui::Indent(custom_indent);
1240 }
1241 
1242 void unindent() {
1243  ImGui::Unindent(custom_indent);
1244 }
1245 
1247  app_workspace::get_instance()->set_err_screen_and_activate(get_localized_text("ERR_USERS_FULL"),
1248  get_localized_text("ERR_USERS_FULL_DESC"));
1249  // app_workspace::get_instance()->set_err_screen_and_activate("Error 1",
1250  // "This is a test. Created by callback 1");
1251 }
1252 
1254  app_workspace::get_instance()->set_err_screen_and_activate("Error 2",
1255  "This is a also test. Created by callback 2");
1256 }
1257 
1259  int rv = app_workspace::get_instance()->hx711_measure();
1260  if (rv != 0) {
1261  spdlog::error("screen_definition.cpp - HX measuring callback: measuring failed with error code {0}", rv);
1262  }
1263 }
1264 
1266  int rv = app_workspace::get_instance()->hx711_continuous_measure();
1267  if (rv != 0) {
1268  spdlog::error("screen_definition.cpp - HX measuring callback: failed to start measuring"
1269  " with error code {0}", rv);
1270  }
1271 }
1272 
1274  app_workspace *app_wrk = app_workspace::get_instance().get();
1275  measurement_header* header =
1276  app_wrk->userspace->get_measured_user()->measur_headers.at(app_wrk->selected_measuring).get();
1277 
1278  int rv = app_wrk->db_conn->is_measurement_continuous(header->measurement_number, header->measuree_id);
1279  if (rv == 0) { // continuous measuring
1280  rv = app_wrk->db_conn->query_continuous_measurement(app_wrk->userspace->continuous_m,
1281  header->measurement_number, header->measuree_id);
1282  if (rv) {
1283  spdlog::error("screen_definition.cpp - Failed to fetch continuous measurment.");
1284  app_wrk->set_err_screen_and_activate(get_localized_text("ERR_S4_QUERY_FAILED"),
1285  get_localized_text("ERR_S4_SELECTED_MEASUREMENT_CANNOT_DISPLAY"));
1286  return;
1287  }
1288 
1289  spdlog::debug("screen_definition.cpp - Successfully retrieved continuous measurement. Preparing to be shown..");
1290 
1291  app_wrk->userspace->picked.reset(new measurement());
1292  measurement::prepare_continuous_to_picked(app_wrk->userspace->continuous_m, app_wrk->userspace->picked.get());
1293  } else { // if measurement is single or error (on error attempt to retrieve single measurement anyway)
1294  measurement* m = new measurement();
1295  rv = app_wrk->db_conn->query_measurement(m, header->id);
1296  if (rv) {
1297  spdlog::error("screen_definition.cpp - Failed to fetch measurement detail (rv: {0})."
1298  " More details from db_driver logs.", rv);
1299  app_wrk->set_err_screen_and_activate(get_localized_text("ERR_S4_QUERY_FAILED"),
1300  get_localized_text("ERR_S4_SELECTED_MEASUREMENT_CANNOT_DISPLAY"));
1301  return;
1302  } else {
1303  spdlog::debug("screen_definition.cpp - Successfully retrieved measurement to be shown");
1304  app_wrk->userspace->picked.reset(m);
1305  }
1306  }
1307 
1308  // fetch username of measuree and measurer and init convienince vars
1309  std::string uname;
1310  rv = app_wrk->db_conn->query_username(uname, app_wrk->userspace->picked->measurer_id);
1311  if (rv) {
1312  spdlog::error("app_workspace.cpp - hx711_measurement: Failed to retrieve measurer username.");
1313  // failed to retrieve username, but measurement data is already selected
1314  app_wrk->userspace->picked->init_convinience_vars("DB ERR", "DB ERR");
1315  } else {
1316  if (app_wrk->userspace->picked->measurer_id != app_wrk->userspace->picked->measuree_id) {
1317  std::string sub_uname;
1318  rv = app_wrk->db_conn->query_username(sub_uname, app_wrk->userspace->picked->measuree_id);
1319 
1320  if (rv) {
1321  spdlog::error("app_workspace.cpp - hx711_measurement: Failed to retrieve measuree username.");
1322  app_wrk->userspace->picked->init_convinience_vars(uname.c_str(), "DB ERR");
1323  } else {
1324  app_wrk->userspace->picked->init_convinience_vars(uname.c_str(), sub_uname.c_str());
1325  }
1326  } else {
1327  app_wrk->userspace->picked->init_convinience_vars(uname.c_str(), uname.c_str());
1328  }
1329  }
1330 
1333 }
1334 
1336  app_workspace::get_instance()->get_scr_mgr()->refresh_screen_elements(3);
1337 }
1338 
1340  app_workspace *app_wrk = app_workspace::get_instance().get();
1341 
1342  if (!app_wrk->has_user()) return; // this shouldn't really uccur
1343  app_wrk->userspace->picked->current_unit = app_wrk->unit_selection[app_wrk->selected_unit_option];
1344  app_wrk->userspace->picked->init_value_strings();
1345  app_wrk->refresh_current_screen = true;
1346 }
1347 
1349  app_workspace *app_wrk = app_workspace::get_instance().get();
1350 
1354 }
1355 
1357  app_workspace *app_wrk = app_workspace::get_instance().get();
1358 
1362 }
1363 
1365  app_workspace *app_wrk = app_workspace::get_instance().get();
1366 
1368  // app_wrk->get_scr_mgr()->refresh_screen_elements(ADMIN_CTRL_SCREEN);
1370  app_wrk->test_hx_samples(); // refresh_screen_elements is called inside this function
1371 }
1372 
1374 app_workspace *app_wrk = app_workspace::get_instance().get();
1375 
1377  // app_wrk->get_scr_mgr()->refresh_screen_elements(ADMIN_CTRL_SCREEN);
1379  app_wrk->test_hx_timeout(); // refresh_screen_elements is called inside this function
1380 }
1381 
1383  app_workspace *app_wrk = app_workspace::get_instance().get();
1384 
1386  app_wrk->set_kb_testing(true);
1389 }
1390 
1391 void start_tare() {
1392  app_workspace *app_wrk = app_workspace::get_instance().get();
1393 
1394  // tare can be ran without having the need for those inputs, but since calibration will follow, check the input
1395  // here as well
1396 
1397  if (app_wrk->s6_ref_mass_in <= 0) {
1398  app_wrk->set_err_screen_and_activate(get_localized_text("ERR_S6_INPUT"),
1399  get_localized_text("ERR_S6_REF_MASS_ERR"));
1400  return;
1401  }
1402 
1403  if (app_wrk->s6_samples_in < S6_MIN_SAMPLES_IN || app_wrk->s6_samples_in > S6_MAX_SAMPLES_IN) {
1404  app_wrk->set_err_screen_and_activate(get_localized_text("ERR_S6_INPUT"),
1405  get_localized_text("ERR_S6_SAMPLES_ERR"));
1406  return;
1407  }
1408 
1409  app_wrk->hx711_tare();
1410 }
1411 
1413  app_workspace *app_wrk = app_workspace::get_instance().get();
1414 
1415  if (app_wrk->s6_ref_mass_in <= 0) {
1416  app_wrk->set_err_screen_and_activate(get_localized_text("ERR_S6_INPUT"),
1417  get_localized_text("ERR_S6_REF_MASS_ERR"));
1418  return;
1419  }
1420 
1421  if (app_wrk->s6_samples_in < S6_MIN_SAMPLES_IN || app_wrk->s6_samples_in > S6_MAX_SAMPLES_IN) {
1422  app_wrk->set_err_screen_and_activate(get_localized_text("ERR_S6_INPUT"),
1423  get_localized_text("ERR_S6_SAMPLES_ERR"));
1424  return;
1425  }
1426 
1427  app_wrk->s6_ref_mass_str = std::to_string(app_wrk->s6_ref_mass_in) + " " +
1428  app_wrk->s6_unit_sel_labels[app_wrk->s6_selected_unit_option];
1429 
1430  app_wrk->hx711_calibrate();
1431 }
1432 
1434  app_workspace *app_wrk = app_workspace::get_instance().get();
1435 
1436  try {
1437  app_wrk->hx711_controller->setReferenceUnit(app_wrk->s6_calib_ref_unit);
1438  app_wrk->hx711_controller->setOffset(app_wrk->s6_calib_offset);
1439  } catch (std::exception &ex) {
1440  spdlog::error("screen_definitions.cpp - Failed to apply HX calibration.");
1441  // FIXME - maybe go to error screen with this
1442  return;
1443  }
1444 
1445  config_loader::replace_opt_in_opt_config(app_wrk->main_config->opt_conf_path.c_str(),
1446  OPT_CFG_OFFSET_KEY, std::to_string(app_wrk->s6_calib_offset));
1447  config_loader::replace_opt_in_opt_config(app_wrk->main_config->opt_conf_path.c_str(),
1448  OPT_CFG_REF_UNIT_KEY, std::to_string(app_wrk->s6_calib_ref_unit));
1449 
1450  spdlog::info("Successfully applied HX711 calibration");
1451 
1455 }
1456 
1458  app_workspace *app_wrk = app_workspace::get_instance().get();
1459  if (app_wrk->register_new_user()) {
1460  spdlog::error("screen_definitions.cpp - Failed to register new user.");
1461  } else {
1465  }
1466 }
#define S5_TO_S6_KB_DELAY_TEST
Definition: app_workspace.h:61
#define UNIT_SEL_CNT
Definition: app_workspace.h:37
#define S2_MAX_SAMPLES_IN
Definition: app_workspace.h:30
#define S6_MAX_SAMPLES_IN
Definition: app_workspace.h:35
#define S3_MIN_FILTER_NUMBER
Definition: app_workspace.h:33
#define S6_ROLE_CNT
Definition: app_workspace.h:41
#define DEF_BUFF_SIZE
Definition: app_workspace.h:23
#define DAY_MIN
Definition: app_workspace.h:44
#define S5_TO_S6_CALIBRATION
Definition: app_workspace.h:57
#define DEF_BUFF_SIZE_EXTRA
Definition: app_workspace.h:27
#define YEAR_MIN
Definition: app_workspace.h:46
#define S5_TO_S6_USERADD
Definition: app_workspace.h:58
#define DEF_BUFF_SIZE_SMALL
Definition: app_workspace.h:22
#define S2_MIN_TIMEOUT_IN
Definition: app_workspace.h:31
#define S2_MIN_SAMPLES_IN
Definition: app_workspace.h:29
#define S5_CALIBRATION_APPLIED
Definition: app_workspace.h:63
#define S6_MIN_SAMPLES_IN
Definition: app_workspace.h:34
#define HX_TEST_CONST_IT_COUNT
Definition: app_workspace.h:52
#define HX_TEST_INC_IT_COUNT
Definition: app_workspace.h:53
#define S5_TO_S6_HX_TEST_TIMEOUT
Definition: app_workspace.h:60
#define S2_MAX_TIMEOUT_IN
Definition: app_workspace.h:32
#define S5_USER_CREATED
Definition: app_workspace.h:64
#define S6_MONTH_CNT
Definition: app_workspace.h:42
#define S2_MEASURE_OTPS_CNT
Definition: app_workspace.h:38
#define S5_FINISHED_KB_DELAYS
Definition: app_workspace.h:65
#define S6_UNIT_SEL_CNT
Definition: app_workspace.h:40
#define DAY_MAX
Definition: app_workspace.h:45
#define S3_FILTER_OPT_CNT
Definition: app_workspace.h:39
#define S5_TO_S6_HX_TEST_SAMPLES
Definition: app_workspace.h:59
One of the most importat classes in the whole project. Holds variables that define the state of the a...
std::unique_ptr< custom_hx711 > hx711_controller
HX711 controller. This is an instance of custom_hx711 which extends library's AdvancedHX711.
std::string s6_ref_mass_str
static std::unique_ptr< app_workspace > & get_instance()
Get the instance app_workspace which is a singleton.
bool s6_calibration_finished
user_workspace * get_userspace()
void set_err_screen_and_activate(const char *title, const char *label)
Set the err screen and activate the screen on next frame.
bool s6_rfid_indicator
const HX711::Mass::Unit unit_selection[UNIT_SEL_CNT]
void hx711_tare()
Function that performs taring on the hx711 controller.
int s5_screen_6_indicator
const char * s6_month_labels[S6_MONTH_CNT]
std::unique_ptr< db_driver > db_conn
Database driver holder.
std::unique_ptr< app_config > main_config
Application config loaded from app_config.conf (main config file).
int register_new_user()
This function validets screen 6 buffers and if everything checks out then inserts new user into the D...
const char * s6_role_labels[S6_ROLE_CNT]
int selected_unit_option
std::pair< long, std::string > test_hx_samples_times[HX_TEST_CONST_IT_COUNT+HX_TEST_INC_IT_COUNT]
char s6_passwd_in[DEF_BUFF_SIZE_SMALL]
std::unique_ptr< measurement > observed_measurement
This variable is used to observe measuring.
const char * s3_filter_opt_labels[S3_FILTER_OPT_CNT]
void hx711_calibrate()
Function that performs calibration on the hx711 controller.
bool hx_not_finished_yet
std::pair< long, std::string > test_hx_timeout_collected[HX_TEST_CONST_IT_COUNT+HX_TEST_INC_IT_COUNT]
char s6_name_in[DEF_BUFF_SIZE]
char s6_lastname_in[DEF_BUFF_SIZE_SMALL]
const char * unit_sel_labels[UNIT_SEL_CNT]
bool has_user()
Checks if user is logged in. This is determined by user_space being initialized and having the user_l...
int selected_hx_measure_opt
screen_manager * get_scr_mgr()
Get the screen manager instance. This instance is kind of singleton. Is initalized only once on start...
void set_kb_testing(bool val)
unsigned long s3_filter_number
const char * s6_unit_sel_labels[S6_UNIT_SEL_CNT]
bool refresh_current_screen
When this is set to true, elements of current screen will be reinitialized for next frame.
int s5_success_indicator
char s6_uname_in[DEF_BUFF_SIZE_SMALL]
std::unique_ptr< user_workspace > userspace
User's workspace. Serves similar function as app_workspace but for user data.
int s6_selected_unit_option
char s6_desc_in[DEF_BUFF_SIZE_EXTRA]
const char * hx_measure_opts[S2_MEASURE_OTPS_CNT]
Handles database querries.
Definition: db_driver.h:41
int insert_measurement(measurement *m)
Definition: db_driver.cpp:1765
int is_username_available(const char *uname)
Definition: db_driver.cpp:1405
int is_rfid_serial_available(uint8_t *serial, uint8_t ser_len)
Definition: db_driver.cpp:1461
int insert_user(user_cont *new_usr, const char *password)
Definition: db_driver.cpp:1678
int update_user_rfid(unsigned long user_id, uint8_t *serial, uint8_t ser_len)
Definition: db_driver.cpp:1635
int query_measurement(measurement *m, unsigned long id)
Definition: db_driver.cpp:720
int query_measurement_headers(user_cont *usr)
Definition: db_driver.cpp:580
int query_user_data(user_cont *usr, const char *uname=nullptr, uint8_t *rfid_serial=nullptr, uint8_t rfid_ser_len=0)
Selects all user data into user container @usr. Data is selected by either username or rfid_serial....
Definition: db_driver.cpp:199
int query_user_credentials(user_cred *creds, const char *uname)
Selects username, password and status into @creds filtered by @uname.
Definition: db_driver.cpp:75
int increment_user_measurement_count(unsigned long id)
Definition: db_driver.cpp:1517
Wrapper for ImGui::Button.
Definition: gui_button.h:11
Wrapper for ImGui combo box structure.
Definition: gui_combobox.h:11
This is a special element, that doesn't wrap any ImGui function. This is used to render ImGui directl...
Definition: gui_direct.h:12
Paren class for other gui elements.
Definition: gui_element.h:8
void set_refresh_screen(bool *refresh_flag)
Definition: gui_element.cpp:5
This is a wrapper for various ImGui input types.
Definition: gui_input.h:24
This is a wrapper for ImGui Text which serves as unchangeble label.
Definition: gui_label.h:11
Allows to create a label, that automatically updates to observed variable value. This class doesn't w...
Definition: gui_observer.h:23
This creates an ImGui::Seletable, which can serve as a label that can be navigated to.
Serves as container for basic measurement information, that is dispayed to GUI.
unsigned long measuree_id
unsigned long measurement_number
const char * get_header_label()
unsigned long id
Container for measurement data and (convenience) variables, that are used to show measurement in GUI.
unsigned long measuring_length
unsigned long id
std::string all_val_avg_str
std::string length_str
std::vector< double > values
static void prepare_continuous_to_picked(std::vector< measurement > &ms, measurement *picked)
std::string end_str
std::string all_val_med_str
std::tm measuring_end
double all_val_med
double all_val_avg
std::string x_val_med_str
unsigned long measuree_id
int cont_measurements
unsigned long measurer_id
std::tm measuring_start
std::string start_str
double x_val_avg
double x_val_med
std::string x_val_avg_str
std::string measurer_uname
std::string measuree_uname
unsigned long measurement_number
void set_selected_screen(uint8_t screen)
void refresh_screen_elements(uint8_t screen)
Class used as a container for user data, that are selected from database. (and also for insert,...
std::string lastname
uint8_t role
std::string username
void log_user_to_debug()
std::vector< std::unique_ptr< measurement_header > > measur_headers
std::tm date_of_birth
std::string name
Container that servers for storing users data and manipulating them.
std::string & get_username()
std::unique_ptr< user_cont > subuser
std::string & get_measured_username()
const char * get_role_string()
#define OPT_CFG_REF_UNIT_KEY
Definition: config_loader.h:6
#define OPT_CFG_OFFSET_KEY
Definition: config_loader.h:7
@ IN_INT
Definition: gui_input.h:12
@ IN_PASSWORD_PLAIN
Definition: gui_input.h:16
@ IN_TEXT
Definition: gui_input.h:14
@ IN_PASSWORD
Definition: gui_input.h:15
@ IN_FLOAT
Definition: gui_input.h:13
@ OBS_INT
Definition: gui_observer.h:12
@ OBS_FLOAT
Definition: gui_observer.h:14
@ OBS_LONG
Definition: gui_observer.h:13
@ OBS_STRING
Definition: gui_observer.h:15
const char * get_localized_text(const char *key)
Get the localized text object.
int replace_opt_in_opt_config(const char *cfg_path, std::string key, std::string value)
This is used to replace a values in optional config.
void start_tare()
void apply_meas_list_filter()
void test_user_creds_sql()
void unindent()
void logout_subuser()
void indent()
void text_wrap_debug()
void login_subuser()
void logout_action()
void define_screen_5_debug(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 5.
void open_measuring_detail()
void define_screen_5(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 5.
void update_rfids_debug()
void define_screen_6(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 6.
void define_screen_1(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 1.
void define_screen_0(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 0.
void define_screen_1_debug(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 1.
void move_to_user_addition()
void define_screen_2_debug(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 2.
void float_test_label()
#define SAME_LINE
gui_label * err_title
void test_errscr_1()
void test_user_inc_measur_cnt()
#define INDENT
#define UNINDENT
void callback_debug()
void apply_calibration()
void test_user_is_uname_avail()
void hx_samples_debug()
void define_screen_4(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 4.
void move_to_hx_calibration()
void render_line()
void define_screen_3_debug(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 3.
void start_hx_measuring()
void begin_scrollabe_region()
void move_to_hx_test_samp()
void test_user_insert()
gui_label * err_desc
void move_to_hx_test_time()
void unit_select_action()
void move_to_kb_delay_test()
void define_screen_3(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 3.
void test_user_login_sql()
void cb()
#define INSERT_ELEMENT(ELEMENT)
void register_user()
void start_hx_continuous()
void empty_cb()
void login_action()
void test_measurement_insert()
void test_user_is_rfid_avail()
void define_screen_2(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 2.
void test_measurement_query()
void invoke_sql_debug()
void hx_timeout_debug()
void test_errscr_2()
void empty_line()
void draw_rect()
void end_scrollabe_region()
void render_vert()
gui_element * last_element(std::vector< std::unique_ptr< gui_element >> &elems)
void text_test_label()
void start_calibration()
void same_line()
void int_test_label()
#define EMPTY_LINE
void test_user_meas_header_sql()
void define_screen_4_debug(std::vector< std::unique_ptr< gui_element >> &elems)
Definitions of gui elemnts of debug screen 4.
#define ADMIN_SELECT_SCREEN
#define DETAIL_SCREEN
#define ADMIN_CTRL_SCREEN
Struct used to contain username, password and user status until credentials are verified.
Definition: db_driver.h:30
char passwd[64]
Definition: db_driver.h:33