163 lines
3.6 KiB
C++
163 lines
3.6 KiB
C++
/***************************************************************************
|
|
|
|
source::worx PiGPIO
|
|
Copyright © 2022 c.holzheuer
|
|
chris@sourceworx.org
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
#ifndef SWPIGPIO_H
|
|
#define SWPIGPIO_H
|
|
|
|
#include <QObject>
|
|
|
|
class PiGPIOFactory;
|
|
class PiGPIOLinFactory;
|
|
class PiGPIOWinFactory;
|
|
class PiGPIOWidget;
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
// Fake4Win
|
|
typedef void (*CBFuncEx_t)( int pi, unsigned user_gpio, unsigned level, uint32_t tick, void * userdata );
|
|
|
|
extern int PI_INPUT;
|
|
extern int PI_PUD_UP;
|
|
extern int EITHER_EDGE;
|
|
extern int PI_TIMEOUT;
|
|
//int PI_TIMEOUT = 42;
|
|
|
|
extern int set_mode(int,int,int);
|
|
extern int set_pull_up_down(int,int,int);
|
|
extern int set_glitch_filter(int,int,int);
|
|
extern int callback_cancel(int);
|
|
extern int callback_ex(int,unsigned,int,CBFuncEx_t,void*);
|
|
extern int gpio_read(int,int);
|
|
|
|
#endif //Q_OS_WIN
|
|
|
|
|
|
/**
|
|
* @brief @brief Prototypische Implementierung eines Wrappers für die 'pigpiod' library.
|
|
*/
|
|
|
|
class PiGPIO
|
|
{
|
|
|
|
public:
|
|
|
|
static PiGPIO& Instance()
|
|
{
|
|
static PiGPIO _Instance; // Guaranteed to be destroyed.
|
|
return _Instance; // Instantiated on first use.
|
|
}
|
|
|
|
|
|
PiGPIO( PiGPIO const& ) = delete;
|
|
void operator=(PiGPIO const&) = delete;
|
|
|
|
~PiGPIO();
|
|
|
|
int PI;
|
|
|
|
private:
|
|
|
|
PiGPIO();
|
|
|
|
bool _initCalled = false;
|
|
|
|
};
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
+---------+ +---------+ 0
|
|
| | | |
|
|
A | | | |
|
|
| | | |
|
|
+---------+ +---------+ +----- 1
|
|
|
|
+---------+ +---------+ 0
|
|
| | | |
|
|
B | | | |
|
|
| | | |
|
|
----+ +---------+ +---------+ 1
|
|
|
|
*/
|
|
|
|
/**
|
|
* @brief Implentiert die Anbindung eines RotaryDials (Dreh-Drück Regler)
|
|
* an die Benutzeroberfläche
|
|
*
|
|
* Version über den 'pigpiod' _ohne_ direkten Hardwarezugriff (welcher root-Rechte
|
|
* benötigen würde)
|
|
*/
|
|
|
|
class PiGRotaryDial : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit PiGRotaryDial( unsigned dialA, unsigned dialB, unsigned button, QObject* parent = nullptr );
|
|
virtual ~PiGRotaryDial();
|
|
void setGlitchFilter( int glitch );
|
|
|
|
signals:
|
|
|
|
void clicked();
|
|
void deltaChanged( int value );
|
|
|
|
protected:
|
|
|
|
void pulse( unsigned gpio, unsigned level );
|
|
void handleClick( unsigned level );
|
|
//void handlePulse( int value );
|
|
|
|
// Need a static callback to link with C.
|
|
static void PiGPIOPulse( int Pi, unsigned gpio, unsigned level, uint32_t tick, void *user );
|
|
|
|
/*
|
|
constexpr const static int Transits[16]=
|
|
{
|
|
// 0000 0001 0010 0011 0100 0101 0110 0111
|
|
0, -1, 1, 0, 1, 0, 0, -1,
|
|
// 1000 1001 1010 1011 1100 1101 1110 1111
|
|
-1, 0, 0, 1, 0, 1, -1, 0
|
|
};
|
|
*/
|
|
|
|
|
|
int _Pi = -1;
|
|
unsigned _dialA = -1;
|
|
unsigned _dialB = -1;
|
|
unsigned _button = -1;
|
|
int _callbackIdA = -1;
|
|
int _callbackIdB = -1;
|
|
int _callbackIdC = -1;
|
|
int _levA = -1;
|
|
int _levB = -1;
|
|
int _oldState = -1;
|
|
int _glitch = -1;
|
|
int _step = 0;
|
|
int _oldStep = 0;
|
|
|
|
bool _pressed = false;
|
|
|
|
|
|
};
|
|
|
|
|
|
#endif // SWPIGPIO_H
|