| 1 | /* |
| 2 | * |
| 3 | */ |
| 4 | |
| 5 | #ifndef RF24_UTILITY_PIGPIO_GPIO_H_ |
| 6 | #define RF24_UTILITY_PIGPIO_GPIO_H_ |
| 7 | |
| 8 | #include <stdexcept> |
| 9 | |
| 10 | /** Specific exception for GPIO errors */ |
| 11 | class GPIOException : public std::runtime_error |
| 12 | { |
| 13 | public: |
| 14 | explicit GPIOException(const std::string& msg) |
| 15 | : std::runtime_error(msg) |
| 16 | { |
| 17 | } |
| 18 | }; |
| 19 | |
| 20 | class GPIO |
| 21 | { |
| 22 | public: |
| 23 | /* Constants */ |
| 24 | static const int DIRECTION_OUT = 1; |
| 25 | static const int DIRECTION_IN = 0; |
| 26 | |
| 27 | static const int OUTPUT_HIGH = 1; |
| 28 | static const int OUTPUT_LOW = 0; |
| 29 | |
| 30 | GPIO(); |
| 31 | |
| 32 | /** |
| 33 | * Similar to Arduino pinMode(pin,mode); |
| 34 | * @param port |
| 35 | * @param DDR |
| 36 | */ |
| 37 | static void open(int port, int DDR); |
| 38 | |
| 39 | /** |
| 40 | * |
| 41 | * @param port |
| 42 | */ |
| 43 | static void close(int port); |
| 44 | |
| 45 | /** |
| 46 | * Similar to Arduino digitalRead(pin); |
| 47 | * @param port |
| 48 | */ |
| 49 | static int read(int port); |
| 50 | |
| 51 | /** |
| 52 | * Similar to Arduino digitalWrite(pin,state); |
| 53 | * @param port |
| 54 | * @param value |
| 55 | */ |
| 56 | static void write(int port, int value); |
| 57 | |
| 58 | virtual ~GPIO(); |
| 59 | |
| 60 | private: |
| 61 | }; |
| 62 | |
| 63 | #endif /* RF24_UTILITY_PIGPIO_GPIO_H_ */ |