1 #ifndef APP_WORKSPACE_H
2 #define APP_WORKSPACE_H
8 #include <hx711/common.h>
13 #include "spidev_lib++.h"
20 #define DEF_BUFF_SIZE_TINY 16
21 #define DEF_BUFF_SIZE_V_SMALL 32
22 #define DEF_BUFF_SIZE_SMALL 64
23 #define DEF_BUFF_SIZE 128
24 #define DEF_BUFF_SIZE_BIG 256
25 #define DEF_BUFF_SIZE_LARGE 512
26 #define DEF_BUFF_SIZE_HUGE 1024
27 #define DEF_BUFF_SIZE_EXTRA 2048
29 #define S2_MIN_SAMPLES_IN 50
30 #define S2_MAX_SAMPLES_IN 5000
31 #define S2_MIN_TIMEOUT_IN 1
32 #define S2_MAX_TIMEOUT_IN 60
33 #define S3_MIN_FILTER_NUMBER 0
34 #define S6_MIN_SAMPLES_IN 10
35 #define S6_MAX_SAMPLES_IN 1000
37 #define UNIT_SEL_CNT 3
38 #define S2_MEASURE_OTPS_CNT 2
39 #define S3_FILTER_OPT_CNT 2
40 #define S6_UNIT_SEL_CNT 2
42 #define S6_MONTH_CNT 12
48 #define HX_CONT_MAX_CONSEC_FAIL_FI 5
49 #define HX_CONT_MAX_CONSEC_FAIL_FM 5
50 #define HX_CONT_SAMPLES 5000
52 #define HX_TEST_CONST_IT_COUNT 5
53 #define HX_TEST_INC_IT_COUNT 5
54 #define HX_TEST_SAMP_COUNT 160
55 #define HX_TEST_TIME_COUNT 2
57 #define S5_TO_S6_CALIBRATION 0
58 #define S5_TO_S6_USERADD 1
59 #define S5_TO_S6_HX_TEST_SAMPLES 2
60 #define S5_TO_S6_HX_TEST_TIMEOUT 3
61 #define S5_TO_S6_KB_DELAY_TEST 4
63 #define S5_CALIBRATION_APPLIED 0
64 #define S5_USER_CREATED 1
65 #define S5_FINISHED_KB_DELAYS 2
117 std::unique_ptr<spi_config_t> config = std::make_unique<spi_config_t>();
170 std::make_unique<app_workspace_ns::kb_input_state>();
197 std::unique_ptr<app_config>
main_config = std::make_unique<app_config>();
214 std::chrono::time_point<std::chrono::high_resolution_clock>
m_start,
m_end;
253 {HX711::Mass::Unit::MG, HX711::Mass::Unit::G, HX711::Mass::Unit::KG};
493 std::unique_ptr<std::thread> measuring_watchdog;
495 std::unique_ptr<std::thread> measuring_thread;
497 std::unique_ptr<std::thread> calib_thread;
499 static std::unique_ptr<app_workspace> instance;
505 void clear_s1_buffers();
506 void clear_s2_buffers();
507 void clear_s6_buffers();
#define DEF_BUFF_SIZE_EXTRA
#define DEF_BUFF_SIZE_SMALL
#define S2_MIN_TIMEOUT_IN
#define S2_MIN_SAMPLES_IN
#define S6_MIN_SAMPLES_IN
#define HX_TEST_CONST_IT_COUNT
#define HX_TEST_INC_IT_COUNT
#define S2_MEASURE_OTPS_CNT
#define S3_FILTER_OPT_CNT
One of the most importat classes in the whole project. Holds variables that define the state of the a...
int hx711_measure()
Performs hx711 measuring with set values of either samples or timeout. The results is saved to the da...
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
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 o...
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
void logoff_user()
Logs out user and subuser if logged in.
bool capslock_flag
Flags used during text input.
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 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 fon...
std::chrono::time_point< std::chrono::high_resolution_clock > m_end
void set_err_screen_and_activate(const char *title, const char *label)
Set the err screen and activate the screen on next frame.
std::unique_ptr< app_workspace_ns::kb_input_state > kb_in_state
Input state holder.
const HX711::Mass::Unit unit_selection[UNIT_SEL_CNT]
void init_labels()
This is called after localisation dictionary is loaded. After the dict is loaded arrays defined in ap...
void hx711_tare()
Function that performs taring on the hx711 controller.
int s5_screen_6_indicator
const char * s6_month_labels[S6_MONTH_CNT]
int selected_hx_result_unit
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 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.
std::pair< long, std::string > test_hx_samples_times[HX_TEST_CONST_IT_COUNT+HX_TEST_INC_IT_COUNT]
int open_db_connection()
Tries to open the database connection and init db_driver.
int load_font_size(app_workspace_ns::font_size key, float size_px)
Initializes font into the map.
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 Gram...
char s6_passwd_in[DEF_BUFF_SIZE_SMALL]
char usr_passwd[DEF_BUFF_SIZE_SMALL]
void logout_subuser()
Logs out subuser.
std::unique_ptr< measurement > observed_measurement
This variable is used to observe measuring.
const char * s3_filter_opt_labels[S3_FILTER_OPT_CNT]
app_workspace()
Construct a new app workspace object.
void hx711_calibrate()
Function that performs calibration on the hx711 controller.
char pass_test[DEF_BUFF_SIZE_SMALL]
int hx711_continuous_measure()
Starts hx711 measuring that will run until its stopped by user.
app_workspace_ns::font_size get_font_size()
Get the font size.
bool is_debug_screens()
Retruns flag is.
int font_push_cnt
Whenever a font is used, it is pushed to the font stack of ImGui library. All pushed fonts need to be...
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...
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 ong...
int selected_hx_measure_opt
int verify_user_cred()
Tests if user entered correct credentials.
screen_manager * get_scr_mgr()
Get the screen manager instance. This instance is kind of singleton. Is initalized only once on start...
std::map< app_workspace_ns::font_size, ImFont * > loaded_fonts
Map of loaded fonts.
char subusr_name[DEF_BUFF_SIZE]
void set_kb_testing(bool val)
unsigned long s3_filter_number
void set_scr_mgr(screen_manager *scr_mgr)
Set the screen manager instancte. This should only be called once, when the application is starting u...
std::unique_ptr< rfid_reader::rfid_tag > s6_rfid_tag
char usr_name[DEF_BUFF_SIZE]
void login_subuser()
When a user is already logged in and their role is employee or admin, they can log in another user as...
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 init_hx711_controller()
Initializes the hx711 controller.
bool user_logged
Flag to indicate if a user is logged in.
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.
char text_test[DEF_BUFF_SIZE]
void log_in_user_cred()
Logs in user using credentials. Credentials are gained from screen_1 buffers.
int s6_selected_unit_option
char s6_desc_in[DEF_BUFF_SIZE_EXTRA]
const char * hx_measure_opts[S2_MEASURE_OTPS_CNT]
Container that servers for storing users data and manipulating them.
This namespace holds structures and enums used in app_workspace class.
font_size
This enum defines sizes of corresponding fonts. E.g.: SMALL_FONT is 12px.
kb_input_type
Enum holding options of keyboard INPUT mode types.
kb_input_mode
Enum holding options of keyboard input mode.
std::unique_ptr< spi_config_t > spi_config
Structure that holds the values of the application configuration file.
app_workspace_ns::spi_config keyb_conf
std::vector< std::string > lang_options
std::string opt_conf_path
app_workspace_ns::hx711_config hx_conf
app_workspace_ns::spi_config rfid_conf
Structure hodling the configuration of hx711 controller.
Structure holding SPI device and SPI config which is a library structure "spi_config_t".
Container for configuration neccessary to open database connnection.
RFID tag structure. Stores data read from SPI.