Compare commits

...

3 Commits

Author SHA1 Message Date
Roberto Viola
b73003316d power chart works! 2021-03-29 09:43:30 +02:00
Roberto Viola
2bbbd0b9bf rolling chart with zones. Issue on left margin 2021-03-28 14:26:20 +02:00
Roberto Viola
1f03a5e10b realtime chart works! 2021-03-27 18:08:51 +01:00
8 changed files with 249 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ HomeForm{
Settings {
id: settings
property real ui_zoom: 100.0
property bool chart_footer: true
}
Popup {
@@ -53,6 +54,45 @@ HomeForm{
onTriggered: popupLap.close();
}
Timer {
id: refreshChartTimer
interval: 500
running: true
repeat: true
property int timeline: 0
onTriggered: {
if(settings.chart_footer) chartView.height = 130 * settings.ui_zoom / 100; else chartView.height = 0;
if(rootItem.labelHelp || rootItem.wattMax === 0 || !settings.chart_footer) return;
series1.upperSeries.append(timeline, rootItem.wattZ1);
series2.upperSeries.append(timeline, rootItem.wattZ2);
series3.upperSeries.append(timeline, rootItem.wattZ3);
series4.upperSeries.append(timeline, rootItem.wattZ4);
series5.upperSeries.append(timeline, rootItem.wattZ5);
series6.upperSeries.append(timeline, rootItem.wattZ6);
series7.upperSeries.append(timeline, rootItem.wattZ7);
series1.axisX.min = (timeline - 60 > 0) ? timeline - 60 : 0;
series2.axisX.min = (timeline - 60 > 0) ? timeline - 60 : 0;
series3.axisX.min = (timeline - 60 > 0) ? timeline - 60 : 0;
series4.axisX.min = (timeline - 60 > 0) ? timeline - 60 : 0;
series5.axisX.min = (timeline - 60 > 0) ? timeline - 60 : 0;
series6.axisX.min = (timeline - 60 > 0) ? timeline - 60 : 0;
series7.axisX.min = (timeline - 60 > 0) ? timeline - 60 : 0;
series1.axisX.max = (timeline - 60 > 0) ? timeline : 60;
series2.axisX.max = (timeline - 60 > 0) ? timeline : 60;
series3.axisX.max = (timeline - 60 > 0) ? timeline : 60;
series4.axisX.max = (timeline - 60 > 0) ? timeline : 60;
series5.axisX.max = (timeline - 60 > 0) ? timeline : 60;
series6.axisX.max = (timeline - 60 > 0) ? timeline : 60;
series7.axisX.max = (timeline - 60 > 0) ? timeline : 60;
/*series1.append(1, 5);
series1.append(2, 50);
series1.append(3, 500);*/
//rootItem.dataSource.update(chartView.series(0));
//console.log("refreshChartTimer" + timeline);
timeline++;
}
}
start.onClicked: { start_clicked(); }
stop.onClicked: { stop_clicked(); }
lap.onClicked: { lap_clicked(); popupLap.open(); popupLapAutoClose.running = true; }
@@ -61,9 +101,9 @@ HomeForm{
GridView {
anchors.horizontalCenter: parent.horizontalCenter
anchors.fill: parent
cellWidth: 175 * settings.ui_zoom / 100
cellHeight: 130 * settings.ui_zoom / 100
anchors.fill: parent
focus: true
model: appModel
leftMargin: { (parent.width % cellWidth) / 2 }
@@ -115,7 +155,7 @@ HomeForm{
id: myIcon
x: 5
anchors {
bottom: id1.bottom
bottom: id1.bottom
}
width: 48 * settings.ui_zoom / 100
height: 48 * settings.ui_zoom / 100
@@ -154,7 +194,7 @@ HomeForm{
top: myIcon.top
}
font.bold: true
font.pointSize: labelFontSize
font.pointSize: labelFontSize
color: "white"
text: name
anchors.left: parent.left

View File

@@ -2,6 +2,7 @@ import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Controls.Material 2.12
import QtGraphicalEffects 1.12
import QtCharts 2.15
Page {
@@ -13,6 +14,15 @@ Page {
property alias lap: lap
property alias row: row
property alias chartView: chartView
property alias series1: series1
property alias series2: series2
property alias series3: series3
property alias series4: series4
property alias series5: series5
property alias series6: series6
property alias series7: series7
Item {
width: parent.width
height: rootItem.topBarHeight
@@ -161,6 +171,112 @@ Page {
visible: rootItem.labelHelp
}
}
footer:
ChartView {
id: chartView
backgroundColor: Material.backgroundColor
margins.bottom: 0
margins.left: 0
margins.right: 0
margins.top: 0
plotAreaColor: Material.backgroundColor
//title: "Spline"
//anchors.top: gridView.bottom
antialiasing: true
legend.visible: false
width: stackView.width
//Label.visible: false
//visible: settings.chart_footer
ValueAxis {
id: valueAxisX
min: 0
max: 60
tickCount: 60
labelFormat: "%.0f"
labelsVisible: false
gridVisible: false
lineVisible: false
}
ValueAxis {
id: valueAxisY
min: 0
max: rootItem.wattMax
//tickCount: 60
labelFormat: "%.0f"
labelsVisible: false
gridVisible: false
lineVisible: false
titleVisible: false
}
AreaSeries {
id: series1
useOpenGL: true
axisX: valueAxisX
axisY: valueAxisY
name: "Z1"
color: "white"
borderColor: color
upperSeries: LineSeries {}
}
AreaSeries {
id: series2
useOpenGL: true
axisX: valueAxisX
axisY: valueAxisY
color: "limegreen"
borderColor: color
upperSeries: LineSeries {}
}
AreaSeries {
id: series3
useOpenGL: true
axisX: valueAxisX
axisY: valueAxisY
color: "gold"
borderColor: color
upperSeries: LineSeries {}
}
AreaSeries {
id: series4
useOpenGL: true
axisX: valueAxisX
axisY: valueAxisY
color: "orange"
borderColor: color
upperSeries: LineSeries {}
}
AreaSeries {
id: series5
useOpenGL: true
axisX: valueAxisX
axisY: valueAxisY
color: "darkorange"
borderColor: color
upperSeries: LineSeries {}
}
AreaSeries {
id: series6
useOpenGL: true
axisX: valueAxisX
axisY: valueAxisY
color: "orangered"
borderColor: color
upperSeries: LineSeries {}
}
AreaSeries {
id: series7
useOpenGL: true
axisX: valueAxisX
axisY: valueAxisY
color: "red"
borderColor: color
upperSeries: LineSeries {}
}
}
}
/*##^##

View File

@@ -149,6 +149,8 @@ void bluetooth::deviceDiscovered(const QBluetoothDeviceInfo &device)
heartRateBeltFound = heartRateBeltAvaiable();
}
if(!device.name().length()) return;
bool found = false;
QMutableListIterator<QBluetoothDeviceInfo> i(devices);
while (i.hasNext()) {
@@ -261,7 +263,7 @@ void bluetooth::deviceDiscovered(const QBluetoothDeviceInfo &device)
emit searchingStop();
}
else if(b.name().startsWith("ECH") && !echelonConnectSport && filter)
{
{
discoveryAgent->stop();
echelonConnectSport = new echelonconnectsport(noWriteResistance, noHeartService, bikeResistanceOffset, bikeResistanceGain);
//stateFileRead();

View File

@@ -896,13 +896,23 @@ void homeform::update()
QString ftpMinW = "0";
QString ftpMaxW = "0";
if(ftpSetting > 0)
{
ftpPerc = (watts / ftpSetting) * 100.0;
m_wattZ1Max = ftpSetting * 0.54;
m_wattZ2Max = ftpSetting * 0.75;
m_wattZ3Max = ftpSetting * 0.90;
m_wattZ4Max = ftpSetting * 1.05;
m_wattZ5Max = ftpSetting * 1.20;
m_wattZ6Max = ftpSetting * 1.50;
}
if(ftpPerc < 55)
{
ftpMinW = QString::number(0, 'f', 0);
ftpMaxW = QString::number(ftpSetting * 0.54, 'f', 0);
ftpZone = 1;
ftp->setValueFontColor("white");
m_wattZ2 = m_wattZ3 = m_wattZ4 = m_wattZ5 = m_wattZ6 = m_wattZ7 = 0;
m_wattZ1 = watts;
}
else if(ftpPerc < 76)
{
@@ -910,6 +920,8 @@ void homeform::update()
ftpMaxW = QString::number(ftpSetting * 0.75, 'f', 0);
ftpZone = 2;
ftp->setValueFontColor("limegreen");
m_wattZ3 = m_wattZ4 = m_wattZ5 = m_wattZ6 = m_wattZ7 = 0;
m_wattZ2 = watts;
}
else if(ftpPerc < 91)
{
@@ -917,6 +929,8 @@ void homeform::update()
ftpMaxW = QString::number(ftpSetting * 0.90, 'f', 0);
ftpZone = 3;
ftp->setValueFontColor("gold");
m_wattZ4 = m_wattZ5 = m_wattZ6 = m_wattZ7 = 0;
m_wattZ3 = watts;
}
else if(ftpPerc < 106)
{
@@ -924,6 +938,8 @@ void homeform::update()
ftpMaxW = QString::number(ftpSetting * 1.05, 'f', 0);
ftpZone = 4;
ftp->setValueFontColor("orange");
m_wattZ5 = m_wattZ6 = m_wattZ7 = 0;
m_wattZ4 = watts;
}
else if(ftpPerc < 121)
{
@@ -931,6 +947,8 @@ void homeform::update()
ftpMaxW = QString::number(ftpSetting * 1.20, 'f', 0);
ftpZone = 5;
ftp->setValueFontColor("darkorange");
m_wattZ6 = m_wattZ7 = 0;
m_wattZ5 = watts;
}
else if(ftpPerc < 151)
{
@@ -938,6 +956,8 @@ void homeform::update()
ftpMaxW = QString::number(ftpSetting * 1.50, 'f', 0);
ftpZone = 6;
ftp->setValueFontColor("orangered");
m_wattZ7 = 0;
m_wattZ6 = watts;
}
else
{
@@ -945,10 +965,13 @@ void homeform::update()
ftpMaxW = "";
ftpZone = 7;
ftp->setValueFontColor("red");
m_wattZ7 = watts;
}
ftp->setValue("Z" + QString::number(ftpZone, 'f', 0));
ftp->setSecondLine(ftpMinW + "-" + ftpMaxW + "W " + QString::number(ftpPerc, 'f', 0) + "%");
emit wattMaxChanged(bluetoothManager->device()->wattsMetric().max());
QString Z;
double maxHeartRate = 220.0 - settings.value("age", 35).toDouble();
if(maxHeartRate == 0) maxHeartRate = 190.0;
@@ -1078,7 +1101,7 @@ void homeform::update()
}
emit changeOfdevice();
emit changeOflap();
emit changeOflap();
}
bool homeform::getDevice()

View File

@@ -88,11 +88,39 @@ class homeform: public QObject
Q_PROPERTY(QStringList bluetoothDevices READ bluetoothDevices NOTIFY bluetoothDevicesChanged)
Q_PROPERTY(QStringList tile_order READ tile_order NOTIFY tile_orderChanged)
Q_PROPERTY(bool generalPopupVisible READ generalPopupVisible NOTIFY generalPopupVisibleChanged WRITE setGeneralPopupVisible)
Q_PROPERTY(double wattZ1 READ wattZ1)
Q_PROPERTY(double wattZ2 READ wattZ2)
Q_PROPERTY(double wattZ3 READ wattZ3)
Q_PROPERTY(double wattZ4 READ wattZ4)
Q_PROPERTY(double wattZ5 READ wattZ5)
Q_PROPERTY(double wattZ6 READ wattZ6)
Q_PROPERTY(double wattZ7 READ wattZ7)
Q_PROPERTY(double wattZ1Max READ wattZ1Max)
Q_PROPERTY(double wattZ2Max READ wattZ2Max)
Q_PROPERTY(double wattZ3Max READ wattZ3Max)
Q_PROPERTY(double wattZ4Max READ wattZ4Max)
Q_PROPERTY(double wattZ5Max READ wattZ5Max)
Q_PROPERTY(double wattZ6Max READ wattZ6Max)
Q_PROPERTY(double wattMax READ wattMax NOTIFY wattMaxChanged)
public:
homeform(QQmlApplicationEngine* engine, bluetooth* bl);
~homeform();
int topBarHeight() {return m_topBarHeight;}
double wattZ1() {return m_wattZ1;}
double wattZ2() {return m_wattZ2;}
double wattZ3() {return m_wattZ3;}
double wattZ4() {return m_wattZ4;}
double wattZ5() {return m_wattZ5;}
double wattZ6() {return m_wattZ6;}
double wattZ7() {return m_wattZ7;}
double wattZ1Max() {return m_wattZ1Max;}
double wattZ2Max() {return m_wattZ2Max;}
double wattZ3Max() {return m_wattZ3Max;}
double wattZ4Max() {return m_wattZ4Max;}
double wattZ5Max() {return m_wattZ5Max;}
double wattZ6Max() {return m_wattZ6Max;}
double wattMax() {if(bluetoothManager && bluetoothManager->device()) return bluetoothManager->device()->wattsMetric().max(); else return 0;}
QString info() {return m_info;}
QString signal();
QString startText();
@@ -122,6 +150,21 @@ private:
QOAuth2AuthorizationCodeFlow* strava;
QNetworkAccessManager* manager = 0;
//charts
double m_wattZ1 = 0;
double m_wattZ2 = 0;
double m_wattZ3 = 0;
double m_wattZ4 = 0;
double m_wattZ5 = 0;
double m_wattZ6 = 0;
double m_wattZ7 = 0;
double m_wattZ1Max = 0;
double m_wattZ2Max = 0;
double m_wattZ3Max = 0;
double m_wattZ4Max = 0;
double m_wattZ5Max = 0;
double m_wattZ6Max = 0;
bool paused = false;
bool stopped = false;
bool lapTrigger = false;
@@ -205,6 +248,7 @@ signals:
void tile_orderChanged(QStringList value);
void changeLabelHelp(bool value);
void generalPopupVisibleChanged(bool value);
void wattMaxChanged(double value);
};
#endif // HOMEFORM_H

View File

@@ -126,7 +126,7 @@ QCoreApplication* createApplication(int &argc, char *argv[])
if(nogui)
return new QCoreApplication(argc, argv);
else if(forceQml)
return new QGuiApplication(argc, argv);
return new QApplication(argc, argv);
else
{
QApplication* a = new QApplication(argc, argv);
@@ -238,7 +238,7 @@ int main(int argc, char *argv[])
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
#else
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QScopedPointer<QGuiApplication> app(new QGuiApplication(argc, argv));
QScopedPointer<QApplication> app(new QApplication(argc, argv));
#endif
app->setOrganizationName("Roberto Viola");

View File

@@ -1,6 +1,6 @@
QT += bluetooth widgets xml positioning quick networkauth
!ios: QT+= charts
QT+= charts
unix:android: QT += androidextras gui-private
CONFIG += c++11 console debug app_bundle

View File

@@ -14,6 +14,7 @@ import Qt.labs.settings 1.0
Settings {
id: settings
property real ui_zoom: 100.0
property bool chart_footer: true
property bool bike_heartrate_service: false
property int bike_resistance_offset: 4
property real bike_resistance_gain_f: 1.0
@@ -180,6 +181,21 @@ import Qt.labs.settings 1.0
}
}
SwitchDelegate {
id: chartFooterDelegate
text: qsTr("Realtime Chart")
spacing: 0
bottomPadding: 0
topPadding: 0
rightPadding: 0
leftPadding: 0
clip: false
checked: settings.chart_footer
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillWidth: true
onClicked: settings.chart_footer = checked
}
RowLayout {
spacing: 10
Label {