Skip to content

Commit

Permalink
Added scoped off
Browse files Browse the repository at this point in the history
  • Loading branch information
vovagorodok committed Jun 13, 2024
1 parent e916912 commit 80d0b00
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Objective arduino pins like:
- `DigitalPulledPin` - pulled input
- `DigitalOutputPin` - output
- `AnalogInputPin` - analog input
- `ScopedOn` - RAII switch that turns off when out of scope
- `ScopedOn/Off` - RAII switch that turns off/on when out of scope

## Configuration
Library requires c++14 or greater.
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DigitalPulledPin KEYWORD1
DigitalOutputPin KEYWORD1
AnalogInputPin KEYWORD1
ScopedOn KEYWORD1
ScopedOff KEYWORD1

# Methods and Functions (KEYWORD2)
on KEYWORD2
Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ArduinoPin",
"version": "1.0.0",
"version": "1.1.0",
"description": "Objective arduino pin",
"keywords": "objective, digital, analog, pin",
"repository":
Expand All @@ -24,7 +24,7 @@
],
"license": "MIT",
"homepage": "https://github.com/vovagorodok/ArduinoPin",
"headers": ["ArduinoPin.h", "DigitalPin.h", "AnalogPin.h", "ScopedOn.h"],
"headers": ["ArduinoPin.h", "DigitalPin.h", "AnalogPin.h", "ScopedSwitch.h"],
"frameworks": "arduino",
"platforms": ["*"]
}
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=vovagorodok_ArduinoPin
version=1.0.0
version=1.1.0
author=vovagorodok
maintainer=vovagorodok <[email protected]>
sentence=Objective arduino pin
paragraph=Objective arduino pin
category=Hardware
url=https://github.com/vovagorodok/ArduinoPin
includes=ArduinoPin.h, DigitalPin.h, AnalogPin.h, ScopedOn.h
includes=ArduinoPin.h, DigitalPin.h, AnalogPin.h, ScopedSwitch.h
architectures=*
2 changes: 1 addition & 1 deletion src/ArduinoPin.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#include <DigitalPin.h>
#include <AnalogPin.h>
#include <ScopedOn.h>
#include <ScopedSwitch.h>
14 changes: 0 additions & 14 deletions src/ScopedOn.h

This file was deleted.

25 changes: 25 additions & 0 deletions src/ScopedSwitch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

template <typename T>
class ScopedOn
{
public:
inline ScopedOn(T& sw) : ref(sw)
{ ref.on(); }
inline ~ScopedOn()
{ ref.off(); }
private:
T& ref;
};

template <typename T>
class ScopedOff
{
public:
inline ScopedOff(T& sw) : ref(sw)
{ ref.off(); }
inline ~ScopedOff()
{ ref.on(); }
private:
T& ref;
};

0 comments on commit 80d0b00

Please sign in to comment.