YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
SensorData.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Yet Another Software Suite
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#pragma once
5
6#include <wpi/hal/Value.h>
7
8#include <functional>
9#include <optional>
10#include <string>
11#include <utility>
12#include <vector>
13#include <wpi/hal/SimDevice.hpp>
14
16
25 public:
27
28 // ---- Constructors -----------------------------------------------------------
29
30 SensorData(std::string name, std::function<HAL_Value()> supplier, HAL_Value defaultValue,
31 HALValueType type);
32 SensorData(std::string name, std::function<double()> supplier, double defaultVal);
33 SensorData(std::string name, std::function<int()> supplier, int defaultVal);
34 SensorData(std::string name, std::function<bool()> supplier, bool defaultVal);
35 SensorData(std::string name, std::function<int64_t()> supplier, int64_t defaultVal);
36
37 // ---- Static converters ------------------------------------------------------
38
39 static HAL_Value Convert(double value);
40 static HAL_Value Convert(int value);
41 static HAL_Value Convert(bool value);
42 static HAL_Value Convert(int64_t value);
43
44 static std::function<HAL_Value()> Convert(std::function<double()> supplier);
45 static std::function<HAL_Value()> Convert(std::function<int()> supplier);
46 static std::function<HAL_Value()> Convert(std::function<bool()> supplier);
47 static std::function<HAL_Value()> Convert(std::function<int64_t()> supplier);
48
49 // ---- Typed getters ----------------------------------------------------------
50
51 double GetAsDouble() const;
52 int GetAsInt() const;
53 bool GetAsBoolean() const;
54 int64_t GetAsLong() const;
55
57 HAL_Value GetValue() const;
58
59 HAL_Value GetDefault() const;
60 std::string GetName() const;
62
63 // ---- Setters ----------------------------------------------------------------
64
65 void Set(HAL_Value val);
66 void Set(double val);
67 void Set(int val);
68 void Set(int64_t val);
69 void Set(bool val);
70
71 // ---- Simulation triggers ----------------------------------------------------
72
74 void AddSimTrigger(HAL_Value value, std::function<bool()> trigger);
75
80 HAL_SimValueHandle CreateValue(HAL_SimDeviceHandle device, int32_t direction);
81
82 private:
83 std::string m_name;
84 std::function<HAL_Value()> m_supplier;
85 HALValueType m_type;
86 HAL_Value m_defaultValue;
87 std::optional<std::vector<std::pair<std::function<bool()>, HAL_Value>>> m_triggerValues;
88 HAL_SimValueHandle m_glassValue{HAL_INVALID_HANDLE};
89 std::optional<HAL_Value> m_prev;
90};
91
92} // namespace yams::motorcontrollers::simulation
static HAL_Value Convert(int64_t value)
void AddSimTrigger(HAL_Value value, std::function< bool()> trigger)
SensorData(std::string name, std::function< HAL_Value()> supplier, HAL_Value defaultValue, HALValueType type)
SensorData(std::string name, std::function< int()> supplier, int defaultVal)
static std::function< HAL_Value()> Convert(std::function< bool()> supplier)
SensorData(std::string name, std::function< double()> supplier, double defaultVal)
SensorData(std::string name, std::function< int64_t()> supplier, int64_t defaultVal)
HALValueType
Definition SensorData.hpp:26
HAL_SimValueHandle CreateValue(HAL_SimDeviceHandle device, int32_t direction)
static std::function< HAL_Value()> Convert(std::function< int()> supplier)
SensorData(std::string name, std::function< bool()> supplier, bool defaultVal)
static std::function< HAL_Value()> Convert(std::function< double()> supplier)
static HAL_Value Convert(double value)
static std::function< HAL_Value()> Convert(std::function< int64_t()> supplier)
Definition SimSensorConfig.hpp:15