Treehopper C++ API
Pin.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Treehopper.h"
4 #include <stdint.h>
5 #include <functional>
6 #include "DigitalIn.h"
7 #include "DigitalOut.h"
8 #include "Event.h"
9 #include "SpiChipSelectPin.h"
10 #include "AdcPin.h"
11 
12 using namespace std;
13 
14 namespace Treehopper {
15  class TreehopperUsb;
16 
17  enum class AdcReferenceLevel {
18  VREF_3V3,
19  VREF_1V65,
20  VREF_1V8,
21  VREF_2V4,
23  VREF_3V6
24  };
25 
26  enum class PinMode {
27  Reserved,
33  };
34 
159  class TREEHOPPER_API Pin : public DigitalIn, public AdcPin, public SpiChipSelectPin {
160  friend class TreehopperUsb;
161 
162  public:
164  Pin(TreehopperUsb *board, uint8_t pinNumber);
165 
167  void mode(PinMode value);
168 
170  PinMode mode();
171 
173  void makePushPullOutput() override;
174 
176  void makeDigitalInput() override;
177 
179  void makeAnalogInput();
180 
184  void digitalValue(bool val) override;
185 
187  bool digitalValue() override;
188 
192  void toggleOutput();
193 
195  void referenceLevel(AdcReferenceLevel value);
196 
198  AdcReferenceLevel referenceLevel();
199 
201  double analogValue();
202 
204  double analogVoltage();
205 
207  int adcValue();
208 
211 
214 
217 
218  protected:
219  void SendCommand(uint8_t *data, size_t length);
220 
221  TreehopperUsb *board;
222 
223  int _adcValue;
224  double _analogValue;
225  double _analogVoltage;
226 
227  virtual void updateValue(uint8_t high, uint8_t low);
228 
229  virtual void writeOutputValue() override;
230 
231  PinMode _mode;
232  AdcReferenceLevel _referenceLevel;
233  };
234 }
Provides a simple C#-style observer pattern event queue.
Definition: Event.h:68
AdcReferenceLevel
Definition: Pin.h:17
Definition: AdcPin.h:20
The core class for communicating with Treehopper USB boards.
Definition: TreehopperUsb.h:59
Event< Pin, AnalogValueChangedEventArgs > analogValueChanged
Fires when the analog value (0.0-1.0) changes.
Definition: Pin.h:210
digital input pin abstract class.
Definition: DigitalIn.h:22
Definition: AdcPin.h:3
Event< Pin, AdcValueChangedEventArgs > adcValueChanged
Fires when the ADC value (0-4091) changes.
Definition: Pin.h:216
Definition: SpiChipSelectPin.h:7
PinMode
Definition: Pin.h:26
#define TREEHOPPER_API
Definition: Treehopper.h:17
Event< Pin, AnalogVoltageChangedEventArgs > analogVoltageChanged
Fires when the analog voltage (0.0-3.6) changes.
Definition: Pin.h:213
Built-in I/O pins.
Definition: Pin.h:159