3 #include <spdlog/spdlog.h>
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));
36 static float custom_indent = 20.0f;
156 if (usr_wrk->
subuser.get() !=
nullptr) {
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))
345 std::vector<std::unique_ptr<measurement_header>> &headers =
348 if (headers.size() <= 0) {
365 for (
size_t i = 0; i < headers.size(); i++) {
374 for (
size_t i = 0; i < headers.size(); i++) {
383 for (
size_t i = 0; i < headers.size(); i++) {
416 if (m ==
nullptr || m->
id <= 0) {
512 if (app_wrk->
userspace->get_user()->role <= 1) {
543 if (app_wrk->
userspace->get_user()->role <= 1) {
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;
733 INSERT_ELEMENT(
new gui_label(
"Following line is defined with absolute positions and width (that's why the position"
762 static bool cb_flag =
false;
763 static int cb_cnt = 0;
768 static const char* first[] = {
"One",
"Two",
"Three"};
769 static int selected_s2d = 0;
794 sprintf(at,
"Callback counter: %d", cb_cnt);
801 static char fake_in[128];
802 static int selected_s3d = 0;
815 static const char* combo[] = {
"Test",
"Pokus"};
851 static char in1[32], in2[32], in3[32], in4[32];
907 ImGuiWindowFlags window_flags = ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_NavFlattened;
908 ImVec2 content_reg = ImGui::GetContentRegionAvail();
911 ImGui::BeginChildFrame(ImGui::GetID(
"ScrollableRegion"), content_reg, window_flags);
915 ImGui::EndChildFrame();
935 return elems.at(elems.size() - 1).get();
943 printf(
"Test callback\n");
947 ImDrawList *wdl = ImGui::GetWindowDrawList();
949 ImVec2 lis = ImGui::GetItemRectMin();
950 ImVec2 lie = ImGui::GetItemRectMax();
951 wdl->AddRect(lis, lie, IM_COL32(255, 0, 0, 255));
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);
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);
981 printf(
"empty callback was called\n");
1011 spdlog::error(
"screen_definition.cpp - user login test: expected user to be initialized!");
1021 char passwd_wrong[64] =
"This is wrong password";
1022 char passwd_correct[64] =
"9999";
1026 spdlog::info(
"screen_definition.cpp - user cred test: wrong username works as expected.");
1028 spdlog::error(
"screen_definition.cpp - user cred test: unexpected result for wrong username supplied.");
1033 spdlog::error(
"screen_definition.cpp - user cred test: unexpected failure of correct username");
1035 if (strcmp(creds.
passwd, passwd_wrong)) {
1036 spdlog::info(
"screen_definition.cpp - user cred test: comparing wrong passwords if false as expected");
1038 spdlog::error(
"screen_definition.cpp - user cred test: didnt expect true comparison with wrong password");
1040 if (strcmp(creds.
passwd, passwd_correct)) {
1041 spdlog::error(
"screen_definition.cpp - user cred test: correct passwd, false comparison");
1043 spdlog::info(
"screen_definition.cpp - user cred test: correct password, ture comparison");
1055 spdlog::error(
"screen_definition.cpp - user header fetch: failed to load user");
1061 spdlog::error(
"screen_definition.cpp - user header fetch: failed to fetch measurement headers");
1069 printf(
"screen_definition.cpp - user header fetch: header %ld (id: {%ld}), {%s}\n",
1083 spdlog::error(
"screen_definition.cpp - failed to increment user measurement count");
1086 spdlog::info(
"screen_definition.cpp - increment success. Please check db to verify");
1096 spdlog::info(
"screen_definition.cpp - uname availability test: taken");
1098 spdlog::error(
"screen_definition.cpp - uname availability test: unexpected rv ({0})", rv);
1103 spdlog::error(
"screen_definition.cpp - uname availability test: unexpected rv ({0})", rv);
1105 spdlog::info(
"screen_definition.cpp - uname availability test: available");
1110 uint8_t valid[4] = {70, 80, 150, 5};
1111 uint8_t exist[4] = {0x31, 0x32, 0x33, 0x34};
1117 spdlog::info(
"screen_definition.cpp - rfid availability test: taken");
1119 spdlog::error(
"screen_definition.cpp - rfid availability test: unexpected rv ({0})", rv);
1124 spdlog::error(
"screen_definition.cpp - rfid availability test: unexpected rv ({0})", rv);
1126 spdlog::info(
"screen_definition.cpp - rfid availability test: available");
1140 std::tm *dob = std::localtime(&time);
1145 spdlog::error(
"screen_definition.cpp - user insert test 1: failed");
1152 spdlog::error(
"screen_definition.cpp - user insert test 2: failed");
1161 std::vector<double> v{5.0, 128.782, 0, 1234.1, 123.0};
1174 std::tm *a = std::localtime(&time);
1181 spdlog::error(
"screen_definition.cpp - measurement insert: failed");
1193 spdlog::error(
"screen_definition.cpp - measurement query: failed");
1202 uint8_t blue_tag[4] = {5, 27, 239, 190};
1203 uint8_t white_tag[4] = {192, 1, 15, 26};
1207 spdlog::error(
"screen_definition.cpp - rfid update failure");
1209 spdlog::info(
"screen_definition.cpp - rfid update success");
1214 spdlog::error(
"screen_definition.cpp - rfid update failure");
1216 spdlog::info(
"screen_definition.cpp - rfid update success");
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();
1239 ImGui::Indent(custom_indent);
1243 ImGui::Unindent(custom_indent);
1255 "This is a also test. Created by callback 2");
1261 spdlog::error(
"screen_definition.cpp - HX measuring callback: measuring failed with error code {0}", rv);
1268 spdlog::error(
"screen_definition.cpp - HX measuring callback: failed to start measuring"
1269 " with error code {0}", rv);
1280 rv = app_wrk->
db_conn->query_continuous_measurement(app_wrk->
userspace->continuous_m,
1283 spdlog::error(
"screen_definition.cpp - Failed to fetch continuous measurment.");
1289 spdlog::debug(
"screen_definition.cpp - Successfully retrieved continuous measurement. Preparing to be shown..");
1295 rv = app_wrk->
db_conn->query_measurement(m, header->
id);
1297 spdlog::error(
"screen_definition.cpp - Failed to fetch measurement detail (rv: {0})."
1298 " More details from db_driver logs.", rv);
1303 spdlog::debug(
"screen_definition.cpp - Successfully retrieved measurement to be shown");
1310 rv = app_wrk->
db_conn->query_username(uname, app_wrk->
userspace->picked->measurer_id);
1312 spdlog::error(
"app_workspace.cpp - hx711_measurement: Failed to retrieve measurer username.");
1314 app_wrk->
userspace->picked->init_convinience_vars(
"DB ERR",
"DB ERR");
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);
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");
1324 app_wrk->
userspace->picked->init_convinience_vars(uname.c_str(), sub_uname.c_str());
1327 app_wrk->
userspace->picked->init_convinience_vars(uname.c_str(), uname.c_str());
1344 app_wrk->
userspace->picked->init_value_strings();
1439 }
catch (std::exception &ex) {
1440 spdlog::error(
"screen_definitions.cpp - Failed to apply HX calibration.");
1450 spdlog::info(
"Successfully applied HX711 calibration");
1460 spdlog::error(
"screen_definitions.cpp - Failed to register new user.");
#define S5_TO_S6_KB_DELAY_TEST
#define S2_MAX_SAMPLES_IN
#define S6_MAX_SAMPLES_IN
#define S3_MIN_FILTER_NUMBER
#define S5_TO_S6_CALIBRATION
#define DEF_BUFF_SIZE_EXTRA
#define DEF_BUFF_SIZE_SMALL
#define S2_MIN_TIMEOUT_IN
#define S2_MIN_SAMPLES_IN
#define S5_CALIBRATION_APPLIED
#define S6_MIN_SAMPLES_IN
#define HX_TEST_CONST_IT_COUNT
#define HX_TEST_INC_IT_COUNT
#define S5_TO_S6_HX_TEST_TIMEOUT
#define S2_MAX_TIMEOUT_IN
#define S2_MEASURE_OTPS_CNT
#define S5_FINISHED_KB_DELAYS
#define S3_FILTER_OPT_CNT
#define S5_TO_S6_HX_TEST_SAMPLES
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.
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]
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.
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.
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.
int insert_measurement(measurement *m)
int is_username_available(const char *uname)
int is_rfid_serial_available(uint8_t *serial, uint8_t ser_len)
int insert_user(user_cont *new_usr, const char *password)
int update_user_rfid(unsigned long user_id, uint8_t *serial, uint8_t ser_len)
int query_measurement(measurement *m, unsigned long id)
int query_measurement_headers(user_cont *usr)
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....
int query_user_credentials(user_cred *creds, const char *uname)
Selects username, password and status into @creds filtered by @uname.
int increment_user_measurement_count(unsigned long id)
Wrapper for ImGui combo box structure.
This is a special element, that doesn't wrap any ImGui function. This is used to render ImGui directl...
Paren class for other gui elements.
void set_refresh_screen(bool *refresh_flag)
This is a wrapper for ImGui Text which serves as unchangeble label.
Allows to create a label, that automatically updates to observed variable value. This class doesn't w...
This creates an ImGui::Seletable, which can serve as a label that can be navigated to.
Container for measurement data and (convenience) variables, that are used to show measurement in GUI.
unsigned long measuring_length
std::string all_val_avg_str
std::vector< double > values
static void prepare_continuous_to_picked(std::vector< measurement > &ms, measurement *picked)
std::string all_val_med_str
std::string x_val_med_str
unsigned long measuree_id
unsigned long measurer_id
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::vector< std::unique_ptr< measurement_header > > measur_headers
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
#define OPT_CFG_OFFSET_KEY
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 apply_meas_list_filter()
void test_user_creds_sql()
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 test_user_inc_measur_cnt()
void test_user_is_uname_avail()
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 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 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()
#define INSERT_ELEMENT(ELEMENT)
void start_hx_continuous()
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 end_scrollabe_region()
gui_element * last_element(std::vector< std::unique_ptr< gui_element >> &elems)
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 ADMIN_CTRL_SCREEN
Struct used to contain username, password and user status until credentials are verified.