mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
(uart, commands) add possibility to set radio channel and volume via uart
This commit is contained in:
@@ -753,7 +753,9 @@ global_settings::ConfigParse(cParser &Parser) {
|
||||
{"main", &uart_conf.mainenable},
|
||||
{"scnd", &uart_conf.scndenable},
|
||||
{"train", &uart_conf.trainenable},
|
||||
{"local", &uart_conf.localenable}
|
||||
{"local", &uart_conf.localenable},
|
||||
{"radiovolume", &uart_conf.radiovolumeenable},
|
||||
{"radiochannel", &uart_conf.radiochannelenable}
|
||||
};
|
||||
|
||||
if(firstToken.find('|') != std::string::npos || features_map.count(firstToken)) {
|
||||
|
||||
45
Train.cpp
45
Train.cpp
@@ -434,6 +434,7 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
|
||||
{ user_command::radiodisable, &TTrain::OnCommand_radiodisable },
|
||||
{ user_command::radiochannelincrease, &TTrain::OnCommand_radiochannelincrease },
|
||||
{ user_command::radiochanneldecrease, &TTrain::OnCommand_radiochanneldecrease },
|
||||
{ user_command::radiochannelset, &TTrain::OnCommand_radiochannelset },
|
||||
{ user_command::radiostopsend, &TTrain::OnCommand_radiostopsend },
|
||||
{ user_command::radiostopenable, &TTrain::OnCommand_radiostopenable },
|
||||
{ user_command::radiostopdisable, &TTrain::OnCommand_radiostopdisable },
|
||||
@@ -441,6 +442,7 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
|
||||
{ user_command::radiocall3send, &TTrain::OnCommand_radiocall3send },
|
||||
{ user_command::radiovolumeincrease, &TTrain::OnCommand_radiovolumeincrease },
|
||||
{ user_command::radiovolumedecrease, &TTrain::OnCommand_radiovolumedecrease },
|
||||
{ user_command::radiovolumeset, &TTrain::OnCommand_radiovolumeset },
|
||||
{ user_command::cabchangeforward, &TTrain::OnCommand_cabchangeforward },
|
||||
{ user_command::cabchangebackward, &TTrain::OnCommand_cabchangebackward },
|
||||
{ user_command::generictoggle0, &TTrain::OnCommand_generictoggle },
|
||||
@@ -6485,9 +6487,10 @@ void TTrain::OnCommand_radiodisable( TTrain *Train, command_data const &Command
|
||||
void TTrain::OnCommand_radiochannelincrease( TTrain *Train, command_data const &Command ) {
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
Train->RadioChannel() = clamp( Train->RadioChannel() + 1, 1, 10 );
|
||||
// visual feedback
|
||||
Train->ggRadioChannelSelector.UpdateValue( Train->RadioChannel() - 1 );
|
||||
command_data newCommand = Command;
|
||||
newCommand.param1 = Train->RadioChannel() + 1;
|
||||
OnCommand_radiochannelset(Train, newCommand);
|
||||
|
||||
Train->ggRadioChannelNext.UpdateValue( 1.0 );
|
||||
}
|
||||
else if( Command.action == GLFW_RELEASE ) {
|
||||
@@ -6499,9 +6502,10 @@ void TTrain::OnCommand_radiochannelincrease( TTrain *Train, command_data const &
|
||||
void TTrain::OnCommand_radiochanneldecrease( TTrain *Train, command_data const &Command ) {
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
Train->RadioChannel() = clamp( Train->RadioChannel() - 1, 1, 10 );
|
||||
// visual feedback
|
||||
Train->ggRadioChannelSelector.UpdateValue( Train->RadioChannel() - 1 );
|
||||
command_data newCommand = Command;
|
||||
newCommand.param1 = Train->RadioChannel() - 1;
|
||||
OnCommand_radiochannelset(Train, newCommand);
|
||||
|
||||
Train->ggRadioChannelPrevious.UpdateValue( 1.0 );
|
||||
}
|
||||
else if( Command.action == GLFW_RELEASE ) {
|
||||
@@ -6510,6 +6514,15 @@ void TTrain::OnCommand_radiochanneldecrease( TTrain *Train, command_data const &
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_radiochannelset(TTrain *Train, command_data const &Command) {
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
// on press or hold
|
||||
Train->RadioChannel() = clamp((int) Command.param1, 1, 10);
|
||||
Train->ggRadioChannelSelector.UpdateValue( Train->RadioChannel() - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TTrain::OnCommand_radiostopsend( TTrain *Train, command_data const &Command ) {
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
@@ -6581,9 +6594,9 @@ void TTrain::OnCommand_radiocall3send( TTrain *Train, command_data const &Comman
|
||||
void TTrain::OnCommand_radiovolumeincrease(TTrain *Train, command_data const &Command) {
|
||||
|
||||
if (Command.action == GLFW_PRESS) {
|
||||
Global.RadioVolume = clamp(Global.RadioVolume + 0.125, 0.0, 1.0);
|
||||
// visual feedback
|
||||
Train->ggRadioVolumeSelector.UpdateValue(Global.RadioVolume);
|
||||
command_data newCommand = Command;
|
||||
newCommand.param1 = Global.RadioVolume + 0.125;
|
||||
OnCommand_radiovolumeset(Train, newCommand);
|
||||
Train->ggRadioVolumeNext.UpdateValue(1.0);
|
||||
}
|
||||
else if (Command.action == GLFW_RELEASE) {
|
||||
@@ -6595,9 +6608,9 @@ void TTrain::OnCommand_radiovolumeincrease(TTrain *Train, command_data const &Co
|
||||
void TTrain::OnCommand_radiovolumedecrease(TTrain *Train, command_data const &Command) {
|
||||
|
||||
if (Command.action == GLFW_PRESS) {
|
||||
Global.RadioVolume = clamp(Global.RadioVolume - 0.125, 0.0, 1.0);
|
||||
// visual feedback
|
||||
Train->ggRadioVolumeSelector.UpdateValue(Global.RadioVolume);
|
||||
command_data newCommand = Command;
|
||||
newCommand.param1 = Global.RadioVolume - 0.125;
|
||||
OnCommand_radiovolumeset(Train, newCommand);
|
||||
Train->ggRadioVolumePrevious.UpdateValue(1.0);
|
||||
}
|
||||
else if (Command.action == GLFW_RELEASE) {
|
||||
@@ -6606,6 +6619,14 @@ void TTrain::OnCommand_radiovolumedecrease(TTrain *Train, command_data const &Co
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_radiovolumeset(TTrain *Train, command_data const &Command) {
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
// on press or hold
|
||||
Global.RadioVolume = clamp(Command.param1, 0.0, 1.0);
|
||||
Train->ggRadioVolumeSelector.UpdateValue(Global.RadioVolume);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TTrain::OnCommand_cabchangeforward( TTrain *Train, command_data const &Command ) {
|
||||
|
||||
|
||||
2
Train.h
2
Train.h
@@ -456,6 +456,7 @@ class TTrain {
|
||||
static void OnCommand_radiodisable( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_radiochannelincrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_radiochanneldecrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_radiochannelset( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_radiostopsend( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_radiostopenable( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_radiostopdisable( TTrain *Train, command_data const &Command );
|
||||
@@ -463,6 +464,7 @@ class TTrain {
|
||||
static void OnCommand_radiocall3send( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_radiovolumeincrease(TTrain *Train, command_data const &Command);
|
||||
static void OnCommand_radiovolumedecrease(TTrain *Train, command_data const &Command);
|
||||
static void OnCommand_radiovolumeset(TTrain *Train, command_data const &Command);
|
||||
static void OnCommand_cabchangeforward( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_cabchangebackward( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_generictoggle( TTrain *Train, command_data const &Command );
|
||||
|
||||
@@ -140,6 +140,7 @@ commanddescription_sequence Commands_descriptions = {
|
||||
{ "radiodisable", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiochannelincrease", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiochanneldecrease", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiochannelset", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiostopsend", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiostopenable", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiostopdisable", command_target::vehicle, command_mode::oneoff },
|
||||
@@ -147,6 +148,7 @@ commanddescription_sequence Commands_descriptions = {
|
||||
{ "radiocall3send", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiovolumeincrease", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiovolumedecrease", command_target::vehicle, command_mode::oneoff },
|
||||
{ "radiovolumeset", command_target::vehicle, command_mode::oneoff },
|
||||
{ "cabchangeforward", command_target::vehicle, command_mode::oneoff },
|
||||
{ "cabchangebackward", command_target::vehicle, command_mode::oneoff },
|
||||
{ "viewturn", command_target::entity, command_mode::oneoff },
|
||||
|
||||
@@ -133,6 +133,7 @@ enum class user_command {
|
||||
radiodisable,
|
||||
radiochannelincrease,
|
||||
radiochanneldecrease,
|
||||
radiochannelset,
|
||||
radiostopsend,
|
||||
radiostopenable,
|
||||
radiostopdisable,
|
||||
@@ -140,6 +141,7 @@ enum class user_command {
|
||||
radiocall3send,
|
||||
radiovolumeincrease,
|
||||
radiovolumedecrease,
|
||||
radiovolumeset,
|
||||
cabchangeforward,
|
||||
cabchangebackward,
|
||||
|
||||
|
||||
@@ -141,6 +141,7 @@ driverkeyboard_input::default_bindings() {
|
||||
// radiodisable
|
||||
{ user_command::radiochannelincrease, GLFW_KEY_EQUAL },
|
||||
{ user_command::radiochanneldecrease, GLFW_KEY_MINUS },
|
||||
// radiochannelset
|
||||
{ user_command::radiostopsend, GLFW_KEY_PAUSE | keymodifier::shift | keymodifier::control },
|
||||
// radiostopenable
|
||||
// radiostopdisable
|
||||
@@ -148,6 +149,7 @@ driverkeyboard_input::default_bindings() {
|
||||
{ user_command::radiocall3send, GLFW_KEY_BACKSPACE },
|
||||
// radiovolumeincrease,
|
||||
// radiovolumedecrease,
|
||||
// radiovolumeset,
|
||||
{ user_command::cabchangeforward, GLFW_KEY_HOME },
|
||||
{ user_command::cabchangebackward, GLFW_KEY_END },
|
||||
// viewturn,
|
||||
|
||||
19
uart.cpp
19
uart.cpp
@@ -485,6 +485,25 @@ void uart_input::poll()
|
||||
// TODO: pass correct entity id once the missing systems are in place
|
||||
0 );
|
||||
}
|
||||
if( true == conf.radiochannelenable ) {
|
||||
relay.post(
|
||||
user_command::radiochannelset,
|
||||
static_cast<int8_t>(buffer[12] & 0xF),
|
||||
0,
|
||||
GLFW_PRESS,
|
||||
0
|
||||
);
|
||||
}
|
||||
if( true == conf.radiovolumeenable ) {
|
||||
int8_t requested_volume = static_cast<int8_t>((buffer[12] & 0xF0) >> 4);
|
||||
relay.post(
|
||||
user_command::radiovolumeset,
|
||||
requested_volume == 0xF ? 1.0 : requested_volume * (1.0 / 15.0),
|
||||
0,
|
||||
GLFW_PRESS,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
old_packet = buffer;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user