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