Move more apps + language module (#1643)

* CoasterP to ext (Burger pager)
* LGE to ext app
* Solve compiler literal removal with centralizing common string literals.
This commit is contained in:
Totoo 2023-12-12 16:55:50 +01:00 committed by GitHub
parent 5b9d898202
commit b58ee761a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 429 additions and 152 deletions

View file

@ -0,0 +1,357 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2019 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.
*/
// The UI for this app is in French because it concerns leisure centers
// only established in France. "LGE" stands for a trademark I'd rather
// not spell out completely here.
#include "lge_app.hpp"
#include "baseband_api.hpp"
#include "ui_textentry.hpp"
#include "string_format.hpp"
#include <cstring>
#include <stdio.h>
using namespace portapack;
namespace ui::external_app::lge {
void LGEView::focus() {
options_frame.focus();
}
LGEView::~LGEView() {
transmitter_model.disable();
baseband::shutdown();
}
void LGEView::generate_lge_frame(const uint8_t command, const uint16_t address_a, const uint16_t address_b, std::vector<uint8_t>& data) {
std::array<uint8_t, 5> header = {
command,
(uint8_t)(address_a & 255),
(uint8_t)(address_a >> 8),
(uint8_t)(address_b & 255),
(uint8_t)(address_b >> 8),
};
data.insert(data.begin(), header.begin(), header.end());
frame_size = rfm69.gen_frame(data);
for (auto b : data)
console.write(to_string_hex(b, 2) + " ");
}
void LGEView::generate_frame_touche() {
// 0001.89s
// 0D 96 02 12 0E 00 46 28 01 45 27 01 44 23 66 30
std::vector<uint8_t> data{0x46, 0x28, 0x01, 0x45, 0x27, 0x01, 0x44, 0x23};
console.write("\n" STR_COLOR_LIGHT_GREY "Touche:");
generate_lge_frame(0x96, (field_player.value() << 8) | field_room.value(), 0x0001, data);
}
void LGEView::generate_frame_nickname() {
// 0040.48s:
// 30 02 1A 00 19 00 FF 00 02 19 42 52 45 42 49 53 20 00 00 00 00 00 00 00 00 00
// 04 01 B0 04 7F 1F 11 33 40 1F 22 01 07 00 00 01 07 00 00 63 05 00 00 99 A2
std::vector<uint8_t> data{};
std::array<uint8_t, 3> data_header = {0xFF, 0x00, 0x02};
std::array<uint8_t, 22> data_footer = {
0x01, 0xB0, 0x04, 0x7F,
0x1F, 0x11, 0x33, 0x40,
0x1F, 0x22, 0x01, 0x07,
0x00, 0x00, 0x01, 0x07,
0x00, 0x00, 0x63, 0x05,
0x00, 0x00};
uint32_t c;
// data_header[2] = field_room.value(); // ?
// data_footer[0] = field_room.value(); // ?
data.insert(data.begin(), data_header.begin(), data_header.end());
data.push_back(field_player.value());
c = 0;
for (auto& ch : nickname) {
data.push_back(ch);
c++;
}
// Space at the end, is this required ?
data.push_back(0x20);
// Pad with zeroes
while (++c < 16)
data.push_back(0x00);
data.push_back(field_team.value());
data.insert(data.end(), data_footer.begin(), data_footer.end());
console.write("\n" STR_COLOR_YELLOW "Set nickname:");
generate_lge_frame(0x02, 0x001A, field_player.value(), data);
}
void LGEView::generate_frame_team() {
// 0041.83s:
// 3D 03 FF FF FF FF 02 03 01 52 4F 55 47 45 00 00 00 00 00 00 00 00 00 00 00 00
// 02 56 45 52 54 45 00 00 00 00 00 00 00 00 00 00 00 01 03 42 4C 45 55 45 00 00
// 00 00 00 00 00 00 00 00 00 02 43 29
std::vector<uint8_t> data{};
std::array<uint8_t, 2> data_header = {0x02, 0x01};
uint32_t c;
data.insert(data.begin(), data_header.begin(), data_header.end());
data.push_back(field_team.value());
c = 0;
for (auto& ch : nickname) {
data.push_back(ch);
c++;
}
// Pad with zeroes
while (c++ < 16)
data.push_back(0x00);
data.push_back(field_team.value() - 1); // Color ?
console.write("\n" STR_COLOR_GREEN "Set team:");
generate_lge_frame(0x03, data);
}
void LGEView::generate_frame_broadcast_nickname() {
// 0043.86s:
// 3D 04 FF FF FF FF 02 03 19 42 52 45 42 49 53 20 00 00 00 00 00 00 00 00 00 04
// 07 50 4F 4E 45 59 20 00 00 00 00 00 00 00 00 00 00 05 1B 41 42 42 59 20 00 00
// 00 00 00 00 00 00 00 00 00 04 0A 02
std::vector<uint8_t> data{};
std::array<uint8_t, 2> data_header = {0x02, 0x01};
uint32_t c;
data.insert(data.begin(), data_header.begin(), data_header.end());
data.push_back(field_player.value());
c = 0;
for (auto& ch : nickname) {
data.push_back(ch);
c++;
}
// Space at the end, is this required ?
data.push_back(0x20);
// Pad with zeroes
while (++c < 16)
data.push_back(0x00);
data.push_back(field_team.value());
console.write("\n" STR_COLOR_BLUE "Broadcast nickname:");
generate_lge_frame(0x04, data);
}
void LGEView::generate_frame_start() {
// 0166.13s:
// 0A 05 FF FF FF FF 02 EC FF FF FF A3 35
std::vector<uint8_t> data{0x02, 0xEC, 0xFF, 0xFF, 0xFF};
// data[0] = field_room.value(); // ?
console.write("\n" STR_COLOR_MAGENTA "Start:");
generate_lge_frame(0x05, data);
}
void LGEView::generate_frame_gameover() {
std::vector<uint8_t> data{(uint8_t)field_room.value()};
console.write("\n" STR_COLOR_RED "Gameover:");
generate_lge_frame(0x0D, data);
}
void LGEView::generate_frame_collier() {
uint8_t flags = 0;
// Custom
// 0C 00 13 37 13 37 id flags channel playerid zapduty zaptime checksum CRC CRC
// channel: field_channel
// playerid: field_player
// zapduty: field_power
// zaptime: field_duration
if (checkbox_heartbeat.value())
flags |= 1;
if (checkbox_rxtick.value())
flags |= 2;
uint8_t checksum = 0;
uint8_t id = (uint8_t)field_id.value();
std::vector<uint8_t> data{
id,
flags,
(uint8_t)field_room.value(),
(uint8_t)field_player.value(),
(uint8_t)field_power.value(),
(uint8_t)(field_duration.value() * 10)};
for (auto& v : data)
checksum += v;
data.push_back(checksum - id);
console.write("\n" STR_COLOR_DARK_YELLOW "Config:");
generate_lge_frame(0x00, 0x3713, 0x3713, data);
}
void LGEView::start_tx() {
if (tx_mode == ALL) {
transmitter_model.set_target_frequency(channels[channel_index]);
tx_view.on_show(); // Refresh tuning frequency display
tx_view.set_dirty();
}
/* By experimental test, previous fw 1.7.4 seems to have setting , tx LPF = 5Mhz
This LGE - seems to be for controlling a "laser tag equipment" (Havoc app) , modulated FSK , low bauds,
and using max GUI fm dev 150k , we are still in NBFM, let's reduce slightly original TX LPF 5M ->2M5*/
transmitter_model.set_baseband_bandwidth(2'500'000);
transmitter_model.enable();
chThdSleep(100);
baseband::set_fsk_data(frame_size * 8, 2280000 / 9600, 4000, 256);
}
void LGEView::stop_tx() {
tx_mode = IDLE;
transmitter_model.disable();
tx_view.set_transmitting(false);
}
void LGEView::on_tx_progress(const uint32_t progress, const bool done) {
(void)progress;
if (!done) return;
transmitter_model.disable();
/*if (repeats < 2) {
chThdSleep(100);
repeats++;
start_tx();
} else {*/
if (tx_mode == ALL) {
if (channel_index < 2) {
channel_index++;
repeats = 0;
start_tx();
} else {
stop_tx();
}
} else {
stop_tx();
}
//}
}
LGEView::LGEView(NavigationView& nav) {
baseband::run_image(portapack::spi_flash::image_tag_fsktx);
add_children({&labels,
&options_frame,
&field_room,
&button_text,
&field_team,
&field_player,
&field_id,
&field_power,
&field_duration,
&checkbox_heartbeat,
&checkbox_rxtick,
&checkbox_channels,
&console,
&tx_view});
field_room.set_value(1);
field_team.set_value(1);
field_player.set_value(1);
field_id.set_value(1);
field_power.set_value(1);
field_duration.set_value(2);
button_text.on_select = [this, &nav](Button&) {
text_prompt(
nav,
nickname,
15,
[this](std::string& buffer) {
button_text.set_text(buffer);
});
};
tx_view.on_edit_frequency = [this, &nav]() {
auto new_view = nav.push<FrequencyKeypadView>(transmitter_model.target_frequency());
new_view->on_changed = [this](rf::Frequency f) {
transmitter_model.set_target_frequency(f);
};
};
tx_view.on_start = [this]() {
if (tx_mode == IDLE) {
auto i = options_frame.selected_index_value();
if (i == 0)
generate_frame_touche();
else if (i == 1)
generate_frame_nickname();
else if (i == 2)
generate_frame_team();
else if (i == 3)
generate_frame_broadcast_nickname();
else if (i == 4)
generate_frame_start();
else if (i == 5)
generate_frame_gameover();
else if (i == 6)
generate_frame_collier();
repeats = 0;
channel_index = 0;
tx_mode = checkbox_channels.value() ? ALL : SINGLE;
tx_view.set_transmitting(true);
start_tx();
}
};
tx_view.on_stop = [this]() {
stop_tx();
};
}
} /* namespace ui::external_app::lge */

View file

@ -0,0 +1,189 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2019 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.
*/
#include "ui.hpp"
#include "ui_language.hpp"
#include "ui_widget.hpp"
#include "ui_navigation.hpp"
#include "ui_transmitter.hpp"
#include "rfm69.hpp"
#include "message.hpp"
#include "transmitter_model.hpp"
#include "portapack.hpp"
#include "app_settings.hpp"
#include "radio_state.hpp"
namespace ui::external_app::lge {
class LGEView : public View {
public:
LGEView(NavigationView& nav);
~LGEView();
void focus() override;
std::string title() const override { return "LGE tool TX"; };
private:
enum tx_modes {
IDLE = 0,
SINGLE,
ALL
};
TxRadioState radio_state_{
868067000 /* frequency */,
1750000 /* bandwidth */,
2280000 /* sampling rate */
};
app_settings::SettingsManager settings_{
"tx_lge", app_settings::Mode::TX};
tx_modes tx_mode = IDLE;
RFM69 rfm69{5, 0x2DD4, true, true};
uint32_t frame_size{0};
uint32_t repeats{0};
uint32_t channel_index{0};
std::string nickname{"ABCDEF"};
rf::Frequency channels[3] = {868067000, 868183000, 868295000};
void start_tx();
void stop_tx();
void generate_lge_frame(const uint8_t command, std::vector<uint8_t>& data) {
generate_lge_frame(command, 0xFFFF, 0xFFFF, data);
}
void generate_lge_frame(const uint8_t command, const uint16_t address_a, const uint16_t address_b, std::vector<uint8_t>& data);
void generate_frame_touche();
void generate_frame_nickname();
void generate_frame_team();
void generate_frame_broadcast_nickname();
void generate_frame_start();
void generate_frame_gameover();
void generate_frame_collier();
void on_tx_progress(const uint32_t progress, const bool done);
Labels labels{
//{ { 7 * 8, 1 * 8 }, "NO FUN ALLOWED !", Color::red() },
{{1 * 8, 1 * 8}, "Frame:", Color::light_grey()},
{{2 * 8, 3 * 8}, "Room:", Color::light_grey()},
{{14 * 8, 3 * 8}, "Text:", Color::light_grey()},
{{2 * 8, 5 * 8}, "Team:", Color::light_grey()},
{{0 * 8, 7 * 8}, "Player:", Color::light_grey()},
{{0 * 8, 10 * 8}, "Vest:", Color::light_grey()},
{{4 * 8, 12 * 8}, "ID:", Color::light_grey()},
{{3 * 8, 14 * 8}, "Pow: /10", Color::light_grey()},
{{2 * 8, 16 * 8}, "Time: x100ms", Color::light_grey()}};
OptionsField options_frame{
{7 * 8, 1 * 8},
13,
{{"Key", 0},
{"Set nickname", 1},
{"Set team", 2},
{"Brdcst nick", 3},
{LanguageHelper::currentMessages[LANG_START], 4},
{"Game over", 5},
{"Set vest", 6}}};
Checkbox checkbox_channels{
{20 * 8, 1 * 8},
7,
"All ch.",
true};
NumberField field_room{
{7 * 8, 3 * 8},
1,
{1, 2},
1,
'0'};
Button button_text{
{14 * 8, 5 * 8, 16 * 8, 3 * 8},
"ABCDEF"};
NumberField field_team{
{7 * 8, 5 * 8},
1,
{1, 6},
1,
'0'};
NumberField field_player{
{7 * 8, 7 * 8},
2,
{1, 50},
1,
'0'};
Checkbox checkbox_heartbeat{
{17 * 8, 12 * 8},
9,
"Heartbeat",
true};
Checkbox checkbox_rxtick{
{17 * 8, 15 * 8},
7,
"RX tick",
true};
NumberField field_id{
{7 * 8, 12 * 8},
1,
{1, 2},
1,
'0'};
NumberField field_power{
{7 * 8, 14 * 8},
2,
{1, 10},
1,
'0'};
NumberField field_duration{
{7 * 8, 16 * 8},
2,
{1, 25},
1,
'0'};
Console console{
{0, 18 * 8, 30 * 8, 7 * 16}};
TransmitterView tx_view{
16 * 16,
10000,
12};
MessageHandlerRegistration message_handler_tx_progress{
Message::ID::TXProgress,
[this](const Message* const p) {
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
this->on_tx_progress(message.progress, message.done);
}};
};
} /* namespace ui::external_app::lge */

View 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 "lge_app.hpp"
#include "ui_navigation.hpp"
#include "external_app.hpp"
namespace ui::external_app::lge {
void initialize_app(ui::NavigationView& nav) {
nav.push<LGEView>();
}
} // namespace ui::external_app::lge
extern "C" {
__attribute__((section(".external_app.app_lge.application_information"), used)) application_information_t _application_information_lge = {
/*.memory_location = */ (uint8_t*)0x00000000,
/*.externalAppEntry = */ ui::external_app::lge::initialize_app,
/*.header_version = */ CURRENT_HEADER_VERSION,
/*.app_version = */ VERSION_MD5,
/*.app_name = */ "LGE",
/*.bitmap_data = */ {
0x00,
0x00,
0x80,
0x00,
0xA4,
0x12,
0xA8,
0x0A,
0xD0,
0x05,
0xEC,
0x1B,
0xF0,
0x07,
0xFE,
0xFF,
0xF0,
0x07,
0xEC,
0x1B,
0xD0,
0x05,
0xA8,
0x0A,
0xA4,
0x12,
0x80,
0x00,
0x00,
0x00,
0x00,
0x00,
},
/*.icon_color = */ ui::Color::yellow().v,
/*.menu_location = */ app_location_t::TX,
/*.m4_app_tag = portapack::spi_flash::image_tag_fsktx */ {'P', 'F', 'S', 'K'},
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
};
}