src,lib: zig fmt and clang-format all code

C style is now fixed by .clang-format.
a handy script to check all source code formatting is in
tools/fmt-check.sh.
pull/20/head
alex 2 years ago
parent 161a2b965b
commit 698e5b6f76
Signed by: x1ddos
GPG Key ID: FDEFB4A63CBD8460

@ -0,0 +1,14 @@
# https://clang.llvm.org/docs/ClangFormat.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
IndentWidth: 4
ContinuationIndentWidth: 4
UseTab: Never
ColumnLimit: 102
PointerAlignment: Right
BreakBeforeBraces: Linux
AlignAfterOpenBracket: DontAlign
BinPackArguments: false
BinPackParameters: false
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true

@ -5,17 +5,17 @@ pub fn addPkg(b: *build.Builder, obj: *build.LibExeObjStep, prefix: []const u8)
} }
pub fn pkgPath(b: *build.Builder, prefix: []const u8) []const u8 { pub fn pkgPath(b: *build.Builder, prefix: []const u8) []const u8 {
return b.pathJoin(&.{prefix, "nif.zig"}); return b.pathJoin(&.{ prefix, "nif.zig" });
} }
pub fn library(b: *build.Builder, prefix: []const u8) *build.LibExeObjStep { pub fn library(b: *build.Builder, prefix: []const u8) *build.LibExeObjStep {
const lib = b.addStaticLibrary("nif", b.pathJoin(&.{prefix, "nif.zig"})); const lib = b.addStaticLibrary("nif", b.pathJoin(&.{ prefix, "nif.zig" }));
lib.addIncludePath(b.pathJoin(&.{prefix, "wpa_supplicant"})); lib.addIncludePath(b.pathJoin(&.{ prefix, "wpa_supplicant" }));
lib.defineCMacro("CONFIG_CTRL_IFACE", null); lib.defineCMacro("CONFIG_CTRL_IFACE", null);
lib.defineCMacro("CONFIG_CTRL_IFACE_UNIX", null); lib.defineCMacro("CONFIG_CTRL_IFACE_UNIX", null);
lib.addCSourceFiles(&.{ lib.addCSourceFiles(&.{
b.pathJoin(&.{prefix, "wpa_supplicant/wpa_ctrl.c"}), b.pathJoin(&.{ prefix, "wpa_supplicant/wpa_ctrl.c" }),
b.pathJoin(&.{prefix, "wpa_supplicant/os_unix.c"}), b.pathJoin(&.{ prefix, "wpa_supplicant/os_unix.c" }),
}, &.{ }, &.{
"-Wall", "-Wall",
"-Wextra", "-Wextra",

@ -90,7 +90,7 @@ pub const Control = struct {
/// add a new blank network, returning its ID. /// add a new blank network, returning its ID.
/// the newly added network can be configured with self.setNetworkParam. /// the newly added network can be configured with self.setNetworkParam.
pub fn addNetwork(self: *Self) (Error||std.fmt.ParseIntError)!u32 { pub fn addNetwork(self: *Self) (Error || std.fmt.ParseIntError)!u32 {
var buf: [10:0]u8 = undefined; var buf: [10:0]u8 = undefined;
const resp = self.request("ADD_NETWORK", &buf, null) catch return error.WpaCtrlAddNetwork; const resp = self.request("ADD_NETWORK", &buf, null) catch return error.WpaCtrlAddNetwork;
return std.fmt.parseUnsigned(u32, mem.trim(u8, resp, "\n "), 10); return std.fmt.parseUnsigned(u32, mem.trim(u8, resp, "\n "), 10);
@ -116,7 +116,7 @@ pub const Control = struct {
pub fn setNetworkParam(self: *Self, id: u32, name: []const u8, value: []const u8) Error!void { pub fn setNetworkParam(self: *Self, id: u32, name: []const u8, value: []const u8) Error!void {
var buf: [512:0]u8 = undefined; var buf: [512:0]u8 = undefined;
const cmd = try std.fmt.bufPrintZ(&buf, "SET_NETWORK {d} {s} {s}", .{id, name, value}); const cmd = try std.fmt.bufPrintZ(&buf, "SET_NETWORK {d} {s} {s}", .{ id, name, value });
return self.reqOK(cmd) catch return error.WpaCtrlSetNetworkParam; return self.reqOK(cmd) catch return error.WpaCtrlSetNetworkParam;
} }

@ -220,8 +220,8 @@ fn svShutdown(allocator: std.mem.Allocator) void {
// http://smarden.org/runit/ // http://smarden.org/runit/
const Argv = []const []const u8; const Argv = []const []const u8;
const cmds: []const Argv = &.{ const cmds: []const Argv = &.{
&.{"sv", "-w", "600", "stop", "lnd"}, &.{ "sv", "-w", "600", "stop", "lnd" },
&.{"sv", "-w", "600", "stop", "bitcoind"}, &.{ "sv", "-w", "600", "stop", "bitcoind" },
}; };
var procs: [cmds.len]?std.ChildProcess = undefined; var procs: [cmds.len]?std.ChildProcess = undefined;
for (cmds) |argv, i| { for (cmds) |argv, i| {
@ -229,7 +229,7 @@ fn svShutdown(allocator: std.mem.Allocator) void {
if (p.spawn()) { if (p.spawn()) {
procs[i] = p; procs[i] = p;
} else |err| { } else |err| {
logger.err("{s}: {any}", .{argv, err}); logger.err("{s}: {any}", .{ argv, err });
} }
} }
for (procs) |_, i| { for (procs) |_, i| {

@ -4,13 +4,13 @@ export fn wifi_ssid_add_network(name: [*:0]const u8) void {
_ = name; _ = name;
} }
export fn lv_timer_del(timer: *opaque{}) void { export fn lv_timer_del(timer: *opaque {}) void {
_ = timer; _ = timer;
} }
test { test {
std.testing.refAllDecls(@This());
_ = @import("comm.zig"); _ = @import("comm.zig");
_ = @import("ngui.zig"); _ = @import("ngui.zig");
std.testing.refAllDecls(@This());
} }

@ -11,4 +11,3 @@ pub const TestTimer = if (!builtin.is_test) @compileError("TestTimer is for test
return self.value; return self.value;
} }
}; };

@ -2,13 +2,13 @@
* framebuffer display + evdev touchpad drivers init * framebuffer display + evdev touchpad drivers init
*/ */
#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h" #include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h" #include "lv_drivers/indev/evdev.h"
#include "lvgl/lvgl.h"
#define DISP_BUF_SIZE NM_DISP_HOR * NM_DISP_VER / 10 #define DISP_BUF_SIZE NM_DISP_HOR *NM_DISP_VER / 10
lv_disp_t* drv_init(void) lv_disp_t *drv_init(void)
{ {
fbdev_init(); fbdev_init();
@ -28,14 +28,14 @@ lv_disp_t* drv_init(void)
disp_drv.ver_res = NM_DISP_VER; disp_drv.ver_res = NM_DISP_VER;
disp_drv.antialiasing = 1; disp_drv.antialiasing = 1;
disp_drv.flush_cb = fbdev_flush; disp_drv.flush_cb = fbdev_flush;
lv_disp_t* disp = lv_disp_drv_register(&disp_drv); lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
if (disp == NULL) { if (disp == NULL) {
return NULL; return NULL;
} }
/* keypad input devices default group; /* keypad input devices default group;
* future-proof: don't have any atm */ * future-proof: don't have any atm */
lv_group_t* g = lv_group_create(); lv_group_t *g = lv_group_create();
if (g == NULL) { if (g == NULL) {
return NULL; return NULL;
} }
@ -46,7 +46,7 @@ lv_disp_t* drv_init(void)
lv_indev_drv_init(&touchpad_drv); lv_indev_drv_init(&touchpad_drv);
touchpad_drv.type = LV_INDEV_TYPE_POINTER; touchpad_drv.type = LV_INDEV_TYPE_POINTER;
touchpad_drv.read_cb = evdev_read; touchpad_drv.read_cb = evdev_read;
lv_indev_t* touchpad = lv_indev_drv_register(&touchpad_drv); lv_indev_t *touchpad = lv_indev_drv_register(&touchpad_drv);
if (touchpad == NULL) { if (touchpad == NULL) {
/* TODO: or continue without the touchpad? */ /* TODO: or continue without the touchpad? */
return NULL; return NULL;

@ -2,14 +2,14 @@
* SDL2 drivers init for display, keyboard and mouse * SDL2 drivers init for display, keyboard and mouse
*/ */
#include "lv_drivers/sdl/sdl.h"
#include "lvgl/lvgl.h" #include "lvgl/lvgl.h"
#include "lvgl/src/misc/lv_log.h" #include "lvgl/src/misc/lv_log.h"
#include "lv_drivers/sdl/sdl.h"
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/ #define SDL_MAIN_HANDLED /* suppress "undefined reference to WinMain" */
#include SDL_INCLUDE_PATH #include SDL_INCLUDE_PATH
lv_disp_t* drv_init(void) lv_disp_t *drv_init(void)
{ {
sdl_init(); sdl_init();
SDL_DisplayMode dm; SDL_DisplayMode dm;
@ -20,7 +20,10 @@ lv_disp_t* drv_init(void)
unsigned char bpp = SDL_BITSPERPIXEL(dm.format); unsigned char bpp = SDL_BITSPERPIXEL(dm.format);
LV_LOG_INFO("%ix%i %dbpp %s", dm.w, dm.h, bpp, SDL_GetPixelFormatName(dm.format)); LV_LOG_INFO("%ix%i %dbpp %s", dm.w, dm.h, bpp, SDL_GetPixelFormatName(dm.format));
if (dm.w != NM_DISP_HOR || dm.h != NM_DISP_VER || bpp != LV_COLOR_DEPTH) { if (dm.w != NM_DISP_HOR || dm.h != NM_DISP_VER || bpp != LV_COLOR_DEPTH) {
LV_LOG_WARN("SDL display mismatch; expected %dx%d %dbpp", NM_DISP_HOR, NM_DISP_VER, LV_COLOR_DEPTH); LV_LOG_WARN("SDL display mismatch; expected %dx%d %dbpp",
NM_DISP_HOR,
NM_DISP_VER,
LV_COLOR_DEPTH);
} }
} }
@ -36,7 +39,7 @@ lv_disp_t* drv_init(void)
disp_drv.hor_res = NM_DISP_HOR; disp_drv.hor_res = NM_DISP_HOR;
disp_drv.ver_res = NM_DISP_VER; disp_drv.ver_res = NM_DISP_VER;
disp_drv.antialiasing = 1; disp_drv.antialiasing = 1;
lv_disp_t* disp = lv_disp_drv_register(&disp_drv); lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
if (disp == NULL) { if (disp == NULL) {
return NULL; return NULL;
} }
@ -45,13 +48,13 @@ lv_disp_t* drv_init(void)
lv_indev_drv_init(&mouse_drv); lv_indev_drv_init(&mouse_drv);
mouse_drv.type = LV_INDEV_TYPE_POINTER; mouse_drv.type = LV_INDEV_TYPE_POINTER;
mouse_drv.read_cb = sdl_mouse_read; mouse_drv.read_cb = sdl_mouse_read;
lv_indev_t* mouse = lv_indev_drv_register(&mouse_drv); lv_indev_t *mouse = lv_indev_drv_register(&mouse_drv);
if (mouse == NULL) { if (mouse == NULL) {
LV_LOG_WARN("lv_indev_drv_register(&mouse_drv) returned NULL"); LV_LOG_WARN("lv_indev_drv_register(&mouse_drv) returned NULL");
} }
/* keypad input devices default group */ /* keypad input devices default group */
lv_group_t * g = lv_group_create(); lv_group_t *g = lv_group_create();
if (g == NULL) { if (g == NULL) {
LV_LOG_WARN("lv_group_create returned NULL; won't set default group"); LV_LOG_WARN("lv_group_create returned NULL; won't set default group");
} else { } else {

@ -7,18 +7,18 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
lv_disp_t* drv_init(void); lv_disp_t *drv_init(void);
static lv_style_t style_title; static lv_style_t style_title;
static lv_style_t style_text_muted; static lv_style_t style_text_muted;
static lv_style_t style_btn_red; static lv_style_t style_btn_red;
static const lv_font_t* font_large; static const lv_font_t *font_large;
static lv_obj_t* virt_keyboard; static lv_obj_t *virt_keyboard;
static lv_obj_t* tabview; /* main tabs content parent; lv_tabview_create */ static lv_obj_t *tabview; /* main tabs content parent; lv_tabview_create */
static void textarea_event_cb(lv_event_t* e) static void textarea_event_cb(lv_event_t *e)
{ {
lv_obj_t* textarea = lv_event_get_target(e); lv_obj_t *textarea = lv_event_get_target(e);
lv_event_code_t code = lv_event_get_code(e); lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_FOCUSED) { if (code == LV_EVENT_FOCUSED) {
if (lv_indev_get_type(lv_indev_get_act()) != LV_INDEV_TYPE_KEYPAD) { if (lv_indev_get_type(lv_indev_get_act()) != LV_INDEV_TYPE_KEYPAD) {
@ -38,31 +38,35 @@ static void textarea_event_cb(lv_event_t* e)
lv_obj_set_height(tabview, NM_DISP_VER); lv_obj_set_height(tabview, NM_DISP_VER);
lv_obj_add_flag(virt_keyboard, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(virt_keyboard, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_state(textarea, LV_STATE_FOCUSED); lv_obj_clear_state(textarea, LV_STATE_FOCUSED);
lv_indev_reset(NULL, textarea); /* forget the last clicked object to make it focusable again */ lv_indev_reset(NULL, textarea); /* forget last obj to make it focusable again */
} }
} }
static void create_bitcoin_panel(lv_obj_t* parent) static void create_bitcoin_panel(lv_obj_t *parent)
{ {
lv_obj_t* label = lv_label_create(parent); lv_obj_t *label = lv_label_create(parent);
lv_label_set_text_static(label, "bitcoin tab isn't designed yet\nfollow https://nakamochi.io"); lv_label_set_text_static(label,
"bitcoin tab isn't designed yet\n"
"follow https://nakamochi.io");
lv_obj_center(label); lv_obj_center(label);
} }
static void create_lnd_panel(lv_obj_t* parent) static void create_lnd_panel(lv_obj_t *parent)
{ {
lv_obj_t* label = lv_label_create(parent); lv_obj_t *label = lv_label_create(parent);
lv_label_set_text_static(label, "lightning tab isn't designed yet\nfollow https://nakamochi.io"); lv_label_set_text_static(label,
"lightning tab isn't designed yet\n"
"follow https://nakamochi.io");
lv_obj_center(label); lv_obj_center(label);
} }
static struct { static struct {
lv_obj_t* wifi_spinner_obj; /* lv_spinner_create */ lv_obj_t *wifi_spinner_obj; /* lv_spinner_create */
lv_obj_t* wifi_status_obj; /* lv_label_create */ lv_obj_t *wifi_status_obj; /* lv_label_create */
lv_obj_t* wifi_connect_btn_obj; /* lv_btn_create */ lv_obj_t *wifi_connect_btn_obj; /* lv_btn_create */
lv_obj_t* wifi_ssid_list_obj; /* lv_dropdown_create */ lv_obj_t *wifi_ssid_list_obj; /* lv_dropdown_create */
lv_obj_t* wifi_pwd_obj; /* lv_textarea_create */ lv_obj_t *wifi_pwd_obj; /* lv_textarea_create */
lv_obj_t* power_halt_btn_obj; /* lv_btn_create */ lv_obj_t *power_halt_btn_obj; /* lv_btn_create */
} settings; } settings;
/** /**
@ -80,7 +84,7 @@ extern void ui_update_network_status(const char *text, const char *wifi_list)
lv_label_set_text(settings.wifi_status_obj, text); lv_label_set_text(settings.wifi_status_obj, text);
} }
static void wifi_connect_btn_callback(lv_event_t* e) static void wifi_connect_btn_callback(lv_event_t *e)
{ {
(void)e; /* unused */ (void)e; /* unused */
lv_obj_add_state(settings.wifi_connect_btn_obj, LV_STATE_DISABLED); lv_obj_add_state(settings.wifi_connect_btn_obj, LV_STATE_DISABLED);
@ -111,86 +115,85 @@ static void power_halt_btn_callback(lv_event_t *e)
/* first button must always be a "proceed", do shutdown; /* first button must always be a "proceed", do shutdown;
* text is irrelevant */ * text is irrelevant */
static const char *btns[] = {"PROCEED", "ABORT", NULL}; static const char *btns[] = {"PROCEED", "ABORT", NULL};
lv_obj_t *msgbox = lv_msgbox_create( lv_obj_t *msgbox = lv_msgbox_create(NULL, /* modal */
NULL /* modal */,
"SHUTDOWN", /* title */ "SHUTDOWN", /* title */
"are you sure?", /* text */ "are you sure?", /* text */
btns, btns, /* */
false /* close btn */); false /* close btn */);
lv_obj_center(msgbox); lv_obj_center(msgbox);
lv_obj_add_event_cb(msgbox, power_halt_btn_callback, LV_EVENT_VALUE_CHANGED, msgbox); lv_obj_add_event_cb(msgbox, power_halt_btn_callback, LV_EVENT_VALUE_CHANGED, msgbox);
return; return;
} }
static void create_settings_panel(lv_obj_t* parent) static void create_settings_panel(lv_obj_t *parent)
{ {
/******************** /********************
* wifi panel * wifi panel
********************/ ********************/
lv_obj_t* wifi_panel = lv_obj_create(parent); lv_obj_t *wifi_panel = lv_obj_create(parent);
lv_obj_set_height(wifi_panel, LV_SIZE_CONTENT); lv_obj_set_height(wifi_panel, LV_SIZE_CONTENT);
lv_obj_t * wifi_panel_title = lv_label_create(wifi_panel); lv_obj_t *wifi_panel_title = lv_label_create(wifi_panel);
lv_label_set_text_static(wifi_panel_title, LV_SYMBOL_WIFI " WIFI"); lv_label_set_text_static(wifi_panel_title, LV_SYMBOL_WIFI " WIFI");
lv_obj_add_style(wifi_panel_title, &style_title, 0); lv_obj_add_style(wifi_panel_title, &style_title, 0);
lv_obj_t* wifi_spinner = lv_spinner_create(wifi_panel, 1000 /* speed */, 60 /* arc in deg */); lv_obj_t *wifi_spinner = lv_spinner_create(wifi_panel, 1000 /* speed */, 60 /* arc in deg */);
settings.wifi_spinner_obj = wifi_spinner; settings.wifi_spinner_obj = wifi_spinner;
lv_obj_add_flag(wifi_spinner, LV_OBJ_FLAG_HIDDEN); lv_obj_add_flag(wifi_spinner, LV_OBJ_FLAG_HIDDEN);
lv_obj_set_size(wifi_spinner, 20, 20); lv_obj_set_size(wifi_spinner, 20, 20);
lv_obj_set_style_arc_width(wifi_spinner, 4, LV_PART_INDICATOR); lv_obj_set_style_arc_width(wifi_spinner, 4, LV_PART_INDICATOR);
lv_obj_t* wifi_status = lv_label_create(wifi_panel); lv_obj_t *wifi_status = lv_label_create(wifi_panel);
settings.wifi_status_obj = wifi_status; settings.wifi_status_obj = wifi_status;
lv_label_set_text_static(wifi_status, "unknown status"); lv_label_set_text_static(wifi_status, "unknown status");
lv_label_set_long_mode(wifi_status, LV_LABEL_LONG_WRAP); lv_label_set_long_mode(wifi_status, LV_LABEL_LONG_WRAP);
lv_obj_set_height(wifi_status, LV_SIZE_CONTENT); lv_obj_set_height(wifi_status, LV_SIZE_CONTENT);
lv_label_set_recolor(wifi_status, true); lv_label_set_recolor(wifi_status, true);
lv_obj_t* wifi_ssid_label = lv_label_create(wifi_panel); lv_obj_t *wifi_ssid_label = lv_label_create(wifi_panel);
lv_label_set_text_static(wifi_ssid_label, "network name"); lv_label_set_text_static(wifi_ssid_label, "network name");
lv_obj_add_style(wifi_ssid_label, &style_text_muted, 0); lv_obj_add_style(wifi_ssid_label, &style_text_muted, 0);
lv_obj_t* wifi_ssid = lv_dropdown_create(wifi_panel); lv_obj_t *wifi_ssid = lv_dropdown_create(wifi_panel);
settings.wifi_ssid_list_obj = wifi_ssid; settings.wifi_ssid_list_obj = wifi_ssid;
lv_dropdown_clear_options(wifi_ssid); lv_dropdown_clear_options(wifi_ssid);
lv_obj_t* wifi_pwd_label = lv_label_create(wifi_panel); lv_obj_t *wifi_pwd_label = lv_label_create(wifi_panel);
lv_label_set_text_static(wifi_pwd_label, "password"); lv_label_set_text_static(wifi_pwd_label, "password");
lv_obj_add_style(wifi_pwd_label, &style_text_muted, 0); lv_obj_add_style(wifi_pwd_label, &style_text_muted, 0);
lv_obj_t* wifi_pwd = lv_textarea_create(wifi_panel); lv_obj_t *wifi_pwd = lv_textarea_create(wifi_panel);
settings.wifi_pwd_obj = wifi_pwd; settings.wifi_pwd_obj = wifi_pwd;
lv_textarea_set_one_line(wifi_pwd, true); lv_textarea_set_one_line(wifi_pwd, true);
lv_textarea_set_password_mode(wifi_pwd, true); lv_textarea_set_password_mode(wifi_pwd, true);
lv_obj_add_event_cb(wifi_pwd, textarea_event_cb, LV_EVENT_ALL, NULL); lv_obj_add_event_cb(wifi_pwd, textarea_event_cb, LV_EVENT_ALL, NULL);
lv_obj_t* wifi_connect_btn = lv_btn_create(wifi_panel); lv_obj_t *wifi_connect_btn = lv_btn_create(wifi_panel);
settings.wifi_connect_btn_obj = wifi_connect_btn; settings.wifi_connect_btn_obj = wifi_connect_btn;
lv_obj_set_height(wifi_connect_btn, LV_SIZE_CONTENT); lv_obj_set_height(wifi_connect_btn, LV_SIZE_CONTENT);
lv_obj_add_event_cb(wifi_connect_btn, wifi_connect_btn_callback, LV_EVENT_CLICKED, NULL); lv_obj_add_event_cb(wifi_connect_btn, wifi_connect_btn_callback, LV_EVENT_CLICKED, NULL);
lv_obj_t* wifi_connect_btn_label = lv_label_create(wifi_connect_btn); lv_obj_t *wifi_connect_btn_label = lv_label_create(wifi_connect_btn);
lv_label_set_text_static(wifi_connect_btn_label, "CONNECT"); lv_label_set_text_static(wifi_connect_btn_label, "CONNECT");
lv_obj_center(wifi_connect_btn_label); lv_obj_center(wifi_connect_btn_label);
/******************** /********************
* power panel * power panel
********************/ ********************/
lv_obj_t* power_panel = lv_obj_create(parent); lv_obj_t *power_panel = lv_obj_create(parent);
lv_obj_set_height(power_panel, LV_SIZE_CONTENT); lv_obj_set_height(power_panel, LV_SIZE_CONTENT);
lv_obj_t * power_panel_title = lv_label_create(power_panel); lv_obj_t *power_panel_title = lv_label_create(power_panel);
lv_label_set_text_static(power_panel_title, LV_SYMBOL_POWER " POWER"); lv_label_set_text_static(power_panel_title, LV_SYMBOL_POWER " POWER");
lv_obj_add_style(power_panel_title, &style_title, 0); lv_obj_add_style(power_panel_title, &style_title, 0);
lv_obj_t* poweroff_text = lv_label_create(power_panel); lv_obj_t *poweroff_text = lv_label_create(power_panel);
lv_label_set_text_static(poweroff_text, "once shut down, the power cord\ncan be removed."); lv_label_set_text_static(poweroff_text, "once shut down, the power cord\ncan be removed.");
lv_label_set_long_mode(poweroff_text, LV_LABEL_LONG_WRAP); lv_label_set_long_mode(poweroff_text, LV_LABEL_LONG_WRAP);
lv_obj_set_height(poweroff_text, LV_SIZE_CONTENT); lv_obj_set_height(poweroff_text, LV_SIZE_CONTENT);
lv_label_set_recolor(poweroff_text, true); lv_label_set_recolor(poweroff_text, true);
lv_obj_t* power_halt_btn = lv_btn_create(power_panel); lv_obj_t *power_halt_btn = lv_btn_create(power_panel);
settings.power_halt_btn_obj = power_halt_btn; settings.power_halt_btn_obj = power_halt_btn;
lv_obj_set_height(power_halt_btn, LV_SIZE_CONTENT); lv_obj_set_height(power_halt_btn, LV_SIZE_CONTENT);
lv_obj_add_style(power_halt_btn, &style_btn_red, 0); lv_obj_add_style(power_halt_btn, &style_btn_red, 0);
lv_obj_add_event_cb(power_halt_btn, power_halt_btn_callback, LV_EVENT_CLICKED, NULL); lv_obj_add_event_cb(power_halt_btn, power_halt_btn_callback, LV_EVENT_CLICKED, NULL);
lv_obj_t* power_halt_btn_label = lv_label_create(power_halt_btn); lv_obj_t *power_halt_btn_label = lv_label_create(power_halt_btn);
lv_label_set_text_static(power_halt_btn_label, "SHUTDOWN"); lv_label_set_text_static(power_halt_btn_label, "SHUTDOWN");
lv_obj_center(power_halt_btn_label); lv_obj_center(power_halt_btn_label);
@ -198,17 +201,16 @@ static void create_settings_panel(lv_obj_t* parent)
* layout * layout
********************/ ********************/
static lv_coord_t parent_grid_cols[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static lv_coord_t parent_grid_cols[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
static lv_coord_t parent_grid_rows[] = { static lv_coord_t parent_grid_rows[] = {/**/
LV_GRID_CONTENT, /* wifi panel */ LV_GRID_CONTENT, /* wifi panel */
LV_GRID_CONTENT, /* power panel */ LV_GRID_CONTENT, /* power panel */
LV_GRID_TEMPLATE_LAST LV_GRID_TEMPLATE_LAST};
};
lv_obj_set_grid_dsc_array(parent, parent_grid_cols, parent_grid_rows); lv_obj_set_grid_dsc_array(parent, parent_grid_cols, parent_grid_rows);
lv_obj_set_grid_cell(wifi_panel, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1); lv_obj_set_grid_cell(wifi_panel, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
lv_obj_set_grid_cell(power_panel, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1); lv_obj_set_grid_cell(power_panel, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
static lv_coord_t wifi_grid_cols[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static lv_coord_t wifi_grid_cols[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
static lv_coord_t wifi_grid_rows[] = { static lv_coord_t wifi_grid_rows[] = {/**/
LV_GRID_CONTENT, /* title */ LV_GRID_CONTENT, /* title */
5, /* separator */ 5, /* separator */
LV_GRID_CONTENT, /* wifi status text */ LV_GRID_CONTENT, /* wifi status text */
@ -218,8 +220,7 @@ static void create_settings_panel(lv_obj_t* parent)
30, /* password input */ 30, /* password input */
5, /* separator */ 5, /* separator */
LV_GRID_CONTENT, /* connect btn */ LV_GRID_CONTENT, /* connect btn */
LV_GRID_TEMPLATE_LAST LV_GRID_TEMPLATE_LAST};
};
lv_obj_set_grid_dsc_array(wifi_panel, wifi_grid_cols, wifi_grid_rows); lv_obj_set_grid_dsc_array(wifi_panel, wifi_grid_cols, wifi_grid_rows);
lv_obj_set_grid_cell(wifi_panel_title, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1); lv_obj_set_grid_cell(wifi_panel_title, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
lv_obj_set_grid_cell(wifi_spinner, LV_GRID_ALIGN_END, 1, 1, LV_GRID_ALIGN_CENTER, 0, 1); lv_obj_set_grid_cell(wifi_spinner, LV_GRID_ALIGN_END, 1, 1, LV_GRID_ALIGN_CENTER, 0, 1);
@ -233,12 +234,11 @@ static void create_settings_panel(lv_obj_t* parent)
lv_obj_set_grid_cell(wifi_connect_btn, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 8, 1); lv_obj_set_grid_cell(wifi_connect_btn, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 8, 1);
static lv_coord_t power_grid_cols[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; static lv_coord_t power_grid_cols[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
static lv_coord_t power_grid_rows[] = { static lv_coord_t power_grid_rows[] = {/**/
LV_GRID_CONTENT, /* title */ LV_GRID_CONTENT, /* title */
5, /* separator */ 5, /* separator */
LV_GRID_CONTENT, /* power off text and btn*/ LV_GRID_CONTENT, /* power off text and btn*/
LV_GRID_TEMPLATE_LAST LV_GRID_TEMPLATE_LAST};
};
lv_obj_set_grid_dsc_array(power_panel, power_grid_cols, power_grid_rows); lv_obj_set_grid_dsc_array(power_panel, power_grid_cols, power_grid_rows);
lv_obj_set_grid_cell(power_panel_title, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_CENTER, 0, 1); lv_obj_set_grid_cell(power_panel_title, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_CENTER, 0, 1);
/* column 0 */ /* column 0 */
@ -247,7 +247,7 @@ static void create_settings_panel(lv_obj_t* parent)
lv_obj_set_grid_cell(power_halt_btn, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 2, 1); lv_obj_set_grid_cell(power_halt_btn, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 2, 1);
} }
static void tab_changed_event_cb(lv_event_t* e) static void tab_changed_event_cb(lv_event_t *e)
{ {
(void)e; /* unused */ (void)e; /* unused */
uint16_t n = lv_tabview_get_tab_act(tabview); uint16_t n = lv_tabview_get_tab_act(tabview);
@ -263,17 +263,16 @@ static void tab_changed_event_cb(lv_event_t* e)
extern int ui_init() extern int ui_init()
{ {
lv_init(); lv_init();
lv_disp_t* disp = drv_init(); lv_disp_t *disp = drv_init();
if (disp == NULL) { if (disp == NULL) {
return -1; return -1;
} }
/* default theme is static */ /* default theme is static */
lv_theme_t* theme = lv_theme_default_init( lv_theme_t *theme = lv_theme_default_init(disp, /**/
disp,
lv_palette_main(LV_PALETTE_BLUE), /* primary */ lv_palette_main(LV_PALETTE_BLUE), /* primary */
lv_palette_main(LV_PALETTE_RED), /* secondary */ lv_palette_main(LV_PALETTE_RED), /* secondary */
true /*LV_THEME_DEFAULT_DARK*/, true, /* dark mode, LV_THEME_DEFAULT_DARK */
LV_FONT_DEFAULT); LV_FONT_DEFAULT /* lv_conf.h def */);
lv_disp_set_theme(disp, theme); lv_disp_set_theme(disp, theme);
font_large = &lv_font_courierprimecode_24; /* static */ font_large = &lv_font_courierprimecode_24; /* static */
@ -306,17 +305,17 @@ extern int ui_init()
* 1: lightning * 1: lightning
* 2: settings * 2: settings
*/ */
lv_obj_t* tab_btc = lv_tabview_add_tab(tabview, NM_SYMBOL_BITCOIN " BITCOIN"); lv_obj_t *tab_btc = lv_tabview_add_tab(tabview, NM_SYMBOL_BITCOIN " BITCOIN");
if (tab_btc == NULL) { if (tab_btc == NULL) {
return -1; return -1;
} }
create_bitcoin_panel(tab_btc); create_bitcoin_panel(tab_btc);
lv_obj_t* tab_lnd = lv_tabview_add_tab(tabview, NM_SYMBOL_BOLT " LIGHTNING"); lv_obj_t *tab_lnd = lv_tabview_add_tab(tabview, NM_SYMBOL_BOLT " LIGHTNING");
if (tab_lnd == NULL) { if (tab_lnd == NULL) {
return -1; return -1;
} }
create_lnd_panel(tab_lnd); create_lnd_panel(tab_lnd);
lv_obj_t* tab_settings = lv_tabview_add_tab(tabview, LV_SYMBOL_SETTINGS " SETTINGS"); lv_obj_t *tab_settings = lv_tabview_add_tab(tabview, LV_SYMBOL_SETTINGS " SETTINGS");
if (tab_settings == NULL) { if (tab_settings == NULL) {
return -1; return -1;
} }

@ -23,6 +23,6 @@ void nm_tab_settings_active();
* initiate connection to a wifi network with the given SSID and a password. * initiate connection to a wifi network with the given SSID and a password.
* connection, if successful, is persisted in wpa_supplicant config. * connection, if successful, is persisted in wpa_supplicant config.
*/ */
int nm_wifi_start_connect(const char* ssid, const char* password); int nm_wifi_start_connect(const char *ssid, const char *password);
#endif #endif

@ -0,0 +1,5 @@
#!/bin/sh
set -e
zig fmt --check .
C_FILES=$(find ./src -type f -name '*.c' ! -name 'lv_font*')
clang-format -style=file -dry-run -verbose -Werror $C_FILES