Clean up some old test code and make sure graphs have right paramaters to be viewed.

This commit is contained in:
2019-11-13 16:23:51 -05:00
parent 1303626dd8
commit e8d666d922
6 changed files with 76 additions and 59 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 145 KiB

View File

@@ -29,24 +29,53 @@ Kirigami.ApplicationWindow {
}
}
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 {
id: monitorView
model: ListModel {
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 {
id: card
banner {
title: model.title
title: i18n(model.title)
titleIcon: model.icon
titleLevel: 2
}
@@ -76,20 +105,33 @@ Kirigami.ApplicationWindow {
implicitWidth: 300
implicitHeight: 200
Charts.ChartView {
id: chart
antialiasing: true
backgroundColor: Kirigami.Theme.backgroundColor
backgroundColor: Kirigami.Theme.buttonBackgroundColor
titleColor: Kirigami.Theme.textColor
legend.visible: false
anchors.fill: parent
Charts.LineSeries {
id: series
axisX: Charts.DateTimeAxis {
id: dateAx
labelsColor: Kirigami.Theme.textColor
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 {
id: valueAx
labelsColor: Kirigami.Theme.textColor
min: 0
max: 50
min: yMin
max: yMax
}
color: model.lineColor
name: model.title
@@ -97,10 +139,18 @@ Kirigami.ApplicationWindow {
Charts.VXYModelMapper {
model: qiflora.model
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));
}
}
}
}
}

View File

@@ -16,12 +16,13 @@
*/
#include "florahistory.h"
#include <QDebug>
QVariant FloraHistory::data(const QModelIndex& index, int role) const
{
if(role == Qt::DisplayRole && tableData.size()-1 >= index.row()) {
if(index.column() == 0) {
return QVariant(tableData[index.row()].time.toMSecsSinceEpoch());
return QVariant(tableData[index.row()].time);
} else if(index.column() == 1) {
return QVariant(tableData[index.row()].temperature);
} else if(index.column() == 2) {
@@ -45,43 +46,14 @@ int FloraHistory::columnCount(const QModelIndex& parent) const
int FloraHistory::rowCount(const QModelIndex& parent) const
{
//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);
return tableData.size();
}
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});
//emit dataChanged(createIndex(0,0), createIndex(tableData.size()-1,4));
//endInsertRows();
emit dataChanged(createIndex(0,0),createIndex(23,4));
endInsertRows();
}
void FloraHistory::clear()

View File

@@ -31,16 +31,12 @@ class FloraHistory : public QAbstractTableModel
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 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 addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity);

View File

@@ -173,10 +173,10 @@ void MiFlora::historyServiceCharRead(QLowEnergyCharacteristic readChar, QByteArr
connect(historyService, &QLowEnergyService::characteristicRead, this, &MiFlora::historyServiceCharReadData);
disconnect(historyService, &QLowEnergyService::characteristicWritten, this, &MiFlora::historyServiceCharWritten);
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;
if(size > 24) {
currentHistoryEntry = 24;
if(size > 48) {
currentHistoryEntry = 48;
} else {
currentHistoryEntry = size;
}
@@ -225,10 +225,8 @@ void MiFlora::historyServiceCharReadData(QLowEnergyCharacteristic readChar, QByt
parser >> conduct;
QDateTime convTime;
convTime.setSecsSinceEpoch(deviceStartTime+time);
qDebug() << convTime.toString(Qt::ISODate) << temp << bright << moisture << conduct;
//Write out items to table
floraModel->addData(convTime, temp, bright, moisture, conduct);
//emit historyUpdated();
}
if(lastHistoryEntry == currentHistoryEntry) {

View File

@@ -28,8 +28,8 @@
#include <QQmlListProperty>
#include <QAbstractItemModel>
#include <QDateTime>
#include <QStandardItemModel>
#include "florahistory.h"
#include <QXYSeries>
/**
* 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(quint8 battery NOTIFY batteryChanged MEMBER battery)
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:
Q_INVOKABLE void startSearch();
Q_INVOKABLE void stopSearch();
Q_INVOKABLE void updateDataFromDevice(QString mac);
QQmlListProperty<BluetoothDevices> getDeviceList();
QAbstractTableModel* getModel();
signals:
void newDeviceFound();
void historyUpdated();
void modelUpdated();
void temperatureChanged(float temperature);
void brightnessChanged(quint32 brightness);
void moistureChanged(quint8 moisture);