blob: 420c8fbd686d22866fdd0398094ff3a0c1c2a7ad [file] [log] [blame]
Patrick Ventureaadb30d2020-08-10 09:17:11 -07001#pragma once
2
Patrick Ventureef1f8862020-08-17 09:34:35 -07003#include <stdexcept>
Patrick Venture84c188f2020-08-10 12:39:12 -07004#include <string>
Patrick Venture1a7c49f2020-10-06 15:49:27 -07005#include <unordered_map>
6#include <utility>
7#include <vector>
Patrick Ventureaadb30d2020-08-10 09:17:11 -07008
9namespace pid_control
10{
11
12struct VariantToDoubleVisitor
13{
14 template <typename T>
15 std::enable_if_t<std::is_arithmetic<T>::value, double>
16 operator()(const T& t) const
17 {
18 return static_cast<double>(t);
19 }
20
21 template <typename T>
22 std::enable_if_t<!std::is_arithmetic<T>::value, double>
23 operator()(const T& t) const
24 {
25 throw std::invalid_argument("Cannot translate type to double");
26 }
27};
28
Patrick Venture84c188f2020-08-10 12:39:12 -070029std::string getSensorPath(const std::string& type, const std::string& id);
30std::string getMatch(const std::string& type, const std::string& id);
31void scaleSensorReading(const double min, const double max, double& value);
32bool validType(const std::string& type);
33
Patrick Venture1a7c49f2020-10-06 15:49:27 -070034bool findSensors(const std::unordered_map<std::string, std::string>& sensors,
35 const std::string& search,
36 std::vector<std::pair<std::string, std::string>>& matches);
37
Patrick Ventureaadb30d2020-08-10 09:17:11 -070038} // namespace pid_control