Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precomputed RGB565 Color palette #69

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions firmware/doom/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void drawTask(void* arg) {
lilka::display.endWrite();
lilka::display.setTextBound(0, 0, LILKA_DISPLAY_WIDTH, LILKA_DISPLAY_HEIGHT);
lilka::display.setCursor(32, 16);
lilka::display.setTextColor(lilka::display.color565(255, 255, 255), lilka::display.color565(0, 0, 0));
lilka::display.setTextColor(lilka::colors::White, lilka::colors::Black);
lilka::display.setFont(FONT_6x12);
lilka::display.print(" FPS: ");
lilka::display.print(1000 / delta);
Expand Down Expand Up @@ -285,7 +285,7 @@ extern "C" void DG_printf(const char* format, ...) {
lilka::display.setFont(u8g2_font_6x12_t_cyrillic);
if (hadNewLine) {
hadNewLine = false;
lilka::display.fillRect(0, bottom, 240, 280 - bottom, lilka::display.color565(0, 0, 0));
lilka::display.fillRect(0, bottom, 240, 280 - bottom, lilka::colors::Black);
lilka::display.setCursor(0, bottom + 10);
}
lilka::display.setTextBound(0, bottom, 240, 280 - bottom);
Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/demos/ball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void BallApp::run() {
xVelo = 500;
}

canvas->fillScreen(canvas->color565(0, 0, 0));
canvas->fillCircle(x, y, radius, canvas->color565(255, 200, 0));
canvas->fillScreen(lilka::colors::Black);
canvas->fillCircle(x, y, radius, lilka::colors::Chrome_yellow);
// Calculate FPS
canvas->setCursor(16, 32);
canvas->println("FPS: " + String(1000 / (millis() - prevRenderTime)));
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void DiskApp::run() {
return;
}

canvas->fillScreen(canvas->color565(0, 0, 0));
canvas->fillScreen(lilka::colors::Black);
canvas->drawCircle(x, y, radius, 0xFFFF);
canvas->setCursor(16, 32);
canvas->println("FPS: " + String(1000 / (millis() - prevRenderTime)));
Expand Down
24 changes: 12 additions & 12 deletions firmware/keira/src/apps/demos/letris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const bool shapesData[7][4][4] = {
};

const uint16_t colors[7] = {
lilka::display.color565(255, 0, 0),
lilka::display.color565(0, 255, 0),
lilka::display.color565(0, 0, 255),
lilka::display.color565(255, 255, 0),
lilka::display.color565(255, 0, 255),
lilka::display.color565(0, 255, 255),
lilka::display.color565(200, 200, 200),
lilka::colors::Red,
lilka::colors::Green,
lilka::colors::Blue,
lilka::colors::Yellow,
lilka::colors::Fuchsia,
lilka::colors::Aqua,
lilka::colors::Light_gray,
};
const uint8_t colorCount = sizeof(colors) / sizeof(colors[0]);

Expand Down Expand Up @@ -71,15 +71,15 @@ class Shape {
(this->y + yy) * BLOCK_SIZE + 2,
BLOCK_SIZE - 4,
BLOCK_SIZE - 4,
lilka::display.color565(0, 0, 0)
lilka::colors::Black
);
} else if (drawEmptyBlocks) {
canvas->fillRect(
xOffset + (this->x + xx) * BLOCK_SIZE,
(this->y + yy) * BLOCK_SIZE,
BLOCK_SIZE,
BLOCK_SIZE,
lilka::display.color565(0, 0, 0)
lilka::colors::Black
);
}
}
Expand Down Expand Up @@ -196,7 +196,7 @@ void LetrisApp::run() {
int16_t xMargin = (canvas->width() - letris_splash_width) / 2;
while (!lilka::controller.getState().a.justPressed) {
float time = millis() / 1000.0;
canvas->fillScreen(canvas->color565(0, 0, 0));
canvas->fillScreen(lilka::colors::Black);
float yShifts[letris_splash_width];
for (uint16_t x = 0; x < letris_splash_width; x++) {
yShifts[x] = cos(time + ((float)x) / 32.0) * 8;
Expand All @@ -215,10 +215,10 @@ void LetrisApp::run() {
}

// Очищаємо екран
canvas->fillScreen(canvas->color565(32, 32, 32));
canvas->fillScreen(lilka::colors::Graygrey);
queueDraw();
// Ми робимо це двічі, щоб очистити обидва буфери (основний та задній)
canvas->fillScreen(canvas->color565(32, 32, 32));
canvas->fillScreen(lilka::colors::Graygrey);
queueDraw();

// Головний цикл гри
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/scan_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void ScanI2CApp::run() {
buffer.fillScreen(0);
buffer.setFont(FONT_9x15);

buffer.fillScreen(canvas->color565(0, 0, 0));
buffer.fillScreen(lilka::colors::Black);
buffer.setTextBound(4, 0, canvas->width() - 8, canvas->height());
buffer.setCursor(4, 20);
buffer.println("I2C init: SDA=" + String(LILKA_P3) + ", SCL=" + String(LILKA_P4));
Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/demos/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TransformApp::TransformApp() : App("Transform") {
}

void TransformApp::run() {
lilka::Image* face = lilka::resources.loadImage("/sd/face.bmp", canvas->color565(0, 0, 0), 32, 32);
lilka::Image* face = lilka::resources.loadImage("/sd/face.bmp", lilka::colors::Black, 32, 32);

if (!face) {
lilka::Alert alert("Помилка", "Не вдалось завантажити face.bmp з SD-карти.");
Expand All @@ -26,7 +26,7 @@ void TransformApp::run() {
int angle = 0;

while (1) {
canvas->fillScreen(canvas->color565(0, 64, 0));
canvas->fillScreen(lilka::colors::Myrtle_green);
// canvas->drawImage(face, x, y);
lilka::Transform transform = lilka::Transform().rotate(angle).scale(sin(angle / 24.0), cos(angle / 50.0));
// lilka::Transform transform = lilka::Transform().rotate(30).scale(1.5, 1);
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/user_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void UserSPIApp::run() {
buffer.fillScreen(0);
buffer.setFont(FONT_9x15);

buffer.fillScreen(buffer.color565(0, 0, 0));
buffer.fillScreen(lilka::colors::Black);
buffer.setTextBound(4, 0, canvas->width() - 8, canvas->height());
buffer.setCursor(4, 20);
buffer.println("SPI2 begin");
Expand Down
22 changes: 11 additions & 11 deletions firmware/keira/src/apps/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ LauncherApp::LauncherApp() : App("Menu") {

void LauncherApp::run() {
lilka::Menu menu("Головне меню");
menu.addItem("Додатки", &demos, lilka::display.color565(255, 200, 200));
menu.addItem("Браузер SD-карти", &sdcard, lilka::display.color565(255, 255, 200));
menu.addItem("Браузер SPIFFS", &memory, lilka::display.color565(200, 255, 200));
menu.addItem("Розробка", &dev, lilka::display.color565(255, 224, 128));
menu.addItem("Налаштування", &settings, lilka::display.color565(255, 200, 224));
menu.addItem("Додатки", &demos, lilka::colors::Pink);
menu.addItem("Браузер SD-карти", &sdcard, lilka::colors::Arylide_yellow);
menu.addItem("Браузер SPIFFS", &memory, lilka::colors::Dark_sea_green);
menu.addItem("Розробка", &dev, lilka::colors::Jasmine);
menu.addItem("Налаштування", &settings, lilka::colors::Orchid);

while (1) {
while (!menu.isFinished()) {
Expand Down Expand Up @@ -122,15 +122,15 @@ const uint16_t get_file_color(const String& filename) {
String lowerCasedFileName = filename;
lowerCasedFileName.toLowerCase();
if (lowerCasedFileName.endsWith(".rom") || lowerCasedFileName.endsWith(".nes")) {
return lilka::display.color565(255, 128, 128);
return lilka::colors::Candy_pink;
} else if (lowerCasedFileName.endsWith(".bin")) {
return lilka::display.color565(128, 255, 128);
return lilka::colors::Mint_green;
} else if (lowerCasedFileName.endsWith(".lua")) {
return lilka::display.color565(128, 128, 255);
return lilka::colors::Maya_blue;
} else if (lowerCasedFileName.endsWith(".js")) {
return lilka::display.color565(255, 200, 128);
return lilka::colors::Butterscotch;
} else {
return lilka::display.color565(200, 200, 200);
return lilka::colors::Light_gray;
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ void LauncherApp::sdBrowserMenu(String path) {
String filename = entries[i].name;
const menu_icon_t* icon =
entries[i].type == lilka::EntryType::ENT_DIRECTORY ? &folder : get_file_icon(filename);
uint16_t color = entries[i].type == lilka::EntryType::ENT_DIRECTORY ? lilka::display.color565(255, 255, 200)
uint16_t color = entries[i].type == lilka::EntryType::ENT_DIRECTORY ? lilka::colors::Arylide_yellow
: get_file_color(filename);
menu.addItem(filename, icon, color);
}
Expand Down
6 changes: 3 additions & 3 deletions firmware/keira/src/apps/lua/luarunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void LuaLiveRunnerApp::run() {
}
canvas->setFont(FONT_10x20);
canvas->setCursor(8, 48);
canvas->fillScreen(canvas->color565(0, 0, 0));
canvas->fillScreen(lilka::colors::Black);
canvas->setTextBound(8, 0, canvas->width() - 16, canvas->height());
canvas->print("Очікування коду\nз UART...\n\n");
canvas->print("Натисніть [A]\n");
Expand Down Expand Up @@ -379,7 +379,7 @@ void LuaLiveRunnerApp::run() {
// canvas->print(String("Зчитано: ") + code.length() + " Б");
// }
if (line.length() == 0) {
canvas->fillScreen(canvas->color565(0, 128, 0));
canvas->fillScreen(lilka::colors::Green);
canvas->print("Запуск...");
queueDraw();
break;
Expand Down Expand Up @@ -454,7 +454,7 @@ void LuaReplApp::run() {

canvas->setFont(FONT_10x20);
canvas->setCursor(8, 48);
canvas->fillScreen(canvas->color565(0, 0, 0));
canvas->fillScreen(lilka::colors::Black);
canvas->setTextBound(8, 0, canvas->width() - 16, canvas->height());
canvas->print("Lua REPL\n\n");
canvas->print("Під'єднайтесь до\nЛілки через серійний\nтермінал та починайте\nвводити команди!");
Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/nes/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ void Driver::customBlit(bitmap_t* bmp, int numDirties, rect_t* dirtyRects) {
// Serial.println("Draw 1 took " + String(micros() - last_render) + "us");

if (last_frame_duration > 0) {
canvas->fillRect(80, canvas->height() - 20, 80, 20, canvas->color565(0, 0, 0));
canvas->fillRect(80, canvas->height() - 20, 80, 20, lilka::colors::Black);
canvas->setCursor(80, canvas->height() - 4);
canvas->setTextSize(1);
canvas->setTextColor(canvas->color565(128, 128, 128));
canvas->setTextColor(lilka::colors::Graygrey);
canvas->print("FPS: ");
canvas->print(1000000 / last_frame_duration);
}
Expand Down
20 changes: 8 additions & 12 deletions firmware/keira/src/apps/statusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const uint16_t* icons[] = {wifi_offline, wifi_0, wifi_1, wifi_2, wifi_3};
void StatusBarApp::run() {
lilka::Canvas iconCanvas(240, 24);
while (1) {
canvas->fillScreen(lilka::display.color565(0, 0, 0));
canvas->fillScreen(lilka::colors::Black);

ClockService* clockService = ServiceManager::getInstance()->getService<ClockService>("clock");
canvas->setTextColor(lilka::display.color565(255, 255, 255), lilka::display.color565(0, 0, 0));
canvas->setTextColor(lilka::colors::White, lilka::colors::Black);
canvas->setFont(FONT_9x15);
canvas->setCursor(24, 17);
struct tm timeinfo = clockService->getTime();
Expand All @@ -47,7 +47,7 @@ int16_t StatusBarApp::drawIcons(lilka::Canvas* iconCanvas) {

int16_t xOffset = 0;

iconCanvas->fillScreen(lilka::display.color565(0, 0, 0));
iconCanvas->fillScreen(lilka::colors::Black);
iconCanvas->setFont(FONT_9x15);

// Draw RAM usage
Expand All @@ -57,8 +57,8 @@ int16_t StatusBarApp::drawIcons(lilka::Canvas* iconCanvas) {
int16_t barWidth = 24 - padding * 2;
int16_t barHeight = 10;
int16_t barWidthUsed = barWidth * (totalRAM - freeRAM) / totalRAM;
iconCanvas->fillRect(xOffset + padding, padding, barWidthUsed, barHeight, lilka::display.color565(255, 128, 128));
iconCanvas->draw16bitRGBBitmapWithTranColor(xOffset, 0, ram, lilka::display.color565(0, 0, 0), 24, 24);
iconCanvas->fillRect(xOffset + padding, padding, barWidthUsed, barHeight, lilka::colors::Red);
iconCanvas->draw16bitRGBBitmapWithTranColor(xOffset, 0, ram, lilka::colors::Black, 24, 24);
xOffset += 4 + 24;

// Draw WiFi signal strength
Expand All @@ -78,21 +78,17 @@ int16_t StatusBarApp::drawIcons(lilka::Canvas* iconCanvas) {
// Draw battery
int level = lilka::battery.readLevel();
if (level == -1) {
iconCanvas->draw16bitRGBBitmapWithTranColor(
xOffset, 0, battery_absent, lilka::display.color565(255, 0, 255), 16, 24
);
iconCanvas->draw16bitRGBBitmapWithTranColor(xOffset, 0, battery_absent, lilka::colors::Fuchsia, 16, 24);
xOffset += 4 + 16;
} else {
int16_t x1 = 4, y1 = 6;
int16_t width = 8, fullHeight = 14;
int filledHeight = fullHeight * level / 100;
if (filledHeight < 1) filledHeight = 1;
int emptyHeight = fullHeight - filledHeight;
int16_t color = level > 50
? lilka::display.color565(0, 255, 0)
: (level > 20 ? lilka::display.color565(255, 255, 0) : lilka::display.color565(255, 0, 0));
int16_t color = level > 50 ? lilka::colors::Green : (level > 20 ? lilka::colors::Yellow : lilka::colors::Red);
iconCanvas->draw16bitRGBBitmapWithTranColor(
xOffset, 0, level > 10 ? battery : battery_danger, lilka::display.color565(255, 0, 255), 16, 24
xOffset, 0, level > 10 ? battery : battery_danger, lilka::colors::Fuchsia, 16, 24
);
iconCanvas->fillRect(xOffset + x1, y1 + emptyHeight, width, filledHeight, color);
xOffset += 4 + 16;
Expand Down
7 changes: 3 additions & 4 deletions firmware/keira/src/apps/wifi_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void WiFiConfigApp::run() {
static_cast<NetworkService*>(ServiceManager::getInstance()->getService<NetworkService>("network"));
// TODO: use dynamic_cast and assert networkService != nullptr

buffer.fillScreen(buffer.color565(0, 0, 0));
buffer.fillScreen(lilka::colors::Black);
buffer.setCursor(8, 24);
canvas->drawCanvas(&buffer);
queueDraw();
Expand Down Expand Up @@ -83,8 +83,7 @@ void WiFiConfigApp::run() {
menu.addItem(
networks[i],
icons[signalStrength],
networkService->getPassword(networks[i]).length() ? lilka::display.color565(0, 255, 0)
: lilka::display.color565(255, 255, 255)
networkService->getPassword(networks[i]).length() ? lilka::colors::Green : lilka::colors::White
);
}
menu.addItem("<< Назад");
Expand Down Expand Up @@ -134,7 +133,7 @@ void WiFiConfigApp::run() {
}
networkService->connect(ssid, password);

buffer.fillScreen(buffer.color565(0, 0, 0));
buffer.fillScreen(lilka::colors::Black);
buffer.setCursor(8, 24);
buffer.println("Під'єднуємось...");
canvas->drawCanvas(&buffer);
Expand Down
8 changes: 4 additions & 4 deletions sdk/lib/lilka/examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ void setup() {

void loop() {
// Заповнити екран чорним кольором
lilka::display.fillScreen(lilka::display.color565(0, 255, 0));
lilka::display.fillScreen(lilka::colors::Green);

lilka::Image* image = lilka::resources.loadImage("/sd/hello.bmp", lilka::display.color565(255, 0, 255));
lilka::Image* image = lilka::resources.loadImage("/sd/hello.bmp", lilka::display.lilka::colors::Fuchsia);
lilka::display.drawImage(image, 32, 64);
delay(1000);

Expand All @@ -21,12 +21,12 @@ void loop() {
// Розпочати відтворення звуку на частоті 440 Гц
lilka::buzzer.play(440);
// Заповнити екран червоним кольором
lilka::display.fillScreen(lilka::display.color565(255, 0, 0));
lilka::display.fillScreen(lilka::colors::Red);
} else if (state.a.justReleased) { // Якщо кнопка "A" щойно була відпущена...
// Зупинити відтворення звуку
lilka::buzzer.stop();
// Заповнити екран зеленим кольором
lilka::display.fillScreen(lilka::display.color565(0, 255, 0));
lilka::display.fillScreen(lilka::colors::Green);
}
}
}
4 changes: 2 additions & 2 deletions sdk/lib/lilka/src/lilka/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ void Alert::draw(Arduino_GFX* canvas) {
int width = right - left;
int xMargin = 4;

canvas->setTextColor(canvas->color565(255, 255, 255));
canvas->setTextColor(lilka::colors::White);

canvas->fillRect(left, top, width, mid - top, canvas->color565(32, 32, 128));
canvas->fillRect(left, top, width, mid - top, lilka::colors::Midnight_blue);
canvas->setFont(FONT_6x13);
canvas->setTextSize(2);
canvas->setTextBound(left + xMargin, top, width - xMargin * 2, mid - top);
Expand Down
Loading
Loading