Compare commits
6 changed files with 25 additions and 54 deletions
|
|
@ -10,8 +10,6 @@ Rectangle {
|
||||||
property int font_enlarged_text_size: 20
|
property int font_enlarged_text_size: 20
|
||||||
property int font_normal_text_size: 16
|
property int font_normal_text_size: 16
|
||||||
property string text: "Connect"
|
property string text: "Connect"
|
||||||
property string text2: "Stop"
|
|
||||||
property int mode: 0
|
|
||||||
signal connect;
|
signal connect;
|
||||||
layer.enabled: true
|
layer.enabled: true
|
||||||
layer.effect: MultiEffect {
|
layer.effect: MultiEffect {
|
||||||
|
|
@ -22,7 +20,7 @@ Rectangle {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
font.pointSize: root.font_enlarged_text_size
|
font.pointSize: root.font_enlarged_text_size
|
||||||
color: root.font_color
|
color: root.font_color
|
||||||
text: mode ? root.text2 : root.text
|
text: root.text
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,16 +46,10 @@ Rectangle {
|
||||||
settings_rect_pressed_prev = root.color
|
settings_rect_pressed_prev = root.color
|
||||||
root.color = "#5A1F4F1F"
|
root.color = "#5A1F4F1F"
|
||||||
root.connect();
|
root.connect();
|
||||||
switchMode();
|
|
||||||
}
|
}
|
||||||
onReleased: {
|
onReleased: {
|
||||||
root.color = settings_rect_pressed_prev
|
root.color = settings_rect_pressed_prev
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function switchMode() {
|
|
||||||
if(root.mode === 0)
|
|
||||||
root.mode = 1
|
|
||||||
else
|
|
||||||
root.mode = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
Main.qml
27
Main.qml
|
|
@ -39,10 +39,10 @@ Window {
|
||||||
color: "#0A0F0F0F"
|
color: "#0A0F0F0F"
|
||||||
SettingsBarIcon {
|
SettingsBarIcon {
|
||||||
height: top_bar.height - 20
|
height: top_bar.height - 20
|
||||||
width: height
|
width: top_bar.width / 12
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: parent.top
|
||||||
right: parent.right
|
left: parent.left
|
||||||
bottomMargin: 5
|
bottomMargin: 5
|
||||||
topMargin: 5
|
topMargin: 5
|
||||||
leftMargin: 5
|
leftMargin: 5
|
||||||
|
|
@ -77,10 +77,10 @@ Window {
|
||||||
anchors {
|
anchors {
|
||||||
top: top_bar.bottom
|
top: top_bar.bottom
|
||||||
horizontalCenter: parent.horizontalCenter
|
horizontalCenter: parent.horizontalCenter
|
||||||
topMargin: 100
|
topMargin: 0
|
||||||
}
|
}
|
||||||
height: (parent.height - top_bar.height) / 2
|
height: (parent.height - top_bar.height) / 1.2
|
||||||
width: parent.width / 2.2
|
width: parent.width / 1.2
|
||||||
base_color: root.background_color
|
base_color: root.background_color
|
||||||
distance: 0
|
distance: 0
|
||||||
tank_lid_color: "#F0121212"
|
tank_lid_color: "#F0121212"
|
||||||
|
|
@ -119,15 +119,8 @@ Window {
|
||||||
bottomMargin: 50
|
bottomMargin: 50
|
||||||
}
|
}
|
||||||
onConnect: {
|
onConnect: {
|
||||||
if(connect_button.mode === 0)
|
requester.start();
|
||||||
{
|
root.status = "Waiting to Send.";
|
||||||
requester.start();
|
|
||||||
root.status = "Waiting to Send.";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
root.status = "Stopped.";
|
|
||||||
requester.stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -141,10 +134,6 @@ Window {
|
||||||
tank.setDistance(water_level);
|
tank.setDistance(water_level);
|
||||||
tank.rate_of_fill = fill_rate;
|
tank.rate_of_fill = fill_rate;
|
||||||
tank.expected_to_fill = expected;
|
tank.expected_to_fill = expected;
|
||||||
status.color = root.accent_color;
|
|
||||||
}
|
|
||||||
onRequestFailed: () => {
|
|
||||||
status.color = root.danger_color;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +145,7 @@ Window {
|
||||||
console.log("Loading initial config");
|
console.log("Loading initial config");
|
||||||
setConfig(config);
|
setConfig(config);
|
||||||
if(root.status === "Initializing") {
|
if(root.status === "Initializing") {
|
||||||
root.status = "Press Connect.";
|
root.status = "Waiting to connect.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function setConfig(config) {
|
function setConfig(config) {
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ Popup {
|
||||||
border.color: settings_popup.accent_color
|
border.color: settings_popup.accent_color
|
||||||
border.width: 1
|
border.width: 1
|
||||||
}
|
}
|
||||||
height: Math.max(parent.height / 1.6, contentHeight)
|
height: Math.max(parent.height / 1.2, contentHeight)
|
||||||
width: parent.width / 1.2
|
width: parent.width / 1.1
|
||||||
anchors.centerIn: Overlay.overlay
|
anchors.centerIn: Overlay.overlay
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: settings_base
|
id: settings_base
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Item {
|
||||||
property double height_max: tank_base.height - 10
|
property double height_max: tank_base.height - 10
|
||||||
property double current_level: 0
|
property double current_level: 0
|
||||||
property double percentage_filled: 0
|
property double percentage_filled: 0
|
||||||
property int distance: 0
|
property double distance: 0
|
||||||
property double min_thres_input: 0
|
property double min_thres_input: 0
|
||||||
property double max_thres_input: 0
|
property double max_thres_input: 0
|
||||||
property double rate_of_fill: 0
|
property double rate_of_fill: 0
|
||||||
|
|
@ -33,16 +33,16 @@ Item {
|
||||||
bottomMargin: -5
|
bottomMargin: -5
|
||||||
}
|
}
|
||||||
radius: 10
|
radius: 10
|
||||||
width: tank_base.width / 3
|
width: parent.width / 4
|
||||||
height: tank_base.height / 15
|
height: parent.height / 15
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: tank_base
|
id: tank_base
|
||||||
color: root.tank_base_color
|
color: root.tank_base_color
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
width: parent.width
|
width: parent.width / 2
|
||||||
height: parent.height
|
height: parent.height / 2
|
||||||
border.color: root.tank_base_border_color
|
border.color: root.tank_base_border_color
|
||||||
border.width: 5
|
border.width: 5
|
||||||
radius: 4
|
radius: 4
|
||||||
|
|
@ -72,7 +72,7 @@ Item {
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: water_level_reading
|
id: water_level_reading
|
||||||
text: "Current Reading: " + (root.distance / 10)+ " cm"
|
text: "Current Reading: " + root.distance + " cm"
|
||||||
font.pointSize: 16
|
font.pointSize: 16
|
||||||
color: root.text_color
|
color: root.text_color
|
||||||
anchors {
|
anchors {
|
||||||
|
|
@ -125,7 +125,7 @@ Item {
|
||||||
text: "Expected to fill in: " + root.expected_to_fill + " s"
|
text: "Expected to fill in: " + root.expected_to_fill + " s"
|
||||||
font.pointSize: 16
|
font.pointSize: 16
|
||||||
color: root.text_color
|
color: root.text_color
|
||||||
visible: (root.rate_of_fill > 0) ? true : false
|
visible: (root.rate_of_fill > 1) ? true : false
|
||||||
anchors {
|
anchors {
|
||||||
margins: 5
|
margins: 5
|
||||||
top: rate_of_fill_label.bottom
|
top: rate_of_fill_label.bottom
|
||||||
|
|
@ -141,11 +141,10 @@ Item {
|
||||||
|
|
||||||
function setDistance(distance) {
|
function setDistance(distance) {
|
||||||
root.distance = distance;
|
root.distance = distance;
|
||||||
let distance_f = distance / 10;
|
console.log("Distance changed to: ", distance);
|
||||||
console.log("Distance changed to: ", distance_f);
|
|
||||||
let current_min_reading = Math.max(0, min_thres_input);
|
let current_min_reading = Math.max(0, min_thres_input);
|
||||||
let effective_max_reading = Math.max(0, max_thres_input) - current_min_reading;
|
let effective_max_reading = Math.max(0, max_thres_input) - current_min_reading;
|
||||||
let current_reading = Math.max(0, distance_f - current_min_reading);
|
let current_reading = Math.max(0, root.distance - current_min_reading);
|
||||||
console.log("Current reading is: " + current_reading)
|
console.log("Current reading is: " + current_reading)
|
||||||
console.log("Current min reading is: " + current_min_reading)
|
console.log("Current min reading is: " + current_min_reading)
|
||||||
console.log("Effective max reading is: " + effective_max_reading)
|
console.log("Effective max reading is: " + effective_max_reading)
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ void RequestWorker::stop()
|
||||||
if(timer->isActive())
|
if(timer->isActive())
|
||||||
timer->stop();
|
timer->stop();
|
||||||
stop_timer = true;
|
stop_timer = true;
|
||||||
qDebug() << "Stopping" << timer->isActive();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestWorker::makeRequest()
|
void RequestWorker::makeRequest()
|
||||||
|
|
@ -71,20 +70,13 @@ void RequestWorker::requestFinished(QNetworkReply *rep)
|
||||||
rep = nullptr;
|
rep = nullptr;
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
auto time_diff = std::chrono::duration_cast<std::chrono::microseconds>(now - prev_time);
|
auto time_diff = std::chrono::duration_cast<std::chrono::microseconds>(now - prev_time);
|
||||||
if(data.size() == 0) {
|
|
||||||
prev_time = now;
|
|
||||||
timer->start();
|
|
||||||
emit requestFailed();
|
|
||||||
emit setStatus("Invalid Response; Resending Request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
unsigned int time_in_microseconds = time_diff.count();
|
unsigned int time_in_microseconds = time_diff.count();
|
||||||
QJsonObject jdata = QJsonDocument::fromJson(data).object();
|
QJsonObject jdata = QJsonDocument::fromJson(data).object();
|
||||||
auto data_water_level = jdata["water_level"].toInt();
|
auto data_water_level = jdata["water_level"].toInt();
|
||||||
float water_level = (float) ((float) (data_water_level) / 10.0);
|
float water_level = (float) ((float) (data_water_level) / 10.0);
|
||||||
float rate_of_fill = ( float )(prev_distance - water_level) /(float) time_in_microseconds;
|
float rate_of_fill = ( float )(water_level - prev_distance) /(float) time_in_microseconds;
|
||||||
rate_of_fill = rate_of_fill * 1'000'000;
|
rate_of_fill = rate_of_fill * 1'000'000;
|
||||||
int expected_to_fill = (water_level - min_height) / rate_of_fill;
|
int expected_to_fill = (max_height - water_level) / rate_of_fill;
|
||||||
if(reply_number == 0) {
|
if(reply_number == 0) {
|
||||||
rate_of_fill = 0;
|
rate_of_fill = 0;
|
||||||
expected_to_fill = 0;
|
expected_to_fill = 0;
|
||||||
|
|
@ -95,7 +87,7 @@ void RequestWorker::requestFinished(QNetworkReply *rep)
|
||||||
qDebug() << "Got expected to fill: " << expected_to_fill;
|
qDebug() << "Got expected to fill: " << expected_to_fill;
|
||||||
qDebug() << "Time difference: " << time_in_microseconds;
|
qDebug() << "Time difference: " << time_in_microseconds;
|
||||||
prev_distance = water_level;
|
prev_distance = water_level;
|
||||||
emit networkReply(data_water_level, rate_of_fill, expected_to_fill);
|
emit networkReply(water_level, rate_of_fill, expected_to_fill);
|
||||||
if(stop_timer) {
|
if(stop_timer) {
|
||||||
setStatus("Timer stopped.");
|
setStatus("Timer stopped.");
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,7 @@ public:
|
||||||
void setStatus(const QString &newStatus);
|
void setStatus(const QString &newStatus);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void requestFailed();
|
void networkReply(float distance, float rate_of_fill, int expected_to_fill);
|
||||||
void networkReply(int distance, float rate_of_fill, int expected_to_fill);
|
|
||||||
void statusChanged();
|
void statusChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue