doc, small fixes
This commit is contained in:
@@ -28,25 +28,40 @@
|
||||
#endif
|
||||
|
||||
|
||||
/*! \class PIGPIO
|
||||
* \brief GPIO support
|
||||
*
|
||||
* \section PIGPIO_sec0 Synopsis
|
||||
* This class provide initialize, get/set and watch functions for GPIO.
|
||||
*
|
||||
* Currently supported only \"/sys/class/gpio\" mechanism on Linux.
|
||||
*
|
||||
* This class should be used with \a PIGPIO::instance() singleton.
|
||||
*
|
||||
*
|
||||
*
|
||||
* \section PIGPIO_sec1 API
|
||||
* There are several function to directly read or write pin states.
|
||||
*
|
||||
* Also you can start %PIGPIO as thread to watch pin states and receive
|
||||
* \a pinChanged() event.
|
||||
*
|
||||
*/
|
||||
//! \class PIGPIO pigpio.h
|
||||
//! \~english \section PIGPIO_sec0 Synopsis
|
||||
//! \~russian \section PIGPIO_sec0 Краткий обзор
|
||||
//! \~english
|
||||
//! This class provide initialize, get/set and watch functions for GPIO.
|
||||
//!
|
||||
//! This class should be used with \a PIGPIO::instance() singleton.
|
||||
//!
|
||||
//! Currently supported only "/sys/class/gpio" mechanism on Linux.
|
||||
//!
|
||||
//!
|
||||
//! \~russian
|
||||
//! Этот класс предоставляет инициализацию, установку, чтение и наблюдение
|
||||
//! за GPIO.
|
||||
//!
|
||||
//! Этот класс используется только через синглтон \a PIGPIO::instance().
|
||||
//!
|
||||
//! Сейчас поддерживается только "/sys/class/gpio" для Linux.
|
||||
//!
|
||||
//!
|
||||
//! \~\section PIGPIO_sec1 API
|
||||
//! \~english
|
||||
//! There are several function to directly read or write pin states.
|
||||
//!
|
||||
//! Also you can start %PIGPIO as thread to watch pin states and receive
|
||||
//! \a pinChanged() event.
|
||||
//!
|
||||
//!
|
||||
//! \~russian
|
||||
//! Имеется несколько методов для прямой записи и чтения состояний пинов.
|
||||
//!
|
||||
//! Также можно запустить %PIGPIO как поток для наблюдения за пинами и
|
||||
//! принимать события \a pinChanged().
|
||||
//!
|
||||
|
||||
|
||||
PIGPIO::PIGPIO(): PIThread() {
|
||||
@@ -155,20 +170,26 @@ void PIGPIO::begin() {
|
||||
|
||||
|
||||
void PIGPIO::run() {
|
||||
PIMutexLocker ml(mutex);
|
||||
if (watch_state.isEmpty()) return;
|
||||
PIVector<int> ids = watch_state.keys();
|
||||
for(int i = 0; i < ids.size_s(); i++) {
|
||||
GPIOData & g(gpio_[ids[i]]);
|
||||
if (g.num != -1 && !g.name.isEmpty()) {
|
||||
bool v = getPinState(g.num);
|
||||
//piCoutObj << "*** pin state ***" << ids[i] << "=" << v;
|
||||
if (watch_state[g.num] != v) {
|
||||
watch_state[g.num] = v;
|
||||
pinChanged(g.num, v);
|
||||
}
|
||||
mutex.lock();
|
||||
if (watch_state.isEmpty()) {
|
||||
mutex.unlock();
|
||||
return;
|
||||
}
|
||||
PIVector<PIPair<int, bool>> changed;
|
||||
auto it = watch_state.makeIterator();
|
||||
while (it.next()) {
|
||||
GPIOData & g(gpio_[it.key()]);
|
||||
if (g.num == -1 || g.name.isEmpty()) continue;
|
||||
bool v = getPinState(g.num);
|
||||
//piCoutObj << "*** pin state ***" << ids[i] << "=" << v;
|
||||
if (watch_state[g.num] != v) {
|
||||
watch_state[g.num] = v;
|
||||
changed.push_back({g.num, v});
|
||||
}
|
||||
}
|
||||
mutex.unlock();
|
||||
for (const auto & i: changed)
|
||||
pinChanged(i.first, i.second);
|
||||
}
|
||||
|
||||
|
||||
@@ -233,6 +254,14 @@ bool PIGPIO::pinState(int gpio_num) {
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! This function doesn`t affect thread state!
|
||||
//! Pins watching starts only with \a PIThread::start() function
|
||||
//!
|
||||
//! \~russian
|
||||
//! Этот метод не меняет состояние потока наблюдения!
|
||||
//! Наблюдение за пинами начинается методом \a PIThread::start()
|
||||
void PIGPIO::pinBeginWatch(int gpio_num) {
|
||||
PIMutexLocker ml(mutex);
|
||||
GPIOData & g(gpio_[gpio_num]);
|
||||
@@ -246,12 +275,28 @@ void PIGPIO::pinBeginWatch(int gpio_num) {
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! This function doesn`t affect thread state!
|
||||
//! Pins watching starts only with \a PIThread::start() function
|
||||
//!
|
||||
//! \~russian
|
||||
//! Этот метод не меняет состояние потока наблюдения!
|
||||
//! Наблюдение за пинами начинается методом \a PIThread::start()
|
||||
void PIGPIO::pinEndWatch(int gpio_num) {
|
||||
PIMutexLocker ml(mutex);
|
||||
watch_state.remove(gpio_num);
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~english
|
||||
//! This function doesn`t affect thread state!
|
||||
//! Pins watching starts only with \a PIThread::start() function
|
||||
//!
|
||||
//! \~russian
|
||||
//! Этот метод не меняет состояние потока наблюдения!
|
||||
//! Наблюдение за пинами начинается методом \a PIThread::start()
|
||||
void PIGPIO::clearWatch() {
|
||||
PIMutexLocker ml(mutex);
|
||||
watch_state.clear();
|
||||
@@ -259,5 +304,5 @@ void PIGPIO::clearWatch() {
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic pop
|
||||
//# pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user