Viam C++ SDK current
Loading...
Searching...
No Matches
power_sensor.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <string>
7
8#include <viam/sdk/common/proto_value.hpp>
9#include <viam/sdk/common/utils.hpp>
10#include <viam/sdk/config/resource.hpp>
11
12namespace viam {
13namespace sdk {
14
16
22class PowerSensor : public Component {
23 public:
25 struct voltage {
27 double volts;
29 bool is_ac;
30 };
31
33 struct current {
35 double amperes;
37 bool is_ac;
38 };
39
40 API api() const override;
41
45 return get_voltage({});
46 }
47
51 virtual voltage get_voltage(const ProtoStruct& extra) = 0;
52
56 return get_current({});
57 }
58
62 virtual current get_current(const ProtoStruct& extra) = 0;
63
66 inline double get_power() {
67 return get_power({});
68 }
69
73 virtual double get_power(const ProtoStruct& extra) = 0;
74
77 inline ProtoStruct get_readings() {
78 return get_readings({});
79 }
80
84 virtual ProtoStruct get_readings(const ProtoStruct& extra) = 0;
85
89 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
90
91 protected:
92 explicit PowerSensor(std::string name) : Component(std::move(name)){};
93};
94
95template <>
97 static API api();
98};
99
100bool operator==(const PowerSensor::voltage& lhs, const PowerSensor::voltage& rhs);
101bool operator==(const PowerSensor::current& lhs, const PowerSensor::current& rhs);
102} // namespace sdk
103} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
Definition component.hpp:10
Definition power_sensor.hpp:22
current get_current()
Returns the current reading of this sensor.
Definition power_sensor.hpp:55
API api() const override
Returns the API associated with a particular resource.
virtual current get_current(const ProtoStruct &extra)=0
Returns the current reading of this sensor.
virtual double get_power(const ProtoStruct &extra)=0
Returns the power reading of this sensor.
virtual voltage get_voltage(const ProtoStruct &extra)=0
Returns the voltage reading of this sensor.
double get_power()
Returns the power reading of this sensor.
Definition power_sensor.hpp:66
ProtoStruct get_readings()
Returns the measurements/data specific to this sensor.
Definition power_sensor.hpp:77
virtual ProtoStruct get_readings(const ProtoStruct &extra)=0
Returns the measurements/data specific to this sensor.
voltage get_voltage()
Returns the voltage reading of this sensor.
Definition power_sensor.hpp:44
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
virtual std::string name() const
Return the resource's name.
Definition resource_api.hpp:50
Definition power_sensor.hpp:33
double amperes
Current in amperes.
Definition power_sensor.hpp:35
bool is_ac
Whether the current is DC or AC.
Definition power_sensor.hpp:37
Definition power_sensor.hpp:25
double volts
Voltage in volts.
Definition power_sensor.hpp:27
bool is_ac
Whether the voltage is DC or AC.
Definition power_sensor.hpp:29