mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-08 22:52:27 -04:00
Stopwatch external app (#2553)
This commit is contained in:
parent
24e9504688
commit
084b88564b
8 changed files with 361 additions and 77 deletions
5
firmware/application/external/external.cmake
vendored
5
firmware/application/external/external.cmake
vendored
|
@ -178,6 +178,10 @@ set(EXTCPPSRC
|
|||
# playlist editor
|
||||
external/playlist_editor/main.cpp
|
||||
external/playlist_editor/ui_playlist_editor.cpp
|
||||
|
||||
#stopwatch
|
||||
external/stopwatch/main.cpp
|
||||
external/stopwatch/ui_stopwatch.cpp
|
||||
)
|
||||
|
||||
set(EXTAPPLIST
|
||||
|
@ -224,4 +228,5 @@ set(EXTAPPLIST
|
|||
view_wav
|
||||
sd_wipe
|
||||
playlist_editor
|
||||
stopwatch
|
||||
)
|
||||
|
|
8
firmware/application/external/external.ld
vendored
8
firmware/application/external/external.ld
vendored
|
@ -66,6 +66,7 @@ MEMORY
|
|||
ram_external_app_playlist_editor(rwx) : org = 0xADD90000, len = 32k
|
||||
ram_external_app_breakout(rwx) : org = 0xADDA0000, len = 32k
|
||||
ram_external_app_snake(rwx) : org = 0xADDB0000, len = 32k
|
||||
ram_external_app_stopwatch(rwx) : org = 0xADDC0000, len = 32k
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
|
@ -208,7 +209,6 @@ SECTIONS
|
|||
*(*ui*external_app*adsbtx*);
|
||||
} > ram_external_app_adsbtx
|
||||
|
||||
|
||||
.external_app_morse_tx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_morse_tx.application_information));
|
||||
|
@ -328,4 +328,10 @@ SECTIONS
|
|||
KEEP(*(.external_app.app_playlist_editor.application_information));
|
||||
*(*ui*external_app*playlist_editor*);
|
||||
} > ram_external_app_playlist_editor
|
||||
|
||||
.external_app_stopwatch : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_stopwatch.application_information));
|
||||
*(*ui*external_app*stopwatch*);
|
||||
} > ram_external_app_stopwatch
|
||||
}
|
||||
|
|
83
firmware/application/external/stopwatch/main.cpp
vendored
Normal file
83
firmware/application/external/stopwatch/main.cpp
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2025 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* 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 2, 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_stopwatch.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::stopwatch {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<StopwatchView>();
|
||||
}
|
||||
} // namespace ui::external_app::stopwatch
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_stopwatch.application_information"), used)) application_information_t _application_information_stopwatch = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::stopwatch::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "Stopwatch",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0xC0,
|
||||
0x01,
|
||||
0x80,
|
||||
0x00,
|
||||
0x80,
|
||||
0x20,
|
||||
0x60,
|
||||
0x13,
|
||||
0x10,
|
||||
0x0C,
|
||||
0x88,
|
||||
0x08,
|
||||
0x84,
|
||||
0x10,
|
||||
0x84,
|
||||
0x10,
|
||||
0xC2,
|
||||
0x21,
|
||||
0x84,
|
||||
0x10,
|
||||
0x04,
|
||||
0x10,
|
||||
0x08,
|
||||
0x08,
|
||||
0x10,
|
||||
0x04,
|
||||
0x60,
|
||||
0x03,
|
||||
0x80,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::cyan().v,
|
||||
/*.menu_location = */ app_location_t::UTILITIES,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_none */ {0, 0, 0, 0},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
101
firmware/application/external/stopwatch/ui_stopwatch.cpp
vendored
Normal file
101
firmware/application/external/stopwatch/ui_stopwatch.cpp
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright 2025 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* 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 2, 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui_stopwatch.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "ch.h"
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui::external_app::stopwatch {
|
||||
|
||||
StopwatchView::StopwatchView(NavigationView& nav) {
|
||||
add_children({
|
||||
&labels,
|
||||
&button_run_stop,
|
||||
&button_reset_lap,
|
||||
&button_done,
|
||||
&big_display,
|
||||
&lap_display,
|
||||
});
|
||||
|
||||
button_run_stop.on_select = [this](Button&) {
|
||||
if (running)
|
||||
stop();
|
||||
else
|
||||
run();
|
||||
};
|
||||
|
||||
button_reset_lap.on_select = [this](Button&) {
|
||||
if (running)
|
||||
lap();
|
||||
else
|
||||
reset();
|
||||
};
|
||||
|
||||
button_done.on_select = [&nav](Button&) {
|
||||
nav.pop();
|
||||
};
|
||||
}
|
||||
|
||||
void StopwatchView::focus() {
|
||||
button_run_stop.focus();
|
||||
}
|
||||
|
||||
void StopwatchView::run() {
|
||||
running = true;
|
||||
start_time = chTimeNow() - previously_elapsed;
|
||||
button_run_stop.set_text("STOP");
|
||||
button_reset_lap.set_text("LAP");
|
||||
}
|
||||
|
||||
void StopwatchView::stop() {
|
||||
running = false;
|
||||
end_time = chTimeNow();
|
||||
previously_elapsed = end_time - start_time;
|
||||
button_run_stop.set_text("START");
|
||||
button_reset_lap.set_text("RESET");
|
||||
}
|
||||
|
||||
void StopwatchView::reset() {
|
||||
lap_time = end_time = start_time = previously_elapsed = 0;
|
||||
big_display.set(0);
|
||||
lap_display.set(0);
|
||||
}
|
||||
|
||||
void StopwatchView::lap() {
|
||||
lap_time = chTimeNow();
|
||||
lap_display.set((lap_time - start_time) * 1000); // convert elapsed time in ms to MHz for BigFrequency widget
|
||||
}
|
||||
|
||||
void StopwatchView::paint(Painter& painter) {
|
||||
(void)painter;
|
||||
if (running) {
|
||||
end_time = chTimeNow();
|
||||
big_display.set((end_time - start_time) * 1000); // convert elapsed time in ms to MHz for BigFrequency widget
|
||||
}
|
||||
}
|
||||
|
||||
void StopwatchView::frame_sync() {
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::stopwatch
|
83
firmware/application/external/stopwatch/ui_stopwatch.hpp
vendored
Normal file
83
firmware/application/external/stopwatch/ui_stopwatch.hpp
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright 2025 Mark Thompson
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* 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 2, 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __UI_STOPWATCH_H__
|
||||
#define __UI_STOPWATCH_H__
|
||||
|
||||
#include "ui_navigation.hpp"
|
||||
|
||||
namespace ui::external_app::stopwatch {
|
||||
|
||||
class StopwatchView : public View {
|
||||
public:
|
||||
StopwatchView(NavigationView& nav);
|
||||
void focus() override;
|
||||
void paint(Painter& painter) override;
|
||||
void frame_sync();
|
||||
std::string title() const override { return "Stopwatch"; };
|
||||
|
||||
private:
|
||||
void run();
|
||||
void stop();
|
||||
void reset();
|
||||
void lap();
|
||||
|
||||
bool running{false};
|
||||
long long start_time{0};
|
||||
long long end_time{0};
|
||||
long long lap_time{0};
|
||||
long long previously_elapsed{0};
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 1 * 16}, "TOTAL:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0 * 8, 7 * 16}, "LAP:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
BigFrequency big_display{
|
||||
{4, 2 * 16 + 4, 28 * 8, 52},
|
||||
0};
|
||||
|
||||
BigFrequency lap_display{
|
||||
{4, 8 * 16 + 4, 28 * 8, 52},
|
||||
0};
|
||||
|
||||
Button button_run_stop{
|
||||
{72, 210, 96, 24},
|
||||
"START"};
|
||||
|
||||
Button button_reset_lap{
|
||||
{72, 240, 96, 24},
|
||||
"RESET"};
|
||||
|
||||
Button button_done{
|
||||
{72, 270, 96, 24},
|
||||
"EXIT"};
|
||||
|
||||
MessageHandlerRegistration message_handler_frame_sync{
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) {
|
||||
this->frame_sync();
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::stopwatch
|
||||
|
||||
#endif /*__UI_STOPWATCH_H__*/
|
|
@ -528,6 +528,10 @@ void BigFrequency::paint(Painter& painter) {
|
|||
Point digit_pos;
|
||||
ui::Color segment_color;
|
||||
|
||||
if (_frequency != _previous_frequency) {
|
||||
_previous_frequency = _frequency;
|
||||
|
||||
rf::Frequency frequency{_frequency};
|
||||
const auto rect = screen_rect();
|
||||
|
||||
// Erase
|
||||
|
@ -536,15 +540,15 @@ void BigFrequency::paint(Painter& painter) {
|
|||
Theme::getInstance()->bg_darkest->background);
|
||||
|
||||
// Prepare digits
|
||||
if (!_frequency) {
|
||||
if (!frequency) {
|
||||
digits.fill(10); // ----.---
|
||||
digit_pos = {0, rect.location().y()};
|
||||
} else {
|
||||
_frequency /= 1000; // GMMM.KKK(uuu)
|
||||
frequency /= 1000; // GMMM.KKK(uuu)
|
||||
|
||||
for (i = 0; i < 7; i++) {
|
||||
digits[6 - i] = _frequency % 10;
|
||||
_frequency /= 10;
|
||||
digits[6 - i] = frequency % 10;
|
||||
frequency /= 10;
|
||||
}
|
||||
|
||||
// Remove leading zeros
|
||||
|
@ -583,6 +587,7 @@ void BigFrequency::paint(Painter& painter) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ProgressBar ***********************************************************/
|
||||
|
||||
|
|
|
@ -291,6 +291,7 @@ class BigFrequency : public Widget {
|
|||
|
||||
private:
|
||||
rf::Frequency _frequency;
|
||||
rf::Frequency _previous_frequency{~0LL};
|
||||
|
||||
static constexpr Dim digit_width = 32;
|
||||
|
||||
|
|
BIN
firmware/graphics/stopwatch.png
Normal file
BIN
firmware/graphics/stopwatch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 204 B |
Loading…
Add table
Add a link
Reference in a new issue