All of this should work

This commit is contained in:
Rasmus Rasmussen 2026-04-24 19:01:52 +02:00
parent 15c7523f21
commit cc000e770e
6 changed files with 69 additions and 58 deletions

View File

@ -71,8 +71,6 @@ void setup() {
delay(100);
Serial.println("Initialization complete");
_display_state->update_display.store(true);
}
void loop() {

View File

@ -21,6 +21,8 @@ enum CLICK_EVENTS : uint8_t {
KEYBOARD = 4,
UP = 5,
DOWN = 6,
ESCAPE = 7,
SPACE = 8,
};
struct CLICK_EVENT {
@ -36,12 +38,6 @@ enum class ApplicationEventState : uint8_t {
CLOSED = 2,
};
struct APPLICATION_EVENT {
char title[64];
short id;
ApplicationEventState state;
};
struct DISPLAY_STATE {
std::atomic<bool> update_display;
};

View File

@ -1,3 +1,4 @@
#include "GLOBALS.h"
#include <cstring>
#include "esp32-hal.h"
#pragma once
@ -5,6 +6,8 @@
#include "shell.h"
#include "tft_handler.h"
#include <Arduino.h>
#include <math.h>
#include <algorithm>
// Example Program 1: Simple counter
class CounterProgram : public Program {
@ -19,13 +22,13 @@ public:
void run() override {
Serial.println("Counter program started!");
WindowContentText text;
WindowStaticText text;
text.x = _window->x + 10;
text.y = _window->y + 50;
text.size = 2;
_window->window_content_text.push_back(text);
_window->window_static_text.push_back(text);
while (_running) {
counter++;
@ -36,8 +39,8 @@ public:
if (!_window->minimized) {
_window->title = "Counter: " + std::to_string(counter);
for (short i = 0; i < _window->window_content_text.size(); i++) {
_window->window_content_text[i].text = std::to_string(counter);
for (short i = 0; i < _window->window_static_text.size(); i++) {
_window->window_static_text[i].text = std::to_string(counter);
}
_display_state->update_display.store(true);
@ -67,15 +70,16 @@ public:
if (event.x >= box.x && event.x <= (box.x + box.width) &&
event.y >= box.y && event.y <= (box.y + box.height)) {
if (event.event == CLICK_EVENTS::LEFT_CLICK) {
// Deselect all boxes
for (auto& b : _window->text_boxes) b.selected = false;
box.selected = true;
selected_box_index = i;
_display_state->update_display.store(true);
}
if (event.event != CLICK_EVENTS::LEFT_CLICK) continue;
for (auto& b : _window->text_boxes) b.selected = false;
box.selected = true;
selected_box_index = i;
_display_state->update_display.store(true);
} else {
if (event.event == CLICK_EVENTS::LEFT_CLICK) for (auto& b : _window->text_boxes) b.selected = false;
if (event.event == CLICK_EVENTS::ESCAPE) for (auto& b : _window->text_boxes) b.selected = false;
}
}
@ -83,7 +87,7 @@ public:
auto& box = _window->text_boxes[selected_box_index];
if (event.event == CLICK_EVENTS::KEYBOARD) {
if (event.character == '\n' || event.character == '\r') {
if (event.character == '\n' || event.character == '\r' || event.event == CLICK_EVENTS::ENTER) {
box.content += '\n';
} else {
box.content += event.character;
@ -206,14 +210,14 @@ public:
_window->width -= 50;
Serial.println("Settings started!");
WindowContentText main_ram_usage_label;
WindowContentText main_ram_usage;
WindowStaticText main_ram_usage_label;
WindowStaticText main_ram_usage;
WindowContentText cpu_usage_label;
WindowContentText cpu_usage;
WindowStaticText cpu_usage_label;
WindowStaticText cpu_usage;
WindowContentText psram_usage_label;
WindowContentText psram_usage;
WindowStaticText psram_usage_label;
WindowStaticText psram_usage;
main_ram_usage_label.size = 2;
main_ram_usage_label.text = "RAM usage:";
@ -242,12 +246,12 @@ public:
cpu_usage.x = _window->x + 7;
cpu_usage.y = _window->y + 160;
_window->window_content_text.push_back(main_ram_usage_label);
_window->window_content_text.push_back(main_ram_usage);
_window->window_content_text.push_back(cpu_usage_label);
_window->window_content_text.push_back(cpu_usage);
_window->window_content_text.push_back(psram_usage_label);
_window->window_content_text.push_back(psram_usage);
_window->window_static_text.push_back(main_ram_usage_label);
_window->window_static_text.push_back(main_ram_usage);
_window->window_static_text.push_back(cpu_usage_label);
_window->window_static_text.push_back(cpu_usage);
_window->window_static_text.push_back(psram_usage_label);
_window->window_static_text.push_back(psram_usage);
ContentButton show_resources;
show_resources.action = "show resources";
@ -325,9 +329,9 @@ public:
idle_count_last = idle_count_current;
_window->window_content_text[1].text = std::to_string(ram_percent) + "%";
_window->window_content_text[3].text = std::to_string((int)cpu_percent) + "%";
_window->window_content_text[5].text = std::to_string((int)psram_percentage) + "%";
_window->window_static_text[1].text = std::to_string(ram_percent) + "%";
_window->window_static_text[3].text = std::to_string((int)cpu_percent) + "%";
_window->window_static_text[5].text = std::to_string((int)psram_percentage) + "%";
vTaskDelay(pdMS_TO_TICKS(1));
if (counter == 1000) {

View File

@ -194,33 +194,42 @@ void InputManager::handle_keyboard_input(char key) {
event.event = CLICK_EVENTS::KEYBOARD;
break;
case 0x20: // Space
case 0x20: // Space
event.character = key;
event.event = CLICK_EVENTS::KEYBOARD;
break;
case 0xB4: // Left arrow key (CardKB sends special codes)
case 0x1b: // Escape
event.event = CLICK_EVENTS::ESCAPE;
break;
case 0x09: // Tab
event.event = CLICK_EVENTS::LEFT_CLICK;
Serial.println("lol");
break;
case 0xB4: // Left arrow key
mi.x = (mi.x - 5 < 0) ? 0 : mi.x - 5;
break;
case 0xB7: // Right arrow key
case 0xB7: // Right arrow key
mi.x = (mi.x + 5 > 476) ? 476 : mi.x + 5;
break;
case 0xB5: // Up arrow key
case 0xB5: // Up arrow key
mi.y = (mi.y - 5 < 0) ? 0 : mi.y - 5;
event.event = CLICK_EVENTS::UP;
break;
case 0xB6: // Down arrow key
case 0xB6: // Down arrow key
mi.y = (mi.y + 5 > 316) ? 316 : mi.y + 5;
event.event = CLICK_EVENTS::DOWN;
break;
case 0xD: // Enter key
case 0x0D: // Enter key
event.x = mi.x;
event.y = mi.y;
event.event = CLICK_EVENTS::LEFT_CLICK;
event.event = CLICK_EVENTS::ENTER;
break;
default:

View File

@ -82,15 +82,11 @@ struct ScrollableTextBox {
}
};
struct WindowContentText {
struct WindowStaticText {
std::string text;
short x;
short y;
short width;
short height;
char size;
bool selectable = false;
bool selected = false;
};
struct ContentButton {
@ -105,7 +101,7 @@ struct ContentButton {
struct Window {
std::string title;
std::vector<ScrollableTextBox> text_boxes;
std::vector<WindowContentText> window_content_text;
std::vector<WindowStaticText> window_static_text;
std::vector<WindowDecoration> window_decorations;
std::vector<ContentButton> content_buttons;
unsigned short x;

View File

@ -1,9 +1,11 @@
#include "program.h"
#include <string>
#include "shell.h"
#include "GLOBALS.h"
#include <algorithm>
#include "system_manager.h"
#include "helpers.h"
#include "factory.h"
void Shell::init(TFT_Handler* th, DISPLAY_STATE* ds, SystemManager* system_manager) {
tft = th;
@ -125,14 +127,14 @@ void Shell::create_window(Window* window) {
task_bar_items[i].focused = false;
}
TaskBarItem item;
item.id = window->id;
TaskBarItem item = shell_factory::create_taskbar_item(window->title.c_str(), 0, 298, 95, 18, window->id, 100, true);
/*item.id = window->id;
item.focused = true;
item.name = window->title;
item.width = 95;
item.height = 18;
item.offset_x = 100;
item.place_y = 298;
item.place_y = 298;*/
// Set place_x and place_y for ALL items
if (task_bar_items.size() == 0) {
@ -239,6 +241,10 @@ void Shell::draw_window(const Window& window) {
tft->draw_scrollable_textbox(box);
}
for (const auto& text : window.window_static_text) {
tft->draw_text(text.x, text.y, text.text, COL_BLACK, text.size);
}
for (ContentButton button : window.content_buttons) {
tft->draw_button(button.x, button.y, button.width, button.height, COL_GREY, button.pressed, button.action);
}
@ -353,21 +359,23 @@ short Shell::handle_desktop_click(CLICK_EVENT event) {
// Create window
Window* win = new Window();
WindowDecoration close_btn = {
WindowDecoration close_btn = shell_factory::create_window_decoration(6, 5, 25, 25, WindowAction::CLOSE);
/*{
.x_offset = 6,
.y_offset = 5,
.width = 25,
.height = 25,
.action = WindowAction::CLOSE,
};
};*/
WindowDecoration minimize_btn = {
WindowDecoration minimize_btn = shell_factory::create_window_decoration(36, 5, 25, 25, WindowAction::MINIMIZE);
/*{
.x_offset = 36,
.y_offset = 5,
.width = 25,
.height = 25,
.action = WindowAction::MINIMIZE,
};
};*/
win->window_decorations.push_back(close_btn);
win->window_decorations.push_back(minimize_btn);
@ -381,7 +389,7 @@ short Shell::handle_desktop_click(CLICK_EVENT event) {
win->focused = true;
win->minimized = false;
win->title = item.name;
win->window_content_text = {};
win->window_static_text = {};
// Spawn program using the program_class
bool result = _system_manager->spawn_program(win, item.program_class);