onewire: Add Qt6 support

master
Simon Stürz 2025-08-08 15:36:13 +02:00
parent 35abae7683
commit c73647c20e
6 changed files with 29 additions and 30 deletions

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -29,9 +29,10 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "integrationpluginonewire.h"
#include "integrations/thing.h"
#include "plugininfo.h"
#include <integrations/thing.h>
#include <QDebug>
#include <QDir>
@ -591,7 +592,7 @@ void IntegrationPluginOneWire::onOneWireDevicesDiscovered(QList<Owfs::OwfsDevice
break;
}
default:
qDebug(dcOneWire()) << "Unknown Device discovered" << oneWireDevice.type << oneWireDevice.address;
qCDebug(dcOneWire()) << "Unknown Device discovered" << oneWireDevice.type << oneWireDevice.address;
break;
}

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -31,10 +31,11 @@
#ifndef INTEGRATIONPLUGINONEWIRE_H
#define INTEGRATIONPLUGINONEWIRE_H
#include "plugintimer.h"
#include "integrations/integrationplugin.h"
#include "owfs.h"
#include "w1.h"
#include <integrations/integrationplugin.h>
#include <plugintimer.h>
#include <owfs.h>
#include <w1.h>
#include "extern-plugininfo.h"

View File

@ -1,10 +1,6 @@
include(../plugins.pri)
TARGET = $$qtLibraryTarget(nymea_integrationpluginonewire)
LIBS += \
-low \
-lowcapi \
LIBS += -low -lowcapi
SOURCES += \
integrationpluginonewire.cpp \

View File

@ -29,8 +29,12 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "owfs.h"
#include "owcapi.h"
#include "extern-plugininfo.h"
#include <QVariant>
Owfs::Owfs(QObject *parent) :
QObject(parent)
{
@ -56,7 +60,7 @@ bool Owfs::init(const QByteArray &owfsInitArguments)
//inifArguments.append("--w1");
if (OW_init(owfsInitArguments) < 0) {
qWarning(dcOneWire()) << "ERROR initialising one wire" << strerror(errno);
qCWarning(dcOneWire()) << "ERROR initialising one wire" << strerror(errno);
return false;
}
m_path = "/";
@ -69,10 +73,10 @@ bool Owfs::discoverDevices()
size_t dirLength ;
if (OW_get(m_path, &dirBuffer, &dirLength) < 0) {
qWarning(dcOneWire()) << "DIRECTORY ERROR" << strerror(errno);
qCWarning(dcOneWire()) << "DIRECTORY ERROR" << strerror(errno);
return false;
}
qDebug(dcOneWire()) << "Directory has members" << dirBuffer;
qCDebug(dcOneWire()) << "Directory has members" << dirBuffer;
QList<QByteArray> dirMembers ;
dirMembers = QByteArray(dirBuffer, dirLength).split(',');
@ -95,7 +99,6 @@ bool Owfs::discoverDevices()
int family = member.split('.').first().toInt(nullptr, 16);
if (family != 0) {
member.remove(member.indexOf('/'), 1);
QByteArray type;
OwfsDevice thing;
thing.family = family;
thing.address = member;
@ -148,10 +151,10 @@ QByteArray Owfs::getValue(const QByteArray &address, const QByteArray &type)
devicePath.append('\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);
free(getBuffer);
@ -171,21 +174,21 @@ void Owfs::setValue(const QByteArray &address, const QByteArray &type, const QBy
devicePath.append('\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)
{
QByteArray temperature = getValue(address, "temperature");
qDebug(dcOneWire()) << "Temperature" << temperature << temperature.replace(',','.').toDouble();
qCDebug(dcOneWire()) << "Temperature" << temperature << temperature.replace(',','.').toDouble();
return temperature.toDouble(ok);
}
double Owfs::getHumidity(const QByteArray &address, bool *ok)
{
QByteArray humidity = getValue(address, "humidity");
qDebug(dcOneWire()) << "Humidity" << humidity << humidity.replace(',','.').toDouble();
qCDebug(dcOneWire()) << "Humidity" << humidity << humidity.replace(',','.').toDouble();
return humidity.toDouble(ok);
}
@ -226,7 +229,7 @@ bool Owfs::getSwitchOutput(const QByteArray &address, SwitchChannel channel, boo
break;
}
QByteArray state = getValue(address, c);
qDebug(dcOneWire()) << "Switch state" << state.toInt();
qCDebug(dcOneWire()) << "Switch state" << state.toInt();
return state.toInt(ok);
}
@ -261,7 +264,7 @@ bool Owfs::getSwitchInput(const QByteArray &address, SwitchChannel channel, bool
break;
}
QByteArray state = getValue(address, c);
qDebug(dcOneWire()) << "Switch state" << state.toInt();
qCDebug(dcOneWire()) << "Switch state" << state.toInt();
return state.toInt(ok);
}

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -31,8 +31,6 @@
#ifndef OWFS_H
#define OWFS_H
#include "owcapi.h"
#include <QObject>
class Owfs : public QObject
@ -88,7 +86,7 @@ private:
void setValue(const QByteArray &address, const QByteArray &deviceType, const QByteArray &value);
signals:
void devicesDiscovered(QList<OwfsDevice> devices);
void devicesDiscovered(QList<Owfs::OwfsDevice> devices);
};
#endif // OWFS_H

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -52,7 +52,7 @@ QStringList W1::discoverDevices()
QFileInfoList list = w1SysFSDir.entryInfoList();
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
if(fileInfo.fileName()[2] == '-') {
if(fileInfo.fileName().at(2) == '-') {
qCDebug(dcOneWire()) << "Found one wire device" << fileInfo.filePath();
deviceList.append(fileInfo.fileName());
}