From c6b1f4414617711798961a618601e959ca3777df Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 6 Jun 2022 18:39:50 +0200 Subject: Reformatted newly added code to be closer to convention --- daemon/hwd.conf | 2 +- daemon/src/Sinewave.cpp | 23 ++++++++++++++++------- daemon/src/Sinewave.h | 3 ++- 3 files changed, 19 insertions(+), 9 deletions(-) (limited to 'daemon') diff --git a/daemon/hwd.conf b/daemon/hwd.conf index bdd1819..ba2ab7d 100644 --- a/daemon/hwd.conf +++ b/daemon/hwd.conf @@ -1 +1 @@ -u hwd - "Daemon for Educational Hardware Simulator" \ No newline at end of file +u hwd - "Daemon for Educational Hardware Simulator" diff --git a/daemon/src/Sinewave.cpp b/daemon/src/Sinewave.cpp index 9d63d78..43cad24 100644 --- a/daemon/src/Sinewave.cpp +++ b/daemon/src/Sinewave.cpp @@ -1,56 +1,65 @@ #include "Sinewave.h" -Sinewave::Sinewave() : m_start_time{clock::now()} + +Sinewave::Sinewave() : + m_start_time {clock::now()} { m_amplitude = 11; m_frequency = 10; m_phase = 30; } + void Sinewave::apply(AssemblyContext ctx) { ctx.bind("/set_amplitude", [&](double amplitude) { set_amplitude(amplitude); }); ctx.bind("/set_frequency", [&](double frequency) { set_frequency(frequency); }); - ctx.bind("/set_phase", [&](double phase) { set_phase(phase); }); - ctx.bind("/get_amplitude", [&]() -> double { return get_amplitude(); }); - ctx.bind("/get_frequency", [&]() -> double { return get_frequency(); }); - ctx.bind("/get_phase", [&]() -> double { return get_phase(); }); - ctx.bind("/get_point", [&]() -> double { return get_point(); }); + ctx.bind("/set_phase", [&](double phase) { set_phase(phase); }); + ctx.bind("/get_amplitude", [&]() -> double { return get_amplitude(); }); + ctx.bind("/get_frequency", [&]() -> double { return get_frequency(); }); + ctx.bind("/get_phase", [&]() -> double { return get_phase(); }); + ctx.bind("/get_point", [&]() -> double { return get_point(); }); } + void Sinewave::set_amplitude(double amplitude) { m_amplitude = amplitude; } + void Sinewave::set_frequency(double frequency) { m_frequency = frequency; } + void Sinewave::set_phase(double phase) { m_phase = phase; } + double Sinewave::get_amplitude() const { return m_amplitude; } + double Sinewave::get_frequency() const { return m_frequency; } + double Sinewave::get_phase() const { return m_phase; } + double Sinewave::get_point() const { const std::chrono::duration time = clock::now() - m_start_time; - return m_amplitude * sin(2 * M_PI * m_frequency * time.count() + m_phase); } diff --git a/daemon/src/Sinewave.h b/daemon/src/Sinewave.h index d5be732..ed0d1de 100644 --- a/daemon/src/Sinewave.h +++ b/daemon/src/Sinewave.h @@ -5,7 +5,8 @@ #include "Assembly.h" -class Sinewave + +class Sinewave { using clock = std::chrono::high_resolution_clock; -- cgit v1.1