mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Calculator app (#1474)
* implemented calculator app * improved output * refactoring
This commit is contained in:
parent
1185b67b28
commit
5a850984b9
2072
firmware/application/external/calculator/ivt.hpp
vendored
Normal file
2072
firmware/application/external/calculator/ivt.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
82
firmware/application/external/calculator/main.cpp
vendored
Normal file
82
firmware/application/external/calculator/main.cpp
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* 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_calculator.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::calculator {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<CalculatorView>();
|
||||
}
|
||||
} // namespace ui::external_app::calculator
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_calculator.application_information"), used)) application_information_t _application_information_calculator = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::calculator::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "Calculator",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0xF8,
|
||||
0x1F,
|
||||
0xF8,
|
||||
0x1F,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x80,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::yellow().v,
|
||||
/*.menu_location = */ app_location_t::UTILITIES,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_noop */ {'\0', '\0', '\0', '\0'}, // optional
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
269
firmware/application/external/calculator/ui_calculator.cpp
vendored
Normal file
269
firmware/application/external/calculator/ui_calculator.cpp
vendored
Normal file
@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* 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_calculator.hpp"
|
||||
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::calculator {
|
||||
|
||||
uint8_t current_key = 255;
|
||||
char display_string[10];
|
||||
uint8_t fgm = 0;
|
||||
|
||||
// interface to external code
|
||||
unsigned int mp;
|
||||
|
||||
char CHARMAP[] = {
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'A',
|
||||
'B',
|
||||
'C',
|
||||
'D',
|
||||
'E',
|
||||
'F',
|
||||
'H',
|
||||
'I',
|
||||
'L',
|
||||
'M',
|
||||
'N',
|
||||
'O',
|
||||
'P',
|
||||
'R',
|
||||
'S',
|
||||
'T',
|
||||
'U',
|
||||
'V',
|
||||
'c',
|
||||
's',
|
||||
't',
|
||||
' ',
|
||||
'.',
|
||||
'*',
|
||||
'+',
|
||||
'-',
|
||||
'/',
|
||||
'!',
|
||||
'<',
|
||||
'=',
|
||||
'>',
|
||||
'^',
|
||||
'f',
|
||||
'n',
|
||||
'p',
|
||||
's',
|
||||
'm',
|
||||
'w',
|
||||
|
||||
};
|
||||
|
||||
void printcat(uint8_t c, uint8_t x) { // Print char c at position x
|
||||
display_string[x] = CHARMAP[c];
|
||||
}
|
||||
uint8_t getkey(void) { // Read keypad
|
||||
return current_key;
|
||||
}
|
||||
|
||||
#include "ivt.hpp"
|
||||
|
||||
void step() {
|
||||
loop();
|
||||
}
|
||||
|
||||
void CalculatorView::focus() {
|
||||
button_F.focus();
|
||||
}
|
||||
|
||||
CalculatorView::CalculatorView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
add_children({&button_F,
|
||||
&button_7,
|
||||
&button_8,
|
||||
&button_9,
|
||||
&button_E,
|
||||
&button_4,
|
||||
&button_5,
|
||||
&button_6,
|
||||
&button_N,
|
||||
&button_1,
|
||||
&button_2,
|
||||
&button_3,
|
||||
&button_C,
|
||||
&button_0,
|
||||
&button_P,
|
||||
&button_D,
|
||||
&console});
|
||||
|
||||
button_F.on_select = [&nav, this](Button&) { on_button_press(0); };
|
||||
button_7.on_select = [&nav, this](Button&) { on_button_press(1); };
|
||||
button_8.on_select = [&nav, this](Button&) { on_button_press(2); };
|
||||
button_9.on_select = [&nav, this](Button&) { on_button_press(3); };
|
||||
|
||||
button_E.on_select = [&nav, this](Button&) { on_button_press(4); };
|
||||
button_4.on_select = [&nav, this](Button&) { on_button_press(5); };
|
||||
button_5.on_select = [&nav, this](Button&) { on_button_press(6); };
|
||||
button_6.on_select = [&nav, this](Button&) { on_button_press(7); };
|
||||
|
||||
button_N.on_select = [&nav, this](Button&) { on_button_press(8); };
|
||||
button_1.on_select = [&nav, this](Button&) { on_button_press(9); };
|
||||
button_2.on_select = [&nav, this](Button&) { on_button_press(10); };
|
||||
button_3.on_select = [&nav, this](Button&) { on_button_press(11); };
|
||||
|
||||
button_C.on_select = [&nav, this](Button&) { on_button_press(12); };
|
||||
button_0.on_select = [&nav, this](Button&) { on_button_press(13); };
|
||||
button_P.on_select = [&nav, this](Button&) { on_button_press(14); };
|
||||
button_D.on_select = [&nav, this](Button&) { on_button_press(15); };
|
||||
}
|
||||
|
||||
void CalculatorView::on_button_press(uint8_t button) {
|
||||
auto pre_fgm = fgm;
|
||||
for (int i = 0; i < 10; i++)
|
||||
display_string[i] = ' ';
|
||||
|
||||
current_key = button;
|
||||
step();
|
||||
|
||||
do {
|
||||
current_key = 255;
|
||||
step();
|
||||
} while (mp);
|
||||
|
||||
std::string d(&display_string[0], 10);
|
||||
|
||||
if (pre_fgm && button != 0) {
|
||||
console.write(" ");
|
||||
switch (button) {
|
||||
case 1:
|
||||
console.write("SUM+");
|
||||
break;
|
||||
case 2:
|
||||
console.write("PRG");
|
||||
break;
|
||||
case 3:
|
||||
console.write("/");
|
||||
break;
|
||||
|
||||
case 4:
|
||||
console.write("SWAP");
|
||||
break;
|
||||
case 5:
|
||||
console.write("DICT");
|
||||
break;
|
||||
case 6:
|
||||
console.write("USR");
|
||||
break;
|
||||
case 7:
|
||||
console.write("*");
|
||||
break;
|
||||
|
||||
case 8:
|
||||
console.write("ROT");
|
||||
break;
|
||||
case 9:
|
||||
console.write("RCL");
|
||||
break;
|
||||
case 10:
|
||||
console.write("STO");
|
||||
break;
|
||||
case 11:
|
||||
console.write("-");
|
||||
break;
|
||||
|
||||
case 12:
|
||||
console.write("CA");
|
||||
break;
|
||||
case 13:
|
||||
console.write("PI");
|
||||
break;
|
||||
case 14:
|
||||
console.write("INT");
|
||||
break;
|
||||
case 15:
|
||||
console.write("+");
|
||||
break;
|
||||
}
|
||||
console.writeln(d);
|
||||
} else if (button == 15) {
|
||||
console.write("\r");
|
||||
console.writeln(d);
|
||||
} else {
|
||||
console.write("\r");
|
||||
console.write(d);
|
||||
}
|
||||
|
||||
update_button_labels();
|
||||
}
|
||||
|
||||
void CalculatorView::update_button_labels() {
|
||||
if (fgm) {
|
||||
button_F.set_text("MENU");
|
||||
button_7.set_text("SUM+");
|
||||
button_8.set_text("PRG");
|
||||
button_9.set_text("/");
|
||||
|
||||
button_E.set_text("SWAP");
|
||||
button_4.set_text("DICT");
|
||||
button_5.set_text("USR");
|
||||
button_6.set_text("*");
|
||||
|
||||
button_N.set_text("ROT");
|
||||
button_1.set_text("RCL");
|
||||
button_2.set_text("STO");
|
||||
button_3.set_text("-");
|
||||
|
||||
button_C.set_text("CA");
|
||||
button_0.set_text("PI");
|
||||
button_P.set_text("INT");
|
||||
button_D.set_text("+");
|
||||
|
||||
} else {
|
||||
button_F.set_text("F");
|
||||
button_7.set_text("7");
|
||||
button_8.set_text("8");
|
||||
button_9.set_text("9");
|
||||
|
||||
button_E.set_text("E");
|
||||
button_4.set_text("4");
|
||||
button_5.set_text("5");
|
||||
button_6.set_text("6");
|
||||
|
||||
button_N.set_text("N");
|
||||
button_1.set_text("1");
|
||||
button_2.set_text("2");
|
||||
button_3.set_text("3");
|
||||
|
||||
button_C.set_text("C");
|
||||
button_0.set_text("0");
|
||||
button_P.set_text(".");
|
||||
button_D.set_text("D");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::calculator
|
77
firmware/application/external/calculator/ui_calculator.hpp
vendored
Normal file
77
firmware/application/external/calculator/ui_calculator.hpp
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
* Copyright (C) 2017 Furrtek
|
||||
*
|
||||
* 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_calculator_H__
|
||||
#define __UI_calculator_H__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_record_view.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::calculator {
|
||||
|
||||
class CalculatorView : public View {
|
||||
public:
|
||||
CalculatorView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Calculator"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
Button button_F{{0 * 8, 11 * 16, 6 * 8, 16 + 8}, "F"};
|
||||
Button button_7{{8 * 8, 11 * 16, 6 * 8, 16 + 8}, "7"};
|
||||
Button button_8{{16 * 8, 11 * 16, 6 * 8, 16 + 8}, "8"};
|
||||
Button button_9{{24 * 8, 11 * 16, 6 * 8, 16 + 8}, "9"};
|
||||
Button button_E{{0 * 8, 13 * 16, 6 * 8, 16 + 8}, "E"};
|
||||
Button button_4{{8 * 8, 13 * 16, 6 * 8, 16 + 8}, "4"};
|
||||
Button button_5{{16 * 8, 13 * 16, 6 * 8, 16 + 8}, "5"};
|
||||
Button button_6{{24 * 8, 13 * 16, 6 * 8, 16 + 8}, "6"};
|
||||
Button button_N{{0 * 8, 15 * 16, 6 * 8, 16 + 8}, "N"};
|
||||
Button button_1{{8 * 8, 15 * 16, 6 * 8, 16 + 8}, "1"};
|
||||
Button button_2{{16 * 8, 15 * 16, 6 * 8, 16 + 8}, "2"};
|
||||
Button button_3{{24 * 8, 15 * 16, 6 * 8, 16 + 8}, "3"};
|
||||
Button button_C{{0 * 8, 17 * 16, 6 * 8, 16 + 8}, "C"};
|
||||
Button button_0{{8 * 8, 17 * 16, 6 * 8, 16 + 8}, "0"};
|
||||
Button button_P{{16 * 8, 17 * 16, 6 * 8, 16 + 8}, "."};
|
||||
Button button_D{{24 * 8, 17 * 16, 6 * 8, 16 + 8}, "D"};
|
||||
|
||||
Console console{
|
||||
{0 * 8, 0 * 16, screen_width, 10 * 16}};
|
||||
|
||||
void on_button_press(uint8_t button);
|
||||
void update_button_labels();
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::calculator
|
||||
|
||||
#endif /*__UI_calculator_H__*/
|
5
firmware/application/external/external.cmake
vendored
5
firmware/application/external/external.cmake
vendored
@ -7,9 +7,14 @@ set(EXTCPPSRC
|
||||
#afsk_rx
|
||||
external/afsk_rx/main.cpp
|
||||
external/afsk_rx/ui_afsk_rx.cpp
|
||||
|
||||
#calculator
|
||||
external/calculator/main.cpp
|
||||
external/calculator/ui_calculator.cpp
|
||||
)
|
||||
|
||||
set(EXTAPPLIST
|
||||
pacman
|
||||
afsk_rx
|
||||
calculator
|
||||
)
|
||||
|
15
firmware/application/external/external.ld
vendored
15
firmware/application/external/external.ld
vendored
@ -17,21 +17,28 @@
|
||||
MEMORY
|
||||
{
|
||||
/* external apps: regions can't overlap so addresses are corrected after build */
|
||||
ram_external_app_pacman (rwx) : org = 0xEEE90000, len = 40k
|
||||
ram_external_app_afsk_rx (rwx) : org = 0xEEEA0000, len = 40k
|
||||
ram_external_app_pacman (rwx) : org = 0xEEE90000, len = 32k
|
||||
ram_external_app_afsk_rx (rwx) : org = 0xEEEA0000, len = 32k
|
||||
ram_external_app_calculator (rwx) : org = 0xEEEB0000, len = 32k
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.external_app_pacman : ALIGN(16) SUBALIGN(16)
|
||||
.external_app_pacman : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_pacman.application_information));
|
||||
*(*ui*external_app*pacman*);
|
||||
} > ram_external_app_pacman
|
||||
|
||||
.external_app_afsk_rx : ALIGN(16) SUBALIGN(16)
|
||||
.external_app_afsk_rx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_afsk_rx.application_information));
|
||||
*(*ui*external_app*afsk_rx*);
|
||||
} > ram_external_app_afsk_rx
|
||||
|
||||
.external_app_calculator : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_calculator.application_information));
|
||||
*(*ui*external_app*calculator*);
|
||||
} > ram_external_app_calculator
|
||||
}
|
||||
|
@ -626,6 +626,8 @@ void Console::write(std::string message) {
|
||||
} else {
|
||||
if (c == '\n') {
|
||||
crlf();
|
||||
} else if (c == '\r') {
|
||||
pos = {0, pos.y()};
|
||||
} else if (c == '\x1B') {
|
||||
escape = true;
|
||||
} else {
|
||||
|
@ -34,7 +34,7 @@ See firmware/application/CMakeLists.txt > COMMAND ${EXPORT_EXTERNAL_APP_IMAGES}
|
||||
Usage: <command> <project source dir> <binary dir> <cmake objcopy path> <list of external image prefixes>
|
||||
"""
|
||||
|
||||
maximum_application_size = 40*1024
|
||||
maximum_application_size = 32*1024
|
||||
|
||||
if len(sys.argv) < 4:
|
||||
print(usage_message)
|
||||
@ -124,7 +124,7 @@ for external_image_prefix in sys.argv[4:]:
|
||||
external_application_image[m4_app_offset_header_position:m4_app_offset_header_position+4] = app_image_len.to_bytes(4, byteorder='little')
|
||||
|
||||
if (len(external_application_image) > maximum_application_size) != 0:
|
||||
print("application {} can not exceed 40kb: {} bytes used".format(external_image_prefix, len(external_application_image)))
|
||||
print("application {} can not exceed 32kb: {} bytes used".format(external_image_prefix, len(external_application_image)))
|
||||
sys.exit(-1)
|
||||
|
||||
# write .ppma (portapack mayhem application)
|
||||
|
Loading…
Reference in New Issue
Block a user