├── speedometer ├── libwiringPi.so ├── qml.qrc ├── main.qml ├── speedometer.pro ├── speedometer.h ├── main.cpp ├── speedometer.cpp └── speedometer.pro.user └── QtMqttRaspberryPiEsp8266 ├── mqttRaspExample ├── qml.qrc ├── main.cpp ├── mqtt.h ├── mqttRaspExample.pro ├── mqtt.cpp ├── main.qml └── mqttRaspExample.pro.user ├── Readme.md └── mqtt_example └── mqtt_example.ino /speedometer/libwiringPi.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PhysicsX/QtRaspberryPiExamples/HEAD/speedometer/libwiringPi.so -------------------------------------------------------------------------------- /speedometer/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /QtMqttRaspberryPiEsp8266/mqttRaspExample/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | 5 | 6 | -------------------------------------------------------------------------------- /QtMqttRaspberryPiEsp8266/Readme.md: -------------------------------------------------------------------------------- 1 | # QtMqtt Raspberry pi - Esp8266 2 | 3 | Example of how to implement mqtt with qt using raspberry pi and also esp8266 4 | 5 | [![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/OLZjdjUlp9M/0.jpg)](//www.youtube.com/watch?v=OLZjdjUlp9M?t=0s "ulas dikme") 6 | 7 | ## Installation 8 | 9 | Choose correct qtmqtt version according to your qt version. 10 | 11 | ```bash 12 | qmake 13 | make 14 | make install 15 | ``` 16 | This will install qtmqtt libraries to your sysroot file. You should sync with your target device. ( target is raspbery pi here ) 17 | 18 | 19 | -------------------------------------------------------------------------------- /QtMqttRaspberryPiEsp8266/mqttRaspExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mqtt.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 8 | 9 | QGuiApplication app(argc, argv); 10 | 11 | qmlRegisterType("com.ulasdikme.mqtt",1,0,"Mqtt"); 12 | 13 | QQmlApplicationEngine engine; 14 | const QUrl url(QStringLiteral("qrc:/main.qml")); 15 | QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, 16 | &app, [url](QObject *obj, const QUrl &objUrl) { 17 | if (!obj && url == objUrl) 18 | QCoreApplication::exit(-1); 19 | }, Qt::QueuedConnection); 20 | engine.load(url); 21 | 22 | return app.exec(); 23 | } 24 | -------------------------------------------------------------------------------- /speedometer/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.9 2 | import QtQuick.Window 2.2 3 | import com.ulasdikme.speedometer 1.0 4 | import QtQuick.Controls 2.0 5 | import QtQuick.Controls 1.2 6 | import QtQuick.Layouts 1.1 7 | 8 | Window { 9 | visible: true 10 | width: 640 11 | height: 480 12 | title: qsTr("Speedometer") 13 | color: "#000000" 14 | visibility: "FullScreen" 15 | Speedometer 16 | { 17 | objectName: "speedoMeter" 18 | anchors.horizontalCenter: parent.horizontalCenter 19 | width: speedometerSize 20 | height: speedometerSize 21 | startAngle: startAngle 22 | alignAngle: alignAngle 23 | lowestRange: lowestRange 24 | highestRange: highestRange 25 | speed: speed 26 | arcWidth: arcWidth 27 | outerColor: outerColor 28 | innerColor: innerColor 29 | textColor: textColor 30 | backgroundColor: backgroundColor 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /QtMqttRaspberryPiEsp8266/mqttRaspExample/mqtt.h: -------------------------------------------------------------------------------- 1 | #ifndef MQTT_H 2 | #define MQTT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class mqtt : public QObject 9 | { 10 | Q_OBJECT 11 | 12 | 13 | public: 14 | 15 | Q_INVOKABLE void connect_a(QString host, QString port, QString user, QString pass); 16 | Q_INVOKABLE void subs_a(QString topic); 17 | 18 | Q_PROPERTY(int value READ getValue WRITE setValue NOTIFY valueChanged) 19 | Q_PROPERTY(bool statu READ getStatu WRITE setStatu NOTIFY statuChanged) 20 | 21 | public: 22 | mqtt(); 23 | ~mqtt(); 24 | void subMess(const QMqttMessage &msg); 25 | 26 | public slots: 27 | int getValue() const; 28 | bool getStatu() const; 29 | 30 | void setValue(int val); 31 | void setStatu(bool stat); 32 | 33 | signals: 34 | void valueChanged(); 35 | void statuChanged(); 36 | 37 | private: 38 | QMqttClient *m_client; 39 | int value; 40 | bool statu; 41 | }; 42 | 43 | #endif // MQTT_H 44 | -------------------------------------------------------------------------------- /QtMqttRaspberryPiEsp8266/mqttRaspExample/mqttRaspExample.pro: -------------------------------------------------------------------------------- 1 | QT += quick mqtt 2 | 3 | CONFIG += c++11 4 | 5 | # The following define makes your compiler emit warnings if you use 6 | # any Qt feature that has been marked deprecated (the exact warnings 7 | # depend on your compiler). Refer to the documentation for the 8 | # deprecated API to know how to port your code away from it. 9 | DEFINES += QT_DEPRECATED_WARNINGS 10 | 11 | # You can also make your code fail to compile if it uses deprecated APIs. 12 | # In order to do so, uncomment the following line. 13 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 14 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 15 | 16 | SOURCES += \ 17 | main.cpp \ 18 | mqtt.cpp 19 | 20 | RESOURCES += qml.qrc 21 | 22 | # Additional import path used to resolve QML modules in Qt Creator's code model 23 | QML_IMPORT_PATH = 24 | 25 | # Additional import path used to resolve QML modules just for Qt Quick Designer 26 | QML_DESIGNER_IMPORT_PATH = 27 | 28 | # Default rules for deployment. 29 | qnx: target.path = /tmp/$${TARGET}/bin 30 | else: unix:!android: target.path = /opt/$${TARGET}/bin 31 | !isEmpty(target.path): INSTALLS += target 32 | 33 | HEADERS += \ 34 | mqtt.h 35 | -------------------------------------------------------------------------------- /speedometer/speedometer.pro: -------------------------------------------------------------------------------- 1 | QT += qml quick 2 | CONFIG += c++11 3 | 4 | # The following define makes your compiler emit warnings if you use 5 | # any feature of Qt which as been marked deprecated (the exact warnings 6 | # depend on your compiler). Please consult the documentation of the 7 | # deprecated API in order to know how to port your code away from it. 8 | DEFINES += QT_DEPRECATED_WARNINGS 9 | 10 | # You can also make your code fail to compile if you use deprecated APIs. 11 | # In order to do so, uncomment the following line. 12 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 13 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 14 | 15 | SOURCES += main.cpp \ 16 | speedometer.cpp 17 | 18 | RESOURCES += qml.qrc 19 | 20 | # Additional import path used to resolve QML modules in Qt Creator's code model 21 | QML_IMPORT_PATH = 22 | 23 | # Additional import path used to resolve QML modules just for Qt Quick Designer 24 | QML_DESIGNER_IMPORT_PATH = 25 | 26 | # Default rules for deployment. 27 | qnx: target.path = /tmp/$${TARGET}/bin 28 | else: unix:!android: target.path = /opt/$${TARGET}/bin 29 | !isEmpty(target.path): INSTALLS += target 30 | 31 | HEADERS += \ 32 | speedometer.h 33 | 34 | INCLUDEPATH += $$PWD 35 | 36 | CONFIG += unversioned_libname unversioned_soname 37 | 38 | unix:!macx: LIBS += -L$$PWD/./ -lwiringPi 39 | 40 | INCLUDEPATH += $$PWD/. 41 | DEPENDPATH += $$PWD/. 42 | -------------------------------------------------------------------------------- /QtMqttRaspberryPiEsp8266/mqttRaspExample/mqtt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mqtt.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | mqtt::mqtt(): QObject() 11 | { 12 | m_client = new QMqttClient(this); 13 | } 14 | 15 | mqtt::~mqtt() 16 | { 17 | 18 | 19 | } 20 | 21 | int mqtt::getValue() const 22 | { 23 | return value; 24 | } 25 | bool mqtt::getStatu() const 26 | { 27 | return statu; 28 | } 29 | 30 | void mqtt::setValue(int val) 31 | { 32 | value = val; 33 | emit valueChanged(); 34 | } 35 | 36 | void mqtt::setStatu(bool stat) 37 | { 38 | statu = stat; 39 | emit statuChanged(); 40 | } 41 | 42 | void mqtt::connect_a(QString host, QString port, QString user, QString pass) 43 | { 44 | 45 | 46 | 47 | if (m_client->state() == QMqttClient::Disconnected) { 48 | m_client->setHostname(host); 49 | 50 | m_client->setPort(port.toInt()); 51 | m_client->setUsername(user); 52 | m_client->setPassword(pass); 53 | 54 | m_client->connectToHost(); 55 | setStatu(false); 56 | } 57 | else { 58 | m_client->disconnectFromHost(); 59 | setStatu(true); 60 | } 61 | 62 | return; 63 | } 64 | 65 | void mqtt::subs_a(QString topic) 66 | { 67 | qDebug()<<"subscribe to topic"; 68 | auto subscription = m_client->subscribe(topic, 0); 69 | if (!subscription) { 70 | qDebug()<<"Can not subscribe to topic"; 71 | return; 72 | } 73 | 74 | connect(subscription, &QMqttSubscription::messageReceived, this, &mqtt::subMess); 75 | 76 | return; 77 | } 78 | 79 | 80 | void mqtt::subMess(const QMqttMessage &msg) 81 | { 82 | qDebug()< 5 | #include 6 | 7 | class Speedometer : public QQuickPaintedItem 8 | { 9 | Q_OBJECT 10 | 11 | Q_PROPERTY(qreal speedometerSize READ getSpeedometerSize WRITE setSpeedometerSize NOTIFY speedometerSizeChanged) 12 | Q_PROPERTY(qreal startAngle READ getStartAngle WRITE setStartAngle NOTIFY startAngleChanged) 13 | Q_PROPERTY(qreal alignAngle READ getAlignAngle WRITE setAlignAngle NOTIFY alignAngleChanged) 14 | Q_PROPERTY(qreal lowestRange READ getLowestRange WRITE setLowestRange NOTIFY lowestRangeChanged) 15 | Q_PROPERTY(qreal highestRange READ getHighestRange WRITE setHighestRange NOTIFY highestRangeChanged) 16 | Q_PROPERTY(qreal speed READ getSpeed WRITE setSpeed NOTIFY speedChanged) 17 | Q_PROPERTY(int arcWidth READ getArcWidth WRITE setArcWidth NOTIFY arcWidthChanged) 18 | Q_PROPERTY(QColor outerColor READ getOuterColor WRITE setOuterColor NOTIFY outerColorChanged) 19 | Q_PROPERTY(QColor innerColor READ getInnerColor WRITE setInnerColor NOTIFY innerColorChanged) 20 | Q_PROPERTY(QColor textColor READ getTextColor WRITE setTextColor NOTIFY textColorChanged) 21 | Q_PROPERTY(QColor backgroundColor READ getBackgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) 22 | 23 | public: 24 | Speedometer(QQuickItem *parent = 0); 25 | virtual void paint(QPainter *painter); 26 | 27 | qreal getSpeedometerSize(); 28 | qreal getStartAngle(); 29 | qreal getAlignAngle(); 30 | qreal getLowestRange(); 31 | qreal getHighestRange(); 32 | qreal getSpeed(); 33 | int getArcWidth(); 34 | QColor getOuterColor(); 35 | QColor getInnerColor(); 36 | QColor getTextColor(); 37 | QColor getBackgroundColor(); 38 | 39 | void setSpeedometerSize(qreal size); 40 | void setStartAngle(qreal startAngle); 41 | void setAlignAngle(qreal angle); 42 | void setLowestRange(qreal losbwestRange); 43 | void setHighestRange(qreal highestRange); 44 | void setSpeed(qreal speed); 45 | void setArcWidth(int arcWidth); 46 | void setOuterColor(QColor outerColor); 47 | void setInnerColor(QColor innerColor); 48 | void setTextColor(QColor textColor); 49 | void setBackgroundColor(QColor backgroundColor); 50 | 51 | signals: 52 | void speedometerSizeChanged(); 53 | void startAngleChanged(); 54 | void alignAngleChanged(); 55 | void lowestRangeChanged(); 56 | void highestRangeChanged(); 57 | void speedChanged(); 58 | void arcWidthChanged(); 59 | void outerColorChanged(); 60 | void innerColorChanged(); 61 | void textColorChanged(); 62 | void backgroundColorChanged(); 63 | 64 | private: 65 | qreal m_SpeedometerSize; 66 | qreal m_StartAngle; 67 | qreal m_AlignAngle; 68 | qreal m_LowestRange; 69 | qreal m_HighestRange; 70 | qreal m_Speed; 71 | int m_ArcWidth; 72 | QColor m_OuterColor; 73 | QColor m_InnerColor; 74 | QColor m_TextColor; 75 | QColor m_BackgroundColor; 76 | 77 | }; 78 | 79 | #endif // SPEEDOMETER_H 80 | -------------------------------------------------------------------------------- /speedometer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "speedometer.h" 5 | #include 6 | #include 7 | 8 | static const int CHANNEL = 1; 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 13 | 14 | QGuiApplication app(argc, argv); 15 | 16 | qmlRegisterType("com.ulasdikme.speedometer",1,0,"Speedometer"); 17 | 18 | QQmlApplicationEngine engine; 19 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 20 | 21 | QObject *object = engine.rootObjects()[0]; 22 | QObject *speedometer = object->findChild("speedoMeter"); 23 | 24 | Speedometer *ptrSpeedometer = qobject_cast(speedometer); 25 | //Speedometer *ptrSpeedometer = dynamic_cast(speedometer); 26 | 27 | qreal val = 0; 28 | //ptrSpeedometer->setSpeed(val); 29 | 30 | //bool direction = true; 31 | QTimer timer; 32 | 33 | // analog value from ltc2400 34 | float volt = 0; 35 | 36 | QObject::connect(&timer, &QTimer::timeout, [&]() 37 | { 38 | 39 | 40 | // val = volt; 41 | 42 | if(val < 1600) 43 | ptrSpeedometer->setOuterColor(QColor(128,255,0)); 44 | else if(val > 1600 && val < 3200) 45 | ptrSpeedometer->setOuterColor(QColor(255,255,0)); 46 | else if(val > 3200) 47 | ptrSpeedometer->setOuterColor(QColor(255,0,0)); 48 | 49 | if(abs(volt-val) <=10) 50 | val = volt; 51 | else if(volt > val) 52 | val = val + 10; 53 | else if( volt < val) 54 | val = val - 10; 55 | 56 | ptrSpeedometer->setSpeed(val); 57 | // if(val >= 4000) 58 | // direction = false; 59 | // else if(val <= 0.1) 60 | // direction = true; 61 | 62 | // if(direction) 63 | // val = val + 10; 64 | // else 65 | // val = val - 10; 66 | 67 | } 68 | ); 69 | 70 | 71 | unsigned char buffer[100]; 72 | wiringPiSPISetup(CHANNEL, 1000000); 73 | 74 | long int ltw = 0; 75 | 76 | QTimer timer2; 77 | 78 | QObject::connect(&timer2,&QTimer::timeout, [&]() 79 | { 80 | 81 | wiringPiSPIDataRW(CHANNEL, buffer, 4); 82 | 83 | // bool sig; 84 | ltw = 0; 85 | 86 | //f((buffer[0]&0x20)==0) sig = 1; 87 | buffer[0] &= 0x1F; 88 | ltw |= buffer[0]; 89 | ltw <<= 8; 90 | ltw |= buffer[1]; 91 | ltw <<= 8; 92 | ltw |= buffer[2]; 93 | ltw <<= 8; 94 | ltw |= buffer[3]; 95 | 96 | //if(sig) ltw |= 0xf0000000; 97 | ltw = ltw/16; 98 | volt = ltw*4000.1 / 16777216; 99 | // qDebug()<<(unsigned int)volt; 100 | 101 | }); 102 | 103 | // usleep(180000); 104 | 105 | 106 | timer2.start(180); 107 | //TODO: pretend first timer to update the data before start the seond timer 108 | timer.start(1); 109 | 110 | if (engine.rootObjects().isEmpty()) 111 | return -1; 112 | 113 | return app.exec(); 114 | } 115 | -------------------------------------------------------------------------------- /QtMqttRaspberryPiEsp8266/mqtt_example/mqtt_example.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | // Update these with values suitable for your network. 6 | 7 | const char* ssid = "UPC1009332"; 8 | const char* password = "FTGYCYGD"; 9 | 10 | const char* mqttServer = "iot.reyax.com"; 11 | const char* mqttUserName = "zFtbPwRwxE"; // MQTT username 12 | const char* mqttPwd = "GhMshMhWG9"; // MQTT password 13 | const char* clientID = "zFtbPwRwxE0123"; // client id 14 | const char* topic = "api/request"; //publish topic 15 | 16 | /* 17 | const char* ssid = "UPC1009332"; 18 | const char* password = "FTGYCYGD"; 19 | const char* mqttServer = "iot.reyax.com"; 20 | const char* mqttUserName = "AxkRcYFqe7"; // MQTT username 21 | const char* mqttPwd = "zhsghF6DSw"; // MQTT password 22 | const char* clientID = "AxkRcYFqe70001"; // client id 23 | const char* topic = "api/request"; //publish topic 24 | */ 25 | 26 | unsigned long prevMillis = 0; 27 | const long interval = 1000; 28 | String msgStr = ""; // MQTT message buffer 29 | 30 | int tmp = 0; 31 | int pot = 0; 32 | unsigned long startMillis; //some global variables available anywhere in the program 33 | unsigned long startMillisPot; 34 | unsigned long currentMillisPot; 35 | unsigned long currentMillis; 36 | const unsigned long period = 2000; //the value is a number of mill 37 | const unsigned long periodPot = 500; //the value is a number of mill 38 | 39 | WiFiClient espClient; 40 | PubSubClient client(espClient); 41 | 42 | void setup_wifi() { 43 | delay(10); 44 | WiFi.begin(ssid, password); 45 | 46 | while (WiFi.status() != WL_CONNECTED) 47 | { 48 | delay(500); 49 | Serial.print("."); 50 | } 51 | 52 | Serial.println(""); 53 | Serial.println("WiFi connected"); 54 | Serial.println("IP address: "); 55 | Serial.println(WiFi.localIP()); 56 | } 57 | 58 | void reconnect() { 59 | while (!client.connected()) 60 | { 61 | 62 | if (client.connect(clientID, mqttUserName, mqttPwd)) 63 | { 64 | Serial.println("MQTT connected"); 65 | client.subscribe("api/command/28/#"); 66 | } 67 | else 68 | { 69 | Serial.print("failed, rc="); 70 | Serial.print(client.state()); 71 | Serial.println(" try again in 5 seconds"); 72 | delay(5000); // wait 5sec and retry 73 | } 74 | 75 | } 76 | } 77 | 78 | void setup() 79 | { 80 | Serial.begin(9600); 81 | setup_wifi(); 82 | client.setServer(mqttServer, 1883); 83 | client.setCallback(callback); 84 | } 85 | 86 | 87 | 88 | void loop() { 89 | if (!client.connected()) { 90 | reconnect(); 91 | } 92 | client.loop(); 93 | 94 | currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the program started) 95 | 96 | if (currentMillis - startMillisPot >= periodPot) //test whether the period has elapsed 97 | { 98 | pot = analogRead(A0); 99 | Serial.println(pot); 100 | startMillisPot = currentMillis; 101 | } 102 | 103 | if (currentMillis - startMillis >= period) //test whether the period has elapsed 104 | { 105 | tmp ++; 106 | //publish Command 107 | // msgStr="{\"action\": \"command/insert\",\"deviceId\": \"c0Qm6reG9T4djVORK11HbhciG6LyCbUdMXQB\",\"command\": {\"command\": \"Control Temperature\",\"parameters\": {\"Control\":\"Temperature\"},\"status\":\"to do\",\"result\":{\"temperature\": \"27\"}}}"; 108 | 109 | 110 | 111 | String tmpStr = String(pot); 112 | msgStr="{\"action\": \"command/insert\",\"deviceId\": \"xD5GufgiHVRm6MkfVypfEDKJJzKOyoILkhl0\",\"command\": {\"command\": \"Control Temperature\",\"parameters\": {\"Control\":\"Temperature\"},\"status\":\"to do\",\"result\":{\"temperature\": \""+tmpStr+"\"}}}"; 113 | 114 | byte arrSize = msgStr.length() + 1; 115 | char msg[arrSize]; 116 | Serial.print("PUBLISH DATA:"); 117 | Serial.println(msgStr); 118 | msgStr.toCharArray(msg, arrSize); 119 | client.publish(topic, msg); 120 | msgStr = ""; 121 | startMillis = currentMillis;; 122 | } 123 | } 124 | 125 | //subscribe call back 126 | void callback(char*topic, byte* payload, unsigned int length) { 127 | Serial.print("Messagearrived in topic: "); 128 | Serial.println(topic); 129 | Serial.print("Message:"); 130 | 131 | for (int i = 0; i< length; i++) { 132 | Serial.print((char)payload[i]); 133 | } 134 | 135 | Serial.println(); 136 | Serial.print("Message size :"); 137 | Serial.println(length); 138 | Serial.println(); 139 | Serial.println("-----------------------"); 140 | } 141 | -------------------------------------------------------------------------------- /speedometer/speedometer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "speedometer.h" 4 | 5 | Speedometer::Speedometer(QQuickItem *parent) 6 | :QQuickPaintedItem(parent), 7 | m_SpeedometerSize(500), // touch screen is 800 x 480 8 | m_StartAngle(50), 9 | m_AlignAngle(260), // it should be 360 - m_StartAngle*3 for good looking 10 | m_LowestRange(0), 11 | m_HighestRange(4000), 12 | m_Speed(2430), 13 | m_ArcWidth(10), 14 | m_OuterColor(QColor(12,16,247)), 15 | m_InnerColor(QColor(51,88,255,80)), 16 | m_TextColor(QColor(255,255,255)), 17 | m_BackgroundColor(Qt::transparent) 18 | { 19 | 20 | } 21 | 22 | void Speedometer::paint(QPainter *painter) 23 | { 24 | 25 | QRectF rect = this->boundingRect(); 26 | painter->setRenderHint(QPainter::Antialiasing); 27 | QPen pen = painter->pen(); 28 | pen.setCapStyle(Qt::FlatCap); 29 | 30 | double startAngle; 31 | double spanAngle; 32 | 33 | startAngle = m_StartAngle - 40; 34 | spanAngle = 0 - m_AlignAngle; 35 | 36 | //all arc 37 | painter->save(); 38 | pen.setWidth(m_ArcWidth); 39 | pen.setColor(m_InnerColor); 40 | painter->setPen(pen); 41 | // painter->drawRect(rect); 42 | painter->drawArc(rect.adjusted(m_ArcWidth, m_ArcWidth, -m_ArcWidth, -m_ArcWidth), startAngle * 16, spanAngle * 16); 43 | painter->restore(); 44 | 45 | //inner pie 46 | int pieSize = m_SpeedometerSize/5; 47 | painter->save(); 48 | pen.setWidth(m_ArcWidth/2); 49 | pen.setColor(m_OuterColor); 50 | painter->setBrush(m_InnerColor); 51 | painter->setPen(pen); 52 | painter->drawPie(rect.adjusted(pieSize, pieSize, -pieSize, -pieSize), startAngle * 16, spanAngle * 16); 53 | painter->restore(); 54 | 55 | //text which shows the value 56 | painter->save(); 57 | QFont font("Halvetica",52,QFont::Bold); 58 | painter->setFont(font); 59 | pen.setColor(m_TextColor); 60 | painter->setPen(pen); 61 | painter->drawText(rect.adjusted(m_SpeedometerSize/30, m_SpeedometerSize/30, -m_SpeedometerSize/30, -m_SpeedometerSize/4), Qt::AlignCenter ,QString::number((m_Speed/40),'f',1)); 62 | painter->restore(); 63 | 64 | //current active progress 65 | painter->save(); 66 | pen.setWidth(m_ArcWidth); 67 | pen.setColor(m_OuterColor); 68 | qreal valueToAngle = ((m_Speed - m_LowestRange)/(m_HighestRange - m_LowestRange)) * spanAngle; 69 | painter->setPen(pen); 70 | painter->drawArc(rect.adjusted(m_ArcWidth, m_ArcWidth, -m_ArcWidth, -m_ArcWidth), startAngle * 16, valueToAngle * 16); 71 | painter->restore(); 72 | 73 | } 74 | 75 | 76 | qreal Speedometer::getSpeedometerSize() 77 | { 78 | return m_SpeedometerSize; 79 | } 80 | 81 | qreal Speedometer::getStartAngle() 82 | { 83 | return m_StartAngle; 84 | } 85 | 86 | 87 | qreal Speedometer::getAlignAngle() 88 | { 89 | return m_AlignAngle; 90 | } 91 | 92 | 93 | qreal Speedometer::getLowestRange() 94 | { 95 | return m_LowestRange; 96 | } 97 | 98 | qreal Speedometer::getHighestRange() 99 | { 100 | return m_HighestRange; 101 | } 102 | 103 | qreal Speedometer::getSpeed() 104 | { 105 | return m_Speed; 106 | } 107 | 108 | int Speedometer::getArcWidth() 109 | { 110 | return m_ArcWidth; 111 | } 112 | 113 | QColor Speedometer::getOuterColor() 114 | { 115 | return m_OuterColor; 116 | } 117 | 118 | QColor Speedometer::getInnerColor() 119 | { 120 | return m_InnerColor; 121 | } 122 | 123 | QColor Speedometer::getTextColor() 124 | { 125 | return m_TextColor; 126 | } 127 | 128 | QColor Speedometer::getBackgroundColor() 129 | { 130 | return m_BackgroundColor; 131 | } 132 | 133 | 134 | 135 | void Speedometer::setSpeedometerSize(qreal size) 136 | { 137 | if(m_SpeedometerSize == size) 138 | return; 139 | m_SpeedometerSize = size; 140 | 141 | emit speedometerSizeChanged(); 142 | } 143 | 144 | void Speedometer::setStartAngle(qreal startAngle) 145 | { 146 | if(m_StartAngle == startAngle) 147 | return; 148 | 149 | m_StartAngle = startAngle; 150 | 151 | emit startAngleChanged(); 152 | } 153 | 154 | void Speedometer::setAlignAngle(qreal angle) 155 | { 156 | if(m_StartAngle == angle) 157 | return; 158 | 159 | m_StartAngle = angle; 160 | 161 | emit alignAngleChanged(); 162 | } 163 | 164 | void Speedometer::setLowestRange(qreal lowestRange) 165 | { 166 | if(m_LowestRange == lowestRange) 167 | return; 168 | 169 | m_LowestRange = lowestRange; 170 | 171 | emit lowestRangeChanged(); 172 | } 173 | 174 | void Speedometer::setHighestRange(qreal highestRange) 175 | { 176 | if(m_HighestRange == highestRange) 177 | return; 178 | 179 | m_HighestRange = highestRange; 180 | 181 | emit highestRangeChanged(); 182 | } 183 | 184 | void Speedometer::setSpeed(qreal speed) 185 | { 186 | if(m_Speed == speed) 187 | return; 188 | 189 | m_Speed = speed; 190 | update(); 191 | emit speedChanged(); 192 | } 193 | 194 | void Speedometer::setArcWidth(int arcWidth) 195 | { 196 | if(m_ArcWidth == arcWidth) 197 | return; 198 | 199 | m_ArcWidth = arcWidth; 200 | 201 | emit arcWidthChanged(); 202 | } 203 | 204 | void Speedometer::setOuterColor(QColor outerColor) 205 | { 206 | if(m_OuterColor == outerColor) 207 | return; 208 | 209 | m_OuterColor = outerColor; 210 | 211 | emit outerColorChanged(); 212 | } 213 | 214 | void Speedometer::setInnerColor(QColor innerColor) 215 | { 216 | if(m_InnerColor == innerColor) 217 | return; 218 | 219 | m_InnerColor = innerColor; 220 | 221 | emit innerColorChanged(); 222 | } 223 | 224 | void Speedometer::setTextColor(QColor textColor) 225 | { 226 | if(m_TextColor == textColor) 227 | return; 228 | 229 | m_TextColor = textColor; 230 | 231 | emit textColorChanged(); 232 | } 233 | 234 | void Speedometer::setBackgroundColor(QColor backgroundColor) 235 | { 236 | if(m_BackgroundColor == backgroundColor) 237 | return; 238 | 239 | m_BackgroundColor = backgroundColor; 240 | 241 | emit backgroundColorChanged(); 242 | } 243 | -------------------------------------------------------------------------------- /speedometer/speedometer.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {7310574f-d528-4349-b9ad-292b0d339e4c} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | Desktop 63 | Desktop 64 | {10a5052b-d4eb-49c2-b8ee-03a6fa274c00} 65 | 0 66 | 0 67 | 0 68 | 69 | /home/vmubuntu/Desktop/SpeedometerExample/build-speedometer-Desktop-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | -w 89 | -r 90 | 91 | false 92 | 93 | 94 | 95 | 2 96 | Build 97 | 98 | ProjectExplorer.BuildSteps.Build 99 | 100 | 101 | 102 | true 103 | Make 104 | 105 | Qt4ProjectManager.MakeStep 106 | 107 | -w 108 | -r 109 | 110 | true 111 | clean 112 | 113 | 114 | 1 115 | Clean 116 | 117 | ProjectExplorer.BuildSteps.Clean 118 | 119 | 2 120 | false 121 | 122 | Debug 123 | 124 | Qt4ProjectManager.Qt4BuildConfiguration 125 | 2 126 | true 127 | 128 | 129 | /home/vmubuntu/Desktop/SpeedometerExample/build-speedometer-Desktop-Release 130 | 131 | 132 | true 133 | qmake 134 | 135 | QtProjectManager.QMakeBuildStep 136 | false 137 | 138 | false 139 | false 140 | false 141 | 142 | 143 | true 144 | Make 145 | 146 | Qt4ProjectManager.MakeStep 147 | 148 | -w 149 | -r 150 | 151 | false 152 | 153 | 154 | 155 | 2 156 | Build 157 | 158 | ProjectExplorer.BuildSteps.Build 159 | 160 | 161 | 162 | true 163 | Make 164 | 165 | Qt4ProjectManager.MakeStep 166 | 167 | -w 168 | -r 169 | 170 | true 171 | clean 172 | 173 | 174 | 1 175 | Clean 176 | 177 | ProjectExplorer.BuildSteps.Clean 178 | 179 | 2 180 | false 181 | 182 | Release 183 | 184 | Qt4ProjectManager.Qt4BuildConfiguration 185 | 0 186 | true 187 | 188 | 189 | /home/vmubuntu/Desktop/SpeedometerExample/build-speedometer-Desktop-Profile 190 | 191 | 192 | true 193 | qmake 194 | 195 | QtProjectManager.QMakeBuildStep 196 | true 197 | 198 | false 199 | true 200 | false 201 | 202 | 203 | true 204 | Make 205 | 206 | Qt4ProjectManager.MakeStep 207 | 208 | -w 209 | -r 210 | 211 | false 212 | 213 | 214 | 215 | 2 216 | Build 217 | 218 | ProjectExplorer.BuildSteps.Build 219 | 220 | 221 | 222 | true 223 | Make 224 | 225 | Qt4ProjectManager.MakeStep 226 | 227 | -w 228 | -r 229 | 230 | true 231 | clean 232 | 233 | 234 | 1 235 | Clean 236 | 237 | ProjectExplorer.BuildSteps.Clean 238 | 239 | 2 240 | false 241 | 242 | Profile 243 | 244 | Qt4ProjectManager.Qt4BuildConfiguration 245 | 0 246 | true 247 | 248 | 3 249 | 250 | 251 | 0 252 | Deploy 253 | 254 | ProjectExplorer.BuildSteps.Deploy 255 | 256 | 1 257 | Deploy locally 258 | 259 | ProjectExplorer.DefaultDeployConfiguration 260 | 261 | 1 262 | 263 | 264 | false 265 | false 266 | 1000 267 | 268 | true 269 | 270 | false 271 | false 272 | false 273 | false 274 | true 275 | 0.01 276 | 10 277 | true 278 | 1 279 | 25 280 | 281 | 1 282 | true 283 | false 284 | true 285 | valgrind 286 | 287 | 0 288 | 1 289 | 2 290 | 3 291 | 4 292 | 5 293 | 6 294 | 7 295 | 8 296 | 9 297 | 10 298 | 11 299 | 12 300 | 13 301 | 14 302 | 303 | -1 304 | 305 | 306 | 307 | %{buildDir} 308 | Custom Executable 309 | 310 | ProjectExplorer.CustomExecutableRunConfiguration 311 | 3768 312 | false 313 | true 314 | false 315 | false 316 | true 317 | 318 | 1 319 | 320 | 321 | 322 | ProjectExplorer.Project.TargetCount 323 | 1 324 | 325 | 326 | ProjectExplorer.Project.Updater.FileVersion 327 | 18 328 | 329 | 330 | Version 331 | 18 332 | 333 | 334 | -------------------------------------------------------------------------------- /QtMqttRaspberryPiEsp8266/mqttRaspExample/mqttRaspExample.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {5821b0e6-ebb2-48ef-88fb-9e8a2208a711} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | RaspiQt 63 | RaspiQt 64 | {30f65088-441b-4acb-8ffe-950deb61d655} 65 | 1 66 | 0 67 | 0 68 | 69 | /home/ulas/Desktop/build-mqttRaspExample-RaspiQt-Debug 70 | 71 | 72 | true 73 | QtProjectManager.QMakeBuildStep 74 | true 75 | 76 | false 77 | false 78 | false 79 | 80 | 81 | true 82 | Qt4ProjectManager.MakeStep 83 | 84 | false 85 | 86 | 87 | false 88 | 89 | 2 90 | Build 91 | Build 92 | ProjectExplorer.BuildSteps.Build 93 | 94 | 95 | 96 | true 97 | Qt4ProjectManager.MakeStep 98 | 99 | true 100 | clean 101 | 102 | false 103 | 104 | 1 105 | Clean 106 | Clean 107 | ProjectExplorer.BuildSteps.Clean 108 | 109 | 2 110 | false 111 | 112 | Debug 113 | Qt4ProjectManager.Qt4BuildConfiguration 114 | 2 115 | 116 | 117 | /home/ulas/Desktop/build-mqttRaspExample-RaspiQt-Release 118 | 119 | 120 | true 121 | QtProjectManager.QMakeBuildStep 122 | false 123 | 124 | false 125 | false 126 | true 127 | 128 | 129 | true 130 | Qt4ProjectManager.MakeStep 131 | 132 | false 133 | 134 | 135 | false 136 | 137 | 2 138 | Build 139 | Build 140 | ProjectExplorer.BuildSteps.Build 141 | 142 | 143 | 144 | true 145 | Qt4ProjectManager.MakeStep 146 | 147 | true 148 | clean 149 | 150 | false 151 | 152 | 1 153 | Clean 154 | Clean 155 | ProjectExplorer.BuildSteps.Clean 156 | 157 | 2 158 | false 159 | 160 | Release 161 | Qt4ProjectManager.Qt4BuildConfiguration 162 | 0 163 | 164 | 165 | /home/ulas/Desktop/build-mqttRaspExample-RaspiQt-Profile 166 | 167 | 168 | true 169 | QtProjectManager.QMakeBuildStep 170 | true 171 | 172 | false 173 | true 174 | true 175 | 176 | 177 | true 178 | Qt4ProjectManager.MakeStep 179 | 180 | false 181 | 182 | 183 | false 184 | 185 | 2 186 | Build 187 | Build 188 | ProjectExplorer.BuildSteps.Build 189 | 190 | 191 | 192 | true 193 | Qt4ProjectManager.MakeStep 194 | 195 | true 196 | clean 197 | 198 | false 199 | 200 | 1 201 | Clean 202 | Clean 203 | ProjectExplorer.BuildSteps.Clean 204 | 205 | 2 206 | false 207 | 208 | Profile 209 | Qt4ProjectManager.Qt4BuildConfiguration 210 | 0 211 | 212 | 3 213 | 214 | 215 | 216 | true 217 | RemoteLinux.CheckForFreeDiskSpaceStep 218 | 219 | 220 | 221 | 222 | / 223 | 5242880 224 | 225 | 226 | 227 | 228 | true 229 | RemoteLinux.KillAppStep 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | true 239 | RemoteLinux.RsyncDeployStep 240 | 241 | 242 | 243 | 244 | 245 | 246 | -av 247 | false 248 | 249 | 3 250 | Deploy 251 | Deploy 252 | ProjectExplorer.BuildSteps.Deploy 253 | 254 | 1 255 | DeployToGenericLinux 256 | 257 | 1 258 | 259 | 260 | dwarf 261 | 262 | cpu-cycles 263 | 264 | 265 | 250 266 | 267 | -e 268 | cpu-cycles 269 | --call-graph 270 | dwarf,4096 271 | -F 272 | 250 273 | 274 | -F 275 | true 276 | 4096 277 | false 278 | false 279 | 1000 280 | 281 | true 282 | 283 | false 284 | false 285 | false 286 | false 287 | true 288 | 0.01 289 | 10 290 | true 291 | kcachegrind 292 | 1 293 | 25 294 | 295 | 1 296 | true 297 | false 298 | true 299 | valgrind 300 | 301 | 0 302 | 1 303 | 2 304 | 3 305 | 4 306 | 5 307 | 6 308 | 7 309 | 8 310 | 9 311 | 10 312 | 11 313 | 12 314 | 13 315 | 14 316 | 317 | 1 318 | 319 | mqttRaspExample (on Raspberry) 320 | RemoteLinuxRunConfiguration:/home/ulas/Desktop/mqttRaspExample/mqttRaspExample.pro 321 | /home/ulas/Desktop/mqttRaspExample/mqttRaspExample.pro 322 | 1 323 | 324 | false 325 | 326 | false 327 | 328 | false 329 | true 330 | false 331 | false 332 | true 333 | false 334 | 335 | 336 | :0 337 | 338 | 1 339 | 340 | 341 | 342 | ProjectExplorer.Project.TargetCount 343 | 1 344 | 345 | 346 | ProjectExplorer.Project.Updater.FileVersion 347 | 22 348 | 349 | 350 | Version 351 | 22 352 | 353 | 354 | --------------------------------------------------------------------------------