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

Matrix transforms, tasks pinned to core, keyboard input dialog, improved status bar icons #6

Merged
merged 8 commits into from
Mar 12, 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
52 changes: 19 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
IMAGE2CODE = ./sdk/tools/image2code/image2code.py
CPPCHECK = cppcheck
CLANG_FORMAT = clang-format

help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-16s\033[0m %s\n", $$1, $$2}'

.PHONY: reformat
reformat: ## Reformat all source files
@find \
.PHONY: todo
todo: ## Find all TODO, FIXME, XXX comments
find \
. \
-not \( -name .ccls-cache -prune \) \
-not \( -name .pio -prune \) \
Expand All @@ -16,24 +20,21 @@ reformat: ## Reformat all source files
-o -iname *.hpp \
-o -iname *.h \
-o -iname *.rst \
| xargs clang-format -i
| xargs grep --color=always -n -H -E "TODO|FIXME|XXX" \

.PHONY: todo
todo: ## Find all TODO, FIXME, XXX comments
@find \
. \
.PHONY: icons
icons:
# Find all PNG images in firmware and sdk folders and convert them to .h
find \
firmware \
sdk \
-not \( -name .ccls-cache -prune \) \
-not \( -name .pio -prune \) \
-not \( -name mjs -prune \) \
-not \( -name doomgeneric -prune \) \
-not \( -name bak -prune \) \
-iname *.h \
-o -iname *.cpp \
-o -iname *.c \
-o -iname *.hpp \
-o -iname *.h \
-o -iname *.rst \
| xargs grep --color=always -n -H -E "TODO|FIXME|XXX" \
-iname *.png \
-exec $(IMAGE2CODE) {} \;

.PHONY: check
check: clang-format cppcheck ## Run all checks
Expand Down Expand Up @@ -61,31 +62,16 @@ clang-format: ## Run clang-format check
-o -iname *.c \
-o -iname *.hpp \
-o -iname *.h \
| xargs clang-format --dry-run --Werror
| xargs $(CLANG_FORMAT) --dry-run --Werror

.PHONY: cppcheck
cppcheck: ## Run cppcheck check
cppcheck . -i.ccls-cache -ipio -imjs -idoomgeneric -ibak --enable=performance,style \
$(CPPCHECK) . -i.ccls-cache -ipio -imjs -idoomgeneric -ibak --enable=performance,style \
--suppress=knownPointerToBool \
--suppress=noCopyConstructor \
--suppress=noOperatorEq \
--inline-suppr \
--error-exitcode=1

.PHONY: fix
fix:
# Find all files, but exclude .pio and .ccls-cache directories
# Preserve colors in output
find \
. \
-not \( -name .ccls-cache -prune \) \
-not \( -name .pio -prune \) \
-not \( -name mjs -prune \) \
-not \( -name doomgeneric -prune \) \
-not \( -name bak -prune \) \
-iname *.h \
-o -iname *.cpp \
-o -iname *.c \
-o -iname *.hpp \
-o -iname *.h \
| xargs clang-format -i
fix: ## Fix code style
3 changes: 3 additions & 0 deletions docs/library/display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@

.. doxygenclass:: lilka::Image
:members:

.. doxygenclass:: lilka::Transform
:members:
2 changes: 1 addition & 1 deletion firmware/keira/sdcard/asteroids/asteroids.lua
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function lilka.update(delta)
bullet.speed_x = ship.speed_x / 2 + display.width * dir_x
bullet.speed_y = ship.speed_y / 2 + display.width * dir_y
table.insert(bullets, bullet)
buzzer.play_melody(SHOOT_SOUND, 400)
buzzer.play_melody(SHOOT_SOUND, 600)
end

-- Вихід з гри
Expand Down
5 changes: 4 additions & 1 deletion firmware/keira/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ App::App(const char* name, uint16_t x, uint16_t y, uint16_t w, uint16_t h) :
backCanvas(new lilka::Canvas(x, y, w, h)),
isDrawQueued(false),
backCanvasMutex(xSemaphoreCreateMutex()) {
// Clear buffers
canvas->fillScreen(0);
backCanvas->fillScreen(0);
Serial.println(
"Created app " + String(name) + " at " + String(x) + ", " + String(y) + " with size " + String(w) + "x" +
String(h)
Expand All @@ -27,7 +30,7 @@ void App::start() {
return;
}
Serial.println("Starting app " + String(name));
if (xTaskCreate(_run, name, 8192, this, 1, &taskHandle) != pdPASS) {
if (xTaskCreatePinnedToCore(_run, name, 8192, this, 1, &taskHandle, 0) != pdPASS) {
Serial.println("Failed to create task for app " + String(name) + " (not enough memory?)");
}
}
Expand Down
27 changes: 27 additions & 0 deletions firmware/keira/src/apps/demos/keyboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "keyboard.h"

KeyboardApp::KeyboardApp() : App("Keyboard") {
}

void KeyboardApp::run() {
lilka::InputDialog dialog("Введіть текст:");

while (true) {
dialog.update();
dialog.draw(canvas);
queueDraw();
if (dialog.isDone()) {
break;
}
}

lilka::Alert alert("Ви ввели:", dialog.getValue());
alert.draw(canvas);
queueDraw();
while (true) {
alert.update();
if (alert.isDone()) {
break;
}
}
}
11 changes: 11 additions & 0 deletions firmware/keira/src/apps/demos/keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "app.h"

class KeyboardApp : public App {
public:
KeyboardApp();

private:
void run() override;
};
45 changes: 45 additions & 0 deletions firmware/keira/src/apps/demos/transform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "transform.h"

#include <math.h>

TransformApp::TransformApp() : App("Transform") {
}

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

if (!face) {
lilka::Alert alert("Помилка", "Не вдалось завантажити face.bmp з SD-карти.");
alert.draw(canvas);
queueDraw();
while (!alert.isDone()) {
alert.update();
}
return;
}

int x = canvas->width() / 2;
int y = canvas->height() / 2;

Serial.println("Drawing face at " + String(x) + ", " + String(y));

int angle = 0;

while (1) {
canvas->fillScreen(canvas->color565(0, 64, 0));
// 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);
// uint64_t start = micros();
canvas->drawImageTransformed(face, x, y, transform);
// uint64_t end = micros();
// Serial.println("Drawing took " + String(end - start) + " us");
queueDraw();
angle += 8;

lilka::State state = lilka::controller.getState();
if (state.a.justPressed) {
return;
}
}
}
11 changes: 11 additions & 0 deletions firmware/keira/src/apps/demos/transform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "app.h"

class TransformApp : public App {
public:
TransformApp();

private:
void run() override;
};
Loading
Loading