Ursprung
54ba3664a6
Commit
779b8f3fb4
@ -57,6 +57,7 @@ std::pair<uint16_t, uint16_t> DecoderController::decoderAddressMinMax(DecoderPro
|
||||
case DecoderProtocol::Selectrix:
|
||||
return {1, 112};
|
||||
|
||||
case DecoderProtocol::MFX:
|
||||
case DecoderProtocol::None:
|
||||
return noAddressMinMax;
|
||||
}
|
||||
@ -69,6 +70,7 @@ tcb::span<const uint8_t> DecoderController::decoderSpeedSteps(DecoderProtocol pr
|
||||
static constexpr std::array<uint8_t, 3> dccSpeedSteps{{14, 28, 128}};
|
||||
static constexpr std::array<uint8_t, 3> motorolaSpeedSteps{{14, 27, 28}};
|
||||
static constexpr std::array<uint8_t, 1> selectrixSpeedSteps{{32}};
|
||||
static constexpr std::array<uint8_t, 1> mfxSpeedSteps{{126}};
|
||||
|
||||
switch(protocol)
|
||||
{
|
||||
@ -82,6 +84,9 @@ tcb::span<const uint8_t> DecoderController::decoderSpeedSteps(DecoderProtocol pr
|
||||
case DecoderProtocol::Selectrix:
|
||||
return selectrixSpeedSteps;
|
||||
|
||||
case DecoderProtocol::MFX:
|
||||
return mfxSpeedSteps;
|
||||
|
||||
case DecoderProtocol::None:
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -59,6 +59,26 @@ MarklinCANInterface::MarklinCANInterface(World& world, std::string_view _id)
|
||||
m_interfaceItems.insertBefore(inputs, notes);
|
||||
}
|
||||
|
||||
tcb::span<const DecoderProtocol> MarklinCANInterface::decoderProtocols() const
|
||||
{
|
||||
static constexpr std::array<DecoderProtocol, 4> protocols{DecoderProtocol::DCCShort, DecoderProtocol::DCCLong, DecoderProtocol::MFX, DecoderProtocol::Motorola};
|
||||
return tcb::span<const DecoderProtocol>{protocols.data(), protocols.size()};
|
||||
}
|
||||
|
||||
tcb::span<const uint8_t> MarklinCANInterface::decoderSpeedSteps(DecoderProtocol protocol) const
|
||||
{
|
||||
static constexpr std::array<uint8_t, 4> dccLongSpeedSteps{{28, 128}}; // 14 not supported for long addresses
|
||||
|
||||
switch(protocol)
|
||||
{
|
||||
case DecoderProtocol::DCCLong:
|
||||
return dccLongSpeedSteps;
|
||||
|
||||
default:
|
||||
return DecoderController::decoderSpeedSteps(protocol);
|
||||
}
|
||||
}
|
||||
|
||||
void MarklinCANInterface::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber)
|
||||
{
|
||||
if(m_kernel)
|
||||
|
||||
@ -60,6 +60,8 @@ class MarklinCANInterface final
|
||||
MarklinCANInterface(World& world, std::string_view _id);
|
||||
|
||||
// DecoderController:
|
||||
tcb::span<const DecoderProtocol> decoderProtocols() const final;
|
||||
tcb::span<const uint8_t> decoderSpeedSteps(DecoderProtocol protocol) const final;
|
||||
void decoderChanged(const Decoder& decoder, DecoderChangeFlags changes, uint32_t functionNumber) final;
|
||||
|
||||
// InputController:
|
||||
|
||||
@ -42,9 +42,15 @@ static std::tuple<bool, DecoderProtocol, uint16_t> uidToProtocolAddress(uint32_t
|
||||
if(inRange(uid, UID::Range::locomotiveMFX))
|
||||
return {true, DecoderProtocol::MFX, uid - UID::Range::locomotiveMFX.first};
|
||||
if(inRange(uid, UID::Range::locomotiveDCC))
|
||||
return {true, DecoderProtocol::DCC, uid - UID::Range::locomotiveDCC.first};
|
||||
|
||||
return {false, DecoderProtocol::Auto, 0};
|
||||
{
|
||||
//! \todo Handle long address < 128
|
||||
const uint16_t address = uid - UID::Range::locomotiveDCC.first;
|
||||
if(address <= DCC::addressShortMax)
|
||||
return {true, DecoderProtocol::DCCShort, address};
|
||||
else
|
||||
return {true, DecoderProtocol::DCCLong, address};
|
||||
}
|
||||
return {false, DecoderProtocol::None, 0};
|
||||
}
|
||||
|
||||
Kernel::Kernel(const Config& config, bool simulation)
|
||||
@ -175,8 +181,7 @@ void Kernel::receive(const Message& message)
|
||||
EventLoop::call(
|
||||
[this, protocol=protocol, address=address]()
|
||||
{
|
||||
const bool longAddress = (protocol == DecoderProtocol::DCC) && DCC::isLongAddress(address);
|
||||
if(const auto& decoder = m_decoderController->getDecoder(protocol, address, longAddress))
|
||||
if(const auto& decoder = m_decoderController->getDecoder(protocol, address))
|
||||
decoder->emergencyStop.setValueInternal(true);
|
||||
});
|
||||
}
|
||||
@ -209,8 +214,7 @@ void Kernel::receive(const Message& message)
|
||||
EventLoop::call(
|
||||
[this, protocol=protocol, address=address, throttle=Decoder::speedStepToThrottle(locomotiveSpeed.speed(), LocomotiveSpeed::speedMax)]()
|
||||
{
|
||||
const bool longAddress = (protocol == DecoderProtocol::DCC) && DCC::isLongAddress(address);
|
||||
if(const auto& decoder = m_decoderController->getDecoder(protocol, address, longAddress))
|
||||
if(const auto& decoder = m_decoderController->getDecoder(protocol, address))
|
||||
{
|
||||
decoder->emergencyStop.setValueInternal(false);
|
||||
decoder->throttle.setValueInternal(throttle);
|
||||
@ -249,8 +253,7 @@ void Kernel::receive(const Message& message)
|
||||
EventLoop::call(
|
||||
[this, protocol=protocol, address=address, direction]()
|
||||
{
|
||||
const bool longAddress = (protocol == DecoderProtocol::DCC) && DCC::isLongAddress(address);
|
||||
if(const auto& decoder = m_decoderController->getDecoder(protocol, address, longAddress))
|
||||
if(const auto& decoder = m_decoderController->getDecoder(protocol, address))
|
||||
decoder->direction.setValueInternal(direction);
|
||||
});
|
||||
}
|
||||
@ -270,8 +273,7 @@ void Kernel::receive(const Message& message)
|
||||
EventLoop::call(
|
||||
[this, protocol=protocol, address=address, number=locomotiveFunction.number(), value=locomotiveFunction.isOn()]()
|
||||
{
|
||||
const bool longAddress = (protocol == DecoderProtocol::DCC) && DCC::isLongAddress(address);
|
||||
if(const auto& decoder = m_decoderController->getDecoder(protocol, address, longAddress))
|
||||
if(const auto& decoder = m_decoderController->getDecoder(protocol, address))
|
||||
decoder->setFunctionValue(number, value);
|
||||
});
|
||||
}
|
||||
@ -363,7 +365,8 @@ void Kernel::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes,
|
||||
|
||||
switch(decoder.protocol.value())
|
||||
{
|
||||
case DecoderProtocol::DCC:
|
||||
case DecoderProtocol::DCCShort:
|
||||
case DecoderProtocol::DCCLong:
|
||||
uid = UID::locomotiveDCC(decoder.address);
|
||||
break;
|
||||
|
||||
@ -375,9 +378,9 @@ void Kernel::decoderChanged(const Decoder& decoder, DecoderChangeFlags changes,
|
||||
uid = UID::locomotiveMFX(decoder.address);
|
||||
break;
|
||||
|
||||
case DecoderProtocol::Auto:
|
||||
case DecoderProtocol::None:
|
||||
case DecoderProtocol::Selectrix:
|
||||
case DecoderProtocol::Custom:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren