-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattery.h
92 lines (79 loc) · 2.51 KB
/
battery.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
/*
* Copyright 2022 Dennis Vesterlund
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef BATTERY_H
#define BATTERY_H
#include <stdlib.h>
#include <stdbool.h>
#define BAT_PATH "/sys/class/power_supply"
// For testing TODO remove when user can specify path.
//#define BAT_PATH "/tmp/battest"
#define BAT_PREFIX "BAT"
#define BAT_PREFIX_LEN 3
// Battery files
#define BAT_CAPACITY "capacity"
#define BAT_CYCLE_COUNT "cycle_count"
#define BAT_ENERGY_FULL "energy_full"
#define BAT_ENERGY_FULL_DESIGN "energy_full_design"
#define BAT_ENERGY_NOW "energy_now"
#define BAT_POWER_NOW "power_now"
#define BAT_VOLTAGE_MIN_DESIGN "voltage_min_design"
#define BAT_VOLTAGE_NOW "voltage_now"
#define BAT_MANUFACTURER "manufacturer"
#define BAT_MODEL_NAME "model_name"
#define BAT_SERIAL_NUMBER "serial_number"
#define BAT_TECHNOLOGY "technology"
#define BAT_TYPE "type"
#define BAT_STATUS "status"
#define BAT_STR_SIZE 255
typedef struct battery {
bool present;
int capacity;
long cycle_count;
long energy_full;
long energy_full_design;
long energy_now;
long power_now;
long voltage_min_design;
long voltage_now;
char *name;
char *path;
char *manufacturer;
size_t manufacturer_len;
char *model_name;
size_t model_name_len;
char *serial_number;
size_t serial_number_len;
char *technology;
size_t technology_len;
char *type;
size_t type_len;
char *status;
size_t status_len;
} battery;
typedef struct batteries {
int num_batteries;
struct battery **batteries;
} batteries;
struct batteries *get_batteries();
struct battery *initiate_battery(char *name);
void get_battery(struct battery *battery);
static int get_int(char *path, char *filename);
static long get_long(char *path, char *filename);
static size_t get_str(char *buf, size_t len, char *path, char *filename);
void free_batteries(struct batteries * batteries);
void free_battery(struct battery * battery);
#endif // BATTERY_H