Skip to content

Commit 2b59344

Browse files
authored
Update System.cpp
1 parent 8ba09f8 commit 2b59344

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/include/System.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,46 @@ uint8_t System::readTouchpad(uint8_t _pad)
9898
*/
9999
double System::readBattery()
100100
{
101+
pinModeInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, INPUT);
102+
int state = digitalReadInternal(MCP23017_INT_ADDR, mcpRegsInt, 9);
103+
pinModeInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, OUTPUT);
104+
105+
if (state)
106+
{
107+
digitalWriteInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, LOW);
108+
}
109+
else
110+
{
111+
digitalWriteInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, HIGH);
112+
}
113+
/*
101114
#ifdef ARDUINO_ESP32_DEV
102115
digitalWriteInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, LOW);
103116
#else
104117
digitalWriteInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, HIGH);
105118
#endif
119+
*/
106120
delay(1);
107121
int adc = analogRead(35);
122+
if (state)
123+
{
124+
pinModeInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, INPUT);
125+
}
126+
else
127+
{
128+
digitalWriteInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, LOW);
129+
}
130+
131+
132+
133+
/*
134+
108135
#ifdef ARDUINO_ESP32_DEV
109136
digitalWriteInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, HIGH);
110137
#else
111138
digitalWriteInternal(MCP23017_INT_ADDR, mcpRegsInt, 9, LOW);
112139
#endif
140+
*/
113141
// Calculate the voltage using the following formula
114142
// 1.1V is internal ADC reference of ESP32, 3.548133892 is 11dB in linear
115143
// scale (Analog signal is attenuated by 11dB before ESP32 ADC input)

0 commit comments

Comments
 (0)