Skip to content

Commit

Permalink
sweep speed
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Sep 8, 2024
1 parent ae3b70d commit 8c019c3
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 11 deletions.
22 changes: 22 additions & 0 deletions src/bedsidemon/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
bedsidemon - Bed-side monitor example GUI project
Copyright (C) 2024 Gagistech Oy <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/* ================ LICENSE END ================ */

#include "settings.hpp"

#include <filesystem>
Expand Down Expand Up @@ -50,6 +71,7 @@ void settings_storage::set(const settings& s)
{
this->settings_v = s;
this->write();
this->settings_changed_signal.emit();
}

void settings_storage::write()
Expand Down
34 changes: 33 additions & 1 deletion src/bedsidemon/settings.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
/*
bedsidemon - Bed-side monitor example GUI project
Copyright (C) 2024 Gagistech Oy <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/* ================ LICENSE END ================ */

#pragma once

#include <tml/tree.hpp>

#include "signal.hpp"

namespace bedsidemon {

struct settings {
uint32_t sweep_speed_um_per_sec = 25000;
constexpr static const auto default_sweep_speed_um_per_sec = 25000;
uint32_t sweep_speed_um_per_sec = default_sweep_speed_um_per_sec;
};

class settings_storage
Expand All @@ -18,8 +42,16 @@ class settings_storage
void write();

public:
utki::signal settings_changed_signal;

settings_storage();

settings_storage(const settings_storage&) = delete;
settings_storage& operator=(const settings_storage&) = delete;

settings_storage(settings_storage&&) = delete;
settings_storage& operator=(settings_storage&&) = delete;

~settings_storage()
{
this->write(); // TODO: remove?
Expand Down
8 changes: 4 additions & 4 deletions src/bedsidemon/settings_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace {
class selection_box_provider : public ruis::selection_box::provider
{
public:
selection_box_provider() {}
selection_box_provider() = default;

size_t count() const noexcept override
{
Expand All @@ -66,7 +66,7 @@ class selection_box_provider : public ruis::selection_box::provider
{
ASSERT(index < sweep_speeds_um_per_sec.size())

auto speed_um_per_sec = *std::next(sweep_speeds_um_per_sec.begin(), index);
auto speed_um_per_sec = *utki::next(sweep_speeds_um_per_sec.begin(), index);

float speed_mm_per_sec = float(speed_um_per_sec) / float(std::kilo::num);

Expand All @@ -79,7 +79,7 @@ class selection_box_provider : public ruis::selection_box::provider
.layout = ruis::layout::pile
},
.frame_params = {
.borders = {10_pp}
.borders = {10_pp} // NOLINT(cppcoreguidelines-avoid-magic-numbers, "TODO: fix")
}
},
{
Expand Down Expand Up @@ -124,7 +124,7 @@ std::vector<utki::shared_ref<ruis::widget>> make_menu_contents(utki::shared_ref<
m::selection_box(c,
{
.layout_params = {
.dims = {200_pp, ruis::dim::min},
.dims = {200_pp, ruis::dim::min}, // NOLINT(cppcoreguidelines-avoid-magic-numbers, "TODO: fix")
.align = {ruis::align::front, ruis::align::center}
},
.widget_params = {
Expand Down
18 changes: 17 additions & 1 deletion src/bedsidemon/spo2/spo2_parameter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <ruis/widget/label/image.hpp>
#include <ruis/widget/label/rectangle.hpp>

#include "../application.hpp"
#include "../style.hpp"

using namespace std::string_literals;
Expand Down Expand Up @@ -233,7 +234,22 @@ spo2_parameter_window::spo2_parameter_window(utki::shared_ref<ruis::context> con
this->on_heart_timer_expired();
}
))
{}
{
auto& ss = bedsidemon::application::inst().settings_storage;
std::function<void()> settings_change_handler = [&pw = *this, &ss]() {
pw.waveform.set_sweep_speed(ruis::real(ss.get().sweep_speed_um_per_sec) / ruis::real(std::milli::den));
};
settings_change_handler();
this->settings_change_signal_connection = ss.settings_changed_signal.connect(std::move(settings_change_handler));
}

spo2_parameter_window::~spo2_parameter_window() = default;

// {
// TODO: disconnect settings change observer
// auto& ss = bedsidemon::application::inst().settings_storage;
// ss.settings_changed_signal.disconnect(this->settings_change_signal_connection);
// }

void spo2_parameter_window::set(const spo2_measurement& meas)
{
Expand Down
10 changes: 10 additions & 0 deletions src/bedsidemon/spo2/spo2_parameter_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <ruis/widget/label/text.hpp>
#include <ruis/widget/widget.hpp>

#include "../signal.hpp"
#include "../waveform.hpp"

#include "spo2_measurement.hpp"
Expand All @@ -46,8 +47,17 @@ class spo2_parameter_window :
void trigger_heart();
void on_heart_timer_expired();

utki::signal::connection settings_change_signal_connection;

public:
spo2_parameter_window(utki::shared_ref<ruis::context> context);
~spo2_parameter_window() override;

spo2_parameter_window(const spo2_parameter_window&) = delete;
spo2_parameter_window& operator=(const spo2_parameter_window&) = delete;

spo2_parameter_window(spo2_parameter_window&&) = delete;
spo2_parameter_window& operator=(spo2_parameter_window&&) = delete;

void set(const spo2_measurement& meas);
};
Expand Down
19 changes: 14 additions & 5 deletions src/bedsidemon/waveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace {
constexpr auto default_max_value = 100;
} // namespace

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init, "TODO: fix")
waveform::waveform(//
utki::shared_ref<ruis::context> context, all_parameters params) :
ruis::widget( //
Expand All @@ -43,16 +44,24 @@ utki::shared_ref<ruis::context> context, all_parameters params) :
}},
value_max(default_max_value)
{
constexpr auto default_sweep_speed_mm_per_sec = 100;
// this->px_per_ms =
// this->context.get().units.mm_to_px(default_sweep_speed_mm_per_sec /
// 1000.0);
this->px_per_ms = ruis::real(default_sweep_speed_mm_per_sec) / std::milli::den;
constexpr auto default_sweep_speed_mm_per_sec = 25;
this->set_sweep_speed(default_sweep_speed_mm_per_sec);

constexpr auto default_gap_pp = 30;
this->gap_px = this->context.get().units.pp_to_px(default_gap_pp);
}

void waveform::set_sweep_speed(ruis::real mm_per_sec)
{
// TODO: use mm_to_px unit conversion
constexpr auto px_per_mm = 6.65;

// this->px_per_ms = this->context.get().units.mm_to_px(default_sweep_speed_mm_per_sec /
// ruis::real(std::milli::den));
this->px_per_ms = ruis::real(mm_per_sec * px_per_mm) / std::milli::den;
// std::cout << "px per ms = " << this->px_per_ms << std::endl;
}

void waveform::render(const ruis::matrix4& matrix) const
{
for (const auto& pv : this->paths) {
Expand Down
2 changes: 2 additions & 0 deletions src/bedsidemon/waveform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class waveform :

void clear();

void set_sweep_speed(ruis::real mm_per_sec);

private:
void make_vaos();
};
Expand Down

0 comments on commit 8c019c3

Please sign in to comment.