Some checks failed
Build and deploy Docs site to GitHub Pages / github-pages (push) Has been cancelled
PR Build Check / build (Heltec_v3_companion_radio_ble) (push) Has been cancelled
PR Build Check / build (Heltec_v3_repeater) (push) Has been cancelled
PR Build Check / build (Heltec_v3_room_server) (push) Has been cancelled
PR Build Check / build (LilyGo_Tlora_C6_repeater_) (push) Has been cancelled
PR Build Check / build (PicoW_repeater) (push) Has been cancelled
PR Build Check / build (RAK_4631_companion_radio_ble) (push) Has been cancelled
PR Build Check / build (RAK_4631_repeater) (push) Has been cancelled
PR Build Check / build (RAK_4631_room_server) (push) Has been cancelled
PR Build Check / build (wio-e5-mini_repeater) (push) Has been cancelled
- MeshCore-based Simple Sensor firmware - Heltec T114 without display - BME280 sensor support (temp/humidity/pressure) - Radio: 868.856018 MHz, SF7, BW62.5 kHz, CR4/7 - 2-byte path hash - PlatformIO project
33 lines
589 B
C++
33 lines
589 B
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
|
|
class RefCountedDigitalPin {
|
|
uint8_t _pin;
|
|
int8_t _claims = 0;
|
|
uint8_t _active = 0;
|
|
public:
|
|
RefCountedDigitalPin(uint8_t pin,uint8_t active=HIGH): _pin(pin), _active(active) { }
|
|
|
|
void begin() {
|
|
pinMode(_pin, OUTPUT);
|
|
digitalWrite(_pin, !_active); // initial state
|
|
}
|
|
|
|
void claim() {
|
|
_claims++;
|
|
if (_claims > 0) {
|
|
digitalWrite(_pin, _active);
|
|
}
|
|
}
|
|
|
|
void release() {
|
|
if (_claims == 0) return; // avoid negative _claims
|
|
|
|
_claims--;
|
|
if (_claims == 0) {
|
|
digitalWrite(_pin, !_active);
|
|
}
|
|
}
|
|
};
|