Clean up some old test code and make sure graphs have right paramaters to be viewed.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 145 KiB |
@@ -30,23 +30,52 @@ Kirigami.ApplicationWindow {
|
|||||||
}
|
}
|
||||||
title: "Monitor"
|
title: "Monitor"
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
monitorTypes.append({"chartType": "temperature", "title": i18n("Temperature"), "icon": "filename-bpm-amarok", "lineColor": "red", "modelCol": 1});
|
|
||||||
monitorTypes.append({"chartType": "moisture", "title": i18n("Moisture"), "icon": "colors-chromablue", "lineColor": "cyan", "modelCol": 3});
|
|
||||||
monitorTypes.append({"chartType": "conductivity", "title": i18n("Conductivity"), "icon": "quickopen", "lineColor": "yellow", "modelCol": 4});
|
|
||||||
monitorTypes.append({"chartType": "brightness", "title": i18n("Brightness"), "icon": "contrast", "lineColor": "orange", "modelCol": 2});
|
|
||||||
}
|
|
||||||
|
|
||||||
Kirigami.CardsListView {
|
Kirigami.CardsListView {
|
||||||
id: monitorView
|
id: monitorView
|
||||||
model: ListModel {
|
model: ListModel {
|
||||||
id: monitorTypes
|
id: monitorTypes
|
||||||
|
ListElement{
|
||||||
|
chartType: "temperature"
|
||||||
|
title: "Temperature"
|
||||||
|
icon: "filename-bpm-amarok"
|
||||||
|
lineColor: "red"
|
||||||
|
yMin: -20
|
||||||
|
yMax: 40
|
||||||
|
modelCol: 1
|
||||||
|
}
|
||||||
|
ListElement{
|
||||||
|
chartType: "moisture"
|
||||||
|
title: "Moisture"
|
||||||
|
icon: "colors-chromablue"
|
||||||
|
lineColor: "cyan"
|
||||||
|
yMin: 0
|
||||||
|
yMax: 75
|
||||||
|
modelCol: 3
|
||||||
|
}
|
||||||
|
ListElement{
|
||||||
|
chartType: "conductivity"
|
||||||
|
title: "Conductivity"
|
||||||
|
icon: "quickopen"
|
||||||
|
lineColor: "gold"
|
||||||
|
yMin: 0
|
||||||
|
yMax: 6000
|
||||||
|
modelCol: 4
|
||||||
|
}
|
||||||
|
ListElement{
|
||||||
|
chartType: "brightness"
|
||||||
|
title: "Brightness"
|
||||||
|
icon: "contrast"
|
||||||
|
lineColor: "orange"
|
||||||
|
yMin: 0
|
||||||
|
yMax: 30000
|
||||||
|
modelCol: 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: Kirigami.Card {
|
delegate: Kirigami.Card {
|
||||||
id: card
|
id: card
|
||||||
banner {
|
banner {
|
||||||
title: model.title
|
title: i18n(model.title)
|
||||||
titleIcon: model.icon
|
titleIcon: model.icon
|
||||||
titleLevel: 2
|
titleLevel: 2
|
||||||
}
|
}
|
||||||
@@ -76,20 +105,33 @@ Kirigami.ApplicationWindow {
|
|||||||
implicitWidth: 300
|
implicitWidth: 300
|
||||||
implicitHeight: 200
|
implicitHeight: 200
|
||||||
Charts.ChartView {
|
Charts.ChartView {
|
||||||
|
id: chart
|
||||||
antialiasing: true
|
antialiasing: true
|
||||||
backgroundColor: Kirigami.Theme.backgroundColor
|
backgroundColor: Kirigami.Theme.buttonBackgroundColor
|
||||||
titleColor: Kirigami.Theme.textColor
|
titleColor: Kirigami.Theme.textColor
|
||||||
legend.visible: false
|
legend.visible: false
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
Charts.LineSeries {
|
Charts.LineSeries {
|
||||||
|
id: series
|
||||||
axisX: Charts.DateTimeAxis {
|
axisX: Charts.DateTimeAxis {
|
||||||
|
id: dateAx
|
||||||
labelsColor: Kirigami.Theme.textColor
|
labelsColor: Kirigami.Theme.textColor
|
||||||
format: "MMM d yyyy ha"
|
format: "MMM d yyyy ha"
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
//On load, change date span to last 24 to remove awkward 1969 empty dates.
|
||||||
|
var yesterday = new Date();
|
||||||
|
yesterday.setDate(yesterday.getDate() -1);
|
||||||
|
dateAx.min = yesterday;
|
||||||
|
dateAx.max = new Date();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
axisY: Charts.ValueAxis {
|
axisY: Charts.ValueAxis {
|
||||||
|
id: valueAx
|
||||||
labelsColor: Kirigami.Theme.textColor
|
labelsColor: Kirigami.Theme.textColor
|
||||||
min: 0
|
min: yMin
|
||||||
max: 50
|
max: yMax
|
||||||
}
|
}
|
||||||
color: model.lineColor
|
color: model.lineColor
|
||||||
name: model.title
|
name: model.title
|
||||||
@@ -97,10 +139,18 @@ Kirigami.ApplicationWindow {
|
|||||||
Charts.VXYModelMapper {
|
Charts.VXYModelMapper {
|
||||||
model: qiflora.model
|
model: qiflora.model
|
||||||
xColumn: 0
|
xColumn: 0
|
||||||
yColumn: 1
|
yColumn: modelCol
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Connections {
|
||||||
|
target: qiflora.model
|
||||||
|
onRowsInserted: {
|
||||||
|
//Readjust graphs to show date range from earliest item.
|
||||||
|
dateAx.max = new Date();
|
||||||
|
dateAx.min = qiflora.model.data(qiflora.model.index(0,0));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "florahistory.h"
|
#include "florahistory.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
QVariant FloraHistory::data(const QModelIndex& index, int role) const
|
QVariant FloraHistory::data(const QModelIndex& index, int role) const
|
||||||
{
|
{
|
||||||
if(role == Qt::DisplayRole && tableData.size()-1 >= index.row()) {
|
if(role == Qt::DisplayRole && tableData.size()-1 >= index.row()) {
|
||||||
if(index.column() == 0) {
|
if(index.column() == 0) {
|
||||||
return QVariant(tableData[index.row()].time.toMSecsSinceEpoch());
|
return QVariant(tableData[index.row()].time);
|
||||||
} else if(index.column() == 1) {
|
} else if(index.column() == 1) {
|
||||||
return QVariant(tableData[index.row()].temperature);
|
return QVariant(tableData[index.row()].temperature);
|
||||||
} else if(index.column() == 2) {
|
} else if(index.column() == 2) {
|
||||||
@@ -45,43 +46,14 @@ int FloraHistory::columnCount(const QModelIndex& parent) const
|
|||||||
|
|
||||||
int FloraHistory::rowCount(const QModelIndex& parent) const
|
int FloraHistory::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
//return tableData.size();
|
return tableData.size();
|
||||||
return 23;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant FloraHistory::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
|
||||||
if(role == Qt::DisplayRole) {
|
|
||||||
if(section == 0) {
|
|
||||||
return QVariant("Time");
|
|
||||||
} else if(section == 1) {
|
|
||||||
return QVariant("Temperature");
|
|
||||||
} else if(section == 2) {
|
|
||||||
return QVariant("Brightness");
|
|
||||||
} else if(section == 3) {
|
|
||||||
return QVariant("Moisture");
|
|
||||||
} else if(section == 4) {
|
|
||||||
return QVariant("Conductivity");
|
|
||||||
} else {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Qt::ItemFlags FloraHistory::flags(const QModelIndex& index) const
|
|
||||||
{
|
|
||||||
return QAbstractTableModel::flags(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloraHistory::addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity)
|
void FloraHistory::addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity)
|
||||||
{
|
{
|
||||||
//beginInsertRows(QModelIndex(),tableData.size(),tableData.size());
|
beginInsertRows(QModelIndex(),tableData.size(),tableData.size());
|
||||||
tableData.append(flora_data{time, temperature, brightness, moisture, conductivity});
|
tableData.append(flora_data{time, temperature, brightness, moisture, conductivity});
|
||||||
//emit dataChanged(createIndex(0,0), createIndex(tableData.size()-1,4));
|
endInsertRows();
|
||||||
//endInsertRows();
|
|
||||||
emit dataChanged(createIndex(0,0),createIndex(23,4));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FloraHistory::clear()
|
void FloraHistory::clear()
|
||||||
|
|||||||
@@ -31,16 +31,12 @@ class FloraHistory : public QAbstractTableModel
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
QVariant data(const QModelIndex& index, int role) const override;
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
int columnCount(const QModelIndex& parent) const override;
|
int columnCount(const QModelIndex& parent) const override;
|
||||||
|
|
||||||
int rowCount(const QModelIndex& parent) const override;
|
int rowCount(const QModelIndex& parent) const override;
|
||||||
|
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex & index) const override;
|
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity);
|
void addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity);
|
||||||
|
|||||||
@@ -173,10 +173,10 @@ void MiFlora::historyServiceCharRead(QLowEnergyCharacteristic readChar, QByteArr
|
|||||||
connect(historyService, &QLowEnergyService::characteristicRead, this, &MiFlora::historyServiceCharReadData);
|
connect(historyService, &QLowEnergyService::characteristicRead, this, &MiFlora::historyServiceCharReadData);
|
||||||
disconnect(historyService, &QLowEnergyService::characteristicWritten, this, &MiFlora::historyServiceCharWritten);
|
disconnect(historyService, &QLowEnergyService::characteristicWritten, this, &MiFlora::historyServiceCharWritten);
|
||||||
connect(historyService, &QLowEnergyService::characteristicWritten, this, &MiFlora::historyServiceCharWrittenData);
|
connect(historyService, &QLowEnergyService::characteristicWritten, this, &MiFlora::historyServiceCharWrittenData);
|
||||||
//Take size given and start by giving the last 24 numbers(if that many) to represent the last day of data. TODO: look to have amount of time be configurable.
|
//Take size given and start by giving the last 48 numbers(if that many) to represent the last day of data. TODO: look to have amount of time be configurable.
|
||||||
lastHistoryEntry = 0;
|
lastHistoryEntry = 0;
|
||||||
if(size > 24) {
|
if(size > 48) {
|
||||||
currentHistoryEntry = 24;
|
currentHistoryEntry = 48;
|
||||||
} else {
|
} else {
|
||||||
currentHistoryEntry = size;
|
currentHistoryEntry = size;
|
||||||
}
|
}
|
||||||
@@ -225,10 +225,8 @@ void MiFlora::historyServiceCharReadData(QLowEnergyCharacteristic readChar, QByt
|
|||||||
parser >> conduct;
|
parser >> conduct;
|
||||||
QDateTime convTime;
|
QDateTime convTime;
|
||||||
convTime.setSecsSinceEpoch(deviceStartTime+time);
|
convTime.setSecsSinceEpoch(deviceStartTime+time);
|
||||||
qDebug() << convTime.toString(Qt::ISODate) << temp << bright << moisture << conduct;
|
|
||||||
//Write out items to table
|
//Write out items to table
|
||||||
floraModel->addData(convTime, temp, bright, moisture, conduct);
|
floraModel->addData(convTime, temp, bright, moisture, conduct);
|
||||||
//emit historyUpdated();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lastHistoryEntry == currentHistoryEntry) {
|
if(lastHistoryEntry == currentHistoryEntry) {
|
||||||
|
|||||||
@@ -28,8 +28,8 @@
|
|||||||
#include <QQmlListProperty>
|
#include <QQmlListProperty>
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QStandardItemModel>
|
|
||||||
#include "florahistory.h"
|
#include "florahistory.h"
|
||||||
|
#include <QXYSeries>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class using QtBluetooth to find and retrive info from Mi Flora devices.
|
* Class using QtBluetooth to find and retrive info from Mi Flora devices.
|
||||||
@@ -43,19 +43,20 @@ class MiFlora : public QObject
|
|||||||
Q_PROPERTY(quint16 conduction NOTIFY conductionChanged MEMBER conduct)
|
Q_PROPERTY(quint16 conduction NOTIFY conductionChanged MEMBER conduct)
|
||||||
Q_PROPERTY(quint8 battery NOTIFY batteryChanged MEMBER battery)
|
Q_PROPERTY(quint8 battery NOTIFY batteryChanged MEMBER battery)
|
||||||
Q_PROPERTY(QQmlListProperty<BluetoothDevices> devices READ getDeviceList NOTIFY newDeviceFound)
|
Q_PROPERTY(QQmlListProperty<BluetoothDevices> devices READ getDeviceList NOTIFY newDeviceFound)
|
||||||
Q_PROPERTY(QAbstractTableModel* model READ getModel NOTIFY historyUpdated)
|
Q_PROPERTY(QAbstractTableModel* model READ getModel NOTIFY modelUpdated)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE void startSearch();
|
Q_INVOKABLE void startSearch();
|
||||||
Q_INVOKABLE void stopSearch();
|
Q_INVOKABLE void stopSearch();
|
||||||
|
|
||||||
Q_INVOKABLE void updateDataFromDevice(QString mac);
|
Q_INVOKABLE void updateDataFromDevice(QString mac);
|
||||||
|
|
||||||
QQmlListProperty<BluetoothDevices> getDeviceList();
|
QQmlListProperty<BluetoothDevices> getDeviceList();
|
||||||
QAbstractTableModel* getModel();
|
QAbstractTableModel* getModel();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void newDeviceFound();
|
void newDeviceFound();
|
||||||
void historyUpdated();
|
void modelUpdated();
|
||||||
void temperatureChanged(float temperature);
|
void temperatureChanged(float temperature);
|
||||||
void brightnessChanged(quint32 brightness);
|
void brightnessChanged(quint32 brightness);
|
||||||
void moistureChanged(quint8 moisture);
|
void moistureChanged(quint8 moisture);
|
||||||
|
|||||||
Reference in New Issue
Block a user