ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
GPIOPin.hpp
1 /*
2  * Copyright 2021 Marcus Behel
3  *
4  * This file is part of ArPiRobot-CoreLib.
5  *
6  * ArPiRobot-CoreLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * ArPiRobot-CoreLib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with ArPiRobot-CoreLib. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include <arpirobot/core/device/BaseDevice.hpp>
23 #include <arpirobot/core/scheduler.hpp>
24 #include <arpirobot/core/network/MainVmon.hpp>
25 #include <arpirobot/core/io/IoDevice.hpp>
26 
27 namespace arpirobot{
28 
38  class GPIOPin : public BaseDevice, public IoDevice{
39  public:
40  enum class Mode {Input = 0, Output = 1};
41  enum class Level {Low = 0, High = 1};
42 
43  GPIOPin(unsigned int pin);
44 
45  GPIOPin(const GPIOPin &other) = delete;
46 
47  ~GPIOPin();
48 
49  GPIOPin &operator=(const GPIOPin &other) = delete;
50 
51  // Pin configuration
52  void setMode(Mode mode);
53 
54  // Digital logic
55  void setLevel(Level level);
56  Level getLevel();
57 
58  // PWM
59  void setPwmValue(uint8_t val);
60  uint8_t getPwmValue();
61  void setPwmFrequency(unsigned int freq);
62  unsigned int getPwmFrequency();
63 
64  protected:
65  void close() override;
66 
67  void begin() override;
68 
69  bool isEnabled() override;
70 
71  bool shouldMatchRobotState() override;
72 
73  bool shouldDisableWithWatchdog() override;
74 
75  void enable() override;
76 
77  void disable() override;
78 
79  private:
80  unsigned int pin;
81  uint8_t lastPwmValue;
82  };
83 
84 }
Definition: BaseDevice.hpp:35
Definition: GPIOPin.hpp:38
Definition: IoDevice.hpp:27
Definition: ArduinoDevice.hpp:27