Firmware  0.0.0
Loading...
Searching...
No Matches
loco.hpp
Go to the documentation of this file.
1// Copyright (C) 2025 Vincent Hamp
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16#pragma once
17
18#include <ArduinoJson.h>
19#include <optional>
20#include <string>
21#include <type_traits>
22#include <z21/z21.hpp>
23#include <ztl/string.hpp>
24
25namespace dcc {
26
28struct NvLocoBase : z21::LocoInfo {
29 void fromJsonDocument(JsonDocument const& doc);
30 JsonDocument toJsonDocument() const;
31 std::string name{};
32};
33
35struct Loco : NvLocoBase {
36 void fromJsonDocument(JsonDocument const& doc);
37 JsonDocument toJsonDocument() const;
38
39 static constexpr uint8_t min_priority{1u};
40 static constexpr uint8_t max_priority{smath::pow(2, priority_bits) - 1};
42
44 void print() const {
45 printf("Loco object:\n");
46 printf(" name: %s\n", name.c_str());
47 printf(" functions: " UINT32_TO_BINARY_FORMAT "\n",
48 UINT32_TO_BINARY(f31_0));
49 printf(" dir: %d\n", static_cast<bool>(rvvvvvvv & 0x80u));
50 printf(" speed: %d\n", z21::decode_rvvvvvvv(speed_steps, rvvvvvvv));
51 }
52};
53
54} // namespace dcc
Definition config.hpp:268
constexpr auto priority_bits
Definition config.hpp:270
Actual object with volatile and non-volatile stuff.
Definition loco.hpp:35
void print() const
Definition loco.hpp:44
uint8_t priority
Definition loco.hpp:41
JsonDocument toJsonDocument() const
Definition loco.cpp:56
void fromJsonDocument(JsonDocument const &doc)
Definition loco.cpp:42
static constexpr uint8_t max_priority
Definition loco.hpp:40
static constexpr uint8_t min_priority
Definition loco.hpp:39
Non-volatile base.
Definition loco.hpp:28
std::string name
Definition loco.hpp:31
void fromJsonDocument(JsonDocument const &doc)
Definition loco.cpp:22
JsonDocument toJsonDocument() const
Definition loco.cpp:34