18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 22:55:16 +01:00
Files
maszyna/input/drivermouseinput.cpp
jerrrrycho 919b4af043 feat(physics): dual-mode vehicles, stage 1: a genset as a second source of the traction circuit (GE#536) (#471)
* test(scenarios): AI through a section without voltage and with interlocked line contactors

Scenario cases for the parts of #272 (line breaker ahead of the
pantographs, PantRequiresMain) and #276 (line contactors interlocked with
the vehicle's own converter, LineContactorsInterlock) that had not been
run in the simulator before. They all run the AI on the timetable run of
td.scn.

- ep05_td_dead_section: an EP05 runs under power into a 61 m span of
  overhead wire that has no voltage. Its line breaker stays closed, the
  traction force drops to 0, and behind the span the AI takes power
  again and stops at Przystanek. eu07_td_dead_section is the same run
  with an EU07, as a reference for the old behaviour: its line breaker
  opens after 0.2 s and the AI closes it again.
- ep05_td_neutral_section: the same span, with the track under it marked
  overhead 0. The AI coasts from before the dead wire.
- ep05_td_section_insulator: a 1 m section insulator, run under power.
  The 0.2 s voltage hold keeps the traction force up past it.
- et42_td_converter_interlock(_cold): an ET42 with the interlock starts
  up and runs its timetable.
- ep05_td_interlock_dead_section_cold: both keys on one EP05, starting
  cold, with the dead span on its way.
- ep05_td_timetable: the plain timetable run of the EP05, as a reference.

The runner gets vehicle_variants, a vehicle of the case's own made from
one of the game's with .fiz replacements. The game's ET42 data doesn't
have the interlock key yet. The runner also gets two new checks:
traction (the traction force between two distances travelled) and
master_controller.

The local converter switch of #276 can't be covered: only the cab can
set it, and in test mode nobody sits in a cab.

* feat(physics): the genset of a dual-mode vehicle, a second source of the traction circuit (GE#536)

A vehicle with induction motors and pantographs can have a diesel
generator set as well (Power: GensetPower and the other Genset* keys,
Cntrl. GensetStart). The traction selector picks the source of the
traction circuit: the catenary through the pantographs, as before, or the
genset. It moves only with the line breaker open.

- the genset starts on request with the battery on, cranks for
  GensetStartTime, then runs at idle and up to full revolutions with the
  traction demand; stopped, it coasts down. It gives its regulated voltage
  from the idle revolutions up.
- on the genset the line breaker closes only on a running genset, the
  undervoltage trip works at half its voltage, the traction power is capped
  at the genset's power at its present revolutions times GensetPmaxRatio,
  braking sends nothing back, and the pantographs' pressure switch is left
  out. The genset's voltage goes to the train's high voltage line as the
  pantographs' does.
- the commands TractionMode and GensetSwitch pass along the train and can
  come from a scenery's PutValues.

Nothing changes without GensetPower: the selector stays on the catenary
and every new branch is unreachable. The keys are ignored, with a line in
the log, on a vehicle which isn't an induction motor one fed by
pantographs.

* feat(cab): the traction selector and the genset switch of a dual-mode vehicle (GE#536)

New commands tractionmodetoggle, tractionmodecatenary, tractionmodegenset
(shift+G toggles) and gensettoggle, gensetenable, gensetdisable (ctrl+G
toggles), and the two-state cab switches tractionmode_sw: and genset_sw:.
The selector switch doesn't move while the line breaker is closed. Both
act on the whole train, as the fuel pump switch does. A cab without the
switches works as before.

* test: the genset of a dual-mode vehicle (GE#536)

The game's E6ACT with the genset of the E6ACTad "last mile" set in the
test (520 kW, the rest assumed): the keys and their defaults, the
selector's interlock with the line breaker, the start, the power cap at
the wheels, the revolutions following the demand, the stop opening the
line breaker, the automatic start, the battery, the pantographs' pressure
switch, braking with nothing sent back, the genset feeding the next car
through the high voltage coupling, the commands along the train and from
a scenery. A run from the catenary is the same, step for step, with the
genset keys as without them.

* test(scenarios): traction_power check, and an E6ACTad timetable run on its genset (GE#536)

traction_power checks the power at the wheels, the traction force times
the vehicle speed, against a ceiling and optionally a peak to reach.

e6actad_genset_td_timetable runs the td/rozklad timetable with an E6ACTad
switched to its genset by the scenery (PutValues from event0 of its
track); e6actad_catenary_td_timetable is the same vehicle left on the
catenary. Both need a temporary vehicle variant in the game's data, which
the README describes; it isn't in the SVN.

* test(scenarios): the genset cases make their own E6ACTad variant

The two E6ACTad cases needed a vehicle variant placed in the game's
dynamic/ by hand. They now make it for the run with vehicle_variants.

vehicle_variants takes an optional fiz_from: a file to copy instead of the
vehicle's own .fiz, named in full, while the .mmd still comes from "from".
e6actad.fiz only includes e6acta.fiz.inc, and the genset keys can't go on a
second Power: line after the include, which would load the power source
again; so the variant is e6acta.fiz.inc with the keys added to its Cntrl.
and Power: lines. Cases without fiz_from work as before.

* fix(physics): the genset's traction current isn't taken from the wire (GE#536)

On the genset the pantographs still handed the traction current to the
wire and the energy meter, so a dual-mode vehicle under a wire loaded the
substation while its genset did the work. The current now comes from
CatenaryCurrent(): on the catenary the expression DynObj had, on the
genset only a heating fed straight from the pantographs.

A selector command refused with the line breaker closed is no longer
passed down the train, and a car whose genset starts on its own passes
the start switch on to the cars behind. The cab's genset switch moves
only when the request was taken, so it no longer sticks on an
automatic-start car.
2026-11-26 22:29:09 +01:00

1252 lines
40 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "input/drivermouseinput.h"
#include "utilities/Globals.h"
#include "application/application.h"
#include "utilities/Globals.h"
#include "utilities/Timer.h"
#include "simulation/simulation.h"
#include "vehicle/Train.h"
#include "model/AnimModel.h"
#include "rendering/renderer.h"
#include "application/uilayer.h"
#include "utilities/Logs.h"
#include "utilities/utilities.h"
auto const EU07_CONTROLLER_MOUSESLIDERSIZE{ 0.6 };
void
mouse_slider::bind( user_command const &Command ) {
m_command = Command;
m_universal.reset();
m_universaldrag.reset();
auto const *train { simulation::Train };
TMoverParameters const *vehicle { nullptr };
switch( m_command ) {
using enum user_command;
case jointcontrollerset:
case mastercontrollerset:
case secondcontrollerset: {
vehicle = train ? train->Controlled() : nullptr;
break;
}
case trainbrakeset:
case independentbrakeset: {
vehicle = train ? train->Occupied() : nullptr;
break;
}
default: {
break;
}
}
if( vehicle == nullptr ) { return; }
// calculate initial value and accepted range
switch( m_command ) {
case user_command::jointcontrollerset: {
// NOTE: special case, merges two separate controls
auto const *occupied { train ? train->Occupied() : nullptr };
if( occupied == nullptr ) { return; }
auto const powerrange { static_cast<double>(
vehicle->CoupledCtrl ?
vehicle->MainCtrlPosNo + vehicle->ScndCtrlPosNo :
vehicle->MainCtrlPosNo ) };
// for simplicity upper half of the range controls power, lower controls brakes
m_valuerange = 1.0;
m_value =
0.5
+ 0.5 * ( vehicle->CoupledCtrl ?
vehicle->MainCtrlPos + vehicle->ScndCtrlPos :
vehicle->MainCtrlPos ) / powerrange
- 0.5 * occupied->LocalBrakePosA;
m_analogue = true;
m_invertrange = false;
break;
}
case user_command::mastercontrollerset: {
m_valuerange = vehicle->CoupledCtrl ? vehicle->MainCtrlPosNo + vehicle->ScndCtrlPosNo : vehicle->MainCtrlPosNo;
m_value = vehicle->CoupledCtrl ? vehicle->MainCtrlPos + vehicle->ScndCtrlPos : vehicle->MainCtrlPos;
m_analogue = false;
m_invertrange = false;
break;
}
case user_command::secondcontrollerset: {
m_valuerange = vehicle->ScndCtrlPosNo;
m_value = vehicle->ScndCtrlPos;
m_analogue = false;
m_invertrange = true;
break;
}
case user_command::trainbrakeset: {
m_valuerange = 1.0;
m_value = ( vehicle->fBrakeCtrlPos - vehicle->Handle->GetPos( bh_MIN ) ) / ( vehicle->Handle->GetPos( bh_MAX ) - vehicle->Handle->GetPos( bh_MIN ) );
m_analogue = true;
m_invertrange = true;
break;
}
case user_command::independentbrakeset: {
m_valuerange = 1.0;
m_value = vehicle->LocalBrakePosA;
m_analogue = true;
m_invertrange = true;
break;
}
default: {
m_valuerange = 1;
break;
}
}
// hide the cursor and place it in accordance with current slider value
m_cursorposition = glm::dvec2(Global.cursor_pos);
Application.set_cursor( GLFW_CURSOR_DISABLED );
auto const controlsize { Global.window_size.y * EU07_CONTROLLER_MOUSESLIDERSIZE };
auto const controledge { Global.window_size.y * 0.5 + controlsize * 0.5 };
auto const stepsize { controlsize / m_valuerange };
if( m_invertrange ) {
m_value = ( m_analogue ? 1.0 : m_valuerange ) - m_value;
}
Application.set_cursor_pos(
Global.window_size.y,
m_analogue ? controledge - m_value * controlsize : controledge - m_value * stepsize - 0.5 * stepsize );
}
void
mouse_slider::bind_universal( int const Index, universal_drag::direction const Drag, float const Position ) {
m_command = static_cast<user_command>( static_cast<int>( user_command::genericset0 ) + Index );
m_universal = Index;
m_universaldrag.emplace( Drag, Position );
m_value = m_universaldrag->position();
m_valuerange = 1.0;
m_analogue = true;
m_invertrange = false;
// the cursor is hidden for the drag and put back where it was when the drag ends; the drag follows its moves
// from wherever it is, so it isn't placed anywhere
m_cursorposition = glm::dvec2( Global.cursor_pos );
Application.set_cursor( GLFW_CURSOR_DISABLED );
}
void
mouse_slider::release() {
m_command = user_command::none;
m_universal.reset();
m_universaldrag.reset();
Application.set_cursor_pos( m_cursorposition.x, m_cursorposition.y );
Application.set_cursor( GLFW_CURSOR_NORMAL );
}
bool
mouse_slider::on_move( double const Mousex, double const Mousey ) {
auto const controlsize { Global.window_size.y * EU07_CONTROLLER_MOUSESLIDERSIZE };
if( m_universaldrag ) {
// a universal control, dragged the same way as the controllers: the move of the cursor over the size of the
// slider takes it from one end to the other
if( false == m_universaldrag->move( Mousex, Mousey, controlsize ) ) {
return false;
}
m_value = m_universaldrag->position();
return true;
}
auto const controledge { Global.window_size.y * 0.5 + controlsize * 0.5 };
auto const stepsize { controlsize / m_valuerange };
auto mousey = std::clamp( Mousey, controledge - controlsize, controledge );
m_value = m_analogue ? (controledge - mousey) / controlsize : std::floor((controledge - mousey) / stepsize);
if( m_invertrange ) {
m_value = ( m_analogue ? 1.0 : m_valuerange ) - m_value; }
return true;
}
bool
drivermouse_input::init() {
#ifdef _WIN32
DWORD systemkeyboardspeed;
::SystemParametersInfo( SPI_GETKEYBOARDSPEED, 0, &systemkeyboardspeed, 0 );
m_updaterate = std::lerp( 0.5, 0.04, systemkeyboardspeed / 31.0 );
DWORD systemkeyboarddelay;
::SystemParametersInfo( SPI_GETKEYBOARDDELAY, 0, &systemkeyboarddelay, 0 );
m_updatedelay = std::lerp( 0.25, 1.0, systemkeyboarddelay / 3.0 );
#endif
default_bindings();
recall_bindings();
return true;
}
namespace fs = std::filesystem;
bool
drivermouse_input::recall_bindings() {
std::string filePath = "eu07_input-mouse.ini";
if (fs::path appPath = user_config_path("eu07_input-mouse.ini"); !appPath.empty() && fs::exists(appPath))
filePath = appPath.string();
cParser bindingparser(filePath, cParser::buffer_FILE);
if (false == bindingparser.ok()) {
return false;
}
// build helper translation tables
std::unordered_map<std::string, user_command> nametocommandmap;
std::size_t commandid = 0;
for( auto const &description : simulation::Commands_descriptions ) {
nametocommandmap.try_emplace(
description.name,
static_cast<user_command>( commandid ) );
++commandid;
}
// NOTE: to simplify things we expect one entry per line, and whole entry in one line
while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
std::string bindingentry;
bindingparser >> bindingentry;
cParser entryparser( bindingentry );
if( true == entryparser.getTokens( 1, true, "\n\r\t " ) ) {
std::string bindingpoint {};
entryparser >> bindingpoint;
std::vector< std::reference_wrapper<user_command> > bindingtargets;
if( bindingpoint == "wheel" ) {
bindingtargets.emplace_back( std::ref( m_wheelbindings.up ) );
bindingtargets.emplace_back( std::ref( m_wheelbindings.down ) );
}
// TODO: binding targets for mouse buttons
for( auto const &bindingtarget : bindingtargets ) {
// grab command(s) associated with the input pin
auto const bindingcommandname{ entryparser.getToken<std::string>() };
if( true == bindingcommandname.empty() ) {
// no tokens left, may as well complain then call it a day
WriteLog( "Mouse binding for " + bindingpoint + " didn't specify associated command(s)" );
break;
}
auto const commandlookup = nametocommandmap.find( bindingcommandname );
if( commandlookup == nametocommandmap.end() ) {
WriteLog( "Mouse binding for " + bindingpoint + " specified unknown command, \"" + bindingcommandname + "\"" );
}
else {
bindingtarget.get() = commandlookup->second;
}
}
}
}
return true;
}
void
drivermouse_input::move( double Mousex, double Mousey ) {
if( false == Global.ControlPicking ) {
// default control mode
m_relay.post(
user_command::viewturn,
Mousex,
Mousey,
GLFW_PRESS,
0 );
}
else {
// control picking mode
if( m_slider.command() != user_command::none
&& true == m_slider.on_move( Mousex, Mousey ) ) {
m_relay.post(
m_slider.command(),
m_slider.value(),
0,
GLFW_PRESS,
0 );
}
if( false == m_pickmodepanning ) {
// even if the view panning isn't active we capture the cursor position in case it does get activated
m_cursorposition.x = Mousex;
m_cursorposition.y = Mousey;
return;
}
glm::dvec2 cursorposition { Mousex, Mousey };
auto const viewoffset = cursorposition - m_cursorposition;
m_relay.post(
user_command::viewturn,
viewoffset.x,
viewoffset.y,
GLFW_PRESS,
0 );
m_cursorposition = cursorposition;
}
}
void
drivermouse_input::scroll( double const /*Xoffset*/, double const Yoffset ) {
if( Global.ctrlState ) {
// ctrl + scroll wheel adjusts fov
Global.FieldOfView = std::clamp( static_cast<float>( Global.FieldOfView - Yoffset * 20.0 / Timer::subsystem.mainloop_total.average() ), 15.0f, 75.0f );
}
else {
// scroll adjusts master controller
// TODO: allow configurable scroll commands
auto command {
adjust_command(
Yoffset > 0.0 ?
m_wheelbindings.up :
m_wheelbindings.down ) };
m_relay.post(
command,
0,
0,
GLFW_PRESS,
// TODO: pass correct entity id once the missing systems are in place
0 );
}
}
void
drivermouse_input::button( int const Button, int const Action ) {
// store key state
if( Button >= 0 ) {
m_buttons[ Button ] = Action;
}
if( false == Global.ControlPicking ) { return; }
if( true == FreeFlyModeFlag ) {
// freefly mode
// left mouse button launches on_click event associated with to the node
if (Button == GLFW_MOUSE_BUTTON_LEFT && Action == GLFW_PRESS) {
GfxRenderer->Pick_Node_Callback(
[](scene::basic_node const *node) {
if( node == nullptr
|| typeid(*node) != typeid(TAnimModel) )
return;
simulation::Region->on_click( static_cast<TAnimModel const *>( node ) ); } );
}
// right button controls panning
if( Button == GLFW_MOUSE_BUTTON_RIGHT ) {
m_pickmodepanning = Action == GLFW_PRESS;
}
}
else {
// cab controls mode
user_command &mousecommand = Button == GLFW_MOUSE_BUTTON_LEFT ? m_mousecommandleft : m_mousecommandright;
if( Action == GLFW_RELEASE ) {
if( mousecommand != user_command::none ) {
// NOTE: basic keyboard controls don't have any parameters
// as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
// TODO: pass correct entity id once the missing systems are in place
m_relay.post( mousecommand, 0, 0, Action, 0 );
mousecommand = user_command::none;
}
else {
m_pickwaiting = false;
if (Button == GLFW_MOUSE_BUTTON_LEFT && m_slider.command() != user_command::none) {
if( auto const universal { m_slider.universal() };
universal && m_slider.is_click() ) {
// a universal control clicked rather than dragged goes to its end, as a click on any universal does
toggle_universal( *universal );
}
else {
m_relay.post( m_slider.command(), 0, 0, Action, 0 );
}
m_slider.release();
}
// if it's the right mouse button that got released and we had no command active, we were potentially in view panning mode; stop it
if( Button == GLFW_MOUSE_BUTTON_RIGHT ) {
m_pickmodepanning = false;
}
}
// if we were in varying command repeat rate, we can stop that now. done without any conditions, to catch some unforeseen edge cases
m_varyingpollrate = false;
}
else {
// if not release then it's press
m_pickwaiting = true;
GfxRenderer->Pick_Control_Callback(
[this, Button, Action, &mousecommand](TSubModel const *controlsubmodel, const glm::vec2 pos) {
using enum user_command;
bool pickwaiting = m_pickwaiting;
m_pickwaiting = false;
// click on python screen
if (Button == GLFW_MOUSE_BUTTON_LEFT
&& controlsubmodel && controlsubmodel->screen_touch_list) {
controlsubmodel->screen_touch_list->emplace_back(pos);
}
auto const [leftbinding, rightbinding]{ bindings( simulation::Train->GetLabel( controlsubmodel ) ) };
// if the recognized element under the cursor has a command associated with the pressed button, notify the recipient
mousecommand = Button == GLFW_MOUSE_BUTTON_LEFT ? leftbinding : rightbinding;
if( mousecommand == none ) {
// if we don't have any recognized element under the cursor and the right button was pressed, enter view panning mode
if( Button == GLFW_MOUSE_BUTTON_RIGHT ) {
m_pickmodepanning = true;
}
return;
}
// check manually for commands which have 'fast' variants launched with shift modifier
if( Global.shiftState ) {
switch( mousecommand ) {
case mastercontrollerincrease: { mousecommand = mastercontrollerincreasefast; break; }
case mastercontrollerdecrease: { mousecommand = mastercontrollerdecreasefast; break; }
case secondcontrollerincrease: { mousecommand = secondcontrollerincreasefast; break; }
case secondcontrollerdecrease: { mousecommand = secondcontrollerdecreasefast; break; }
case independentbrakeincrease: { mousecommand = independentbrakeincreasefast; break; }
case independentbrakedecrease: { mousecommand = independentbrakedecreasefast; break; }
default: { break; }
}
}
// a universal control with drag: in its definition is dragged to any position between its ends,
// and a click without dragging toggles it as before (MaSzyna-EU07/maszyna#62)
if( Button == GLFW_MOUSE_BUTTON_LEFT ) {
auto const universal { universal_index( mousecommand ) };
auto const drag {
universal ?
simulation::Train->universal_drag_direction( *universal ) :
universal_drag::direction::none };
if( drag != universal_drag::direction::none ) {
mousecommand = none;
if( false == pickwaiting ) {
// the button was let go before the control was found under the cursor: a click
toggle_universal( *universal );
return;
}
m_slider.bind_universal( *universal, drag, simulation::Train->universal_position( *universal ) );
return;
}
}
switch( mousecommand ) {
case mastercontrollerincrease:
case mastercontrollerdecrease:
case secondcontrollerincrease:
case secondcontrollerdecrease:
case trainbrakeincrease:
case trainbrakedecrease:
case independentbrakeincrease:
case independentbrakedecrease: {
// these commands trigger varying repeat rate mode,
// which scales the rate based on the distance of the cursor from its point when the command was first issued
m_varyingpollrateorigin = m_cursorposition;
m_varyingpollrate = true;
break;
}
case jointcontrollerset:
case mastercontrollerset:
case secondcontrollerset:
case trainbrakeset:
case independentbrakeset: {
m_slider.bind( mousecommand );
mousecommand = none;
return;
}
default: {
break;
}
}
// NOTE: basic keyboard controls don't have any parameters
// NOTE: as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
// TODO: pass correct entity id once the missing systems are in place
m_relay.post( mousecommand, 0, 0, Action, 0 );
if (!pickwaiting) // already depressed
m_relay.post( mousecommand, 0, 0, GLFW_RELEASE, 0 );
m_updateaccumulator = -0.25; // prevent potential command repeat right after issuing one
} );
}
}
}
int
drivermouse_input::button( int const Button ) const {
return m_buttons[ Button ];
}
void
drivermouse_input::poll() {
m_updateaccumulator += Timer::GetDeltaRenderTime();
auto updaterate { m_updaterate };
if( m_varyingpollrate ) {
updaterate /= std::max( 0.15, 2.0 * glm::length( m_cursorposition - m_varyingpollrateorigin ) / std::max( 1, Global.window_size.y ) );
}
while( m_updateaccumulator > updaterate ) {
if( m_mousecommandleft != user_command::none ) {
// NOTE: basic keyboard controls don't have any parameters
// as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
// TODO: pass correct entity id once the missing systems are in place
m_relay.post( m_mousecommandleft, 0, 0, GLFW_REPEAT, 0 );
}
if( m_mousecommandright != user_command::none ) {
// NOTE: basic keyboard controls don't have any parameters
// as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
// TODO: pass correct entity id once the missing systems are in place
m_relay.post( m_mousecommandright, 0, 0, GLFW_REPEAT, 0 );
}
m_updateaccumulator -= updaterate;
}
}
user_command
drivermouse_input::command() const {
return m_slider.command() != user_command::none ? m_slider.command() : m_mousecommandleft != user_command::none ? m_mousecommandleft : m_mousecommandright;
}
// returns pair of bindings associated with specified cab control
std::pair<user_command, user_command>
drivermouse_input::bindings( std::string const &Control ) const {
auto const lookup{ m_buttonbindings.find( Control ) };
if( lookup != m_buttonbindings.end() )
return { lookup->second.left, lookup->second.right };
else {
return { user_command::none, user_command::none };
}
}
void
drivermouse_input::default_bindings() {
using enum user_command;
// pierwsza komenda jest od zwiekszania a druga od zmniejszania - ewentualnie kolejno lewy i prawy przycisk
m_buttonbindings = {
{ "jointctrl:", {
jointcontrollerset,
none } },
{ "mainctrl:", {
mastercontrollerset,
none } },
{ "dynamicbrakectrl:", {
dynamicbrakecontrollerset,
none } },
{ "scndctrl:", {
secondcontrollerset,
none } },
{ "shuntmodepower:", {
secondcontrollerincrease,
secondcontrollerdecrease } },
{ "tempomat_sw:", {
tempomattoggle,
none } },
{ "tempomatoff_sw:", {
tempomattoggle,
none } },
{ "dirkey:", {
reverserincrease,
reverserdecrease } },
{ "dirforward_bt:", {
reverserforward,
none } },
{ "dirneutral_bt:", {
reverserneutral,
none } },
{ "dirbackward_bt:", {
reverserbackward,
none } },
{ "brakectrl:", {
trainbrakeset,
none } },
{ "localbrake:", {
independentbrakeset,
none } },
{ "manualbrake:", {
manualbrakeincrease,
manualbrakedecrease } },
{ "alarmchain:", {
alarmchaintoggle,
none } },
{ "alarmchainon:", {
alarmchainenable,
none} },
{ "alarmchainoff:", {
alarmchainenable,
none} },
{ "brakeprofile_sw:", {
brakeactingspeedincrease,
brakeactingspeeddecrease } },
// TODO: dedicated methods for braking speed switches
{ "brakeprofileg_sw:", {
brakeactingspeedsetcargo,
brakeactingspeedsetpassenger } },
{ "brakeprofiler_sw:", {
brakeactingspeedsetrapid,
brakeactingspeedsetpassenger } },
{ "brakeopmode_sw:", {
trainbrakeoperationmodeincrease,
trainbrakeoperationmodedecrease } },
{ "maxcurrent_sw:", {
motoroverloadrelaythresholdtoggle,
none } },
{ "autorelay_sw:", {
notchingrelaytoggle,
none } },
{ "waterpumpbreaker_sw:", {
waterpumpbreakertoggle,
none } },
{ "waterpump_sw:", {
waterpumptoggle,
none } },
{ "waterheaterbreaker_sw:", {
waterheaterbreakertoggle,
none } },
{ "waterheater_sw:", {
waterheatertoggle,
none } },
{ "fuelpump_sw:", {
fuelpumptoggle,
none } },
{ "oilpump_sw:", {
oilpumptoggle,
none } },
{ "oilfuelpump_sw:", {
oilfuelpumptoggle,
none } },
{ "tractionmode_sw:", {
tractionmodetoggle,
none } },
{ "genset_sw:", {
gensettoggle,
none } },
{ "motorblowersfront_sw:", {
motorblowerstogglefront,
none } },
{ "motorblowersrear_sw:", {
motorblowerstogglerear,
none } },
{ "motorblowersalloff_sw:", {
motorblowersdisableall,
none } },
{ "coolingfans_sw:", {
coolingfanstoggle,
none } },
{ "main_off_bt:", {
linebreakeropen,
none } },
{ "main_on_bt:",{
linebreakerclose,
none } },
{ "mainb_off_bt:", {
linebreakeropenb,
none } },
{ "mainb_on_bt:", {
linebreakercloseb,
none } },
{ "mainc_off_bt:", {
linebreakeropenc,
none } },
{ "mainc_on_bt:", {
linebreakerclosec,
none } },
{ "security_reset_bt:", {
alerteracknowledge,
none } },
{ "shp_reset_bt:", {
cabsignalacknowledge,
none } },
{ "releaser_bt:", {
independentbrakebailoff,
none } },
{ "springbraketoggle_bt:",{
springbraketoggle,
none } },
{ "springbrakeon_bt:",{
springbrakeenable,
none } },
{ "springbrakeoff_bt:",{
springbrakedisable,
none } },
{ "universalbrake1_bt:",{
universalbrakebutton1,
none } },
{ "universalbrake2_bt:",{
universalbrakebutton2,
none } },
{ "universalbrake3_bt:",{
universalbrakebutton3,
none } },
{ "epbrake_bt:",{
epbrakecontroltoggle,
none } },
{ "epbrakeon_bt:",{
epbrakecontrolenable,
none } },
{ "epbrakeoff_bt:",{
epbrakecontroldisable,
none } },
{ "sand_bt:", {
sandboxactivate,
none } },
{ "antislip_bt:", {
wheelspinbrakeactivate,
none } },
{ "horn_bt:", {
hornhighactivate,
hornlowactivate } },
{ "hornlow_bt:", {
hornlowactivate,
none } },
{ "hornhigh_bt:", {
hornhighactivate,
none } },
{ "whistle_bt:", {
whistleactivate,
none } },
{ "fuse_bt:", {
motoroverloadrelayreset,
none } },
{ "converterfuse_bt:", {
converteroverloadrelayreset,
none } },
{ "relayreset1_bt:", {
universalrelayreset1,
none } },
{ "relayreset2_bt:", {
universalrelayreset2,
none } },
{ "relayreset3_bt:", {
universalrelayreset3,
none } },
{ "stlinoff_bt:", {
motorconnectorsopen,
none } },
{ "doorleftpermit_sw:", {
doorpermitleft,
none } },
{ "doorrightpermit_sw:", {
doorpermitright,
none } },
{ "doorpermitpreset_sw:", {
doorpermitpresetactivatenext,
doorpermitpresetactivateprevious } },
{ "door_left_sw:", {
doortoggleleft,
none } },
{ "door_right_sw:", {
doortoggleright,
none } },
{ "doorlefton_sw:", {
dooropenleft,
none } },
{ "doorrighton_sw:", {
dooropenright,
none } },
{ "doorleftoff_sw:", {
doorcloseleft,
none } },
{ "doorrightoff_sw:", {
doorcloseright,
none } },
{ "doorallon_sw:", {
dooropenall,
none } },
{ "dooralloff_sw:", {
doorcloseall,
none } },
{ "doorstep_sw:", {
doorsteptoggle,
none } },
{ "doormode_sw:", {
doormodetoggle,
none } },
{ "mirrors_sw:", {
mirrorstoggle,
none } },
{ "departure_signal_bt:", {
departureannounce,
none } },
{ "upperlight_sw:", {
headlighttoggleupper,
none } },
{ "leftlight_sw:", {
headlighttoggleleft,
none } },
{ "rightlight_sw:", {
headlighttoggleright,
none } },
{ "dimheadlights_sw:", {
headlightsdimtoggle,
none } },
{"moderndimmer_sw:", {
modernlightdimmerincrease,
modernlightdimmerdecrease } },
{ "leftend_sw:", {
redmarkertoggleleft,
none } },
{ "rightend_sw:", {
redmarkertoggleright,
none } },
{ "lights_sw:", {
lightspresetactivatenext,
lightspresetactivateprevious } },
{ "rearupperlight_sw:", {
headlighttogglerearupper,
none } },
{ "rearleftlight_sw:", {
headlighttogglerearleft,
none } },
{ "rearrightlight_sw:", {
headlighttogglerearright,
none } },
{ "rearleftend_sw:", {
redmarkertogglerearleft,
none } },
{ "rearrightend_sw:", {
redmarkertogglerearright,
none } },
{ "compressor_sw:", {
compressortoggle,
none } },
{ "compressorlocal_sw:", {
compressortogglelocal,
none } },
{ "compressorlist_sw:", {
compressorpresetactivatenext,
compressorpresetactivateprevious } },
{ "converter_sw:", {
convertertoggle,
none } },
{ "converterlocal_sw:", {
convertertogglelocal,
none } },
{ "converteroff_sw:", {
convertertoggle,
none } }, // TODO: dedicated converter shutdown command
{ "main_sw:", {
linebreakertoggle,
none } },
{ "mainb_sw:", {
linebreakertoggleb,
none } },
{ "mainc_sw:", {
linebreakertogglec,
none } },
{ "radio_sw:", {
radiotoggle,
none } },
{ "radioon_sw:", {
radioenable,
none } },
{ "radiooff_sw:", {
radiodisable,
none } },
{ "radiofuse_sw:", {
radiofusetoggle,
none } },
{ "radiofuseon_sw:", {
radiofuseenable,
none } },
{ "radiofuseoff_sw:", {
radiofusedisable,
none } },
{ "radiochannel_sw:", {
radiochannelincrease,
radiochanneldecrease } },
{ "radiochannelprev_sw:", {
radiochanneldecrease,
none } },
{ "radiochannelnext_sw:", {
radiochannelincrease,
none } },
{ "radiostop_sw:", {
radiostopsend,
none } },
{ "radiostopon_sw:", {
radiostopenable,
none } },
{ "radiostopoff_sw:", {
radiostopdisable,
none } },
{ "radiotest_sw:", {
radiostoptest,
none } },
{ "radiocall1_sw:", {
radiocall1send,
none } },
{ "radiocall3_sw:", {
radiocall3send,
none } },
{ "radiovolume_sw:",{
radiovolumeincrease,
radiovolumedecrease } },
{ "radiovolumeprev_sw:",{
radiovolumedecrease,
none } },
{ "radiovolumenext_sw:",{
radiovolumeincrease,
none } },
{ "pantfront_sw:", {
pantographtogglefront,
none } },
{ "pantrear_sw:", {
pantographtogglerear,
none } },
{ "pantfrontoff_sw:", {
pantographlowerfront,
none } },
{ "pantrearoff_sw:", {
pantographlowerrear,
none } },
{ "pantalloff_sw:", {
pantographlowerall,
none } },
{ "pantselected_sw:", {
pantographtoggleselected,
none } }, // TBD: bind lowerselected in case of toggle switch
{ "pantselectedoff_sw:", {
pantographlowerselected,
none } },
{ "pantselect_sw:", {
pantographselectnext,
pantographselectprevious } },
{ "pantvalves_sw:", {
pantographvalvesupdate,
pantographvalvesoff } },
{ "pantvalvesupdate_bt:", {
pantographvalvesupdate,
none}},
{ "pantvalvesoff_bt:", {
pantographvalvesoff,
none}},
{ "pantcompressor_sw:", {
pantographcompressoractivate,
none } },
{ "pantcompressorvalve_sw:", {
pantographcompressorvalvetoggle,
none } },
{ "trainheating_sw:", {
heatingtoggle,
none } },
{ "signalling_sw:", {
mubrakingindicatortoggle,
none } },
{ "door_signalling_sw:", {
doorlocktoggle,
none } },
{ "nextcurrent_sw:", {
mucurrentindicatorothersourceactivate,
none } },
{ "distancecounter_sw:", {
distancecounteractivate,
none } },
{ "instrumentlight_sw:", {
instrumentlighttoggle,
none } },
{ "dashboardlight_sw:", {
dashboardlighttoggle,
none } },
{ "dashboardlighton_sw:", {
dashboardlightenable,
none } },
{ "dashboardlightoff_sw:", {
dashboardlightdisable,
none } },
{ "timetablelight_sw:", {
timetablelighttoggle,
none } },
{ "timetablelighton_sw:", {
timetablelightenable,
none } },
{ "timetablelightoff_sw:", {
timetablelightdisable,
none } },
{ "cablight_sw:", {
interiorlighttoggle,
none } },
{ "cablightdim_sw:", {
interiorlightdimtoggle,
none } },
{ "compartmentlights_sw:", {
compartmentlightstoggle,
none } },
{ "compartmentlightson_sw:", {
compartmentlightsenable,
none } },
{ "compartmentlightsoff_sw:", {
compartmentlightsdisable,
none } },
{ "battery_sw:", {
batterytoggle,
none } },
{ "batteryon_sw:", {
batteryenable,
none } },
{ "batteryoff_sw:", {
batterydisable,
none } },
{ "cabactivation_sw:", {
cabactivationtoggle,
none } },
{ "couplingdisconnect_sw:",{
occupiedcarcouplingdisconnect,
none } },
{ "couplingdisconnectback_sw:",{
occupiedcarcouplingdisconnectback,
none } },
{"universal0:", {generictoggle0, none}},
{"universal1:", {generictoggle1, none}},
{"universal2:", {generictoggle2, none}},
{"universal3:", {generictoggle3, none}},
{"universal4:", {generictoggle4, none}},
{"universal5:", {generictoggle5, none}},
{"universal6:", {generictoggle6, none}},
{"universal7:", {generictoggle7, none}},
{"universal8:", {generictoggle8, none}},
{"universal9:", {generictoggle9, none}},
{"universal10:", {generictoggle10, none}},
{"universal11:", {generictoggle11, none}},
{"universal12:", {generictoggle12, none}},
{"universal13:", {generictoggle13, none}},
{"universal14:", {generictoggle14, none}},
{"universal15:", {generictoggle15, none}},
{"universal16:", {generictoggle16, none}},
{"universal17:", {generictoggle17, none}},
{"universal18:", {generictoggle18, none}},
{"universal19:", {generictoggle19, none}},
{"universal20:", {generictoggle20, none}},
{"universal21:", {generictoggle21, none}},
{"universal22:", {generictoggle22, none}},
{"universal23:", {generictoggle23, none}},
{"universal24:", {generictoggle24, none}},
{"universal25:", {generictoggle25, none}},
{"universal26:", {generictoggle26, none}},
{"universal27:", {generictoggle27, none}},
{"universal28:", {generictoggle28, none}},
{"universal29:", {generictoggle29, none}},
{ "speedinc_bt:",{
speedcontrolincrease,
none } },
{ "speeddec_bt:",{
speedcontroldecrease,
none } },
{ "speedctrlpowerinc_bt:",{
speedcontrolpowerincrease,
none } },
{ "speedctrlpowerdec_bt:",{
speedcontrolpowerdecrease,
none } },
{ "speedbutton0:",{
speedcontrolbutton0,
none } },
{ "speedbutton1:",{
speedcontrolbutton1,
none } },
{ "speedbutton2:",{
speedcontrolbutton2,
none } },
{ "speedbutton3:",{
speedcontrolbutton3,
none } },
{ "speedbutton4:",{
speedcontrolbutton4,
none } },
{ "speedbutton5:",{
speedcontrolbutton5,
none } },
{ "speedbutton6:",{
speedcontrolbutton6,
none } },
{ "speedbutton7:",{
speedcontrolbutton7,
none } },
{ "speedbutton8:",{
speedcontrolbutton8,
none } },
{ "speedbutton9:",{
speedcontrolbutton9,
none } },
{ "inverterenable1_bt:",{
inverterenable1,
none } },
{ "inverterenable2_bt:",{
inverterenable2,
none } },
{ "inverterenable3_bt:",{
inverterenable3,
none } },
{ "inverterenable4_bt:",{
inverterenable4,
none } },
{ "inverterenable5_bt:",{
inverterenable5,
none } },
{ "inverterenable6_bt:",{
inverterenable6,
none } },
{ "inverterenable7_bt:",{
inverterenable7,
none } },
{ "inverterenable8_bt:",{
inverterenable8,
none } },
{ "inverterenable9_bt:",{
inverterenable9,
none } },
{ "inverterenable10_bt:",{
inverterenable10,
none } },
{ "inverterenable11_bt:",{
inverterenable11,
none } },
{ "inverterenable12_bt:",{
inverterenable12,
none } },
{ "inverterdisable1_bt:",{
inverterdisable1,
none } },
{ "inverterdisable2_bt:",{
inverterdisable2,
none } },
{ "inverterdisable3_bt:",{
inverterdisable3,
none } },
{ "inverterdisable4_bt:",{
inverterdisable4,
none } },
{ "inverterdisable5_bt:",{
inverterdisable5,
none } },
{ "inverterdisable6_bt:",{
inverterdisable6,
none } },
{ "inverterdisable7_bt:",{
inverterdisable7,
none } },
{ "inverterdisable8_bt:",{
inverterdisable8,
none } },
{ "inverterdisable9_bt:",{
inverterdisable9,
none } },
{ "inverterdisable10_bt:",{
inverterdisable10,
none } },
{ "inverterdisable11_bt:",{
inverterdisable11,
none } },
{ "inverterdisable12_bt:",{
inverterdisable12,
none } },
{ "invertertoggle1_bt:",{
invertertoggle1,
none } },
{ "invertertoggle2_bt:",{
invertertoggle2,
none } },
{ "invertertoggle3_bt:",{
invertertoggle3,
none } },
{ "invertertoggle4_bt:",{
invertertoggle4,
none } },
{ "invertertoggle5_bt:",{
invertertoggle5,
none } },
{ "invertertoggle6_bt:",{
invertertoggle6,
none } },
{ "invertertoggle7_bt:",{
invertertoggle7,
none } },
{ "invertertoggle8_bt:",{
invertertoggle8,
none } },
{ "invertertoggle9_bt:",{
invertertoggle9,
none } },
{ "invertertoggle10_bt:",{
invertertoggle10,
none } },
{ "invertertoggle11_bt:",{
invertertoggle11,
none } },
{ "invertertoggle12_bt:",{
invertertoggle12,
none } },
{ "wipers_sw:",{
wiperswitchincrease,
wiperswitchdecrease
} },
};
}
user_command
drivermouse_input::adjust_command( user_command Command ) const {
using enum user_command;
if( true == Global.shiftState
&& Command != none ) {
switch( Command ) {
case mastercontrollerincrease: { Command = mastercontrollerincreasefast; break; }
case mastercontrollerdecrease: { Command = mastercontrollerdecreasefast; break; }
case secondcontrollerincrease: { Command = secondcontrollerincreasefast; break; }
case secondcontrollerdecrease: { Command = secondcontrollerdecreasefast; break; }
case independentbrakeincrease: { Command = independentbrakeincreasefast; break; }
case independentbrakedecrease: { Command = independentbrakedecreasefast; break; }
default: { break; }
}
}
return Command;
}
std::optional<int>
drivermouse_input::universal_index( user_command const Command ) {
auto const index { static_cast<int>( Command ) - static_cast<int>( user_command::generictoggle0 ) };
if( index < 0
|| index > static_cast<int>( user_command::generictoggle29 ) - static_cast<int>( user_command::generictoggle0 ) ) {
return std::nullopt;
}
return index;
}
void
drivermouse_input::toggle_universal( int const Index ) const {
auto const toggle { static_cast<user_command>( static_cast<int>( user_command::generictoggle0 ) + Index ) };
m_relay.post( toggle, 0, 0, GLFW_PRESS, 0 );
m_relay.post( toggle, 0, 0, GLFW_RELEASE, 0 );
}
//---------------------------------------------------------------------------