-
Notifications
You must be signed in to change notification settings - Fork 5
/
Device.hh
104 lines (87 loc) · 3.15 KB
/
Device.hh
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
/* Copyright © 2018, Maciej Sopyło <[email protected]>
*
* This file is part of libb6.
*
* libb6 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libb6 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with libb6. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIB_B6_DEMO_B6DEVICE_HH
#define LIB_B6_DEMO_B6DEVICE_HH
#include <string>
#include <vector>
#include <libusb.h>
#include <stdexcept>
#include "Packet.hh"
#include "Enum.hh"
#include "Error.hh"
#define B6_VENDOR_ID 0x0000
#define B6_PRODUCT_ID 0x0001
namespace b6 {
struct SysInfo {
unsigned int cycleTime, timeLimit, capLimit, lowDCLimit, tempLimit, voltage, cells[8];
bool timeLimitOn, capLimitOn, keyBuzzer, systemBuzzer;
};
struct ChargeInfo {
unsigned int state, tempExt, tempInt, capacity, time, voltage, current, impendance, cells[8];
};
struct ChargeProfile {
BATTERY_TYPE batteryType;
uint8_t cellCount, rPeakCount, cycleType, cycleCount;
union {
CHARGING_MODE_LI li;
CHARGING_MODE_NI ni;
CHARGING_MODE_PB pb;
} mode;
uint16_t chargeCurrent, dischargeCurrent, cellDischargeVoltage, endVoltage, trickleCurrent;
};
class Device {
public:
Device();
~Device();
SysInfo getSysInfo();
ChargeInfo getChargeInfo();
std::string getCoreType() { return m_coreType; };
int getUpgradeType() { return m_upgradeType; };
int getLanguageID() { return m_languageID; };
int getCustomerID() { return m_customerID; };
double getHWVersion() { return m_hwVersion; };
double getSWVersion() { return m_swVersion; };
bool isEncrypted() { return m_isEncrypted; };
int getCellCount() { return m_cellCount; };
ChargeProfile getDefaultChargeProfile(BATTERY_TYPE type);
bool setCycleTime(int cycleTime);
bool setTimeLimit(bool enabled, int limit);
bool setCapacityLimit(bool enabled, int limit);
bool setTempLimit(int limit);
bool setBuzzers(bool system, bool key);
void stopCharging();
bool startCharging(ChargeProfile profile);
static bool isBatteryLi(BATTERY_TYPE type) { return type >= BATTERY_TYPE::LIPO && type <= BATTERY_TYPE::LIHV; };
static bool isBatteryNi(BATTERY_TYPE type) { return type == BATTERY_TYPE::NIMH || type == BATTERY_TYPE::NICD; };
private:
libusb_context *m_libusbCtx{};
libusb_device_handle *m_dev;
bool m_hadKernelDriver = false;
int m_cellCount = 6;
std::string m_coreType;
int m_upgradeType{}, m_languageID{}, m_customerID{};
double m_hwVersion{}, m_swVersion{};
bool m_isEncrypted{};
Packet m_read();
void m_write(Packet packet);
Packet m_sendCommand(CMD cmd);
void m_getDevInfo();
ChargingError m_throwError(ERROR err);
};
}
#endif //LIB_B6_DEMO_B6DEVICE_HH