1 #pragma once
2 
3 #include <cstdint>
4 #include <map>
5 #include <stdexcept>
6 #include <string>
7 #include <unordered_map>
8 #include <utility>
9 #include <vector>
10 
11 namespace pid_control
12 {
13 
14 struct 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>
25         operator()(const T& t) const
26     {
27         throw std::invalid_argument("Cannot translate type to double");
28     }
29 };
30 
31 std::string getSensorPath(const std::string& type, const std::string& id);
32 std::string getMatch(const std::string& type, const std::string& id);
33 void scaleSensorReading(const double min, const double max, double& value);
34 bool validType(const std::string& type);
35 
36 bool 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 
40 // Set zone number for a zone, 0-based
41 int64_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.
45 int64_t getZoneIndex(const std::string& name,
46                      std::map<std::string, int64_t>& zones);
47 
48 } // namespace pid_control
49