Raspberry Pi Weighting Control System
This project serves as a simple weighting control system, that was realized as a Bachelor Thesis
|
One of the most importat classes in the whole project. Holds variables that define the state of the application and also provides logic for some of the variables held there. For example the hx711 controller is held and used from this class. More...
#include <app_workspace.h>
Public Member Functions | |
app_workspace () | |
Construct a new app workspace object. More... | |
void | init_labels () |
This is called after localisation dictionary is loaded. After the dict is loaded arrays defined in app_workspace must be initialized so they can be used in GUI comboboxes. More... | |
int | init_hx711_controller () |
Initializes the hx711 controller. More... | |
void | hx711_tare () |
Function that performs taring on the hx711 controller. More... | |
void | hx711_calibrate () |
Function that performs calibration on the hx711 controller. More... | |
int | hx711_measure () |
Performs hx711 measuring with set values of either samples or timeout. The results is saved to the database and to userspace variable - measured. More... | |
int | hx711_continuous_measure () |
Starts hx711 measuring that will run until its stopped by user. More... | |
int | open_db_connection () |
Tries to open the database connection and init db_driver. More... | |
void | set_err_screen_and_activate (const char *title, const char *label) |
Set the err screen and activate the screen on next frame. More... | |
void | use_font_size (app_workspace_ns::font_size font_size) |
When this is called following gui elements will use selected font_size until next call of this or font pop. More... | |
app_workspace_ns::font_size | get_font_size () |
Get the font size. More... | |
int | load_font_size (app_workspace_ns::font_size key, float size_px) |
Initializes font into the map. More... | |
int | log_in_user_rfid (rfid_reader::rfid_tag *tag, bool loading_sub=false) |
Logs in user through scanned RFID tag. Initializes user_workspace if loading_sub is false. More... | |
int | verify_user_cred () |
Tests if user entered correct credentials. More... | |
void | log_in_user_cred () |
Logs in user using credentials. Credentials are gained from screen_1 buffers. More... | |
void | login_subuser () |
When a user is already logged in and their role is employee or admin, they can log in another user as their subuser. More... | |
void | logout_subuser () |
Logs out subuser. More... | |
void | logoff_user () |
Logs out user and subuser if logged in. More... | |
int | register_new_user () |
This function validets screen 6 buffers and if everything checks out then inserts new user into the DB. More... | |
std::vector< double > | normalize_raw_values (std::vector< HX711::Value > &raw_vals) |
Takes raw values and normalizes them using HX offset and reference unit. Resulting values are in Grams! More... | |
std::vector< HX711::Value > | hx711_values_samples (int samples) |
Reads the HX711 sensor until @samples is collected. Also starts new thread which is used to monitor ongoing measuring. More... | |
std::vector< HX711::Value > | hx711_values_timeout (int seconds) |
Reads the HX711 sensor until @timeout is reached. Also starts new thread which is used to monitor ongoing measuring. More... | |
screen_manager * | get_scr_mgr () |
Get the screen manager instance. This instance is kind of singleton. Is initalized only once on startup. More... | |
void | set_scr_mgr (screen_manager *scr_mgr) |
Set the screen manager instancte. This should only be called once, when the application is starting up. More... | |
bool | is_debug_screens () |
Retruns flag is. More... | |
bool | has_user () |
Checks if user is logged in. This is determined by user_space being initialized and having the user_logged flag set. More... | |
user_workspace * | get_userspace () |
void | print_config () |
int | test_hx_samples () |
int | test_hx_timeout () |
bool | get_kb_testing () |
void | set_kb_testing (bool val) |
Static Public Member Functions | |
static std::unique_ptr< app_workspace > & | get_instance () |
Get the instance app_workspace which is a singleton. More... | |
Public Attributes | |
std::unique_ptr< app_workspace_ns::kb_input_state > | kb_in_state |
Input state holder. More... | |
std::unique_ptr< custom_hx711 > | hx711_controller |
HX711 controller. This is an instance of custom_hx711 which extends library's AdvancedHX711. More... | |
std::unique_ptr< db_driver > | db_conn |
Database driver holder. More... | |
bool | refresh_current_screen = false |
When this is set to true, elements of current screen will be reinitialized for next frame. More... | |
bool | capslock_flag = false |
Flags used during text input. More... | |
bool | lshift_flag = false |
std::unique_ptr< app_config > | main_config = std::make_unique<app_config>() |
Application config loaded from app_config.conf (main config file). More... | |
bool | user_logged = false |
Flag to indicate if a user is logged in. More... | |
std::unique_ptr< user_workspace > | userspace |
User's workspace. Serves similar function as app_workspace but for user data. More... | |
bool | hx_measuring = false |
bool | hx_continuous = false |
bool | hx_not_finished_yet = false |
std::chrono::time_point< std::chrono::high_resolution_clock > | m_start |
std::chrono::time_point< std::chrono::high_resolution_clock > | m_end |
int | selected_hx_measure_opt = 0 |
int | selected_hx_result_unit = 0 |
std::unique_ptr< measurement > | observed_measurement |
This variable is used to observe measuring. More... | |
std::map< app_workspace_ns::font_size, ImFont * > | loaded_fonts |
Map of loaded fonts. More... | |
int | font_push_cnt = 0 |
Whenever a font is used, it is pushed to the font stack of ImGui library. All pushed fonts need to be popped before the end of the frame to prevent application crash. More... | |
char | usr_name [DEF_BUFF_SIZE] |
char | usr_passwd [DEF_BUFF_SIZE_SMALL] |
char | subusr_name [DEF_BUFF_SIZE] |
const char * | hx_measure_opts [S2_MEASURE_OTPS_CNT] |
int | samples_in = S2_MIN_SAMPLES_IN |
int | timeout_in = S2_MIN_TIMEOUT_IN |
int | selected_measuring = 0 |
const char * | s3_filter_opt_labels [S3_FILTER_OPT_CNT] |
int | s3_selected_filter = 0 |
unsigned long | s3_filter_number = 0 |
int | selected_unit_option = 1 |
const char * | unit_sel_labels [UNIT_SEL_CNT] |
const HX711::Mass::Unit | unit_selection [UNIT_SEL_CNT] |
int | s5_screen_6_indicator = -1 |
int | s5_success_indicator = -1 |
int | s6_ref_mass_in = 0 |
int | s6_samples_in = S6_MIN_SAMPLES_IN |
int | s6_calib_ref_unit = 0 |
int | s6_calib_offset = 0 |
int | s6_selected_unit_option = 0 |
const char * | s6_unit_sel_labels [S6_UNIT_SEL_CNT] |
bool | s6_calibration_finished = false |
bool | s6_tare_complete = false |
std::string | s6_ref_mass_str |
HX711::Value | zero_value = 0 |
HX711::Value | ref_unit = 0 |
bool | s6_rfid_indicator = false |
std::unique_ptr< rfid_reader::rfid_tag > | s6_rfid_tag |
int | s6_selected_role = 0 |
int | s6_selected_month = 0 |
const char * | s6_role_labels [S6_ROLE_CNT] |
const char * | s6_month_labels [S6_MONTH_CNT] |
char | s6_name_in [DEF_BUFF_SIZE] = {0} |
char | s6_uname_in [DEF_BUFF_SIZE_SMALL] = {0} |
char | s6_passwd_in [DEF_BUFF_SIZE_SMALL] = {0} |
char | s6_desc_in [DEF_BUFF_SIZE_EXTRA] = {0} |
char | s6_lastname_in [DEF_BUFF_SIZE_SMALL] = {0} |
int | s6_year_in = 2022 |
int | s6_day_in = 1 |
int | int_test = 0 |
float | float_test = 0.0f |
char | text_test [DEF_BUFF_SIZE] |
char | pass_test [DEF_BUFF_SIZE_SMALL] |
int | kb_delay_ms = 0 |
int | kb_delay_us = 0 |
int | kb_ev_delay_ms = 0 |
int | kb_ev_delay_us = 0 |
bool | test_hx_testing = false |
std::pair< long, std::string > | test_hx_samples_times [HX_TEST_CONST_IT_COUNT+HX_TEST_INC_IT_COUNT] |
std::pair< long, std::string > | test_hx_timeout_collected [HX_TEST_CONST_IT_COUNT+HX_TEST_INC_IT_COUNT] |
One of the most importat classes in the whole project. Holds variables that define the state of the application and also provides logic for some of the variables held there. For example the hx711 controller is held and used from this class.
Definition at line 159 of file app_workspace.h.
app_workspace::app_workspace | ( | ) |
Construct a new app workspace object.
One of the most importat classes in the whole project. Holds variables that define the state of the application and also provides logic for some of the variables held there. For example the hx711 controller is held and used from this class.
Definition at line 58 of file app_workspace.cpp.
app_workspace_ns::font_size app_workspace::get_font_size | ( | ) |
Get the font size.
Definition at line 316 of file app_workspace.cpp.
|
static |
Get the instance app_workspace which is a singleton.
Definition at line 45 of file app_workspace.cpp.
bool app_workspace::get_kb_testing | ( | ) |
Gets if keyboard testing is happening. This is a wrapper for thread secure function
Definition at line 831 of file app_workspace.cpp.
screen_manager * app_workspace::get_scr_mgr | ( | ) |
Get the screen manager instance. This instance is kind of singleton. Is initalized only once on startup.
Definition at line 286 of file app_workspace.cpp.
user_workspace * app_workspace::get_userspace | ( | ) |
Definition at line 630 of file app_workspace.cpp.
bool app_workspace::has_user | ( | ) |
Checks if user is logged in. This is determined by user_space being initialized and having the user_logged flag set.
Definition at line 626 of file app_workspace.cpp.
void app_workspace::hx711_calibrate | ( | ) |
Function that performs calibration on the hx711 controller.
Definition at line 134 of file app_workspace.cpp.
int app_workspace::hx711_continuous_measure | ( | ) |
Starts hx711 measuring that will run until its stopped by user.
measures into userspace->measured based on screen2 inputs
Definition at line 193 of file app_workspace.cpp.
int app_workspace::hx711_measure | ( | ) |
Performs hx711 measuring with set values of either samples or timeout. The results is saved to the database and to userspace variable - measured.
Definition at line 144 of file app_workspace.cpp.
void app_workspace::hx711_tare | ( | ) |
Function that performs taring on the hx711 controller.
Definition at line 123 of file app_workspace.cpp.
std::vector< HX711::Value > app_workspace::hx711_values_samples | ( | int | samples | ) |
Reads the HX711 sensor until @samples is collected. Also starts new thread which is used to monitor ongoing measuring.
samples | to be measured |
Definition at line 219 of file app_workspace.cpp.
std::vector< HX711::Value > app_workspace::hx711_values_timeout | ( | int | seconds | ) |
Reads the HX711 sensor until @timeout is reached. Also starts new thread which is used to monitor ongoing measuring.
seconds | for how long the measuring will be going |
Definition at line 252 of file app_workspace.cpp.
int app_workspace::init_hx711_controller | ( | ) |
Initializes the hx711 controller.
Definition at line 93 of file app_workspace.cpp.
void app_workspace::init_labels | ( | ) |
This is called after localisation dictionary is loaded. After the dict is loaded arrays defined in app_workspace must be initialized so they can be used in GUI comboboxes.
Definition at line 61 of file app_workspace.cpp.
bool app_workspace::is_debug_screens | ( | ) |
int app_workspace::load_font_size | ( | app_workspace_ns::font_size | key, |
float | size_px | ||
) |
Initializes font into the map.
key | under which font is inited |
size_px | size of inited font |
Definition at line 320 of file app_workspace.cpp.
void app_workspace::log_in_user_cred | ( | ) |
Logs in user using credentials. Credentials are gained from screen_1 buffers.
Definition at line 418 of file app_workspace.cpp.
int app_workspace::log_in_user_rfid | ( | rfid_reader::rfid_tag * | tag, |
bool | loading_sub = false |
||
) |
Logs in user through scanned RFID tag. Initializes user_workspace if loading_sub is false.
tag | RFID tag structure |
loading_sub | if the user is to be logged as a subuser. |
Definition at line 338 of file app_workspace.cpp.
void app_workspace::login_subuser | ( | ) |
When a user is already logged in and their role is employee or admin, they can log in another user as their subuser.
Definition at line 456 of file app_workspace.cpp.
void app_workspace::logoff_user | ( | ) |
Logs out user and subuser if logged in.
Definition at line 514 of file app_workspace.cpp.
void app_workspace::logout_subuser | ( | ) |
std::vector< double > app_workspace::normalize_raw_values | ( | std::vector< HX711::Value > & | raw_vals | ) |
Takes raw values and normalizes them using HX offset and reference unit. Resulting values are in Grams!
raw_vals | values before normalization |
Definition at line 673 of file app_workspace.cpp.
int app_workspace::open_db_connection | ( | ) |
Tries to open the database connection and init db_driver.
Definition at line 637 of file app_workspace.cpp.
void app_workspace::print_config | ( | ) |
int app_workspace::register_new_user | ( | ) |
This function validets screen 6 buffers and if everything checks out then inserts new user into the DB.
Definition at line 523 of file app_workspace.cpp.
void app_workspace::set_err_screen_and_activate | ( | const char * | title, |
const char * | label | ||
) |
Set the err screen and activate the screen on next frame.
title | of the error |
label | description of the error |
Definition at line 302 of file app_workspace.cpp.
void app_workspace::set_kb_testing | ( | bool | val | ) |
Sets keyboard testing. This is a wrapper for thread secure function
Definition at line 835 of file app_workspace.cpp.
void app_workspace::set_scr_mgr | ( | screen_manager * | scr_mgr | ) |
Set the screen manager instancte. This should only be called once, when the application is starting up.
This function should only be used once in the program. Function is required, because screen_manager cannot be initialized during construction due to cycling.
scr_mgr |
Definition at line 298 of file app_workspace.cpp.
int app_workspace::test_hx_samples | ( | ) |
Tests how long (in ms) it takes hx to take X (def 160) samples. Does 5 iterations with X and 5 iterations with X * it
Definition at line 731 of file app_workspace.cpp.
int app_workspace::test_hx_timeout | ( | ) |
Tests how many samples hx can create in X (def 2) seconds. Does 5 iterations with X and 5 iterations with X * it
Definition at line 782 of file app_workspace.cpp.
void app_workspace::use_font_size | ( | app_workspace_ns::font_size | font_size | ) |
When this is called following gui elements will use selected font_size until next call of this or font pop.
font_size | to be used |
Definition at line 310 of file app_workspace.cpp.
int app_workspace::verify_user_cred | ( | ) |
Tests if user entered correct credentials.
Definition at line 390 of file app_workspace.cpp.
bool app_workspace::capslock_flag = false |
Flags used during text input.
Definition at line 191 of file app_workspace.h.
std::unique_ptr<db_driver> app_workspace::db_conn |
Database driver holder.
Definition at line 180 of file app_workspace.h.
float app_workspace::float_test = 0.0f |
Definition at line 282 of file app_workspace.h.
int app_workspace::font_push_cnt = 0 |
Whenever a font is used, it is pushed to the font stack of ImGui library. All pushed fonts need to be popped before the end of the frame to prevent application crash.
Definition at line 233 of file app_workspace.h.
std::unique_ptr<custom_hx711> app_workspace::hx711_controller |
HX711 controller. This is an instance of custom_hx711 which extends library's AdvancedHX711.
Definition at line 175 of file app_workspace.h.
bool app_workspace::hx_continuous = false |
Definition at line 212 of file app_workspace.h.
const char* app_workspace::hx_measure_opts[S2_MEASURE_OTPS_CNT] |
screen_2 vars - these variables are used for gui elemnts on screen 2
Definition at line 239 of file app_workspace.h.
bool app_workspace::hx_measuring = false |
hx711 (scale) variables
Definition at line 211 of file app_workspace.h.
bool app_workspace::hx_not_finished_yet = false |
Definition at line 213 of file app_workspace.h.
int app_workspace::int_test = 0 |
Following variables are used for testing and debugging
Definition at line 281 of file app_workspace.h.
int app_workspace::kb_delay_ms = 0 |
Definition at line 286 of file app_workspace.h.
int app_workspace::kb_delay_us = 0 |
Definition at line 286 of file app_workspace.h.
int app_workspace::kb_ev_delay_ms = 0 |
Definition at line 286 of file app_workspace.h.
int app_workspace::kb_ev_delay_us = 0 |
Definition at line 286 of file app_workspace.h.
std::unique_ptr<app_workspace_ns::kb_input_state> app_workspace::kb_in_state |
Input state holder.
Definition at line 169 of file app_workspace.h.
std::map<app_workspace_ns::font_size, ImFont*> app_workspace::loaded_fonts |
Map of loaded fonts.
Definition at line 227 of file app_workspace.h.
bool app_workspace::lshift_flag = false |
Definition at line 191 of file app_workspace.h.
std::chrono::time_point<std::chrono::high_resolution_clock> app_workspace::m_end |
Definition at line 214 of file app_workspace.h.
std::chrono::time_point<std::chrono::high_resolution_clock> app_workspace::m_start |
Definition at line 214 of file app_workspace.h.
std::unique_ptr<app_config> app_workspace::main_config = std::make_unique<app_config>() |
Application config loaded from app_config.conf (main config file).
Definition at line 197 of file app_workspace.h.
std::unique_ptr<measurement> app_workspace::observed_measurement |
This variable is used to observe measuring.
Definition at line 221 of file app_workspace.h.
char app_workspace::pass_test[DEF_BUFF_SIZE_SMALL] |
Definition at line 284 of file app_workspace.h.
HX711::Value app_workspace::ref_unit = 0 |
Definition at line 266 of file app_workspace.h.
bool app_workspace::refresh_current_screen = false |
When this is set to true, elements of current screen will be reinitialized for next frame.
Definition at line 186 of file app_workspace.h.
unsigned long app_workspace::s3_filter_number = 0 |
Definition at line 246 of file app_workspace.h.
const char* app_workspace::s3_filter_opt_labels[S3_FILTER_OPT_CNT] |
Definition at line 244 of file app_workspace.h.
int app_workspace::s3_selected_filter = 0 |
Definition at line 245 of file app_workspace.h.
int app_workspace::s5_screen_6_indicator = -1 |
screen_5 vars - these variables are used for gui elemnts on screen 5
Definition at line 256 of file app_workspace.h.
int app_workspace::s5_success_indicator = -1 |
Definition at line 257 of file app_workspace.h.
int app_workspace::s6_calib_offset = 0 |
Definition at line 260 of file app_workspace.h.
int app_workspace::s6_calib_ref_unit = 0 |
Definition at line 260 of file app_workspace.h.
bool app_workspace::s6_calibration_finished = false |
Definition at line 263 of file app_workspace.h.
int app_workspace::s6_day_in = 1 |
Definition at line 276 of file app_workspace.h.
char app_workspace::s6_desc_in[DEF_BUFF_SIZE_EXTRA] = {0} |
Definition at line 275 of file app_workspace.h.
char app_workspace::s6_lastname_in[DEF_BUFF_SIZE_SMALL] = {0} |
Definition at line 275 of file app_workspace.h.
const char* app_workspace::s6_month_labels[S6_MONTH_CNT] |
Definition at line 272 of file app_workspace.h.
char app_workspace::s6_name_in[DEF_BUFF_SIZE] = {0} |
Definition at line 273 of file app_workspace.h.
char app_workspace::s6_passwd_in[DEF_BUFF_SIZE_SMALL] = {0} |
Definition at line 274 of file app_workspace.h.
int app_workspace::s6_ref_mass_in = 0 |
screen_6 vars - these variables are used for gui elemnts on screen 6
Definition at line 260 of file app_workspace.h.
std::string app_workspace::s6_ref_mass_str |
Definition at line 264 of file app_workspace.h.
bool app_workspace::s6_rfid_indicator = false |
Definition at line 268 of file app_workspace.h.
std::unique_ptr<rfid_reader::rfid_tag> app_workspace::s6_rfid_tag |
if available rfid is scanned for user set it to true
Definition at line 269 of file app_workspace.h.
const char* app_workspace::s6_role_labels[S6_ROLE_CNT] |
Definition at line 271 of file app_workspace.h.
int app_workspace::s6_samples_in = S6_MIN_SAMPLES_IN |
Definition at line 260 of file app_workspace.h.
int app_workspace::s6_selected_month = 0 |
Definition at line 270 of file app_workspace.h.
int app_workspace::s6_selected_role = 0 |
Definition at line 270 of file app_workspace.h.
int app_workspace::s6_selected_unit_option = 0 |
Definition at line 261 of file app_workspace.h.
bool app_workspace::s6_tare_complete = false |
Definition at line 263 of file app_workspace.h.
char app_workspace::s6_uname_in[DEF_BUFF_SIZE_SMALL] = {0} |
Definition at line 273 of file app_workspace.h.
const char* app_workspace::s6_unit_sel_labels[S6_UNIT_SEL_CNT] |
Definition at line 262 of file app_workspace.h.
int app_workspace::s6_year_in = 2022 |
Definition at line 276 of file app_workspace.h.
int app_workspace::samples_in = S2_MIN_SAMPLES_IN |
Definition at line 240 of file app_workspace.h.
int app_workspace::selected_hx_measure_opt = 0 |
Definition at line 215 of file app_workspace.h.
int app_workspace::selected_hx_result_unit = 0 |
0 = samples, 1 = timeout
Definition at line 216 of file app_workspace.h.
int app_workspace::selected_measuring = 0 |
screen_3 vars - these variables are used for gui elemnts on screen 3
Definition at line 243 of file app_workspace.h.
int app_workspace::selected_unit_option = 1 |
screen_4 vars - these variables are used for gui elemnts on screen 4
Definition at line 249 of file app_workspace.h.
char app_workspace::subusr_name[DEF_BUFF_SIZE] |
Definition at line 236 of file app_workspace.h.
std::pair<long, std::string> app_workspace::test_hx_samples_times[HX_TEST_CONST_IT_COUNT+HX_TEST_INC_IT_COUNT] |
Time in [ms] it took to collected samples. First 5 is constant time. Second 5 is increasing timeout
Definition at line 290 of file app_workspace.h.
bool app_workspace::test_hx_testing = false |
Definition at line 288 of file app_workspace.h.
std::pair<long, std::string> app_workspace::test_hx_timeout_collected[HX_TEST_CONST_IT_COUNT+HX_TEST_INC_IT_COUNT] |
Number of collected samples in time. First 5 during constant timeout. Second 5 during increasing timeout
Definition at line 292 of file app_workspace.h.
char app_workspace::text_test[DEF_BUFF_SIZE] |
Definition at line 283 of file app_workspace.h.
int app_workspace::timeout_in = S2_MIN_TIMEOUT_IN |
Definition at line 240 of file app_workspace.h.
const char* app_workspace::unit_sel_labels[UNIT_SEL_CNT] |
Definition at line 251 of file app_workspace.h.
const HX711::Mass::Unit app_workspace::unit_selection[UNIT_SEL_CNT] |
Definition at line 252 of file app_workspace.h.
bool app_workspace::user_logged = false |
Flag to indicate if a user is logged in.
Definition at line 203 of file app_workspace.h.
std::unique_ptr<user_workspace> app_workspace::userspace |
User's workspace. Serves similar function as app_workspace but for user data.
Definition at line 208 of file app_workspace.h.
char app_workspace::usr_name[DEF_BUFF_SIZE] |
screen_1 vars - these variables are used for gui elemnts on screen 1
Definition at line 236 of file app_workspace.h.
char app_workspace::usr_passwd[DEF_BUFF_SIZE_SMALL] |
Definition at line 236 of file app_workspace.h.
HX711::Value app_workspace::zero_value = 0 |
Definition at line 266 of file app_workspace.h.