Skip to content

Commit f7087f4

Browse files
committed
v2.1.4 (#1) wallpaper config improvement
1 parent bbffff9 commit f7087f4

9 files changed

Lines changed: 237 additions & 33 deletions

File tree

include/coresys/commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "pingpong.h"
1919
#include "d20.h"
2020
#include "coin.h"
21+
#include "wallpaper.h"
2122
#include "tools/calc.h"
2223
#include "tools/fetch.h"
2324
#include "tools/ping.h"

include/coresys/config.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ void saveConfig();
5757
std::string getDeviceName();
5858
void setDeviceName();
5959

60-
int getSavedTheme();
60+
int getSavedTheme();
6161
void saveSavedTheme(int index);
6262

63+
int getSavedTheme();
64+
void saveSavedTheme(int index);
65+
66+
int getSavedWallpaper();
67+
void saveSavedWallpaper(int index);
68+
69+
6370
void setWifiConfig(const std::string& SSID, const std::string& PASS);
6471
std::string getWifiSSID();
6572
std::string getWifiPass();

include/coresys/wallpaper.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef WALLPAPER_H
2+
#define WALLPAPER_H
3+
4+
5+
#include "display.h"
6+
#include "theme.h"
7+
#include "config.h"
8+
#include <Adafruit_GFX.h>
9+
#include <string>
10+
11+
12+
struct Wallpaper {
13+
char name[32];
14+
void (*drawWallpaper)();
15+
};
16+
17+
extern Wallpaper wallpapers[];
18+
extern int currentWallpaperNum;
19+
extern int wallpaperCount;
20+
extern Wallpaper currentWallpaper;
21+
void listWallpaper();
22+
void setWallpaper(const std::string& wallpaperName);
23+
Wallpaper getCurrentWallpaper();
24+
25+
26+
27+
#endif

src/coresys/commands.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,17 @@ void runCommand(const std::string& cmd_in) {
361361
}
362362
setTheme(args.arg1);
363363
}
364+
else if (baseCmd == "wallpapers") {
365+
listWallpaper();
366+
}
367+
else if (baseCmd == "wallpaper") {
368+
if (args.arg1.length() == 0) {
369+
printLine("Usage: wallpaper <number>");
370+
listWallpaper();
371+
return;
372+
}
373+
setWallpaper(args.arg1);
374+
}
364375
// else if (baseCmd == "pug") {
365376
// displayPug();
366377
// }

src/coresys/config.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const char* OS_VERSION = "MiniOS-ESP v2.1.3";
1616

1717
static std::string deviceName = "Mini";
1818
static int savedTheme = 0;
19+
static int savedWallpaper = 0;
1920
#if defined(DEVICE_RP2350)
2021
static std::string storedSSID = "";
2122
static std::string storedPASS = "";
@@ -30,6 +31,8 @@ static void setConfigKey(const std::string& key, const std::string& value) {
3031
deviceName = value;
3132
} else if (key == "theme") {
3233
savedTheme = std::stoi(value);
34+
} else if (key == "wallpaper") {
35+
savedWallpaper = std::stoi(value);
3336
} else if (key == "SSID") {
3437
storedSSID = value;
3538
} else if (key == "PASS") {
@@ -40,6 +43,7 @@ static void setConfigKey(const std::string& key, const std::string& value) {
4043
static std::string getConfigKey(const std::string& key) {
4144
if (key == "deviceName") return deviceName;
4245
if (key == "theme") return std::to_string(savedTheme);
46+
if (key == "wallpaper") return std::to_string(savedWallpaper);
4347
if (key == "SSID") return storedSSID;
4448
if (key == "PASS") return storedPASS;
4549
return "";
@@ -118,10 +122,21 @@ void loadConfig() {
118122
}
119123
}
120124

125+
std::string wallpaperStr = getConfigKey("wallpaper");
126+
if (!wallpaperStr.empty()) {
127+
try {
128+
savedWallpaper = std::stoi(wallpaperStr);
129+
} catch (...) {
130+
savedWallpaper = 0;
131+
}
132+
}
133+
121134
printLine("[CONFIG] Loaded: name=" + deviceName +
122-
" theme=" + std::to_string(savedTheme));
135+
" theme=" + std::to_string(savedTheme) +
136+
" wallpaper=" + std::to_string(savedWallpaper));
123137
logKernelMessage("[CONFIG] Loaded: name=" + deviceName +
124-
" theme=" + std::to_string(savedTheme));
138+
" theme=" + std::to_string(savedTheme) +
139+
" wallpaper=" + std::to_string(savedWallpaper));
125140
#else
126141
printLine("[CONFIG] RP2350 config support not available. Using defaults.");
127142
logKernelMessage("[CONFIG] RP2350 config support not available. Using defaults.");
@@ -132,6 +147,7 @@ void saveConfig() {
132147
#if !defined(DEVICE_RP2350)
133148
setConfigKey("deviceName", deviceName);
134149
setConfigKey("theme", std::to_string(savedTheme));
150+
setConfigKey("wallpaper", std::to_string(savedWallpaper));
135151
printLine("[CONFIG] Saved.");
136152
logKernelMessage("[CONFIG] Saved.");
137153
#else
@@ -253,6 +269,15 @@ void saveSavedTheme(int index) {
253269
setConfigKey("theme", std::to_string(savedTheme));
254270
}
255271

272+
int getSavedWallpaper() {
273+
return savedWallpaper;
274+
}
275+
276+
void saveSavedWallpaper(int index) {
277+
savedWallpaper = index;
278+
setConfigKey("wallpaper", std::to_string(savedWallpaper));
279+
}
280+
256281
void setWifiConfig(const std::string& SSID, const std::string& PASS){
257282
setConfigKey("SSID", SSID);
258283
setConfigKey("PASS", PASS);

src/coresys/wallpaper.cpp

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#include "wallpaper.h"
2+
#include "config.h"
3+
#include "display.h"
4+
#include "kernel.h"
5+
6+
int currentWallpaperNum = 0;
7+
int wallpaperCount = 3;
8+
9+
void drawNoneWallpaper() {
10+
tft.fillScreen(getCurrentTheme().bg);
11+
}
12+
13+
14+
void drawBlocksWallpaper() {
15+
tft.fillRect(0, 0, 80, 80, 0xE987);
16+
17+
tft.fillRect(0, 80, 80, 80, 0x61B0);
18+
19+
tft.fillRect(0, 160, 80, 80, 0x2E0F);
20+
21+
tft.fillRect(80, 0, 80, 80, 0xE521);
22+
23+
tft.fillRect(80, 80, 80, 80, 0x1AF6);
24+
25+
tft.fillRect(80, 160, 80, 80, 0x63F1);
26+
27+
tft.fillRect(160, 0, 80, 80, 0xFAA4);
28+
29+
tft.fillRect(160, 80, 80, 80, 0xCEE7);
30+
31+
tft.fillRect(160, 160, 80, 80, 0x651D);
32+
33+
tft.fillRect(240, 0, 80, 80, 0x6225);
34+
35+
tft.fillRect(240, 80, 80, 80, 0x1B9B);
36+
37+
tft.fillRect(240, 160, 80, 80, 0xC0E5);
38+
}
39+
40+
41+
42+
43+
static void draw_polygon_1() {
44+
tft.drawLine(106, 40, 235, 70, 0xCD5C);
45+
tft.drawLine(235, 70, 103, 138, 0xCD5C);
46+
tft.drawLine(103, 138, 185, 33, 0xCD5C);
47+
tft.drawLine(185, 33, 199, 152, 0xCD5C);
48+
tft.drawLine(199, 152, 106, 40, 0xCD5C);
49+
}
50+
51+
static void draw_polygon_2() {
52+
tft.drawLine(30, 128, 103, 198, 0xCD5C);
53+
tft.drawLine(103, 198, 29, 222, 0xCD5C);
54+
tft.drawLine(29, 222, 86, 135, 0xCD5C);
55+
tft.drawLine(86, 135, 78, 234, 0xCD5C);
56+
tft.drawLine(78, 234, 30, 128, 0xCD5C);
57+
}
58+
59+
static void draw_polygon_3() {
60+
tft.drawLine(257, 198, 279, 129, 0xCD5C);
61+
tft.drawLine(279, 129, 299, 199, 0xCD5C);
62+
tft.drawLine(299, 199, 256, 143, 0xCD5C);
63+
tft.drawLine(256, 143, 307, 157, 0xCD5C);
64+
tft.drawLine(307, 157, 257, 198, 0xCD5C);
65+
}
66+
67+
static void draw_polygon_4() {
68+
tft.drawLine(162, 158, 175, 237, 0xCD5C);
69+
tft.drawLine(175, 237, 226, 200, 0xCD5C);
70+
tft.drawLine(226, 200, 139, 209, 0xCD5C);
71+
tft.drawLine(139, 209, 224, 232, 0xCD5C);
72+
tft.drawLine(224, 232, 162, 158, 0xCD5C);
73+
}
74+
75+
static void draw_polygon_5() {
76+
tft.drawLine(39, 6, 15, 99, 0xCD5C);
77+
tft.drawLine(15, 99, 94, 87, 0xCD5C);
78+
tft.drawLine(94, 87, 3, 35, 0xCD5C);
79+
tft.drawLine(3, 35, 71, 131, 0xCD5C);
80+
tft.drawLine(71, 131, 39, 6, 0xCD5C);
81+
}
82+
83+
static void draw_polygon_6() {
84+
tft.drawLine(285, 13, 263, 76, 0xCD5C);
85+
tft.drawLine(263, 76, 301, 76, 0xCD5C);
86+
tft.drawLine(301, 76, 250, 37, 0xCD5C);
87+
tft.drawLine(250, 37, 285, 92, 0xCD5C);
88+
tft.drawLine(285, 92, 285, 13, 0xCD5C);
89+
}
90+
void drawStarsWallpaper() {
91+
tft.fillScreen(0x0);
92+
93+
draw_polygon_1();
94+
95+
draw_polygon_2();
96+
97+
draw_polygon_3();
98+
99+
draw_polygon_4();
100+
101+
draw_polygon_5();
102+
103+
draw_polygon_6();
104+
}
105+
106+
Wallpaper wallpapers[] = {
107+
{"none", drawNoneWallpaper},
108+
{"blocks", drawBlocksWallpaper},
109+
{"stars", drawStarsWallpaper}
110+
};
111+
112+
Wallpaper currentWallpaper = wallpapers[0];
113+
114+
void listWallpaper() {
115+
for (int i = 0 ; i < wallpaperCount; ++i) {
116+
std::string marker = (i == currentWallpaperNum) ? " *" : "";
117+
printLine(std::to_string(i) + "." + wallpapers[i].name + marker);
118+
}
119+
}
120+
121+
void setWallpaper(const std::string& wallpaperName) {
122+
for (int i = 0; i < wallpaperCount; i++) {
123+
if (wallpaperName == wallpapers[i].name) {
124+
currentWallpaperNum = i;
125+
currentWallpaper = wallpapers[i];
126+
saveSavedWallpaper(currentWallpaperNum);
127+
clearScreen();
128+
printLine("[SYSTEM] Wallpaper set: " + std::string(wallpapers[currentWallpaperNum].name));
129+
logKernelMessage("[SYSTEM] Wallpaper set: " + std::string(wallpapers[currentWallpaperNum].name));
130+
return;
131+
}
132+
}
133+
134+
try {
135+
int wn = std::stoi(wallpaperName);
136+
if (wn >= 0 && wn < wallpaperCount) {
137+
currentWallpaperNum = wn;
138+
currentWallpaper = wallpapers[wn];
139+
saveSavedWallpaper(currentWallpaperNum);
140+
clearScreen();
141+
printLine("[SYSTEM] Wallpaper set: " + std::string(wallpapers[currentWallpaperNum].name));
142+
logKernelMessage("[SYSTEM] Wallpaper set: " + std::string(wallpapers[currentWallpaperNum].name));
143+
144+
return;
145+
}
146+
} catch (...) {
147+
}
148+
149+
printLine("Invalid wallpaper.");
150+
printLine("Use 'wallpapers' to list.");
151+
}
152+
153+
Wallpaper getCurrentWallpaper() {
154+
return wallpapers[currentWallpaperNum];
155+
}

src/drivers/display.cpp

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "display.h"
22
#include "theme.h"
33
#include "config.h"
4+
#include "wallpaper.h"
45
#include <Adafruit_GFX.h>
56
#include <string>
67
#if defined(DEVICE_RP2350) && !defined(__FREERTOS)
@@ -33,40 +34,16 @@ int bufferCount = 0;
3334
int scrollOffset = 0;
3435
std::string lineBuffer[SCROLL_BUFFER_SIZE];
3536

36-
void drawWallpaper() {
37-
tft.fillRect(0, 0, 80, 80, 0xE987);
38-
// rect 1 copy 1
39-
tft.fillRect(0, 80, 80, 80, 0x61B0);
40-
// rect 1 copy 2
41-
tft.fillRect(0, 160, 80, 80, 0x2E0F);
42-
// rect 1 copy 3
43-
tft.fillRect(80, 0, 80, 80, 0xE521);
44-
// rect 1 copy 4
45-
tft.fillRect(80, 80, 80, 80, 0x1AF6);
46-
// rect 1 copy 5
47-
tft.fillRect(80, 160, 80, 80, 0x63F1);
48-
// rect 1 copy 6
49-
tft.fillRect(160, 0, 80, 80, 0xFAA4);
50-
// rect 1 copy 7
51-
tft.fillRect(160, 80, 80, 80, 0xCEE7);
52-
// rect 1 copy 8
53-
tft.fillRect(160, 160, 80, 80, 0x651D);
54-
// rect 1 copy 9
55-
tft.fillRect(240, 0, 80, 80, 0x6225);
56-
// rect 1 copy 10
57-
tft.fillRect(240, 80, 80, 80, 0x1B9B);
58-
// rect 1 copy 11
59-
tft.fillRect(240, 160, 80, 80, 0xC0E5);
60-
}
6137

6238
void renderScreen(){
6339
if (bufferMutex != NULL) {
6440
xSemaphoreTake(bufferMutex, portMAX_DELAY);
6541
}
6642

6743
Theme current = getCurrentTheme();
44+
6845
// tft.fillScreen(current.bg);
69-
drawWallpaper();
46+
currentWallpaper.drawWallpaper();
7047
tft.setTextColor(current.fg, current.bg);
7148

7249
int total = bufferCount;
@@ -222,7 +199,7 @@ void initDisplay() {
222199
void applyTheme() {
223200
Theme current = getCurrentTheme();
224201
// tft.fillScreen(current.bg);
225-
drawWallpaper();
202+
currentWallpaper.drawWallpaper();
226203
tft.setTextColor(current.fg);
227204
tft.setCursor(5, 0);
228205
currentCursorY = 0;
@@ -235,7 +212,7 @@ void clearScreen() {
235212

236213
Theme current = getCurrentTheme();
237214
// tft.fillScreen(current.bg);
238-
drawWallpaper();
215+
currentWallpaper.drawWallpaper();
239216
tft.setCursor(5, 0);
240217
currentCursorY = 0;
241218
scrollOffset = 0;
@@ -251,7 +228,7 @@ void clearScreen() {
251228
void newPage() {
252229
Theme current = getCurrentTheme();
253230
// tft.fillScreen(current.bg);
254-
drawWallpaper();
231+
currentWallpaper.drawWallpaper();
255232
tft.setCursor(5, 0);
256233
currentCursorY = 0;
257234
tft.setTextColor(current.fg, current.bg);

src/kernel/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int createProcess(TaskFunction_t function, const char* name, uint32_t stackSize,
8989
Serial.printf("[KERNEL] Created process '%s' (PID: %d, Priority: %d)\n",
9090
name, pid, priority);
9191
logKernelMessage(
92-
std::string("[KERNEL] Created process '") + name +
92+
std::string("[KERNEL] Created proc. '") + name +
9393
"'(PID:" + std::to_string(pid) +
9494
",Priority:" + std::to_string(priority) + ")"
9595
);

src/kernel/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void initProcess(void *parameter) {
4444
logKernelMessage("[SYSTEM] Filesystem initialized");
4545
loadConfig();
4646
setTheme(std::to_string(getSavedTheme()));
47+
setWallpaper(std::to_string(getSavedWallpaper()));
4748

4849
printLine("[SYSTEM] MiniOS Ready");
4950
logKernelMessage("[SYSTEM] MiniOS Ready");

0 commit comments

Comments
 (0)