mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
* fix(cab): the compartment lights keyboard toggle works more than once in a cab without the switch The compartment lights get two requests, on (CompartmentLights.is_enabled) and off (is_disabled), and the off one wins in LightsCheck(). The enable and disable commands withdrew the other request only when the cab had a toggle type compartmentlights_sw:. A push type switch and the separate compartmentlightson_sw:/compartmentlightsoff_sw: push buttons withdraw their own request when released, but a cab with none of these controls (the CD 810 cab A, where only the engine compartment has the switch) never withdrew anything: after one on/off both requests stayed set, the lights stayed off and ctrl+; kept choosing "turn off". Now a command withdraws the other request when the cab has the toggle type switch (as before), or when it has no compartmentlights_sw: and no push button for the other request, so the keyboard toggle acts as a two-state switch there. Cabs with a push type switch or with the on/off push buttons keep their behaviour. The decision is in vehicle/compartmentlightsswitch.h, unit tested together with the vehicle's LightsCheck() on the Elf definition. * fix(cab): the compartment lights keyboard toggle latches in a cab with the on and off push buttons (#355) In a cab with the compartmentlightson_sw: / compartmentlightsoff_sw: push buttons and no compartmentlights_sw: (the EN57-2000, the SA134, the 214M, the EN57AKL/AL/KM and EN71) ctrl+; turned the compartment lights off only while the key was held. OnCommand_compartmentlightstoggle picked the command from the lights' state again on the key release, after the press had changed that state, so the release went to the other command: the push button that was pressed never withdrew its request. After the first press the on request stayed set, and from then on every release withdrew the off request and the lights came back on. The toggle now sends the release to both commands, as a release of the push buttons would: each returns its own push type control to the neutral position and withdraws its request. The press is picked from the state as before. Mouse clicks on the push buttons go to the enable and disable commands directly and are unchanged; with a compartmentlights_sw: both commands release it the same way, and a cab without the controls has nothing to release. In the Elf cab (an impulse compartmentlights_sw: and the on/off return buttons) the lights worked, but the button the key had pressed stayed pressed; now it returns too. * test(cab): the compartment lights switch test without Sonar issues using enum for range_t in the release helpers, and the lights declared in the if that reads them. No change in what is tested.
28 lines
1.4 KiB
C++
28 lines
1.4 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/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
// the compartment lights get two requests: on (CompartmentLights.is_enabled) and off (is_disabled), and the off one
|
|
// wins. A two-state compartmentlights_sw: holds one of them, so turning it to one position withdraws the other request.
|
|
// A push type compartmentlights_sw: and the separate compartmentlightson_sw: / compartmentlightsoff_sw: push buttons
|
|
// withdraw their own request when they're released, so the other command leaves it alone. A cab with none of these
|
|
// controls (the keyboard toggle, ctrl+;, is all there is) acts as if it had the two-state switch, otherwise nothing
|
|
// would ever withdraw the off request and the lights couldn't be turned on again.
|
|
namespace compartment_lights_switch {
|
|
|
|
// whether the command for one of the requests also withdraws the other one, from the cab's compartmentlights_sw:
|
|
// (whether it's there and whether it's a toggle type switch) and whether the cab has the push button of the other
|
|
// request (compartmentlightsoff_sw: for the on command, compartmentlightson_sw: for the off command)
|
|
inline bool withdraws_other_request(bool const Hasswitch, bool const Switchistoggle, bool const Hasotherbutton) {
|
|
return Hasswitch ? Switchistoggle : false == Hasotherbutton;
|
|
}
|
|
|
|
} // namespace compartment_lights_switch
|