Treehopper C++ API
DigitalIn.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Treehopper.h"
4 #include <functional>
5 #include <vector>
6 #include "Event.h"
7 
8 namespace Treehopper {
9  using namespace std;
10 
11  class DigitalIn;
12 
14  public:
15  bool newValue;
16  };
17 
23  public:
24  DigitalIn() : digitalValueChanged(*this) {}
25 
28 
31  virtual void makeDigitalInput() = 0;
32 
35  virtual bool digitalValue() {
36  return _digitalValue;
37  }
38 
39  protected:
40  bool _digitalValue;
41 
42  virtual void update(bool newValue) {
43  if (newValue == _digitalValue) return;
44 
45  _digitalValue = newValue;
47  args.newValue = newValue;
48  digitalValueChanged.invoke(args);
49  }
50  };
51 }
Definition: DigitalIn.h:13
Provides a simple C#-style observer pattern event queue.
Definition: Event.h:68
virtual bool digitalValue()
Get the digital value.
Definition: DigitalIn.h:35
DigitalIn()
Definition: DigitalIn.h:24
bool newValue
Definition: DigitalIn.h:15
digital input pin abstract class.
Definition: DigitalIn.h:22
Definition: AdcPin.h:3
Event< DigitalIn, PinChangedEventArgs > digitalValueChanged
Fires whenever the digital input changes.
Definition: DigitalIn.h:27
#define TREEHOPPER_API
Definition: Treehopper.h:17