-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower_supply.h
138 lines (110 loc) · 2.28 KB
/
power_supply.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//SPDX-License-Identifier: GPL-2.0-or-later
/*
Copyright (C) 2022 Cyril Hrubis <[email protected]>
*/
#ifndef POWER_SUPPLY_H
#define POWER_SUPPLY_H
#include <stdint.h>
enum ps_type {
PS_UNKNOWN = 0x00,
PS_BATTERY = 0x01,
PS_UPS = 0x02,
PS_USB = 0x04,
PS_MAINS = 0x08,
PS_WIRELESS = 0x10,
};
enum ps_bat_status {
PS_BAT_UNKNOWN,
PS_BAT_CHARGING,
PS_BAT_DISCHARGING,
PS_BAT_NOT_CHARGING,
PS_BAT_FULL,
};
enum ps_bat_energy_type {
/* state_* is in uAh */
PS_BAT_CHARGE = 0x00,
/* state_* is in uWh */
PS_BAT_ENERGY = 0x01,
};
struct ps_bat {
/* enum ps_bat_status */
uint8_t status;
/* enum ps_bat_energy_type */
uint8_t state_type;
/* internal, do not touch */
uint8_t idx;
/* in uV */
uint32_t voltage_now;
uint32_t voltage_avg;
/* in uA */
uint32_t current_now;
uint32_t current_avg;
/* in uW */
uint32_t power_now;
uint32_t power_avg;
/* in uWh or uAh depends on state_type */
uint32_t state_now;
uint32_t state_full;
uint32_t state_design;
/* battery cycles set to 0 if not available */
uint32_t cycle_count;
/* Technology */
char technology[16];
};
struct ps_mains {
uint8_t online;
};
struct ps {
enum ps_type type;
struct ps *next;
int dir_fd;
union {
struct ps_bat bat;
struct ps_mains mains;
};
char id[];
};
struct ps *ps_init(enum ps_type type_filter);
const char *ps_bat_status_name(enum ps_bat_status status);
static inline const char *ps_bat_state_unit(struct ps *ps)
{
if (ps->bat.state_type == PS_BAT_CHARGE)
return "Ah";
return "Wh";
}
/**
* @brief returns current time estimate to charge/discharge battery
*
* Uses power_now low pass, which needs some time to stabilize.
*
* @return Remaining time in seconds.
*/
uint32_t ps_bat_sec_rem(struct ps *ps);
/**
* @brief Returns average current.
*
* @return Average current in uA.
*/
uint32_t ps_bat_current_avg(struct ps *ps);
/**
* @brief Returns current.
*
* @return Current in uA.
*/
uint32_t ps_bat_current_now(struct ps *ps);
/**
* @brief Returns average power.
*
* @return Average power in uW.
*/
uint32_t ps_bat_power_avg(struct ps *ps);
/**
* @brief Returns power.
*
* @return Power in uW.
*/
uint32_t ps_bat_power_now(struct ps *ps);
void ps_print(struct ps *root);
void ps_refresh(struct ps *root);
void ps_exit(struct ps *root);
#endif /* POWER_SUPPLY_H */