diff options
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | DoubleSpinBox.qml | 35 | ||||
| -rw-r--r-- | Main.qml | 100 | ||||
| -rw-r--r-- | main.cpp | 3 |
4 files changed, 103 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 30cf56d..736b59f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ qt_add_qml_module(appeurydice QML_FILES request.js QML_FILES ImageViewer.qml RESOURCES eurydice.qrc + QML_FILES DoubleSpinBox.qml ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. diff --git a/DoubleSpinBox.qml b/DoubleSpinBox.qml new file mode 100644 index 0000000..8a86e89 --- /dev/null +++ b/DoubleSpinBox.qml @@ -0,0 +1,35 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Controls.Material + +SpinBox { + id: spinBox + from: 0 + // value: decimalToInt(1.1) + to: decimalToInt(100) + stepSize: decimalFactor + editable: true + + property int decimals: 2 + property real realValue: value / decimalFactor + readonly property int decimalFactor: Math.pow(10, decimals) + + function decimalToInt(decimal) { + return decimal * decimalFactor + } + + validator: DoubleValidator { + bottom: Math.min(spinBox.from, spinBox.to) + top: Math.max(spinBox.from, spinBox.to) + decimals: spinBox.decimals + notation: DoubleValidator.StandardNotation + } + + textFromValue: function(value, locale) { + return Number(value / decimalFactor).toLocaleString(locale, 'f', spinBox.decimals) + } + + valueFromText: function(text, locale) { + return Math.round(Number.fromLocaleString(locale, text) * decimalFactor) + } +} @@ -60,7 +60,8 @@ ApplicationWindow { } function readParams() { - var url = apiRoot + "/sensor/params" + // var url = apiRoot + "/sensor/params" + var url = "http://radxa:8080/v1/sensor/params" console.log("readParams:", url); XHR.sendRequest("GET", url, function(response) { @@ -79,21 +80,32 @@ ApplicationWindow { var json = JSON.parse(response.content); - console.log("readParams result:", json) + console.log("readParams result:", json, json.exposureTime) - if (exposureTimeSpinBox.value != json.exposureTime) { + if (enableAutoExposureCheckbox.checked !== (json.autoExposure === "true")) { + console.log("update enableAutoExposureCheckbox to", json.autoExposure) + enableAutoExposureCheckbox.checked = json.autoExposure === "true"; + } + + if (exposureTimeSpinBox.value !== json.exposureTime) { console.log("update exposureTimeSpinBox to", json.exposureTime) exposureTimeSpinBox.value = json.exposureTime; } - if (laserLevelSpinBox.value != json.laserLevel) { - console.log("update laserLevelSpinBox to", json.laserLevel) - laserLevelSpinBox.value = json.laserLevel; + if (enableAutoGainCheckbox.checked !== (json.autoGain === "true")) { + console.log("update enableAutoGainCheckbox to", json.autoGain) + enableAutoGainCheckbox.checked = json.autoGain === "true"; } - if (enableAutoExposureCheckbox.checked != (json.aeEnable == "true")) { - console.log("update enableAutoExposureCheckbox to", json.aeEnable) - enableAutoExposureCheckbox.checked = json.aeEnable == "true"; + // TODO: fix this bullshit in DoubleSpinBox + if (gainSpinBox.value !== json.gain) { + console.log("update gainSpinBox to", json.gain / 10.) + gainSpinBox.value = json.gain / 10.; + } + + if (laserLevelSpinBox.value !== json.laserLevel) { + console.log("update laserLevelSpinBox to", json.laserLevel) + laserLevelSpinBox.value = json.laserLevel; } }); } @@ -102,15 +114,24 @@ ApplicationWindow { readParams(); } + // Timer { + // repeat: true + // interval: 1000 / 500 + // running: true + // onTriggered: readParams() + // } + function writeParams() { - var url = apiRoot + "/sensor/params"; + // var url = apiRoot + "/sensor/params"; + var url = "http://radxa:8080/v1/sensor/params" console.log("writeParams:", url); var json = new Object(); - json["aeEnable"] = enableAutoExposureCheckbox.checked; + json["autoExposure"] = enableAutoExposureCheckbox.checked; json["exposureTime"] = exposureTimeSpinBox.value; + json["autoGain"] = enableAutoGainCheckbox.checked; + json["gain"] = gainSpinBox.value / 10.; json["laserLevel"] = laserLevelSpinBox.value; - json["gain"] = gainSpinBox.value; console.log(JSON.stringify(json)); XHR.sendRequest("POST", url, function(response) { @@ -300,6 +321,16 @@ ApplicationWindow { (parseFloat(timestampUs % (1000 * 1000 * 1000)) / 1000.).toFixed(1) } + CheckBox { + id: enableAutoExposureCheckbox + + Layout.columnSpan: 2 + + text: qsTr("Auto exposure") + + onCheckedChanged: writeParams() + } + Label { text: qsTr("Exposure time (us):") } @@ -313,62 +344,63 @@ ApplicationWindow { from: 10 to: 94000000 - stepSize: 100 + stepSize: 10 editable: true value: 68000 onValueChanged: writeParams() } + CheckBox { + id: enableAutoGainCheckbox + + Layout.columnSpan: 2 + + text: qsTr("Auto gain") + + onCheckedChanged: writeParams() + } + Label { - text: qsTr("Laser level (1/50K):") + text: qsTr("Gain [0,254]:") } - SpinBox { - id: laserLevelSpinBox + DoubleSpinBox { + id: gainSpinBox Layout.fillWidth: true - Layout.minimumWidth: implicitWidth - from: 0 - to: 50000 + from: 0.0 + // TODO: fix this bullshit in DoubleSpinBox + to: 40.0 * 10. stepSize: 1 + decimals: 1 editable: true - value: 3 onValueChanged: writeParams() } Label { - text: qsTr("Gain [1,254]:") + text: qsTr("Laser level (1/50K):") } SpinBox { - id: gainSpinBox + id: laserLevelSpinBox Layout.fillWidth: true + Layout.minimumWidth: implicitWidth from: 0 - to: 254 + to: 50000 stepSize: 1 editable: true - value: 2 + value: 3 onValueChanged: writeParams() } - CheckBox { - id: enableAutoExposureCheckbox - - Layout.columnSpan: 2 - - text: qsTr("Auto exposure") - - onCheckedChanged: writeParams() - } - Label { text: qsTr("Printer distance (mm):") } @@ -22,7 +22,6 @@ int main( auto font = app.font(); // font.setPointSize(font.pointSize() / 1.5); app.setFont(font); - QQmlApplicationEngine engine; qmlRegisterType<QmlCustomPlot>("QmlCustomPlot", 1, 0, "QmlCustomPlot"); @@ -158,7 +157,7 @@ int main( // qDebug() << "pc" << jsonPixels.count() << json.isEmpty() // << doc.isObject(); // qDebug().noquote() << QString::fromUtf8(ra); - qDebug() << "pixels reply size:" << ra.size(); + // qDebug() << "pixels reply size:" << ra.size(); for (int i = 0; i < jsonPixels.count(); ++i) { |
