25 #include <QTextStream> 33 #define MIN_READ_INTERVAL 10000 39 m_timer.setTimerType(Qt::CoarseTimer);
40 m_timer.setSingleShot(
true);
48 if (!m_file.open(QIODevice::ReadOnly))
50 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to read device '%1' (Error #%2: '%3')")
51 .arg(m_file.fileName()).arg(m_file.error()).arg(m_file.errorString()));
58 QTextStream text(&m_file);
61 QString line = text.readLine();
62 if (!line.contains(QStringLiteral(
"crc")) || !line.contains(QStringLiteral(
"YES")))
64 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"CRC check failed for device %1").arg(m_file.fileName()));
70 line = text.readLine().trimmed();
71 int index = line.lastIndexOf(QStringLiteral(
"t="));
74 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to parse temperature for device %1").arg(m_file.fileName()));
79 line = line.mid(index + 2);
81 double temp = line.toDouble(&ok);
88 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Failed to convert temperature for device %1").arg(m_file.fileName()));
101 m_deviceName(DeviceName)
120 m_parent->
Read(0.0,
false);
128 m_deviceId(Details.value(QStringLiteral(
"wire1serial")).toString()),
129 m_readThread(this, Details.value(QStringLiteral(
"wire1serial")).toString())
131 m_readThread.start();
142 return QStringList() << tr(
"1Wire DS18B20 Temperature" ) << tr(
"Serial# %1").arg(m_deviceId);
150 double value = Value;
163 TorcInput* Create(
const QString &DeviceType,
const QVariantMap &Details)
Torc1WireReadThread(Torc1WireDS18B20 *Parent, const QString &DeviceName)
QStringList GetDescription(void) override
static TemperatureUnits GetGlobalTemperatureUnits(void)
#define MIN_READ_INTERVAL
void NewTemperature(double Value, double Valid)
void Read(double Value, bool Valid)
#define LOG(_MASK_, _LEVEL_, _STRING_)
void Start(void) override
Torc1WireDS18B20(const QVariantMap &Details)
Torc1WireDS18B20Factory Torc1WireDS18B20Factory
#define ONE_WIRE_DIRECTORY
A Torc specific wrapper around QThread.
Torc1WireReader(const QString &DeviceName)
void Finish(void) override