mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-10 16:49:36 +00:00
Stopwatch external app (#2553)
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
@@ -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
|
||||
@@ -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__*/
|
||||
Reference in New Issue
Block a user