Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopwatch external app #2553

Merged
merged 3 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions firmware/application/external/external.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ set(EXTCPPSRC

#shoppingcart_lock
external/shoppingcart_lock/main.cpp
external/shoppingcart_lock/shoppingcart_lock.cpp
external/shoppingcart_lock/shoppingcart_lock.cpp

#ookbrute
external/ookbrute/main.cpp
Expand All @@ -129,8 +129,8 @@ set(EXTCPPSRC

#cvs_spam
external/cvs_spam/main.cpp
external/cvs_spam/cvs_spam.cpp
external/cvs_spam/cvs_spam.cpp

#flippertx
external/flippertx/main.cpp
external/flippertx/ui_flippertx.cpp
Expand All @@ -142,15 +142,15 @@ set(EXTCPPSRC
#mcu_temperature
external/mcu_temperature/main.cpp
external/mcu_temperature/mcu_temperature.cpp

#fmradio
external/fmradio/main.cpp
external/fmradio/ui_fmradio.cpp

#tuner
external/tuner/main.cpp
external/tuner/ui_tuner.cpp

#metronome
external/metronome/main.cpp
external/metronome/ui_metronome.cpp
Expand All @@ -162,8 +162,8 @@ set(EXTCPPSRC
#hopper
external/hopper/main.cpp
external/hopper/ui_hopper.cpp
# whip calculator

# whip calculator
external/antenna_length/main.cpp
external/antenna_length/ui_whipcalc.cpp

Expand All @@ -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
Expand Down Expand Up @@ -224,4 +228,5 @@ set(EXTAPPLIST
view_wav
sd_wipe
playlist_editor
stopwatch
)
48 changes: 27 additions & 21 deletions firmware/application/external/external.ld
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,25 @@ MEMORY
ram_external_app_sstvtx(rwx) : org = 0xADC70000, len = 32k
ram_external_app_random_password(rwx) : org = 0xADC80000, len = 32k
ram_external_app_acars_rx(rwx) : org = 0xADC90000, len = 32k
ram_external_app_shoppingcart_lock(rwx) : org = 0xADCA0000, len = 32k
ram_external_app_cvs_spam(rwx) : org = 0xADCB0000, len = 32k
ram_external_app_ookbrute(rwx) : org = 0xADCC0000, len = 32k
ram_external_app_flippertx(rwx) : org = 0xADCD0000, len = 32k
ram_external_app_ook_editor(rwx) : org = 0xADCE0000, len = 32k
ram_external_app_remote(rwx) : org = 0xADCF0000, len = 32k
ram_external_app_mcu_temperature(rwx) : org = 0xADD00000, len = 32k
ram_external_app_fmradio(rwx) : org = 0xADD10000, len = 32k
ram_external_app_shoppingcart_lock(rwx) : org = 0xADCA0000, len = 32k
ram_external_app_cvs_spam(rwx) : org = 0xADCB0000, len = 32k
ram_external_app_ookbrute(rwx) : org = 0xADCC0000, len = 32k
ram_external_app_flippertx(rwx) : org = 0xADCD0000, len = 32k
ram_external_app_ook_editor(rwx) : org = 0xADCE0000, len = 32k
ram_external_app_remote(rwx) : org = 0xADCF0000, len = 32k
ram_external_app_mcu_temperature(rwx) : org = 0xADD00000, len = 32k
ram_external_app_fmradio(rwx) : org = 0xADD10000, len = 32k
ram_external_app_tuner(rwx) : org = 0xADD20000, len = 32k
ram_external_app_metronome(rwx) : org = 0xADD30000, len = 32k
ram_external_app_app_manager(rwx) : org = 0xADD40000, len = 32k
ram_external_app_hopper(rwx) : org = 0xADD50000, len = 32k
ram_external_app_antenna_length(rwx) : org = 0xADD60000, len = 32k
ram_external_app_view_wav(rwx) : org = 0xADD70000, len = 32k
ram_external_app_sd_wipe(rwx) : org = 0xADD80000, len = 32k
ram_external_app_playlist_editor(rwx) : org = 0xADD90000, len = 32k
ram_external_app_metronome(rwx) : org = 0xADD30000, len = 32k
ram_external_app_app_manager(rwx) : org = 0xADD40000, len = 32k
ram_external_app_hopper(rwx) : org = 0xADD50000, len = 32k
ram_external_app_antenna_length(rwx) : org = 0xADD60000, len = 32k
ram_external_app_view_wav(rwx) : org = 0xADD70000, len = 32k
ram_external_app_sd_wipe(rwx) : org = 0xADD80000, len = 32k
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_snake(rwx) : org = 0xADDB0000, len = 32k
ram_external_app_stopwatch(rwx) : org = 0xADDC0000, len = 32k
}

SECTIONS
Expand Down Expand Up @@ -158,13 +159,13 @@ SECTIONS
{
KEEP(*(.external_app.app_breakout.application_information));
*(*ui*external_app*breakout*);
} > ram_external_app_breakout
} > ram_external_app_breakout

.external_app_snake : ALIGN(4) SUBALIGN(4)
{
KEEP(*(.external_app.app_snake.application_information));
*(*ui*external_app*snake*);
} > ram_external_app_snake
} > ram_external_app_snake

.external_app_extsensors : ALIGN(4) SUBALIGN(4)
{
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -274,13 +274,13 @@ SECTIONS
KEEP(*(.external_app.app_mcu_temperature.application_information));
*(*ui*external_app*mcu_temperature*);
} > ram_external_app_mcu_temperature

.external_app_fmradio : ALIGN(4) SUBALIGN(4)
{
KEEP(*(.external_app.app_fmradio.application_information));
*(*ui*external_app*fmradio*);
} > ram_external_app_fmradio

.external_app_tuner : ALIGN(4) SUBALIGN(4)
{
KEEP(*(.external_app.app_tuner.application_information));
Expand Down Expand Up @@ -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 changes: 83 additions & 0 deletions firmware/application/external/stopwatch/main.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 101 additions & 0 deletions firmware/application/external/stopwatch/ui_stopwatch.cpp
Original file line number Diff line number Diff line change
@@ -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
Loading