gpio_explorer.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <gpiod.h>
  2. #include <list>
  3. #include <mutex>
  4. // This is a class GPIO explorer that uses the libgpiod library to read the state of a GPIO pin.
  5. class GPIOExplorer
  6. {
  7. public:
  8. GPIOExplorer(const char *chipname, int line_offset);
  9. ~GPIOExplorer();
  10. int setWaitingTime(int nTime){
  11. std::lock_guard<std::mutex> lock(m_mutex);
  12. m_nWaitingTime = nTime;
  13. }
  14. int read();
  15. int monitorRisingEdge();
  16. bool getFailingStatus(int index) {
  17. return FailingStatus & (1 << index);
  18. };
  19. void resetFailingStatus(int index) {
  20. std::lock_guard<std::mutex> lock(m_mutex);
  21. FailingStatus = FailingStatus & ~(1 << index);
  22. }
  23. std::mutex* getMutex(){return &m_mutex;}
  24. bool detectZWave();
  25. void close();
  26. private:
  27. struct gpiod_chip *chip;
  28. struct gpiod_line *line;
  29. std::list<int> m_StatusList;
  30. bool StatusKeep{false};
  31. unsigned char FailingStatus{0x00};
  32. std::mutex m_mutex;
  33. int m_nWaitingTime = 50;
  34. };
  35. extern GPIOExplorer* g_gpioExplorer;