From d6dc0ba07b2ddf69c7af1a78727b729101339c32 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 3 May 2020 23:25:05 +0200 Subject: [PATCH] =?UTF-8?q?New=20Plugin:=20I=C2=B2C=20devices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debian/control | 25 +- debian/nymea-plugin-i2cdevices.install.in | 1 + i2cdevices/README.md | 101 ++++ i2cdevices/ads1115channel.cpp | 97 ++++ i2cdevices/ads1115channel.h | 63 +++ i2cdevices/i2cdevices.pro | 12 + i2cdevices/integrationplugini2cdevices.cpp | 212 ++++++++ i2cdevices/integrationplugini2cdevices.h | 63 +++ i2cdevices/integrationplugini2cdevices.json | 456 ++++++++++++++++++ i2cdevices/meta.json | 9 + i2cdevices/pi16adcchannel.cpp | 88 ++++ i2cdevices/pi16adcchannel.h | 53 ++ ...7318d45b-2eed-472c-ae08-aad56db31e28-de.ts | 346 +++++++++++++ ...8d45b-2eed-472c-ae08-aad56db31e28-en_US.ts | 346 +++++++++++++ nymea-plugins.pro | 1 + 15 files changed, 1866 insertions(+), 7 deletions(-) create mode 100644 debian/nymea-plugin-i2cdevices.install.in create mode 100644 i2cdevices/README.md create mode 100644 i2cdevices/ads1115channel.cpp create mode 100644 i2cdevices/ads1115channel.h create mode 100644 i2cdevices/i2cdevices.pro create mode 100644 i2cdevices/integrationplugini2cdevices.cpp create mode 100644 i2cdevices/integrationplugini2cdevices.h create mode 100644 i2cdevices/integrationplugini2cdevices.json create mode 100644 i2cdevices/meta.json create mode 100644 i2cdevices/pi16adcchannel.cpp create mode 100644 i2cdevices/pi16adcchannel.h create mode 100644 i2cdevices/translations/7318d45b-2eed-472c-ae08-aad56db31e28-de.ts create mode 100644 i2cdevices/translations/7318d45b-2eed-472c-ae08-aad56db31e28-en_US.ts diff --git a/debian/control b/debian/control index 8c4c3847..ebd52a48 100644 --- a/debian/control +++ b/debian/control @@ -325,6 +325,19 @@ Description: nymea.io plugin for gpio This package will install the nymea.io plugin for gpio +Package: nymea-plugin-i2cdevices +Architecture: any +Section: libs +Depends: ${shlibs:Depends}, + ${misc:Depends}, + nymea-plugins-translations, +Description: nymea.io plugin for I2C devies + This plugin adds support for I2C devices to nymea. + Currently supported devices are the ADS1114/1114/1115 and the Pi-16ADC. + . + This package will install the nymea.io plugin for AD converters + + Package: nymea-plugin-kodi Architecture: any Depends: ${shlibs:Depends}, @@ -966,6 +979,7 @@ Depends: nymea-plugin-boblight, nymea-plugin-avahimonitor, nymea-plugin-anel, nymea-plugin-gpio, + nymea-plugin-i2cdevices, nymea-plugin-mqttclient, nymea-plugin-remotessh, nymea-plugin-serialportcommander, @@ -973,14 +987,11 @@ Depends: nymea-plugin-boblight, nymea-plugin-onewire, nymea-plugin-dynatrace, Replaces: guh-plugins-maker -Description: Plugins for nymea IoT server - Meta package for makers, tinkers and hackers - The nymea daemon is a plugin based IoT (Internet of Things) server. The - server works like a translator for devices, things and services and - allows them to interact. - With the powerful rule engine you are able to connect any device available - in the system and create individual scenes and behaviors for your environment. +Description: Meta package for nymea makers, tinkerers and hackers plugins. + This package is a meta package that pulls in useful nymea plugins for makers. + Such plugins allow tinkering with GPIOs, I2C, One-Wire, raw MQTT and more. . - This package will install nymea plugins for maker, tinker and hackers. + This package will install nymea plugins for makers, tinkerers and hackers. Package: nymea-plugins-merkurboard diff --git a/debian/nymea-plugin-i2cdevices.install.in b/debian/nymea-plugin-i2cdevices.install.in new file mode 100644 index 00000000..ec483f37 --- /dev/null +++ b/debian/nymea-plugin-i2cdevices.install.in @@ -0,0 +1 @@ +usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/libnymea_integrationplugini2cdevices.so diff --git a/i2cdevices/README.md b/i2cdevices/README.md new file mode 100644 index 00000000..6ea4a0d4 --- /dev/null +++ b/i2cdevices/README.md @@ -0,0 +1,101 @@ +# I²C devices + +This integration plugin adds support for some I²C devices. + +Currently supported devices are: + +* ADS1113/ADS1114/ADS1115 +* Pi-16ADC + +## ADS1113/ADS1114/ADS1115 + +The ADS1113/1114/1115 is a 4 channel, I²C-compatible, 16-Bit ADC by Texas Instruments and supports +measuring input voltages from 0 to 6.144V. + +### Usage + +In order to use this device within nymea, it needs to be connected to the I²C bus. At least SDA, +SCL, GND and VDD must be connected. VDD can be any desired voltage from 2V to 5.5V. Input channels +are to be connected at the according pins and will perform an analog to digital conversion of their +input voltage. + +> IMPORTANT: The input voltage on the connected AINX channels must never exceed VDD + 0.3V. + +The measured input value will be a floating point value from 0 to 1, depending on the selected input gain. +For instance, if the selected input gain is 4.096V, a voltage of 0V will be indicated in nymea as +0 while an input voltage of 4.096V will be represented as 1. + +Setup can be done by performing a discovery for it in nymea. Please verify that the found results +are matching with the address configuration of the device. If the address pin is not connected +at all, the I²C address will be 72 (0x48). It can be configured to another I²C address by connecting +the address pin as follows: + +| Pin | Address (Hex) | +|:---:|:-------------:| +| GND | 72 (0x48) | +| VDD | 73 (0x49) | +| SDA | 74 (0x4a) | +| SCL | 75 (0x4b) | +----------------------- + +By assigning different addresses, up to 4 such devices can be used on a single I²C bus. + +> Note: At this point, this plugin does not support the devices dual channel mode. + +## Pi-16ADC + +The Pi-16ADC is a 16 channel analog/digital converter Raspberry Pi HAT by Alchemy Power and +supports measuring input voltage from 0 to 2.5V. + +### Usage + +In order to use this device within nymea, it needs to be plugged onto the Rasperry. The +analog input channels can be connected to to the respective channels. Unused channels +should be connected to GND in order to prevent them from oscillating. + +The measured input value will be a floating point voltage value from 0V to 2.5V. + +Setup can be done by performing a discovery for it in nymea. Please verify that the found results +are matching with the address configuration of the device. The default address is 118 (0x76).The +jumpers on the board can be used to configure the I²C address of the board by setting the jumpers +to low (connect AX to GND), high (connect AX to +) or floating (remove jumper). The following +table shows the possible address configurations: + +| A2 | A1 | A0 | Address (Hex) | +|:-----:|:-----:|:-----:|:-------------:| +| Low | Low | Low | 20 (0x14) | +| Low | Low | High | 22 (0x16) | +| Low | Low | Float | 21 (0x15) | +| Low | High | Low | 38 (0x26) | +| Low | High | High | 52 (0x34) | +| Low | High | Float | 39 (0x27) | +| Low | Float | Low | 23 (0x17) | +| Low | Float | High | 37 (0x25) | +| Low | Float | Float | 36 (0x24) | +| High | Low | Low | 86 (0x56) | +| High | Low | High | 100 (0x64) | +| High | Low | Float | 87 (0x57) | +| High | High | Low | 116 (0x74) | +| High | High | High | 118 (0x76) | +| High | High | Float | 117 (0x75) | +| High | Float | Low | 101 (0x65) | +| High | Float | High | 103 (0x67) | +| High | Float | Float | 102 (0x66) | +| Float | Low | Low | 53 (0x35) | +| Float | Low | High | 55 (0x37) | +| Float | Low | Float | 54 (0x36) | +| Float | High | Low | 71 (0x47) | +| Float | High | High | 85 (0x55) | +| Float | High | Float | 54 (0x54) | +| Float | Float | Low | 68 (0x44) | +| Float | Float | High | 70 (0x46) | +| Float | Float | Float | 69 (0x45) | +----------------------------------------- + +By assigning different addresses, multiple such boards can be stacked on top of each other if +more than 16 channels are required. + +> Note: At this point, this plugin does not support the devices dual channel mode. + +Additional information ca be found at the devices users guide at +[https://www.alchemy-power.com/wp-content/uploads/2017/03/Pi-16ADC-User-Guide.pdf](https://www.alchemy-power.com/wp-content/uploads/2017/03/Pi-16ADC-User-Guide.pdf). diff --git a/i2cdevices/ads1115channel.cpp b/i2cdevices/ads1115channel.cpp new file mode 100644 index 00000000..cc42dab1 --- /dev/null +++ b/i2cdevices/ads1115channel.cpp @@ -0,0 +1,97 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "ads1115channel.h" +#include "extern-plugininfo.h" + +#include + +#define REGISTER_CONVERSATION 0x00 +#define REGISTER_CONFIG 0x01 + +#define OPERATIONAL_STATE_IDLE 0x00 +#define OPERATIONAL_STATE_CONVERSATION 0x80 + +#define CONVERSION_MODE_CONTINUOUS 0x00 +#define CONVERSION_MODE_SINGLE 0x40 + +#define CHANNEL_MODE_DIFFERENTIAL 0x00 +#define CHANNEL_MODE_SINGLE 0x01 + +ADS1115Channel::ADS1115Channel(const QString &portName, int address, int channel, Gain gain, QObject *parent): + I2CDevice(portName, address, parent), + m_channel(channel), + m_gain(gain) +{ + +} + + +QByteArray ADS1115Channel::readData(int fd) +{ + // Start a configuration conversation + unsigned char writeBuf[3] = {0}; + writeBuf[0] = REGISTER_CONFIG; // Select config register + writeBuf[1] |= OPERATIONAL_STATE_CONVERSATION; // Set conversation bit + writeBuf[1] |= CHANNEL_MODE_SINGLE; + writeBuf[1] |= m_channel << 4; + writeBuf[1] |= m_gain << 1; + writeBuf[1] |= CONVERSION_MODE_SINGLE; + writeBuf[2] = 0x85; // 0b10000101: Data rate: 100, not using comparator + if (write(fd, writeBuf, 3) != 3) { + qCWarning(dcI2cDevices()) << "ADS1115: could not write config register"; + return QByteArray(); + } + + // Wait for device to accept configuration (conversation bit is cleared) + char readBuf[2] = {0}; + do { + if (read(fd, readBuf, 2) != 2) { + qCWarning(dcI2cDevices()) << "ADS1115: could not read ADC data"; + return QByteArray(); + } + } while (!(readBuf[0] & OPERATIONAL_STATE_CONVERSATION)); + + // Select conversation register + writeBuf[0] = REGISTER_CONVERSATION; + if (write(fd, writeBuf, 1) != 1) { + qCWarning(dcI2cDevices()) << "ADS1115: could not write select register"; + return QByteArray(); + } + + // Read conversation register + if (read(fd, readBuf, 2) != 2) { + qCWarning(dcI2cDevices()) << "ADS1115: could not read ADC data"; + return QByteArray(); + } + + return QByteArray(readBuf, 2); +} + diff --git a/i2cdevices/ads1115channel.h b/i2cdevices/ads1115channel.h new file mode 100644 index 00000000..f9757c4f --- /dev/null +++ b/i2cdevices/ads1115channel.h @@ -0,0 +1,63 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef ADS1115_H +#define ADS1115_H + +#include +#include + +#include + +class ADS1115Channel: public I2CDevice +{ + Q_OBJECT +public: + + enum Gain { + Gain_6_144 = 0, + Gain_4_096 = 1, + Gain_2_048 = 2, + Gain_1_024 = 3, + Gain_0_512 = 4, + Gain_0_256 = 5 + }; + + explicit ADS1115Channel(const QString &portName, int address, int channel, Gain gain, QObject *parent = nullptr); + + QByteArray readData(int fd) override; + +private: + int m_channel = 0; + Gain m_gain = Gain_4_096; + +}; + +#endif // ADS1115_H diff --git a/i2cdevices/i2cdevices.pro b/i2cdevices/i2cdevices.pro new file mode 100644 index 00000000..b6b22cbd --- /dev/null +++ b/i2cdevices/i2cdevices.pro @@ -0,0 +1,12 @@ +include(../plugins.pri) + +HEADERS += \ + integrationplugini2cdevices.h \ + ads1115channel.h \ + pi16adcchannel.h + + +SOURCES += \ + integrationplugini2cdevices.cpp \ + ads1115channel.cpp \ + pi16adcchannel.cpp diff --git a/i2cdevices/integrationplugini2cdevices.cpp b/i2cdevices/integrationplugini2cdevices.cpp new file mode 100644 index 00000000..e3f3b0b6 --- /dev/null +++ b/i2cdevices/integrationplugini2cdevices.cpp @@ -0,0 +1,212 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "integrationplugini2cdevices.h" +#include "plugininfo.h" + +#include "pi16adcchannel.h" +#include "ads1115channel.h" + +#include + +#include + +IntegrationPluginI2CDevices::IntegrationPluginI2CDevices(): IntegrationPlugin() +{ + m_ads1115ChannelMap.insert(0, ads1115Channel1StateTypeId); + m_ads1115ChannelMap.insert(1, ads1115Channel2StateTypeId); + m_ads1115ChannelMap.insert(2, ads1115Channel3StateTypeId); + m_ads1115ChannelMap.insert(3, ads1115Channel4StateTypeId); + + m_ads1115OvervoltageMap.insert(0, ads1115Channel1overvoltageStateTypeId); + m_ads1115OvervoltageMap.insert(1, ads1115Channel2overvoltageStateTypeId); + m_ads1115OvervoltageMap.insert(2, ads1115Channel3overvoltageStateTypeId); + m_ads1115OvervoltageMap.insert(3, ads1115Channel4overvoltageStateTypeId); + + m_pi16adcChannelMap.insert(0, pi16ADCChannel1StateTypeId); + m_pi16adcChannelMap.insert(1, pi16ADCChannel2StateTypeId); + m_pi16adcChannelMap.insert(2, pi16ADCChannel3StateTypeId); + m_pi16adcChannelMap.insert(3, pi16ADCChannel4StateTypeId); + m_pi16adcChannelMap.insert(4, pi16ADCChannel5StateTypeId); + m_pi16adcChannelMap.insert(5, pi16ADCChannel6StateTypeId); + m_pi16adcChannelMap.insert(6, pi16ADCChannel7StateTypeId); + m_pi16adcChannelMap.insert(7, pi16ADCChannel8StateTypeId); + m_pi16adcChannelMap.insert(8, pi16ADCChannel9StateTypeId); + m_pi16adcChannelMap.insert(9, pi16ADCChannel10StateTypeId); + m_pi16adcChannelMap.insert(10, pi16ADCChannel11StateTypeId); + m_pi16adcChannelMap.insert(11, pi16ADCChannel12StateTypeId); + m_pi16adcChannelMap.insert(12, pi16ADCChannel13StateTypeId); + m_pi16adcChannelMap.insert(13, pi16ADCChannel14StateTypeId); + m_pi16adcChannelMap.insert(14, pi16ADCChannel15StateTypeId); + m_pi16adcChannelMap.insert(15, pi16ADCChannel16StateTypeId); + + m_pi16adcOvervoltageMap.insert(0, pi16ADCChannel1overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(1, pi16ADCChannel2overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(2, pi16ADCChannel3overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(3, pi16ADCChannel4overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(4, pi16ADCChannel5overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(5, pi16ADCChannel6overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(6, pi16ADCChannel7overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(7, pi16ADCChannel8overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(8, pi16ADCChannel9overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(9, pi16ADCChannel10overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(10, pi16ADCChannel11overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(11, pi16ADCChannel12overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(12, pi16ADCChannel13overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(13, pi16ADCChannel14overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(14, pi16ADCChannel15overvoltageStateTypeId); + m_pi16adcOvervoltageMap.insert(15, pi16ADCChannel16overvoltageStateTypeId); +} + +void IntegrationPluginI2CDevices::init() { +} + +void IntegrationPluginI2CDevices::discoverThings(ThingDiscoveryInfo *info) +{ + foreach (const I2CScanResult &scanResult, hardwareManager()->i2cManager()->scanRegisters()) { + qCDebug(dcI2cDevices()) << "Found I2C deevice on port:" << scanResult.portName << "0x" + QString::number(scanResult.address, 16); + + if (info->thingClassId() == pi16ADCThingClassId) { + // Depending on jumper settings, the Pi-16ADC can be any of those: + QList addresses = {0x14, 0x15, 0x16, 0x17, 0x24, 0x25, 0x26, 0x27, 0x34, 0x35, 0x36, 0x37, 0x44, 0x45, 0x46, 0x47, 0x54, 0x55, 0x56, 0x57, 0x64, 0x65, 0x66, 0x67, 0x74, 0x75, 0x76}; + if (addresses.contains(scanResult.address)) { + ThingDescriptor descriptor(pi16ADCThingClassId, "Pi-16ADC", QString("%1: 0x%2").arg(scanResult.portName).arg(scanResult.address, 0, 16)); + ParamList params; + params << Param(pi16ADCThingI2cPortParamTypeId, scanResult.portName); + params << Param(pi16ADCThingI2cAddressParamTypeId, scanResult.address); + descriptor.setParams(params); + info->addThingDescriptor(descriptor); + } + } + + if (info->thingClassId() == ads1115ThingClassId) { + // The ADS1115 has selectable addresses from 0x48 to 0x51 + if (scanResult.address >= 0x48 && scanResult.address <= 0x4B) { + ThingDescriptor descriptor(ads1115ThingClassId, "ADS1113/ADS1114/ADS1115", QString("%1: 0x%2").arg(scanResult.portName).arg(scanResult.address, 0, 16)); + ParamList params; + params << Param(ads1115ThingI2cPortParamTypeId, scanResult.portName); + params << Param(ads1115ThingI2cAddressParamTypeId, scanResult.address); + descriptor.setParams(params); + info->addThingDescriptor(descriptor); + } + } + } + + info->finish(Thing::ThingErrorNoError); +} + +void IntegrationPluginI2CDevices::setupThing(ThingSetupInfo *info) +{ + if (info->thing()->thingClassId() == pi16ADCThingClassId) { + + QString i2cPortName = info->thing()->paramValue(pi16ADCThingI2cPortParamTypeId).toString(); + int i2cAddress = info->thing()->paramValue(pi16ADCThingI2cAddressParamTypeId).toInt(); + Q_UNUSED(i2cAddress) + + for (int i = 0; i < 16; i++) { + Pi16ADCChannel *pi16ADC = new Pi16ADCChannel(i2cPortName, i2cAddress, i, this); + if (!hardwareManager()->i2cManager()->open(pi16ADC)) { + delete pi16ADC; + info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Failed to open I2C port.")); + return; + } + Thing *thing = info->thing(); + connect(pi16ADC, &Pi16ADCChannel::readingAvailable, thing, [this, thing, i](const QByteArray &data){ + if (data.length() != 3) { + qCWarning(dcI2cDevices()) << "Error reading from" << thing->name(); + return; + } + int value = ((((data[0]&0x3F))<<16))+((data[1]<<8))+(((data[2]&0xE0))); + const int max = 8388608; + double transformedValue = 2.5 * value / max; + thing->setStateValue(m_pi16adcChannelMap.value(i), transformedValue); + thing->setStateValue(m_pi16adcOvervoltageMap.value(i), (data[0] & 0xC0)); + }); + hardwareManager()->i2cManager()->startReading(pi16ADC, 5000); + m_i2cDevices.insert(pi16ADC, thing); + } + + info->finish(Thing::ThingErrorNoError); + } + + if (info->thing()->thingClassId() == ads1115ThingClassId) { + QString i2cPortName = info->thing()->paramValue(ads1115ThingI2cPortParamTypeId).toString(); + int i2cAddress = info->thing()->paramValue(ads1115ThingI2cAddressParamTypeId).toInt(); + double gainParam = info->thing()->paramValue(ads1115ThingInputGainParamTypeId).toDouble(); + ADS1115Channel::Gain inputGain = ADS1115Channel::Gain_4_096; + if (qFuzzyCompare(gainParam, 6.144)) { + inputGain = ADS1115Channel::Gain_6_144; + } else if (qFuzzyCompare(gainParam, 4.096)) { + inputGain = ADS1115Channel::Gain_4_096; + } else if (qFuzzyCompare(gainParam, 2.048)) { + inputGain = ADS1115Channel::Gain_2_048; + } else if (qFuzzyCompare(gainParam, 1.024)) { + inputGain = ADS1115Channel::Gain_1_024; + } else if (qFuzzyCompare(gainParam, 0.512)) { + inputGain = ADS1115Channel::Gain_0_512; + } else if (qFuzzyCompare(gainParam, 0.256)) { + inputGain = ADS1115Channel::Gain_0_256; + } + + for (int i = 0; i < 4; i++) { + ADS1115Channel *ads1115 = new ADS1115Channel(i2cPortName, i2cAddress, i, inputGain, this); + if (!hardwareManager()->i2cManager()->open(ads1115)) { + delete ads1115; + info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Failed to open I2C port.")); + return; + } + + Thing *thing = info->thing(); + connect(ads1115, &ADS1115Channel::readingAvailable, thing, [this, thing, i](const QByteArray &data){ + if (data.length() != 2) { + qCWarning(dcI2cDevices()) << "Error reading from" << thing; + return; + } + const int max = 32768; + int value = static_cast(data[0]) * 256 + static_cast(data[1]); + double transformedValue = qMin(1.0 * value / max, 1.0); + thing->setStateValue(m_ads1115ChannelMap.value(i), transformedValue); + thing->setStateValue(m_ads1115OvervoltageMap.value(i), value > 32768); + }); + hardwareManager()->i2cManager()->startReading(ads1115, 5000); + m_i2cDevices.insert(ads1115, thing); + } + info->finish(Thing::ThingErrorNoError); + } +} + +void IntegrationPluginI2CDevices::thingRemoved(Thing *thing) +{ + foreach (I2CDevice* i2cDevice, m_i2cDevices.keys(thing)) { + hardwareManager()->i2cManager()->close(i2cDevice); + i2cDevice->deleteLater(); + m_i2cDevices.take(i2cDevice); + } +} diff --git a/i2cdevices/integrationplugini2cdevices.h b/i2cdevices/integrationplugini2cdevices.h new file mode 100644 index 00000000..b8d8ca06 --- /dev/null +++ b/i2cdevices/integrationplugini2cdevices.h @@ -0,0 +1,63 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef INTEGRATIONPLUGINPII2CDEVICES_H +#define INTEGRATIONPLUGINPII2CDEVICES_H + +#include + +class I2CDevice; + +class IntegrationPluginI2CDevices: public IntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "io.nymea.IntegrationPlugin" FILE "integrationplugini2cdevices.json") + Q_INTERFACES(IntegrationPlugin) + +public: + IntegrationPluginI2CDevices(); + + void init() override; + void discoverThings(ThingDiscoveryInfo *info) override; + + void setupThing(ThingSetupInfo *info) override; + void thingRemoved(Thing *thing) override; + +private: + QHash m_i2cDevices; + + QHash m_ads1115ChannelMap; + QHash m_ads1115OvervoltageMap; + + QHash m_pi16adcChannelMap; + QHash m_pi16adcOvervoltageMap; +}; + +#endif diff --git a/i2cdevices/integrationplugini2cdevices.json b/i2cdevices/integrationplugini2cdevices.json new file mode 100644 index 00000000..1f2105a3 --- /dev/null +++ b/i2cdevices/integrationplugini2cdevices.json @@ -0,0 +1,456 @@ +{ + "id": "7318d45b-2eed-472c-ae08-aad56db31e28", + "name": "i2cDevices", + "displayName": "I²C devices", + "vendors": [ + { + "id": "4625197b-96ab-4566-9425-5579a4acf4c0", + "name": "alchemyPower", + "displayName": "Alchemy Power Inc.", + "thingClasses": [ + { + "id": "15ecc88f-cdf0-498f-b1bc-bb630bcfb3c7", + "name": "pi16ADC", + "displayName": "Pi-16ADC", + "createMethods": ["user", "discovery"], + "setupMethod": "justAdd", + "paramTypes": [ + { + "id": "1c99ab01-ccb9-4ca6-a8d9-c2c2cfafd0af", + "name": "i2cPort", + "displayName": "I2C port", + "type": "QString" + }, + { + "id": "97f047d2-a6dc-4d40-9235-03baa1502c61", + "name": "i2cAddress", + "displayName": "I2C address", + "type": "int" + } + ], + "stateTypes": [ + { + "id": "bcb5a45f-cacb-4a74-ba81-3309875e77eb", + "name": "channel1", + "displayName": "Channel 1", + "displayNameEvent": "Channel 1 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "1a41c14f-d9e2-40d5-a424-6ec0391362aa", + "name": "channel1overvoltage", + "displayName": "Channel 1 overvoltage", + "displayNameEvent": "Channel 1 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "d48dab3f-cefd-4efc-a7c9-9a56d1763e5a", + "name": "channel2", + "displayName": "Channel 2", + "displayNameEvent": "Channel 2 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "83232516-eb5c-4e50-adda-6c03e26d90f2", + "name": "channel2overvoltage", + "displayName": "Channel 2 overvoltage", + "displayNameEvent": "Channel 2 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "d52cd791-6d92-49e4-b46b-593cb0691d46", + "name": "channel3", + "displayName": "Channel 3", + "displayNameEvent": "Channel 1 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "9af3c914-f9b9-48a5-9022-ede4a0f5f2f7", + "name": "channel3overvoltage", + "displayName": "Channel 3 overvoltage", + "displayNameEvent": "Channel 3 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "5a2e61c6-8934-40fb-b0ae-755563e1f01c", + "name": "channel4", + "displayName": "Channel 4", + "displayNameEvent": "Channel 4 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "6f2ae858-a5de-45cc-bc6c-1119a3b2e767", + "name": "channel4overvoltage", + "displayName": "Channel 4 overvoltage", + "displayNameEvent": "Channel 4 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "0eeff27c-aa76-4473-9fe5-baeb94c0fc4f", + "name": "channel5", + "displayName": "Channel 5", + "displayNameEvent": "Channel 5 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "a298ce28-72a1-4bb8-965e-22061f367a73", + "name": "channel5overvoltage", + "displayName": "Channel 5 overvoltage", + "displayNameEvent": "Channel 5 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "75a336da-4486-4709-830e-ac5ceafa44f7", + "name": "channel6", + "displayName": "Channel 6", + "displayNameEvent": "Channel 6 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "276f1a63-2403-4c3e-9bf4-96f6c510f5d0", + "name": "channel6overvoltage", + "displayName": "Channel 6 overvoltage", + "displayNameEvent": "Channel 6 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "ca863478-b520-4a3f-900b-e864d2c975f2", + "name": "channel7", + "displayName": "Channel 7", + "displayNameEvent": "Channel 7 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "07561810-a851-42dd-88c9-61afd3c761b6", + "name": "channel7overvoltage", + "displayName": "Channel 7 overvoltage", + "displayNameEvent": "Channel 7 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "582bd216-ac59-4045-b9ec-d7922c5db52d", + "name": "channel8", + "displayName": "Channel 8", + "displayNameEvent": "Channel 8 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "c22e5e29-e078-4b27-b602-d8ee90f333bc", + "name": "channel8overvoltage", + "displayName": "Channel 8 overvoltage", + "displayNameEvent": "Channel 8 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "fe58220c-6916-4194-9015-d948580d4daf", + "name": "channel9", + "displayName": "Channel 9", + "displayNameEvent": "Channel 9 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "0d6218c9-b848-4b5f-be88-69f88d05490c", + "name": "channel9overvoltage", + "displayName": "Channel 9 overvoltage", + "displayNameEvent": "Channel 9 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "88fa2326-76a7-40ad-921c-725d9c871ef4", + "name": "channel10", + "displayName": "Channel 10", + "displayNameEvent": "Channel 10 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "3a999e76-b1bb-453a-931e-17f0130a7788", + "name": "channel10overvoltage", + "displayName": "Channel 10 overvoltage", + "displayNameEvent": "Channel 10 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "015320ae-350d-4797-a5ed-7e7f74569b7a", + "name": "channel11", + "displayName": "Channel 11", + "displayNameEvent": "Channel 11 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "d22fe888-69a9-4328-98a8-4499f34edb53", + "name": "channel11overvoltage", + "displayName": "Channel 11 overvoltage", + "displayNameEvent": "Channel 11 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "096bcf38-aa9b-434f-b45d-b4164bfd4eef", + "name": "channel12", + "displayName": "Channel 12", + "displayNameEvent": "Channel 12 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "edb9cac9-b819-48bb-9a5b-e7da5e3558ea", + "name": "channel12overvoltage", + "displayName": "Channel 12 overvoltage", + "displayNameEvent": "Channel 12 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "7e28eb87-87c6-4864-bfad-e457c1187d6a", + "name": "channel13", + "displayName": "Channel 13", + "displayNameEvent": "Channel 13 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "dbb3a3f7-3fce-4f8a-bf19-2c4bade5c60a", + "name": "channel13overvoltage", + "displayName": "Channel 13 overvoltage", + "displayNameEvent": "Channel 13 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "ea3dde63-092d-4857-b836-70016647872c", + "name": "channel14", + "displayName": "Channel 14", + "displayNameEvent": "Channel 14 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "0633d37f-894c-4fcd-a818-3779cf2e507c", + "name": "channel14overvoltage", + "displayName": "Channel 14 overvoltage", + "displayNameEvent": "Channel 14 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "d580d189-cb9e-446d-8a19-5c0c7891ed1b", + "name": "channel15", + "displayName": "Channel 15", + "displayNameEvent": "Channel 15 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "43fb2001-3020-48b0-adc0-3ccd1d52e912", + "name": "channel15overvoltage", + "displayName": "Channel 15 overvoltage", + "displayNameEvent": "Channel 15 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "80fabf7c-39cb-4ff2-aa55-a7760b13b0d5", + "name": "channel16", + "displayName": "Channel 16", + "displayNameEvent": "Channel 16 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 2.5, + "ioType": "analogInput" + }, + { + "id": "b5b51627-acf8-4cb6-91b9-6aafd3074d97", + "name": "channel16overvoltage", + "displayName": "Channel 16 overvoltage", + "displayNameEvent": "Channel 16 overvoltage changed", + "type": "bool", + "defaultValue": false + } + ] + } + ] + }, + { + "id": "2edf543e-dc2c-4693-bb0c-e76c0d305fad", + "name": "texasInstruments", + "displayName": "Texas Instruments", + "thingClasses": [ + { + "id": "7f285010-8bc1-4a45-b9d0-185fbac0c14d", + "name": "ads1115", + "displayName": "ADS1113/ADS1114/ADS1115", + "createMethods": ["user", "discovery"], + "setupMethod": "justAdd", + "paramTypes": [ + { + "id": "190c932f-5c97-497b-89b6-d34e37087467", + "name": "i2cPort", + "displayName": "I2C port", + "type": "QString" + }, + { + "id": "d3a14498-f0f4-4480-9a07-2fc8ed6fa3e9", + "name": "i2cAddress", + "displayName": "I2C address", + "type": "int" + }, + { + "id": "c1845769-636e-4744-965c-8bb0b96b80b1", + "name": "inputGain", + "displayName": "Input gain", + "type": "double", + "allowedValues": [ 6.144, 4.096, 2.048, 1.024, 0.512, 0.256 ], + "unit": "Volt", + "defaultValue": 4.096 + } + ], + "stateTypes": [ + { + "id": "2d2ca0f6-ad6c-41f5-9aa6-cd08c43fc4bc", + "name": "channel1", + "displayName": "Channel 1", + "displayNameEvent": "Channel 1 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 1, + "ioType": "analogInput" + }, + { + "id": "b2b8f75a-37f9-44c1-aa08-90bbb2c19fbd", + "name": "channel1overvoltage", + "displayName": "Channel 1 overvoltage", + "displayNameEvent": "Channel 1 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "5ee7a800-a8ef-4298-aa0b-284afec75e68", + "name": "channel2", + "displayName": "Channel 2", + "displayNameEvent": "Channel 2 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 1, + "ioType": "analogInput" + }, + { + "id": "78898e55-760a-471f-ae02-011b69040dc2", + "name": "channel2overvoltage", + "displayName": "Channel 2 overvoltage", + "displayNameEvent": "Channel 2 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "1f44b1f5-afc8-4e6e-919f-7b1d158a8b6e", + "name": "channel3", + "displayName": "Channel 3", + "displayNameEvent": "Channel 3 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 1, + "ioType": "analogInput" + }, + { + "id": "b6ed4cd1-486e-40e3-b6fa-577c9a1831b6", + "name": "channel3overvoltage", + "displayName": "Channel 3 overvoltage", + "displayNameEvent": "Channel 3 overvoltage changed", + "type": "bool", + "defaultValue": false + }, + { + "id": "caba4fc0-7c06-4724-bd70-cc44b3451e17", + "name": "channel4", + "displayName": "Channel 4", + "displayNameEvent": "Channel 4 value changed", + "type": "double", + "defaultValue": 0, + "minValue": 0, + "maxValue": 1, + "ioType": "analogInput" + }, + { + "id": "187faeb9-d357-4bef-a7de-2b0e195510b8", + "name": "channel4overvoltage", + "displayName": "Channel 4 overvoltage", + "displayNameEvent": "Channel 4 overvoltage changed", + "type": "bool", + "defaultValue": false + } + ] + } + ] + } + ] +} diff --git a/i2cdevices/meta.json b/i2cdevices/meta.json new file mode 100644 index 00000000..b896be16 --- /dev/null +++ b/i2cdevices/meta.json @@ -0,0 +1,9 @@ +{ + "title": "I²C devices", + "tagline": "Allows using various analog to digital converters with nymea", + "icon": "", + "stability": "community", + "offline": true, + "technologies": ["i2c"], + "categories": [] +} diff --git a/i2cdevices/pi16adcchannel.cpp b/i2cdevices/pi16adcchannel.cpp new file mode 100644 index 00000000..37e548e5 --- /dev/null +++ b/i2cdevices/pi16adcchannel.cpp @@ -0,0 +1,88 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "pi16adcchannel.h" +#include "extern-plugininfo.h" + +#include + +#include + +static QHash channelMap = { + {0, 0xB0}, + {1, 0xB8}, + {2, 0xB1}, + {3, 0xB9}, + {4, 0xB2}, + {5, 0xBA}, + {6, 0xB3}, + {7, 0xBB}, + {8, 0xB4}, + {9, 0xBC}, + {10, 0xB5}, + {11, 0xBD}, + {12, 0xB6}, + {13, 0xBE}, + {14, 0xB7}, + {15, 0xBF} +}; + +Pi16ADCChannel::Pi16ADCChannel(const QString &portName, int address, int channel, QObject *parent): + I2CDevice(portName, address, parent), + m_channel(channel) +{ +} + +QByteArray Pi16ADCChannel::readData(int fd) +{ + // The chip requires a minimum of 200ms of wating between each call or it might just ignore it. + // Make sure to wait here long enough for any previous access having settled + QThread::msleep(200); + + // Select the wanted channel + qint64 len = write(fd, &channelMap[m_channel], 1); + if (len != 1) { + qCWarning(dcI2cDevices()) << "Pi-16ADC: Error writing channel config to device"; + return QByteArray(); + } + + // Wait for write the chip to settle + QThread::msleep(200); + + // ready to read the value + char readBuf[3] = {0}; + if (read(fd, readBuf, 3) != 3) { + qCWarning(dcI2cDevices()) << "Pi-16ADC: could not read ADC data" << readBuf; + return QByteArray(); + } + + return QByteArray(readBuf, 3); +} + diff --git a/i2cdevices/pi16adcchannel.h b/i2cdevices/pi16adcchannel.h new file mode 100644 index 00000000..d993dcb6 --- /dev/null +++ b/i2cdevices/pi16adcchannel.h @@ -0,0 +1,53 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef PI16ADC_H +#define PI16ADC_H + +#include +#include +#include +#include + +#include + +class Pi16ADCChannel : public I2CDevice +{ + Q_OBJECT +public: + explicit Pi16ADCChannel(const QString &portName, int address, int channel, QObject *parent = nullptr); + + QByteArray readData(int fileDescriptor) override; + +private: + int m_channel = 0; +}; + +#endif // PI16ADC_H diff --git a/i2cdevices/translations/7318d45b-2eed-472c-ae08-aad56db31e28-de.ts b/i2cdevices/translations/7318d45b-2eed-472c-ae08-aad56db31e28-de.ts new file mode 100644 index 00000000..afc38b5a --- /dev/null +++ b/i2cdevices/translations/7318d45b-2eed-472c-ae08-aad56db31e28-de.ts @@ -0,0 +1,346 @@ + + + + + IntegrationPluginADConverters + + + + Failed to open I2C port. + Fehler beim Öffnen des I2C ports. + + + + adConverters + + + ADC converters + The name of the plugin adConverters ({7318d45b-2eed-472c-ae08-aad56db31e28}) + ADC Konverter + + + + ADS1113/ADS1114/ADS1115 + The name of the ThingClass ({7f285010-8bc1-4a45-b9d0-185fbac0c14d}) + ADS1113/ADS1114/ADS1115 + + + + Alchemy Power Inc. + The name of the vendor ({4625197b-96ab-4566-9425-5579a4acf4c0}) + Alchemy Powert Inc. + + + + + + + Channel 1 + The name of the ParamType (ThingClass: ads1115, EventType: channel1, ID: {2d2ca0f6-ad6c-41f5-9aa6-cd08c43fc4bc}) +---------- +The name of the StateType ({2d2ca0f6-ad6c-41f5-9aa6-cd08c43fc4bc}) of ThingClass ads1115 +---------- +The name of the ParamType (ThingClass: pi16ADC, EventType: channel1, ID: {bcb5a45f-cacb-4a74-ba81-3309875e77eb}) +---------- +The name of the StateType ({bcb5a45f-cacb-4a74-ba81-3309875e77eb}) of ThingClass pi16ADC + Kanal 1 + + + + + + Channel 1 value changed + The name of the EventType ({2d2ca0f6-ad6c-41f5-9aa6-cd08c43fc4bc}) of ThingClass ads1115 +---------- +The name of the EventType ({d52cd791-6d92-49e4-b46b-593cb0691d46}) of ThingClass pi16ADC +---------- +The name of the EventType ({bcb5a45f-cacb-4a74-ba81-3309875e77eb}) of ThingClass pi16ADC + Wert Kanal 1 geändert + + + + + Channel 10 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel10, ID: {88fa2326-76a7-40ad-921c-725d9c871ef4}) +---------- +The name of the StateType ({88fa2326-76a7-40ad-921c-725d9c871ef4}) of ThingClass pi16ADC + Kanal 10 + + + + Channel 10 value changed + The name of the EventType ({88fa2326-76a7-40ad-921c-725d9c871ef4}) of ThingClass pi16ADC + Wert Kanal 10 geändert + + + + + Channel 11 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel11, ID: {015320ae-350d-4797-a5ed-7e7f74569b7a}) +---------- +The name of the StateType ({015320ae-350d-4797-a5ed-7e7f74569b7a}) of ThingClass pi16ADC + Kanal 11 + + + + Channel 11 value changed + The name of the EventType ({015320ae-350d-4797-a5ed-7e7f74569b7a}) of ThingClass pi16ADC + Wert Kanal 11 geändert + + + + + Channel 12 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel12, ID: {096bcf38-aa9b-434f-b45d-b4164bfd4eef}) +---------- +The name of the StateType ({096bcf38-aa9b-434f-b45d-b4164bfd4eef}) of ThingClass pi16ADC + Kanal 12 + + + + Channel 12 value changed + The name of the EventType ({096bcf38-aa9b-434f-b45d-b4164bfd4eef}) of ThingClass pi16ADC + Wert Kanal 12 geändert + + + + + Channel 13 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel13, ID: {7e28eb87-87c6-4864-bfad-e457c1187d6a}) +---------- +The name of the StateType ({7e28eb87-87c6-4864-bfad-e457c1187d6a}) of ThingClass pi16ADC + Kanal 13 + + + + Channel 13 value changed + The name of the EventType ({7e28eb87-87c6-4864-bfad-e457c1187d6a}) of ThingClass pi16ADC + Wert Kanal 13 geändert + + + + + Channel 14 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel14, ID: {ea3dde63-092d-4857-b836-70016647872c}) +---------- +The name of the StateType ({ea3dde63-092d-4857-b836-70016647872c}) of ThingClass pi16ADC + Kanal 14 + + + + Channel 14 value changed + The name of the EventType ({ea3dde63-092d-4857-b836-70016647872c}) of ThingClass pi16ADC + Wert Kanal 14 geändert + + + + + Channel 15 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel15, ID: {d580d189-cb9e-446d-8a19-5c0c7891ed1b}) +---------- +The name of the StateType ({d580d189-cb9e-446d-8a19-5c0c7891ed1b}) of ThingClass pi16ADC + Kanal 15 + + + + Channel 15 value changed + The name of the EventType ({d580d189-cb9e-446d-8a19-5c0c7891ed1b}) of ThingClass pi16ADC + Wert Kanal 15 geändert + + + + + Channel 16 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel16, ID: {80fabf7c-39cb-4ff2-aa55-a7760b13b0d5}) +---------- +The name of the StateType ({80fabf7c-39cb-4ff2-aa55-a7760b13b0d5}) of ThingClass pi16ADC + Kanal 16 + + + + Channel 16 value changed + The name of the EventType ({80fabf7c-39cb-4ff2-aa55-a7760b13b0d5}) of ThingClass pi16ADC + Wert Kanal 16 geändert + + + + + + + Channel 2 + The name of the ParamType (ThingClass: ads1115, EventType: channel2, ID: {5ee7a800-a8ef-4298-aa0b-284afec75e68}) +---------- +The name of the StateType ({5ee7a800-a8ef-4298-aa0b-284afec75e68}) of ThingClass ads1115 +---------- +The name of the ParamType (ThingClass: pi16ADC, EventType: channel2, ID: {d48dab3f-cefd-4efc-a7c9-9a56d1763e5a}) +---------- +The name of the StateType ({d48dab3f-cefd-4efc-a7c9-9a56d1763e5a}) of ThingClass pi16ADC + Kanal 2 + + + + + Channel 2 value changed + The name of the EventType ({5ee7a800-a8ef-4298-aa0b-284afec75e68}) of ThingClass ads1115 +---------- +The name of the EventType ({d48dab3f-cefd-4efc-a7c9-9a56d1763e5a}) of ThingClass pi16ADC + Wert Kanal 2 geändert + + + + + + + Channel 3 + The name of the ParamType (ThingClass: ads1115, EventType: channel3, ID: {1f44b1f5-afc8-4e6e-919f-7b1d158a8b6e}) +---------- +The name of the StateType ({1f44b1f5-afc8-4e6e-919f-7b1d158a8b6e}) of ThingClass ads1115 +---------- +The name of the ParamType (ThingClass: pi16ADC, EventType: channel3, ID: {d52cd791-6d92-49e4-b46b-593cb0691d46}) +---------- +The name of the StateType ({d52cd791-6d92-49e4-b46b-593cb0691d46}) of ThingClass pi16ADC + Kanal 3 + + + + Channel 3 value changed + The name of the EventType ({1f44b1f5-afc8-4e6e-919f-7b1d158a8b6e}) of ThingClass ads1115 + Wert Kanal 3 geändert + + + + + + + Channel 4 + The name of the ParamType (ThingClass: ads1115, EventType: channel4, ID: {caba4fc0-7c06-4724-bd70-cc44b3451e17}) +---------- +The name of the StateType ({caba4fc0-7c06-4724-bd70-cc44b3451e17}) of ThingClass ads1115 +---------- +The name of the ParamType (ThingClass: pi16ADC, EventType: channel4, ID: {5a2e61c6-8934-40fb-b0ae-755563e1f01c}) +---------- +The name of the StateType ({5a2e61c6-8934-40fb-b0ae-755563e1f01c}) of ThingClass pi16ADC + Kanal 4 + + + + + Channel 4 value changed + The name of the EventType ({caba4fc0-7c06-4724-bd70-cc44b3451e17}) of ThingClass ads1115 +---------- +The name of the EventType ({5a2e61c6-8934-40fb-b0ae-755563e1f01c}) of ThingClass pi16ADC + Wert Kanal 4 geändert + + + + + Channel 5 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel5, ID: {0eeff27c-aa76-4473-9fe5-baeb94c0fc4f}) +---------- +The name of the StateType ({0eeff27c-aa76-4473-9fe5-baeb94c0fc4f}) of ThingClass pi16ADC + Kanal 5 + + + + Channel 5 value changed + The name of the EventType ({0eeff27c-aa76-4473-9fe5-baeb94c0fc4f}) of ThingClass pi16ADC + Wert Kanal 5 geändert + + + + + Channel 6 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel6, ID: {75a336da-4486-4709-830e-ac5ceafa44f7}) +---------- +The name of the StateType ({75a336da-4486-4709-830e-ac5ceafa44f7}) of ThingClass pi16ADC + Kanal 6 + + + + Channel 6 value changed + The name of the EventType ({75a336da-4486-4709-830e-ac5ceafa44f7}) of ThingClass pi16ADC + Wert Kanal 6 geändert + + + + + Channel 7 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel7, ID: {ca863478-b520-4a3f-900b-e864d2c975f2}) +---------- +The name of the StateType ({ca863478-b520-4a3f-900b-e864d2c975f2}) of ThingClass pi16ADC + Kanal 7 + + + + Channel 7 value changed + The name of the EventType ({ca863478-b520-4a3f-900b-e864d2c975f2}) of ThingClass pi16ADC + Wert Kanal 7 geändert + + + + + Channel 8 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel8, ID: {582bd216-ac59-4045-b9ec-d7922c5db52d}) +---------- +The name of the StateType ({582bd216-ac59-4045-b9ec-d7922c5db52d}) of ThingClass pi16ADC + Kanal 8 + + + + Channel 8 value changed + The name of the EventType ({582bd216-ac59-4045-b9ec-d7922c5db52d}) of ThingClass pi16ADC + Wert Kanal 8 geändert + + + + + Channel 9 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel9, ID: {fe58220c-6916-4194-9015-d948580d4daf}) +---------- +The name of the StateType ({fe58220c-6916-4194-9015-d948580d4daf}) of ThingClass pi16ADC + Kanal 9 + + + + Channel 9 value changed + The name of the EventType ({fe58220c-6916-4194-9015-d948580d4daf}) of ThingClass pi16ADC + Wert Kanal 9 geändert + + + + + I2C address + The name of the ParamType (ThingClass: ads1115, Type: thing, ID: {d3a14498-f0f4-4480-9a07-2fc8ed6fa3e9}) +---------- +The name of the ParamType (ThingClass: pi16ADC, Type: thing, ID: {97f047d2-a6dc-4d40-9235-03baa1502c61}) + I2C Adresse + + + + + I2C port + The name of the ParamType (ThingClass: ads1115, Type: thing, ID: {190c932f-5c97-497b-89b6-d34e37087467}) +---------- +The name of the ParamType (ThingClass: pi16ADC, Type: thing, ID: {1c99ab01-ccb9-4ca6-a8d9-c2c2cfafd0af}) + I2C Port + + + + Input gain + The name of the ParamType (ThingClass: ads1115, Type: thing, ID: {c1845769-636e-4744-965c-8bb0b96b80b1}) + Eingangspegel + + + + Pi-16ADC + The name of the ThingClass ({15ecc88f-cdf0-498f-b1bc-bb630bcfb3c7}) + Pi-16ADC + + + + Texas Instruments + The name of the vendor ({2edf543e-dc2c-4693-bb0c-e76c0d305fad}) + Texas Instruments + + + diff --git a/i2cdevices/translations/7318d45b-2eed-472c-ae08-aad56db31e28-en_US.ts b/i2cdevices/translations/7318d45b-2eed-472c-ae08-aad56db31e28-en_US.ts new file mode 100644 index 00000000..3c8bea90 --- /dev/null +++ b/i2cdevices/translations/7318d45b-2eed-472c-ae08-aad56db31e28-en_US.ts @@ -0,0 +1,346 @@ + + + + + IntegrationPluginADConverters + + + + Failed to open I2C port. + + + + + adConverters + + + ADC converters + The name of the plugin adConverters ({7318d45b-2eed-472c-ae08-aad56db31e28}) + + + + + ADS1113/ADS1114/ADS1115 + The name of the ThingClass ({7f285010-8bc1-4a45-b9d0-185fbac0c14d}) + + + + + Alchemy Power Inc. + The name of the vendor ({4625197b-96ab-4566-9425-5579a4acf4c0}) + + + + + + + + Channel 1 + The name of the ParamType (ThingClass: ads1115, EventType: channel1, ID: {2d2ca0f6-ad6c-41f5-9aa6-cd08c43fc4bc}) +---------- +The name of the StateType ({2d2ca0f6-ad6c-41f5-9aa6-cd08c43fc4bc}) of ThingClass ads1115 +---------- +The name of the ParamType (ThingClass: pi16ADC, EventType: channel1, ID: {bcb5a45f-cacb-4a74-ba81-3309875e77eb}) +---------- +The name of the StateType ({bcb5a45f-cacb-4a74-ba81-3309875e77eb}) of ThingClass pi16ADC + + + + + + + Channel 1 value changed + The name of the EventType ({2d2ca0f6-ad6c-41f5-9aa6-cd08c43fc4bc}) of ThingClass ads1115 +---------- +The name of the EventType ({d52cd791-6d92-49e4-b46b-593cb0691d46}) of ThingClass pi16ADC +---------- +The name of the EventType ({bcb5a45f-cacb-4a74-ba81-3309875e77eb}) of ThingClass pi16ADC + + + + + + Channel 10 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel10, ID: {88fa2326-76a7-40ad-921c-725d9c871ef4}) +---------- +The name of the StateType ({88fa2326-76a7-40ad-921c-725d9c871ef4}) of ThingClass pi16ADC + + + + + Channel 10 value changed + The name of the EventType ({88fa2326-76a7-40ad-921c-725d9c871ef4}) of ThingClass pi16ADC + + + + + + Channel 11 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel11, ID: {015320ae-350d-4797-a5ed-7e7f74569b7a}) +---------- +The name of the StateType ({015320ae-350d-4797-a5ed-7e7f74569b7a}) of ThingClass pi16ADC + + + + + Channel 11 value changed + The name of the EventType ({015320ae-350d-4797-a5ed-7e7f74569b7a}) of ThingClass pi16ADC + + + + + + Channel 12 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel12, ID: {096bcf38-aa9b-434f-b45d-b4164bfd4eef}) +---------- +The name of the StateType ({096bcf38-aa9b-434f-b45d-b4164bfd4eef}) of ThingClass pi16ADC + + + + + Channel 12 value changed + The name of the EventType ({096bcf38-aa9b-434f-b45d-b4164bfd4eef}) of ThingClass pi16ADC + + + + + + Channel 13 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel13, ID: {7e28eb87-87c6-4864-bfad-e457c1187d6a}) +---------- +The name of the StateType ({7e28eb87-87c6-4864-bfad-e457c1187d6a}) of ThingClass pi16ADC + + + + + Channel 13 value changed + The name of the EventType ({7e28eb87-87c6-4864-bfad-e457c1187d6a}) of ThingClass pi16ADC + + + + + + Channel 14 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel14, ID: {ea3dde63-092d-4857-b836-70016647872c}) +---------- +The name of the StateType ({ea3dde63-092d-4857-b836-70016647872c}) of ThingClass pi16ADC + + + + + Channel 14 value changed + The name of the EventType ({ea3dde63-092d-4857-b836-70016647872c}) of ThingClass pi16ADC + + + + + + Channel 15 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel15, ID: {d580d189-cb9e-446d-8a19-5c0c7891ed1b}) +---------- +The name of the StateType ({d580d189-cb9e-446d-8a19-5c0c7891ed1b}) of ThingClass pi16ADC + + + + + Channel 15 value changed + The name of the EventType ({d580d189-cb9e-446d-8a19-5c0c7891ed1b}) of ThingClass pi16ADC + + + + + + Channel 16 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel16, ID: {80fabf7c-39cb-4ff2-aa55-a7760b13b0d5}) +---------- +The name of the StateType ({80fabf7c-39cb-4ff2-aa55-a7760b13b0d5}) of ThingClass pi16ADC + + + + + Channel 16 value changed + The name of the EventType ({80fabf7c-39cb-4ff2-aa55-a7760b13b0d5}) of ThingClass pi16ADC + + + + + + + + Channel 2 + The name of the ParamType (ThingClass: ads1115, EventType: channel2, ID: {5ee7a800-a8ef-4298-aa0b-284afec75e68}) +---------- +The name of the StateType ({5ee7a800-a8ef-4298-aa0b-284afec75e68}) of ThingClass ads1115 +---------- +The name of the ParamType (ThingClass: pi16ADC, EventType: channel2, ID: {d48dab3f-cefd-4efc-a7c9-9a56d1763e5a}) +---------- +The name of the StateType ({d48dab3f-cefd-4efc-a7c9-9a56d1763e5a}) of ThingClass pi16ADC + + + + + + Channel 2 value changed + The name of the EventType ({5ee7a800-a8ef-4298-aa0b-284afec75e68}) of ThingClass ads1115 +---------- +The name of the EventType ({d48dab3f-cefd-4efc-a7c9-9a56d1763e5a}) of ThingClass pi16ADC + + + + + + + + Channel 3 + The name of the ParamType (ThingClass: ads1115, EventType: channel3, ID: {1f44b1f5-afc8-4e6e-919f-7b1d158a8b6e}) +---------- +The name of the StateType ({1f44b1f5-afc8-4e6e-919f-7b1d158a8b6e}) of ThingClass ads1115 +---------- +The name of the ParamType (ThingClass: pi16ADC, EventType: channel3, ID: {d52cd791-6d92-49e4-b46b-593cb0691d46}) +---------- +The name of the StateType ({d52cd791-6d92-49e4-b46b-593cb0691d46}) of ThingClass pi16ADC + + + + + Channel 3 value changed + The name of the EventType ({1f44b1f5-afc8-4e6e-919f-7b1d158a8b6e}) of ThingClass ads1115 + + + + + + + + Channel 4 + The name of the ParamType (ThingClass: ads1115, EventType: channel4, ID: {caba4fc0-7c06-4724-bd70-cc44b3451e17}) +---------- +The name of the StateType ({caba4fc0-7c06-4724-bd70-cc44b3451e17}) of ThingClass ads1115 +---------- +The name of the ParamType (ThingClass: pi16ADC, EventType: channel4, ID: {5a2e61c6-8934-40fb-b0ae-755563e1f01c}) +---------- +The name of the StateType ({5a2e61c6-8934-40fb-b0ae-755563e1f01c}) of ThingClass pi16ADC + + + + + + Channel 4 value changed + The name of the EventType ({caba4fc0-7c06-4724-bd70-cc44b3451e17}) of ThingClass ads1115 +---------- +The name of the EventType ({5a2e61c6-8934-40fb-b0ae-755563e1f01c}) of ThingClass pi16ADC + + + + + + Channel 5 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel5, ID: {0eeff27c-aa76-4473-9fe5-baeb94c0fc4f}) +---------- +The name of the StateType ({0eeff27c-aa76-4473-9fe5-baeb94c0fc4f}) of ThingClass pi16ADC + + + + + Channel 5 value changed + The name of the EventType ({0eeff27c-aa76-4473-9fe5-baeb94c0fc4f}) of ThingClass pi16ADC + + + + + + Channel 6 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel6, ID: {75a336da-4486-4709-830e-ac5ceafa44f7}) +---------- +The name of the StateType ({75a336da-4486-4709-830e-ac5ceafa44f7}) of ThingClass pi16ADC + + + + + Channel 6 value changed + The name of the EventType ({75a336da-4486-4709-830e-ac5ceafa44f7}) of ThingClass pi16ADC + + + + + + Channel 7 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel7, ID: {ca863478-b520-4a3f-900b-e864d2c975f2}) +---------- +The name of the StateType ({ca863478-b520-4a3f-900b-e864d2c975f2}) of ThingClass pi16ADC + + + + + Channel 7 value changed + The name of the EventType ({ca863478-b520-4a3f-900b-e864d2c975f2}) of ThingClass pi16ADC + + + + + + Channel 8 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel8, ID: {582bd216-ac59-4045-b9ec-d7922c5db52d}) +---------- +The name of the StateType ({582bd216-ac59-4045-b9ec-d7922c5db52d}) of ThingClass pi16ADC + + + + + Channel 8 value changed + The name of the EventType ({582bd216-ac59-4045-b9ec-d7922c5db52d}) of ThingClass pi16ADC + + + + + + Channel 9 + The name of the ParamType (ThingClass: pi16ADC, EventType: channel9, ID: {fe58220c-6916-4194-9015-d948580d4daf}) +---------- +The name of the StateType ({fe58220c-6916-4194-9015-d948580d4daf}) of ThingClass pi16ADC + + + + + Channel 9 value changed + The name of the EventType ({fe58220c-6916-4194-9015-d948580d4daf}) of ThingClass pi16ADC + + + + + + I2C address + The name of the ParamType (ThingClass: ads1115, Type: thing, ID: {d3a14498-f0f4-4480-9a07-2fc8ed6fa3e9}) +---------- +The name of the ParamType (ThingClass: pi16ADC, Type: thing, ID: {97f047d2-a6dc-4d40-9235-03baa1502c61}) + + + + + + I2C port + The name of the ParamType (ThingClass: ads1115, Type: thing, ID: {190c932f-5c97-497b-89b6-d34e37087467}) +---------- +The name of the ParamType (ThingClass: pi16ADC, Type: thing, ID: {1c99ab01-ccb9-4ca6-a8d9-c2c2cfafd0af}) + + + + + Input gain + The name of the ParamType (ThingClass: ads1115, Type: thing, ID: {c1845769-636e-4744-965c-8bb0b96b80b1}) + + + + + Pi-16ADC + The name of the ThingClass ({15ecc88f-cdf0-498f-b1bc-bb630bcfb3c7}) + + + + + Texas Instruments + The name of the vendor ({2edf543e-dc2c-4693-bb0c-e76c0d305fad}) + + + + diff --git a/nymea-plugins.pro b/nymea-plugins.pro index 6763749e..f3a4cc57 100644 --- a/nymea-plugins.pro +++ b/nymea-plugins.pro @@ -20,6 +20,7 @@ PLUGIN_DIRS = \ genericelements \ genericthings \ gpio \ + i2cdevices \ httpcommander \ keba \ kodi \