mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-05-22 15:18:22 +00:00
Sync
This commit is contained in:
parent
107c212d88
commit
7e56183986
@ -19,6 +19,8 @@
|
|||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//BUG: No audio in about when shown second time
|
||||||
|
//BUG: Description doesn't show up first time going to system>module info (UI drawn on top)
|
||||||
//TODO: Morse coder
|
//TODO: Morse coder
|
||||||
//TODO: Playdead amnesia and login
|
//TODO: Playdead amnesia and login
|
||||||
//TODO: Touch screen calibration
|
//TODO: Touch screen calibration
|
||||||
|
@ -19,9 +19,11 @@
|
|||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ui_font_fixed_8x16.hpp"
|
||||||
#include "ui_setup.hpp"
|
#include "ui_setup.hpp"
|
||||||
#include "touch.hpp"
|
#include "touch.hpp"
|
||||||
|
|
||||||
|
#include "portapack.hpp"
|
||||||
#include "portapack_persistent_memory.hpp"
|
#include "portapack_persistent_memory.hpp"
|
||||||
#include "lpc43xx_cpp.hpp"
|
#include "lpc43xx_cpp.hpp"
|
||||||
|
|
||||||
@ -246,8 +248,179 @@ void SetUIView::focus() {
|
|||||||
button_ok.focus();
|
button_ok.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModInfoView::on_show() {
|
||||||
|
update_infos(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModInfoView::update_infos(uint8_t modn) {
|
||||||
|
char info_str[27];
|
||||||
|
char ch;
|
||||||
|
uint8_t c;
|
||||||
|
Point pos = { 0, 0 };
|
||||||
|
Rect rect = { { 16, 144 }, { 208, 144 } };
|
||||||
|
|
||||||
|
info_str[0] = 0;
|
||||||
|
strcat(info_str, module_list[modn].name);
|
||||||
|
text_namestr.set(info_str);
|
||||||
|
|
||||||
|
info_str[0] = 0;
|
||||||
|
strcat(info_str, to_string_dec_uint(module_list[modn].size).c_str());
|
||||||
|
strcat(info_str, " bytes");
|
||||||
|
text_sizestr.set(info_str);
|
||||||
|
|
||||||
|
info_str[0] = 0;
|
||||||
|
for (c = 0; c < 8; c++)
|
||||||
|
strcat(info_str, to_string_hex(module_list[modn].md5[c], 2).c_str());
|
||||||
|
text_md5_a.set(info_str);
|
||||||
|
|
||||||
|
info_str[0] = 0;
|
||||||
|
for (c = 8; c < 16; c++)
|
||||||
|
strcat(info_str, to_string_hex(module_list[modn].md5[c], 2).c_str());
|
||||||
|
text_md5_b.set(info_str);
|
||||||
|
|
||||||
|
// TODO: Use ui_console
|
||||||
|
display.fill_rectangle(rect, Color::black());
|
||||||
|
|
||||||
|
const Font& font = font::fixed_8x16;
|
||||||
|
const auto line_height = font.line_height();
|
||||||
|
c = 0;
|
||||||
|
while((ch = module_list[modn].description[c++])) {
|
||||||
|
const auto glyph = font.glyph(ch);
|
||||||
|
const auto advance = glyph.advance();
|
||||||
|
if((pos.x + advance.x) > rect.width()) {
|
||||||
|
pos.x = 0;
|
||||||
|
pos.y += line_height;
|
||||||
|
}
|
||||||
|
const Point pos_glyph {
|
||||||
|
static_cast<Coord>(rect.pos.x + pos.x),
|
||||||
|
static_cast<Coord>(rect.pos.y + pos.y)
|
||||||
|
};
|
||||||
|
display.draw_glyph(pos_glyph, glyph, Color::white(), Color::black());
|
||||||
|
pos.x += advance.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModInfoView::ModInfoView(NavigationView& nav) {
|
||||||
|
const char magic[4] = {'P', 'P', 'M', ' '};
|
||||||
|
UINT bw;
|
||||||
|
uint8_t i;
|
||||||
|
char read_buf[16];
|
||||||
|
char info_str[25];
|
||||||
|
FILINFO modinfo;
|
||||||
|
FIL modfile;
|
||||||
|
DIR rootdir;
|
||||||
|
FRESULT res;
|
||||||
|
|
||||||
|
using option_t = std::pair<std::string, int32_t>;
|
||||||
|
using options_t = std::vector<option_t>;
|
||||||
|
uint8_t c;
|
||||||
|
option_t opt;
|
||||||
|
options_t opts;
|
||||||
|
|
||||||
|
static constexpr Style style_orange {
|
||||||
|
.font = font::fixed_8x16,
|
||||||
|
.background = Color::black(),
|
||||||
|
.foreground = Color::orange(),
|
||||||
|
};
|
||||||
|
|
||||||
|
add_children({{
|
||||||
|
&text_modcount,
|
||||||
|
&text_name,
|
||||||
|
&text_namestr,
|
||||||
|
&text_size,
|
||||||
|
&text_sizestr,
|
||||||
|
&text_md5,
|
||||||
|
&text_md5_a,
|
||||||
|
&text_md5_b,
|
||||||
|
&button_ok
|
||||||
|
}});
|
||||||
|
|
||||||
|
text_name.set_style(&style_orange);
|
||||||
|
text_size.set_style(&style_orange);
|
||||||
|
text_md5.set_style(&style_orange);
|
||||||
|
|
||||||
|
// TODO: Find a way to merge this with m4_load_image() in m4_startup.cpp
|
||||||
|
|
||||||
|
// Scan SD card root directory for files starting with the magic bytes
|
||||||
|
c = 0;
|
||||||
|
if (f_opendir(&rootdir, "/") == FR_OK) {
|
||||||
|
for (;;) {
|
||||||
|
res = f_readdir(&rootdir, &modinfo);
|
||||||
|
if (res != FR_OK || modinfo.fname[0] == 0) break; // Reached last file, abort
|
||||||
|
// Only care about files with .bin extension
|
||||||
|
if ((!(modinfo.fattrib & AM_DIR)) && (modinfo.fname[9] == 'B') && (modinfo.fname[10] == 'I') && (modinfo.fname[11] == 'N')) {
|
||||||
|
f_open(&modfile, modinfo.fname, FA_OPEN_EXISTING | FA_READ);
|
||||||
|
// Magic bytes check
|
||||||
|
f_read(&modfile, &read_buf, 4, &bw);
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
if (read_buf[i] != magic[i]) break;
|
||||||
|
if (i == 4) {
|
||||||
|
memcpy(&module_list[c].filename, modinfo.fname, 8);
|
||||||
|
module_list[c].filename[8] = 0;
|
||||||
|
|
||||||
|
f_lseek(&modfile, 4);
|
||||||
|
f_read(&modfile, &module_list[c].version, 2, &bw);
|
||||||
|
f_lseek(&modfile, 6);
|
||||||
|
f_read(&modfile, &module_list[c].size, 4, &bw);
|
||||||
|
f_lseek(&modfile, 10);
|
||||||
|
f_read(&modfile, &module_list[c].name, 16, &bw);
|
||||||
|
f_lseek(&modfile, 26);
|
||||||
|
f_read(&modfile, &module_list[c].md5, 16, &bw);
|
||||||
|
f_lseek(&modfile, 42);
|
||||||
|
f_read(&modfile, &module_list[c].description, 214, &bw);
|
||||||
|
f_lseek(&modfile, 256);
|
||||||
|
|
||||||
|
// Sanitize
|
||||||
|
module_list[c].name[15] = 0;
|
||||||
|
module_list[c].description[213] = 0;
|
||||||
|
|
||||||
|
memcpy(info_str, module_list[c].filename, 16);
|
||||||
|
strcat(info_str, "(V");
|
||||||
|
strcat(info_str, to_string_dec_uint(module_list[c].version, 4, '0').c_str());
|
||||||
|
strcat(info_str, ")");
|
||||||
|
while(strlen(info_str) < 24)
|
||||||
|
strcat(info_str, " ");
|
||||||
|
|
||||||
|
opt = std::make_pair(info_str, c);
|
||||||
|
opts.insert(opts.end(), opt);
|
||||||
|
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
f_close(&modfile);
|
||||||
|
}
|
||||||
|
if (c == 8) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f_closedir(&rootdir);
|
||||||
|
|
||||||
|
memcpy(info_str, "Found ", 7);
|
||||||
|
strcat(info_str, to_string_dec_uint(c, 1).c_str());
|
||||||
|
strcat(info_str, " module(s)");
|
||||||
|
|
||||||
|
if (c) {
|
||||||
|
text_modcount.set(info_str);
|
||||||
|
option_modules.set_options(opts);
|
||||||
|
|
||||||
|
add_child(&option_modules);
|
||||||
|
|
||||||
|
option_modules.on_change = [this](size_t n, OptionsField::value_t v) {
|
||||||
|
(void)n;
|
||||||
|
update_infos(v);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
button_ok.on_select = [&nav,this](Button&){
|
||||||
|
nav.pop();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModInfoView::focus() {
|
||||||
|
option_modules.focus();
|
||||||
|
}
|
||||||
|
|
||||||
SetupMenuView::SetupMenuView(NavigationView& nav) {
|
SetupMenuView::SetupMenuView(NavigationView& nav) {
|
||||||
add_items<5>({ {
|
add_items<6>({ {
|
||||||
|
{ "SD card modules", ui::Color::white(), [&nav](){ nav.push(new ModInfoView { nav }); } },
|
||||||
{ "Date/Time", ui::Color::white(), [&nav](){ nav.push(new SetDateTimeView { nav }); } },
|
{ "Date/Time", ui::Color::white(), [&nav](){ nav.push(new SetDateTimeView { nav }); } },
|
||||||
{ "Frequency correction", ui::Color::white(), [&nav](){ nav.push(new SetFrequencyCorrectionView { nav }); } },
|
{ "Frequency correction", ui::Color::white(), [&nav](){ nav.push(new SetFrequencyCorrectionView { nav }); } },
|
||||||
{ "Touch screen", ui::Color::white(), [&nav](){ nav.push(new SetTouchCalibView { nav }); } },
|
{ "Touch screen", ui::Color::white(), [&nav](){ nav.push(new SetTouchCalibView { nav }); } },
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#ifndef __UI_SETUP_H__
|
#ifndef __UI_SETUP_H__
|
||||||
#define __UI_SETUP_H__
|
#define __UI_SETUP_H__
|
||||||
|
|
||||||
|
#include "ff.h"
|
||||||
|
|
||||||
#include "ui_widget.hpp"
|
#include "ui_widget.hpp"
|
||||||
#include "ui_menu.hpp"
|
#include "ui_menu.hpp"
|
||||||
#include "ui_navigation.hpp"
|
#include "ui_navigation.hpp"
|
||||||
@ -223,7 +225,7 @@ private:
|
|||||||
|
|
||||||
OptionsField options_bloff {
|
OptionsField options_bloff {
|
||||||
{ 10 * 8, 5 * 16 + 4 },
|
{ 10 * 8, 5 * 16 + 4 },
|
||||||
5,
|
10,
|
||||||
{
|
{
|
||||||
{ "5 seconds ", 0 },
|
{ "5 seconds ", 0 },
|
||||||
{ "15 seconds", 1 },
|
{ "15 seconds", 1 },
|
||||||
@ -264,6 +266,73 @@ private:
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ModInfoView : public View {
|
||||||
|
public:
|
||||||
|
ModInfoView(NavigationView& nav);
|
||||||
|
void focus() override;
|
||||||
|
void on_show() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void update_infos(uint8_t modn);
|
||||||
|
|
||||||
|
typedef struct moduleinfo_t{
|
||||||
|
char filename[9];
|
||||||
|
uint16_t version;
|
||||||
|
uint32_t size;
|
||||||
|
char md5[16];
|
||||||
|
char name[16];
|
||||||
|
char description[214];
|
||||||
|
} moduleinfo_t;
|
||||||
|
|
||||||
|
moduleinfo_t module_list[8]; // 8 max for now
|
||||||
|
|
||||||
|
Text text_modcount {
|
||||||
|
{ 2 * 8, 1 * 16, 18 * 8, 16 },
|
||||||
|
"Searching..."
|
||||||
|
};
|
||||||
|
|
||||||
|
OptionsField option_modules {
|
||||||
|
{ 2 * 8, 2 * 16 },
|
||||||
|
24,
|
||||||
|
{ { "-", 0 }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Text text_name {
|
||||||
|
{ 2 * 8, 4 * 16, 5 * 8, 16 },
|
||||||
|
"Name:"
|
||||||
|
};
|
||||||
|
Text text_namestr {
|
||||||
|
{ 8 * 8, 4 * 16, 16 * 8, 16 },
|
||||||
|
"..."
|
||||||
|
};
|
||||||
|
Text text_size {
|
||||||
|
{ 2 * 8, 5 * 16, 5 * 8, 16 },
|
||||||
|
"Size:"
|
||||||
|
};
|
||||||
|
Text text_sizestr {
|
||||||
|
{ 8 * 8, 5 * 16, 16 * 8, 16 },
|
||||||
|
"..."
|
||||||
|
};
|
||||||
|
Text text_md5 {
|
||||||
|
{ 2 * 8, 6 * 16, 4 * 8, 16 },
|
||||||
|
"MD5:"
|
||||||
|
};
|
||||||
|
Text text_md5_a {
|
||||||
|
{ 7 * 8, 6 * 16, 16 * 8, 16 },
|
||||||
|
"..."
|
||||||
|
};
|
||||||
|
Text text_md5_b {
|
||||||
|
{ 7 * 8, 7 * 16, 16 * 8, 16 },
|
||||||
|
"..."
|
||||||
|
};
|
||||||
|
|
||||||
|
Button button_ok {
|
||||||
|
{ 4 * 8, 272, 64, 24 },
|
||||||
|
"Ok"
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
class SetupMenuView : public MenuView {
|
class SetupMenuView : public MenuView {
|
||||||
public:
|
public:
|
||||||
SetupMenuView(NavigationView& nav);
|
SetupMenuView(NavigationView& nav);
|
||||||
|
@ -361,13 +361,22 @@ void Text::set(const std::string value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Text::paint(Painter& painter) {
|
void Text::paint(Painter& painter) {
|
||||||
|
if (style_ == nullptr) style_ = &style();
|
||||||
|
|
||||||
painter.draw_string(
|
painter.draw_string(
|
||||||
screen_pos(),
|
screen_pos(),
|
||||||
style(),
|
(*style_),
|
||||||
text
|
text
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Text::set_style(const Style* new_style) {
|
||||||
|
if( new_style != style_ ) {
|
||||||
|
style_ = new_style;
|
||||||
|
set_dirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Checkbox **************************************************************/
|
/* Checkbox **************************************************************/
|
||||||
|
|
||||||
void Checkbox::set_text(const std::string value) {
|
void Checkbox::set_text(const std::string value) {
|
||||||
@ -641,6 +650,12 @@ void OptionsField::set_by_value(value_t v) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionsField::set_options(options_t new_options) {
|
||||||
|
options = new_options;
|
||||||
|
set_by_value(0);
|
||||||
|
set_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
void OptionsField::paint(Painter& painter) {
|
void OptionsField::paint(Painter& painter) {
|
||||||
const auto paint_style = has_focus() ? style().invert() : style();
|
const auto paint_style = has_focus() ? style().invert() : style();
|
||||||
|
|
||||||
|
@ -220,11 +220,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void set(const std::string value);
|
void set(const std::string value);
|
||||||
|
void set_style(const Style* new_style);
|
||||||
|
|
||||||
void paint(Painter& painter) override;
|
void paint(Painter& painter) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string text;
|
std::string text;
|
||||||
|
const Style* style_ { nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
class Checkbox : public Widget {
|
class Checkbox : public Widget {
|
||||||
@ -316,6 +318,8 @@ public:
|
|||||||
flags.focusable = true;
|
flags.focusable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_options(options_t new_options);
|
||||||
|
|
||||||
size_t selected_index() const;
|
size_t selected_index() const;
|
||||||
void set_selected_index(const size_t new_index);
|
void set_selected_index(const size_t new_index);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user