Much appreciated for clarifying that... and after adding your code and trying I still couldn't see anything in the main.qml.
I'm using the "double oil_pressure_volt" in my serialport.cpp code below, it takes my 10 bit analog input and turns it into a voltage reading. Would I be better doing the conversion in the qml?
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
SerialPort serialport;
qmlRegisterType<SerialPort>("SerialPortlib", 1, 0, "SerialPort");
engine.
load(QUrl(QStringLiteral
("qrc:/main.qml")));
return app.exec();
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
SerialPort serialport;
qmlRegisterType<SerialPort>("SerialPortlib", 1, 0, "SerialPort");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
To copy to clipboard, switch view to plain text mode
{
Q_OBJECT
Q_PROPERTY( double oilPressureVoltage MEMBER m_oil_pressure_volt WRITE set_oil_pressure_volt NOTIFY oil_pressure_volt_Changed )
public:
public slots:
void analogRead2();
void set_oil_pressure_volt(double oilPressureVoltage)
{
if (m_oilPressureVoltage == oilPressureVoltage)
return;
m_oilPressureVoltage = oilPressureVoltage;
emit oil_pressure_volt_Changed(oilPressureVoltage);
}
signals:
void oil_pressure_volt_Changed(double oilPressureVoltage);
private:
QSerialPort *arduino;
static const quint16 arduino_uno_vendor_id = 0x2341;
static const quint16 arduino_uno_product_id = 0x0001;
double oil_pressure_volt;
double m_oilPressureVoltage;
};
#endif // SERIALPORT_H
class SerialPort : public QObject
{
Q_OBJECT
Q_PROPERTY( double oilPressureVoltage MEMBER m_oil_pressure_volt WRITE set_oil_pressure_volt NOTIFY oil_pressure_volt_Changed )
public:
SerialPort(QObject *parent = 0);
SerialPort(QString);
public slots:
void analogRead2();
void updateOilPressure(QString);
void set_oil_pressure_volt(double oilPressureVoltage)
{
if (m_oilPressureVoltage == oilPressureVoltage)
return;
m_oilPressureVoltage = oilPressureVoltage;
emit oil_pressure_volt_Changed(oilPressureVoltage);
}
signals:
void oil_pressure_volt_Changed(double oilPressureVoltage);
private:
QSerialPort *arduino;
static const quint16 arduino_uno_vendor_id = 0x2341;
static const quint16 arduino_uno_product_id = 0x0001;
QByteArray serialData;
QString serialBuffer;
QString parsed_data;
double oil_pressure_volt;
double m_oilPressureVoltage;
};
#endif // SERIALPORT_H
To copy to clipboard, switch view to plain text mode
void SerialPort::analogRead2()
{
if(buffer_split.length() < 3)
{
serialData = arduino->readAll();
serialBuffer
= serialBuffer
+ QString::fromStdString(serialData.
toStdString());
serialData.clear();
}else{
serialBuffer = "";
qDebug() << buffer_split << "\n";
parsed_data = buffer_split[1];
oil_pressure_volt = (0.0048) * (parsed_data.toDouble());
qDebug() << "Pressure: " << oil_pressure_volt << "\n";
}
void SerialPort::analogRead2()
{
QStringList buffer_split = serialBuffer.split(",");
if(buffer_split.length() < 3)
{
serialData = arduino->readAll();
serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
serialData.clear();
}else{
serialBuffer = "";
qDebug() << buffer_split << "\n";
parsed_data = buffer_split[1];
oil_pressure_volt = (0.0048) * (parsed_data.toDouble());
qDebug() << "Pressure: " << oil_pressure_volt << "\n";
}
To copy to clipboard, switch view to plain text mode
import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Extras 1.4
import QtQuick.Controls 2.0
import SerialPortlib 1.0
Window {
id: gauge
visible: true
width: 640
height: 480
TextField {
id: textField
x: 250
y: 280
text: SerialPort.oilPressureVoltage
}
}
import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Extras 1.4
import QtQuick.Controls 2.0
import SerialPortlib 1.0
Window {
id: gauge
visible: true
width: 640
height: 480
TextField {
id: textField
x: 250
y: 280
text: SerialPort.oilPressureVoltage
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks