should be almost done

This commit is contained in:
zxkmm 2024-09-29 13:42:27 +08:00
parent 6ed071b918
commit 8f67ae85ac
2 changed files with 124 additions and 61 deletions

View File

@ -55,7 +55,6 @@ RandomView::RandomView(NavigationView& nav)
&field_vga,
&field_frequency,
&check_log,
&text_debug,
&button_modem_setup,
&labels,
&text_generated_passwd,
@ -64,8 +63,12 @@ RandomView::RandomView(NavigationView& nav)
&check_latin_lower,
&check_latin_upper,
&check_punctuation,
&check_show_seeds,
&check_auto_send,
&button_refresh,
&button_show_qr,
&button_pause,
&button_send,
&field_digits,
&check_allow_confusable_chars,
&text_seed});
@ -144,15 +147,33 @@ RandomView::RandomView(NavigationView& nav)
nav.push<QRCodeView>(password.data());
};
button_pause.on_select = [this](Button&) {
if (paused) {
paused = false;
button_pause.set_text("pause");
} else {
paused = true;
button_pause.set_text("resume");
}
};
button_send.on_select = [this, &nav](Button&) {
portapack::async_tx_enabled = true;
UsbSerialAsyncmsg::asyncmsg(password);
portapack::async_tx_enabled = false;
};
field_digits.on_change = [this](int32_t) {
this->new_password();
};
/// v init setting
/// v check defauly val init
check_digits.set_value(true);
check_latin_lower.set_value(true);
check_latin_upper.set_value(true);
check_punctuation.set_value(true);
check_show_seeds.set_value(true);
field_digits.set_value(8);
///^ init setting
///^ check defauly val init
logger = std::make_unique<RandomLogger>();
if (logger)
@ -167,13 +188,11 @@ RandomView::RandomView(NavigationView& nav)
}
void RandomView::on_data(uint32_t value, bool is_data) {
if (paused)
return;
if (is_data) {
seed = static_cast<unsigned int>(value);
text_seed.set( to_string_dec_uint(seed));
prev_value = value;
text_seed.set(to_string_dec_uint(check_show_seeds.value() ? seed : 0));
} else {
text_generated_passwd.set("Baudrate estimation: ~");
text_char_type_hints.set(to_string_dec_uint(value));
@ -228,32 +247,65 @@ void RandomView::new_password() {
}
int password_length = field_digits.value();
for (int i = 0; i < password_length; i++) {
char c = charset[std::rand() % charset.length()];
password += c;
if (std::isdigit(c))
if (std::isdigit(c)) {
char_type_hints += "1";
else if (std::islower(c))
} else if (std::islower(c)) {
char_type_hints += "a";
else if (std::isupper(c))
} else if (std::isupper(c)) {
char_type_hints += "A";
else
} else {
char_type_hints += ",";
}
}
text_generated_passwd.set(password);
text_char_type_hints.set(char_type_hints);
paint_password_hints(); // TODO: why flash and disappeared
if (logger && logging) {
str_log += generate_log_line();
logger->log_raw_data(str_log);
str_log = "";
}
// portapack::async_tx_enabled = true;
// UsbSerialAsyncmsg::asyncmsg(password);
// portapack::async_tx_enabled = false;
if (check_auto_send.value()) {
portapack::async_tx_enabled = true;
UsbSerialAsyncmsg::asyncmsg(password);
portapack::async_tx_enabled = false;
}
}
void RandomView::paint_password_hints() { // TODO: why flash and disappeared
Painter painter;
const int char_width = 8;
const int char_height = 16;
const int start_y = 6 * char_height + 5;
const int rect_height = 4;
for (size_t i = 0; i < password.length(); i++) {
char c = password[i];
Color color;
if (std::isdigit(c)) {
color = Color::red();
} else if (std::islower(c)) {
color = Color::green();
} else if (std::isupper(c)) {
color = Color::blue();
} else {
color = Color::white();
}
painter.fill_rectangle(
{{static_cast<int>(i) * char_width, start_y},
{char_width, rect_height}},
color);
}
}
std::string RandomView::generate_log_line() {
@ -263,8 +315,6 @@ std::string RandomView::generate_log_line() {
return line;
}
bool RandomView::seed_protect_helper() {}
RandomView::~RandomView() {
receiver_model.disable();
baseband::shutdown();

View File

@ -36,7 +36,6 @@
#include "ui_qrcode.hpp"
#include "usb_serial_asyncmsg.hpp"
using namespace ui;
namespace ui::external_app::random {
@ -69,98 +68,114 @@ class RandomView : public View {
void on_data(uint32_t value, bool is_data);
void new_password();
std::string generate_log_line();
void paint_password_hints();
NavigationView& nav_;
RxRadioState radio_state_{};
app_settings::SettingsManager settings_{
"rx_afsk", app_settings::Mode::RX};
uint32_t prev_value{0};
std::string str_log{""};
bool logging{false};
bool paused{false};
Labels labels{
{{0 * 8, 0 * 16}, "------------seeds-------------", Theme::getInstance()->fg_light->foreground},
{{0 * 8, 3 * 16}, "-----------password-----------", Theme::getInstance()->fg_light->foreground},
{{5 * 8, 7 * 16}, "digits:", Theme::getInstance()->fg_light->foreground},
};
RFAmpField field_rf_amp{
{13 * 8, 0 * 16}};
{13 * 8, 1 * 16}};
LNAGainField field_lna{
{15 * 8, 0 * 16}};
{15 * 8, 1 * 16}};
VGAGainField field_vga{
{18 * 8, 0 * 16}};
{18 * 8, 1 * 16}};
RSSI rssi{
{21 * 8, 0, 6 * 8, 4}};
{21 * 8, 1 * 16 + 0, 6 * 8, 4}};
Channel channel{
{21 * 8, 5, 6 * 8, 4}};
{21 * 8, 1 * 16 + 5, 6 * 8, 4}};
RxFrequencyField field_frequency{
{0 * 8, 0 * 16},
{0 * 8, 1 * 16},
nav_};
Checkbox check_log{
{0 * 8, 1 * 16},
3,
"save gened pw",
false};
Text text_debug{
{0 * 8, 12 + 2 * 16, screen_width, 16},
LanguageHelper::currentMessages[LANG_DEBUG]};
Button button_modem_setup{
{screen_width - 12 * 8, 1 * 16, 96, 24},
{screen_width - 12 * 8, 2 * 16, 96, 16},
"AFSK modem"};
Text text_seed{
{0, 4 * 16, 240, 16},
"test seed"
};
Labels labels{
{{5 * 8, 9 * 16}, "digits:", Theme::getInstance()->fg_light->foreground}};
{0, 2 * 16, screen_width / 2, 16},
"0000000000"};
Text text_generated_passwd{
{0, 5 * 16, screen_width, 28},
{0, 4 * 16, screen_width, 28},
"000000000000000000000000000000"};
Text text_char_type_hints{
{0, 6 * 16, screen_width, 28},
{0, 5 * 16, screen_width, 28},
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"};
Checkbox check_digits{
{3 * 8, 13 * 16},
3,
"123"};
Checkbox check_show_seeds{
{17 * 8, 8 * 16},
6,
"show seed"};
Checkbox check_auto_send{
{1 * 8, 8 * 16},
20,
"auto send"};
Checkbox check_punctuation{
{20 * 8, 13 * 16},
{17 * 8, 12 * 16},
6,
".,-!?"};
Checkbox check_allow_confusable_chars{
{1 * 8, 10 * 16},
20,
"0 O o 1 l"};
Checkbox check_digits{
{1 * 8, 12 * 16},
3,
"123"};
Checkbox check_latin_lower{
{3 * 8, 15 * 16},
{1 * 8, 14 * 16},
3,
"abc"};
Checkbox check_latin_upper{
{20 * 8, 15 * 16},
{17 * 8, 14 * 16},
3,
"ABC"};
Checkbox check_allow_confusable_chars{
{3 * 8, 11 * 16},
20,
"Include 0 O o 1 l"};
Checkbox check_log{
{17 * 8, 10 * 16},
3,
"savin",
false};
Button button_pause{
{0 * 8, 15 * 16 + 20, screen_width / 2, 24},
"pause"};
Button button_send{
{screen_width / 2, 15 * 16 + 20, screen_width / 2, 24},
"send pwd"};
Button button_refresh{
{0 * 8, 17 * 16 + 10, screen_width / 2, 24},
"refresh"};
"generate"};
Button button_show_qr{
{screen_width / 2, 17 * 16 + 10, screen_width / 2, 24},
"show QR"};
NumberField field_digits{
{24 * 8, 9 * 16},
{16 * 8, 7 * 16},
2,
{1, 30},
1,
@ -184,8 +199,6 @@ class RandomView : public View {
this->on_freqchg(message->freq);
}};
bool seed_protect_helper();
void on_freqchg(int64_t freq);
void set_random_freq();
};