blob: 49ec859fdb66a16283516fbe9e829759228f9370 [file] [log] [blame]
Patrick Ventureaadb30d2020-08-10 09:17:11 -07001#pragma once
2
Patrick Ventureb8cfc642020-10-07 08:30:22 -07003#include <cstdint>
4#include <map>
Patrick Ventureef1f8862020-08-17 09:34:35 -07005#include <stdexcept>
Patrick Venture84c188f2020-08-10 12:39:12 -07006#include <string>
Patrick Venture1a7c49f2020-10-06 15:49:27 -07007#include <unordered_map>
8#include <utility>
9#include <vector>
Patrick Ventureaadb30d2020-08-10 09:17:11 -070010
11namespace pid_control
12{
13
14struct VariantToDoubleVisitor
15{
16 template <typename T>
17 std::enable_if_t<std::is_arithmetic<T>::value, double>
18 operator()(const T& t) const
19 {
20 return static_cast<double>(t);
21 }
22
23 template <typename T>
24 std::enable_if_t<!std::is_arithmetic<T>::value, double>
Harvey.Wua1ae4fa2022-10-28 17:38:35 +080025 operator()([[maybe_unused]] const T& t) const
Patrick Ventureaadb30d2020-08-10 09:17:11 -070026 {
27 throw std::invalid_argument("Cannot translate type to double");
28 }
29};
30
Patrick Venture84c188f2020-08-10 12:39:12 -070031std::string getSensorPath(const std::string& type, const std::string& id);
Harvey.Wuf2efcbb2022-02-09 10:24:30 +080032std::string getMatch(const std::string& path);
Patrick Venture84c188f2020-08-10 12:39:12 -070033void scaleSensorReading(const double min, const double max, double& value);
34bool validType(const std::string& type);
35
Patrick Venture1a7c49f2020-10-06 15:49:27 -070036bool findSensors(const std::unordered_map<std::string, std::string>& sensors,
37 const std::string& search,
38 std::vector<std::pair<std::string, std::string>>& matches);
39
Patrick Ventureb8cfc642020-10-07 08:30:22 -070040// Set zone number for a zone, 0-based
41int64_t setZoneIndex(const std::string& name,
42 std::map<std::string, int64_t>& zones, int64_t index);
43
44// Read zone number for a zone.
45int64_t getZoneIndex(const std::string& name,
46 std::map<std::string, int64_t>& zones);
47
Patrick Ventureaadb30d2020-08-10 09:17:11 -070048} // namespace pid_control