mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* Heltec tracker: new 'periph_power' shared pin (between Display & GPS)
This commit is contained in:
parent
997261a68e
commit
810fc8b8f0
8 changed files with 86 additions and 27 deletions
29
src/helpers/RefCountedDigitalPin.h
Normal file
29
src/helpers/RefCountedDigitalPin.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class RefCountedDigitalPin {
|
||||
uint8_t _pin;
|
||||
int8_t _claims = 0;
|
||||
|
||||
public:
|
||||
RefCountedDigitalPin(uint8_t pin): _pin(pin) { }
|
||||
|
||||
void begin() {
|
||||
pinMode(_pin, OUTPUT);
|
||||
digitalWrite(_pin, LOW); // initial state
|
||||
}
|
||||
|
||||
void claim() {
|
||||
_claims++;
|
||||
if (_claims > 0) {
|
||||
digitalWrite(_pin, HIGH);
|
||||
}
|
||||
}
|
||||
void release() {
|
||||
_claims--;
|
||||
if (_claims == 0) {
|
||||
digitalWrite(_pin, LOW);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue