throttle: removed functions wrapping, access function via train/decoder
Dieser Commit ist enthalten in:
Ursprung
4d317156f6
Commit
71db228d40
@ -332,11 +332,11 @@ void Kernel::receiveFrom(std::string_view message, IOHandler::ClientId clientId)
|
||||
postSendTo(throttleCommand(multiThrottleId, '+', address.address, address.isLong), clientId);
|
||||
|
||||
std::unordered_map<uint32_t, std::string_view> functionNames;
|
||||
for(const auto& f : *throttle->functions)
|
||||
for(const auto& f : *throttle->decoder()->functions)
|
||||
functionNames.emplace(f->number.value(), f->name.value());
|
||||
postSendTo(throttleFuctionNames(multiThrottleId, address.address, address.isLong, functionNames), clientId);
|
||||
|
||||
for(const auto& f : *throttle->functions)
|
||||
for(const auto& f : *throttle->decoder()->functions)
|
||||
postSendTo(throttleFunction(multiThrottleId, address.address, address.isLong, f->number, f->value), clientId);
|
||||
|
||||
if(throttle->decoder()->emergencyStop)
|
||||
@ -580,14 +580,46 @@ void Kernel::multiThrottleAction(IOHandler::ClientId clientId, char multiThrottl
|
||||
{
|
||||
if(const auto& throttle = getThottle(clientId, multiThrottleId); throttle && throttle->acquired())
|
||||
{
|
||||
if(const auto& function = throttle->getFunction(number))
|
||||
if(const auto& function = throttle->decoder()->getFunction(number))
|
||||
{
|
||||
if(force)
|
||||
if(force) // set
|
||||
{
|
||||
function->value = value;
|
||||
else if(value)
|
||||
function->press();
|
||||
else
|
||||
function->release();
|
||||
}
|
||||
else if(value) // press
|
||||
{
|
||||
switch(function->type.value())
|
||||
{
|
||||
case DecoderFunctionType::Hold:
|
||||
case DecoderFunctionType::Momentary:
|
||||
function->value = false;
|
||||
break;
|
||||
|
||||
case DecoderFunctionType::OnOff:
|
||||
// toggle when button is pushed, do nothing on release
|
||||
function->value = !function->value;
|
||||
break;
|
||||
|
||||
case DecoderFunctionType::AlwaysOff:
|
||||
case DecoderFunctionType::AlwaysOn:
|
||||
break; // do nothing
|
||||
}
|
||||
}
|
||||
else // release
|
||||
{
|
||||
switch(function->type.value())
|
||||
{
|
||||
case DecoderFunctionType::Hold:
|
||||
case DecoderFunctionType::Momentary:
|
||||
function->value = false;
|
||||
break;
|
||||
|
||||
case DecoderFunctionType::OnOff:
|
||||
case DecoderFunctionType::AlwaysOff:
|
||||
case DecoderFunctionType::AlwaysOn:
|
||||
break; // do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -68,7 +68,6 @@ Throttle::Throttle(World& world, std::string_view _id)
|
||||
{
|
||||
return acquired();
|
||||
}}
|
||||
, functions{*this, "functions", {}, PropertyFlags::ReadOnly}
|
||||
, train{this, "train", nullptr, PropertyFlags::ReadOnly}
|
||||
, emergencyStop{*this, "emergency_stop",
|
||||
[this]()
|
||||
@ -276,28 +275,7 @@ Throttle::AcquireResult Throttle::acquire(std::shared_ptr<Decoder> decoder, bool
|
||||
|
||||
m_decoder = std::move(decoder);
|
||||
|
||||
for(auto function : *m_decoder->functions)
|
||||
{
|
||||
const auto& type = function->type.value();
|
||||
if(type != DecoderFunctionType::AlwaysOff && type != DecoderFunctionType::AlwaysOn)
|
||||
{
|
||||
functions.appendInternal(std::make_shared<ThrottleFunction>(*this, function->number));
|
||||
}
|
||||
}
|
||||
|
||||
Attributes::setEnabled({emergencyStop, throttle, stop, setDirection}, true);
|
||||
|
||||
return AcquireResult::Success;
|
||||
}
|
||||
|
||||
const std::shared_ptr<ThrottleFunction>& Throttle::getFunction(uint32_t number) const
|
||||
{
|
||||
static const std::shared_ptr<ThrottleFunction> noFunction;
|
||||
|
||||
for(const auto& function : *functions)
|
||||
if(function->number == number)
|
||||
return function;
|
||||
|
||||
return noFunction;
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
|
||||
#include "../../core/idobject.hpp"
|
||||
#include <traintastic/enum/direction.hpp>
|
||||
#include "throttlefunction.hpp"
|
||||
#include "../../core/property.hpp"
|
||||
#include "../../core/objectproperty.hpp"
|
||||
#include "../../core/objectvectorproperty.hpp"
|
||||
@ -71,7 +70,6 @@ class Throttle : public IdObject
|
||||
Property<std::string> name;
|
||||
Property<Direction> direction;
|
||||
Property<float> throttle;
|
||||
ObjectVectorProperty<ThrottleFunction> functions;
|
||||
ObjectProperty<Train> train;
|
||||
Method<bool()> emergencyStop;
|
||||
Method<bool()> stop;
|
||||
@ -91,8 +89,6 @@ class Throttle : public IdObject
|
||||
{
|
||||
return m_decoder;
|
||||
}
|
||||
|
||||
const std::shared_ptr<ThrottleFunction>& getFunction(uint32_t number) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,95 +0,0 @@
|
||||
/**
|
||||
* server/src/hardware/throttle/throttlefunction.cpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "throttlefunction.hpp"
|
||||
#include "throttle.hpp"
|
||||
#include "../../core/method.tpp"
|
||||
#include "../decoder/decoder.hpp"
|
||||
|
||||
ThrottleFunction::ThrottleFunction(Throttle& throttle, uint32_t number_)
|
||||
: m_throttle{throttle}
|
||||
, number{this, "number", number_, PropertyFlags::ReadOnly}
|
||||
, name{this, "name", {}, PropertyFlags::ReadOnly}
|
||||
, value{this, "value", false, PropertyFlags::ReadWrite}
|
||||
, press{*this, "press",
|
||||
[this]()
|
||||
{
|
||||
if(!m_throttle.m_decoder)
|
||||
return;
|
||||
|
||||
if(auto function = m_throttle.m_decoder->getFunction(number))
|
||||
{
|
||||
switch(function->type.value())
|
||||
{
|
||||
case DecoderFunctionType::Hold:
|
||||
case DecoderFunctionType::Momentary:
|
||||
function->value = false;
|
||||
break;
|
||||
|
||||
case DecoderFunctionType::OnOff:
|
||||
// toggle when button is pushed, do nothing on release
|
||||
function->value = !function->value;
|
||||
break;
|
||||
|
||||
case DecoderFunctionType::AlwaysOff:
|
||||
case DecoderFunctionType::AlwaysOn:
|
||||
break; // do nothing
|
||||
}
|
||||
}
|
||||
}}
|
||||
, release{*this, "release",
|
||||
[this]()
|
||||
{
|
||||
if(!m_throttle.m_decoder)
|
||||
return;
|
||||
|
||||
if(auto function = m_throttle.m_decoder->getFunction(number))
|
||||
{
|
||||
switch(function->type.value())
|
||||
{
|
||||
case DecoderFunctionType::Hold:
|
||||
case DecoderFunctionType::Momentary:
|
||||
function->value = false;
|
||||
break;
|
||||
|
||||
case DecoderFunctionType::OnOff:
|
||||
case DecoderFunctionType::AlwaysOff:
|
||||
case DecoderFunctionType::AlwaysOn:
|
||||
break; // do nothing
|
||||
}
|
||||
}
|
||||
}}
|
||||
{
|
||||
if(const auto& decoder = m_throttle.m_decoder)
|
||||
{
|
||||
if(auto function = decoder->getFunction(number))
|
||||
{
|
||||
name.setValueInternal(function->name);
|
||||
value.setValueInternal(function->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ThrottleFunction::getObjectId() const
|
||||
{
|
||||
return m_throttle.getObjectId().append(".").append(m_throttle.functions.name()).append(".f").append(std::to_string(number));
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* server/src/hardware/throttle/throttlefunction.hpp
|
||||
*
|
||||
* This file is part of the traintastic source code.
|
||||
*
|
||||
* Copyright (C) 2022 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef TRAINTASTIC_SERVER_HARDWARE_THROTTLE_THROTTLEFUNCTION_HPP
|
||||
#define TRAINTASTIC_SERVER_HARDWARE_THROTTLE_THROTTLEFUNCTION_HPP
|
||||
|
||||
#include "../../core/object.hpp"
|
||||
#include "../../core/property.hpp"
|
||||
#include "../../core/method.hpp"
|
||||
|
||||
class Throttle;
|
||||
|
||||
class ThrottleFunction : public Object
|
||||
{
|
||||
CLASS_ID("throttle_function")
|
||||
|
||||
private:
|
||||
Throttle& m_throttle;
|
||||
|
||||
public:
|
||||
Property<uint32_t> number;
|
||||
Property<std::string> name;
|
||||
Property<bool> value;
|
||||
Method<void()> press;
|
||||
Method<void()> release;
|
||||
|
||||
ThrottleFunction(Throttle& throttle, uint32_t number);
|
||||
|
||||
std::string getObjectId() const final;
|
||||
};
|
||||
|
||||
#endif
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren