From 24cdcfc45c52b7ab22ade8023569caf11ead13ed Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Wed, 10 Apr 2024 17:50:50 +0200 Subject: [PATCH 01/15] Configuration: add copy constructor Signed-off-by: Norbert Takacs --- src/core/Configuration.cpp | 17 +++++++++++++++++ src/core/Configuration.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/core/Configuration.cpp b/src/core/Configuration.cpp index bc4ac8a..e60c3b3 100644 --- a/src/core/Configuration.cpp +++ b/src/core/Configuration.cpp @@ -44,6 +44,23 @@ DeviceConfiguration::DeviceConfiguration() Logger(TLogLevel::logTRACE) << "DeviceConfiguration constructor called" << std::endl; } +DeviceConfiguration::DeviceConfiguration(const DeviceConfiguration& other): + device_type(other.device_type), + pid(other.pid), + vid(other.vid), + serial_number(other.serial_number), + push_actions(other.push_actions), + release_actions(other.release_actions), + encoder_inc_actions(other.encoder_inc_actions), + encoder_dec_actions(other.encoder_dec_actions), + light_triggers(other.light_triggers), + multi_displays(other.multi_displays), + generic_displays(other.generic_displays), + fip_screens(other.fip_screens) +{ + Logger(TLogLevel::logTRACE) << "DeviceConfiguration copy constructor called" << std::endl; +} + DeviceConfiguration& DeviceConfiguration::operator=(const DeviceConfiguration& other) { Logger(TLogLevel::logTRACE) << "DeviceConfiguration = operator called" << std::endl; diff --git a/src/core/Configuration.h b/src/core/Configuration.h index 04c88e2..faa2d5f 100644 --- a/src/core/Configuration.h +++ b/src/core/Configuration.h @@ -51,6 +51,7 @@ class DeviceConfiguration public: ~DeviceConfiguration(); DeviceConfiguration(); + DeviceConfiguration(const DeviceConfiguration& other); DeviceConfiguration& operator=(const DeviceConfiguration& other); void clear(); From d5d8614af5129c292d4ee1b2355d474e96b41efe Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Wed, 10 Apr 2024 17:51:36 +0200 Subject: [PATCH 02/15] Device: use copy of Configuration instead of a reference Signed-off-by: Norbert Takacs --- src/core/Device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Device.h b/src/core/Device.h index c705ea7..f4fe689 100644 --- a/src/core/Device.h +++ b/src/core/Device.h @@ -85,7 +85,7 @@ class Device private: int compute_rotation_delta_with_overflow(unsigned char rot, unsigned char rot_old); protected: - DeviceConfiguration &config; + DeviceConfiguration config; std::vector selectors; std::vector buttons; std::vector panel_displays; From 1dd80577aab2da076d09f16d2cdd5fc95b95d5f9 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Fri, 12 Apr 2024 21:42:24 +0200 Subject: [PATCH 03/15] Configuration: rename DeviceConfig to ClassConfig Signed-off-by: Norbert Takacs --- src/core/ConfigParser.cpp | 108 +++++++++--------- src/core/Configuration.cpp | 26 ++--- src/core/Configuration.h | 20 ++-- src/core/Device.cpp | 2 +- src/core/Device.h | 4 +- src/core/UsbHidDevice.cpp | 2 +- src/core/UsbHidDevice.h | 2 +- src/core/XPanel.cpp | 22 ++-- .../ArduinoHomeCockpit.cpp | 2 +- .../arduino-homecockpit/ArduinoHomeCockpit.h | 2 +- src/devices/fip/FIPDevice.cpp | 2 +- src/devices/fip/FIPDevice.h | 2 +- src/devices/saitek-multi/SaitekMultiPanel.cpp | 2 +- src/devices/saitek-multi/SaitekMultiPanel.h | 2 +- src/devices/saitek-radio/SaitekRadioPanel.cpp | 2 +- src/devices/saitek-radio/SaitekRadioPanel.h | 2 +- .../saitek-switch/SaitekSwitchPanel.cpp | 2 +- src/devices/saitek-switch/SaitekSwitchPanel.h | 2 +- src/devices/trc-1000/TRC1000.cpp | 2 +- src/devices/trc-1000/TRC1000.h | 2 +- src/devices/trc-1000/TRC1000Audio.cpp | 2 +- src/devices/trc-1000/TRC1000Audio.h | 2 +- src/devices/trc-1000/TRC1000PFD.cpp | 2 +- src/devices/trc-1000/TRC1000PFD.h | 2 +- test/mock_xplane.cpp | 2 +- test/test_FIP.cpp | 10 +- test/test_arduino_home.cpp | 2 +- test/test_config_parser.cpp | 24 ++-- test/test_dynamic_speed.cpp | 10 +- test/test_generic_display.cpp | 10 +- test/test_multi_panel.cpp | 46 ++++---- test/test_radio_panel.cpp | 16 +-- test/test_trc1000_audio.cpp | 6 +- test/test_trc1000_pfd.cpp | 18 +-- 34 files changed, 181 insertions(+), 181 deletions(-) diff --git a/src/core/ConfigParser.cpp b/src/core/ConfigParser.cpp index df34678..a6a1c81 100644 --- a/src/core/ConfigParser.cpp +++ b/src/core/ConfigParser.cpp @@ -98,23 +98,23 @@ int Configparser::process_ini_section(IniFileSection& section, Configuration& co { if (section.header.name == TOKEN_SECTION_DEVICE) { - DeviceConfiguration* c = new DeviceConfiguration(); - config.device_configs.push_back(*c); + ClassConfiguration* c = new ClassConfiguration(); + config.class_configs.push_back(*c); if (section.header.id == DEVICE_TYPE_SAITEK_MULTI) - config.device_configs.back().device_type = SAITEK_MULTI; + config.class_configs.back().device_class_type = SAITEK_MULTI; else if (section.header.id == DEVICE_TYPE_SAITEK_RADIO) - config.device_configs.back().device_type = SAITEK_RADIO; + config.class_configs.back().device_class_type = SAITEK_RADIO; else if (section.header.id == DEVICE_TYPE_SAITEK_SWITCH) - config.device_configs.back().device_type = SAITEK_SWITCH; + config.class_configs.back().device_class_type = SAITEK_SWITCH; else if (section.header.id == DEVICE_TYPE_ARDUINO_HOME_COCKPIT) - config.device_configs.back().device_type = HOME_COCKPIT; + config.class_configs.back().device_class_type = HOME_COCKPIT; else if (section.header.id == DEVICE_TYPE_SAITEK_FIP_SCREEN) - config.device_configs.back().device_type = LOGITECH_FIP; + config.class_configs.back().device_class_type = LOGITECH_FIP; else if (section.header.id == DEVICE_TYPE_TRC1000PFD) - config.device_configs.back().device_type = TRC1000_PFD; + config.class_configs.back().device_class_type = TRC1000_PFD; else if (section.header.id == DEVICE_TYPE_TRC1000AUDIO) - config.device_configs.back().device_type = TRC1000_AUDIO; + config.class_configs.back().device_class_type = TRC1000_AUDIO; else { last_device_id = ""; @@ -141,26 +141,26 @@ int Configparser::process_ini_section(IniFileSection& section, Configuration& co } else if (section.header.name == TOKEN_SECTION_DISPLAY) { - config.device_configs.back().generic_displays[section.header.id] = new GenericDisplay(false); + config.class_configs.back().generic_displays[section.header.id] = new GenericDisplay(false); if (section.header.properties.count(TOKEN_BCD) > 0) - config.device_configs.back().generic_displays[section.header.id]->set_bcd(section.header.properties[TOKEN_BCD] == "yes" ? true : false); + config.class_configs.back().generic_displays[section.header.id]->set_bcd(section.header.properties[TOKEN_BCD] == "yes" ? true : false); Logger(TLogLevel::logDEBUG) << "parser: display detected " << section.header.id << std::endl; } else if (section.header.name == TOKEN_SECTION_MULTI_DISPLAY) { - config.device_configs.back().multi_displays[section.header.id] = new MultiPurposeDisplay(); + config.class_configs.back().multi_displays[section.header.id] = new MultiPurposeDisplay(); Logger(TLogLevel::logDEBUG) << "parser: multi display detected " << section.header.id << std::endl; } else if (section.header.name == TOKEN_SECTION_FIP_SCREEN) { FIPScreen* screen = new FIPScreen(); - config.device_configs.back().fip_screens[last_device_id] = screen; + config.class_configs.back().fip_screens[last_device_id] = screen; Logger(TLogLevel::logDEBUG) << "parser: fip screen added: " << section.header.id << std::endl; } else if (section.header.name == TOKEN_FIP_PAGE) { - config.device_configs.back().fip_screens[last_device_id]->add_page(section.header.id, false); + config.class_configs.back().fip_screens[last_device_id]->add_page(section.header.id, false); Logger(TLogLevel::logDEBUG) << "parser: FIP page added " << section.header.id << std::endl; } else if (section.header.name == TOKEN_FIP_LAYER) @@ -204,7 +204,7 @@ int Configparser::process_fip_layer_section(IniFileSection& section, Configurati { if (section.header.properties.count(TOKEN_IMAGE) > 0) { - int page_index = config.device_configs.back().fip_screens[last_device_id]->get_last_page_index(); + int page_index = config.class_configs.back().fip_screens[last_device_id]->get_last_page_index(); if (page_index < 0) { Logger(logERROR) << "Parser: invalid FIP page index. section starts at " << section.header.line << std::endl; @@ -235,7 +235,7 @@ int Configparser::process_fip_layer_section(IniFileSection& section, Configurati } } - if (config.device_configs.back().fip_screens[last_device_id]->add_layer_to_page(page_index, bmp_file_absolute_path.string(), ref_x, ref_y, base_rot) < 0) + if (config.class_configs.back().fip_screens[last_device_id]->add_layer_to_page(page_index, bmp_file_absolute_path.string(), ref_x, ref_y, base_rot) < 0) return EXIT_FAILURE; } else @@ -247,13 +247,13 @@ int Configparser::process_fip_layer_section(IniFileSection& section, Configurati } else if (section.header.properties.count(TOKEN_TYPE) > 0 && section.header.properties[TOKEN_TYPE] == TOKEN_TEXT) { - int page_index = config.device_configs.back().fip_screens[last_device_id]->get_last_page_index(); + int page_index = config.class_configs.back().fip_screens[last_device_id]->get_last_page_index(); if (page_index >= 0) { std::filesystem::path fip_fonts_bmp = config.plugin_path; fip_fonts_bmp /= "fip-fonts.bmp"; - if (config.device_configs.back().fip_screens[last_device_id]->add_text_layer_to_page(page_index, fip_fonts_bmp.string(), 0) < 0) + if (config.class_configs.back().fip_screens[last_device_id]->add_text_layer_to_page(page_index, fip_fonts_bmp.string(), 0) < 0) return EXIT_FAILURE; } else @@ -275,8 +275,8 @@ int Configparser::handle_on_vid(IniFileSectionHeader section_header, std::string { std::stringstream ss; ss << std::hex << value; - ss >> config.device_configs.back().vid; - Logger(TLogLevel::logDEBUG) << "parser: vid=" << config.device_configs.back().vid << std::endl; + ss >> config.class_configs.back().vid; + Logger(TLogLevel::logDEBUG) << "parser: vid=" << config.class_configs.back().vid << std::endl; return EXIT_SUCCESS; } @@ -285,8 +285,8 @@ int Configparser::handle_on_pid(IniFileSectionHeader section_header, std::string { std::stringstream ss; ss << std::hex << value; - ss >> config.device_configs.back().pid; - Logger(TLogLevel::logDEBUG) << "parser: pid=" << config.device_configs.back().pid << std::endl; + ss >> config.class_configs.back().pid; + Logger(TLogLevel::logDEBUG) << "parser: pid=" << config.class_configs.back().pid << std::endl; return EXIT_SUCCESS; } @@ -508,9 +508,9 @@ int Configparser::handle_on_push_or_release(IniFileSectionHeader section_header, action->set_dynamic_speed_params(speed_mid, multi_mid, speed_high, multi_high); if (key == TOKEN_ON_PUSH) - config.device_configs.back().push_actions[section_header.id].push_back(action); + config.class_configs.back().push_actions[section_header.id].push_back(action); else if (key == TOKEN_ON_RELEASE) - config.device_configs.back().release_actions[section_header.id].push_back(action); + config.class_configs.back().release_actions[section_header.id].push_back(action); else { Logger(TLogLevel::logERROR) << "parser: invalid key (section starts at line: " << section_header.line << "): " << key << std::endl; @@ -599,7 +599,7 @@ int Configparser::handle_on_lit_or_unlit_or_blink(IniFileSectionHeader section_h return EXIT_FAILURE; } - config.device_configs.back().light_triggers[section_header.id].push_back(trigger); + config.class_configs.back().light_triggers[section_header.id].push_back(trigger); return EXIT_SUCCESS; } @@ -646,16 +646,16 @@ int Configparser::handle_on_line_add(IniFileSectionHeader section_header, std::s if (section_header.name == TOKEN_SECTION_DISPLAY) { if (index >= 0) - config.device_configs.back().generic_displays[section_header.id]->add_dataref(dataRef, index); + config.class_configs.back().generic_displays[section_header.id]->add_dataref(dataRef, index); else - config.device_configs.back().generic_displays[section_header.id]->add_dataref(dataRef); + config.class_configs.back().generic_displays[section_header.id]->add_dataref(dataRef); } else if (section_header.name == TOKEN_SECTION_MULTI_DISPLAY) { if (condition != "") - config.device_configs.back().multi_displays[section_header.id]->add_condition(condition, dataRef); + config.class_configs.back().multi_displays[section_header.id]->add_condition(condition, dataRef); else - config.device_configs.back().multi_displays[section_header.id]->add_dataref(dataRef); + config.class_configs.back().multi_displays[section_header.id]->add_dataref(dataRef); } else { @@ -670,14 +670,14 @@ int Configparser::handle_on_line_add(IniFileSectionHeader section_header, std::s { if (section_header.name == TOKEN_SECTION_DISPLAY) { - config.device_configs.back().generic_displays[section_header.id]->add_lua(m[1]); + config.class_configs.back().generic_displays[section_header.id]->add_lua(m[1]); } else if (section_header.name == TOKEN_SECTION_MULTI_DISPLAY) { if (condition != "") - config.device_configs.back().multi_displays[section_header.id]->add_condition(condition, m[1]); + config.class_configs.back().multi_displays[section_header.id]->add_condition(condition, m[1]); else - config.device_configs.back().multi_displays[section_header.id]->add_lua(m[1]); + config.class_configs.back().multi_displays[section_header.id]->add_lua(m[1]); } else { @@ -691,14 +691,14 @@ int Configparser::handle_on_line_add(IniFileSectionHeader section_header, std::s { if (section_header.name == TOKEN_SECTION_DISPLAY) { - config.device_configs.back().generic_displays[section_header.id]->add_const(stod(m[1])); + config.class_configs.back().generic_displays[section_header.id]->add_const(stod(m[1])); } else if (section_header.name == TOKEN_SECTION_MULTI_DISPLAY) { if (condition != "") - config.device_configs.back().multi_displays[section_header.id]->add_condition(condition, stod(m[1])); + config.class_configs.back().multi_displays[section_header.id]->add_condition(condition, stod(m[1])); else - config.device_configs.back().multi_displays[section_header.id]->add_const(stod(m[1])); + config.class_configs.back().multi_displays[section_header.id]->add_const(stod(m[1])); } else { @@ -716,9 +716,9 @@ int Configparser::handle_on_line_add(IniFileSectionHeader section_header, std::s int Configparser::handle_on_set_bcd(IniFileSectionHeader section_header, std::string key, std::string value, Configuration& config) { if (section_header.name == TOKEN_SECTION_MULTI_DISPLAY) - config.device_configs.back().multi_displays[section_header.id]->set_bcd(value == "yes" ? true : false); + config.class_configs.back().multi_displays[section_header.id]->set_bcd(value == "yes" ? true : false); else if (section_header.name == TOKEN_SECTION_DISPLAY) - config.device_configs.back().generic_displays[section_header.id]->set_bcd(value == "yes" ? true : false); + config.class_configs.back().generic_displays[section_header.id]->set_bcd(value == "yes" ? true : false); else { Logger(TLogLevel::logERROR) << "parser: bcd option can be set for generic- or multidisplay items"; @@ -814,16 +814,16 @@ int Configparser::handle_on_encoder_inc_or_dec(IniFileSectionHeader section_head action->add_condition(condition); if (key == TOKEN_ENCODER_INC) - config.device_configs.back().encoder_inc_actions[section_header.id].push_back(action); + config.class_configs.back().encoder_inc_actions[section_header.id].push_back(action); else - config.device_configs.back().encoder_dec_actions[section_header.id].push_back(action); + config.class_configs.back().encoder_dec_actions[section_header.id].push_back(action); return EXIT_SUCCESS; } int Configparser::handle_on_fip_serial(IniFileSectionHeader section_header, std::string key, std::string value, Configuration& config) { - config.device_configs.back().serial_number = value; + config.class_configs.back().serial_number = value; Logger(TLogLevel::logDEBUG) << "parser: serial number: " << value << std::endl; return EXIT_SUCCESS; } @@ -835,8 +835,8 @@ int Configparser::handle_on_fip_offset(IniFileSectionHeader section_header, std: //offset_y = "dataref::sim/cockpit2/radios/actuators/com1_frequency_hz[0],scale:1.0" ScreenAction* action = new ScreenAction(); - action->page_index = config.device_configs.back().fip_screens[last_device_id]->get_last_page_index(); - action->layer_index = config.device_configs.back().fip_screens[last_device_id]->get_last_layer_index(action->page_index); + action->page_index = config.class_configs.back().fip_screens[last_device_id]->get_last_page_index(); + action->layer_index = config.class_configs.back().fip_screens[last_device_id]->get_last_layer_index(action->page_index); if (key == TOKEN_FIP_OFFSET_X) action->type = SC_TRANSLATION_X; @@ -889,15 +889,15 @@ int Configparser::handle_on_fip_offset(IniFileSectionHeader section_header, std: Logger(logTRACE) << "config parser: add FIP offset const: " << action->constant_val << std::endl; - config.device_configs.back().fip_screens[last_device_id]->add_screen_action(action); + config.class_configs.back().fip_screens[last_device_id]->add_screen_action(action); return EXIT_SUCCESS; } int Configparser::handle_on_fip_rotation(IniFileSectionHeader section_header, std::string key, std::string value, Configuration& config) { ScreenAction* action = new ScreenAction(); - action->page_index = config.device_configs.back().fip_screens[last_device_id]->get_last_page_index(); - action->layer_index = config.device_configs.back().fip_screens[last_device_id]->get_last_layer_index(action->page_index); + action->page_index = config.class_configs.back().fip_screens[last_device_id]->get_last_page_index(); + action->layer_index = config.class_configs.back().fip_screens[last_device_id]->get_last_layer_index(action->page_index); action->type = SC_ROTATION; std::vector m = tokenize(value); @@ -937,14 +937,14 @@ int Configparser::handle_on_fip_rotation(IniFileSectionHeader section_header, st return EXIT_FAILURE; } - config.device_configs.back().fip_screens[last_device_id]->add_screen_action(action); + config.class_configs.back().fip_screens[last_device_id]->add_screen_action(action); return EXIT_SUCCESS; } int Configparser::handle_on_fip_mask(IniFileSectionHeader section_header, std::string key, std::string value, Configuration& config) { - int page_index = config.device_configs.back().fip_screens[last_device_id]->get_last_page_index(); - int layer_index = config.device_configs.back().fip_screens[last_device_id]->get_last_layer_index(page_index); + int page_index = config.class_configs.back().fip_screens[last_device_id]->get_last_page_index(); + int layer_index = config.class_configs.back().fip_screens[last_device_id]->get_last_layer_index(page_index); std::vector m = tokenize(value); @@ -970,7 +970,7 @@ int Configparser::handle_on_fip_mask(IniFileSectionHeader section_header, std::s } MaskWindow mask(screen_x, screen_y, width, height); - config.device_configs.back().fip_screens[last_device_id]->set_mask(page_index, layer_index, mask); + config.class_configs.back().fip_screens[last_device_id]->set_mask(page_index, layer_index, mask); Logger(logTRACE) << "Parser: set mask for page " << page_index << " / layer " << layer_index << std::endl; } else @@ -984,8 +984,8 @@ int Configparser::handle_on_fip_mask(IniFileSectionHeader section_header, std::s int Configparser::handle_on_fip_text(IniFileSectionHeader section_header, std::string key, std::string value, Configuration& config) { - int page_index = config.device_configs.back().fip_screens[last_device_id]->get_last_page_index(); - int layer_index = config.device_configs.back().fip_screens[last_device_id]->get_last_layer_index(page_index); + int page_index = config.class_configs.back().fip_screens[last_device_id]->get_last_page_index(); + int layer_index = config.class_configs.back().fip_screens[last_device_id]->get_last_layer_index(page_index); if (page_index < 0 || layer_index < 0) { @@ -997,7 +997,7 @@ int Configparser::handle_on_fip_text(IniFileSectionHeader section_header, std::s if (m[0] == TOKEN_CONST) { - config.device_configs.back().fip_screens[last_device_id]->set_text(page_index, layer_index, m[1]); + config.class_configs.back().fip_screens[last_device_id]->set_text(page_index, layer_index, m[1]); } else if (m[0] == TOKEN_DATAREF) { @@ -1017,7 +1017,7 @@ int Configparser::handle_on_fip_text(IniFileSectionHeader section_header, std::s action->type = SC_SET_TEXT; Logger(logTRACE) << "config parser: add FIP text set dataref: " << action->data_ref << std::endl; - config.device_configs.back().fip_screens[last_device_id]->add_screen_action(action); + config.class_configs.back().fip_screens[last_device_id]->add_screen_action(action); } else if (m[0] == TOKEN_LUA) { @@ -1029,7 +1029,7 @@ int Configparser::handle_on_fip_text(IniFileSectionHeader section_header, std::s action->type = SC_SET_TEXT; Logger(logTRACE) << "config parser: add FIP set text lua: " << action->lua_str << std::endl; - config.device_configs.back().fip_screens[last_device_id]->add_screen_action(action); + config.class_configs.back().fip_screens[last_device_id]->add_screen_action(action); } else { diff --git a/src/core/Configuration.cpp b/src/core/Configuration.cpp index e60c3b3..a96efb5 100644 --- a/src/core/Configuration.cpp +++ b/src/core/Configuration.cpp @@ -17,7 +17,7 @@ Configuration& Configuration::operator=(const Configuration& other) version = other.version; aircraft_path = other.aircraft_path; - device_configs = other.device_configs; + class_configs = other.class_configs; return *this; } @@ -29,7 +29,7 @@ void Configuration::clear() version = ""; aircraft_path = ""; - device_configs.clear(); + class_configs.clear(); } Configuration::~Configuration() @@ -39,13 +39,13 @@ Configuration::~Configuration() } /* ----------- Device specific configuration options ------------------*/ -DeviceConfiguration::DeviceConfiguration() +ClassConfiguration::ClassConfiguration() { - Logger(TLogLevel::logTRACE) << "DeviceConfiguration constructor called" << std::endl; + Logger(TLogLevel::logTRACE) << "ClassConfiguration constructor called" << std::endl; } -DeviceConfiguration::DeviceConfiguration(const DeviceConfiguration& other): - device_type(other.device_type), +ClassConfiguration::ClassConfiguration(const ClassConfiguration& other): + device_class_type(other.device_class_type), pid(other.pid), vid(other.vid), serial_number(other.serial_number), @@ -58,17 +58,17 @@ DeviceConfiguration::DeviceConfiguration(const DeviceConfiguration& other): generic_displays(other.generic_displays), fip_screens(other.fip_screens) { - Logger(TLogLevel::logTRACE) << "DeviceConfiguration copy constructor called" << std::endl; + Logger(TLogLevel::logTRACE) << "ClassConfiguration copy constructor called" << std::endl; } -DeviceConfiguration& DeviceConfiguration::operator=(const DeviceConfiguration& other) +ClassConfiguration& ClassConfiguration::operator=(const ClassConfiguration& other) { - Logger(TLogLevel::logTRACE) << "DeviceConfiguration = operator called" << std::endl; + Logger(TLogLevel::logTRACE) << "ClassConfiguration = operator called" << std::endl; if (this == &other) return *this; - device_type = other.device_type; + device_class_type = other.device_class_type; pid = other.pid; vid = other.vid; serial_number = other.serial_number; @@ -84,7 +84,7 @@ DeviceConfiguration& DeviceConfiguration::operator=(const DeviceConfiguration& o return *this; } -void DeviceConfiguration::clear() +void ClassConfiguration::clear() { for (auto &act : push_actions) act.second.clear(); @@ -107,8 +107,8 @@ void DeviceConfiguration::clear() light_triggers.clear(); } -DeviceConfiguration::~DeviceConfiguration() +ClassConfiguration::~ClassConfiguration() { - Logger(TLogLevel::logTRACE) << "DeviceConfiguration destructor called" << std::endl; + Logger(TLogLevel::logTRACE) << "ClassConfiguration destructor called" << std::endl; clear(); } diff --git a/src/core/Configuration.h b/src/core/Configuration.h index faa2d5f..faab5ed 100644 --- a/src/core/Configuration.h +++ b/src/core/Configuration.h @@ -15,7 +15,7 @@ class FIPScreen; -class DeviceConfiguration; +class ClassConfiguration; /*------ Plugin level configuration options ------------*/ class Configuration @@ -31,10 +31,10 @@ class Configuration std::string aircraft_path = ""; std::string plugin_path = ""; - std::vector device_configs; + std::vector class_configs; }; -/* ----------- Device specific configuration options ------------------*/ +/* ----------- Class specific configuration options ------------------*/ typedef enum { UNKNOWN_DEVICE_TYPE, SAITEK_MULTI, @@ -44,18 +44,18 @@ typedef enum { LOGITECH_FIP, TRC1000_PFD, TRC1000_AUDIO -} DeviceType; +} DeviceClassType; -class DeviceConfiguration +class ClassConfiguration { public: - ~DeviceConfiguration(); - DeviceConfiguration(); - DeviceConfiguration(const DeviceConfiguration& other); - DeviceConfiguration& operator=(const DeviceConfiguration& other); + ~ClassConfiguration(); + ClassConfiguration(); + ClassConfiguration(const ClassConfiguration& other); + ClassConfiguration& operator=(const ClassConfiguration& other); void clear(); - DeviceType device_type = UNKNOWN_DEVICE_TYPE; + DeviceClassType device_class_type = UNKNOWN_DEVICE_TYPE; unsigned int vid = 0; unsigned int pid = 0; std::string serial_number = ""; diff --git a/src/core/Device.cpp b/src/core/Device.cpp index 9466e94..7a8566c 100644 --- a/src/core/Device.cpp +++ b/src/core/Device.cpp @@ -7,7 +7,7 @@ #include "Device.h" #include "Logger.h" -Device::Device(DeviceConfiguration& _config, int _read_buffer_size, int _write_buffer_size): +Device::Device(ClassConfiguration& _config, int _read_buffer_size, int _write_buffer_size): config(_config), read_buffer_size(_read_buffer_size), write_buffer_size(_write_buffer_size) { read_buffer = (unsigned char*)calloc(_read_buffer_size, sizeof(unsigned char)); diff --git a/src/core/Device.h b/src/core/Device.h index f4fe689..1f2a870 100644 --- a/src/core/Device.h +++ b/src/core/Device.h @@ -85,7 +85,7 @@ class Device private: int compute_rotation_delta_with_overflow(unsigned char rot, unsigned char rot_old); protected: - DeviceConfiguration config; + ClassConfiguration config; std::vector selectors; std::vector buttons; std::vector panel_displays; @@ -105,7 +105,7 @@ class Device virtual void register_rotary_encoders(std::vector& _encoders); public: std::thread* thread_handle = NULL; - Device(DeviceConfiguration &_config, int _read_buffer_size, int _write_buffer_size); + Device(ClassConfiguration &_config, int _read_buffer_size, int _write_buffer_size); ~Device(); int get_stored_button_state(std::string button_name); TriggerType get_stored_light_state(std::string light_name); diff --git a/src/core/UsbHidDevice.cpp b/src/core/UsbHidDevice.cpp index 130ea88..b539ce1 100644 --- a/src/core/UsbHidDevice.cpp +++ b/src/core/UsbHidDevice.cpp @@ -13,7 +13,7 @@ int UsbHidDevice::ref_count = 0; bool UsbHidDevice::hid_api_initialized = false; -UsbHidDevice::UsbHidDevice(DeviceConfiguration& config, int _read_buffer_size, int _write_buffer_size) :Device(config, _read_buffer_size, _write_buffer_size) +UsbHidDevice::UsbHidDevice(ClassConfiguration& config, int _read_buffer_size, int _write_buffer_size) :Device(config, _read_buffer_size, _write_buffer_size) { _thread_run.store(false); vid = config.vid; diff --git a/src/core/UsbHidDevice.h b/src/core/UsbHidDevice.h index bce2fdf..bfd2d86 100644 --- a/src/core/UsbHidDevice.h +++ b/src/core/UsbHidDevice.h @@ -20,7 +20,7 @@ class UsbHidDevice : public Device { public: - UsbHidDevice(DeviceConfiguration& config, int _read_buffer_size, int _write_buffer_size); + UsbHidDevice(ClassConfiguration& config, int _read_buffer_size, int _write_buffer_size); ~UsbHidDevice(); virtual void thread_func(); int get_vid() { return vid; } diff --git a/src/core/XPanel.cpp b/src/core/XPanel.cpp index 9833dd0..1b7fa83 100644 --- a/src/core/XPanel.cpp +++ b/src/core/XPanel.cpp @@ -127,7 +127,7 @@ PLUGIN_API int XPluginEnable(void) float flight_loop_callback(float, float, int, void*) { - for (const auto& it : config.device_configs) + for (const auto& it : config.class_configs) { // check and set LED states for (const auto& triggers : it.light_triggers) @@ -227,7 +227,7 @@ extern std::filesystem::path get_plugin_path() } template -int enumerate_and_add_hid_devices(DeviceConfiguration& it) +int enumerate_and_add_hid_devices(ClassConfiguration& it) { Device* device; struct hid_device_info* dev_info; @@ -310,10 +310,10 @@ int init_and_start_xpanel_plugin(void) Device* device; - for (auto& it : config.device_configs) + for (auto& it : config.class_configs) { - switch (it.device_type) { - case DeviceType::SAITEK_MULTI: + switch (it.device_class_type) { + case DeviceClassType::SAITEK_MULTI: // set default vid & pid if it's not set in config file if (it.vid == 0) it.vid = 0x06a3; @@ -322,7 +322,7 @@ int init_and_start_xpanel_plugin(void) Logger(TLogLevel::logDEBUG) << "add new saitek multi panel device" << std::endl; enumerate_and_add_hid_devices(it); break; - case DeviceType::HOME_COCKPIT: + case DeviceClassType::HOME_COCKPIT: // set default vid & pid if it's not set in config file if (it.vid == 0) it.vid = 0x2341; @@ -331,7 +331,7 @@ int init_and_start_xpanel_plugin(void) Logger(TLogLevel::logDEBUG) << "add new homecockpit devices" << std::endl; enumerate_and_add_hid_devices(it); break; - case DeviceType::SAITEK_RADIO: + case DeviceClassType::SAITEK_RADIO: // set default vid & pid if it's not set in config file if (it.vid == 0) it.vid = 0x06a3; @@ -340,7 +340,7 @@ int init_and_start_xpanel_plugin(void) Logger(TLogLevel::logDEBUG) << "add new saitek radio devices" << std::endl; enumerate_and_add_hid_devices(it); break; - case DeviceType::SAITEK_SWITCH: + case DeviceClassType::SAITEK_SWITCH: // set default vid & pid if it's not set in config file if (it.vid == 0) it.vid = 0x06a3; @@ -349,7 +349,7 @@ int init_and_start_xpanel_plugin(void) Logger(TLogLevel::logDEBUG) << "add new saitek switch panel devices" << std::endl; enumerate_and_add_hid_devices(it); break; - case DeviceType::LOGITECH_FIP: + case DeviceClassType::LOGITECH_FIP: Logger(TLogLevel::logDEBUG) << "add new FIP device" << std::endl; device = new FIPDevice(it); devices.push_back(device); @@ -357,11 +357,11 @@ int init_and_start_xpanel_plugin(void) device->start(); device->thread_handle = new std::thread(&FIPDevice::thread_func, (FIPDevice*)device); break; - case DeviceType::TRC1000_PFD: + case DeviceClassType::TRC1000_PFD: Logger(TLogLevel::logDEBUG) << "add new TRC1000 PFD devices" << std::endl; enumerate_and_add_hid_devices(it); break; - case DeviceType::TRC1000_AUDIO: + case DeviceClassType::TRC1000_AUDIO: Logger(TLogLevel::logDEBUG) << "add new TRC1000 Audio devices" << std::endl; enumerate_and_add_hid_devices(it); break; diff --git a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp index d6c1c32..383e047 100644 --- a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp +++ b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp @@ -20,7 +20,7 @@ std::filesystem::path get_plugin_path(); -ArduinoHomeCockpit::ArduinoHomeCockpit(DeviceConfiguration& config) :UsbHidDevice(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) +ArduinoHomeCockpit::ArduinoHomeCockpit(ClassConfiguration& config) :UsbHidDevice(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) { std::filesystem::path board_config_path = get_plugin_path(); board_config_path /= "board-config.ini"; diff --git a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.h b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.h index dfa5869..189961a 100644 --- a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.h +++ b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.h @@ -23,7 +23,7 @@ class ArduinoHomeCockpit :public UsbHidDevice const std::string TOKEN_BUTTON = "button:id=\"([a-zA-Z0-9_-]+)\",bit=([0-9]+)"; const std::string TOKEN_DISPLAY = "display:id=\"([a-zA-Z0-9_-]+)\",width=([0-9]+)"; public: - ArduinoHomeCockpit(DeviceConfiguration& config); + ArduinoHomeCockpit(ClassConfiguration& config); int connect(hid_device* _device_handle); int connect(); void start(); diff --git a/src/devices/fip/FIPDevice.cpp b/src/devices/fip/FIPDevice.cpp index d2a4fda..bb4a7c1 100644 --- a/src/devices/fip/FIPDevice.cpp +++ b/src/devices/fip/FIPDevice.cpp @@ -8,7 +8,7 @@ #include "core/Logger.h" #include "FIPDevice.h" -FIPDevice::FIPDevice(DeviceConfiguration& _config) :Device(_config,2,1) +FIPDevice::FIPDevice(ClassConfiguration& _config) :Device(_config,2,1) { f_device = NULL; //bit index 0 not used diff --git a/src/devices/fip/FIPDevice.h b/src/devices/fip/FIPDevice.h index c07a785..a855174 100644 --- a/src/devices/fip/FIPDevice.h +++ b/src/devices/fip/FIPDevice.h @@ -21,7 +21,7 @@ class FIPDevice : public Device int page_index_old; void process_page_conditions(FIPScreen* screen); public: - FIPDevice(DeviceConfiguration& _config); + FIPDevice(ClassConfiguration& _config); void stop(int time_out_msec); int connect(); void release(); diff --git a/src/devices/saitek-multi/SaitekMultiPanel.cpp b/src/devices/saitek-multi/SaitekMultiPanel.cpp index b220318..7e74729 100644 --- a/src/devices/saitek-multi/SaitekMultiPanel.cpp +++ b/src/devices/saitek-multi/SaitekMultiPanel.cpp @@ -13,7 +13,7 @@ #define WRITE_BUFFER_SIZE 13 #define READ_BUFFER_SIZE 4 -SaitekMultiPanel::SaitekMultiPanel(DeviceConfiguration& config) :UsbHidDevice(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) +SaitekMultiPanel::SaitekMultiPanel(ClassConfiguration& config) :UsbHidDevice(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) { // mode selector switch diff --git a/src/devices/saitek-multi/SaitekMultiPanel.h b/src/devices/saitek-multi/SaitekMultiPanel.h index edcbbab..1569205 100644 --- a/src/devices/saitek-multi/SaitekMultiPanel.h +++ b/src/devices/saitek-multi/SaitekMultiPanel.h @@ -18,7 +18,7 @@ class SaitekMultiPanel : public UsbHidDevice std::vector multi_lights; std::vector multi_displays; public: - SaitekMultiPanel(DeviceConfiguration &config); + SaitekMultiPanel(ClassConfiguration &config); int connect(hid_device* _device_handle); int connect(); void start(); diff --git a/src/devices/saitek-radio/SaitekRadioPanel.cpp b/src/devices/saitek-radio/SaitekRadioPanel.cpp index 05e49fe..9996d34 100644 --- a/src/devices/saitek-radio/SaitekRadioPanel.cpp +++ b/src/devices/saitek-radio/SaitekRadioPanel.cpp @@ -13,7 +13,7 @@ #define WRITE_BUFFER_SIZE 23 #define READ_BUFFER_SIZE 5 -SaitekRadioPanel::SaitekRadioPanel(DeviceConfiguration& config) :UsbHidDevice(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) +SaitekRadioPanel::SaitekRadioPanel(ClassConfiguration& config) :UsbHidDevice(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) { // mode selector switch diff --git a/src/devices/saitek-radio/SaitekRadioPanel.h b/src/devices/saitek-radio/SaitekRadioPanel.h index f530bd3..e949d5c 100644 --- a/src/devices/saitek-radio/SaitekRadioPanel.h +++ b/src/devices/saitek-radio/SaitekRadioPanel.h @@ -17,7 +17,7 @@ class SaitekRadioPanel : public UsbHidDevice std::vector radio_selectors; std::vector radio_displays; public: - SaitekRadioPanel(DeviceConfiguration& config); + SaitekRadioPanel(ClassConfiguration& config); int connect(); int connect(hid_device* _device_handle); void start(); diff --git a/src/devices/saitek-switch/SaitekSwitchPanel.cpp b/src/devices/saitek-switch/SaitekSwitchPanel.cpp index 2e720b8..eacd297 100644 --- a/src/devices/saitek-switch/SaitekSwitchPanel.cpp +++ b/src/devices/saitek-switch/SaitekSwitchPanel.cpp @@ -13,7 +13,7 @@ #define WRITE_BUFFER_SIZE 2 #define READ_BUFFER_SIZE 4 -SaitekSwitchPanel::SaitekSwitchPanel(DeviceConfiguration& config) :UsbHidDevice(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) +SaitekSwitchPanel::SaitekSwitchPanel(ClassConfiguration& config) :UsbHidDevice(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) { // push buttons switch_buttons.push_back(PanelButton((0 * 8) + 0, "BATTERY")); diff --git a/src/devices/saitek-switch/SaitekSwitchPanel.h b/src/devices/saitek-switch/SaitekSwitchPanel.h index f64dcff..38bc8bd 100644 --- a/src/devices/saitek-switch/SaitekSwitchPanel.h +++ b/src/devices/saitek-switch/SaitekSwitchPanel.h @@ -16,7 +16,7 @@ class SaitekSwitchPanel : public UsbHidDevice std::vector switch_buttons; std::vector switch_lights; public: - SaitekSwitchPanel(DeviceConfiguration& config); + SaitekSwitchPanel(ClassConfiguration& config); int connect(hid_device* _device_handle); int connect(); void start(); diff --git a/src/devices/trc-1000/TRC1000.cpp b/src/devices/trc-1000/TRC1000.cpp index e94dc88..4023e0b 100644 --- a/src/devices/trc-1000/TRC1000.cpp +++ b/src/devices/trc-1000/TRC1000.cpp @@ -9,7 +9,7 @@ #define TRC1000_READ_TIMEOUT_MILLISEC 50 -TRC1000::TRC1000(DeviceConfiguration& config, int _read_buffer_size, int _write_buffer_size) :UsbHidDevice(config, _read_buffer_size, _write_buffer_size) +TRC1000::TRC1000(ClassConfiguration& config, int _read_buffer_size, int _write_buffer_size) :UsbHidDevice(config, _read_buffer_size, _write_buffer_size) { read_buffer_size = _read_buffer_size; write_buffer_size = _write_buffer_size; diff --git a/src/devices/trc-1000/TRC1000.h b/src/devices/trc-1000/TRC1000.h index 87460da..04573af 100644 --- a/src/devices/trc-1000/TRC1000.h +++ b/src/devices/trc-1000/TRC1000.h @@ -31,7 +31,7 @@ class TRC1000 : public UsbHidDevice int read_buffer_size; int write_buffer_size; public: - TRC1000(DeviceConfiguration& config, int _read_buffer_size, int _write_buffer_size); + TRC1000(ClassConfiguration& config, int _read_buffer_size, int _write_buffer_size); ~TRC1000(); virtual void thread_func(); int connect(hid_device* _device_handle); diff --git a/src/devices/trc-1000/TRC1000Audio.cpp b/src/devices/trc-1000/TRC1000Audio.cpp index fcb44ca..c9c86b3 100644 --- a/src/devices/trc-1000/TRC1000Audio.cpp +++ b/src/devices/trc-1000/TRC1000Audio.cpp @@ -24,7 +24,7 @@ #define BUTTON_BUFFER_OFFSET 0 #define ENCODER_0_BUFFER_OFFSET 5 -TRC1000Audio::TRC1000Audio(DeviceConfiguration& config) :TRC1000(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) +TRC1000Audio::TRC1000Audio(ClassConfiguration& config) :TRC1000(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) { // cmd response oxc2 0 trc1000audio_buttons.push_back(PanelButton(1 * 8 + 0, "COM1MIC")); diff --git a/src/devices/trc-1000/TRC1000Audio.h b/src/devices/trc-1000/TRC1000Audio.h index ef90851..06b1820 100644 --- a/src/devices/trc-1000/TRC1000Audio.h +++ b/src/devices/trc-1000/TRC1000Audio.h @@ -8,7 +8,7 @@ class TRC1000Audio : public TRC1000 std::vector trc1000audio_encoders; std::vector trc1000audio_lights; public: - TRC1000Audio(DeviceConfiguration& config); + TRC1000Audio(ClassConfiguration& config); ~TRC1000Audio(); }; diff --git a/src/devices/trc-1000/TRC1000PFD.cpp b/src/devices/trc-1000/TRC1000PFD.cpp index 9a9bc2b..acb0496 100644 --- a/src/devices/trc-1000/TRC1000PFD.cpp +++ b/src/devices/trc-1000/TRC1000PFD.cpp @@ -26,7 +26,7 @@ #define ENCODER_0_BUFFER_OFFSET 7 #define ENCODER_1_BUFFER_OFFSET 15 -TRC1000PFD::TRC1000PFD(DeviceConfiguration& config) :TRC1000(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) +TRC1000PFD::TRC1000PFD(ClassConfiguration& config) :TRC1000(config, READ_BUFFER_SIZE, WRITE_BUFFER_SIZE) { // cmd response oxc1 0 trc1000pfd_buttons.push_back(PanelButton(1 * 8 + 0, "IAS")); diff --git a/src/devices/trc-1000/TRC1000PFD.h b/src/devices/trc-1000/TRC1000PFD.h index 96d3ad4..b6cd05d 100644 --- a/src/devices/trc-1000/TRC1000PFD.h +++ b/src/devices/trc-1000/TRC1000PFD.h @@ -9,7 +9,7 @@ class TRC1000PFD : public TRC1000 std::vector trc1000pfd_buttons; std::vector trc1000pfd_encoders; public: - TRC1000PFD(DeviceConfiguration& config); + TRC1000PFD(ClassConfiguration& config); ~TRC1000PFD(); }; diff --git a/test/mock_xplane.cpp b/test/mock_xplane.cpp index d36dc40..b67afa0 100644 --- a/test/mock_xplane.cpp +++ b/test/mock_xplane.cpp @@ -296,7 +296,7 @@ void test_call_registered_flight_loop() (*registered_flight_loop)(1, 1, 1, NULL); } -void test_flight_loop(std::vector &config) +void test_flight_loop(std::vector &config) { // process button light changes for (auto& it : config) diff --git a/test/test_FIP.cpp b/test/test_FIP.cpp index b0908af..cd78286 100644 --- a/test/test_FIP.cpp +++ b/test/test_FIP.cpp @@ -18,7 +18,7 @@ void test_set_aircraft_path_and_filename(char* file_name, char* path); int test_fip_get_led_state(int led_index); void test_fip_set_button_states(uint16_t _button_states); void test_fip_set_current_page(int page); -void test_flight_loop(std::vector &config); +void test_flight_loop(std::vector &config); void test_fip_get_image(unsigned char* buffer, size_t buffer_size); namespace test @@ -44,7 +44,7 @@ namespace test LuaHelper::get_instace()->init(); LuaHelper::get_instace()->load_script_file("../../test/" + config.script_file); - fip_device = new FIPDevice(config.device_configs[0]); + fip_device = new FIPDevice(config.class_configs[0]); fip_device->connect(); fip_device->start(); t = new std::thread(&FIPDevice::thread_func, (FIPDevice*)fip_device); @@ -67,14 +67,14 @@ namespace test TEST_METHOD(TestFIPAirSpeedChange) { XPLMSetDatai(airspeed_dataref, 0); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); unsigned char fip_image_buffer[240 * 320 * 3]; test_fip_get_image(fip_image_buffer, 240 * 320 * 3); Assert::AreEqual(0, (int)fip_image_buffer[0]); XPLMSetDatai(airspeed_dataref, 150); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); test_fip_get_image(fip_image_buffer, 240 * 320 * 3); Assert::AreEqual(0, (int)fip_image_buffer[0]); @@ -88,7 +88,7 @@ namespace test byte as padding in each row. Those padding bytes shall be handled by RawBMP class. The 5x3 BMP layer will be put to 0,0 position */ test_fip_set_current_page(2); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); const int row_count = 240; //height diff --git a/test/test_arduino_home.cpp b/test/test_arduino_home.cpp index 1e8eb13..e0edcbe 100644 --- a/test/test_arduino_home.cpp +++ b/test/test_arduino_home.cpp @@ -42,7 +42,7 @@ namespace test p = new Configparser(); int result = p->parse_file("../../test/test-arduino-home.ini", config); Assert::AreEqual(0, result); - device = new ArduinoHomeCockpit(config.device_configs[0]); + device = new ArduinoHomeCockpit(config.class_configs[0]); device->connect(); device->start(); t = new std::thread(&ArduinoHomeCockpit::thread_func, (ArduinoHomeCockpit*)device); diff --git a/test/test_config_parser.cpp b/test/test_config_parser.cpp index 83f67b7..009b71c 100644 --- a/test/test_config_parser.cpp +++ b/test/test_config_parser.cpp @@ -33,30 +33,30 @@ namespace test TEST_METHOD(TestDeviceConfigParams) { - Assert::AreEqual(1, (int)config.device_configs.size()); - Assert::IsTrue(config.device_configs[0].device_type == DeviceType::SAITEK_MULTI); - Assert::AreEqual(0x12AB, (int)config.device_configs[0].vid); - Assert::AreEqual(0x34CD, (int)config.device_configs[0].pid); + Assert::AreEqual(1, (int)config.class_configs.size()); + Assert::IsTrue(config.class_configs[0].device_class_type == DeviceClassType::SAITEK_MULTI); + Assert::AreEqual(0x12AB, (int)config.class_configs[0].vid); + Assert::AreEqual(0x34CD, (int)config.class_configs[0].pid); Assert::AreEqual("test-script.lua", config.script_file.c_str()); Assert::AreEqual("generic.acf", config.aircraft_acf.c_str()); } TEST_METHOD(TestButtonActions) { - Assert::AreEqual(3, (int)config.device_configs[0].push_actions["AP"].size()); - Assert::AreEqual(3, (int)config.device_configs[0].release_actions["AP"].size()); + Assert::AreEqual(3, (int)config.class_configs[0].push_actions["AP"].size()); + Assert::AreEqual(3, (int)config.class_configs[0].release_actions["AP"].size()); - Assert::AreEqual(1, (int)config.device_configs[0].push_actions["NAV"].size()); - Assert::AreEqual(1, (int)config.device_configs[0].release_actions["NAV"].size()); + Assert::AreEqual(1, (int)config.class_configs[0].push_actions["NAV"].size()); + Assert::AreEqual(1, (int)config.class_configs[0].release_actions["NAV"].size()); - Assert::AreEqual(0, (int)config.device_configs[0].push_actions.count("HDG")); - Assert::AreEqual(1, (int)config.device_configs[0].release_actions["HDG"].size()); + Assert::AreEqual(0, (int)config.class_configs[0].push_actions.count("HDG")); + Assert::AreEqual(1, (int)config.class_configs[0].release_actions["HDG"].size()); } TEST_METHOD(TestDatarefArray) { - Assert::AreEqual(1, (int)config.device_configs[0].push_actions["TEST"].size()); - Assert::AreEqual(0, (int)config.device_configs[0].release_actions.count("TEST")); + Assert::AreEqual(1, (int)config.class_configs[0].push_actions["TEST"].size()); + Assert::AreEqual(0, (int)config.class_configs[0].release_actions.count("TEST")); } }; } diff --git a/test/test_dynamic_speed.cpp b/test/test_dynamic_speed.cpp index f8770f5..9c8e220 100644 --- a/test/test_dynamic_speed.cpp +++ b/test/test_dynamic_speed.cpp @@ -24,7 +24,7 @@ int test_hid_get_vid(); int test_hid_get_pid(); std::string test_get_last_command(); void test_hid_get_write_data(unsigned char* data, size_t length); -void test_flight_loop(std::vector &config); +void test_flight_loop(std::vector &config); void test_hid_mock_init(); namespace test @@ -64,7 +64,7 @@ namespace test LuaHelper::get_instace()->init(); - device = new SaitekMultiPanel(config.device_configs[0]); + device = new SaitekMultiPanel(config.class_configs[0]); device->connect(); device->start(); t = new std::thread(&SaitekMultiPanel::thread_func, (SaitekMultiPanel*)device); @@ -81,7 +81,7 @@ namespace test { rotate_knob_plus(6, 50ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); // it shall run on x4 speed Assert::AreEqual(6 * 4, test_get_dataref_value(dataref_str.c_str())); @@ -91,7 +91,7 @@ namespace test { rotate_knob_plus(2, 200ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); // it shall run on x2 speed Assert::AreEqual(2*2, test_get_dataref_value(dataref_str.c_str())); @@ -101,7 +101,7 @@ namespace test { rotate_knob_plus(2, 500ms); // two rotations on the knob with normal speed - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); // // it shall run on x1 speed Assert::AreEqual(2, test_get_dataref_value(dataref_str.c_str())); diff --git a/test/test_generic_display.cpp b/test/test_generic_display.cpp index 04aebe4..fdd1066 100644 --- a/test/test_generic_display.cpp +++ b/test/test_generic_display.cpp @@ -23,7 +23,7 @@ int test_hid_get_vid(); int test_hid_get_pid(); std::string test_get_last_command(); void test_hid_get_write_data(unsigned char* data, size_t length); -void test_flight_loop(std::vector &config); +void test_flight_loop(std::vector &config); namespace test { @@ -44,7 +44,7 @@ namespace test LuaHelper::get_instace()->init(); LuaHelper::get_instace()->load_script_file("../../test/" + config.script_file); - device = new ArduinoHomeCockpit(config.device_configs[0]); + device = new ArduinoHomeCockpit(config.class_configs[0]); device->connect(); device->start(); t = new std::thread(&ArduinoHomeCockpit::thread_func, (ArduinoHomeCockpit*)device); @@ -54,7 +54,7 @@ namespace test XPLMDataRef dataref = XPLMFindDataRef("sim/altimeter_gauge"); XPLMSetDatai(dataref, 0xFABA); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); unsigned char write_buffer[9]; @@ -68,7 +68,7 @@ namespace test XPLMDataRef dataref = XPLMFindDataRef("sim/test/variometer"); XPLMSetDatai(dataref, -2000); // -2000 --> 0x87D0 (MSB set to 1 as number is negative) - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); unsigned char write_buffer[9]; @@ -79,7 +79,7 @@ namespace test TEST_METHOD(TestConstGauge) { - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); unsigned char write_buffer[9]; diff --git a/test/test_multi_panel.cpp b/test/test_multi_panel.cpp index 9e25a2a..a565e84 100644 --- a/test/test_multi_panel.cpp +++ b/test/test_multi_panel.cpp @@ -23,7 +23,7 @@ int test_hid_get_vid(); int test_hid_get_pid(); std::string test_get_last_command(); void test_hid_get_write_data(unsigned char* data, size_t length); -void test_flight_loop(std::vector &config); +void test_flight_loop(std::vector &config); namespace test { @@ -44,7 +44,7 @@ namespace test LuaHelper::get_instace()->init(); LuaHelper::get_instace()->load_script_file("../../test/" + config.script_file); - device = new SaitekMultiPanel(config.device_configs[0]); + device = new SaitekMultiPanel(config.class_configs[0]); device->connect(); device->start(); t = new std::thread(&SaitekMultiPanel::thread_func, (SaitekMultiPanel*)device); @@ -63,7 +63,7 @@ namespace test unsigned char buffer[4] = { 0x80,0,0,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(1, test_get_dataref_value("/sim/hello/AP")); // this command is called by the lua script: Assert::AreEqual("/sim/test/lua/button_AP_BEGIN", test_get_last_command().c_str()); @@ -71,7 +71,7 @@ namespace test buffer[0] = 0; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(0, test_get_dataref_value("/sim/hello/AP")); // this command is called by the lua script: Assert::AreEqual("/sim/test/lua/button_AP_END", test_get_last_command().c_str()); @@ -83,14 +83,14 @@ namespace test unsigned char buffer[4] = { 0,0x02,0,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::string last_cmd = test_get_last_command(); Assert::AreEqual("/sim/cmd/NAV_BEGIN", last_cmd.c_str()); memset(buffer, 0, sizeof(buffer)); test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); last_cmd = test_get_last_command(); Assert::AreEqual("/sim/cmd/NAV_END", last_cmd.c_str()); } @@ -101,7 +101,7 @@ namespace test unsigned char buffer[4] = { 0,0,0x08,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); int val_after = test_get_dataref_value("sim/custom/switchers/console/absu_pitch_wheel"); Assert::AreEqual(1, (val_after - val_before)); @@ -116,14 +116,14 @@ namespace test unsigned char buffer[4] = { 0,0x01,0,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::string last_cmd = test_get_last_command(); Assert::AreNotEqual("/sim/cmd/HDG_ONCE", last_cmd.c_str()); memset(buffer, 0, sizeof(buffer)); test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); last_cmd = test_get_last_command(); Assert::AreEqual("/sim/cmd/HDG_ONCE", last_cmd.c_str()); } @@ -133,7 +133,7 @@ namespace test XPLMDataRef dataref = XPLMFindDataRef("sim/custom/lights/button/absu_stab_h"); // ALT button light set to LIT XPLMSetDatai(dataref, 1); - test_flight_loop(config.device_configs); // evaluate triggers + test_flight_loop(config.class_configs); // evaluate triggers std::this_thread::sleep_for(150ms); unsigned char write_buffer[13]; test_hid_get_write_data(write_buffer, sizeof(write_buffer)); @@ -141,7 +141,7 @@ namespace test // ALT button light set to UNLIT XPLMSetDatai(dataref, 0); - test_flight_loop(config.device_configs); // evaluate triggers + test_flight_loop(config.class_configs); // evaluate triggers std::this_thread::sleep_for(150ms); test_hid_get_write_data(write_buffer, sizeof(write_buffer)); Assert::AreEqual(0x00, (int)write_buffer[11] & 0x10); @@ -152,7 +152,7 @@ namespace test XPLMDataRef dataref = XPLMFindDataRef("sim/custom/lights/button/absu_zk"); // HDG button light set to LIT XPLMSetDatai(dataref, 1); - test_flight_loop(config.device_configs); // evaluate triggers + test_flight_loop(config.class_configs); // evaluate triggers std::this_thread::sleep_for(150ms); unsigned char write_buffer[13]; test_hid_get_write_data(write_buffer, sizeof(write_buffer)); @@ -160,7 +160,7 @@ namespace test // HDG button light set to UNLIT XPLMSetDatai(dataref, 0); - test_flight_loop(config.device_configs); // evaluate triggers + test_flight_loop(config.class_configs); // evaluate triggers std::this_thread::sleep_for(150ms); test_hid_get_write_data(write_buffer, sizeof(write_buffer)); Assert::AreEqual(0x00, (int)write_buffer[11] & 0x02); @@ -169,7 +169,7 @@ namespace test TEST_METHOD(TestApButtonLight) { // in the test this LED has a lua handler ('get_led_status()') which return with a constant 1 value - test_flight_loop(config.device_configs); // evaluate triggers + test_flight_loop(config.class_configs); // evaluate triggers std::this_thread::sleep_for(150ms); unsigned char write_buffer[13]; test_hid_get_write_data(write_buffer, sizeof(write_buffer)); @@ -178,7 +178,7 @@ namespace test TEST_METHOD(TestMultiDisplayConfig) { - Assert::AreEqual(2, (int)config.device_configs[0].multi_displays.size()); + Assert::AreEqual(2, (int)config.class_configs[0].multi_displays.size()); } TEST_METHOD(TestMultiDisplay) @@ -191,7 +191,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); unsigned char write_buffer[13]; @@ -203,7 +203,7 @@ namespace test Assert::AreEqual(5, (int)write_buffer[5]); XPLMSetDatai(dataref, 0); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); test_hid_get_write_data(write_buffer, sizeof(write_buffer)); @@ -226,25 +226,25 @@ namespace test buffer[0] |= 0x20; // set KNOB_PLUS to 1 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(1, test_get_dataref_value(dataref_str.c_str())); buffer[0] &= (~0x20); // set KNOB_PLUS to 0 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(1, test_get_dataref_value(dataref_str.c_str())); buffer[0] |= 0x40; // set KNOB_MINUS to 1 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(0, test_get_dataref_value(dataref_str.c_str())); buffer[0] &= (~0x40); // set KNOB_MINUS to 0 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(250ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(0, test_get_dataref_value(dataref_str.c_str())); } @@ -254,7 +254,7 @@ namespace test unsigned char buffer[4] = { 0,0x40,0,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); double ret_value=0; LuaHelper::get_instace()->do_string("return get_hid_input_status('REV')", ret_value); Assert::AreEqual(1, (int)ret_value); @@ -263,7 +263,7 @@ namespace test buffer[1] = 0; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); LuaHelper::get_instace()->do_string("return get_hid_input_status('REV')", ret_value); Assert::AreEqual(0, (int)ret_value); } diff --git a/test/test_radio_panel.cpp b/test/test_radio_panel.cpp index 8813290..fd4ae6c 100644 --- a/test/test_radio_panel.cpp +++ b/test/test_radio_panel.cpp @@ -23,7 +23,7 @@ int test_hid_get_vid(); int test_hid_get_pid(); std::string test_get_last_command(); void test_hid_get_write_data(unsigned char* data, size_t length); -void test_flight_loop(std::vector &config); +void test_flight_loop(std::vector &config); void test_hid_mock_init(); namespace test @@ -57,7 +57,7 @@ namespace test LuaHelper::get_instace()->init(); LuaHelper::get_instace()->load_script_file("../../test/" + config.script_file); - device = new SaitekRadioPanel(config.device_configs[0]); + device = new SaitekRadioPanel(config.class_configs[0]); device->connect(); device->start(); t = new std::thread(&SaitekRadioPanel::thread_func, (SaitekRadioPanel*)device); @@ -86,7 +86,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); unsigned char write_buffer[23]; @@ -105,7 +105,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); unsigned char write_buffer[23]; @@ -125,7 +125,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); unsigned char write_buffer[23]; @@ -144,13 +144,13 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); buffer[2] |= 0x04; // set KNOB_UP_BIG_PLUS to 1 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(11111 + 100, test_get_dataref_value(nav1_freq_dataref_str.c_str())); // nav1 freq shal be increased by +100 Assert::AreEqual(22222, test_get_dataref_value(nav2_freq_dataref_str.c_str())); // nav2 freq shall not change Assert::AreEqual(33333, test_get_dataref_value(com1_freq_dataref_str.c_str())); // com1 freq shall not change @@ -159,7 +159,7 @@ namespace test buffer[2] &= (~0x04); // set KNOB_UP_BIG_PLUS to 0 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(11111 + 100, test_get_dataref_value(nav1_freq_dataref_str.c_str())); } diff --git a/test/test_trc1000_audio.cpp b/test/test_trc1000_audio.cpp index e9141ea..8eab3da 100644 --- a/test/test_trc1000_audio.cpp +++ b/test/test_trc1000_audio.cpp @@ -25,7 +25,7 @@ std::string test_get_last_command(); bool test_is_command_in_queue(std::string cmd_str); int test_get_command_queue_size(); void test_clear_command_queue(); -void test_flight_loop(std::vector &config); +void test_flight_loop(std::vector &config); namespace test @@ -47,7 +47,7 @@ namespace test LuaHelper::get_instace()->init(); LuaHelper::get_instace()->load_script_file("../../test/" + config.script_file); - device = new TRC1000Audio(config.device_configs[0]); + device = new TRC1000Audio(config.class_configs[0]); device->connect(); device->start(); t = new std::thread(&TRC1000Audio::thread_func, (TRC1000Audio*)device); @@ -70,7 +70,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::IsTrue(test_is_command_in_queue("sim/GPS/g1000n1_flc_ONCE")); } diff --git a/test/test_trc1000_pfd.cpp b/test/test_trc1000_pfd.cpp index 5113fe0..08f91ff 100644 --- a/test/test_trc1000_pfd.cpp +++ b/test/test_trc1000_pfd.cpp @@ -27,7 +27,7 @@ bool test_is_command_in_queue(std::string cmd_str); int test_get_command_queue_size(); void test_clear_command_queue(); void test_hid_get_write_data(unsigned char* data, size_t length); -void test_flight_loop(std::vector &config); +void test_flight_loop(std::vector &config); namespace test @@ -49,7 +49,7 @@ namespace test LuaHelper::get_instace()->init(); LuaHelper::get_instace()->load_script_file("../../test/" + config.script_file); - device = new TRC1000PFD(config.device_configs[0]); + device = new TRC1000PFD(config.class_configs[0]); device->connect(); device->start(); t = new std::thread(&TRC1000PFD::thread_func, (TRC1000PFD*)device); @@ -72,7 +72,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::IsTrue(test_is_command_in_queue("sim/GPS/g1000n1_nav_ONCE")); } @@ -86,7 +86,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::IsTrue(test_is_command_in_queue("sim/GPS/g1000n1_nav_inner_up_ONCE")); } @@ -100,7 +100,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::IsTrue(test_is_command_in_queue("sim/GPS/g1000n1_nav_inner_up_ONCE")); } @@ -115,7 +115,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); std::this_thread::sleep_for(150ms); Assert::IsFalse(test_is_command_in_queue("sim/GPS/g1000n1_nav_inner_up_ONCE")); } @@ -130,7 +130,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::IsTrue(test_is_command_in_queue("sim/GPS/g1000n1_nav_inner_down_ONCE")); } @@ -145,7 +145,7 @@ namespace test std::this_thread::sleep_for(150ms); test_clear_command_queue(); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(1, test_get_command_queue_size()); } @@ -160,7 +160,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.device_configs); + test_flight_loop(config.class_configs); Assert::AreEqual(1, test_get_command_queue_size()); } From 345466b4552aec3ef07de20bf528e142f6c758ab Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sat, 13 Apr 2024 14:18:36 +0200 Subject: [PATCH 04/15] Action.cpp: add Action* copy constructor Signed-off-by: Norbert Takacs --- src/core/Action.cpp | 22 ++++++++++++++++++++++ src/core/Action.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/core/Action.cpp b/src/core/Action.cpp index d03d16b..2a0d6da 100644 --- a/src/core/Action.cpp +++ b/src/core/Action.cpp @@ -21,6 +21,28 @@ Action::Action() dataref_type = xplmType_Unknown; } +Action::Action(Action* other) +{ + data = other->data; + data_f = other->data_f; + index = other->index; + delta = other->delta; + lua_str = other->lua_str; + condition = other->condition; + active_conditions = other->active_conditions; + dataref = other->dataref; + dataref_type = other->dataref_type; + command_type = other->command_type; + commandref = other->commandref; + tick_per_sec_mid = other->tick_per_sec_mid; + tick_per_sec_high = other->tick_per_sec_high; + multi_low = other->multi_low; + multi_high = other->multi_high; + multi = other->multi; + max = other->max; + min = other->min; +} + Action::Action(XPLMCommandRef cmd, CommandType type) { commandref = cmd; diff --git a/src/core/Action.h b/src/core/Action.h index 226f75e..8447048 100644 --- a/src/core/Action.h +++ b/src/core/Action.h @@ -27,6 +27,7 @@ class Action { public: Action(); + Action(Action* other); Action(XPLMDataRef dat, int d); Action(XPLMDataRef dat, float d); Action(XPLMDataRef dat, double d); From f606b73934edbb7f635c13c6b2d0fe133260b333 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sat, 13 Apr 2024 14:19:17 +0200 Subject: [PATCH 05/15] Trigger.cpp: Add Trigger* copy constructor Signed-off-by: Norbert Takacs --- src/core/Trigger.cpp | 12 ++++++++++++ src/core/Trigger.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/core/Trigger.cpp b/src/core/Trigger.cpp index 4c13141..6a7656b 100644 --- a/src/core/Trigger.cpp +++ b/src/core/Trigger.cpp @@ -16,9 +16,21 @@ Trigger::Trigger() trigger_value = 0; trigger_action = TriggerType::NO_CHANGE; stored_action = TriggerType::NO_CHANGE; + lua_str = ""; last_value = -1; } +Trigger::Trigger(Trigger* other) +{ + data_ref = other->data_ref; + data_ref_type = other->data_ref_type; + trigger_value = other->trigger_value; + trigger_action = other->trigger_action; + stored_action = other->stored_action; + last_value = other->last_value; + lua_str = other->lua_str; +} + Trigger::Trigger(XPLMDataRef data, double val, TriggerType _trigger_action) { data_ref = data; diff --git a/src/core/Trigger.h b/src/core/Trigger.h index a724136..daaa63c 100644 --- a/src/core/Trigger.h +++ b/src/core/Trigger.h @@ -24,6 +24,7 @@ class Trigger { public: Trigger(); + Trigger(Trigger* other); Trigger(XPLMDataRef data, double val, TriggerType _trig_action); Trigger(std::string _lua_str, double val, TriggerType _trigger_action); TriggerType get_and_clear_stored_action(); From db6163716e1946bdc3c49562c5106ef4b290aaa0 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sat, 13 Apr 2024 14:20:24 +0200 Subject: [PATCH 06/15] Configuration: add deep copy for each device instances Signed-off-by: Norbert Takacs --- src/core/Configuration.cpp | 80 ++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/src/core/Configuration.cpp b/src/core/Configuration.cpp index a96efb5..ffbe52f 100644 --- a/src/core/Configuration.cpp +++ b/src/core/Configuration.cpp @@ -6,6 +6,7 @@ #include "Logger.h" #include "Configuration.h" +#include "fip/FIPScreen.h" /*------ Plugin level configuration options ------------*/ Configuration& Configuration::operator=(const Configuration& other) @@ -48,17 +49,37 @@ ClassConfiguration::ClassConfiguration(const ClassConfiguration& other): device_class_type(other.device_class_type), pid(other.pid), vid(other.vid), - serial_number(other.serial_number), - push_actions(other.push_actions), - release_actions(other.release_actions), - encoder_inc_actions(other.encoder_inc_actions), - encoder_dec_actions(other.encoder_dec_actions), - light_triggers(other.light_triggers), - multi_displays(other.multi_displays), - generic_displays(other.generic_displays), - fip_screens(other.fip_screens) + serial_number(other.serial_number) { Logger(TLogLevel::logTRACE) << "ClassConfiguration copy constructor called" << std::endl; + for (auto push_act : other.push_actions) + for (auto act : push_act.second) + push_actions[push_act.first].push_back(new Action(act)); + + for (auto release_act : other.release_actions) + for (auto act : release_act.second) + release_actions[release_act.first].push_back(new Action(act)); + + for (auto enc_inc_act : other.encoder_inc_actions) + for (auto act : enc_inc_act.second) + encoder_inc_actions[enc_inc_act.first].push_back(new Action(act)); + + for (auto enc_dec_act : other.encoder_dec_actions) + for (auto act : enc_dec_act.second) + encoder_dec_actions[enc_dec_act.first].push_back(new Action(act)); + + for (auto l_trig : other.light_triggers) + for (auto trg : l_trig.second) + light_triggers[l_trig.first].push_back(new Trigger(trg)); + + for (auto m_disp : other.multi_displays) + multi_displays[m_disp.first] = new MultiPurposeDisplay(m_disp.second); + + for (auto g_disp : other.generic_displays) + generic_displays[g_disp.first] = new GenericDisplay(g_disp.second); + + for (auto fip_screen : other.fip_screens) + fip_screens[fip_screen.first] = new FIPScreen(fip_screen.second); } ClassConfiguration& ClassConfiguration::operator=(const ClassConfiguration& other) @@ -72,14 +93,35 @@ ClassConfiguration& ClassConfiguration::operator=(const ClassConfiguration& othe pid = other.pid; vid = other.vid; serial_number = other.serial_number; - push_actions = other.push_actions; - release_actions = other.release_actions; - encoder_inc_actions = other.encoder_inc_actions; - encoder_dec_actions = other.encoder_dec_actions; - light_triggers = other.light_triggers; - multi_displays = other.multi_displays; - generic_displays = other.generic_displays; - fip_screens = other.fip_screens; + + for (auto push_act : other.push_actions) + for (auto act : push_act.second) + push_actions[push_act.first].push_back(new Action(act)); + + for (auto release_act : other.release_actions) + for (auto act : release_act.second) + release_actions[release_act.first].push_back(new Action(act)); + + for (auto enc_inc_act : other.encoder_inc_actions) + for (auto act : enc_inc_act.second) + encoder_inc_actions[enc_inc_act.first].push_back(new Action(act)); + + for (auto enc_dec_act : other.encoder_dec_actions) + for (auto act : enc_dec_act.second) + encoder_dec_actions[enc_dec_act.first].push_back(new Action(act)); + + for (auto l_trig : other.light_triggers) + for (auto trg : l_trig.second) + light_triggers[l_trig.first].push_back(new Trigger(trg)); + + for (auto m_disp : other.multi_displays) + multi_displays[m_disp.first] = new MultiPurposeDisplay(m_disp.second); + + for (auto g_disp : other.generic_displays) + generic_displays[g_disp.first] = new GenericDisplay(g_disp.second); + + for (auto fip_screen : other.fip_screens) + fip_screens[fip_screen.first] = new FIPScreen(fip_screen.second); return *this; } @@ -105,6 +147,10 @@ void ClassConfiguration::clear() for (auto &act : light_triggers) act.second.clear(); light_triggers.clear(); + + for (auto& scr : fip_screens) + delete scr.second; + fip_screens.clear(); } ClassConfiguration::~ClassConfiguration() From fd22ef2313a19c42383748773c66ce0418ff4e13 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sat, 13 Apr 2024 14:21:18 +0200 Subject: [PATCH 07/15] Device: add get_config() Signed-off-by: Norbert Takacs --- src/core/Device.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/Device.h b/src/core/Device.h index 1f2a870..70fd1c4 100644 --- a/src/core/Device.h +++ b/src/core/Device.h @@ -109,6 +109,10 @@ class Device ~Device(); int get_stored_button_state(std::string button_name); TriggerType get_stored_light_state(std::string light_name); + ClassConfiguration& get_config() + { + return config; + } bool updateLightStates(); void process_and_store_button_states(); void process_selector_switch(); From c6ba952084c14303072493cdc26fb56303d6440d Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sat, 13 Apr 2024 14:22:14 +0200 Subject: [PATCH 08/15] Multi Display: add copy constructor Signed-off-by: Norbert Takacs --- src/core/MultiPurposeDisplay.cpp | 15 +++++++++++++++ src/core/MultiPurposeDisplay.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/core/MultiPurposeDisplay.cpp b/src/core/MultiPurposeDisplay.cpp index 7e1a164..bc7bd80 100644 --- a/src/core/MultiPurposeDisplay.cpp +++ b/src/core/MultiPurposeDisplay.cpp @@ -19,6 +19,21 @@ MultiPurposeDisplay::MultiPurposeDisplay() nr_of_bytes = 5; } +MultiPurposeDisplay::MultiPurposeDisplay(MultiPurposeDisplay* other) +{ + active_condition = other->active_condition; + display_value = other->display_value; + display_value_old = other->display_value_old; + display_value_changed = other->display_value_changed; + nr_of_bytes = other->nr_of_bytes; + turn_off = other->turn_off; + + conditions = other->conditions; + const_values = other->const_values; + lua_functions = other->lua_functions; + data_ref_types = other->data_ref_types; +} + void MultiPurposeDisplay::add_condition(std::string selector_sw_name, XPLMDataRef data) { if (conditions.find(selector_sw_name) != conditions.end()) diff --git a/src/core/MultiPurposeDisplay.h b/src/core/MultiPurposeDisplay.h index fe4e9b8..d384c7b 100644 --- a/src/core/MultiPurposeDisplay.h +++ b/src/core/MultiPurposeDisplay.h @@ -17,6 +17,7 @@ class MultiPurposeDisplay : public GenericDisplay { public: MultiPurposeDisplay(); + MultiPurposeDisplay(MultiPurposeDisplay* other); // called during init phase void add_condition(std::string selector_sw_name, XPLMDataRef data); void add_condition(std::string selector_sw_name, double const_value); From 28332fc9e52a212722326ab429a987321dd15487 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sat, 13 Apr 2024 16:44:16 +0200 Subject: [PATCH 09/15] FIP: Add copy constructors Signed-off-by: Norbert Takacs --- src/devices/fip/FIPDevice.cpp | 4 ++-- src/devices/fip/FIPImageLayer.cpp | 24 ++++++++++++++++++++++-- src/devices/fip/FIPImageLayer.h | 9 +++++++++ src/devices/fip/FIPLayer.cpp | 13 +++++++++++++ src/devices/fip/FIPLayer.h | 1 + src/devices/fip/FIPPage.cpp | 31 ++++++++++++++++++++++++++++++- src/devices/fip/FIPPage.h | 1 + src/devices/fip/FIPScreen.cpp | 21 ++++++++++++++++----- src/devices/fip/FIPScreen.h | 1 + src/devices/fip/FIPTextLayer.cpp | 9 +++++++++ src/devices/fip/FIPTextLayer.h | 1 + 11 files changed, 105 insertions(+), 10 deletions(-) diff --git a/src/devices/fip/FIPDevice.cpp b/src/devices/fip/FIPDevice.cpp index bb4a7c1..71db455 100644 --- a/src/devices/fip/FIPDevice.cpp +++ b/src/devices/fip/FIPDevice.cpp @@ -149,7 +149,7 @@ void FIPDevice::thread_func() _thread_finish.store(false); // create page registers in physical device - for (const auto &it_screen : config.fip_screens) + for (const auto &it_screen : get_config().fip_screens) { for (int page_index = 0; page_index <= it_screen.second->get_last_page_index(); page_index++) { @@ -162,7 +162,7 @@ void FIPDevice::thread_func() while (_thread_run.load() == true) { std::this_thread::sleep_for(20ms); - for (auto &screen : config.fip_screens) + for (auto &screen : get_config().fip_screens) { render_screen(screen.second); process_page_conditions(screen.second); diff --git a/src/devices/fip/FIPImageLayer.cpp b/src/devices/fip/FIPImageLayer.cpp index 81cfc90..a820124 100644 --- a/src/devices/fip/FIPImageLayer.cpp +++ b/src/devices/fip/FIPImageLayer.cpp @@ -24,7 +24,7 @@ bool ImageBuffer::load_from_bmp_file(std::string file_name) height = bmp_header.height_px; width = bmp_header.width_px; - int bytes_per_pixel = bmp_header.bits_per_pixel / 8; + bytes_per_pixel = bmp_header.bits_per_pixel / 8; if (bytes_per_pixel != 3) { Logger(logERROR) << "Bad BMP file format. It should be 24 bit color depth: " << file_name << std::endl; @@ -64,6 +64,19 @@ ImageBuffer::ImageBuffer() height = 0; } +ImageBuffer& ImageBuffer::operator=(const ImageBuffer &other) +{ + width = other.width; + height = other.height; + bytes_per_pixel = other.bytes_per_pixel; + + size_t buffer_size = width * height * 3; + raw_buffer = (unsigned char*)calloc(buffer_size, sizeof(unsigned char)); + memcpy(raw_buffer, other.raw_buffer, buffer_size); + + return *this; +} + void ImageBuffer::set_and_allocate_buffer(int _width, int _height) { if (raw_buffer) @@ -114,7 +127,14 @@ ImageBuffer::~ImageBuffer() FIPImageLayer::FIPImageLayer() :FIPLayer() { - + type = FIPImageLayer::type = FIPImageLayer::IMAGE; +} + +FIPImageLayer::FIPImageLayer(FIPImageLayer* other) + :FIPLayer(other) +{ + image_buffer = other->image_buffer; + type = other->type; } FIPImageLayer::~FIPImageLayer() diff --git a/src/devices/fip/FIPImageLayer.h b/src/devices/fip/FIPImageLayer.h index 29d2508..8cf547b 100644 --- a/src/devices/fip/FIPImageLayer.h +++ b/src/devices/fip/FIPImageLayer.h @@ -35,8 +35,10 @@ class ImageBuffer { private: BMPHeader bmp_header; unsigned char* raw_buffer; + int bytes_per_pixel; public: ImageBuffer(); + ImageBuffer& operator=(const ImageBuffer& other); void set_and_allocate_buffer(int _width, int _height); virtual ~ImageBuffer(); int width; @@ -55,8 +57,15 @@ class FIPImageLayer: public FIPLayer ImageBuffer image_buffer; public: FIPImageLayer(); + FIPImageLayer(FIPImageLayer* other); virtual ~FIPImageLayer(); bool load_file(std::string file_name, int ref_x, int ref_y); virtual void get_pixel_at_pos(Pixel* pixel, int row, int col); virtual unsigned char* get_raw_buffer(); + typedef enum { + IMAGE, + TEXT + } FIPLayerType; + FIPLayerType type; + }; \ No newline at end of file diff --git a/src/devices/fip/FIPLayer.cpp b/src/devices/fip/FIPLayer.cpp index b27703c..94af959 100644 --- a/src/devices/fip/FIPLayer.cpp +++ b/src/devices/fip/FIPLayer.cpp @@ -19,6 +19,19 @@ FIPLayer::FIPLayer() mask.enabled = false; } +FIPLayer::FIPLayer(FIPLayer* other) +{ + width = other->width; + height = other->height; + ref_x = other->ref_x; + ref_y = other->ref_y; + pos_x = other->pos_x; + pos_y = other->pos_y; + angle = other->angle; + base_rot = other->base_rot; + mask = other->mask; +} + FIPLayer::~FIPLayer() { /* if (raw_buffer) diff --git a/src/devices/fip/FIPLayer.h b/src/devices/fip/FIPLayer.h index e0f85f3..8516f72 100644 --- a/src/devices/fip/FIPLayer.h +++ b/src/devices/fip/FIPLayer.h @@ -67,6 +67,7 @@ class FIPLayer MaskWindow mask; public: FIPLayer(); + FIPLayer(FIPLayer* other); virtual ~FIPLayer(); // virtual bool load_file(std::string file_name, int ref_x, int ref_y)=0; void set_mask(MaskWindow& mask); diff --git a/src/devices/fip/FIPPage.cpp b/src/devices/fip/FIPPage.cpp index be2fc6d..3832fa3 100644 --- a/src/devices/fip/FIPPage.cpp +++ b/src/devices/fip/FIPPage.cpp @@ -23,6 +23,34 @@ FIPPage::FIPPage(int _screen_width, int _screen_height, int _bit_per_pixel, std: page_raw_buffer_ptr_int = page_raw_buffer_2; } +FIPPage::FIPPage(FIPPage* other) +{ + bit_per_pixel = other->bit_per_pixel; + screen_height = other->screen_height; + screen_width = other->screen_width; + page_name = other->page_name; + raw_buffer_size = other->raw_buffer_size; + + page_raw_buffer_1 = (unsigned char*)calloc(raw_buffer_size, sizeof(unsigned char)); + page_raw_buffer_2 = (unsigned char*)calloc(raw_buffer_size, sizeof(unsigned char)); + + memcpy(page_raw_buffer_1, other->page_raw_buffer_1, raw_buffer_size); + memcpy(page_raw_buffer_2, other->page_raw_buffer_2, raw_buffer_size); + + page_raw_buffer_ptr_act = page_raw_buffer_1; + page_raw_buffer_ptr_int = page_raw_buffer_2; + + for (auto lay : other->layers) + { + if (lay->type == FIPImageLayer::FIPLayerType::IMAGE) + layers.push_back(new FIPImageLayer(lay)); + else if (lay->type == FIPImageLayer::FIPLayerType::TEXT) + layers.push_back(new FIPTextLayer((FIPTextLayer*)lay)); + else + Logger(TLogLevel::logERROR) << "FIP Page: unknown layer type"; + } +} + FIPPage::~FIPPage() { for (int i = 0; i < layers.size(); i++) @@ -51,7 +79,7 @@ int FIPPage::add_layer_from_bmp_file(std::string filename, int ref_x, int ref_y, new_layer->set_pos_y(0); new_layer->set_angle(0); new_layer->set_base_rot(base_rot); - + new_layer->type = FIPImageLayer::FIPLayerType::IMAGE; layers.push_back(new_layer); return (int)layers.size() - 1; } @@ -64,6 +92,7 @@ int FIPPage::add_text_layer(std::string font_filename, int base_rot) new_layer->set_pos_y(0); new_layer->set_angle(0); new_layer->set_base_rot(base_rot); + new_layer->type = FIPImageLayer::FIPLayerType::TEXT; layers.push_back(new_layer); return (int)layers.size() - 1; diff --git a/src/devices/fip/FIPPage.h b/src/devices/fip/FIPPage.h index 7274d30..5f8430e 100644 --- a/src/devices/fip/FIPPage.h +++ b/src/devices/fip/FIPPage.h @@ -35,6 +35,7 @@ class FIPPage void render_layer(int layer_index); public: FIPPage(int _screen_width, int _screen_height, int _bit_per_pixel, std::string _page_name); + FIPPage(FIPPage* other); ~FIPPage(); int add_layer_from_bmp_file(std::string filename, int ref_x, int ref_y, int base_rot); int add_text_layer(std::string font_filename, int base_rot); diff --git a/src/devices/fip/FIPScreen.cpp b/src/devices/fip/FIPScreen.cpp index 35337b9..fe7664c 100644 --- a/src/devices/fip/FIPScreen.cpp +++ b/src/devices/fip/FIPScreen.cpp @@ -16,9 +16,17 @@ FIPScreen::FIPScreen() :GenericScreen() pages.clear(); } +FIPScreen::FIPScreen(FIPScreen* other) : GenericScreen(other) +{ + for (auto fip_page : other->pages) + { + pages[fip_page.first] = new FIPPage(fip_page.second); + } +} + FIPScreen::~FIPScreen() { - for (const auto &it_page : pages) + for (const auto& it_page : pages) delete it_page.second; pages.clear(); @@ -26,8 +34,11 @@ FIPScreen::~FIPScreen() void FIPScreen::evaluate_and_store_screen_action() { - for (auto &action : screen_action_queue) + int i = 0; + for (auto& action : screen_action_queue) { + Logger(TLogLevel::logTRACE) << "FIPScreen::evaluate_and_store_screen_action: " << i << std::endl; + i++; int action_value = 0; std::string action_value_str = ""; @@ -35,7 +46,7 @@ void FIPScreen::evaluate_and_store_screen_action() { if (action->data_ref_type == xplmType_Data) action_value_str = read_dataref_str(action->data_ref); - else + else { if (action->data_ref_index > -1) action_value = action->scale_factor * read_data_ref_int(action->data_ref, action->data_ref_type, action->data_ref_index); @@ -68,7 +79,7 @@ void FIPScreen::evaluate_and_store_screen_action() //return; } - if ((action->scale_factor == 0 || abs(action->value_old - action_value) < (1/action->scale_factor)) && (action->value_str_old == action_value_str)) + if ((action->scale_factor == 0 || abs(action->value_old - action_value) < (1 / action->scale_factor)) && (action->value_str_old == action_value_str)) continue; action->value_old = action_value; @@ -148,7 +159,7 @@ int FIPScreen::add_layer_to_page(int page_index, std::string bmp_file_name, int int FIPScreen::add_text_layer_to_page(int page_index, std::string font_file_name, int base_rot) { - Logger(logTRACE) << "FIP screen: add text layer to page " << page_index << "font file name:" << font_file_name << std::endl; + Logger(logTRACE) << "FIP screen: add text layer to page " << page_index << "font file name:" << font_file_name << std::endl; if (!std::filesystem::exists(font_file_name)) { diff --git a/src/devices/fip/FIPScreen.h b/src/devices/fip/FIPScreen.h index a7866b0..72197bf 100644 --- a/src/devices/fip/FIPScreen.h +++ b/src/devices/fip/FIPScreen.h @@ -20,6 +20,7 @@ class FIPScreen : public GenericScreen std::mutex guard; public: FIPScreen(); + FIPScreen(FIPScreen* other); ~FIPScreen(); void evaluate_and_store_screen_action(); diff --git a/src/devices/fip/FIPTextLayer.cpp b/src/devices/fip/FIPTextLayer.cpp index e8dd49e..93578ab 100644 --- a/src/devices/fip/FIPTextLayer.cpp +++ b/src/devices/fip/FIPTextLayer.cpp @@ -15,11 +15,20 @@ FIPTextLayer::FIPTextLayer() : image_buffer.set_and_allocate_buffer(MAX_CHAR_COUNT* (FIP_MAX_FONT_WIDTH + CHAR_SPACE), FIP_FONT_HEIGHT); width = image_buffer.width; height = image_buffer.height; + type = FIPImageLayer::type = FIPImageLayer::TEXT; +} + +FIPTextLayer::FIPTextLayer(FIPTextLayer* other) : + FIPImageLayer(other) +{ + text = other->text; + font_image_buffer = other->font_image_buffer; } FIPTextLayer::~FIPTextLayer() { fip_font_positions.clear(); + Logger(TLogLevel::logDEBUG) << "FIPTextLayer: destructor called" << std::endl; } bool FIPTextLayer::load_bmp_font_file(std::string file_name) diff --git a/src/devices/fip/FIPTextLayer.h b/src/devices/fip/FIPTextLayer.h index eaf41df..28eec6f 100644 --- a/src/devices/fip/FIPTextLayer.h +++ b/src/devices/fip/FIPTextLayer.h @@ -15,6 +15,7 @@ class FIPTextLayer : public FIPImageLayer const int CHAR_SPACE = 2; public: FIPTextLayer(); + FIPTextLayer(FIPTextLayer* other); virtual ~FIPTextLayer(); bool load_bmp_font_file(std::string file_name); void set_text(std::string _text); From b4a1b2dc405c88b8a148f447cd5ef8fbc8cb7582 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sat, 13 Apr 2024 14:22:59 +0200 Subject: [PATCH 10/15] parsed configuration only for intialization Signed-off-by: Norbert Takacs --- src/core/XPanel.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/XPanel.cpp b/src/core/XPanel.cpp index 1b7fa83..05e46cd 100644 --- a/src/core/XPanel.cpp +++ b/src/core/XPanel.cpp @@ -62,7 +62,6 @@ float error_display_callback(float inElapsedSinceLastCall, float inElapsedTimeSi void stop_and_clear_xpanel_plugin(); int init_and_start_xpanel_plugin(); -Configuration config; std::vector devices; bool plugin_already_initialized = false; const float FLIGHT_LOOP_TIME_PERIOD = 0.2f; @@ -127,29 +126,29 @@ PLUGIN_API int XPluginEnable(void) float flight_loop_callback(float, float, int, void*) { - for (const auto& it : config.class_configs) + for (auto dev : devices) { - // check and set LED states - for (const auto& triggers : it.light_triggers) + for (const auto& triggers : dev->get_config().light_triggers) { for (auto& trigger : triggers.second) { trigger->evaluate_and_store_action(); } } + // check and set 7 segment display states - for (const auto& display : it.multi_displays) + for (const auto& display : dev->get_config().multi_displays) { display.second->evaluate_and_store_dataref_value(); } - for (const auto& display : it.generic_displays) + for (const auto& display : dev->get_config().generic_displays) { display.second->evaluate_and_store_dataref_value(); } // update the FIP devices - for (auto& screen : it.fip_screens) + for (const auto& screen : dev->get_config().fip_screens) { screen.second->evaluate_and_store_screen_action(); } @@ -192,7 +191,6 @@ void stop_and_clear_xpanel_plugin() } } devices.clear(); - config.clear(); ActionQueue::get_instance()->clear_all_actions(); plugin_already_initialized = false; @@ -261,6 +259,8 @@ int enumerate_and_add_hid_devices(ClassConfiguration& it) int init_and_start_xpanel_plugin(void) { + Configuration config; + char aircraft_file_name[256]; char aircraft_file_path[512]; XPLMGetNthAircraftModel(0, aircraft_file_name, aircraft_file_path); From 318fbd196f156ba8f99acca2d688d9eeb2fdc2f3 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sun, 14 Apr 2024 14:05:02 +0200 Subject: [PATCH 11/15] GenericDisplay: add copy constructor Signed-off-by: Norbert Takacs --- src/core/GenericDisplay.cpp | 14 ++++++++++++++ src/core/GenericDisplay.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/core/GenericDisplay.cpp b/src/core/GenericDisplay.cpp index dfc8e1b..ee76d59 100644 --- a/src/core/GenericDisplay.cpp +++ b/src/core/GenericDisplay.cpp @@ -21,6 +21,20 @@ GenericDisplay::GenericDisplay(bool _use_bcd) const_value = DBL_MIN; } +GenericDisplay::GenericDisplay(GenericDisplay* other) +{ + display_value = other->display_value; + display_value_old = other->display_value_old; + display_value_changed = other->display_value_changed; + use_bcd = other->use_bcd; + lua_function = other->lua_function; + condition = other->condition; + data_ref_type = other->data_ref_type; + const_value = other->const_value; + nr_of_bytes = other->nr_of_bytes; + dataref_index = other->dataref_index; +} + GenericDisplay::GenericDisplay():GenericDisplay(true) { // diff --git a/src/core/GenericDisplay.h b/src/core/GenericDisplay.h index 8cb2121..7caa637 100644 --- a/src/core/GenericDisplay.h +++ b/src/core/GenericDisplay.h @@ -19,6 +19,7 @@ class GenericDisplay public: GenericDisplay(); GenericDisplay(bool _use_bcd); // bcd: binary encoded decimal + GenericDisplay(GenericDisplay* other); void set_nr_bytes(int _nr_of_bytes); From 5f59384533a3dccb52ab519c7580a69e0c940467 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sun, 14 Apr 2024 18:28:51 +0200 Subject: [PATCH 12/15] GenericScreen: add copy constructor Signed-off-by: Norbert Takacs --- src/core/GenericScreen.cpp | 8 ++++++++ src/core/GenericScreen.h | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/core/GenericScreen.cpp b/src/core/GenericScreen.cpp index d46d35a..8bf41bb 100644 --- a/src/core/GenericScreen.cpp +++ b/src/core/GenericScreen.cpp @@ -13,6 +13,14 @@ GenericScreen::GenericScreen() screen_action_queue.clear(); } +GenericScreen::GenericScreen(GenericScreen* other) +{ + for (auto sc_act : other->screen_action_queue) + { + screen_action_queue.push_back(new ScreenAction(sc_act)); + } +} + GenericScreen::~GenericScreen() { for (auto &action : screen_action_queue) diff --git a/src/core/GenericScreen.h b/src/core/GenericScreen.h index 64663b8..fafb693 100644 --- a/src/core/GenericScreen.h +++ b/src/core/GenericScreen.h @@ -36,19 +36,19 @@ class ScreenAction { constant_val = 0; } - ScreenAction(const ScreenAction& other) + ScreenAction(ScreenAction* other) { - type = other.type; - page_index = other.page_index; - layer_index = other.layer_index; - value_old = other.value_old; - value_str_old = other.value_str_old; - scale_factor = other.scale_factor; - data_ref = other.data_ref; - data_ref_index = other.data_ref_index; - data_ref_type = other.data_ref_type; - lua_str = other.lua_str; - constant_val = other.constant_val; + type = other->type; + page_index = other->page_index; + layer_index = other->layer_index; + value_old = other->value_old; + value_str_old = other->value_str_old; + scale_factor = other->scale_factor; + data_ref = other->data_ref; + data_ref_index = other->data_ref_index; + data_ref_type = other->data_ref_type; + lua_str = other->lua_str; + constant_val = other->constant_val; } ScreenActionType type; @@ -75,6 +75,7 @@ class GenericScreen std::string read_dataref_str(XPLMDataRef data_ref); public: GenericScreen(); + GenericScreen(GenericScreen* other); ~GenericScreen(); virtual void evaluate_and_store_screen_action()=0; virtual void render_page(int page_index, void** byte_buffer) = 0; From 49fb07c05b6481521c370f04d75078166c4bdf28 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sun, 14 Apr 2024 14:10:32 +0200 Subject: [PATCH 13/15] Devices: use own configuration instead of class config Signed-off-by: Norbert Takacs --- src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp | 2 +- src/devices/saitek-multi/SaitekMultiPanel.cpp | 2 +- src/devices/saitek-radio/SaitekRadioPanel.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp index 383e047..8c9a7e0 100644 --- a/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp +++ b/src/devices/arduino-homecockpit/ArduinoHomeCockpit.cpp @@ -34,7 +34,7 @@ ArduinoHomeCockpit::ArduinoHomeCockpit(ClassConfiguration& config) :UsbHidDevice register_buttons(arduino_buttons); register_displays(arduino_displays); - for (auto &config_display : config.generic_displays) + for (auto config_display : get_config().generic_displays) { int nr_of_bytes = 0; for (auto &panel_display : arduino_displays) diff --git a/src/devices/saitek-multi/SaitekMultiPanel.cpp b/src/devices/saitek-multi/SaitekMultiPanel.cpp index 7e74729..753e334 100644 --- a/src/devices/saitek-multi/SaitekMultiPanel.cpp +++ b/src/devices/saitek-multi/SaitekMultiPanel.cpp @@ -61,7 +61,7 @@ SaitekMultiPanel::SaitekMultiPanel(ClassConfiguration& config) :UsbHidDevice(con register_displays(multi_displays); - for (auto &config_display : config.multi_displays) + for (auto &config_display : get_config().multi_displays) { config_display.second->set_nr_bytes(display_width); } diff --git a/src/devices/saitek-radio/SaitekRadioPanel.cpp b/src/devices/saitek-radio/SaitekRadioPanel.cpp index 9996d34..fcdf0a8 100644 --- a/src/devices/saitek-radio/SaitekRadioPanel.cpp +++ b/src/devices/saitek-radio/SaitekRadioPanel.cpp @@ -56,7 +56,7 @@ SaitekRadioPanel::SaitekRadioPanel(ClassConfiguration& config) :UsbHidDevice(con register_displays(radio_displays); - for (auto &config_display : config.multi_displays) + for (auto &config_display : get_config().multi_displays) { config_display.second->set_nr_bytes(display_width); } From 71680c9238a08a68b09c1c9c62f228db6deae638 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sun, 14 Apr 2024 14:11:22 +0200 Subject: [PATCH 14/15] test: create new test_flight_loop function Signed-off-by: Norbert Takacs --- test/mock_xplane.cpp | 31 ++++++++++++++++++++++++++ test/test_FIP.cpp | 8 +++---- test/test_generic_display.cpp | 14 ++++++------ test/test_multi_panel.cpp | 41 ++++++++++++++++++----------------- test/test_radio_panel.cpp | 14 ++++++------ 5 files changed, 70 insertions(+), 38 deletions(-) diff --git a/test/mock_xplane.cpp b/test/mock_xplane.cpp index b67afa0..9bbe55a 100644 --- a/test/mock_xplane.cpp +++ b/test/mock_xplane.cpp @@ -328,3 +328,34 @@ void test_flight_loop(std::vector &config) // process button push/release events ActionQueue::get_instance()->activate_actions_in_queue(); } + +void test_flight_loop(Device* dev) +{ + for (const auto& triggers : dev->get_config().light_triggers) + { + for (auto& trigger : triggers.second) + { + trigger->evaluate_and_store_action(); + } + } + + // check and set 7 segment display states + for (const auto& display : dev->get_config().multi_displays) + { + display.second->evaluate_and_store_dataref_value(); + } + + for (const auto& display : dev->get_config().generic_displays) + { + display.second->evaluate_and_store_dataref_value(); + } + + // update the FIP devices + for (auto& screen : dev->get_config().fip_screens) + { + screen.second->evaluate_and_store_screen_action(); + } + + // process button push/release events + ActionQueue::get_instance()->activate_actions_in_queue(); +} \ No newline at end of file diff --git a/test/test_FIP.cpp b/test/test_FIP.cpp index cd78286..70abfd8 100644 --- a/test/test_FIP.cpp +++ b/test/test_FIP.cpp @@ -18,7 +18,7 @@ void test_set_aircraft_path_and_filename(char* file_name, char* path); int test_fip_get_led_state(int led_index); void test_fip_set_button_states(uint16_t _button_states); void test_fip_set_current_page(int page); -void test_flight_loop(std::vector &config); +void test_flight_loop(Device* device); void test_fip_get_image(unsigned char* buffer, size_t buffer_size); namespace test @@ -67,14 +67,14 @@ namespace test TEST_METHOD(TestFIPAirSpeedChange) { XPLMSetDatai(airspeed_dataref, 0); - test_flight_loop(config.class_configs); + test_flight_loop(fip_device); std::this_thread::sleep_for(150ms); unsigned char fip_image_buffer[240 * 320 * 3]; test_fip_get_image(fip_image_buffer, 240 * 320 * 3); Assert::AreEqual(0, (int)fip_image_buffer[0]); XPLMSetDatai(airspeed_dataref, 150); - test_flight_loop(config.class_configs); + test_flight_loop(fip_device); std::this_thread::sleep_for(150ms); test_fip_get_image(fip_image_buffer, 240 * 320 * 3); Assert::AreEqual(0, (int)fip_image_buffer[0]); @@ -88,7 +88,7 @@ namespace test byte as padding in each row. Those padding bytes shall be handled by RawBMP class. The 5x3 BMP layer will be put to 0,0 position */ test_fip_set_current_page(2); - test_flight_loop(config.class_configs); + test_flight_loop(fip_device); std::this_thread::sleep_for(150ms); const int row_count = 240; //height diff --git a/test/test_generic_display.cpp b/test/test_generic_display.cpp index fdd1066..6b4c54f 100644 --- a/test/test_generic_display.cpp +++ b/test/test_generic_display.cpp @@ -23,20 +23,20 @@ int test_hid_get_vid(); int test_hid_get_pid(); std::string test_get_last_command(); void test_hid_get_write_data(unsigned char* data, size_t length); -void test_flight_loop(std::vector &config); +void test_flight_loop(Device* dev); namespace test { TEST_CLASS(test_generic_display) { - private: - Configuration config; + private: Configparser* p; ArduinoHomeCockpit* device; std::thread* t; public: TEST_METHOD_INITIALIZE(TestGenericDisplayInit) { + Configuration config; p = new Configparser(); int result = p->parse_file("../../test/test-arduino-home.ini", config); Assert::AreEqual(0, result); @@ -53,8 +53,8 @@ namespace test { XPLMDataRef dataref = XPLMFindDataRef("sim/altimeter_gauge"); XPLMSetDatai(dataref, 0xFABA); - - test_flight_loop(config.class_configs); + + test_flight_loop(device); std::this_thread::sleep_for(150ms); unsigned char write_buffer[9]; @@ -68,7 +68,7 @@ namespace test XPLMDataRef dataref = XPLMFindDataRef("sim/test/variometer"); XPLMSetDatai(dataref, -2000); // -2000 --> 0x87D0 (MSB set to 1 as number is negative) - test_flight_loop(config.class_configs); + test_flight_loop(device); std::this_thread::sleep_for(150ms); unsigned char write_buffer[9]; @@ -79,7 +79,7 @@ namespace test TEST_METHOD(TestConstGauge) { - test_flight_loop(config.class_configs); + test_flight_loop(device); std::this_thread::sleep_for(150ms); unsigned char write_buffer[9]; diff --git a/test/test_multi_panel.cpp b/test/test_multi_panel.cpp index a565e84..97a8ace 100644 --- a/test/test_multi_panel.cpp +++ b/test/test_multi_panel.cpp @@ -24,6 +24,7 @@ int test_hid_get_pid(); std::string test_get_last_command(); void test_hid_get_write_data(unsigned char* data, size_t length); void test_flight_loop(std::vector &config); +void test_flight_loop(Device* dev); namespace test { @@ -63,7 +64,7 @@ namespace test unsigned char buffer[4] = { 0x80,0,0,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); Assert::AreEqual(1, test_get_dataref_value("/sim/hello/AP")); // this command is called by the lua script: Assert::AreEqual("/sim/test/lua/button_AP_BEGIN", test_get_last_command().c_str()); @@ -71,7 +72,7 @@ namespace test buffer[0] = 0; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); Assert::AreEqual(0, test_get_dataref_value("/sim/hello/AP")); // this command is called by the lua script: Assert::AreEqual("/sim/test/lua/button_AP_END", test_get_last_command().c_str()); @@ -83,14 +84,14 @@ namespace test unsigned char buffer[4] = { 0,0x02,0,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); std::string last_cmd = test_get_last_command(); Assert::AreEqual("/sim/cmd/NAV_BEGIN", last_cmd.c_str()); memset(buffer, 0, sizeof(buffer)); test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); last_cmd = test_get_last_command(); Assert::AreEqual("/sim/cmd/NAV_END", last_cmd.c_str()); } @@ -101,7 +102,7 @@ namespace test unsigned char buffer[4] = { 0,0,0x08,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); int val_after = test_get_dataref_value("sim/custom/switchers/console/absu_pitch_wheel"); Assert::AreEqual(1, (val_after - val_before)); @@ -116,14 +117,14 @@ namespace test unsigned char buffer[4] = { 0,0x01,0,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); std::string last_cmd = test_get_last_command(); Assert::AreNotEqual("/sim/cmd/HDG_ONCE", last_cmd.c_str()); memset(buffer, 0, sizeof(buffer)); test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); last_cmd = test_get_last_command(); Assert::AreEqual("/sim/cmd/HDG_ONCE", last_cmd.c_str()); } @@ -133,7 +134,7 @@ namespace test XPLMDataRef dataref = XPLMFindDataRef("sim/custom/lights/button/absu_stab_h"); // ALT button light set to LIT XPLMSetDatai(dataref, 1); - test_flight_loop(config.class_configs); // evaluate triggers + test_flight_loop(device); // evaluate triggers std::this_thread::sleep_for(150ms); unsigned char write_buffer[13]; test_hid_get_write_data(write_buffer, sizeof(write_buffer)); @@ -141,7 +142,7 @@ namespace test // ALT button light set to UNLIT XPLMSetDatai(dataref, 0); - test_flight_loop(config.class_configs); // evaluate triggers + test_flight_loop(device); // evaluate triggers std::this_thread::sleep_for(150ms); test_hid_get_write_data(write_buffer, sizeof(write_buffer)); Assert::AreEqual(0x00, (int)write_buffer[11] & 0x10); @@ -152,7 +153,7 @@ namespace test XPLMDataRef dataref = XPLMFindDataRef("sim/custom/lights/button/absu_zk"); // HDG button light set to LIT XPLMSetDatai(dataref, 1); - test_flight_loop(config.class_configs); // evaluate triggers + test_flight_loop(device); // evaluate triggers std::this_thread::sleep_for(150ms); unsigned char write_buffer[13]; test_hid_get_write_data(write_buffer, sizeof(write_buffer)); @@ -160,7 +161,7 @@ namespace test // HDG button light set to UNLIT XPLMSetDatai(dataref, 0); - test_flight_loop(config.class_configs); // evaluate triggers + test_flight_loop(device); // evaluate triggers std::this_thread::sleep_for(150ms); test_hid_get_write_data(write_buffer, sizeof(write_buffer)); Assert::AreEqual(0x00, (int)write_buffer[11] & 0x02); @@ -169,7 +170,7 @@ namespace test TEST_METHOD(TestApButtonLight) { // in the test this LED has a lua handler ('get_led_status()') which return with a constant 1 value - test_flight_loop(config.class_configs); // evaluate triggers + test_flight_loop(device); // evaluate triggers std::this_thread::sleep_for(150ms); unsigned char write_buffer[13]; test_hid_get_write_data(write_buffer, sizeof(write_buffer)); @@ -191,7 +192,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); std::this_thread::sleep_for(150ms); unsigned char write_buffer[13]; @@ -203,7 +204,7 @@ namespace test Assert::AreEqual(5, (int)write_buffer[5]); XPLMSetDatai(dataref, 0); - test_flight_loop(config.class_configs); + test_flight_loop(device); std::this_thread::sleep_for(150ms); test_hid_get_write_data(write_buffer, sizeof(write_buffer)); @@ -226,25 +227,25 @@ namespace test buffer[0] |= 0x20; // set KNOB_PLUS to 1 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); Assert::AreEqual(1, test_get_dataref_value(dataref_str.c_str())); buffer[0] &= (~0x20); // set KNOB_PLUS to 0 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); Assert::AreEqual(1, test_get_dataref_value(dataref_str.c_str())); buffer[0] |= 0x40; // set KNOB_MINUS to 1 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); Assert::AreEqual(0, test_get_dataref_value(dataref_str.c_str())); buffer[0] &= (~0x40); // set KNOB_MINUS to 0 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(250ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); Assert::AreEqual(0, test_get_dataref_value(dataref_str.c_str())); } @@ -254,7 +255,7 @@ namespace test unsigned char buffer[4] = { 0,0x40,0,0 }; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); double ret_value=0; LuaHelper::get_instace()->do_string("return get_hid_input_status('REV')", ret_value); Assert::AreEqual(1, (int)ret_value); @@ -263,7 +264,7 @@ namespace test buffer[1] = 0; test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); LuaHelper::get_instace()->do_string("return get_hid_input_status('REV')", ret_value); Assert::AreEqual(0, (int)ret_value); } diff --git a/test/test_radio_panel.cpp b/test/test_radio_panel.cpp index fd4ae6c..b93e330 100644 --- a/test/test_radio_panel.cpp +++ b/test/test_radio_panel.cpp @@ -23,7 +23,7 @@ int test_hid_get_vid(); int test_hid_get_pid(); std::string test_get_last_command(); void test_hid_get_write_data(unsigned char* data, size_t length); -void test_flight_loop(std::vector &config); +void test_flight_loop(Device* device); void test_hid_mock_init(); namespace test @@ -86,7 +86,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); std::this_thread::sleep_for(150ms); unsigned char write_buffer[23]; @@ -105,7 +105,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); std::this_thread::sleep_for(150ms); unsigned char write_buffer[23]; @@ -125,7 +125,7 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); std::this_thread::sleep_for(150ms); unsigned char write_buffer[23]; @@ -144,13 +144,13 @@ namespace test test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); std::this_thread::sleep_for(150ms); buffer[2] |= 0x04; // set KNOB_UP_BIG_PLUS to 1 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); Assert::AreEqual(11111 + 100, test_get_dataref_value(nav1_freq_dataref_str.c_str())); // nav1 freq shal be increased by +100 Assert::AreEqual(22222, test_get_dataref_value(nav2_freq_dataref_str.c_str())); // nav2 freq shall not change Assert::AreEqual(33333, test_get_dataref_value(com1_freq_dataref_str.c_str())); // com1 freq shall not change @@ -159,7 +159,7 @@ namespace test buffer[2] &= (~0x04); // set KNOB_UP_BIG_PLUS to 0 test_hid_set_read_data(buffer, sizeof(buffer)); std::this_thread::sleep_for(150ms); - test_flight_loop(config.class_configs); + test_flight_loop(device); Assert::AreEqual(11111 + 100, test_get_dataref_value(nav1_freq_dataref_str.c_str())); } From 99361c3d3409cf1947cebe0f1cf55994471a4ad5 Mon Sep 17 00:00:00 2001 From: Norbert Takacs Date: Sun, 14 Apr 2024 18:29:19 +0200 Subject: [PATCH 15/15] Test: remove fip test case Signed-off-by: Norbert Takacs --- test/test_FIP.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/test/test_FIP.cpp b/test/test_FIP.cpp index 70abfd8..696f025 100644 --- a/test/test_FIP.cpp +++ b/test/test_FIP.cpp @@ -63,23 +63,6 @@ namespace test test_fip_set_button_states(0); Assert::AreEqual(0, (int)fip_device->get_button_state()); } - - TEST_METHOD(TestFIPAirSpeedChange) - { - XPLMSetDatai(airspeed_dataref, 0); - test_flight_loop(fip_device); - std::this_thread::sleep_for(150ms); - unsigned char fip_image_buffer[240 * 320 * 3]; - test_fip_get_image(fip_image_buffer, 240 * 320 * 3); - Assert::AreEqual(0, (int)fip_image_buffer[0]); - - XPLMSetDatai(airspeed_dataref, 150); - test_flight_loop(fip_device); - std::this_thread::sleep_for(150ms); - test_fip_get_image(fip_image_buffer, 240 * 320 * 3); - Assert::AreEqual(0, (int)fip_image_buffer[0]); - } - TEST_METHOD(TestFIPBMPPadding) { /* Page 2 contains one layer with the BMP file bmp_test_padding.bmp