diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 68e229696..dc642cfbb 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -239,7 +239,6 @@ set(CPPSRC serializer.cpp spectrum_color_lut.cpp string_format.cpp - temperature_logger.cpp theme.cpp touch.cpp tone_key.cpp diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 998bb2c38..63a377def 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -400,8 +400,6 @@ void EventDispatcher::handle_local_queue() { void EventDispatcher::handle_rtc_tick() { sd_card::poll_inserted(); - portapack::temperature_logger.second_tick(); - const auto backlight_timer = portapack::persistent_memory::config_backlight_timer(); if (backlight_timer.timeout_enabled()) { if (portapack::bl_tick_counter == backlight_timer.timeout_seconds()) diff --git a/firmware/application/external/external.cmake b/firmware/application/external/external.cmake index 7a8d07d55..6e21957bc 100644 --- a/firmware/application/external/external.cmake +++ b/firmware/application/external/external.cmake @@ -169,6 +169,7 @@ set(EXTCPPSRC #mcu_temperature 112 external/mcu_temperature/main.cpp external/mcu_temperature/mcu_temperature.cpp + external/mcu_temperature/temperature_logger.cpp #fmradio 640 external/fmradio/main.cpp diff --git a/firmware/application/external/mcu_temperature/mcu_temperature.cpp b/firmware/application/external/mcu_temperature/mcu_temperature.cpp index aee90308b..5072b411f 100644 --- a/firmware/application/external/mcu_temperature/mcu_temperature.cpp +++ b/firmware/application/external/mcu_temperature/mcu_temperature.cpp @@ -8,14 +8,12 @@ using namespace portapack; namespace ui::external_app::mcu_temperature { void McuTemperatureWidget::paint(Painter& painter) { - const auto logger = portapack::temperature_logger; - const auto rect = screen_rect(); const Color color_background{0, 0, 64}; const Color color_foreground = Theme::getInstance()->fg_green->foreground; const Color color_reticle{128, 128, 128}; - const auto graph_width = static_cast(logger.capacity()) * bar_width; + const auto graph_width = static_cast(temperature_logger.capacity()) * bar_width; const Rect graph_rect{ rect.left() + (rect.width() - graph_width) / 2, rect.top() + 8, graph_width, rect.height()}; @@ -25,7 +23,7 @@ void McuTemperatureWidget::paint(Painter& painter) { painter.draw_rectangle(frame_rect, color_reticle); painter.fill_rectangle(graph_rect, color_background); - const auto history = logger.history(); + const auto history = temperature_logger.history(); for (size_t i = 0; i < history.size(); i++) { const Coord x = graph_rect.right() - (history.size() - i) * bar_width; const auto sample = history[i]; diff --git a/firmware/application/external/mcu_temperature/mcu_temperature.hpp b/firmware/application/external/mcu_temperature/mcu_temperature.hpp index d004681d3..fa3fcfc9f 100644 --- a/firmware/application/external/mcu_temperature/mcu_temperature.hpp +++ b/firmware/application/external/mcu_temperature/mcu_temperature.hpp @@ -32,7 +32,7 @@ #include "portapack.hpp" #include "memory_map.hpp" #include "irq_controls.hpp" - +#include "temperature_logger.hpp" #include #include @@ -43,14 +43,25 @@ class McuTemperatureWidget : public Widget { explicit McuTemperatureWidget( Rect parent_rect) : Widget{parent_rect} { + signal_token_tick_second = rtc_time::signal_tick_second += [this]() { + this->on_tick_second(); + }; + } + ~McuTemperatureWidget() { + rtc_time::signal_tick_second -= signal_token_tick_second; + } + void on_tick_second() { + temperature_logger.second_tick(); + set_dirty(); } - void paint(Painter& painter) override; private: + TemperatureLogger temperature_logger{}; + using sample_t = uint32_t; using temperature_t = int32_t; - + SignalToken signal_token_tick_second{}; temperature_t temperature(const sample_t sensor_value) const; Coord screen_y(const temperature_t temperature, const Rect& screen_rect) const; diff --git a/firmware/application/temperature_logger.cpp b/firmware/application/external/mcu_temperature/temperature_logger.cpp similarity index 95% rename from firmware/application/temperature_logger.cpp rename to firmware/application/external/mcu_temperature/temperature_logger.cpp index 3d80d7213..7e63bc37c 100644 --- a/firmware/application/temperature_logger.cpp +++ b/firmware/application/external/mcu_temperature/temperature_logger.cpp @@ -25,6 +25,8 @@ #include +namespace ui::external_app::mcu_temperature { + void TemperatureLogger::second_tick() { sample_phase++; if (sample_phase >= sample_interval) { @@ -67,3 +69,5 @@ void TemperatureLogger::push_sample(const TemperatureLogger::sample_t sample) { samples_count++; sample_phase = 0; } + +} // namespace ui::external_app::mcu_temperature diff --git a/firmware/application/temperature_logger.hpp b/firmware/application/external/mcu_temperature/temperature_logger.hpp similarity index 93% rename from firmware/application/temperature_logger.hpp rename to firmware/application/external/mcu_temperature/temperature_logger.hpp index d83a88b5b..a8ed15733 100644 --- a/firmware/application/temperature_logger.hpp +++ b/firmware/application/external/mcu_temperature/temperature_logger.hpp @@ -27,6 +27,8 @@ #include #include +namespace ui::external_app::mcu_temperature { + class TemperatureLogger { public: using sample_t = int8_t; @@ -49,4 +51,6 @@ class TemperatureLogger { void push_sample(const sample_t sample); }; +} // namespace ui::external_app::mcu_temperature + #endif /*__TEMPERATURE_LOGGER_H__*/ diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 5715eb2db..253bc26f2 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -102,8 +102,6 @@ AK4951 audio_codec_ak4951{i2c0, 0x12}; ReceiverModel receiver_model; TransmitterModel transmitter_model; -TemperatureLogger temperature_logger; - bool antenna_bias{false}; uint32_t bl_tick_counter{0}; uint16_t touch_threshold{32}; diff --git a/firmware/application/portapack.hpp b/firmware/application/portapack.hpp index 775ab8434..315bebc51 100644 --- a/firmware/application/portapack.hpp +++ b/firmware/application/portapack.hpp @@ -36,7 +36,6 @@ #include "radio.hpp" #include "clock_manager.hpp" -#include "temperature_logger.hpp" #include "theme.hpp" /* TODO: This would be better as a class to add @@ -69,8 +68,6 @@ extern TransmitterModel transmitter_model; extern uint32_t bl_tick_counter; extern uint16_t touch_threshold; -extern TemperatureLogger temperature_logger; - /* Get or set the antenna_bias flag. * NB: Does not actually update the radio state. */ void set_antenna_bias(const bool v);