NDEVR
API Documentation
Battery.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Hardware
28File: Battery
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Device.h>
34#include <QObject>
35namespace NDEVR
36{
37 class Log;
38 class JSONNode;
51
60
63 struct HARDWARE_API BatteryCapacityInfo
64 {
65 fltp04 current_level = Constant<fltp04>::Invalid;
66 fltp04 max_level = Constant<fltp04>::Invalid;
67 fltp04 discharge_rate = Constant<fltp04>::Invalid;
68 fltp04 warning_level = Constant<fltp04>::Invalid;
69 fltp04 critical_level = Constant<fltp04>::Invalid;
70 fltp04 shutdown_level = Constant<fltp04>::Invalid;
71
76 void toJSONNode(JSONNode& node) const;
81 void fromJSONNode(const JSONNode& node);
87 bool operator!=(const BatteryCapacityInfo& info) const;
97 fltp04 percent() const;
98 };
99
105 class HARDWARE_API Battery : public Device
106 {
107 Q_OBJECT
108 public:
115 Battery(const Model& name, LogPtr log, QObject* parent = nullptr);
120 [[nodiscard]] fltp04 percent() const;
144 virtual void setBatteryLevel(BatteryCapacityType type, fltp04 value, bool update_state = true);
155 void showWarning(const TranslatedString& warning) const override;
160 bool isCharging() const;
165 void setIsCharging(bool is_charging);
175 virtual void forceBatteryState(const BatteryState& state);
180 [[nodiscard]] virtual BatteryState batteryState() const;
185 [[nodiscard]] virtual BatteryState batteryGroupState() const;
186 signals:
195 void batteryGroupStateChangedSignal(bool originator);
196 protected:
204 };
205}
virtual fltp04 batteryLevel(BatteryCapacityType type) const
Returns the current battery level for a given capacity type.
virtual void forceBatteryState(const BatteryState &state)
Forces the battery into a specific state, overriding automatic state determination.
Vector< 3, BatteryCapacityInfo > m_capacity_info
Capacity info indexed by BatteryCapacityType.
Definition Battery.h:198
virtual BatteryState batteryState() const
Returns the current state of this individual battery.
virtual void autoUpdateBatteryState(BatteryCapacityType mode)
Re-evaluates the battery state based on the current level and thresholds for the given mode.
BatteryState m_bat_state
Current state of this individual battery.
Definition Battery.h:200
virtual void setBatteryLevel(BatteryCapacityType type, fltp04 value, bool update_state=true)
Sets the current battery level for a given capacity type.
Buffer< Battery * > m_battery_group_members
Other batteries in this battery's group.
Definition Battery.h:197
BatteryState m_bat_group_state
Aggregate state of the battery group.
Definition Battery.h:201
void setCapacityInfo(BatteryCapacityType type, const BatteryCapacityInfo &info)
Sets the capacity info for a given capacity type.
bool m_is_charging
Whether the battery is currently charging.
Definition Battery.h:203
BatteryState m_forced_bat_state
Manually forced state, if any.
Definition Battery.h:202
fltp04 percent() const
Returns the battery charge as a percentage, using the best available capacity type.
void addBatteryGroupMember(Battery *battery)
Adds another Battery to this battery's group for aggregate state tracking.
void showWarning(const TranslatedString &warning) const override
Displays a warning message associated with this battery device.
void batteryStateChangedSignal()
Emitted when this battery's state changes.
void setIsCharging(bool is_charging)
Sets whether the battery is currently charging.
Time m_last_state_stable_time
Timestamp of the last stable state transition.
Definition Battery.h:199
bool isCharging() const
Checks whether the battery is currently charging.
Battery(const Model &name, LogPtr log, QObject *parent=nullptr)
Constructs a Battery device.
virtual BatteryState batteryGroupState() const
Returns the worst state among all batteries in this battery's group.
BatteryCapacityInfo capacityInfo(BatteryCapacityType type) const
Returns the capacity info for a given capacity type.
void batteryGroupStateChangedSignal(bool originator)
Emitted when the aggregate battery group state changes.
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
Device(const Model &model, LogPtr log, QObject *parent=nullptr)
Constructs a Device from a Model with the given log and optional Qt parent.
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:149
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Serves as the primary program interface for processes to report issues and allows any number of LogSt...
Definition Log.h:50
A core class that represents a node on model hierarchy.
Definition Model.h:292
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
BatteryState
An indication of what state a Battery object is in.
Definition Battery.h:43
@ e_shutdown_voltage
Battery voltage is at or below the shutdown threshold.
Definition Battery.h:48
@ e_no_battery
No battery is present.
Definition Battery.h:44
@ e_critical_voltage
Battery voltage has reached a critical level.
Definition Battery.h:47
@ e_low_voltage
Battery voltage has dropped below the warning threshold.
Definition Battery.h:46
@ e_invalid
No fix available or fix is invalid.
Definition GPSPoint.h:17
BatteryCapacityType
The various types of capacity information a Battery may have.
Definition Battery.h:55
@ e_watt_hours
Capacity expressed in watt-hours.
Definition Battery.h:57
@ e_voltage
Capacity expressed as a raw voltage reading.
Definition Battery.h:58
@ e_percentage
Capacity expressed as a percentage of full charge.
Definition Battery.h:56
@ e_normal
Normal map channel for per-pixel lighting.
For a given BatteryCapacityType, the limits that define the state of the battery.
Definition Battery.h:64
void fromJSONNode(const JSONNode &node)
Deserializes capacity info from a JSON node.
bool operator!=(const BatteryCapacityInfo &info) const
Inequality comparison operator.
fltp04 percent() const
Computes the capacity as a percentage of the maximum level.
fltp04 max_level
The maximum capacity level when fully charged.
Definition Battery.h:66
fltp04 shutdown_level
The threshold at or below which the device should shut down.
Definition Battery.h:70
fltp04 critical_level
The threshold at which the battery state becomes critical.
Definition Battery.h:69
void toJSONNode(JSONNode &node) const
Serializes this capacity info into a JSON node.
fltp04 current_level
The current capacity level.
Definition Battery.h:65
bool canChangeBatteryState() const
Checks whether this capacity info has enough valid data to determine battery state.
fltp04 discharge_rate
The rate at which capacity is being consumed.
Definition Battery.h:67
fltp04 warning_level
The threshold at which a low-battery warning is issued.
Definition Battery.h:68