Treehopper C++ API
HardwareUart.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Uart.h"
4 #include "OneWire.h"
5 
6 namespace Treehopper {
7 
8  enum class UartMode {
9 
13  Uart,
14 
18  OneWire
19  };
20 
21  class TreehopperUsb;
22 
53  class HardwareUart : public Uart, OneWire {
54  public:
55  void startOneWire() override;
56 
57  void oneWireResetAndMatchAddress(uint64_t address) override;
58 
59  std::vector<uint64_t> oneWireSearch() override;
60 
61  bool oneWireReset() override;
62 
63  std::vector<uint8_t> receive(int numBytes) override;
64 
65  void send(std::vector<uint8_t> dataToSend) override;
66 
67  void send(uint8_t dataToSend) override;
68 
69  void startUart() override;
70 
71  std::vector<uint8_t> receive() override;
72 
73  void baud(int baud) override;
74 
75  int baud() override;
76 
78  void mode(UartMode mode);
79 
81  UartMode mode();
82 
84  void enabled(bool enabled);
85 
86  bool enabled();
87 
88 
89  private:
90  void updateConfig();
91  TreehopperUsb &_device;
92  bool _enabled = false;
93  int _baud = 9600;
94  UartMode _mode = UartMode::Uart;
95  bool _useOpenDrainTx = false;
96 
97  enum class UartConfig
98  {
99  Disabled,
100  Standard,
101  OneWire
102  };
103 
104  enum class UartCommand
105  {
106  Transmit,
107  Receive,
108  OneWireReset,
109  OneWireScan
110  };
111  };
112 }
Built-in UART peripheral.
Definition: HardwareUart.h:53
UartMode mode()
gets the UartMode of the UART peripheral
void send(std::vector< uint8_t > dataToSend) override
Send data
void startUart() override
Start the UART with the specified baud
std::vector< uint8_t > receive() override
Receive bytes from the UART in UART mode
std::vector< uint64_t > oneWireSearch() override
Search the One Wire bus and return a vector of addresses found.
int baud() override
Gets the baud of the UART.
void startOneWire() override
Start one wire mode.
bool oneWireReset() override
Reset the One Wire bus
void oneWireResetAndMatchAddress(uint64_t address) override
Reset the One Wire bus and address the specified device.
Definition: OneWire.h:7
The core class for communicating with Treehopper USB boards.
Definition: TreehopperUsb.h:59
The module is operating in UART mode.
Definition: Uart.h:8
Definition: AdcPin.h:3
UartMode
Definition: HardwareUart.h:8