mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
* fix: the light preset selector turns on past its end with sound (eu07/maszyna#464) A selector with Wrap=Yes turned past its last position to the first one (or back) was set with PutValue(): no animation and no sound. On the EN57AKM these are the positions 0 and A1. A knob whose positions make a full turn now turns on the same way it was turned, sounding the position it reaches; other switches still jump, but sound the position too. * refactor(cab): the wrapping rotary switch without Sonar issues The full turn and the way on are declared in the ifs that use them, and the optional is tested with has_value(). No change in behaviour.
30 lines
1.4 KiB
C++
30 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
|
|
|
|
#include <optional>
|
|
|
|
// a multi-position rotary switch of the cab turned past its last position to the first one, or back past the first
|
|
// one to the last (a selector with Wrap=Yes, such as the light preset selector)
|
|
namespace gauge_wrap {
|
|
|
|
// the number of positions in one full turn of a rotary switch of Positions positions that turns by Scale of a full turn
|
|
// per position, if the switch can turn on past its end the short way round: the full turn is a whole number of positions
|
|
// (within the rounding of the scale in the cab definition, e.g. 0.167 for a sixth), all the positions fit in it, and the
|
|
// way on from the last position to the first one is at most half a turn. None otherwise
|
|
std::optional<int> full_turn(float Scale, int Positions);
|
|
|
|
// the value of the switch at Value seen one full turn of Turn positions earlier (Forward: it turns on past its last
|
|
// position to the first one) or later (back past the first position to the last one). The knob stands the same there,
|
|
// and turning from that value to the new position turns it on the way it was turned rather than all the way back
|
|
float turned_round(float Value, int Turn, bool Forward);
|
|
|
|
} // namespace gauge_wrap
|