IoAbstraction
NegatingIoAbstraction.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 https://www.thecoderscorner.com (Dave Cherry).
3  * This product is licensed under an Apache license, see the LICENSE file in the top-level directory.
4  */
5 #ifndef _NEGATING_IO_ABSTRACTION_
6 #define _NEGATING_IO_ABSTRACTION_
7 
8 #include "BasicIoAbstraction.h"
9 
21 private:
22  IoAbstractionRef delegate;
23 public:
24  NegatingIoAbstraction(IoAbstractionRef toInvert) { delegate = toInvert; }
25 
26  void pinDirection(pinid_t pin, uint8_t mode) override {
27  delegate->pinDirection(pin, mode);
28  }
29 
30  void writeValue(pinid_t pin, uint8_t value) override {
31  delegate->writeValue(pin, !value);
32  }
33 
34  uint8_t readValue(pinid_t pin) override {
35  return !delegate->readValue(pin);
36  }
37 
38  void attachInterrupt(pinid_t pin, RawIntHandler interruptHandler, uint8_t mode) override {
39  delegate->attachInterrupt(pin, interruptHandler, mode);
40  }
41 
42  bool runLoop() override {
43  return delegate->runLoop();
44  }
45 
46  void writePort(pinid_t pin, uint8_t portVal) override {
47  delegate->writePort(pin, ~portVal);
48  }
49 
50  uint8_t readPort(pinid_t pin) override {
51  return ~(delegate->readPort(pin));
52  }
53 };
54 
55 #endif // _NEGATING_IO_ABSTRACTION_
Provides the core IoAbstraction interface and Arduino implementation of that interface.
Definition: BasicIoAbstraction.h:38
virtual void pinDirection(pinid_t pin, uint8_t mode)
virtual void writePort(pinid_t pin, uint8_t portVal)
virtual uint8_t readValue(pinid_t pin)
virtual void writeValue(pinid_t pin, uint8_t value)
virtual void attachInterrupt(pinid_t pin, RawIntHandler interruptHandler, uint8_t mode)
virtual bool runLoop()
Definition: BasicIoAbstraction.h:147
virtual uint8_t readPort(pinid_t pin)
Definition: NegatingIoAbstraction.h:20
void attachInterrupt(pinid_t pin, RawIntHandler interruptHandler, uint8_t mode) override
Definition: NegatingIoAbstraction.h:38
uint8_t readValue(pinid_t pin) override
Definition: NegatingIoAbstraction.h:34
bool runLoop() override
Definition: NegatingIoAbstraction.h:42
void pinDirection(pinid_t pin, uint8_t mode) override
Definition: NegatingIoAbstraction.h:26
void writeValue(pinid_t pin, uint8_t value) override
Definition: NegatingIoAbstraction.h:30
uint8_t readPort(pinid_t pin) override
Definition: NegatingIoAbstraction.h:50
void writePort(pinid_t pin, uint8_t portVal) override
Definition: NegatingIoAbstraction.h:46