| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <string> |
| 24 |
|
| 25 |
#include "ControlInterface.h" |
| 26 |
#include "DataModel/LocoFunctions.h" |
| 27 |
#include "DataTypes.h" |
| 28 |
#include "Hardware/HardwareInterface.h" |
| 29 |
#include "Hardware/HardwareParams.h" |
| 30 |
#include "Hardware/LocoCache.h" |
| 31 |
#include "Manager.h" |
| 32 |
|
| 33 |
namespace Hardware |
| 34 |
{ |
| 35 |
class HardwareHandler: public ControlInterface |
| 36 |
{ |
| 37 |
public: |
| 38 |
HardwareHandler() = delete; |
| 39 |
HardwareHandler(const HardwareHandler&) = delete; |
| 40 |
HardwareHandler& operator=(const HardwareHandler&) = delete; |
| 41 |
|
| 42 |
inline HardwareHandler(const HardwareParams* params) |
| 43 |
: ControlInterface(ControlTypeHardware), |
| 44 |
instance(nullptr), |
| 45 |
params(nullptr) |
| 46 |
{ |
| 47 |
Init(params); |
| 48 |
} |
| 49 |
|
| 50 |
inline ~HardwareHandler() |
| 51 |
{ |
| 52 |
Close(); |
| 53 |
} |
| 54 |
|
| 55 |
virtual void Start() override |
| 56 |
{ |
| 57 |
if (instance == nullptr) |
| 58 |
{ |
| 59 |
return; |
| 60 |
} |
| 61 |
instance->Start(); |
| 62 |
} |
| 63 |
|
| 64 |
inline void ReInit(const HardwareParams* params) override |
| 65 |
{ |
| 66 |
Close(); |
| 67 |
Init(params); |
| 68 |
Start(); |
| 69 |
} |
| 70 |
|
| 71 |
inline ControlID GetControlID() const |
| 72 |
{ |
| 73 |
return params->GetControlID(); |
| 74 |
} |
| 75 |
|
| 76 |
const std::string& GetName() const override; |
| 77 |
|
| 78 |
const std::string& GetShortName() const override; |
| 79 |
|
| 80 |
void AccessoryProtocols(std::vector<Protocol>& protocols) const override; |
| 81 |
bool AccessoryProtocolSupported(Protocol protocol) const override; |
| 82 |
void AccessoryState(const ControlType controlType, const DataModel::Accessory* accessory) override; |
| 83 |
|
| 84 |
void Booster(const ControlType controlType, BoosterState status) override; |
| 85 |
Hardware::Capabilities GetCapabilities() const override; |
| 86 |
|
| 87 |
void LocoBaseOrientation(const ControlType controlType, |
| 88 |
const DataModel::LocoBase* loco, |
| 89 |
const Orientation orientation) override; |
| 90 |
|
| 91 |
void LocoBaseFunction(const ControlType controlType, |
| 92 |
const DataModel::LocoBase* loco, |
| 93 |
const DataModel::LocoFunctionNr function, |
| 94 |
const DataModel::LocoFunctionState on) override; |
| 95 |
|
| 96 |
void LocoProtocols(std::vector<Protocol>& protocols) const override; |
| 97 |
|
| 98 |
bool LocoProtocolSupported(Protocol protocol) const override; |
| 99 |
|
| 100 |
void LocoBaseSpeed(const ControlType controlType, |
| 101 |
const DataModel::LocoBase* loco, |
| 102 |
const Speed speed) override; |
| 103 |
|
| 104 |
void LocoBaseSpeedOrientationFunctions(const DataModel::LocoBase* loco, |
| 105 |
const Speed speed, |
| 106 |
const Orientation orientation, |
| 107 |
std::vector<DataModel::LocoFunctionEntry>& functions) override; |
| 108 |
|
| 109 |
void LocoSettings(const LocoID locoId, |
| 110 |
const std::string& name, |
| 111 |
const std::string& matchKey) override; |
| 112 |
|
| 113 |
void LocoDelete(const LocoID locoId, |
| 114 |
const std::string& name, |
| 115 |
const std::string& matchKey) override; |
| 116 |
|
| 117 |
void AccessorySettings(const AccessoryID accessoryId, |
| 118 |
const std::string& name, |
| 119 |
const std::string& matchKey) override; |
| 120 |
|
| 121 |
void AccessoryDelete(const AccessoryID accessoryId, |
| 122 |
const std::string& name, |
| 123 |
const std::string& matchKey) override; |
| 124 |
|
| 125 |
void SwitchSettings(const SwitchID switchId, |
| 126 |
const std::string& name, |
| 127 |
const std::string& matchKey) override; |
| 128 |
|
| 129 |
void SwitchDelete(const SwitchID switchId, |
| 130 |
const std::string& name, |
| 131 |
const std::string& matchKey) override; |
| 132 |
|
| 133 |
void SwitchState(const ControlType controlType, const DataModel::Switch* mySwitch) override; |
| 134 |
|
| 135 |
void SignalSettings(const SignalID signalId, |
| 136 |
const std::string& name, |
| 137 |
const std::string& matchKey) override; |
| 138 |
|
| 139 |
void SignalDelete(const SignalID signalId, |
| 140 |
const std::string& name, |
| 141 |
const std::string& matchKey) override; |
| 142 |
|
| 143 |
void SignalState(const ControlType controlType, const DataModel::Signal* signal) override; |
| 144 |
|
| 145 |
void ProgramRead(const ProgramMode mode, const Address address, const CvNumber cv) override; |
| 146 |
void ProgramWrite(const ProgramMode mode, const Address address, const CvNumber cv, const CvValue value) override; |
| 147 |
|
| 148 |
void FeedbackDelete(const FeedbackID feedbackID, const std::string& name) override; |
| 149 |
|
| 150 |
|
| 151 |
void FeedbackSettings(const FeedbackID feedbackID, const std::string& name) override; |
| 152 |
|
| 153 |
void AddUnmatchedLocos(std::map<std::string,DataModel::LocoConfig>& list) const override; |
| 154 |
std::map<std::string,DataModel::LocoConfig> GetUnmatchedLocos(const std::string& matchKey) const override; |
| 155 |
DataModel::LocoConfig GetLocoByMatchKey(const std::string& match) const override; |
| 156 |
|
| 157 |
void AddUnmatchedMultipleUnits(std::map<std::string,DataModel::LocoConfig>& list) const override; |
| 158 |
std::map<std::string,DataModel::LocoConfig> GetUnmatchedMultipleUnits(const std::string& matchKey) const override; |
| 159 |
DataModel::LocoConfig GetMultipleUnitByMatchKey(const std::string& match) const override; |
| 160 |
|
| 161 |
void AddUnmatchedAccessories(std::map<std::string,DataModel::AccessoryConfig>& list) const override; |
| 162 |
std::map<std::string,DataModel::AccessoryConfig> GetUnmatchedAccessories(const std::string& matchKey) const override; |
| 163 |
DataModel::AccessoryConfig GetAccessoryByMatchKey(const std::string& match) const override; |
| 164 |
|
| 165 |
void AddUnmatchedFeedbacks(std::map<std::string,DataModel::FeedbackConfig>& list) const override; |
| 166 |
std::map<std::string,DataModel::FeedbackConfig> GetUnmatchedFeedbacks(const std::string& matchKey) const override; |
| 167 |
DataModel::FeedbackConfig GetFeedbackByMatchKey(const std::string& match) const override; |
| 168 |
|
| 169 |
static void ArgumentTypesOfHardwareTypeAndHint(const HardwareType hardwareType, std::map<unsigned char,ArgumentType>& arguments, std::string& hint); |
| 170 |
|
| 171 |
private: |
| 172 |
Hardware::HardwareInterface* instance; |
| 173 |
const HardwareParams* params; |
| 174 |
|
| 175 |
static const std::string Unknown; |
| 176 |
|
| 177 |
void Init(const HardwareParams* params); |
| 178 |
void Close(); |
| 179 |
bool ProgramCheckValues(const ProgramMode mode, const CvNumber cv, const CvValue value = 1); |
| 180 |
|
| 181 |
void AccessoryBaseState(const Protocol protocol, |
| 182 |
const Address address, |
| 183 |
const DataModel::AccessoryState state, |
| 184 |
const DataModel::AccessoryPulseDuration duration); |
| 185 |
|
| 186 |
static inline void AccessoryBaseStateStatic(HardwareInterface* instance, |
| 187 |
const Protocol protocol, |
| 188 |
const Address address, |
| 189 |
const DataModel::AccessoryState state, |
| 190 |
const DataModel::AccessoryPulseDuration duration) |
| 191 |
{ |
| 192 |
Utils::Utils::SleepForMilliseconds(duration); |
| 193 |
instance->Accessory(protocol, address, state, false, 0); |
| 194 |
} |
| 195 |
}; |
| 196 |
} |
| 197 |
|