Skip to content

Commit

Permalink
Merge pull request #101 from norberttak/99-bug-multiple-instance-of-h…
Browse files Browse the repository at this point in the history
…id-devices

Add handle of multiple instances of the same devices
  • Loading branch information
norberttak authored Apr 16, 2024
2 parents c266e6e + 99361c3 commit 90f2c61
Show file tree
Hide file tree
Showing 54 changed files with 489 additions and 235 deletions.
22 changes: 22 additions & 0 deletions src/core/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/core/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
108 changes: 54 additions & 54 deletions src/core/ConfigParser.cpp

Large diffs are not rendered by default.

99 changes: 81 additions & 18 deletions src/core/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "Logger.h"
#include "Configuration.h"
#include "fip/FIPScreen.h"

/*------ Plugin level configuration options ------------*/
Configuration& Configuration::operator=(const Configuration& other)
Expand All @@ -17,7 +18,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;
}
Expand All @@ -29,7 +30,7 @@ void Configuration::clear()
version = "";
aircraft_path = "";

device_configs.clear();
class_configs.clear();
}

Configuration::~Configuration()
Expand All @@ -39,35 +40,93 @@ 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::operator=(const DeviceConfiguration& other)
ClassConfiguration::ClassConfiguration(const ClassConfiguration& other):
device_class_type(other.device_class_type),
pid(other.pid),
vid(other.vid),
serial_number(other.serial_number)
{
Logger(TLogLevel::logTRACE) << "DeviceConfiguration = operator called" << std::endl;
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)
{
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;
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;
}

void DeviceConfiguration::clear()
void ClassConfiguration::clear()
{
for (auto &act : push_actions)
act.second.clear();
Expand All @@ -88,10 +147,14 @@ void DeviceConfiguration::clear()
for (auto &act : light_triggers)
act.second.clear();
light_triggers.clear();

for (auto& scr : fip_screens)
delete scr.second;
fip_screens.clear();
}

DeviceConfiguration::~DeviceConfiguration()
ClassConfiguration::~ClassConfiguration()
{
Logger(TLogLevel::logTRACE) << "DeviceConfiguration destructor called" << std::endl;
Logger(TLogLevel::logTRACE) << "ClassConfiguration destructor called" << std::endl;
clear();
}
19 changes: 10 additions & 9 deletions src/core/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class FIPScreen;

class DeviceConfiguration;
class ClassConfiguration;

/*------ Plugin level configuration options ------------*/
class Configuration
Expand All @@ -31,10 +31,10 @@ class Configuration
std::string aircraft_path = "";
std::string plugin_path = "";

std::vector<DeviceConfiguration> device_configs;
std::vector<ClassConfiguration> class_configs;
};

/* ----------- Device specific configuration options ------------------*/
/* ----------- Class specific configuration options ------------------*/
typedef enum {
UNKNOWN_DEVICE_TYPE,
SAITEK_MULTI,
Expand All @@ -44,17 +44,18 @@ typedef enum {
LOGITECH_FIP,
TRC1000_PFD,
TRC1000_AUDIO
} DeviceType;
} DeviceClassType;

class DeviceConfiguration
class ClassConfiguration
{
public:
~DeviceConfiguration();
DeviceConfiguration();
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 = "";
Expand Down
2 changes: 1 addition & 1 deletion src/core/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 6 additions & 2 deletions src/core/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PanelButton> selectors;
std::vector<PanelButton> buttons;
std::vector<PanelDisplay> panel_displays;
Expand All @@ -105,10 +105,14 @@ class Device
virtual void register_rotary_encoders(std::vector<PanelRotaryEncoder>& _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);
ClassConfiguration& get_config()
{
return config;
}
bool updateLightStates();
void process_and_store_button_states();
void process_selector_switch();
Expand Down
14 changes: 14 additions & 0 deletions src/core/GenericDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
//
Expand Down
1 change: 1 addition & 0 deletions src/core/GenericDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/core/GenericScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 13 additions & 12 deletions src/core/GenericScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/core/MultiPurposeDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions src/core/MultiPurposeDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 90f2c61

Please sign in to comment.