Skip to content

Commit

Permalink
github: add cppcheck, rename workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Mar 9, 2024
1 parent 0565aa3 commit b0fa5dc
Show file tree
Hide file tree
Showing 31 changed files with 106 additions and 85 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: code-quality

on: [push]

jobs:
clang-format:
runs-on: ubuntu-latest
container: ubuntu:24.04

steps:
- uses: actions/checkout@v3
- name: Run clang-format
run: |
apt update -y
apt install -y make clang-format
make clang-format
cppcheck:
runs-on: ubuntu-latest
container: ubuntu:24.04

steps:
- uses: actions/checkout@v3
- name: Run cppcheck
run: |
apt update -y
apt install -y make cppcheck
make cppcheck
16 changes: 0 additions & 16 deletions .github/workflows/code_style.yml

This file was deleted.

File renamed without changes.
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ todo:
-o -iname *.rst \
| xargs grep --color=always -n -H -E "TODO|FIXME|XXX" \

.PHONY: lint
lint:
.PHONY: check
check: clang-format cppcheck

.PHONY: clang-format
clang-format:
# Find all files, but exclude .pio and .ccls-cache directories
# Preserve colors in output
find \
Expand All @@ -49,6 +52,17 @@ lint:
-o -iname *.h \
| xargs clang-format --dry-run --Werror

.PHONY: cppcheck
cppcheck:
cppcheck . -i.ccls-cache -ipio -imjs -idoomgeneric -ibak --enable=performance,style \
--suppress=cstyleCast \
--suppress=constVariablePointer \
--suppress=constParameterPointer \
--suppress=noExplicitConstructor \
--suppress=noCopyConstructor \
--suppress=noOperatorEq \
--error-exitcode=1

.PHONY: fix
fix:
# Find all files, but exclude .pio and .ccls-cache directories
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Documentation Status](https://readthedocs.org/projects/lilka/badge/?version=latest)](https://docs.lilka.dev)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/and3rson/library/Lilka.svg)](https://registry.platformio.org/libraries/and3rson/Lilka)
[![firmware](https://github.com/and3rson/lilka/actions/workflows/firmware.yml/badge.svg)](https://github.com/and3rson/lilka/actions/workflows/firmware.yml)
[![code style](https://github.com/and3rson/lilka/actions/workflows/code_style.yml/badge.svg)](https://github.com/and3rson/lilka/actions/workflows/code_style.yml)
[![code quality](https://github.com/and3rson/lilka/actions/workflows/code-quality.yml/badge.svg)](https://github.com/and3rson/lilka/actions/workflows/code-quality.yml)
[![Discord](https://img.shields.io/discord/1202315568846213172?label=Discord)][discord]

DIY-консоль, яку можна зібрати з дешевих готових модулів.
Expand Down
17 changes: 10 additions & 7 deletions firmware/keira/src/appmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

AppManager* AppManager::instance = NULL;

AppManager::AppManager() {
panel = NULL;
mutex = xSemaphoreCreateMutex();
AppManager::AppManager() : mutex(xSemaphoreCreateMutex()), panel(NULL) {
}

AppManager::~AppManager() {
Expand Down Expand Up @@ -52,13 +50,18 @@ App* AppManager::removeTopApp() {
App* topApp = apps.back();
apps.pop_back();
delete topApp;
if (apps.size() > 0) {
if (apps.size() == 0) {
// Panic! No apps left
lilka::serial_err("appmanager: no apps left! Panic!");
while (1) {
}
} else {
topApp = apps.back();
topApp->resume();
topApp->forceRedraw();
panel->forceRedraw();
return topApp;
}
topApp->forceRedraw();
panel->forceRedraw();
return topApp;
}

/// Perform one iteration of the main loop.
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/ball.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class BallApp : public App {
BallApp();

private:
void run();
void run() override;
};
8 changes: 5 additions & 3 deletions firmware/keira/src/apps/demos/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ DiskApp::DiskApp() : App("Disk") {
void DiskApp::run() {
float x = random(16, canvas->width() - 16);
float y = random(16, canvas->height() - 16);
float xDir = 3;
float yDir = 3;
float xDir = 5;
float yDir = 5;
int16_t radius = 16;
uint64_t prevRenderTime = millis();
while (1) {
Expand All @@ -16,13 +16,15 @@ void DiskApp::run() {
bool hit = false;
if (x < radius || x > canvas->width() - radius) {
xDir *= -1;
hit = true;
}
if (y < radius || y > canvas->height() - radius) {
yDir *= -1;
hit = true;
}
if (hit) {
// Rotate vector a little bit randomly
float angle = ((float)random(-30, 30)) / 180 * PI;
float angle = ((float)random(-15, 15)) / 180 * PI;
float xDirNew = xDir * cos(angle) - yDir * sin(angle);
float yDirNew = xDir * sin(angle) + yDir * cos(angle);
xDir = xDirNew;
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class DiskApp : public App {
DiskApp();

private:
void run();
void run() override;
};
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/epilepsy.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class EpilepsyApp : public App {
EpilepsyApp();

private:
void run();
void run() override;
};
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/demos/letris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Shape {
int shapeData[4][4];
uint16_t color;

Shape() {
Shape() : x(0), y(0), shapeData(), color(0) {
}

void reset() {
Expand Down Expand Up @@ -243,7 +243,7 @@ void LetrisApp::run() {
while (millis() < nextMove) {
// Обробляємо ввід
lilka::State state = lilka::controller.getState();
int8_t dx = 0, dy = 0;
int8_t dx = 0;
if (state.left.justPressed) {
// Користувач натиснув вліво
dx = -1;
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/letris.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class LetrisApp : public App {
LetrisApp();

private:
void run();
void run() override;
};
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/lines.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class DemoLines : public App {
DemoLines();

private:
void run();
void run() override;
};
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/scan_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class ScanI2CApp : public App {
ScanI2CApp();

private:
void run();
void run() override;
};
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/user_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class UserSPIApp : public App {
UserSPIApp();

private:
void run();
void run() override;
};
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/demos/wifi_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class WifiScanApp : public App {
WifiScanApp();

private:
void run();
void run() override;
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// This is a generated file, do not edit.
// clang-format off
#include <stdint.h>
const uint16_t file_width = 24;
const uint16_t file_height = 24;
const uint16_t file[] = {
const uint16_t normalfile_width = 24;
const uint16_t normalfile_height = 24;
const uint16_t normalfile[] = {
0x0000,
0x0000,
0x0000,
Expand Down
File renamed without changes
12 changes: 4 additions & 8 deletions firmware/keira/src/apps/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "icons/settings.h"
#include "icons/info.h"

#include "icons/file.h"
#include "icons/normalfile.h"
#include "icons/folder.h"
#include "icons/nes.h"
#include "icons/bin.h"
Expand Down Expand Up @@ -116,7 +116,7 @@ const menu_icon_t* get_file_icon(const String& filename) {
} else if (filename.endsWith(".js")) {
return &js;
} else {
return &file;
return &normalfile;
}
}

Expand Down Expand Up @@ -210,7 +210,6 @@ void LauncherApp::spiffsBrowserMenu() {
icons[numEntries - 1] = 0;
colors[numEntries - 1] = 0;

int cursor = 0;
lilka::Menu menu("SPIFFS");
for (int i = 0; i < numEntries; i++) {
menu.addItem(filenames[i], icons[i], colors[i]);
Expand Down Expand Up @@ -244,7 +243,7 @@ void LauncherApp::selectFile(String path) {
);
dialog.draw(canvas);
queueDraw();
while ((error = lilka::multiboot.process()) != 0) {
while ((error = lilka::multiboot.process()) > 0) {
int progress = lilka::multiboot.getBytesWritten() * 100 / lilka::multiboot.getBytesTotal();
dialog.setProgress(progress);
dialog.draw(canvas);
Expand All @@ -254,7 +253,7 @@ void LauncherApp::selectFile(String path) {
return;
}
}
if (error) {
if (error < 0) {
alert("Помилка", String("Етап: 2\nКод: ") + error);
return;
}
Expand Down Expand Up @@ -287,7 +286,6 @@ void LauncherApp::devMenu() {
"Lua REPL",
"<< Назад",
};
int cursor = 0;
int count = sizeof(titles) / sizeof(titles[0]);
lilka::Menu menu("Розробка");
for (int i = 0; i < count; i++) {
Expand Down Expand Up @@ -319,7 +317,6 @@ void LauncherApp::systemUtilsMenu() {
"Таблиця розділів",
"<< Назад",
};
int cursor = 0;
int count = sizeof(titles) / sizeof(titles[0]);
lilka::Menu menu("Системні утиліти");
for (int i = 0; i < count; i++) {
Expand Down Expand Up @@ -360,7 +357,6 @@ void LauncherApp::systemUtilsMenu() {
String labels[16];
int labelCount = lilka::sys.get_partition_labels(labels);
labels[labelCount++] = "<< Назад";
int partitionCursor = 0;
lilka::Menu partitionMenu("Таблиця розділів");
for (int i = 0; i < labelCount; i++) {
partitionMenu.addItem(labels[i]);
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LauncherApp : public App {
LauncherApp();

private:
void run();
void run() override;
void appsMenu();
void sdBrowserMenu(String path);
void spiffsBrowserMenu();
Expand Down
6 changes: 3 additions & 3 deletions firmware/keira/src/apps/lua/lualilka_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ int lualilka_state_load(lua_State* L, const char* path) {
// Read state table
char key[256];
char type[32];
while (fscanf(file, "%s", key) != EOF) {
while (fscanf(file, "%255s", key) != EOF) {
// Read value type
fscanf(file, "%s", type);
fscanf(file, "%31s", type);
if (strcmp(type, "number") == 0) {
// Read number
double value;
Expand All @@ -27,7 +27,7 @@ int lualilka_state_load(lua_State* L, const char* path) {
} else if (strcmp(type, "string") == 0) {
// Read string
char value[256];
fscanf(file, "%s", value);
fscanf(file, "%255s", value);
lilka::serial_log("lua: state: load string %s = %s", key, value);
lua_pushstring(L, value);
lua_setfield(L, -2, key);
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/lua/luarunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ int AbstractLuaRunnerApp::execute() {

if (!callUpdate(L, delta) || !callDraw(L)) {
// No update or draw function - we're done
longjmp(stopjmp, 32);
lilka::serial_log("lua: no update or draw function");
longjmp(stopjmp, 32);
}

// Check if show_fps is true and render FPS
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/statusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class StatusBarApp : public App {
StatusBarApp();

private:
void run();
void run() override;
};
4 changes: 1 addition & 3 deletions firmware/keira/src/service.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "service.h"

Service::Service(const char* name) {
this->name = name;
taskHandle = NULL;
Service::Service(const char* name) : name(name), taskHandle(NULL) {
}

Service::~Service() {
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/services/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NetworkService : public Service {
int getSignalStrength();

private:
void run();
void run() override;
void connect();
NetworkState state;

Expand Down
4 changes: 1 addition & 3 deletions sdk/lib/lilka/src/lilka/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace lilka {

#define fmap(x, in_min, in_max, out_min, out_max) (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

Battery::Battery() {
Battery::Battery() : emptyVoltage(LILKA_DEFAULT_EMPTY_VOLTAGE), fullVoltage(LILKA_DEFAULT_FULL_VOLTAGE) {
}

void Battery::begin() {
Expand All @@ -21,8 +21,6 @@ void Battery::begin() {
LILKA_BATTERY_ADC_FUNC(config_channel_atten)(LILKA_BATTERY_ADC_CHANNEL, ADC_ATTEN_DB_11); // 0..3100mV
// adcX_config_width(adc_width_t width)
LILKA_BATTERY_ADC_FUNC(config_width)(ADC_WIDTH_BIT_12);
setEmptyVoltage(LILKA_DEFAULT_EMPTY_VOLTAGE);
setFullVoltage(LILKA_DEFAULT_FULL_VOLTAGE);
#endif
}

Expand Down
Loading

0 comments on commit b0fa5dc

Please sign in to comment.