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",

@ -28,36 +28,36 @@ extern "c" fn freeifaddrs(ptr: *ifaddrs) void;
/// optionally filtering by the interface name. /// optionally filtering by the interface name.
/// caller owns the returned value. /// caller owns the returned value.
pub fn pubAddresses(allocator: mem.Allocator, ifname: ?[]const u8) ![]net.Address { pub fn pubAddresses(allocator: mem.Allocator, ifname: ?[]const u8) ![]net.Address {
var res: *ifaddrs = undefined; var res: *ifaddrs = undefined;
if (getifaddrs(&res) != 0) { if (getifaddrs(&res) != 0) {
return error.Getifaddrs; return error.Getifaddrs;
} }
defer freeifaddrs(res); defer freeifaddrs(res);
var list = std.ArrayList(net.Address).init(allocator); var list = std.ArrayList(net.Address).init(allocator);
var it: ?*ifaddrs = res; var it: ?*ifaddrs = res;
while (it) |ifa| : (it = ifa.next) { while (it) |ifa| : (it = ifa.next) {
const sa: *os.sockaddr = ifa.addr orelse continue; const sa: *os.sockaddr = ifa.addr orelse continue;
if (sa.family != os.AF.INET and sa.family != os.AF.INET6) { if (sa.family != os.AF.INET and sa.family != os.AF.INET6) {
// not an IP address // not an IP address
continue; continue;
} }
if (ifa.flags & IFF_UP == 0 or ifa.flags & IFF_LOOPBACK != 0) { if (ifa.flags & IFF_UP == 0 or ifa.flags & IFF_LOOPBACK != 0) {
// skip loopbacks and those which are not "up" // skip loopbacks and those which are not "up"
continue; continue;
} }
const ipaddr = net.Address.initPosix(@alignCast(4, sa)); // initPosix makes a copy const ipaddr = net.Address.initPosix(@alignCast(4, sa)); // initPosix makes a copy
if (ipaddr.any.family == os.AF.INET6 and ipaddr.in6.sa.scope_id > 0) { if (ipaddr.any.family == os.AF.INET6 and ipaddr.in6.sa.scope_id > 0) {
// want only global, with 0 scope // want only global, with 0 scope
// non-zero scopes make sense for link-local addr only. // non-zero scopes make sense for link-local addr only.
continue;
}
if (ifname) |name| {
if (!mem.eql(u8, name, mem.sliceTo(ifa.name, 0))) {
continue; continue;
} }
if (ifname) |name| {
if (!mem.eql(u8, name, mem.sliceTo(ifa.name, 0))) {
continue;
}
}
try list.append(ipaddr);
} }
return list.toOwnedSlice(); try list.append(ipaddr);
}
return list.toOwnedSlice();
} }

@ -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,55 +2,55 @@
* 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();
static lv_disp_draw_buf_t buf; static lv_disp_draw_buf_t buf;
static lv_color_t cb[DISP_BUF_SIZE]; static lv_color_t cb[DISP_BUF_SIZE];
lv_disp_draw_buf_init(&buf, cb, NULL, DISP_BUF_SIZE); lv_disp_draw_buf_init(&buf, cb, NULL, DISP_BUF_SIZE);
uint32_t hor, vert; uint32_t hor, vert;
fbdev_get_sizes(&hor, &vert, NULL); fbdev_get_sizes(&hor, &vert, NULL);
if (hor != NM_DISP_HOR || vert != NM_DISP_VER) { if (hor != NM_DISP_HOR || vert != NM_DISP_VER) {
LV_LOG_WARN("framebuffer display mismatch; expected %dx%d", NM_DISP_HOR, NM_DISP_VER); LV_LOG_WARN("framebuffer display mismatch; expected %dx%d", NM_DISP_HOR, NM_DISP_VER);
} }
static lv_disp_drv_t disp_drv; static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &buf; disp_drv.draw_buf = &buf;
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;
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;
} }
lv_group_set_default(g); lv_group_set_default(g);
evdev_init(); evdev_init();
static lv_indev_drv_t touchpad_drv; static lv_indev_drv_t touchpad_drv;
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;
} }
return disp; return disp;
} }

@ -2,72 +2,75 @@
* 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;
int dm_err = SDL_GetDesktopDisplayMode(0, &dm); int dm_err = SDL_GetDesktopDisplayMode(0, &dm);
if (dm_err != 0) { if (dm_err != 0) {
LV_LOG_WARN("SDL_GetDesktopDisplayMode: %i", dm_err); LV_LOG_WARN("SDL_GetDesktopDisplayMode: %i", dm_err);
} else { } else {
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);
}
}
static lv_disp_draw_buf_t buf; static lv_disp_draw_buf_t buf;
static lv_color_t cb1[NM_DISP_HOR * 100]; static lv_color_t cb1[NM_DISP_HOR * 100];
static lv_color_t cb2[NM_DISP_HOR * 100]; static lv_color_t cb2[NM_DISP_HOR * 100];
lv_disp_draw_buf_init(&buf, cb1, cb2, NM_DISP_HOR * 100); lv_disp_draw_buf_init(&buf, cb1, cb2, NM_DISP_HOR * 100);
static lv_disp_drv_t disp_drv; static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv); lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &buf; disp_drv.draw_buf = &buf;
disp_drv.flush_cb = sdl_display_flush; disp_drv.flush_cb = sdl_display_flush;
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;
} }
static lv_indev_drv_t mouse_drv; static lv_indev_drv_t mouse_drv;
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 {
lv_group_set_default(g); lv_group_set_default(g);
} }
static lv_indev_drv_t keyboard_drv; static lv_indev_drv_t keyboard_drv;
lv_indev_drv_init(&keyboard_drv); lv_indev_drv_init(&keyboard_drv);
keyboard_drv.type = LV_INDEV_TYPE_KEYPAD; keyboard_drv.type = LV_INDEV_TYPE_KEYPAD;
keyboard_drv.read_cb = sdl_keyboard_read; keyboard_drv.read_cb = sdl_keyboard_read;
lv_indev_t *kb = lv_indev_drv_register(&keyboard_drv); lv_indev_t *kb = lv_indev_drv_register(&keyboard_drv);
if (kb == NULL) { if (kb == NULL) {
LV_LOG_WARN("lv_indev_drv_register(&keyboard_drv) returned NULL"); LV_LOG_WARN("lv_indev_drv_register(&keyboard_drv) returned NULL");
} else if (g) { } else if (g) {
lv_indev_set_group(kb, g); lv_indev_set_group(kb, g);
} }
return disp; return disp;
} }

@ -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,
lv_obj_center(label); "bitcoin tab isn't designed yet\n"
"follow https://nakamochi.io");
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,
lv_obj_center(label); "lightning tab isn't designed yet\n"
"follow https://nakamochi.io");
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,143 +115,139 @@ 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);
/******************** /********************
* 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 */ 30, /* wifi selector */
30, /* wifi selector */ 5, /* separator */
5, /* separator */ LV_GRID_CONTENT, /* password label */
LV_GRID_CONTENT, /* password label */ 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_cell(wifi_panel_title, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
lv_obj_set_grid_dsc_array(wifi_panel, wifi_grid_cols, wifi_grid_rows); 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_panel_title, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1); /* column 0 */
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_status, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 2, 7);
/* column 0 */ /* column 1 */
lv_obj_set_grid_cell(wifi_status, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 2, 7); lv_obj_set_grid_cell(wifi_ssid_label, LV_GRID_ALIGN_START, 1, 1, LV_GRID_ALIGN_START, 2, 1);
/* column 1 */ lv_obj_set_grid_cell(wifi_ssid, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 3, 1);
lv_obj_set_grid_cell(wifi_ssid_label, LV_GRID_ALIGN_START, 1, 1, LV_GRID_ALIGN_START, 2, 1); lv_obj_set_grid_cell(wifi_pwd_label, LV_GRID_ALIGN_START, 1, 1, LV_GRID_ALIGN_START, 5, 1);
lv_obj_set_grid_cell(wifi_ssid, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 3, 1); lv_obj_set_grid_cell(wifi_pwd, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 6, 1);
lv_obj_set_grid_cell(wifi_pwd_label, LV_GRID_ALIGN_START, 1, 1, LV_GRID_ALIGN_START, 5, 1); 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_pwd, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 6, 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_rows[] = {/**/
static lv_coord_t power_grid_cols[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; LV_GRID_CONTENT, /* title */
static lv_coord_t power_grid_rows[] = { 5, /* separator */
LV_GRID_CONTENT, /* title */ LV_GRID_CONTENT, /* power off text and btn*/
5, /* separator */ LV_GRID_TEMPLATE_LAST};
LV_GRID_CONTENT, /* power off text and btn*/ lv_obj_set_grid_dsc_array(power_panel, power_grid_cols, power_grid_rows);
LV_GRID_TEMPLATE_LAST lv_obj_set_grid_cell(power_panel_title, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_CENTER, 0, 1);
}; /* column 0 */
lv_obj_set_grid_dsc_array(power_panel, power_grid_cols, power_grid_rows); lv_obj_set_grid_cell(poweroff_text, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 2, 1);
lv_obj_set_grid_cell(power_panel_title, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_CENTER, 0, 1); /* column 1 */
/* column 0 */ 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(poweroff_text, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 2, 1);
/* column 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);
@ -262,66 +262,65 @@ 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, /* dark mode, LV_THEME_DEFAULT_DARK */
true /*LV_THEME_DEFAULT_DARK*/, LV_FONT_DEFAULT /* lv_conf.h def */);
LV_FONT_DEFAULT); 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 */ lv_style_init(&style_title);
lv_style_init(&style_title); lv_style_set_text_font(&style_title, font_large);
lv_style_set_text_font(&style_title, font_large);
lv_style_init(&style_text_muted);
lv_style_init(&style_text_muted); lv_style_set_text_opa(&style_text_muted, LV_OPA_50);
lv_style_set_text_opa(&style_text_muted, LV_OPA_50);
lv_style_init(&style_btn_red);
lv_style_init(&style_btn_red); lv_style_set_bg_color(&style_btn_red, lv_palette_main(LV_PALETTE_RED));
lv_style_set_bg_color(&style_btn_red, lv_palette_main(LV_PALETTE_RED));
/* global virtual keyboard */
/* global virtual keyboard */ virt_keyboard = lv_keyboard_create(lv_scr_act());
virt_keyboard = lv_keyboard_create(lv_scr_act()); if (virt_keyboard == NULL) {
if (virt_keyboard == NULL) { /* TODO: or continue without keyboard? */
/* TODO: or continue without keyboard? */ return -1;
return -1; }
} lv_obj_add_flag(virt_keyboard, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(virt_keyboard, LV_OBJ_FLAG_HIDDEN);
const lv_coord_t tabh = 60;
const lv_coord_t tabh = 60; tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, tabh);
tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, tabh); if (tabview == NULL) {
if (tabview == NULL) { return -1;
return -1; }
}
/**
/** * tab_changed_event_cb relies on the specific tab order, 0-based index:
* tab_changed_event_cb relies on the specific tab order, 0-based index: * 0: bitcoin
* 0: bitcoin * 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; }
} create_settings_panel(tab_settings);
create_settings_panel(tab_settings);
lv_obj_add_event_cb(tabview, tab_changed_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_add_event_cb(tabview, tab_changed_event_cb, LV_EVENT_VALUE_CHANGED, NULL); return 0;
return 0;
} }

@ -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