-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iioutil: created IIOUnitsManager singleton
Signed-off-by: Adrian Suciu <adrian.suciu@analog.com>
- Loading branch information
Showing
6 changed files
with
120 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef IIOUNITS_H | ||
#define IIOUNITS_H | ||
|
||
#include <QString> | ||
#include <QMap> | ||
#include <QObject> | ||
|
||
#include "scopy-iioutil_export.h" | ||
#include <iio.h> | ||
|
||
namespace scopy { | ||
|
||
typedef struct IIOUnit_ | ||
{ | ||
QString name; | ||
QString symbol; | ||
double scale = 1; | ||
} IIOUnit; | ||
|
||
class SCOPY_IIOUTIL_EXPORT IIOUnitsManager : public QObject | ||
{ | ||
Q_OBJECT | ||
protected: | ||
IIOUnitsManager(QObject *parent = nullptr); | ||
~IIOUnitsManager(); | ||
|
||
public: | ||
// singleton | ||
IIOUnitsManager(IIOUnitsManager &other) = delete; | ||
void operator=(const IIOUnitsManager &) = delete; | ||
static IIOUnitsManager *GetInstance(); | ||
|
||
static QMap<iio_chan_type, IIOUnit> iioChannelTypes(); | ||
static QMap<hwmon_chan_type, IIOUnit> hwmonChannelTypes(); | ||
|
||
private: | ||
QMap<iio_chan_type, IIOUnit> _iioChannelTypes(); | ||
QMap<hwmon_chan_type, IIOUnit> _hwmonChannelTypes(); | ||
|
||
private: | ||
static IIOUnitsManager *pinstance_; | ||
QMap<iio_chan_type, IIOUnit> m_iioChannelTypes; | ||
QMap<hwmon_chan_type, IIOUnit> m_hwmonChannelTypes; | ||
}; | ||
|
||
}; // namespace scopy | ||
|
||
#endif // IIOUNITS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <iiounits.h> | ||
#include <QApplication> | ||
|
||
using namespace scopy; | ||
|
||
IIOUnitsManager *IIOUnitsManager::pinstance_{nullptr}; | ||
|
||
IIOUnitsManager::IIOUnitsManager(QObject *parent) | ||
: QObject(parent) | ||
{ | ||
|
||
m_iioChannelTypes = QMap<iio_chan_type, IIOUnit>({ | ||
{IIO_VOLTAGE, {"Voltage", "V", 0.001}}, | ||
{IIO_TEMP, {"Degree Celsius", "°C", 0.001}}, | ||
{IIO_CURRENT, {"Ampere", "A", 0.001}}, | ||
{IIO_PRESSURE, {"Pascal", "Pa", 1000}}, | ||
{IIO_ACCEL, {"Metre per second squared", "m/s2", 1}}, | ||
{IIO_ANGL_VEL, {"Radian per second", "rad/s", 1}}, | ||
{IIO_MAGN, {"Gauss", "Gs", 1}} | ||
/// and others | ||
}); | ||
|
||
m_hwmonChannelTypes = { | ||
{HWMON_VOLTAGE, {"Voltage", "V", 0.001}}, {HWMON_TEMP, {"Degree Celsius", "°C", 0.001}}, | ||
{HWMON_CURRENT, {"Ampere", "A", 0.001}}, {HWMON_POWER, {"Watt", "W", 0.000001}}, | ||
{HWMON_ENERGY, {"Joule", "J", 0.000001}}, {HWMON_FAN, {"Revolution/Min", "RPM", 1}}, | ||
{HWMON_HUMIDITY, {"percent", "%", 0.001}} | ||
/// and others | ||
}; | ||
} | ||
|
||
IIOUnitsManager *IIOUnitsManager::GetInstance() | ||
{ | ||
if(pinstance_ == nullptr) { | ||
pinstance_ = new IIOUnitsManager(QApplication::instance()); // singleton has the app as parent | ||
} | ||
return pinstance_; | ||
} | ||
|
||
QMap<iio_chan_type, IIOUnit> IIOUnitsManager::iioChannelTypes() | ||
{ | ||
return IIOUnitsManager::GetInstance()->_iioChannelTypes(); | ||
} | ||
|
||
QMap<hwmon_chan_type, IIOUnit> IIOUnitsManager::hwmonChannelTypes() | ||
{ | ||
return IIOUnitsManager::GetInstance()->_hwmonChannelTypes(); | ||
} | ||
|
||
IIOUnitsManager::~IIOUnitsManager() {} | ||
|
||
QMap<iio_chan_type, IIOUnit> IIOUnitsManager::_iioChannelTypes() { return m_iioChannelTypes; } | ||
|
||
QMap<hwmon_chan_type, IIOUnit> IIOUnitsManager::_hwmonChannelTypes() { return m_hwmonChannelTypes; } | ||
|
||
#include "moc_iiounits.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters