All of this should work
This commit is contained in:
parent
15c7523f21
commit
cc000e770e
@ -71,8 +71,6 @@ void setup() {
|
|||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
Serial.println("Initialization complete");
|
Serial.println("Initialization complete");
|
||||||
|
|
||||||
_display_state->update_display.store(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
@ -21,6 +21,8 @@ enum CLICK_EVENTS : uint8_t {
|
|||||||
KEYBOARD = 4,
|
KEYBOARD = 4,
|
||||||
UP = 5,
|
UP = 5,
|
||||||
DOWN = 6,
|
DOWN = 6,
|
||||||
|
ESCAPE = 7,
|
||||||
|
SPACE = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CLICK_EVENT {
|
struct CLICK_EVENT {
|
||||||
@ -36,12 +38,6 @@ enum class ApplicationEventState : uint8_t {
|
|||||||
CLOSED = 2,
|
CLOSED = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct APPLICATION_EVENT {
|
|
||||||
char title[64];
|
|
||||||
short id;
|
|
||||||
ApplicationEventState state;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DISPLAY_STATE {
|
struct DISPLAY_STATE {
|
||||||
std::atomic<bool> update_display;
|
std::atomic<bool> update_display;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#include "GLOBALS.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "esp32-hal.h"
|
#include "esp32-hal.h"
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -5,6 +6,8 @@
|
|||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "tft_handler.h"
|
#include "tft_handler.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// Example Program 1: Simple counter
|
// Example Program 1: Simple counter
|
||||||
class CounterProgram : public Program {
|
class CounterProgram : public Program {
|
||||||
@ -19,13 +22,13 @@ public:
|
|||||||
void run() override {
|
void run() override {
|
||||||
Serial.println("Counter program started!");
|
Serial.println("Counter program started!");
|
||||||
|
|
||||||
WindowContentText text;
|
WindowStaticText text;
|
||||||
|
|
||||||
text.x = _window->x + 10;
|
text.x = _window->x + 10;
|
||||||
text.y = _window->y + 50;
|
text.y = _window->y + 50;
|
||||||
text.size = 2;
|
text.size = 2;
|
||||||
|
|
||||||
_window->window_content_text.push_back(text);
|
_window->window_static_text.push_back(text);
|
||||||
|
|
||||||
while (_running) {
|
while (_running) {
|
||||||
counter++;
|
counter++;
|
||||||
@ -36,8 +39,8 @@ public:
|
|||||||
if (!_window->minimized) {
|
if (!_window->minimized) {
|
||||||
_window->title = "Counter: " + std::to_string(counter);
|
_window->title = "Counter: " + std::to_string(counter);
|
||||||
|
|
||||||
for (short i = 0; i < _window->window_content_text.size(); i++) {
|
for (short i = 0; i < _window->window_static_text.size(); i++) {
|
||||||
_window->window_content_text[i].text = std::to_string(counter);
|
_window->window_static_text[i].text = std::to_string(counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
_display_state->update_display.store(true);
|
_display_state->update_display.store(true);
|
||||||
@ -67,15 +70,16 @@ public:
|
|||||||
if (event.x >= box.x && event.x <= (box.x + box.width) &&
|
if (event.x >= box.x && event.x <= (box.x + box.width) &&
|
||||||
event.y >= box.y && event.y <= (box.y + box.height)) {
|
event.y >= box.y && event.y <= (box.y + box.height)) {
|
||||||
|
|
||||||
if (event.event == CLICK_EVENTS::LEFT_CLICK) {
|
if (event.event != CLICK_EVENTS::LEFT_CLICK) continue;
|
||||||
// Deselect all boxes
|
|
||||||
for (auto& b : _window->text_boxes) b.selected = false;
|
for (auto& b : _window->text_boxes) b.selected = false;
|
||||||
|
|
||||||
box.selected = true;
|
box.selected = true;
|
||||||
selected_box_index = i;
|
selected_box_index = i;
|
||||||
|
|
||||||
_display_state->update_display.store(true);
|
_display_state->update_display.store(true);
|
||||||
}
|
|
||||||
} else {
|
} 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];
|
auto& box = _window->text_boxes[selected_box_index];
|
||||||
|
|
||||||
if (event.event == CLICK_EVENTS::KEYBOARD) {
|
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';
|
box.content += '\n';
|
||||||
} else {
|
} else {
|
||||||
box.content += event.character;
|
box.content += event.character;
|
||||||
@ -206,14 +210,14 @@ public:
|
|||||||
_window->width -= 50;
|
_window->width -= 50;
|
||||||
|
|
||||||
Serial.println("Settings started!");
|
Serial.println("Settings started!");
|
||||||
WindowContentText main_ram_usage_label;
|
WindowStaticText main_ram_usage_label;
|
||||||
WindowContentText main_ram_usage;
|
WindowStaticText main_ram_usage;
|
||||||
|
|
||||||
WindowContentText cpu_usage_label;
|
WindowStaticText cpu_usage_label;
|
||||||
WindowContentText cpu_usage;
|
WindowStaticText cpu_usage;
|
||||||
|
|
||||||
WindowContentText psram_usage_label;
|
WindowStaticText psram_usage_label;
|
||||||
WindowContentText psram_usage;
|
WindowStaticText psram_usage;
|
||||||
|
|
||||||
main_ram_usage_label.size = 2;
|
main_ram_usage_label.size = 2;
|
||||||
main_ram_usage_label.text = "RAM usage:";
|
main_ram_usage_label.text = "RAM usage:";
|
||||||
@ -242,12 +246,12 @@ public:
|
|||||||
cpu_usage.x = _window->x + 7;
|
cpu_usage.x = _window->x + 7;
|
||||||
cpu_usage.y = _window->y + 160;
|
cpu_usage.y = _window->y + 160;
|
||||||
|
|
||||||
_window->window_content_text.push_back(main_ram_usage_label);
|
_window->window_static_text.push_back(main_ram_usage_label);
|
||||||
_window->window_content_text.push_back(main_ram_usage);
|
_window->window_static_text.push_back(main_ram_usage);
|
||||||
_window->window_content_text.push_back(cpu_usage_label);
|
_window->window_static_text.push_back(cpu_usage_label);
|
||||||
_window->window_content_text.push_back(cpu_usage);
|
_window->window_static_text.push_back(cpu_usage);
|
||||||
_window->window_content_text.push_back(psram_usage_label);
|
_window->window_static_text.push_back(psram_usage_label);
|
||||||
_window->window_content_text.push_back(psram_usage);
|
_window->window_static_text.push_back(psram_usage);
|
||||||
|
|
||||||
ContentButton show_resources;
|
ContentButton show_resources;
|
||||||
show_resources.action = "show resources";
|
show_resources.action = "show resources";
|
||||||
@ -325,9 +329,9 @@ public:
|
|||||||
|
|
||||||
idle_count_last = idle_count_current;
|
idle_count_last = idle_count_current;
|
||||||
|
|
||||||
_window->window_content_text[1].text = std::to_string(ram_percent) + "%";
|
_window->window_static_text[1].text = std::to_string(ram_percent) + "%";
|
||||||
_window->window_content_text[3].text = std::to_string((int)cpu_percent) + "%";
|
_window->window_static_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[5].text = std::to_string((int)psram_percentage) + "%";
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1));
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
if (counter == 1000) {
|
if (counter == 1000) {
|
||||||
|
|||||||
@ -199,7 +199,16 @@ void InputManager::handle_keyboard_input(char key) {
|
|||||||
event.event = CLICK_EVENTS::KEYBOARD;
|
event.event = CLICK_EVENTS::KEYBOARD;
|
||||||
break;
|
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;
|
mi.x = (mi.x - 5 < 0) ? 0 : mi.x - 5;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -217,10 +226,10 @@ void InputManager::handle_keyboard_input(char key) {
|
|||||||
event.event = CLICK_EVENTS::DOWN;
|
event.event = CLICK_EVENTS::DOWN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xD: // Enter key
|
case 0x0D: // Enter key
|
||||||
event.x = mi.x;
|
event.x = mi.x;
|
||||||
event.y = mi.y;
|
event.y = mi.y;
|
||||||
event.event = CLICK_EVENTS::LEFT_CLICK;
|
event.event = CLICK_EVENTS::ENTER;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -82,15 +82,11 @@ struct ScrollableTextBox {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WindowContentText {
|
struct WindowStaticText {
|
||||||
std::string text;
|
std::string text;
|
||||||
short x;
|
short x;
|
||||||
short y;
|
short y;
|
||||||
short width;
|
|
||||||
short height;
|
|
||||||
char size;
|
char size;
|
||||||
bool selectable = false;
|
|
||||||
bool selected = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ContentButton {
|
struct ContentButton {
|
||||||
@ -105,7 +101,7 @@ struct ContentButton {
|
|||||||
struct Window {
|
struct Window {
|
||||||
std::string title;
|
std::string title;
|
||||||
std::vector<ScrollableTextBox> text_boxes;
|
std::vector<ScrollableTextBox> text_boxes;
|
||||||
std::vector<WindowContentText> window_content_text;
|
std::vector<WindowStaticText> window_static_text;
|
||||||
std::vector<WindowDecoration> window_decorations;
|
std::vector<WindowDecoration> window_decorations;
|
||||||
std::vector<ContentButton> content_buttons;
|
std::vector<ContentButton> content_buttons;
|
||||||
unsigned short x;
|
unsigned short x;
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
|
#include "program.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "GLOBALS.h"
|
#include "GLOBALS.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "system_manager.h"
|
#include "system_manager.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
#include "factory.h"
|
||||||
|
|
||||||
void Shell::init(TFT_Handler* th, DISPLAY_STATE* ds, SystemManager* system_manager) {
|
void Shell::init(TFT_Handler* th, DISPLAY_STATE* ds, SystemManager* system_manager) {
|
||||||
tft = th;
|
tft = th;
|
||||||
@ -125,14 +127,14 @@ void Shell::create_window(Window* window) {
|
|||||||
task_bar_items[i].focused = false;
|
task_bar_items[i].focused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskBarItem item;
|
TaskBarItem item = shell_factory::create_taskbar_item(window->title.c_str(), 0, 298, 95, 18, window->id, 100, true);
|
||||||
item.id = window->id;
|
/*item.id = window->id;
|
||||||
item.focused = true;
|
item.focused = true;
|
||||||
item.name = window->title;
|
item.name = window->title;
|
||||||
item.width = 95;
|
item.width = 95;
|
||||||
item.height = 18;
|
item.height = 18;
|
||||||
item.offset_x = 100;
|
item.offset_x = 100;
|
||||||
item.place_y = 298;
|
item.place_y = 298;*/
|
||||||
|
|
||||||
// Set place_x and place_y for ALL items
|
// Set place_x and place_y for ALL items
|
||||||
if (task_bar_items.size() == 0) {
|
if (task_bar_items.size() == 0) {
|
||||||
@ -239,6 +241,10 @@ void Shell::draw_window(const Window& window) {
|
|||||||
tft->draw_scrollable_textbox(box);
|
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) {
|
for (ContentButton button : window.content_buttons) {
|
||||||
tft->draw_button(button.x, button.y, button.width, button.height, COL_GREY, button.pressed, button.action);
|
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
|
// Create window
|
||||||
Window* win = new 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,
|
.x_offset = 6,
|
||||||
.y_offset = 5,
|
.y_offset = 5,
|
||||||
.width = 25,
|
.width = 25,
|
||||||
.height = 25,
|
.height = 25,
|
||||||
.action = WindowAction::CLOSE,
|
.action = WindowAction::CLOSE,
|
||||||
};
|
};*/
|
||||||
|
|
||||||
WindowDecoration minimize_btn = {
|
WindowDecoration minimize_btn = shell_factory::create_window_decoration(36, 5, 25, 25, WindowAction::MINIMIZE);
|
||||||
|
/*{
|
||||||
.x_offset = 36,
|
.x_offset = 36,
|
||||||
.y_offset = 5,
|
.y_offset = 5,
|
||||||
.width = 25,
|
.width = 25,
|
||||||
.height = 25,
|
.height = 25,
|
||||||
.action = WindowAction::MINIMIZE,
|
.action = WindowAction::MINIMIZE,
|
||||||
};
|
};*/
|
||||||
|
|
||||||
win->window_decorations.push_back(close_btn);
|
win->window_decorations.push_back(close_btn);
|
||||||
win->window_decorations.push_back(minimize_btn);
|
win->window_decorations.push_back(minimize_btn);
|
||||||
@ -381,7 +389,7 @@ short Shell::handle_desktop_click(CLICK_EVENT event) {
|
|||||||
win->focused = true;
|
win->focused = true;
|
||||||
win->minimized = false;
|
win->minimized = false;
|
||||||
win->title = item.name;
|
win->title = item.name;
|
||||||
win->window_content_text = {};
|
win->window_static_text = {};
|
||||||
|
|
||||||
// Spawn program using the program_class
|
// Spawn program using the program_class
|
||||||
bool result = _system_manager->spawn_program(win, item.program_class);
|
bool result = _system_manager->spawn_program(win, item.program_class);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user