Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit50b70ac

Browse files
committed
feat: nesso_n1: enable battery
only charging for now
1 parent3faa73a commit50b70ac

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

‎variants/arduino_nesso_n1/expander.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,37 @@ int digitalRead(ExpanderPin pin) {
8585
returnreadBitRegister(pin.address,0xF, pin.pin);
8686
}
8787

88+
voidNessoBattery::enableCharge() {
89+
// AW32001E - address 0x49
90+
// set CEB bit low (charge enable)
91+
if (!wireInitialized) {
92+
WireInternal.begin(SDA, SCL);
93+
wireInitialized =true;
94+
}
95+
writeBitRegister(0x49,0x1,3,false);
96+
}
97+
98+
floatNessoBattery::getVoltage() {
99+
// BQ27220 - address 0x55
100+
if (!wireInitialized) {
101+
WireInternal.begin(SDA, SCL);
102+
wireInitialized =true;
103+
}
104+
uint16_t voltage = (readRegister(0x55,0x9) <<8) |readRegister(0x55,0x8);
105+
return (float)voltage /1000.0f;
106+
}
107+
108+
uint16_tNessoBattery::getChargeLevel() {
109+
// BQ27220 - address 0x55
110+
if (!wireInitialized) {
111+
WireInternal.begin(SDA, SCL);
112+
wireInitialized =true;
113+
}
114+
uint16_t current_capacity =readRegister(0x55,0x11) <<8 |readRegister(0x55,0x10);
115+
uint16_t total_capacity =readRegister(0x55,0x13) <<8 |readRegister(0x55,0x12);
116+
return (current_capacity *100) / total_capacity;
117+
}
118+
88119
ExpanderPinLORA_LNA_ENABLE(5);
89120
ExpanderPinLORA_ANTENNA_SWITCH(6);
90121
ExpanderPinLORA_ENABLE(7);

‎variants/arduino_nesso_n1/pins_arduino.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class ExpanderPin {
4949
uint8_t address;
5050
};
5151

52+
classNessoBattery {
53+
public:
54+
NessoBattery() {};
55+
voidenableCharge();// enable charging
56+
floatgetVoltage();// get battery voltage in Volts
57+
uint16_tgetChargeLevel();// get battery charge level in percents
58+
};
59+
5260
extern ExpanderPin LORA_LNA_ENABLE;
5361
extern ExpanderPin LORA_ANTENNA_SWITCH;
5462
extern ExpanderPin LORA_ENABLE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp