fixed switches, added init arguments

This commit is contained in:
nymea 2019-08-26 00:26:00 +02:00
parent e0e77abcbf
commit 5e0e99900a
5 changed files with 140 additions and 147 deletions

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * *
* Copyright (C) 2018 Bernhard Trinnes <bernhard.trinnes@guh.io * * Copyright (C) 2018 Bernhard Trinnes <bernhard.trinnes@nymea.io> *
* * * *
* This file is part of nymea. * * This file is part of nymea. *
* * * *
@ -20,24 +20,7 @@
* * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*!
\page onewire.html
\title One wire
\brief Plugin for one wire devices.
\ingroup plugins
\ingroup nymea-plugins
This plugin allows to receive data from the onw wire file system.
\chapter Plugin properties
Following JSON file contains the definition and the description of all available \l{DeviceClass}{DeviceClasses}
and \l{Vendor}{Vendors} of this \l{DevicePlugin}.
For more details how to read this JSON file please check out the documentation for \l{The plugin JSON File}.
\quotefile plugins/deviceplugins/OneWire/devicepluginOneWire.json
*/
#include "devicepluginonewire.h" #include "devicepluginonewire.h"
#include "devices/device.h" #include "devices/device.h"
@ -46,19 +29,22 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
//https://github.com/owfs
//https://github.com/owfs/owfs-doc/wiki
DevicePluginOneWire::DevicePluginOneWire() DevicePluginOneWire::DevicePluginOneWire()
{ {
} }
void DevicePluginOneWire::init()
{
}
Device::DeviceError DevicePluginOneWire::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginOneWire::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params); Q_UNUSED(params);
if (deviceClassId == temperatureSensorDeviceClassId) { if (deviceClassId == temperatureSensorDeviceClassId ||
deviceClassId == singleChannelSwitchDeviceClassId ||
deviceClassId == dualChannelSwitchDeviceClassId ||
deviceClassId == eightChannelSwitchDeviceClassId) {
foreach(Device *parentDevice, myDevices().filterByDeviceClassId(oneWireInterfaceDeviceClassId)) { foreach(Device *parentDevice, myDevices().filterByDeviceClassId(oneWireInterfaceDeviceClassId)) {
if (parentDevice->stateValue(oneWireInterfaceAutoAddStateTypeId).toBool()) { if (parentDevice->stateValue(oneWireInterfaceAutoAddStateTypeId).toBool()) {
@ -77,6 +63,7 @@ Device::DeviceError DevicePluginOneWire::discoverDevices(const DeviceClassId &de
Device::DeviceSetupStatus DevicePluginOneWire::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginOneWire::setupDevice(Device *device)
{ {
if(!m_pluginTimer) { if(!m_pluginTimer) {
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(10); m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(10);
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginOneWire::onPluginTimer); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginOneWire::onPluginTimer);
@ -85,14 +72,16 @@ Device::DeviceSetupStatus DevicePluginOneWire::setupDevice(Device *device)
if (device->deviceClassId() == oneWireInterfaceDeviceClassId) { if (device->deviceClassId() == oneWireInterfaceDeviceClassId) {
qCDebug(dcOneWire) << "Setup one wire interface"; qCDebug(dcOneWire) << "Setup one wire interface";
/*if(!myDevices().filterByDeviceClassId(oneWireInterfaceDeviceClassId).isEmpty()) { if (m_oneWireInterface) {
qCWarning(dcOneWire) << "Only one one wire interfaces allowed"; qCWarning(dcOneWire) << "One wire interface already set up";
return Device::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
}*/ }
m_oneWireInterface = new OneWire(device->paramValue(oneWireInterfaceDevicePathParamTypeId).toByteArray(), this); m_oneWireInterface = new OneWire(this);
QByteArray initArguments = device->paramValue(oneWireInterfaceDeviceInitArgsParamTypeId).toByteArray();
if (!m_oneWireInterface->init()){ if (!m_oneWireInterface->init(initArguments)){
m_oneWireInterface->deleteLater(); m_oneWireInterface->deleteLater();
m_oneWireInterface = nullptr;
return Device::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
connect(m_oneWireInterface, &OneWire::devicesDiscovered, this, &DevicePluginOneWire::onOneWireDevicesDiscovered); connect(m_oneWireInterface, &OneWire::devicesDiscovered, this, &DevicePluginOneWire::onOneWireDevicesDiscovered);
@ -109,14 +98,6 @@ Device::DeviceSetupStatus DevicePluginOneWire::setupDevice(Device *device)
return Device::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == iButtonDeviceClassId) {
qCDebug(dcOneWire) << "Setup one wire iButton" << device->params();
if (!m_oneWireInterface) {
}
return Device::DeviceSetupStatusSuccess;
}
if (device->deviceClassId() == singleChannelSwitchDeviceClassId) { if (device->deviceClassId() == singleChannelSwitchDeviceClassId) {
qCDebug(dcOneWire) << "Setup one wire switch" << device->params(); qCDebug(dcOneWire) << "Setup one wire switch" << device->params();
if (!m_oneWireInterface) { if (!m_oneWireInterface) {
@ -125,6 +106,32 @@ Device::DeviceSetupStatus DevicePluginOneWire::setupDevice(Device *device)
} }
return Device::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == dualChannelSwitchDeviceClassId) {
qCDebug(dcOneWire) << "Setup one wire dual switch" << device->params();
if (!m_oneWireInterface) {
QByteArray address = device->paramValue(dualChannelSwitchDeviceAddressParamTypeId).toByteArray();
device->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A));
device->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_B));
}
return Device::DeviceSetupStatusSuccess;
}
if (device->deviceClassId() == eightChannelSwitchDeviceClassId) {
qCDebug(dcOneWire) << "Setup one wire eight channel switch" << device->params();
if (!m_oneWireInterface) {
QByteArray address = device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray();
device->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A));
device->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_B));
device->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_C));
device->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_D));
device->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_E));
device->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_F));
device->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_G));
device->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_H));
}
return Device::DeviceSetupStatusSuccess;
}
return Device::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
@ -147,6 +154,54 @@ Device::DeviceError DevicePluginOneWire::executeAction(Device *device, const Act
} }
return Device::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == dualChannelSwitchDeviceClassId) {
if (action.actionTypeId() == dualChannelSwitchDigitalOutput1ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(dualChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_A, action.param(dualChannelSwitchDigitalOutput1ActionDigitalOutput1ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == dualChannelSwitchDigitalOutput2ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(dualChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_B, action.param(dualChannelSwitchDigitalOutput2ActionDigitalOutput2ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
return Device::DeviceErrorActionTypeNotFound;
}
if (device->deviceClassId() == eightChannelSwitchDeviceClassId) {
if (action.actionTypeId() == eightChannelSwitchDigitalOutput1ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_A, action.param(eightChannelSwitchDigitalOutput1ActionDigitalOutput1ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == eightChannelSwitchDigitalOutput2ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_B, action.param(eightChannelSwitchDigitalOutput2ActionDigitalOutput2ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == eightChannelSwitchDigitalOutput3ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_C, action.param(eightChannelSwitchDigitalOutput3ActionDigitalOutput3ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == eightChannelSwitchDigitalOutput4ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_D, action.param(eightChannelSwitchDigitalOutput4ActionDigitalOutput4ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == eightChannelSwitchDigitalOutput5ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_E, action.param(eightChannelSwitchDigitalOutput5ActionDigitalOutput5ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == eightChannelSwitchDigitalOutput6ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_F, action.param(eightChannelSwitchDigitalOutput6ActionDigitalOutput6ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == eightChannelSwitchDigitalOutput7ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_G, action.param(eightChannelSwitchDigitalOutput7ActionDigitalOutput7ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
if (action.actionTypeId() == eightChannelSwitchDigitalOutput8ActionTypeId){
m_oneWireInterface->setSwitchOutput(device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray(), OneWire::SwitchChannel::PIO_H, action.param(eightChannelSwitchDigitalOutput8ActionDigitalOutput8ParamTypeId).value().toBool());
return Device::DeviceErrorNoError;
}
return Device::DeviceErrorActionTypeNotFound;
}
return Device::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
@ -155,12 +210,13 @@ void DevicePluginOneWire::deviceRemoved(Device *device)
{ {
if (device->deviceClassId() == oneWireInterfaceDeviceClassId) { if (device->deviceClassId() == oneWireInterfaceDeviceClassId) {
m_oneWireInterface->deleteLater(); m_oneWireInterface->deleteLater();
m_oneWireInterface = nullptr;
return; return;
} }
if (myDevices().empty()) { if (myDevices().empty()) {
hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer); hardwareManager()->pluginTimerManager()->unregisterTimer(m_pluginTimer);
m_pluginTimer = nullptr;
} }
} }
@ -182,6 +238,29 @@ void DevicePluginOneWire::onPluginTimer()
double temperature = m_oneWireInterface->getTemperature(address); double temperature = m_oneWireInterface->getTemperature(address);
device->setStateValue(temperatureSensorTemperatureStateTypeId, temperature); device->setStateValue(temperatureSensorTemperatureStateTypeId, temperature);
} }
if (device->deviceClassId() == singleChannelSwitchDeviceClassId) {
QByteArray address = device->paramValue(singleChannelSwitchDeviceAddressParamTypeId).toByteArray();
device->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A));
}
if (device->deviceClassId() == dualChannelSwitchDeviceClassId) {
QByteArray address = device->paramValue(dualChannelSwitchDeviceAddressParamTypeId).toByteArray();
device->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A));
device->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_B));
}
if (device->deviceClassId() == eightChannelSwitchDeviceClassId) {
QByteArray address = device->paramValue(eightChannelSwitchDeviceAddressParamTypeId).toByteArray();
device->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_A));
device->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_B));
device->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_C));
device->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_D));
device->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_E));
device->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_F));
device->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_G));
device->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_oneWireInterface->getSwitchOutput(address, OneWire::SwitchChannel::PIO_H));
}
} }
} }
@ -272,66 +351,19 @@ void DevicePluginOneWire::onOneWireDevicesDiscovered(QList<OneWire::OneWireDevic
if (!singleChannelSwitchDeviceDescriptors.isEmpty()) if (!singleChannelSwitchDeviceDescriptors.isEmpty())
emit autoDevicesAppeared(singleChannelSwitchDeviceClassId, singleChannelSwitchDeviceDescriptors); emit autoDevicesAppeared(singleChannelSwitchDeviceClassId, singleChannelSwitchDeviceDescriptors);
if (!dualChannelSwitchDeviceDescriptors.isEmpty()) if (!dualChannelSwitchDeviceDescriptors.isEmpty())
emit autoDevicesAppeared(dualChannelSwitchDeviceClassId, temperatureDeviceDescriptors); emit autoDevicesAppeared(dualChannelSwitchDeviceClassId, dualChannelSwitchDeviceDescriptors);
if (!temperatureDeviceDescriptors.isEmpty()) if (!eightChannelSwitchDeviceDescriptors.isEmpty())
emit autoDevicesAppeared(temperatureSensorDeviceClassId, temperatureDeviceDescriptors); emit autoDevicesAppeared(eightChannelSwitchDeviceClassId, eightChannelSwitchDeviceDescriptors);
} else { } else {
if (!temperatureDeviceDescriptors.isEmpty()) if (!temperatureDeviceDescriptors.isEmpty())
emit devicesDiscovered(temperatureSensorDeviceClassId, temperatureDeviceDescriptors); emit devicesDiscovered(temperatureSensorDeviceClassId, temperatureDeviceDescriptors);
if (!singleChannelSwitchDeviceDescriptors.isEmpty()) if (!singleChannelSwitchDeviceDescriptors.isEmpty())
emit devicesDiscovered(singleChannelSwitchDeviceClassId, singleChannelSwitchDeviceDescriptors); emit devicesDiscovered(singleChannelSwitchDeviceClassId, singleChannelSwitchDeviceDescriptors);
if (!dualChannelSwitchDeviceDescriptors.isEmpty()) if (!dualChannelSwitchDeviceDescriptors.isEmpty())
emit devicesDiscovered(dualChannelSwitchDeviceClassId, temperatureDeviceDescriptors); emit devicesDiscovered(dualChannelSwitchDeviceClassId, dualChannelSwitchDeviceDescriptors);
if (!temperatureDeviceDescriptors.isEmpty()) if (!eightChannelSwitchDeviceDescriptors.isEmpty())
emit devicesDiscovered(temperatureSensorDeviceClassId, temperatureDeviceDescriptors); emit devicesDiscovered(eightChannelSwitchDeviceClassId, eightChannelSwitchDeviceDescriptors);
} }
break; break;
} }
} }
/* foreach(QByteArray member, dirMembers) {
int family = member.split('.').first().toInt(nullptr, 16);
qDebug(dcOneWire()) << "Member" << member << member.left(2) << family;
member.remove(member.indexOf('/'), 1);
QByteArray type;
switch (family) {
//https://github.com/owfs/owfs-doc/wiki/1Wire-Device-List
case 0x10: //DS18S20
case 0x28: //DS18B20
case 0x3b: //DS1825, MAX31826, MAX31850
OneWireDevice device;
device.family =family;
device.Address = member.split('.').last();
device.Type = getValue(member, "type");
oneWireDevices.append(device);
qDebug(dcOneWire()) << "Discovered temperature sensor" << type << member;
break;
case 0x05:
case 0x12:
case 0x1C:
case 0x3A:
OneWireDevice device;
device.family =family;
device.Address = member.split('.').last();
device.Type = getValue(member, "type");
oneWireDevices.append(device);
qDebug(dcOneWire()) << "Discovered temperature sensor" << type << member;
qDebug(dcOneWire()) << "Discovered switch" << type << member;
break;
case 0x08: //DS1992 1kbit Memory iButton
case 0x06: //DS1993 4kbit Memory iButton
case 0x0A: //DS1995 16kbit Memory iButton
case 0x0C: //DS1996 64kbit Memory iButton
type = getValue(member, "type");
qDebug(dcOneWire()) << "Discovered ID device" << type << member;
break;
default:
//type = getValue(member, "type");
//qDebug(dcOneWire()) << "Discovered unknown " << type << member;
//emit unknownDeviceDiscovered(member, type);
break ;
}
}
if(!oneWireDevices.isEmpty*/

View File

@ -37,6 +37,7 @@ class DevicePluginOneWire : public DevicePlugin
public: public:
explicit DevicePluginOneWire(); explicit DevicePluginOneWire();
void init() override;
Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
Device::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
@ -49,7 +50,6 @@ private:
private slots: private slots:
void onPluginTimer(); void onPluginTimer();
void onOneWireDevicesDiscovered(QList<OneWire::OneWireDevice> devices); void onOneWireDevicesDiscovered(QList<OneWire::OneWireDevice> devices);
}; };

View File

@ -12,15 +12,15 @@
"id": "c36c68d9-6182-4ae1-972d-b8b5e0cf185f", "id": "c36c68d9-6182-4ae1-972d-b8b5e0cf185f",
"name": "oneWireInterface", "name": "oneWireInterface",
"displayName": "One wire interface", "displayName": "One wire interface",
"interfaces": ["connectable"], "interfaces": ["gateway"],
"createMethods": ["user"], "createMethods": ["user"],
"paramTypes": [ "paramTypes": [
{ {
"id": "a0e773ff-fd19-499e-96f0-830168229cd3", "id": "a0e773ff-fd19-499e-96f0-830168229cd3",
"name": "path", "name": "initArgs",
"displayName": "Path", "displayName": "OWFS init arguments",
"type": "QString", "type": "QString",
"defaultValue": "/dev/ttyS0" "defaultValue": "--i2c=ALL:ALL"
} }
], ],
"stateTypes": [ "stateTypes": [
@ -267,40 +267,6 @@
"writable": true "writable": true
} }
] ]
},
{
"id": "22aff41f-0f48-40f2-aa4e-bb251723be1c",
"name": "iButton",
"displayName": "iButton",
"interfaces": [ ],
"createMethods": ["discovery"],
"paramTypes": [
{
"id": "759e919c-8af2-43dd-af99-9b8c59321050",
"name": "address",
"displayName": "Address",
"type": "QString",
"readOnly": true
},
{
"id": "5ca8d942-4ef2-47be-8ac9-be2ee19e168d",
"name": "type",
"displayName": "Type",
"type": "QString",
"inputType": "TextLine",
"readOnly": true
}
],
"stateTypes": [
],
"eventTypes": [
{
"id": "61d69bec-c948-4703-9686-8762381d0ae4",
"name": "authenticated",
"displayName": "Authenticated"
}
]
} }
] ]
} }

View File

@ -23,9 +23,8 @@
#include "onewire.h" #include "onewire.h"
#include "extern-plugininfo.h" #include "extern-plugininfo.h"
OneWire::OneWire(const QByteArray &deviceLocation, QObject *parent) : OneWire::OneWire(QObject *parent) :
QObject(parent), QObject(parent)
m_deviceLocation(deviceLocation)
{ {
} }
@ -35,13 +34,17 @@ OneWire::~OneWire()
OW_finish(); OW_finish();
} }
bool OneWire::init() bool OneWire::init(const QByteArray &owfsInitArguments)
{ {
QByteArray initArguments; //QByteArray initArguments;
//Test OWFS arguments
//initArguments.append("--fake 28 --fake 10"); //fake temperature sensors //initArguments.append("--fake 28 --fake 10"); //fake temperature sensors
//initArguments.append("--fake 29 --fake 12 --fake 05"); //fake temperature sensors //initArguments.append("--fake 29 --fake 12 --fake 05"); //fake temperature sensor
initArguments.append("--i2c=ALL:ALL");
if (OW_init(initArguments) < 0) { //Test i2c
//initArguments.append("--i2c=ALL:ALL");
if (OW_init(owfsInitArguments) < 0) {
qWarning(dcOneWire()) << "ERROR initialising one wire" << strerror(errno); qWarning(dcOneWire()) << "ERROR initialising one wire" << strerror(errno);
return false; return false;
} }
@ -165,12 +168,6 @@ double OneWire::getTemperature(const QByteArray &address)
return temperature.toDouble(); return temperature.toDouble();
} }
QByteArray OneWire::readMemory(const QByteArray &address)
{
//getValue
return address; //TODDO
}
QByteArray OneWire::getType(const QByteArray &address) QByteArray OneWire::getType(const QByteArray &address)
{ {
QByteArray type = getValue(address, "type"); QByteArray type = getValue(address, "type");

View File

@ -58,9 +58,9 @@ public:
QByteArray type; QByteArray type;
}; };
explicit OneWire(const QByteArray &deviceLocation, QObject *parent = nullptr); explicit OneWire(QObject *parent = nullptr);
~OneWire(); ~OneWire();
bool init(); bool init(const QByteArray &owfsInitArguments);
QByteArray getPath(); QByteArray getPath();
bool discoverDevices(); bool discoverDevices();
@ -69,13 +69,11 @@ public:
double getTemperature(const QByteArray &address); double getTemperature(const QByteArray &address);
QByteArray getType(const QByteArray &address); QByteArray getType(const QByteArray &address);
QByteArray readMemory(const QByteArray &address);
bool getSwitchOutput(const QByteArray &address, SwitchChannel channel); bool getSwitchOutput(const QByteArray &address, SwitchChannel channel);
void setSwitchOutput(const QByteArray &address, SwitchChannel channel, bool state); void setSwitchOutput(const QByteArray &address, SwitchChannel channel, bool state);
bool getSwitchInput(const QByteArray &address, SwitchChannel channel); bool getSwitchInput(const QByteArray &address, SwitchChannel channel);
private: private:
QByteArray m_deviceLocation;
QByteArray m_path; QByteArray m_path;
QByteArray getValue(const QByteArray &address, const QByteArray &deviceType); QByteArray getValue(const QByteArray &address, const QByteArray &deviceType);
void setValue(const QByteArray &address, const QByteArray &deviceType, const QByteArray &value); void setValue(const QByteArray &address, const QByteArray &deviceType, const QByteArray &value);