Link bluetooth.
Implement class that talks to BLE miflora devices. Have UI show current values from new class.
This commit is contained in:
83
src/miflora/miflora.h
Normal file
83
src/miflora/miflora.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Kevin Whitaker <eyecreate@eyecreate.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MIFLORA_H
|
||||
#define MIFLORA_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtBluetooth/QBluetoothDeviceDiscoveryAgent>
|
||||
#include <QtBluetooth/QBluetoothDeviceInfo>
|
||||
#include <QtBluetooth/QLowEnergyController>
|
||||
#include <QtBluetooth/QLowEnergyService>
|
||||
#include <QtBluetooth/QLowEnergyCharacteristic>
|
||||
|
||||
/**
|
||||
* Class using QtBluetooth to find and retrive info from Mi Flora devices.
|
||||
*/
|
||||
class MiFlora : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(float temperature NOTIFY temperatureChanged MEMBER temp)
|
||||
Q_PROPERTY(quint32 brightness NOTIFY brightnessChanged MEMBER bright)
|
||||
Q_PROPERTY(quint8 moisture NOTIFY moistureChanged MEMBER moisture)
|
||||
Q_PROPERTY(quint16 conduction NOTIFY conductionChanged MEMBER conduct)
|
||||
Q_PROPERTY(quint8 battery NOTIFY batteryChanged MEMBER battery)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE void startSearch();
|
||||
Q_INVOKABLE void stopSearch();
|
||||
|
||||
Q_INVOKABLE void updateDataFromDevice(QString mac);
|
||||
//TODO:History?
|
||||
|
||||
signals:
|
||||
void newDeviceFound(QString name, QString address);
|
||||
void temperatureChanged(float temperature);
|
||||
void brightnessChanged(quint32 brightness);
|
||||
void moistureChanged(quint8 moisture);
|
||||
void conductionChanged(quint16 conduction);
|
||||
void batteryChanged(quint8 battery);
|
||||
|
||||
private:
|
||||
void foundDevice(const QBluetoothDeviceInfo &device);
|
||||
void serviceDiscovered(const QBluetoothUuid &gatt);
|
||||
void logControllerError(QLowEnergyController::Error err);
|
||||
void logServiceError(QLowEnergyService::ServiceError err);
|
||||
void serviceStateChanges(QLowEnergyService::ServiceState state);
|
||||
void serviceCharWritten(QLowEnergyCharacteristic changedChar, QByteArray value);
|
||||
void serviceCharRead(QLowEnergyCharacteristic readChar, QByteArray value);
|
||||
|
||||
QBluetoothDeviceDiscoveryAgent *agent;
|
||||
QList<QBluetoothDeviceInfo> devices;
|
||||
QLowEnergyController *currentController;
|
||||
QLowEnergyService *sensorService;
|
||||
|
||||
const quint16 dataService = 4612; //0x1204
|
||||
const quint16 batteryFirmwareChar = 6658;//0x1a02
|
||||
const quint16 sensorsChar = 6657; //0x1a01
|
||||
const quint16 magicChar = 6656; //0x1a00
|
||||
|
||||
float temp = 0.0;
|
||||
quint32 bright = 0;
|
||||
quint8 moisture = 0;
|
||||
quint16 conduct = 0;
|
||||
quint8 battery = 0;
|
||||
QString version;
|
||||
|
||||
};
|
||||
|
||||
#endif // MIFLORA_H
|
||||
Reference in New Issue
Block a user