Skip to content

Commit 80d0b00

Browse files
committed
Added scoped off
1 parent e916912 commit 80d0b00

7 files changed

Lines changed: 32 additions & 20 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Objective arduino pins like:
66
- `DigitalPulledPin` - pulled input
77
- `DigitalOutputPin` - output
88
- `AnalogInputPin` - analog input
9-
- `ScopedOn` - RAII switch that turns off when out of scope
9+
- `ScopedOn/Off` - RAII switch that turns off/on when out of scope
1010

1111
## Configuration
1212
Library requires c++14 or greater.

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ DigitalPulledPin KEYWORD1
55
DigitalOutputPin KEYWORD1
66
AnalogInputPin KEYWORD1
77
ScopedOn KEYWORD1
8+
ScopedOff KEYWORD1
89

910
# Methods and Functions (KEYWORD2)
1011
on KEYWORD2

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ArduinoPin",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Objective arduino pin",
55
"keywords": "objective, digital, analog, pin",
66
"repository":
@@ -24,7 +24,7 @@
2424
],
2525
"license": "MIT",
2626
"homepage": "https://github.com/vovagorodok/ArduinoPin",
27-
"headers": ["ArduinoPin.h", "DigitalPin.h", "AnalogPin.h", "ScopedOn.h"],
27+
"headers": ["ArduinoPin.h", "DigitalPin.h", "AnalogPin.h", "ScopedSwitch.h"],
2828
"frameworks": "arduino",
2929
"platforms": ["*"]
3030
}

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=vovagorodok_ArduinoPin
2-
version=1.0.0
2+
version=1.1.0
33
author=vovagorodok
44
maintainer=vovagorodok <vovagorodok2@gmail.com>
55
sentence=Objective arduino pin
66
paragraph=Objective arduino pin
77
category=Hardware
88
url=https://github.com/vovagorodok/ArduinoPin
9-
includes=ArduinoPin.h, DigitalPin.h, AnalogPin.h, ScopedOn.h
9+
includes=ArduinoPin.h, DigitalPin.h, AnalogPin.h, ScopedSwitch.h
1010
architectures=*

src/ArduinoPin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#pragma once
22
#include <DigitalPin.h>
33
#include <AnalogPin.h>
4-
#include <ScopedOn.h>
4+
#include <ScopedSwitch.h>

src/ScopedOn.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/ScopedSwitch.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
template <typename T>
4+
class ScopedOn
5+
{
6+
public:
7+
inline ScopedOn(T& sw) : ref(sw)
8+
{ ref.on(); }
9+
inline ~ScopedOn()
10+
{ ref.off(); }
11+
private:
12+
T& ref;
13+
};
14+
15+
template <typename T>
16+
class ScopedOff
17+
{
18+
public:
19+
inline ScopedOff(T& sw) : ref(sw)
20+
{ ref.off(); }
21+
inline ~ScopedOff()
22+
{ ref.on(); }
23+
private:
24+
T& ref;
25+
};

0 commit comments

Comments
 (0)