[bootloader > menus] Improvement

This commit is contained in:
devdl11
2022-04-09 11:02:34 +02:00
parent ff307b8df8
commit eeff886cc1
11 changed files with 50 additions and 46 deletions

View File

@@ -19,6 +19,20 @@ bootloader_images = $(addprefix bootloader/, \
computer.png \
)
bootloader_src += $(addprefix bootloader/interface/src/,\
menu.cpp \
)
bootloader_src += $(addprefix bootloader/interface/menus/about/,\
about.cpp \
)
bootloader_src += $(addprefix bootloader/interface/menus/home/,\
home.cpp \
)
bootloader_src += $(ion_src) $(simple_kandinsky_src) $(liba_src) $(libaxx_src) $(bootloader_images)
$(eval $(call depends_on_image,bootloader/interface.cpp,$(bootloader_images)))
$(eval $(call depends_on_image,bootloader/interface/menus/home/home.cpp,$(bootloader_images)))

View File

@@ -8,6 +8,7 @@
#include <bootloader/usb_data.h>
#include <ion/src/device/shared/drivers/flash.h>
#include <bootloader/utility.h>
#include <bootloader/interface/menus/home/home.h>
#include <assert.h>
@@ -51,31 +52,9 @@ void Boot::bootSlot(Bootloader::Slot s) {
__attribute__((noreturn)) void Boot::boot() {
assert(mode() != BootMode::Unknown);
bool isSlotA = Slot::A().kernelHeader()->isValid();
bool isSlotB = Slot::B().kernelHeader()->isValid();
bool isSlotKhi = Slot::Khi().kernelHeader()->isValid();
Interface::drawMenu();
while (true) {
uint64_t scan = Ion::Keyboard::scan();
if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::One) && isSlotA) {
Boot::bootSlot(Slot::A());
} else if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Two) && isSlotKhi) {
Boot::bootSlot(Slot::Khi());
} else if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Three) && isSlotB) {
Boot::bootSlot(Slot::B());
} else if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Four)) {
installerMenu();
} else if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Five)) {
aboutMenu();
}
// else if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::Six)) {
// Ion::Device::Reset::core();
// }
else if (scan == Ion::Keyboard::State(Ion::Keyboard::Key::OnOff)) {
Ion::Power::standby(); // Force a core reset to exit
}
HomeMenu menu = HomeMenu();
menu.open(true);
}
// Achievement unlocked: How Did We Get Here?

View File

@@ -290,7 +290,7 @@ void Interface::drawInstallerSelection() {
ctx->drawString(Messages::installerText3, KDPoint(initPos, y), KDFont::SmallFont, KDColorBlack, KDColorWhite);
}
void Interface::drawBLUpdate() {
void Interface::drawBootloaderUpdate() {
Interface::drawHeader();
KDContext * ctx = KDIonContext::sharedContext();
int y = ImageStore::Computer->height() + (KDFont::LargeFont->glyphSize().height() + 10) + (KDFont::SmallFont->glyphSize().height() + 10);

View File

@@ -54,9 +54,9 @@ const char * Bootloader::HomeMenu::slotB_text() {
}
void Bootloader::HomeMenu::setup() {
m_colomns[0] = Colomn(slotA_text(), Ion::Keyboard::Key::One, k_large_font, 10, false, &slotA_submenu);
m_colomns[1] = Colomn(slotKhi_text(), Ion::Keyboard::Key::Two, k_large_font, 10, false, &slotKhi_submenu);
m_colomns[2] = Colomn(slotB_text(), Ion::Keyboard::Key::Three, k_large_font, 10, false, &slotB_submenu);
m_colomns[3] = Colomn("4- installer", Ion::Keyboard::Key::Four, k_large_font, 10, false, &installer_submenu);
m_colomns[4] = Colomn("5- about", Ion::Keyboard::Key::Five, k_large_font, 10, false, &about_submenu);
m_colomns[0] = Colomn(slotA_text(), Ion::Keyboard::Key::One, k_small_font, 30, false, &slotA_submenu);
m_colomns[1] = Colomn(slotKhi_text(), Ion::Keyboard::Key::Two, k_small_font, 30, false, &slotKhi_submenu);
m_colomns[2] = Colomn(slotB_text(), Ion::Keyboard::Key::Three, k_small_font, 30, false, &slotB_submenu);
m_colomns[3] = Colomn("4- installer", Ion::Keyboard::Key::Four, k_small_font, 30, false, &installer_submenu);
m_colomns[4] = Colomn("5- about", Ion::Keyboard::Key::Five, k_small_font, 30, false, &about_submenu);
}

View File

@@ -4,13 +4,15 @@
#include <kandinsky/context.h>
#include <string.h>
#include "computer.h"
#include <bootloader/computer.h>
const Ion::Keyboard::Key Bootloader::Menu::k_breaking_keys[];
void Bootloader::Menu::setup() {
// Here we add the colomns to the menu.
}
void Bootloader::Menu::open() {
void Bootloader::Menu::open(bool noreturn) {
showMenu();
uint64_t scan = 0;
@@ -19,16 +21,19 @@ void Bootloader::Menu::open() {
while(!exit) {
scan = Ion::Keyboard::scan();
exit = !handleKey(scan);
if (noreturn) {
exit = false;
}
}
}
int Bootloader::Menu::calculateCenterX(const char * text, int fontWidth) {
return (k_screen.width() - fontWidth * strlen(text)) / 2;
return (getScreen().width() - fontWidth * strlen(text)) / 2;
}
void Bootloader::Menu::showMenu() {
KDContext * ctx = KDIonContext::sharedContext();
ctx->fillRect(k_screen, m_background);
ctx->fillRect(getScreen(), m_background);
Interface::drawImage(ctx, ImageStore::Computer, 25);
int y = ImageStore::Computer->height() + 25 + 10;
int x = calculateCenterX(m_title, largeFontWidth());
@@ -45,7 +50,7 @@ void Bootloader::Menu::showMenu() {
}
if (m_bottom != nullptr) {
y = k_screen.height() - smallFontHeight() - 10;
y = getScreen().height() - smallFontHeight() - 10;
x = calculateCenterX(m_bottom, smallFontWidth());
ctx->drawString(m_bottom, KDPoint(x, y), k_small_font, m_foreground, m_background);
}
@@ -57,7 +62,7 @@ bool Bootloader::Menu::handleKey(uint64_t key) {
return false;
}
}
if (key == Ion::Keyboard::State(Ion::Keyboard::Key::Power)) {
if (key == Ion::Keyboard::State(Ion::Keyboard::Key::OnOff)) {
Ion::Power::standby();
return false;
}
@@ -65,7 +70,9 @@ bool Bootloader::Menu::handleKey(uint64_t key) {
if (colomn.isNull() || !colomn.isClickable()) {
continue;
} else {
colomn.didHandledEvent(key);
if (colomn.didHandledEvent(key)) {
redraw();
}
}
}
return true;

View File

@@ -46,20 +46,21 @@ namespace Bootloader {
bool (*m_callback)();
};
void open();
void open(bool noreturn = false);
void redraw() { showMenu(); };
static int calculateCenterX(const char * text, int fontWidth);
static constexpr const KDFont * k_small_font = KDFont::SmallFont;
static constexpr const KDFont * k_large_font = KDFont::LargeFont;
static const KDRect getScreen() { return KDRect(0, 0, 320, 240); };
private:
static const int k_max_colomns = 5;
static const int k_colomns_margin = 5;
static constexpr Ion::Keyboard::Key k_breaking_keys[] = {Ion::Keyboard::Key::Back, Ion::Keyboard::Key::Home};
static constexpr KDRect k_screen = KDRect(0, 0, 320, 240);
int smallFontHeight() const { return k_small_font->glyphSize().height(); };
int largeFontHeight() const { return k_large_font->glyphSize().height(); };

View File

@@ -19,7 +19,7 @@ char* reverse(char *buffer, int i, int j) {
}
// Iterative function to implement `itoa()` function in C
char* Utility::itoa(int value, char* buffer, int base) {
char* Bootloader::Utility::itoa(int value, char* buffer, int base) {
// invalid input
if (base < 2 || base > 32) {
return buffer;

View File

@@ -2,6 +2,7 @@
#define BOOTLOADER_KERNEL_HEADER_H
#include <stdint.h>
#include <bootloader/utility.h>
namespace Bootloader {

View File

@@ -13,13 +13,13 @@ static char data[255];
const char * Bootloader::USBData::buildStringDescriptor(StringHeader header, uint32_t startAddress, uint32_t size) {
strlcpy(data, header.getString(), sizeof(data));
Utility::itoa((int32_t)startAddress, &data[strlen(header.getString())], 16);
Bootloader::Utility::itoa((int32_t)startAddress, &data[strlen(header.getString())], 16);
data[strlen(header.getString()) + 8] = '/';
data[strlen(header.getString()) + 8 + 1] = '0';
data[strlen(header.getString()) + 8 + 2] = '1';
data[strlen(header.getString()) + 8 + 3] = '*';
data[strlen(header.getString()) + 8 + 4] = '0';
Utility::itoa((int32_t)size/1024, &data[strlen(header.getString()) + 8 + 5], 10);
Bootloader::Utility::itoa((int32_t)size/1024, &data[strlen(header.getString()) + 8 + 5], 10);
data[strlen(header.getString()) + 8 + 5 + 2] = 'K';
data[strlen(header.getString()) + 8 + 5 + 2 + 1] = 'g';
data[strlen(header.getString()) + 8 + 5 + 2 + 2] = '\0';

View File

@@ -1,7 +1,7 @@
#include <bootloader/utility.h>
#include <string.h>
int Utility::versionSum(const char * version, int length) {
int Bootloader::Utility::versionSum(const char * version, int length) {
int sum = 0;
for (int i = 0; i < length; i++) {
sum += version[i] * (strlen(version) * 100 - i * 10);

View File

@@ -1,9 +1,11 @@
#ifndef _BOOTLOADER_ITOA_H_
#define _BOOTLOADER_ITOA_H_
namespace Utility {
static char * itoa(int value, char * result, int base);
static int versionSum(const char * version, int length);
namespace Bootloader {
namespace Utility {
static char * itoa(int value, char * result, int base);
static int versionSum(const char * version, int length);
}
}
#endif