Fixed RefCountedDigitalPin.h to release claim correctly to save back 26mA#1569
Conversation
…gative claims number.
|
Hi @IoTThinks ,Thank you for your hard work, but we believe that #1570 is the correct reason. |
|
Ok, let me try yours. If your PR works then I will close this PR as you have clearer picture than I. |
|
Ho this is working? Will this code stay on on Heltec v3 +v4 platforms or this code also will impact my PicoW variant? I don't have OLED display and possibly use this GPIO pin for things... |
@JDat If you don't have OLED, this issue will not happen to you. However, the OLED and sensors need to use claim() and release(). So no impact for you. |
|
I will keep this PR for review. The release() function should work correctly on its own. |
|
LGTM. Nice and clean and a generic fix for other use cases as well. |
src/helpers/RefCountedDigitalPin.h
Outdated
|
|
||
| void release() { | ||
| _claims--; | ||
| if (_claims == 0) { | ||
| digitalWrite(_pin, !_active); | ||
| } else { | ||
| _claims--; |
There was a problem hiding this comment.
Won't this mean that if claims == 1 and you call release(), claims is will end up as 0 but you the pin won't be deactivated until you call release an extra time?
There was a problem hiding this comment.
Haha, true.
Let me adjust.
There was a problem hiding this comment.
@oltaco We can change to this.
This is fix for future vExt usage.
However, it won't fix the OLED. We may need to fix or revert the SSD1306Display as it does not use vExt at all.
See my comment below. #1569 (comment)
void release() {
if (_claims == 0) return; // avoid negative _claims
_claims--;
if (_claims == 0) {
digitalWrite(_pin, !_active);
}
}
|
@oltaco : When I fixed it properly, it does not work anymore. This is in powersaving off. So there is no sleep yet. Don't off the vExt at all and ...save power So we aggressive "off" the vExt, the power is increased at 8x mA So I can guess LOW = vExt off. HIGH = vExt ON, this is correct based on my previously found docs and same to other Heltec boards. To test further, I guess OLED SSD1306 has nothing related to the vExt at all. I can conclude SSD1306Display is not powered by vExt at all. That also explains why MeshCore 1.11.0 worked fine. In MC 1.12.0, we turn on vExt unneccessarily. Please correct me if I'm incorrect somewhere. |
|
So the fix this is one for future usage. Then revert the SSD1306Display.h as it does not use vExt at all. |
|
It works perfect now.
Tested on Heltec v4 with screen.
|

Hi friends,
This is to fix RefCountedDigitalPin.h to release claim correctly and to ensure no negative "claims" number.
Without this, Heltec v4 comsumes extra 26mA in normal mode and in power saving mode when the power to OLED does not cut off in turnOff correctly.
Tested working fine on Heltec v3 and v4.
It should be fine for other boards too.