* Fix chart background based on theme
* Change chart history to one day based on some devices having less history.(thanks michael.hufer@gmx.de) * Have charts min/max be based on actual data received instead of hard coded values.(thanks michael.hufer@gmx.de)
This commit is contained in:
@@ -145,7 +145,7 @@ Kirigami.ApplicationWindow {
|
|||||||
Charts.ChartView {
|
Charts.ChartView {
|
||||||
id: chart
|
id: chart
|
||||||
antialiasing: true
|
antialiasing: true
|
||||||
backgroundColor: Kirigami.Theme.buttonBackgroundColor
|
backgroundColor: Kirigami.Theme.backgroundColor
|
||||||
titleColor: Kirigami.Theme.textColor
|
titleColor: Kirigami.Theme.textColor
|
||||||
legend.visible: false
|
legend.visible: false
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
@@ -169,8 +169,10 @@ Kirigami.ApplicationWindow {
|
|||||||
id: valueAx
|
id: valueAx
|
||||||
labelFormat: "%d "+units
|
labelFormat: "%d "+units
|
||||||
labelsColor: Kirigami.Theme.textColor
|
labelsColor: Kirigami.Theme.textColor
|
||||||
min: yMin
|
Component.onCompleted: {
|
||||||
max: yMax
|
valueAx.min = yMin;
|
||||||
|
valueAx.max = yMax;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
color: model.lineColor
|
color: model.lineColor
|
||||||
name: model.title
|
name: model.title
|
||||||
@@ -188,6 +190,7 @@ Kirigami.ApplicationWindow {
|
|||||||
//Readjust graphs to show date range from earliest item.
|
//Readjust graphs to show date range from earliest item.
|
||||||
dateAx.max = new Date();
|
dateAx.max = new Date();
|
||||||
dateAx.min = qiflora.model.data(qiflora.model.index(0,0));
|
dateAx.min = qiflora.model.data(qiflora.model.index(0,0));
|
||||||
|
valueAx.max = qiflora.model.maxValue(modelCol)*1.25;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
|||||||
|
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
qmlRegisterType<BluetoothDevices>();
|
qmlRegisterAnonymousType<BluetoothDevices>("",1);
|
||||||
qmlRegisterType<MiFlora>("org.eyecreate.qiflora",1,1,"QiFlora");
|
qmlRegisterType<MiFlora>("org.eyecreate.qiflora",1,1,"QiFlora");
|
||||||
engine.rootContext()->setContextProperty(QStringLiteral("appAboutData"), QVariant::fromValue(aboutData));
|
engine.rootContext()->setContextProperty(QStringLiteral("appAboutData"), QVariant::fromValue(aboutData));
|
||||||
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
|
||||||
|
|||||||
@@ -55,6 +55,14 @@ int FloraHistory::rowCount(const QModelIndex& parent) const
|
|||||||
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());
|
||||||
|
if( tableData.size() == 0 ) {
|
||||||
|
maxData = {time, temperature, brightness, moisture, conductivity};
|
||||||
|
} else {
|
||||||
|
if( maxData.temperature < temperature ) maxData.temperature = temperature;
|
||||||
|
if( maxData.brightness < brightness ) maxData.brightness = brightness;
|
||||||
|
if( maxData.moisture < moisture ) maxData.moisture = moisture;
|
||||||
|
if( maxData.conductivity < conductivity ) maxData.conductivity = conductivity;
|
||||||
|
}
|
||||||
tableData.append(flora_data{time, temperature, brightness, moisture, conductivity});
|
tableData.append(flora_data{time, temperature, brightness, moisture, conductivity});
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
@@ -65,4 +73,21 @@ void FloraHistory::clear()
|
|||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant FloraHistory::maxValue(int Column )
|
||||||
|
{
|
||||||
|
if( Column == 1 ) {
|
||||||
|
return QVariant( std::round( maxData.temperature*10/10 ));
|
||||||
|
} else if( Column == 2 ) {
|
||||||
|
return QVariant( maxData.brightness );
|
||||||
|
} else if( Column == 3 ) {
|
||||||
|
return QVariant( maxData.moisture );
|
||||||
|
} else if( Column == 4 ) {
|
||||||
|
return QVariant( maxData.conductivity );
|
||||||
|
} else if( Column == 5 ) {
|
||||||
|
return QVariant( std::round( (maxData.temperature*1.8+32)*10/10 ));
|
||||||
|
} else {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ public:
|
|||||||
|
|
||||||
void addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity);
|
void addData(QDateTime time, float temperature, quint32 brightness, quint8 moisture, quint16 conductivity);
|
||||||
|
|
||||||
|
Q_INVOKABLE QVariant maxValue(int Column);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct flora_data {
|
struct flora_data {
|
||||||
QDateTime time;
|
QDateTime time;
|
||||||
@@ -51,6 +53,7 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
QList<flora_data> tableData;
|
QList<flora_data> tableData;
|
||||||
|
flora_data maxData;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ void MiFlora::foundDevice ( const QBluetoothDeviceInfo& device )
|
|||||||
|
|
||||||
QQmlListProperty<BluetoothDevices> MiFlora::getDeviceList()
|
QQmlListProperty<BluetoothDevices> MiFlora::getDeviceList()
|
||||||
{
|
{
|
||||||
return QQmlListProperty<BluetoothDevices>(this, devices);
|
return QQmlListProperty<BluetoothDevices>(this, &devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiFlora::logControllerError ( QLowEnergyController::Error err )
|
void MiFlora::logControllerError ( QLowEnergyController::Error err )
|
||||||
@@ -175,10 +175,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 48 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 24 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 > 48) {
|
if(size > historySize) {
|
||||||
currentHistoryEntry = 48;
|
currentHistoryEntry = historySize;
|
||||||
} else {
|
} else {
|
||||||
currentHistoryEntry = size;
|
currentHistoryEntry = size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,8 @@ private:
|
|||||||
const QByteArray magicBytes = QByteArray::fromHex("a01f");
|
const QByteArray magicBytes = QByteArray::fromHex("a01f");
|
||||||
const QByteArray historyReadInit = QByteArray::fromHex("a00000");
|
const QByteArray historyReadInit = QByteArray::fromHex("a00000");
|
||||||
|
|
||||||
|
const quint16 historySize = 24;
|
||||||
|
|
||||||
float temp = 0.0;
|
float temp = 0.0;
|
||||||
quint32 bright = 0;
|
quint32 bright = 0;
|
||||||
quint8 moisture = 0;
|
quint8 moisture = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user