| 1 |
/* |
| 2 |
RailControl - Model Railway Control Software |
| 3 |
|
| 4 |
Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org |
| 5 |
|
| 6 |
RailControl is free software; you can redistribute it and/or modify it |
| 7 |
under the terms of the GNU General Public License as published by the |
| 8 |
Free Software Foundation; either version 3, or (at your option) any |
| 9 |
later version. |
| 10 |
|
| 11 |
RailControl is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 14 |
See the GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with RailControl; see the file LICENCE. If not see |
| 18 |
<http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <vector> |
| 24 |
|
| 25 |
#include "DataModel/Serializable.h" |
| 26 |
|
| 27 |
namespace DataModel |
| 28 |
{ |
| 29 |
typedef uint16_t LocoFunctionNr; |
| 30 |
// 16 bit because icon is added with 256 to select f number and icon in same select dropdown box in relation. |
| 31 |
|
| 32 |
static const LocoFunctionNr NumberOfLocoFunctions = 33; // f0 - f32 = 33 |
| 33 |
|
| 34 |
enum LocoFunctionState : uint8_t |
| 35 |
{ |
| 36 |
LocoFunctionStateOff = 0, |
| 37 |
LocoFunctionStateOn = 1, |
| 38 |
LocoFunctionState0s5 = 5, |
| 39 |
LocoFunctionState1s0 = 10, |
| 40 |
LocoFunctionState1s5 = 15, |
| 41 |
LocoFunctionState2s0 = 20, |
| 42 |
}; |
| 43 |
|
| 44 |
enum LocoFunctionType : uint8_t |
| 45 |
{ |
| 46 |
LocoFunctionTypeNone = 0, |
| 47 |
LocoFunctionTypePermanent = 1, |
| 48 |
LocoFunctionTypeMoment = 2, |
| 49 |
LocoFunctionTypeFlashing = 3, // actually not implemented |
| 50 |
LocoFunctionTypeTimer = 4 // actually not implemented |
| 51 |
}; |
| 52 |
|
| 53 |
enum LocoFunctionIcon : uint16_t |
| 54 |
// 16 bit because icon is added with 256 to select f number and icon in same select dropdown box in relation. |
| 55 |
{ |
| 56 |
// Do not change numbers! |
| 57 |
// Only add numbers! |
| 58 |
// If you add numbers, add them also in |
| 59 |
// - ProtocolMaerklin.cpp |
| 60 |
// - WebServer::WebClient::HtmlTagRelationObject |
| 61 |
// - WebServer::WebClient::HandleLocoEdit |
| 62 |
LocoFunctionIconNone = 0, |
| 63 |
LocoFunctionIconDefault = 1, |
| 64 |
// logical functions |
| 65 |
LocoFunctionIconShuntingMode = 2, |
| 66 |
LocoFunctionIconInertia, |
| 67 |
// light functions |
| 68 |
LocoFunctionIconLight = 32, |
| 69 |
LocoFunctionIconHeadlightLowBeamForward, |
| 70 |
LocoFunctionIconHeadlightLowBeamReverse, |
| 71 |
LocoFunctionIconHeadlightHighBeamForward, |
| 72 |
LocoFunctionIconHeadlightHighBeamReverse, |
| 73 |
LocoFunctionIconBacklightForward, |
| 74 |
LocoFunctionIconBacklightReverse, |
| 75 |
LocoFunctionIconShuntingLight, |
| 76 |
LocoFunctionIconBlinkingLight, |
| 77 |
LocoFunctionIconInteriorLight1, |
| 78 |
LocoFunctionIconInteriorLight2, |
| 79 |
LocoFunctionIconTableLight1, |
| 80 |
LocoFunctionIconTableLight2, |
| 81 |
LocoFunctionIconTableLight3, |
| 82 |
LocoFunctionIconCabLight1, |
| 83 |
LocoFunctionIconCabLight2, |
| 84 |
LocoFunctionIconCabLight12, |
| 85 |
LocoFunctionIconDriversDeskLight, |
| 86 |
LocoFunctionIconTrainDestinationIndicator, |
| 87 |
LocoFunctionIconLocomotiveNumberIndicator, |
| 88 |
LocoFunctionIconEngineLight, |
| 89 |
LocoFunctionIconFireBox, |
| 90 |
LocoFunctionIconStairsLight, |
| 91 |
// mechanical functions |
| 92 |
LocoFunctionIconSmokeGenerator = 64, |
| 93 |
LocoFunctionIconTelex1, |
| 94 |
LocoFunctionIconTelex2, |
| 95 |
LocoFunctionIconTelex12, |
| 96 |
LocoFunctionIconPanto1, |
| 97 |
LocoFunctionIconPanto2, |
| 98 |
LocoFunctionIconPanto12, |
| 99 |
LocoFunctionIconUp, |
| 100 |
LocoFunctionIconDown, |
| 101 |
LocoFunctionIconUpDown1, |
| 102 |
LocoFunctionIconUpDown2, |
| 103 |
LocoFunctionIconLeft, |
| 104 |
LocoFunctionIconRight, |
| 105 |
LocoFunctionIconLeftRight, |
| 106 |
LocoFunctionIconTurnLeft, |
| 107 |
LocoFunctionIconTurnRight, |
| 108 |
LocoFunctionIconTurn, |
| 109 |
LocoFunctionIconCrane, |
| 110 |
LocoFunctionIconMagnet, |
| 111 |
LocoFunctionIconCraneHook, |
| 112 |
LocoFunctionIconFan, |
| 113 |
LocoFunctionIconBreak, |
| 114 |
// sound functions |
| 115 |
LocoFunctionIconNoSound = 96, |
| 116 |
LocoFunctionIconSoundGeneral, |
| 117 |
LocoFunctionIconRunning1, |
| 118 |
LocoFunctionIconRunning2, |
| 119 |
LocoFunctionIconEngine1, |
| 120 |
LocoFunctionIconEngine2, |
| 121 |
LocoFunctionIconBreak1, |
| 122 |
LocoFunctionIconBreak2, |
| 123 |
LocoFunctionIconCurve, |
| 124 |
LocoFunctionIconHorn1, |
| 125 |
LocoFunctionIconHorn2, |
| 126 |
LocoFunctionIconWhistle1, |
| 127 |
LocoFunctionIconWhistle2, |
| 128 |
LocoFunctionIconBell, |
| 129 |
LocoFunctionIconStationAnnouncement1, |
| 130 |
LocoFunctionIconStationAnnouncement2, |
| 131 |
LocoFunctionIconStationAnnouncement3, |
| 132 |
LocoFunctionIconSpeak, |
| 133 |
LocoFunctionIconRadio, |
| 134 |
LocoFunctionIconMusic1, |
| 135 |
LocoFunctionIconMusic2, |
| 136 |
LocoFunctionIconOpenDoor, |
| 137 |
LocoFunctionIconCloseDoor, |
| 138 |
LocoFunctionIconFan1, |
| 139 |
LocoFunctionIconFan2, |
| 140 |
LocoFunctionIconFan3, |
| 141 |
LocoFunctionIconShovelCoal, |
| 142 |
LocoFunctionIconCompressedAir, |
| 143 |
LocoFunctionIconReliefValve, |
| 144 |
LocoFunctionIconSteamBlowOut, |
| 145 |
LocoFunctionIconSteamBlow, |
| 146 |
LocoFunctionIconDrainValve, |
| 147 |
LocoFunctionIconShakingRust, |
| 148 |
LocoFunctionIconAirPump, |
| 149 |
LocoFunctionIconWaterPump, |
| 150 |
LocoFunctionIconBufferPush, |
| 151 |
LocoFunctionIconGenerator, |
| 152 |
LocoFunctionIconGearBox, |
| 153 |
LocoFunctionIconGearUp, |
| 154 |
LocoFunctionIconGearDown, |
| 155 |
LocoFunctionIconFillWater, |
| 156 |
LocoFunctionIconFillDiesel, |
| 157 |
LocoFunctionIconFillGas, |
| 158 |
LocoFunctionIconSand, |
| 159 |
LocoFunctionIconRailJoint, |
| 160 |
LocoFunctionIconCoupler, |
| 161 |
LocoFunctionIconPanto, |
| 162 |
LocoFunctionIconMainSwitch, |
| 163 |
LocoFunctionIconSoundLouder, |
| 164 |
LocoFunctionIconSoundLower, |
| 165 |
LocoFunctionIconNoBreak, |
| 166 |
|
| 167 |
MaxLocoFunctionIcons |
| 168 |
}; |
| 169 |
|
| 170 |
typedef uint8_t LocoFunctionTimer; |
| 171 |
|
| 172 |
class LocoFunctionEntry |
| 173 |
{ |
| 174 |
public: |
| 175 |
inline LocoFunctionEntry() |
| 176 |
: nr(0), |
| 177 |
state(LocoFunctionStateOff), |
| 178 |
type(LocoFunctionTypeNone), |
| 179 |
icon(LocoFunctionIconNone), |
| 180 |
timer(0) |
| 181 |
{ |
| 182 |
} |
| 183 |
|
| 184 |
LocoFunctionNr nr; |
| 185 |
LocoFunctionState state; |
| 186 |
LocoFunctionType type; |
| 187 |
LocoFunctionIcon icon; |
| 188 |
LocoFunctionTimer timer; |
| 189 |
}; |
| 190 |
|
| 191 |
class LocoFunctions : private Serializable |
| 192 |
{ |
| 193 |
public: |
| 194 |
LocoFunctions(); |
| 195 |
|
| 196 |
inline LocoFunctions(const std::string& serialized) |
| 197 |
: LocoFunctions() |
| 198 |
{ |
| 199 |
Deserialize(serialized); |
| 200 |
} |
| 201 |
|
| 202 |
inline void SetFunctionState(const LocoFunctionNr nr, const LocoFunctionState state) |
| 203 |
{ |
| 204 |
if (nr >= NumberOfLocoFunctions) |
| 205 |
{ |
| 206 |
return; |
| 207 |
} |
| 208 |
entries[nr].state = state; |
| 209 |
} |
| 210 |
|
| 211 |
inline void SetFunction(const DataModel::LocoFunctionNr nr, |
| 212 |
const DataModel::LocoFunctionType type, |
| 213 |
const DataModel::LocoFunctionIcon icon, |
| 214 |
const DataModel::LocoFunctionTimer timer) |
| 215 |
{ |
| 216 |
if (nr >= NumberOfLocoFunctions) |
| 217 |
{ |
| 218 |
return; |
| 219 |
} |
| 220 |
LocoFunctionEntry& entry = entries[nr]; |
| 221 |
entry.type = type; |
| 222 |
entry.icon = icon; |
| 223 |
entry.timer = timer; |
| 224 |
} |
| 225 |
|
| 226 |
inline void ClearFunction(const DataModel::LocoFunctionNr nr) |
| 227 |
{ |
| 228 |
if (nr >= NumberOfLocoFunctions) |
| 229 |
{ |
| 230 |
return; |
| 231 |
} |
| 232 |
LocoFunctionEntry& entry = entries[nr]; |
| 233 |
entry.state = LocoFunctionStateOff; |
| 234 |
entry.type = LocoFunctionTypeNone; |
| 235 |
entry.icon = LocoFunctionIconNone; |
| 236 |
entry.timer = 0; |
| 237 |
} |
| 238 |
|
| 239 |
void ConfigureFunctions(const std::vector<LocoFunctionEntry>& newEntries); |
| 240 |
|
| 241 |
void SetFunctionStates(const std::vector<LocoFunctionEntry>& newEntries); |
| 242 |
|
| 243 |
inline LocoFunctionState GetFunctionState(const LocoFunctionNr nr) const |
| 244 |
{ |
| 245 |
if (nr >= NumberOfLocoFunctions) |
| 246 |
{ |
| 247 |
return LocoFunctionStateOff; |
| 248 |
} |
| 249 |
return entries[nr].state; |
| 250 |
} |
| 251 |
|
| 252 |
std::vector<LocoFunctionEntry> GetFunctionStates() const; |
| 253 |
|
| 254 |
inline void GetFunctions(LocoFunctionEntry* out) const |
| 255 |
{ |
| 256 |
for (int nr = 0; nr < NumberOfLocoFunctions; ++nr) |
| 257 |
{ |
| 258 |
out[nr] = entries[nr]; |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
std::string Serialize() const override; |
| 263 |
|
| 264 |
bool Deserialize(const std::string& serialized) override; |
| 265 |
|
| 266 |
inline LocoFunctionIcon GetFunctionIcon(const LocoFunctionNr nr) const |
| 267 |
{ |
| 268 |
if (nr >= NumberOfLocoFunctions) |
| 269 |
{ |
| 270 |
return LocoFunctionIconNone; |
| 271 |
} |
| 272 |
return entries[nr].icon; |
| 273 |
} |
| 274 |
|
| 275 |
static std::string GetLocoFunctionIcon(const LocoFunctionNr nr, const LocoFunctionIcon icon); |
| 276 |
|
| 277 |
inline LocoFunctionType GetFunctionType(const LocoFunctionNr nr) const |
| 278 |
{ |
| 279 |
if (nr >= NumberOfLocoFunctions) |
| 280 |
{ |
| 281 |
return LocoFunctionTypeNone; |
| 282 |
} |
| 283 |
return entries[nr].type; |
| 284 |
} |
| 285 |
|
| 286 |
private: |
| 287 |
LocoFunctionEntry entries[NumberOfLocoFunctions]; |
| 288 |
}; |
| 289 |
} // namespace DataModel |