onewire: Add Qt6 support
This commit is contained in:
parent
35abae7683
commit
c73647c20e
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2025, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -29,9 +29,10 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "integrationpluginonewire.h"
|
#include "integrationpluginonewire.h"
|
||||||
#include "integrations/thing.h"
|
|
||||||
#include "plugininfo.h"
|
#include "plugininfo.h"
|
||||||
|
|
||||||
|
#include <integrations/thing.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
@ -591,7 +592,7 @@ void IntegrationPluginOneWire::onOneWireDevicesDiscovered(QList<Owfs::OwfsDevice
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
qDebug(dcOneWire()) << "Unknown Device discovered" << oneWireDevice.type << oneWireDevice.address;
|
qCDebug(dcOneWire()) << "Unknown Device discovered" << oneWireDevice.type << oneWireDevice.address;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2025, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -31,10 +31,11 @@
|
|||||||
#ifndef INTEGRATIONPLUGINONEWIRE_H
|
#ifndef INTEGRATIONPLUGINONEWIRE_H
|
||||||
#define INTEGRATIONPLUGINONEWIRE_H
|
#define INTEGRATIONPLUGINONEWIRE_H
|
||||||
|
|
||||||
#include "plugintimer.h"
|
#include <integrations/integrationplugin.h>
|
||||||
#include "integrations/integrationplugin.h"
|
#include <plugintimer.h>
|
||||||
#include "owfs.h"
|
|
||||||
#include "w1.h"
|
#include <owfs.h>
|
||||||
|
#include <w1.h>
|
||||||
|
|
||||||
#include "extern-plugininfo.h"
|
#include "extern-plugininfo.h"
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
include(../plugins.pri)
|
include(../plugins.pri)
|
||||||
|
|
||||||
TARGET = $$qtLibraryTarget(nymea_integrationpluginonewire)
|
LIBS += -low -lowcapi
|
||||||
|
|
||||||
LIBS += \
|
|
||||||
-low \
|
|
||||||
-lowcapi \
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
integrationpluginonewire.cpp \
|
integrationpluginonewire.cpp \
|
||||||
|
|||||||
@ -29,8 +29,12 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "owfs.h"
|
#include "owfs.h"
|
||||||
|
#include "owcapi.h"
|
||||||
|
|
||||||
#include "extern-plugininfo.h"
|
#include "extern-plugininfo.h"
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
Owfs::Owfs(QObject *parent) :
|
Owfs::Owfs(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
@ -56,7 +60,7 @@ bool Owfs::init(const QByteArray &owfsInitArguments)
|
|||||||
//inifArguments.append("--w1");
|
//inifArguments.append("--w1");
|
||||||
|
|
||||||
if (OW_init(owfsInitArguments) < 0) {
|
if (OW_init(owfsInitArguments) < 0) {
|
||||||
qWarning(dcOneWire()) << "ERROR initialising one wire" << strerror(errno);
|
qCWarning(dcOneWire()) << "ERROR initialising one wire" << strerror(errno);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_path = "/";
|
m_path = "/";
|
||||||
@ -69,10 +73,10 @@ bool Owfs::discoverDevices()
|
|||||||
size_t dirLength ;
|
size_t dirLength ;
|
||||||
|
|
||||||
if (OW_get(m_path, &dirBuffer, &dirLength) < 0) {
|
if (OW_get(m_path, &dirBuffer, &dirLength) < 0) {
|
||||||
qWarning(dcOneWire()) << "DIRECTORY ERROR" << strerror(errno);
|
qCWarning(dcOneWire()) << "DIRECTORY ERROR" << strerror(errno);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
qDebug(dcOneWire()) << "Directory has members" << dirBuffer;
|
qCDebug(dcOneWire()) << "Directory has members" << dirBuffer;
|
||||||
|
|
||||||
QList<QByteArray> dirMembers ;
|
QList<QByteArray> dirMembers ;
|
||||||
dirMembers = QByteArray(dirBuffer, dirLength).split(',');
|
dirMembers = QByteArray(dirBuffer, dirLength).split(',');
|
||||||
@ -95,7 +99,6 @@ bool Owfs::discoverDevices()
|
|||||||
int family = member.split('.').first().toInt(nullptr, 16);
|
int family = member.split('.').first().toInt(nullptr, 16);
|
||||||
if (family != 0) {
|
if (family != 0) {
|
||||||
member.remove(member.indexOf('/'), 1);
|
member.remove(member.indexOf('/'), 1);
|
||||||
QByteArray type;
|
|
||||||
OwfsDevice thing;
|
OwfsDevice thing;
|
||||||
thing.family = family;
|
thing.family = family;
|
||||||
thing.address = member;
|
thing.address = member;
|
||||||
@ -148,10 +151,10 @@ QByteArray Owfs::getValue(const QByteArray &address, const QByteArray &type)
|
|||||||
devicePath.append('\0');
|
devicePath.append('\0');
|
||||||
|
|
||||||
if (OW_get(devicePath, &getBuffer, &getLength) < 0) {
|
if (OW_get(devicePath, &getBuffer, &getLength) < 0) {
|
||||||
qWarning(dcOneWire()) << "ERROR reading" << devicePath << strerror(errno);
|
qCWarning(dcOneWire()) << "ERROR reading" << devicePath << strerror(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug(dcOneWire()) << "Device value" << devicePath << getBuffer;
|
qCDebug(dcOneWire()) << "Device value" << devicePath << getBuffer;
|
||||||
|
|
||||||
QByteArray value = QByteArray(getBuffer, getLength);
|
QByteArray value = QByteArray(getBuffer, getLength);
|
||||||
free(getBuffer);
|
free(getBuffer);
|
||||||
@ -171,21 +174,21 @@ void Owfs::setValue(const QByteArray &address, const QByteArray &type, const QBy
|
|||||||
devicePath.append('\0');
|
devicePath.append('\0');
|
||||||
|
|
||||||
if (OW_put(devicePath, value, value.length()) < 0) {
|
if (OW_put(devicePath, value, value.length()) < 0) {
|
||||||
qWarning(dcOneWire()) << "ERROR reading" << devicePath << strerror(errno);
|
qCWarning(dcOneWire()) << "ERROR reading" << devicePath << strerror(errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double Owfs::getTemperature(const QByteArray &address, bool *ok)
|
double Owfs::getTemperature(const QByteArray &address, bool *ok)
|
||||||
{
|
{
|
||||||
QByteArray temperature = getValue(address, "temperature");
|
QByteArray temperature = getValue(address, "temperature");
|
||||||
qDebug(dcOneWire()) << "Temperature" << temperature << temperature.replace(',','.').toDouble();
|
qCDebug(dcOneWire()) << "Temperature" << temperature << temperature.replace(',','.').toDouble();
|
||||||
return temperature.toDouble(ok);
|
return temperature.toDouble(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Owfs::getHumidity(const QByteArray &address, bool *ok)
|
double Owfs::getHumidity(const QByteArray &address, bool *ok)
|
||||||
{
|
{
|
||||||
QByteArray humidity = getValue(address, "humidity");
|
QByteArray humidity = getValue(address, "humidity");
|
||||||
qDebug(dcOneWire()) << "Humidity" << humidity << humidity.replace(',','.').toDouble();
|
qCDebug(dcOneWire()) << "Humidity" << humidity << humidity.replace(',','.').toDouble();
|
||||||
return humidity.toDouble(ok);
|
return humidity.toDouble(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +229,7 @@ bool Owfs::getSwitchOutput(const QByteArray &address, SwitchChannel channel, boo
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QByteArray state = getValue(address, c);
|
QByteArray state = getValue(address, c);
|
||||||
qDebug(dcOneWire()) << "Switch state" << state.toInt();
|
qCDebug(dcOneWire()) << "Switch state" << state.toInt();
|
||||||
return state.toInt(ok);
|
return state.toInt(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +264,7 @@ bool Owfs::getSwitchInput(const QByteArray &address, SwitchChannel channel, bool
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QByteArray state = getValue(address, c);
|
QByteArray state = getValue(address, c);
|
||||||
qDebug(dcOneWire()) << "Switch state" << state.toInt();
|
qCDebug(dcOneWire()) << "Switch state" << state.toInt();
|
||||||
return state.toInt(ok);
|
return state.toInt(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2025, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -31,8 +31,6 @@
|
|||||||
#ifndef OWFS_H
|
#ifndef OWFS_H
|
||||||
#define OWFS_H
|
#define OWFS_H
|
||||||
|
|
||||||
#include "owcapi.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class Owfs : public QObject
|
class Owfs : public QObject
|
||||||
@ -88,7 +86,7 @@ private:
|
|||||||
void setValue(const QByteArray &address, const QByteArray &deviceType, const QByteArray &value);
|
void setValue(const QByteArray &address, const QByteArray &deviceType, const QByteArray &value);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void devicesDiscovered(QList<OwfsDevice> devices);
|
void devicesDiscovered(QList<Owfs::OwfsDevice> devices);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OWFS_H
|
#endif // OWFS_H
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2025, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -52,7 +52,7 @@ QStringList W1::discoverDevices()
|
|||||||
QFileInfoList list = w1SysFSDir.entryInfoList();
|
QFileInfoList list = w1SysFSDir.entryInfoList();
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
QFileInfo fileInfo = list.at(i);
|
QFileInfo fileInfo = list.at(i);
|
||||||
if(fileInfo.fileName()[2] == '-') {
|
if(fileInfo.fileName().at(2) == '-') {
|
||||||
qCDebug(dcOneWire()) << "Found one wire device" << fileInfo.filePath();
|
qCDebug(dcOneWire()) << "Found one wire device" << fileInfo.filePath();
|
||||||
deviceList.append(fileInfo.fileName());
|
deviceList.append(fileInfo.fileName());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user