88 lines
3.1 KiB
C
Executable File
88 lines
3.1 KiB
C
Executable File
/*
|
|
* deploy.c -- Flash Storage Management module
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*
|
|
* Flash storage manager. Shows storage stats via statvfs("/") and
|
|
* allows manual sync() via the PLAY button.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <sys/statvfs.h>
|
|
#include <sys/stat.h>
|
|
#include <linux/input.h>
|
|
#include "h2_ui.h"
|
|
#include "log_manager.h"
|
|
|
|
#define BUF_SIZE 256
|
|
|
|
static void read_block_stats(char *buf, size_t len) {
|
|
struct statvfs vfs;
|
|
if (statvfs("/", &vfs) != 0) {
|
|
snprintf(buf, len, "statvfs failed");
|
|
return;
|
|
}
|
|
unsigned long long total = (unsigned long long)vfs.f_blocks * vfs.f_frsize;
|
|
unsigned long long used = (unsigned long long)(vfs.f_blocks - vfs.f_bfree) * vfs.f_frsize;
|
|
unsigned long long avail = (unsigned long long)vfs.f_bavail * vfs.f_frsize;
|
|
int pct = (total > 0) ? (int)((used * 100) / total) : 0;
|
|
|
|
snprintf(buf, len,
|
|
"Total: %llu MB\nUsed: %llu MB (%d%%)\nFree: %llu MB",
|
|
total / (1024 * 1024), used / (1024 * 1024), pct, avail / (1024 * 1024));
|
|
}
|
|
|
|
int main(void) {
|
|
init_h2_graphics_runtime("STORAGE SYNCHRONIZER");
|
|
LOG_INF("deploy module started");
|
|
|
|
lv_obj_t *scr = lv_scr_act();
|
|
|
|
lv_obj_t *title = lv_label_create(scr);
|
|
lv_label_set_text(title, "FLASH STORAGE MANAGEMENT");
|
|
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 15);
|
|
lv_obj_set_style_text_color(title, COLOR_PRIMARY, LV_PART_MAIN);
|
|
|
|
lv_obj_t *card = lv_obj_create(scr);
|
|
lv_obj_set_size(card, 280, 140);
|
|
lv_obj_align(card, LV_ALIGN_CENTER, 0, 10);
|
|
|
|
lv_obj_t *stats_lbl = lv_label_create(card);
|
|
lv_obj_set_width(stats_lbl, 260);
|
|
lv_obj_align(stats_lbl, LV_ALIGN_TOP_LEFT, 10, 8);
|
|
|
|
char stats_buf[BUF_SIZE];
|
|
read_block_stats(stats_buf, sizeof(stats_buf));
|
|
lv_label_set_text(stats_lbl, stats_buf);
|
|
|
|
lv_obj_t *status_lbl = lv_label_create(card);
|
|
lv_obj_align(status_lbl, LV_ALIGN_BOTTOM_LEFT, 10, 8);
|
|
lv_obj_set_style_text_color(status_lbl, COLOR_MUTED, LV_PART_MAIN);
|
|
lv_label_set_text(status_lbl, "[PLAY] Sync [BACK] Exit");
|
|
|
|
int input_fd = open("/dev/input/event0", O_RDONLY | O_NONBLOCK);
|
|
struct input_event ev;
|
|
while (1) {
|
|
lv_timer_handler();
|
|
if (input_fd >= 0 && read(input_fd, &ev, sizeof(struct input_event)) > 0) {
|
|
if (ev.type == EV_KEY && ev.code == H2_KEY_PLAY && ev.value == 1) {
|
|
lv_label_set_text(status_lbl, "SYNCING...");
|
|
lv_obj_set_style_text_color(status_lbl, COLOR_PRIMARY, LV_PART_MAIN);
|
|
lv_timer_handler();
|
|
sync();
|
|
read_block_stats(stats_buf, sizeof(stats_buf));
|
|
lv_label_set_text(stats_lbl, stats_buf);
|
|
lv_label_set_text(status_lbl, "SYNC COMPLETE.");
|
|
lv_obj_set_style_text_color(status_lbl, COLOR_ACCENT, LV_PART_MAIN);
|
|
LOG_INF("manual sync triggered");
|
|
}
|
|
if (ev.type == EV_KEY && ev.code == H2_KEY_BACK && ev.value == 1) break;
|
|
}
|
|
usleep(20000);
|
|
}
|
|
if (input_fd >= 0) close(input_fd);
|
|
LOG_INF("deploy module exited");
|
|
return 0;
|
|
} |