mirror of
https://github.com/cottongin/cardputerzero-camera.git
synced 2026-11-20 14:24:48 -06:00
feat(app): add 320x170 shadcn Option A UI, keyboard controller, and device/SDL2 runtime
This commit is contained in:
@@ -10,9 +10,9 @@ option(CZ_TARGET_DEVICE "Build for CardputerZero Linux fbdev/evdev target" OFF)
|
||||
option(CZ_BUILD_TESTS "Build czcamera unit tests" ON)
|
||||
option(CZ_ENABLE_LVGL "Enable optional LVGL UI hook if available" OFF)
|
||||
|
||||
find_package(PkgConfig QUIET)
|
||||
find_package(JPEG QUIET)
|
||||
if(NOT JPEG_FOUND)
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(LIBJPEG IMPORTED_TARGET libjpeg)
|
||||
endif()
|
||||
@@ -22,7 +22,17 @@ if(NOT JPEG_FOUND)
|
||||
find_package(JPEG REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CZ_FREETYPE_TARGET "")
|
||||
find_package(Freetype QUIET)
|
||||
if(TARGET Freetype::Freetype)
|
||||
set(CZ_FREETYPE_TARGET Freetype::Freetype)
|
||||
elseif(PkgConfig_FOUND)
|
||||
pkg_check_modules(FREETYPE QUIET IMPORTED_TARGET freetype2)
|
||||
if(TARGET PkgConfig::FREETYPE)
|
||||
set(CZ_FREETYPE_TARGET PkgConfig::FREETYPE)
|
||||
endif()
|
||||
endif()
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
if(CZ_ENABLE_LVGL)
|
||||
@@ -41,6 +51,8 @@ add_library(czcamera_core STATIC
|
||||
src/timelapse_engine.cpp
|
||||
src/gallery_model.cpp
|
||||
src/video_player.cpp
|
||||
src/ui_controller.cpp
|
||||
src/app_ui.cpp
|
||||
)
|
||||
|
||||
target_include_directories(czcamera_core
|
||||
@@ -61,9 +73,12 @@ target_link_libraries(czcamera_core
|
||||
JPEG::JPEG
|
||||
)
|
||||
|
||||
if(Freetype_FOUND)
|
||||
if(CZ_FREETYPE_TARGET)
|
||||
target_compile_definitions(czcamera_core PUBLIC CZ_HAS_FREETYPE=1)
|
||||
target_link_libraries(czcamera_core PUBLIC Freetype::Freetype)
|
||||
target_link_libraries(czcamera_core PUBLIC ${CZ_FREETYPE_TARGET})
|
||||
message(STATUS "FreeType2 enabled via ${CZ_FREETYPE_TARGET}")
|
||||
else()
|
||||
message(STATUS "FreeType2 not found: using built-in 5x7 bitmap fallback")
|
||||
endif()
|
||||
|
||||
if(CZ_ENABLE_LVGL AND lvgl_FOUND)
|
||||
@@ -82,10 +97,34 @@ if(CZ_BUILD_APP)
|
||||
add_executable(czcamera src/main.cpp)
|
||||
target_compile_options(czcamera PRIVATE -Wall -Wextra -Wpedantic)
|
||||
target_link_libraries(czcamera PRIVATE czcamera_core JPEG::JPEG)
|
||||
if(NOT CZ_TARGET_DEVICE)
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(czcamera PRIVATE SDL2::SDL2)
|
||||
if(CZ_TARGET_DEVICE)
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
message(FATAL_ERROR "CZ_TARGET_DEVICE=ON requires Linux (fbdev/evdev); got CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
message(STATUS "Target backend: Linux fbdev + evdev")
|
||||
else()
|
||||
set(CZ_SDL2_TARGET "")
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(SDL2 QUIET IMPORTED_TARGET sdl2)
|
||||
if(TARGET PkgConfig::SDL2)
|
||||
set(CZ_SDL2_TARGET PkgConfig::SDL2)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT CZ_SDL2_TARGET)
|
||||
find_package(SDL2 REQUIRED)
|
||||
if(TARGET SDL2::SDL2)
|
||||
set(CZ_SDL2_TARGET SDL2::SDL2)
|
||||
endif()
|
||||
endif()
|
||||
if(CZ_SDL2_TARGET)
|
||||
target_link_libraries(czcamera PRIVATE ${CZ_SDL2_TARGET})
|
||||
else()
|
||||
target_include_directories(czcamera PRIVATE ${SDL2_INCLUDE_DIRS})
|
||||
target_link_libraries(czcamera PRIVATE ${SDL2_LIBRARIES})
|
||||
endif()
|
||||
message(STATUS "Target backend: SDL2 320x170 simulator")
|
||||
endif()
|
||||
install(TARGETS czcamera RUNTIME DESTINATION bin)
|
||||
endif()
|
||||
|
||||
if(CZ_BUILD_TESTS)
|
||||
@@ -112,4 +151,9 @@ if(CZ_BUILD_TESTS)
|
||||
target_compile_options(test_timelapse_and_gallery PRIVATE -Wall -Wextra -Wpedantic)
|
||||
target_link_libraries(test_timelapse_and_gallery PRIVATE czcamera_core)
|
||||
add_test(NAME test_timelapse_and_gallery COMMAND test_timelapse_and_gallery)
|
||||
|
||||
add_executable(test_ui_controller tests/test_ui_controller.cpp)
|
||||
target_compile_options(test_ui_controller PRIVATE -Wall -Wextra -Wpedantic)
|
||||
target_link_libraries(test_ui_controller PRIVATE czcamera_core)
|
||||
add_test(NAME test_ui_controller COMMAND test_ui_controller)
|
||||
endif()
|
||||
|
||||
1601
app/src/app_ui.cpp
Normal file
1601
app/src/app_ui.cpp
Normal file
File diff suppressed because it is too large
Load Diff
52
app/src/app_ui.hpp
Normal file
52
app/src/app_ui.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "camera_backend.hpp"
|
||||
#include "theme.hpp"
|
||||
#include "ui_controller.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace cz {
|
||||
|
||||
/// 320x170 shadcn/ui Zinc Option A Split View & Modal Renderer.
|
||||
/// Supports optional FreeType2 / LVGL hooks and built-in anti-aliased
|
||||
/// software framebuffer + 5x7 bitmap fallback.
|
||||
class AppView {
|
||||
public:
|
||||
static constexpr int kWidth = 320;
|
||||
static constexpr int kHeight = 170;
|
||||
|
||||
AppView();
|
||||
~AppView();
|
||||
|
||||
AppView(const AppView&) = delete;
|
||||
AppView& operator=(const AppView&) = delete;
|
||||
|
||||
/// Swap active Zinc Dark / Zinc Light palette tokens without recreating view objects.
|
||||
void apply_theme(ThemeMode mode);
|
||||
|
||||
/// Re-render the 320x170 framebuffer from UiState and optional preview frames.
|
||||
void render(const UiState& state,
|
||||
const PreviewFrame* live_frame = nullptr,
|
||||
const PreviewFrame* gallery_frame = nullptr);
|
||||
|
||||
/// Return 320*170 ARGB8888 (0xAARRGGBB) framebuffer pixels.
|
||||
const uint32_t* pixels() const;
|
||||
|
||||
/// Write current 320x170 framebuffer as a binary PPM (P6) image.
|
||||
bool save_ppm(const std::string& path) const;
|
||||
|
||||
/// True if at least one FreeType font (.ttf/.ttc/.otf) was loaded.
|
||||
bool using_freetype() const;
|
||||
|
||||
/// Return currently applied theme mode.
|
||||
ThemeMode active_theme() const;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace cz
|
||||
865
app/src/main.cpp
Normal file
865
app/src/main.cpp
Normal file
@@ -0,0 +1,865 @@
|
||||
#include "app_ui.hpp"
|
||||
#include "camera_backend.hpp"
|
||||
#include "fb_blit.hpp"
|
||||
#include "storage.hpp"
|
||||
#include "ui_controller.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <csignal>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#if defined(CZ_TARGET_DEVICE) && defined(__linux__)
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/input.h>
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#else
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
volatile std::sig_atomic_t g_signal_stop = 0;
|
||||
|
||||
void handle_signal(int /*sig*/) { g_signal_stop = 1; }
|
||||
|
||||
uint64_t steady_now_ms() {
|
||||
return static_cast<uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count());
|
||||
}
|
||||
|
||||
void print_usage(const char* argv0) {
|
||||
std::cout
|
||||
<< "Usage: " << argv0 << " [options]\n"
|
||||
<< " --sim Run desktop 320x170 SDL2 simulator\n"
|
||||
<< " --scale <1..4> Integer window scale factor (default: 2)\n"
|
||||
<< " --mock-cam Force procedural SimCameraBackend\n"
|
||||
<< " --output-dir <path> Override media output directory\n"
|
||||
<< " --render-test <path.ppm> Render 320x170 snapshot to PPM and exit\n"
|
||||
<< " --theme <dark|light> Theme override (dark or light)\n"
|
||||
<< " --mode <photo|video|timelapse|gallery|settings>\n"
|
||||
<< " Initial mode or modal\n"
|
||||
<< " --rail <right|left> Control rail side (right or left)\n"
|
||||
<< " --help Show this help message\n";
|
||||
}
|
||||
|
||||
struct ScopedTempDir {
|
||||
std::string path;
|
||||
~ScopedTempDir() {
|
||||
if (!path.empty()) {
|
||||
std::error_code ec;
|
||||
fs::remove_all(path, ec);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct CliOptions {
|
||||
int scale = 2;
|
||||
bool mock_cam = false;
|
||||
std::string output_dir;
|
||||
std::string render_test_path;
|
||||
std::string theme_override;
|
||||
std::string mode_override;
|
||||
std::string rail_override;
|
||||
};
|
||||
|
||||
int run_render_test(const CliOptions& cli) {
|
||||
ScopedTempDir temp_dir;
|
||||
std::string eff_out = cli.output_dir;
|
||||
if (eff_out.empty()) {
|
||||
temp_dir.path = "/tmp/czcamera_render_" + std::to_string(::getpid());
|
||||
std::error_code ec;
|
||||
fs::remove_all(temp_dir.path, ec);
|
||||
if (!cz::mkdir_p(temp_dir.path)) {
|
||||
std::cerr << "Failed to prepare temporary render directory\n";
|
||||
return 1;
|
||||
}
|
||||
eff_out = temp_dir.path;
|
||||
}
|
||||
|
||||
cz::UiControllerOptions opts;
|
||||
opts.output_dir_override = eff_out;
|
||||
opts.mock_backend = true;
|
||||
opts.persist_config = false;
|
||||
opts.skip_startup_recovery_scan = true;
|
||||
|
||||
cz::UiController ctrl(nullptr, opts);
|
||||
uint64_t now = 1000;
|
||||
if (!ctrl.init(now)) {
|
||||
std::cerr << "Failed to initialize controller for render-test\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!cli.theme_override.empty()) {
|
||||
const cz::ThemeMode target_theme = cz::theme_from_string(cli.theme_override);
|
||||
if (ctrl.state().theme != target_theme) {
|
||||
ctrl.handle_key('t', cz::KeyCode::Char, now);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cli.rail_override.empty()) {
|
||||
const std::string target_rail =
|
||||
(cli.rail_override == "left") ? "left" : "right";
|
||||
if (ctrl.state().config.rail_side != target_rail) {
|
||||
ctrl.handle_key('w', cz::KeyCode::Char, now);
|
||||
}
|
||||
}
|
||||
|
||||
if (cli.mode_override == "video") {
|
||||
ctrl.handle_key('2', cz::KeyCode::Char, now);
|
||||
} else if (cli.mode_override == "timelapse") {
|
||||
ctrl.handle_key('3', cz::KeyCode::Char, now);
|
||||
} else if (cli.mode_override == "gallery") {
|
||||
// Capture a realistic sample photo if the target directory has no media yet
|
||||
cz::GalleryStore probe;
|
||||
probe.refresh(ctrl.state().effective_output_dir);
|
||||
if (probe.items().empty()) {
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
(void)ctrl.consume_capture_flash();
|
||||
now += 4000;
|
||||
ctrl.tick(now);
|
||||
}
|
||||
ctrl.handle_key('8', cz::KeyCode::Char, now);
|
||||
} else if (cli.mode_override == "settings") {
|
||||
ctrl.handle_key('s', cz::KeyCode::Char, now);
|
||||
}
|
||||
|
||||
cz::PreviewFrame live_frame;
|
||||
if (ctrl.backend()) {
|
||||
ctrl.backend()->copy_latest_preview(0, live_frame);
|
||||
}
|
||||
|
||||
cz::AppView view;
|
||||
view.apply_theme(ctrl.state().theme);
|
||||
view.render(ctrl.state(), &live_frame, ctrl.gallery_preview());
|
||||
const bool ok = view.save_ppm(cli.render_test_path);
|
||||
|
||||
ctrl.shutdown();
|
||||
if (!ok) {
|
||||
std::cerr << "Failed to write PPM to " << cli.render_test_path << "\n";
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CZ_TARGET_DEVICE) && defined(__linux__)
|
||||
|
||||
char map_evdev_code(uint16_t code, bool shift) {
|
||||
switch (code) {
|
||||
case KEY_1: return shift ? '!' : '1';
|
||||
case KEY_2: return shift ? '@' : '2';
|
||||
case KEY_3: return shift ? '#' : '3';
|
||||
case KEY_4: return shift ? '$' : '4';
|
||||
case KEY_5: return shift ? '%' : '5';
|
||||
case KEY_6: return shift ? '^' : '6';
|
||||
case KEY_7: return shift ? '&' : '7';
|
||||
case KEY_8: return shift ? '*' : '8';
|
||||
case KEY_9: return shift ? '(' : '9';
|
||||
case KEY_0: return shift ? ')' : '0';
|
||||
case KEY_A: return shift ? 'A' : 'a';
|
||||
case KEY_B: return shift ? 'B' : 'b';
|
||||
case KEY_C: return shift ? 'C' : 'c';
|
||||
case KEY_D: return shift ? 'D' : 'd';
|
||||
case KEY_E: return shift ? 'E' : 'e';
|
||||
case KEY_F: return shift ? 'F' : 'f';
|
||||
case KEY_G: return shift ? 'G' : 'g';
|
||||
case KEY_H: return shift ? 'H' : 'h';
|
||||
case KEY_I: return shift ? 'I' : 'i';
|
||||
case KEY_J: return shift ? 'J' : 'j';
|
||||
case KEY_K: return shift ? 'K' : 'k';
|
||||
case KEY_L: return shift ? 'L' : 'l';
|
||||
case KEY_M: return shift ? 'M' : 'm';
|
||||
case KEY_N: return shift ? 'N' : 'n';
|
||||
case KEY_O: return shift ? 'O' : 'o';
|
||||
case KEY_P: return shift ? 'P' : 'p';
|
||||
case KEY_Q: return shift ? 'Q' : 'q';
|
||||
case KEY_R: return shift ? 'R' : 'r';
|
||||
case KEY_S: return shift ? 'S' : 's';
|
||||
case KEY_T: return shift ? 'T' : 't';
|
||||
case KEY_U: return shift ? 'U' : 'u';
|
||||
case KEY_V: return shift ? 'V' : 'v';
|
||||
case KEY_W: return shift ? 'W' : 'w';
|
||||
case KEY_X: return shift ? 'X' : 'x';
|
||||
case KEY_Y: return shift ? 'Y' : 'y';
|
||||
case KEY_Z: return shift ? 'Z' : 'z';
|
||||
case KEY_MINUS: return shift ? '_' : '-';
|
||||
case KEY_EQUAL: return shift ? '+' : '=';
|
||||
case KEY_LEFTBRACE: return shift ? '{' : '[';
|
||||
case KEY_RIGHTBRACE: return shift ? '}' : ']';
|
||||
case KEY_SEMICOLON: return shift ? ':' : ';';
|
||||
case KEY_APOSTROPHE: return shift ? '"' : '\'';
|
||||
case KEY_COMMA: return shift ? '<' : ',';
|
||||
case KEY_DOT: return shift ? '>' : '.';
|
||||
case KEY_SLASH: return shift ? '?' : '/';
|
||||
case KEY_BACKSLASH: return shift ? '|' : '\\';
|
||||
case KEY_GRAVE: return shift ? '~' : '`';
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void blit_fbdev(uint8_t* fb_mem,
|
||||
size_t map_size,
|
||||
const fb_var_screeninfo& vinfo,
|
||||
const fb_fix_screeninfo& finfo,
|
||||
const uint32_t* pixels) {
|
||||
cz::FbBlitSpec spec;
|
||||
spec.xres = vinfo.xres;
|
||||
spec.yres = vinfo.yres;
|
||||
spec.xres_virtual = vinfo.xres_virtual;
|
||||
spec.yres_virtual = vinfo.yres_virtual;
|
||||
spec.xoffset = vinfo.xoffset;
|
||||
spec.yoffset = vinfo.yoffset;
|
||||
spec.bits_per_pixel = vinfo.bits_per_pixel;
|
||||
spec.line_length = finfo.line_length;
|
||||
spec.red = {vinfo.red.offset, vinfo.red.length};
|
||||
spec.green = {vinfo.green.offset, vinfo.green.length};
|
||||
spec.blue = {vinfo.blue.offset, vinfo.blue.length};
|
||||
spec.transp = {vinfo.transp.offset, vinfo.transp.length};
|
||||
cz::blit_framebuffer(fb_mem, map_size, spec, pixels, cz::AppView::kWidth,
|
||||
cz::AppView::kHeight);
|
||||
}
|
||||
|
||||
std::vector<int> open_keyboard_evdevs() {
|
||||
std::vector<int> fds;
|
||||
if (const char* override_dev = std::getenv("CZCAMERA_EVDEV_DEVICE")) {
|
||||
const int fd = ::open(override_dev, O_RDONLY | O_NONBLOCK);
|
||||
if (fd >= 0) {
|
||||
fds.push_back(fd);
|
||||
}
|
||||
return fds;
|
||||
}
|
||||
|
||||
DIR* dir = ::opendir("/dev/input");
|
||||
if (dir == nullptr) {
|
||||
return fds;
|
||||
}
|
||||
struct dirent* ent = nullptr;
|
||||
while ((ent = ::readdir(dir)) != nullptr) {
|
||||
if (std::strncmp(ent->d_name, "event", 5) != 0) {
|
||||
continue;
|
||||
}
|
||||
const std::string dev_path = std::string("/dev/input/") + ent->d_name;
|
||||
const int fd = ::open(dev_path.c_str(), O_RDONLY | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
continue;
|
||||
}
|
||||
unsigned long ev_bits[4]{};
|
||||
if (::ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) >= 0 &&
|
||||
(ev_bits[0] & (1UL << EV_KEY)) != 0) {
|
||||
fds.push_back(fd);
|
||||
} else {
|
||||
::close(fd);
|
||||
}
|
||||
}
|
||||
::closedir(dir);
|
||||
return fds;
|
||||
}
|
||||
|
||||
int run_device_loop(cz::UiController& ctrl, cz::AppView& view) {
|
||||
const char* fb_dev = std::getenv("CZCAMERA_FB_DEVICE");
|
||||
if (fb_dev == nullptr || fb_dev[0] == '\0') {
|
||||
fb_dev = "/dev/fb0";
|
||||
}
|
||||
const int fb_fd = ::open(fb_dev, O_RDWR);
|
||||
if (fb_fd < 0) {
|
||||
std::cerr << "Failed to open framebuffer " << fb_dev << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
fb_var_screeninfo vinfo{};
|
||||
fb_fix_screeninfo finfo{};
|
||||
if (::ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ||
|
||||
::ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
|
||||
std::cerr << "Failed to query framebuffer info\n";
|
||||
::close(fb_fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const size_t map_size = finfo.smem_len;
|
||||
if (map_size == 0) {
|
||||
std::cerr << "Framebuffer reports zero memory length\n";
|
||||
::close(fb_fd);
|
||||
return 1;
|
||||
}
|
||||
void* mapped = ::mmap(nullptr, map_size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
fb_fd, 0);
|
||||
if (mapped == MAP_FAILED) {
|
||||
std::cerr << "Failed to mmap framebuffer\n";
|
||||
::close(fb_fd);
|
||||
return 1;
|
||||
}
|
||||
auto* fb_mem = static_cast<uint8_t*>(mapped);
|
||||
|
||||
std::vector<int> ev_fds = open_keyboard_evdevs();
|
||||
std::vector<pollfd> pfds;
|
||||
pfds.reserve(ev_fds.size());
|
||||
for (int fd : ev_fds) {
|
||||
pfds.push_back(pollfd{fd, POLLIN, 0});
|
||||
}
|
||||
|
||||
cz::PreviewFrame live_frame;
|
||||
uint64_t last_live_seq = 0;
|
||||
uint64_t last_gal_seq = 0;
|
||||
double last_vp_pos = -1.0;
|
||||
bool last_vp_playing = false;
|
||||
|
||||
view.apply_theme(ctrl.state().theme);
|
||||
if (ctrl.backend()) {
|
||||
if (ctrl.backend()->copy_latest_preview(last_live_seq, live_frame)) {
|
||||
last_live_seq = live_frame.seq;
|
||||
}
|
||||
}
|
||||
view.render(ctrl.state(), &live_frame, ctrl.gallery_preview());
|
||||
blit_fbdev(fb_mem, map_size, vinfo, finfo, view.pixels());
|
||||
|
||||
bool shift_down = false;
|
||||
bool prev_flash = ctrl.state().capture_flash_active;
|
||||
bool prev_dimmed = ctrl.state().timelapse_dimmed;
|
||||
int prev_tl_shots = ctrl.state().timelapse.shots_taken;
|
||||
int prev_tl_next = ctrl.state().timelapse.next_shot_in_sec;
|
||||
int prev_tl_elapsed = ctrl.state().timelapse.elapsed_sec;
|
||||
int prev_vid_sec = ctrl.state().video_elapsed_sec;
|
||||
int prev_timer_sec = ctrl.state().timer_remaining_sec;
|
||||
int prev_comp_cur = ctrl.state().timelapse.compile_current;
|
||||
std::string prev_toast = ctrl.state().toast_message;
|
||||
cz::OverlayModal prev_modal = ctrl.state().modal;
|
||||
|
||||
while (!ctrl.should_quit() && !g_signal_stop) {
|
||||
bool dirty = false;
|
||||
if (!pfds.empty()) {
|
||||
const int prc = ::poll(pfds.data(), static_cast<nfds_t>(pfds.size()), 16);
|
||||
if (prc < 0) {
|
||||
if (errno != EINTR) {
|
||||
::usleep(16000);
|
||||
}
|
||||
} else if (prc > 0) {
|
||||
std::vector<size_t> dead_indices;
|
||||
for (size_t idx = 0;
|
||||
idx < pfds.size() && !ctrl.should_quit() && !g_signal_stop; ++idx) {
|
||||
const auto& p = pfds[idx];
|
||||
bool remove_fd = (p.revents & (POLLERR | POLLHUP | POLLNVAL)) != 0;
|
||||
if ((p.revents & POLLIN) != 0) {
|
||||
while (!ctrl.should_quit() && !g_signal_stop) {
|
||||
struct input_event ev {};
|
||||
const ssize_t n = ::read(p.fd, &ev, sizeof(ev));
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) break;
|
||||
remove_fd = true;
|
||||
break;
|
||||
}
|
||||
if (n == 0) {
|
||||
remove_fd = true;
|
||||
break;
|
||||
}
|
||||
if (n != static_cast<ssize_t>(sizeof(ev))) {
|
||||
break;
|
||||
}
|
||||
if (ev.type != EV_KEY) {
|
||||
continue;
|
||||
}
|
||||
if (ev.code == KEY_LEFTSHIFT || ev.code == KEY_RIGHTSHIFT) {
|
||||
shift_down = (ev.value != 0);
|
||||
continue;
|
||||
}
|
||||
if (ev.value != 1 && ev.value != 2) {
|
||||
continue;
|
||||
}
|
||||
const uint64_t now = steady_now_ms();
|
||||
bool handled = false;
|
||||
switch (ev.code) {
|
||||
case KEY_UP:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Up, now);
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Down, now);
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Left, now);
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Right, now);
|
||||
break;
|
||||
case KEY_ENTER:
|
||||
case KEY_KPENTER:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
break;
|
||||
case KEY_ESC:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
break;
|
||||
case KEY_BACKSPACE:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Backspace, now);
|
||||
break;
|
||||
case KEY_DELETE:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Delete, now);
|
||||
break;
|
||||
case KEY_SPACE:
|
||||
handled = ctrl.handle_key(' ', cz::KeyCode::Space, now);
|
||||
break;
|
||||
default: {
|
||||
const char c = map_evdev_code(ev.code, shift_down);
|
||||
if (c != 0) {
|
||||
handled = ctrl.handle_key(c, cz::KeyCode::Char, now);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (handled) {
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (remove_fd) {
|
||||
::close(p.fd);
|
||||
dead_indices.push_back(idx);
|
||||
}
|
||||
}
|
||||
for (auto it = dead_indices.rbegin(); it != dead_indices.rend(); ++it) {
|
||||
pfds.erase(pfds.begin() + static_cast<std::ptrdiff_t>(*it));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
::usleep(16000);
|
||||
}
|
||||
|
||||
if (ctrl.should_quit() || g_signal_stop) {
|
||||
break;
|
||||
}
|
||||
|
||||
const uint64_t now = steady_now_ms();
|
||||
ctrl.tick(now);
|
||||
|
||||
if (ctrl.backend() && ctrl.state().modal != cz::OverlayModal::Gallery) {
|
||||
if (ctrl.backend()->copy_latest_preview(last_live_seq, live_frame)) {
|
||||
last_live_seq = live_frame.seq;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
const cz::PreviewFrame* gp = ctrl.gallery_preview();
|
||||
const uint64_t gal_seq = gp ? gp->seq : 0;
|
||||
const auto& st = ctrl.state();
|
||||
if (gal_seq != last_gal_seq || st.video_player.position_sec != last_vp_pos ||
|
||||
st.video_player.playing != last_vp_playing ||
|
||||
st.capture_flash_active != prev_flash ||
|
||||
st.timelapse_dimmed != prev_dimmed ||
|
||||
st.timelapse.shots_taken != prev_tl_shots ||
|
||||
st.timelapse.next_shot_in_sec != prev_tl_next ||
|
||||
st.timelapse.elapsed_sec != prev_tl_elapsed ||
|
||||
st.video_elapsed_sec != prev_vid_sec ||
|
||||
st.timer_remaining_sec != prev_timer_sec ||
|
||||
st.timelapse.compile_current != prev_comp_cur ||
|
||||
st.toast_message != prev_toast || st.modal != prev_modal) {
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (dirty) {
|
||||
last_gal_seq = gal_seq;
|
||||
last_vp_pos = st.video_player.position_sec;
|
||||
last_vp_playing = st.video_player.playing;
|
||||
prev_flash = st.capture_flash_active;
|
||||
prev_dimmed = st.timelapse_dimmed;
|
||||
prev_tl_shots = st.timelapse.shots_taken;
|
||||
prev_tl_next = st.timelapse.next_shot_in_sec;
|
||||
prev_tl_elapsed = st.timelapse.elapsed_sec;
|
||||
prev_vid_sec = st.video_elapsed_sec;
|
||||
prev_timer_sec = st.timer_remaining_sec;
|
||||
prev_comp_cur = st.timelapse.compile_current;
|
||||
prev_toast = st.toast_message;
|
||||
prev_modal = st.modal;
|
||||
|
||||
view.render(st, &live_frame, gp);
|
||||
blit_fbdev(fb_mem, map_size, vinfo, finfo, view.pixels());
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& p : pfds) {
|
||||
::close(p.fd);
|
||||
}
|
||||
::munmap(mapped, map_size);
|
||||
::close(fb_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int run_sdl_loop(cz::UiController& ctrl, cz::AppView& view, int scale) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
|
||||
std::cerr << "SDL_Init failed: " << SDL_GetError() << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_AudioDeviceID audio_dev = 0;
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) == 0) {
|
||||
SDL_AudioSpec want{};
|
||||
SDL_AudioSpec have{};
|
||||
want.freq = 44100;
|
||||
want.format = AUDIO_S16SYS;
|
||||
want.channels = 1;
|
||||
want.samples = 1024;
|
||||
audio_dev = SDL_OpenAudioDevice(nullptr, 0, &want, &have, 0);
|
||||
if (audio_dev != 0) {
|
||||
SDL_PauseAudioDevice(audio_dev, 0);
|
||||
ctrl.video_player().set_pcm_sink(
|
||||
[audio_dev](const int16_t* samples, size_t count) {
|
||||
if (samples != nullptr && count > 0) {
|
||||
SDL_QueueAudio(audio_dev, samples,
|
||||
static_cast<Uint32>(count * sizeof(int16_t)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Window* window = SDL_CreateWindow(
|
||||
"czcamera", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
cz::AppView::kWidth * scale, cz::AppView::kHeight * scale,
|
||||
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
|
||||
if (window == nullptr) {
|
||||
std::cerr << "SDL_CreateWindow failed: " << SDL_GetError() << "\n";
|
||||
ctrl.video_player().set_pcm_sink(nullptr);
|
||||
if (audio_dev != 0) SDL_CloseAudioDevice(audio_dev);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Renderer* renderer = SDL_CreateRenderer(
|
||||
window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (renderer == nullptr) {
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
}
|
||||
if (renderer == nullptr) {
|
||||
std::cerr << "SDL_CreateRenderer failed: " << SDL_GetError() << "\n";
|
||||
SDL_DestroyWindow(window);
|
||||
ctrl.video_player().set_pcm_sink(nullptr);
|
||||
if (audio_dev != 0) SDL_CloseAudioDevice(audio_dev);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_RenderSetLogicalSize(renderer, cz::AppView::kWidth,
|
||||
cz::AppView::kHeight);
|
||||
SDL_Texture* texture = SDL_CreateTexture(
|
||||
renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING,
|
||||
cz::AppView::kWidth, cz::AppView::kHeight);
|
||||
if (texture == nullptr) {
|
||||
std::cerr << "SDL_CreateTexture failed: " << SDL_GetError() << "\n";
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
ctrl.video_player().set_pcm_sink(nullptr);
|
||||
if (audio_dev != 0) SDL_CloseAudioDevice(audio_dev);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_StartTextInput();
|
||||
|
||||
cz::PreviewFrame live_frame;
|
||||
uint64_t last_live_seq = 0;
|
||||
uint64_t last_gal_seq = 0;
|
||||
double last_vp_pos = -1.0;
|
||||
bool last_vp_playing = false;
|
||||
|
||||
view.apply_theme(ctrl.state().theme);
|
||||
if (ctrl.backend()) {
|
||||
if (ctrl.backend()->copy_latest_preview(last_live_seq, live_frame)) {
|
||||
last_live_seq = live_frame.seq;
|
||||
}
|
||||
}
|
||||
view.render(ctrl.state(), &live_frame, ctrl.gallery_preview());
|
||||
|
||||
auto present = [&]() {
|
||||
SDL_UpdateTexture(texture, nullptr, view.pixels(),
|
||||
cz::AppView::kWidth * static_cast<int>(sizeof(uint32_t)));
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
||||
SDL_RenderPresent(renderer);
|
||||
};
|
||||
present();
|
||||
|
||||
bool running = true;
|
||||
bool prev_flash = ctrl.state().capture_flash_active;
|
||||
bool prev_dimmed = ctrl.state().timelapse_dimmed;
|
||||
int prev_tl_shots = ctrl.state().timelapse.shots_taken;
|
||||
int prev_tl_next = ctrl.state().timelapse.next_shot_in_sec;
|
||||
int prev_tl_elapsed = ctrl.state().timelapse.elapsed_sec;
|
||||
int prev_vid_sec = ctrl.state().video_elapsed_sec;
|
||||
int prev_timer_sec = ctrl.state().timer_remaining_sec;
|
||||
int prev_comp_cur = ctrl.state().timelapse.compile_current;
|
||||
std::string prev_toast = ctrl.state().toast_message;
|
||||
cz::OverlayModal prev_modal = ctrl.state().modal;
|
||||
|
||||
while (running && !ctrl.should_quit() && !g_signal_stop) {
|
||||
bool dirty = false;
|
||||
SDL_Event ev;
|
||||
if (SDL_WaitEventTimeout(&ev, 16) != 0) {
|
||||
do {
|
||||
if (ev.type == SDL_QUIT) {
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
if (ev.type == SDL_WINDOWEVENT &&
|
||||
(ev.window.event == SDL_WINDOWEVENT_EXPOSED ||
|
||||
ev.window.event == SDL_WINDOWEVENT_RESIZED)) {
|
||||
dirty = true;
|
||||
continue;
|
||||
}
|
||||
if (ev.type == SDL_TEXTINPUT) {
|
||||
const uint64_t now = steady_now_ms();
|
||||
for (int i = 0;
|
||||
running && !ctrl.should_quit() && !g_signal_stop &&
|
||||
ev.text.text[i] != '\0';
|
||||
++i) {
|
||||
if (ctrl.handle_key(ev.text.text[i], cz::KeyCode::Char, now)) {
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (ev.type == SDL_KEYDOWN) {
|
||||
const SDL_Keycode sym = ev.key.keysym.sym;
|
||||
const uint16_t mod = ev.key.keysym.mod;
|
||||
if ((mod & (KMOD_CTRL | KMOD_GUI)) != 0 && sym == SDLK_q) {
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
const uint64_t now = steady_now_ms();
|
||||
bool handled = false;
|
||||
switch (sym) {
|
||||
case SDLK_UP:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Up, now);
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Down, now);
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Left, now);
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Right, now);
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
case SDLK_KP_ENTER:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
break;
|
||||
case SDLK_ESCAPE:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Backspace, now);
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
handled = ctrl.handle_key(0, cz::KeyCode::Delete, now);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (handled) {
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
} while (running && !ctrl.should_quit() && SDL_PollEvent(&ev) != 0);
|
||||
}
|
||||
|
||||
if (!running || ctrl.should_quit() || g_signal_stop) {
|
||||
break;
|
||||
}
|
||||
|
||||
const uint64_t now = steady_now_ms();
|
||||
ctrl.tick(now);
|
||||
|
||||
if (ctrl.backend() && ctrl.state().modal != cz::OverlayModal::Gallery) {
|
||||
if (ctrl.backend()->copy_latest_preview(last_live_seq, live_frame)) {
|
||||
last_live_seq = live_frame.seq;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
const auto& st = ctrl.state();
|
||||
if (audio_dev != 0) {
|
||||
if ((!st.video_player.playing && last_vp_playing) ||
|
||||
(st.video_player.playing &&
|
||||
std::abs(st.video_player.position_sec - last_vp_pos) > 0.45)) {
|
||||
SDL_ClearQueuedAudio(audio_dev);
|
||||
}
|
||||
}
|
||||
|
||||
const cz::PreviewFrame* gp = ctrl.gallery_preview();
|
||||
const uint64_t gal_seq = gp ? gp->seq : 0;
|
||||
if (gal_seq != last_gal_seq || st.video_player.position_sec != last_vp_pos ||
|
||||
st.video_player.playing != last_vp_playing ||
|
||||
st.capture_flash_active != prev_flash ||
|
||||
st.timelapse_dimmed != prev_dimmed ||
|
||||
st.timelapse.shots_taken != prev_tl_shots ||
|
||||
st.timelapse.next_shot_in_sec != prev_tl_next ||
|
||||
st.timelapse.elapsed_sec != prev_tl_elapsed ||
|
||||
st.video_elapsed_sec != prev_vid_sec ||
|
||||
st.timer_remaining_sec != prev_timer_sec ||
|
||||
st.timelapse.compile_current != prev_comp_cur ||
|
||||
st.toast_message != prev_toast || st.modal != prev_modal) {
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if (dirty) {
|
||||
last_gal_seq = gal_seq;
|
||||
last_vp_pos = st.video_player.position_sec;
|
||||
last_vp_playing = st.video_player.playing;
|
||||
prev_flash = st.capture_flash_active;
|
||||
prev_dimmed = st.timelapse_dimmed;
|
||||
prev_tl_shots = st.timelapse.shots_taken;
|
||||
prev_tl_next = st.timelapse.next_shot_in_sec;
|
||||
prev_tl_elapsed = st.timelapse.elapsed_sec;
|
||||
prev_vid_sec = st.video_elapsed_sec;
|
||||
prev_timer_sec = st.timer_remaining_sec;
|
||||
prev_comp_cur = st.timelapse.compile_current;
|
||||
prev_toast = st.toast_message;
|
||||
prev_modal = st.modal;
|
||||
|
||||
view.render(st, &live_frame, gp);
|
||||
present();
|
||||
}
|
||||
}
|
||||
|
||||
ctrl.video_player().set_pcm_sink(nullptr);
|
||||
ctrl.shutdown();
|
||||
if (audio_dev != 0) {
|
||||
SDL_CloseAudioDevice(audio_dev);
|
||||
}
|
||||
SDL_StopTextInput();
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::signal(SIGINT, handle_signal);
|
||||
std::signal(SIGTERM, handle_signal);
|
||||
|
||||
CliOptions cli;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
const std::string arg = argv[i];
|
||||
if (arg == "--help" || arg == "-h") {
|
||||
print_usage(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
if (arg == "--sim") {
|
||||
continue;
|
||||
}
|
||||
if (arg == "--mock-cam") {
|
||||
cli.mock_cam = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "--scale" && i + 1 < argc) {
|
||||
const int parsed = std::atoi(argv[++i]);
|
||||
if (parsed < 1 || parsed > 4) {
|
||||
std::cerr << "Invalid --scale value (expected 1..4)\n";
|
||||
return 2;
|
||||
}
|
||||
cli.scale = parsed;
|
||||
continue;
|
||||
}
|
||||
if (arg == "--output-dir" && i + 1 < argc) {
|
||||
cli.output_dir = argv[++i];
|
||||
continue;
|
||||
}
|
||||
if (arg == "--render-test" && i + 1 < argc) {
|
||||
cli.render_test_path = argv[++i];
|
||||
continue;
|
||||
}
|
||||
if (arg == "--theme" && i + 1 < argc) {
|
||||
cli.theme_override = argv[++i];
|
||||
if (cli.theme_override != "dark" && cli.theme_override != "light") {
|
||||
std::cerr << "Invalid --theme value: " << cli.theme_override << "\n";
|
||||
return 2;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (arg == "--mode" && i + 1 < argc) {
|
||||
cli.mode_override = argv[++i];
|
||||
if (cli.mode_override != "photo" && cli.mode_override != "video" &&
|
||||
cli.mode_override != "timelapse" && cli.mode_override != "gallery" &&
|
||||
cli.mode_override != "settings") {
|
||||
std::cerr << "Invalid --mode value: " << cli.mode_override << "\n";
|
||||
return 2;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (arg == "--rail" && i + 1 < argc) {
|
||||
cli.rail_override = argv[++i];
|
||||
if (cli.rail_override != "right" && cli.rail_override != "left") {
|
||||
std::cerr << "Invalid --rail value: " << cli.rail_override << "\n";
|
||||
return 2;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
std::cerr << "Unknown or incomplete option: " << arg << "\n";
|
||||
print_usage(argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (!cli.render_test_path.empty()) {
|
||||
return run_render_test(cli);
|
||||
}
|
||||
|
||||
cz::UiControllerOptions opts;
|
||||
opts.output_dir_override = cli.output_dir;
|
||||
opts.mock_backend = cli.mock_cam;
|
||||
|
||||
cz::UiController ctrl(nullptr, opts);
|
||||
const uint64_t now = steady_now_ms();
|
||||
ctrl.init(now);
|
||||
|
||||
if (!cli.theme_override.empty()) {
|
||||
const cz::ThemeMode target_theme = cz::theme_from_string(cli.theme_override);
|
||||
if (ctrl.state().theme != target_theme) {
|
||||
ctrl.handle_key('t', cz::KeyCode::Char, now);
|
||||
}
|
||||
}
|
||||
if (!cli.rail_override.empty() &&
|
||||
ctrl.state().config.rail_side != cli.rail_override) {
|
||||
ctrl.handle_key('w', cz::KeyCode::Char, now);
|
||||
}
|
||||
if (cli.mode_override == "video") {
|
||||
ctrl.handle_key('2', cz::KeyCode::Char, now);
|
||||
} else if (cli.mode_override == "timelapse") {
|
||||
ctrl.handle_key('3', cz::KeyCode::Char, now);
|
||||
} else if (cli.mode_override == "gallery") {
|
||||
ctrl.handle_key('8', cz::KeyCode::Char, now);
|
||||
} else if (cli.mode_override == "settings") {
|
||||
ctrl.handle_key('s', cz::KeyCode::Char, now);
|
||||
}
|
||||
|
||||
cz::AppView view;
|
||||
#if defined(CZ_TARGET_DEVICE) && defined(__linux__)
|
||||
(void)cli.scale;
|
||||
const int rc = run_device_loop(ctrl, view);
|
||||
ctrl.shutdown();
|
||||
return rc;
|
||||
#else
|
||||
return run_sdl_loop(ctrl, view, cli.scale);
|
||||
#endif
|
||||
}
|
||||
1959
app/src/ui_controller.cpp
Normal file
1959
app/src/ui_controller.cpp
Normal file
File diff suppressed because it is too large
Load Diff
248
app/src/ui_controller.hpp
Normal file
248
app/src/ui_controller.hpp
Normal file
@@ -0,0 +1,248 @@
|
||||
#pragma once
|
||||
|
||||
#include "backlight.hpp"
|
||||
#include "camera_backend.hpp"
|
||||
#include "config.hpp"
|
||||
#include "filters.hpp"
|
||||
#include "gallery_model.hpp"
|
||||
#include "theme.hpp"
|
||||
#include "timelapse_engine.hpp"
|
||||
#include "video_player.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace cz {
|
||||
|
||||
enum class KeyCode {
|
||||
Char,
|
||||
Enter,
|
||||
Space,
|
||||
Backspace,
|
||||
Delete,
|
||||
Esc,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
};
|
||||
|
||||
enum class AppMode {
|
||||
Photo = 0,
|
||||
Video = 1,
|
||||
Timelapse = 2,
|
||||
};
|
||||
|
||||
enum class OverlayModal {
|
||||
None,
|
||||
Gallery,
|
||||
Settings,
|
||||
DirPicker,
|
||||
TextInput,
|
||||
TimelapseCustomInput,
|
||||
TimelapseRecovery,
|
||||
TimelapseStopConfirm,
|
||||
TimelapseCompiling,
|
||||
};
|
||||
|
||||
struct UiControllerOptions {
|
||||
std::string config_path;
|
||||
std::string output_dir_override;
|
||||
std::string backlight_sysfs_root = "/sys/class/backlight";
|
||||
bool mock_backend = false;
|
||||
bool persist_config = true;
|
||||
bool skip_startup_recovery_scan = false;
|
||||
};
|
||||
|
||||
struct UiState {
|
||||
AppMode mode = AppMode::Photo;
|
||||
OverlayModal modal = OverlayModal::None;
|
||||
ThemeMode theme = ThemeMode::Dark;
|
||||
AppConfig config;
|
||||
std::string effective_output_dir;
|
||||
|
||||
// Rail & camera live controls
|
||||
int rail_cursor = 1; // 0..3
|
||||
float zoom = 1.0f;
|
||||
bool loupe_enabled = false;
|
||||
FilterId filter = FilterId::None;
|
||||
|
||||
// Photo countdown & flash
|
||||
bool timer_active = false;
|
||||
int timer_remaining_sec = 0;
|
||||
bool capture_flash_active = false;
|
||||
|
||||
// Video recording
|
||||
bool video_recording = false;
|
||||
int video_elapsed_sec = 0;
|
||||
|
||||
// Timelapse runtime & dimming
|
||||
TimelapseState timelapse;
|
||||
bool timelapse_dimmed = false;
|
||||
bool has_hardware_backlight = false;
|
||||
|
||||
// Timelapse custom input modal
|
||||
int tl_custom_cursor = 0; // 0: interval, 1: fps, 2: stop_mode, 3: stop_value
|
||||
int tl_custom_interval_sec = 5;
|
||||
int tl_custom_fps = 24;
|
||||
std::string tl_custom_stop_mode = "manual";
|
||||
int tl_custom_stop_value = 0;
|
||||
std::string tl_custom_text;
|
||||
|
||||
// Timelapse orphan recovery modal
|
||||
TimelapseManifest recovery_manifest;
|
||||
int recovery_remaining = 0;
|
||||
|
||||
// Settings modal
|
||||
int settings_cursor = 0; // 0..5
|
||||
|
||||
// Directory picker & manual path input
|
||||
std::string dir_current_path;
|
||||
std::vector<std::string> dir_entries;
|
||||
int dir_cursor = -1;
|
||||
std::string text_buffer;
|
||||
std::string modal_error;
|
||||
|
||||
// Gallery modal
|
||||
std::vector<GalleryItem> gallery_items;
|
||||
int gallery_cursor = 0;
|
||||
bool gallery_in_session = false;
|
||||
std::string gallery_session_name;
|
||||
bool gallery_delete_confirm = false;
|
||||
VideoPlayerState video_player;
|
||||
|
||||
// Status / storage / toast
|
||||
uint64_t free_bytes = 0;
|
||||
bool backend_ready = false;
|
||||
bool backend_paused = false;
|
||||
std::string backend_error;
|
||||
std::string toast_message;
|
||||
bool toast_is_error = false;
|
||||
};
|
||||
|
||||
class UiController {
|
||||
public:
|
||||
explicit UiController(std::unique_ptr<ICameraBackend> backend = nullptr,
|
||||
const UiControllerOptions& opts = UiControllerOptions{});
|
||||
~UiController();
|
||||
|
||||
UiController(const UiController&) = delete;
|
||||
UiController& operator=(const UiController&) = delete;
|
||||
|
||||
bool init(uint64_t now_ms);
|
||||
void shutdown();
|
||||
|
||||
void tick(uint64_t now_ms);
|
||||
bool handle_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
|
||||
const UiState& state() const { return state_; }
|
||||
bool should_quit() const { return quit_; }
|
||||
bool consume_capture_flash();
|
||||
|
||||
ICameraBackend* backend() { return backend_.get(); }
|
||||
const BacklightController& backlight() const { return backlight_; }
|
||||
BacklightController& backlight() { return backlight_; }
|
||||
VideoPlayer& video_player() { return video_player_; }
|
||||
const PreviewFrame* gallery_preview() const {
|
||||
return has_gallery_preview_ ? &gallery_frame_ : nullptr;
|
||||
}
|
||||
|
||||
void set_toast(const std::string& message, bool is_error, uint64_t now_ms);
|
||||
void refresh_storage_stats();
|
||||
|
||||
private:
|
||||
CameraStreamSpec build_stream_spec() const;
|
||||
AppConfig effective_engine_config() const;
|
||||
void persist_config();
|
||||
bool reconfigure_backend(std::string& out_err);
|
||||
void sync_backend_status();
|
||||
|
||||
void switch_mode(AppMode target);
|
||||
void adjust_zoom(int delta_step);
|
||||
void adjust_ev(int delta_step);
|
||||
void adjust_rail_setting(int delta);
|
||||
void trigger_photo_shutter(uint64_t now_ms);
|
||||
void capture_photo_now(uint64_t now_ms);
|
||||
|
||||
void start_video_recording(uint64_t now_ms);
|
||||
void stop_video_recording(bool low_storage, uint64_t now_ms);
|
||||
|
||||
void start_timelapse(uint64_t now_ms);
|
||||
void start_compile_async(const TimelapseSessionPaths& paths,
|
||||
int fps,
|
||||
const std::string& resolution,
|
||||
const TimelapseManifest& fallback_manifest,
|
||||
bool from_recovery);
|
||||
void join_compile_thread();
|
||||
void finish_compile_if_ready(uint64_t now_ms);
|
||||
void advance_recovery_queue();
|
||||
|
||||
void open_gallery(uint64_t now_ms);
|
||||
void close_gallery(bool resume_camera);
|
||||
void load_current_gallery_preview();
|
||||
|
||||
void open_settings();
|
||||
void apply_settings_row(int delta);
|
||||
void open_dir_picker();
|
||||
void load_directory(const std::string& path, const std::string& select_name = "");
|
||||
void open_text_input();
|
||||
void open_timelapse_custom_input();
|
||||
|
||||
bool handle_none_modal_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
bool handle_gallery_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
bool handle_settings_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
bool handle_dir_picker_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
bool handle_text_input_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
bool handle_tl_custom_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
bool handle_tl_recovery_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
bool handle_tl_stop_confirm_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
bool handle_tl_compiling_key(char ch, KeyCode code, uint64_t now_ms);
|
||||
|
||||
UiControllerOptions opts_;
|
||||
std::unique_ptr<ICameraBackend> backend_;
|
||||
BacklightController backlight_;
|
||||
TimelapseEngine timelapse_engine_;
|
||||
GalleryStore gallery_store_;
|
||||
VideoPlayer video_player_;
|
||||
|
||||
UiState state_;
|
||||
std::string persisted_output_dir_;
|
||||
bool output_dir_override_active_ = false;
|
||||
bool initialized_ = false;
|
||||
bool quit_ = false;
|
||||
bool capture_flash_pending_ = false;
|
||||
|
||||
uint64_t last_activity_ms_ = 0;
|
||||
uint64_t timer_target_ms_ = 0;
|
||||
uint64_t flash_until_ms_ = 0;
|
||||
uint64_t toast_until_ms_ = 0;
|
||||
|
||||
uint64_t video_start_ms_ = 0;
|
||||
uint64_t last_storage_check_ms_ = 0;
|
||||
std::string video_tmp_path_;
|
||||
std::string video_final_path_;
|
||||
bool warned_audio_ = false;
|
||||
|
||||
PreviewFrame gallery_frame_;
|
||||
bool has_gallery_preview_ = false;
|
||||
bool gallery_muted_ = false;
|
||||
|
||||
std::vector<TimelapseManifest> orphaned_timelapses_;
|
||||
|
||||
std::thread compile_thread_;
|
||||
std::atomic<bool> compile_in_flight_{false};
|
||||
std::atomic<bool> compile_finished_{false};
|
||||
std::mutex compile_result_mutex_;
|
||||
bool compile_ok_ = false;
|
||||
bool compile_cancelled_by_user_ = false;
|
||||
bool compile_from_recovery_ = false;
|
||||
std::string compile_result_msg_;
|
||||
TimelapseManifest compile_fallback_manifest_;
|
||||
};
|
||||
|
||||
} // namespace cz
|
||||
770
app/tests/test_ui_controller.cpp
Normal file
770
app/tests/test_ui_controller.cpp
Normal file
@@ -0,0 +1,770 @@
|
||||
#include "app_ui.hpp"
|
||||
#include "config.hpp"
|
||||
#include "sim_backend.hpp"
|
||||
#include "storage.hpp"
|
||||
#include "ui_controller.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
struct TempDir {
|
||||
std::string path;
|
||||
explicit TempDir(const std::string& name) {
|
||||
const std::string base =
|
||||
"/tmp/czcamera_test_t6_" + name + "_" + std::to_string(::getpid());
|
||||
std::error_code ec;
|
||||
fs::remove_all(base, ec);
|
||||
fs::create_directories(base, ec);
|
||||
assert(!ec);
|
||||
path = base;
|
||||
}
|
||||
~TempDir() {
|
||||
std::error_code ec;
|
||||
fs::remove_all(path, ec);
|
||||
}
|
||||
};
|
||||
|
||||
void write_text(const std::string& path, const std::string& content) {
|
||||
std::ofstream out(path, std::ios::binary | std::ios::trunc);
|
||||
assert(out.is_open());
|
||||
out.write(content.data(), static_cast<std::streamsize>(content.size()));
|
||||
out.close();
|
||||
assert(out.good());
|
||||
}
|
||||
|
||||
std::string read_text(const std::string& path) {
|
||||
std::ifstream in(path, std::ios::binary);
|
||||
assert(in.is_open());
|
||||
return std::string((std::istreambuf_iterator<char>(in)),
|
||||
std::istreambuf_iterator<char>());
|
||||
}
|
||||
|
||||
int count_files_with_ext(const std::string& dir, const std::string& ext) {
|
||||
int count = 0;
|
||||
std::error_code ec;
|
||||
for (const auto& entry : fs::directory_iterator(dir, ec)) {
|
||||
if (!entry.is_regular_file(ec)) continue;
|
||||
const std::string name = entry.path().filename().string();
|
||||
if (name.empty() || name[0] == '.') continue;
|
||||
if (name.size() >= ext.size() &&
|
||||
name.compare(name.size() - ext.size(), ext.size(), ext) == 0) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int count_hidden_files(const std::string& dir) {
|
||||
int count = 0;
|
||||
std::error_code ec;
|
||||
for (const auto& entry : fs::directory_iterator(dir, ec)) {
|
||||
const std::string name = entry.path().filename().string();
|
||||
if (!name.empty() && name[0] == '.') {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
class SpyCameraBackend final : public cz::ICameraBackend {
|
||||
public:
|
||||
bool start(const cz::CameraStreamSpec& initial_spec,
|
||||
std::string& out_err) override {
|
||||
start_specs.push_back(initial_spec);
|
||||
last_zoom = initial_spec.zoom;
|
||||
last_ev = initial_spec.ev;
|
||||
return inner_.start(initial_spec, out_err);
|
||||
}
|
||||
|
||||
void stop() override { inner_.stop(); }
|
||||
|
||||
bool reconfigure(const cz::CameraStreamSpec& spec,
|
||||
std::string& out_err) override {
|
||||
reconfigure_specs.push_back(spec);
|
||||
last_zoom = spec.zoom;
|
||||
last_ev = spec.ev;
|
||||
return inner_.reconfigure(spec, out_err);
|
||||
}
|
||||
|
||||
bool set_controls(float zoom, float ev, std::string& out_err) override {
|
||||
last_zoom = zoom;
|
||||
last_ev = ev;
|
||||
++set_controls_calls;
|
||||
return inner_.set_controls(zoom, ev, out_err);
|
||||
}
|
||||
|
||||
bool pause(std::string& out_err) override {
|
||||
++pause_calls;
|
||||
return inner_.pause(out_err);
|
||||
}
|
||||
|
||||
bool resume(std::string& out_err) override {
|
||||
++resume_calls;
|
||||
return inner_.resume(out_err);
|
||||
}
|
||||
|
||||
bool copy_latest_preview(uint64_t last_seen_seq,
|
||||
cz::PreviewFrame& out_frame) override {
|
||||
return inner_.copy_latest_preview(last_seen_seq, out_frame);
|
||||
}
|
||||
|
||||
cz::StillCaptureResult capture_still(const std::string& tmp_jpeg_path,
|
||||
int width,
|
||||
int height) override {
|
||||
++capture_still_calls;
|
||||
return inner_.capture_still(tmp_jpeg_path, width, height);
|
||||
}
|
||||
|
||||
bool start_video(const cz::VideoSpec& spec, std::string& out_err) override {
|
||||
return inner_.start_video(spec, out_err);
|
||||
}
|
||||
|
||||
cz::VideoStopResult stop_video() override { return inner_.stop_video(); }
|
||||
|
||||
cz::BackendHealth status() const override { return inner_.status(); }
|
||||
|
||||
std::vector<cz::CameraStreamSpec> start_specs;
|
||||
std::vector<cz::CameraStreamSpec> reconfigure_specs;
|
||||
float last_zoom = 1.0f;
|
||||
float last_ev = 0.0f;
|
||||
int set_controls_calls = 0;
|
||||
int pause_calls = 0;
|
||||
int resume_calls = 0;
|
||||
int capture_still_calls = 0;
|
||||
|
||||
private:
|
||||
cz::SimCameraBackend inner_;
|
||||
};
|
||||
|
||||
void test_photo_controls_zoom_loupe_filters_and_timer() {
|
||||
TempDir tmp("photo");
|
||||
const std::string cfg_path = tmp.path + "/config.json";
|
||||
const std::string out_dir = tmp.path + "/out";
|
||||
assert(cz::mkdir_p(out_dir));
|
||||
|
||||
cz::AppConfig cfg;
|
||||
cfg.output_dir = out_dir;
|
||||
assert(cz::save_config(cfg, cfg_path));
|
||||
|
||||
auto spy_owned = std::make_unique<SpyCameraBackend>();
|
||||
SpyCameraBackend* spy = spy_owned.get();
|
||||
|
||||
cz::UiControllerOptions opts;
|
||||
opts.config_path = cfg_path;
|
||||
opts.backlight_sysfs_root = tmp.path + "/no_backlight";
|
||||
|
||||
cz::UiController ctrl(std::move(spy_owned), opts);
|
||||
uint64_t now = 1000;
|
||||
assert(ctrl.init(now));
|
||||
assert(ctrl.state().mode == cz::AppMode::Photo);
|
||||
assert(ctrl.state().zoom == 1.0f);
|
||||
assert(!ctrl.state().loupe_enabled);
|
||||
assert(ctrl.state().filter == cz::FilterId::None);
|
||||
assert(ctrl.state().config.photo_resolution == "8mp");
|
||||
assert(ctrl.state().config.photo_timer_sec == 0);
|
||||
|
||||
// Crop zoom 5/7 steps through 1.0 -> 1.5 -> 2.0 -> 3.0 -> 4.0 and back
|
||||
ctrl.handle_key('7', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 1.5f);
|
||||
assert(spy->last_zoom == 1.5f);
|
||||
ctrl.handle_key('7', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 2.0f);
|
||||
ctrl.handle_key('7', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 3.0f);
|
||||
ctrl.handle_key('7', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 4.0f);
|
||||
ctrl.handle_key('7', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 4.0f);
|
||||
|
||||
ctrl.handle_key('5', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 3.0f);
|
||||
ctrl.handle_key('5', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 2.0f);
|
||||
ctrl.handle_key('5', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 1.5f);
|
||||
ctrl.handle_key('5', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 1.0f);
|
||||
ctrl.handle_key('5', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 1.0f);
|
||||
|
||||
// Loupe L toggles 2x viewfinder magnification without changing sensor zoom
|
||||
ctrl.handle_key('7', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 1.5f);
|
||||
const int calls_before_loupe = spy->set_controls_calls;
|
||||
ctrl.handle_key('l', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().loupe_enabled);
|
||||
assert(ctrl.state().zoom == 1.5f);
|
||||
assert(spy->last_zoom == 1.5f);
|
||||
assert(spy->set_controls_calls == calls_before_loupe);
|
||||
ctrl.handle_key('L', cz::KeyCode::Char, now);
|
||||
assert(!ctrl.state().loupe_enabled);
|
||||
|
||||
// F cycles through all 9 filters and wraps back to None
|
||||
const cz::FilterId expected_filters[9] = {
|
||||
cz::FilterId::BW, cz::FilterId::HiCon, cz::FilterId::Sepia,
|
||||
cz::FilterId::Cool, cz::FilterId::Vivid, cz::FilterId::Invert,
|
||||
cz::FilterId::Retro, cz::FilterId::GameBoy, cz::FilterId::None,
|
||||
};
|
||||
for (cz::FilterId ef : expected_filters) {
|
||||
ctrl.handle_key('f', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().filter == ef);
|
||||
}
|
||||
|
||||
// R toggles 8MP <-> 2MP and reconfigures backend
|
||||
const size_t reconf_before = spy->reconfigure_specs.size();
|
||||
ctrl.handle_key('r', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().config.photo_resolution == "2mp");
|
||||
assert(spy->reconfigure_specs.size() == reconf_before + 1);
|
||||
assert(spy->reconfigure_specs.back().main_width == 1640);
|
||||
assert(spy->reconfigure_specs.back().main_height == 1232);
|
||||
ctrl.handle_key('R', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().config.photo_resolution == "8mp");
|
||||
assert(spy->reconfigure_specs.back().main_width == 3280);
|
||||
assert(spy->reconfigure_specs.back().main_height == 2464);
|
||||
|
||||
// C cycles Off -> 3s -> 10s -> Off; Esc cancels an active countdown
|
||||
ctrl.handle_key('c', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().config.photo_timer_sec == 3);
|
||||
ctrl.handle_key('c', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().config.photo_timer_sec == 10);
|
||||
ctrl.handle_key('c', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().config.photo_timer_sec == 0);
|
||||
|
||||
ctrl.handle_key('c', cz::KeyCode::Char, now); // 3s
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().timer_active);
|
||||
assert(ctrl.state().timer_remaining_sec == 3);
|
||||
now += 1500;
|
||||
ctrl.tick(now);
|
||||
assert(ctrl.state().timer_active);
|
||||
assert(ctrl.state().timer_remaining_sec == 2);
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
assert(!ctrl.state().timer_active);
|
||||
assert(!ctrl.should_quit());
|
||||
assert(count_files_with_ext(out_dir, ".jpg") == 0);
|
||||
|
||||
// Set timer back to Off, switch to Invert filter, and shoot via Enter and '6'
|
||||
ctrl.handle_key('c', cz::KeyCode::Char, now); // 10
|
||||
ctrl.handle_key('c', cz::KeyCode::Char, now); // 0
|
||||
assert(ctrl.state().config.photo_timer_sec == 0);
|
||||
ctrl.handle_key('f', cz::KeyCode::Char, now); // BW
|
||||
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.consume_capture_flash());
|
||||
assert(!ctrl.consume_capture_flash());
|
||||
assert(count_files_with_ext(out_dir, ".jpg") == 1);
|
||||
assert(count_hidden_files(out_dir) == 0);
|
||||
|
||||
now += 1000;
|
||||
ctrl.handle_key('6', cz::KeyCode::Char, now);
|
||||
assert(ctrl.consume_capture_flash());
|
||||
assert(count_files_with_ext(out_dir, ".jpg") == 2);
|
||||
assert(count_hidden_files(out_dir) == 0);
|
||||
}
|
||||
|
||||
void test_rail_side_and_theme_toggles_persist() {
|
||||
TempDir tmp("rail_theme");
|
||||
const std::string cfg_path = tmp.path + "/config.json";
|
||||
const std::string out_dir = tmp.path + "/out";
|
||||
assert(cz::mkdir_p(out_dir));
|
||||
|
||||
cz::AppConfig cfg;
|
||||
cfg.output_dir = out_dir;
|
||||
assert(cz::save_config(cfg, cfg_path));
|
||||
|
||||
cz::UiControllerOptions opts;
|
||||
opts.config_path = cfg_path;
|
||||
opts.backlight_sysfs_root = tmp.path + "/no_backlight";
|
||||
|
||||
cz::UiController ctrl(std::make_unique<cz::SimCameraBackend>(), opts);
|
||||
assert(ctrl.init(1000));
|
||||
assert(ctrl.state().config.rail_side == "right");
|
||||
assert(ctrl.state().theme == cz::ThemeMode::Dark);
|
||||
|
||||
ctrl.handle_key('w', cz::KeyCode::Char, 1010);
|
||||
assert(ctrl.state().config.rail_side == "left");
|
||||
assert(cz::load_config(cfg_path).rail_side == "left");
|
||||
|
||||
ctrl.handle_key('t', cz::KeyCode::Char, 1020);
|
||||
assert(ctrl.state().theme == cz::ThemeMode::Light);
|
||||
assert(ctrl.state().config.theme == "light");
|
||||
assert(cz::load_config(cfg_path).theme == "light");
|
||||
|
||||
// Render check: Dark+Right vs Light+Left must differ
|
||||
cz::PreviewFrame live;
|
||||
assert(ctrl.backend()->copy_latest_preview(0, live));
|
||||
|
||||
cz::AppView view;
|
||||
view.apply_theme(ctrl.state().theme);
|
||||
view.render(ctrl.state(), &live, nullptr);
|
||||
std::vector<uint32_t> light_left(
|
||||
view.pixels(),
|
||||
view.pixels() + cz::AppView::kWidth * cz::AppView::kHeight);
|
||||
|
||||
ctrl.handle_key('W', cz::KeyCode::Char, 1030);
|
||||
assert(ctrl.state().config.rail_side == "right");
|
||||
assert(cz::load_config(cfg_path).rail_side == "right");
|
||||
|
||||
ctrl.handle_key('T', cz::KeyCode::Char, 1040);
|
||||
assert(ctrl.state().theme == cz::ThemeMode::Dark);
|
||||
assert(cz::load_config(cfg_path).theme == "dark");
|
||||
|
||||
view.apply_theme(ctrl.state().theme);
|
||||
view.render(ctrl.state(), &live, nullptr);
|
||||
std::vector<uint32_t> dark_right(
|
||||
view.pixels(),
|
||||
view.pixels() + cz::AppView::kWidth * cz::AppView::kHeight);
|
||||
assert(light_left != dark_right);
|
||||
}
|
||||
|
||||
void test_video_mode_locks_transitions_while_recording() {
|
||||
TempDir tmp("video");
|
||||
const std::string cfg_path = tmp.path + "/config.json";
|
||||
const std::string out_dir = tmp.path + "/out";
|
||||
assert(cz::mkdir_p(out_dir));
|
||||
|
||||
cz::AppConfig cfg;
|
||||
cfg.output_dir = out_dir;
|
||||
assert(cz::save_config(cfg, cfg_path));
|
||||
|
||||
cz::UiControllerOptions opts;
|
||||
opts.config_path = cfg_path;
|
||||
opts.backlight_sysfs_root = tmp.path + "/no_backlight";
|
||||
|
||||
cz::UiController ctrl(std::make_unique<cz::SimCameraBackend>(), opts);
|
||||
uint64_t now = 1000;
|
||||
assert(ctrl.init(now));
|
||||
|
||||
ctrl.handle_key('2', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().mode == cz::AppMode::Video);
|
||||
assert(ctrl.state().config.video_audio);
|
||||
|
||||
ctrl.handle_key('m', cz::KeyCode::Char, now);
|
||||
assert(!ctrl.state().config.video_audio);
|
||||
ctrl.handle_key('M', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().config.video_audio);
|
||||
|
||||
// Start recording with Enter
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().video_recording);
|
||||
|
||||
// Locked keys while recording must be ignored cleanly
|
||||
const char locked_keys[] = {'1', '3', '8', 's', 'w', 'm', 'r', 't', 'q'};
|
||||
for (char ch : locked_keys) {
|
||||
ctrl.handle_key(ch, cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().mode == cz::AppMode::Video);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
assert(ctrl.state().config.rail_side == "right");
|
||||
assert(ctrl.state().config.video_audio);
|
||||
assert(ctrl.state().config.video_resolution == "720p");
|
||||
assert(ctrl.state().theme == cz::ThemeMode::Dark);
|
||||
assert(ctrl.state().video_recording);
|
||||
assert(!ctrl.should_quit());
|
||||
}
|
||||
|
||||
// Zoom 5/7 still works live during recording
|
||||
ctrl.handle_key('7', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().zoom == 1.5f);
|
||||
|
||||
now += 1500;
|
||||
ctrl.tick(now);
|
||||
assert(ctrl.state().video_elapsed_sec >= 1);
|
||||
|
||||
// Esc stops recording without quitting
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
assert(!ctrl.state().video_recording);
|
||||
assert(!ctrl.should_quit());
|
||||
assert(count_files_with_ext(out_dir, ".mp4") == 1);
|
||||
assert(count_hidden_files(out_dir) == 0);
|
||||
|
||||
// Enter also starts & stops recording cleanly
|
||||
now += 500;
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().video_recording);
|
||||
now += 500;
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(!ctrl.state().video_recording);
|
||||
assert(count_files_with_ext(out_dir, ".mp4") == 2);
|
||||
}
|
||||
|
||||
void test_timelapse_dimmed_safe_wake() {
|
||||
auto run_wake_case = [](const std::string& label,
|
||||
char wake_ch,
|
||||
cz::KeyCode wake_code,
|
||||
bool finish_with_stop_confirm) {
|
||||
TempDir tmp("tl_wake_" + label);
|
||||
const std::string cfg_path = tmp.path + "/config.json";
|
||||
const std::string out_dir = tmp.path + "/out";
|
||||
const std::string bl_root = tmp.path + "/backlight";
|
||||
const std::string lcd0 = bl_root + "/lcd0";
|
||||
assert(cz::mkdir_p(out_dir));
|
||||
assert(cz::mkdir_p(lcd0));
|
||||
write_text(lcd0 + "/brightness", "128\n");
|
||||
write_text(lcd0 + "/max_brightness", "255\n");
|
||||
|
||||
cz::AppConfig cfg;
|
||||
cfg.output_dir = out_dir;
|
||||
cfg.timelapse_dim_sec = 5;
|
||||
cfg.timelapse_interval_sec = 4;
|
||||
cfg.timelapse_output_mode = "video";
|
||||
cfg.timelapse_resolution = "2mp";
|
||||
assert(cz::save_config(cfg, cfg_path));
|
||||
|
||||
cz::UiControllerOptions opts;
|
||||
opts.config_path = cfg_path;
|
||||
opts.backlight_sysfs_root = bl_root;
|
||||
|
||||
cz::UiController ctrl(std::make_unique<cz::SimCameraBackend>(), opts);
|
||||
uint64_t now = 1000;
|
||||
assert(ctrl.init(now));
|
||||
assert(ctrl.backlight().has_hardware_backlight());
|
||||
|
||||
ctrl.handle_key('3', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().mode == cz::AppMode::Timelapse);
|
||||
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
ctrl.tick(now);
|
||||
assert(ctrl.state().timelapse.running);
|
||||
assert(ctrl.state().timelapse.shots_taken >= 1);
|
||||
assert(!ctrl.backlight().is_dimmed());
|
||||
|
||||
// Advance 6s (> 5s dim threshold)
|
||||
now += 6000;
|
||||
ctrl.tick(now);
|
||||
assert(ctrl.backlight().is_dimmed());
|
||||
assert(ctrl.state().timelapse_dimmed);
|
||||
assert(std::stoi(read_text(lcd0 + "/brightness")) == 0);
|
||||
|
||||
// First keypress while dimmed ONLY wakes backlight
|
||||
ctrl.handle_key(wake_ch, wake_code, now);
|
||||
assert(!ctrl.backlight().is_dimmed());
|
||||
assert(!ctrl.state().timelapse_dimmed);
|
||||
assert(std::stoi(read_text(lcd0 + "/brightness")) == 128);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
assert(ctrl.state().timelapse.running);
|
||||
assert(!ctrl.should_quit());
|
||||
|
||||
if (finish_with_stop_confirm) {
|
||||
// Pressing Esc while awake opens TimelapseStopConfirm
|
||||
now += 50;
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::TimelapseStopConfirm);
|
||||
assert(ctrl.state().timelapse.running);
|
||||
|
||||
// [N] resumes capture
|
||||
now += 50;
|
||||
ctrl.handle_key('n', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
assert(ctrl.state().timelapse.running);
|
||||
|
||||
// Esc again -> [Y] stops & compiles MP4
|
||||
now += 50;
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::TimelapseStopConfirm);
|
||||
now += 50;
|
||||
ctrl.handle_key('y', cz::KeyCode::Char, now);
|
||||
assert(!ctrl.state().timelapse.running);
|
||||
|
||||
const auto dl =
|
||||
std::chrono::steady_clock::now() + std::chrono::seconds(8);
|
||||
while (ctrl.state().modal == cz::OverlayModal::TimelapseCompiling &&
|
||||
std::chrono::steady_clock::now() < dl) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
now += 20;
|
||||
ctrl.tick(now);
|
||||
}
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
assert(!ctrl.state().timelapse.compiling);
|
||||
assert(count_files_with_ext(out_dir, ".mp4") == 1);
|
||||
assert(count_hidden_files(out_dir) == 0);
|
||||
} else {
|
||||
// Clean stop before teardown
|
||||
now += 50;
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
ctrl.handle_key('y', cz::KeyCode::Char, now);
|
||||
const auto dl =
|
||||
std::chrono::steady_clock::now() + std::chrono::seconds(8);
|
||||
while (ctrl.state().modal == cz::OverlayModal::TimelapseCompiling &&
|
||||
std::chrono::steady_clock::now() < dl) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
now += 20;
|
||||
ctrl.tick(now);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
run_wake_case("enter", 0, cz::KeyCode::Enter, false);
|
||||
run_wake_case("6", '6', cz::KeyCode::Char, false);
|
||||
run_wake_case("esc", 0, cz::KeyCode::Esc, false);
|
||||
run_wake_case("q", 'q', cz::KeyCode::Char, true);
|
||||
}
|
||||
|
||||
void test_settings_dir_picker_camera_orient_and_gallery_delete() {
|
||||
TempDir tmp("settings_gallery");
|
||||
const std::string cfg_path = tmp.path + "/config.json";
|
||||
const std::string out1 = tmp.path + "/out1";
|
||||
const std::string alt_parent = tmp.path + "/alt_dir";
|
||||
const std::string picked_sub = alt_parent + "/picked_sub";
|
||||
assert(cz::mkdir_p(out1));
|
||||
assert(cz::mkdir_p(picked_sub));
|
||||
|
||||
cz::AppConfig cfg;
|
||||
cfg.output_dir = out1;
|
||||
assert(cz::save_config(cfg, cfg_path));
|
||||
|
||||
auto spy_owned = std::make_unique<SpyCameraBackend>();
|
||||
SpyCameraBackend* spy = spy_owned.get();
|
||||
|
||||
cz::UiControllerOptions opts;
|
||||
opts.config_path = cfg_path;
|
||||
opts.backlight_sysfs_root = tmp.path + "/no_backlight";
|
||||
|
||||
cz::UiController ctrl(std::move(spy_owned), opts);
|
||||
uint64_t now = 1000;
|
||||
assert(ctrl.init(now));
|
||||
|
||||
// [S] opens Settings
|
||||
ctrl.handle_key('s', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::Settings);
|
||||
assert(ctrl.state().settings_cursor == 0);
|
||||
|
||||
// Navigate to Camera Orient (row 5) and cycle auto -> 0 -> 180 -> hflip -> vflip
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
ctrl.handle_key(0, cz::KeyCode::Down, now);
|
||||
}
|
||||
assert(ctrl.state().settings_cursor == 5);
|
||||
|
||||
const std::string expected_orients[] = {"0", "180", "hflip", "vflip", "auto"};
|
||||
for (const std::string& exp : expected_orients) {
|
||||
const size_t n_before = spy->reconfigure_specs.size();
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().config.camera_transform == exp);
|
||||
assert(spy->reconfigure_specs.size() == n_before + 1);
|
||||
assert(spy->reconfigure_specs.back().camera_transform == exp);
|
||||
}
|
||||
|
||||
// Navigate back to Output Dir (row 0) and open DirPicker
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
ctrl.handle_key(0, cz::KeyCode::Up, now);
|
||||
}
|
||||
assert(ctrl.state().settings_cursor == 0);
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::DirPicker);
|
||||
assert(ctrl.state().dir_current_path == fs::weakly_canonical(out1).string());
|
||||
|
||||
// Up to tmp.path, find alt_dir, Enter into alt_dir, select picked_sub with Space
|
||||
ctrl.handle_key(0, cz::KeyCode::Backspace, now);
|
||||
assert(ctrl.state().dir_current_path == fs::weakly_canonical(tmp.path).string());
|
||||
|
||||
int alt_idx = -1;
|
||||
for (size_t i = 0; i < ctrl.state().dir_entries.size(); ++i) {
|
||||
if (fs::path(ctrl.state().dir_entries[i]).filename().string() == "alt_dir") {
|
||||
alt_idx = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(alt_idx >= 0);
|
||||
while (ctrl.state().dir_cursor < alt_idx) {
|
||||
ctrl.handle_key(0, cz::KeyCode::Down, now);
|
||||
}
|
||||
while (ctrl.state().dir_cursor > alt_idx) {
|
||||
ctrl.handle_key(0, cz::KeyCode::Up, now);
|
||||
}
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().dir_current_path ==
|
||||
fs::weakly_canonical(alt_parent).string());
|
||||
assert(ctrl.state().dir_entries.size() == 1);
|
||||
assert(fs::path(ctrl.state().dir_entries[0]).filename().string() ==
|
||||
"picked_sub");
|
||||
|
||||
ctrl.handle_key(' ', cz::KeyCode::Space, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::Settings);
|
||||
assert(ctrl.state().effective_output_dir ==
|
||||
fs::weakly_canonical(picked_sub).string());
|
||||
assert(cz::load_config(cfg_path).output_dir ==
|
||||
fs::weakly_canonical(picked_sub).string());
|
||||
|
||||
// Close Settings
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
|
||||
// Capture a photo into picked_sub
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(count_files_with_ext(picked_sub, ".jpg") == 1);
|
||||
|
||||
// [8] pauses backend and opens Gallery
|
||||
assert(spy->pause_calls == 0);
|
||||
ctrl.handle_key('8', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::Gallery);
|
||||
assert(spy->pause_calls == 1);
|
||||
assert(ctrl.state().gallery_items.size() == 1);
|
||||
assert(ctrl.gallery_preview() != nullptr);
|
||||
assert(!ctrl.gallery_preview()->rgb24.empty());
|
||||
|
||||
// [D] requires [Y] before deleting
|
||||
ctrl.handle_key('d', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().gallery_delete_confirm);
|
||||
assert(count_files_with_ext(picked_sub, ".jpg") == 1);
|
||||
|
||||
ctrl.handle_key('n', cz::KeyCode::Char, now);
|
||||
assert(!ctrl.state().gallery_delete_confirm);
|
||||
assert(count_files_with_ext(picked_sub, ".jpg") == 1);
|
||||
|
||||
ctrl.handle_key('d', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().gallery_delete_confirm);
|
||||
ctrl.handle_key('y', cz::KeyCode::Char, now);
|
||||
assert(!ctrl.state().gallery_delete_confirm);
|
||||
assert(ctrl.state().gallery_items.empty());
|
||||
assert(count_files_with_ext(picked_sub, ".jpg") == 0);
|
||||
|
||||
// Esc exits Gallery and resumes backend
|
||||
assert(spy->resume_calls == 0);
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
assert(spy->resume_calls == 1);
|
||||
}
|
||||
|
||||
void test_text_input_timelapse_custom_recovery_and_modal_renders() {
|
||||
TempDir tmp("modals");
|
||||
const std::string cfg_path = tmp.path + "/config.json";
|
||||
const std::string out_dir = tmp.path + "/out";
|
||||
const std::string typed_dir = tmp.path + "/typed_out";
|
||||
assert(cz::mkdir_p(out_dir));
|
||||
|
||||
cz::AppConfig cfg;
|
||||
cfg.output_dir = out_dir;
|
||||
assert(cz::save_config(cfg, cfg_path));
|
||||
|
||||
// Create an orphaned timelapse work directory to exercise TimelapseRecovery
|
||||
const cz::TimelapseSessionPaths orphan_paths =
|
||||
cz::create_timelapse_session(out_dir, true);
|
||||
{
|
||||
cz::SimCameraBackend sim;
|
||||
cz::CameraStreamSpec sp;
|
||||
std::string err;
|
||||
assert(sim.start(sp, err));
|
||||
const cz::StagedPaths f1 =
|
||||
cz::next_timelapse_frame_paths(orphan_paths.work_dir, 1);
|
||||
assert(sim.capture_still(f1.tmp_path, 320, 240).ok);
|
||||
assert(cz::commit_staged_file(f1.tmp_path, f1.final_path, err));
|
||||
sim.stop();
|
||||
}
|
||||
cz::TimelapseManifest m;
|
||||
m.session_id = orphan_paths.session_id;
|
||||
m.work_dir = orphan_paths.work_dir;
|
||||
m.resolution = "2mp";
|
||||
m.interval_sec = 5;
|
||||
m.fps = 24;
|
||||
m.frame_count = 1;
|
||||
m.status = "recording";
|
||||
assert(cz::write_timelapse_manifest(orphan_paths.manifest_path, m));
|
||||
|
||||
cz::UiControllerOptions opts;
|
||||
opts.config_path = cfg_path;
|
||||
opts.backlight_sysfs_root = tmp.path + "/no_backlight";
|
||||
|
||||
cz::UiController ctrl(std::make_unique<cz::SimCameraBackend>(), opts);
|
||||
uint64_t now = 1000;
|
||||
assert(ctrl.init(now));
|
||||
|
||||
// Startup detects orphan and opens TimelapseRecovery modal
|
||||
assert(ctrl.state().modal == cz::OverlayModal::TimelapseRecovery);
|
||||
cz::AppView view;
|
||||
cz::PreviewFrame live;
|
||||
assert(ctrl.backend()->copy_latest_preview(0, live));
|
||||
view.render(ctrl.state(), &live, nullptr);
|
||||
|
||||
// [K] Keep as Photos Folder -> moves to TL_<id>/ and closes recovery modal
|
||||
ctrl.handle_key('k', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
assert(fs::is_directory(orphan_paths.photos_dir));
|
||||
assert(!fs::exists(orphan_paths.work_dir));
|
||||
|
||||
// Gallery drill-down into TL_<id>/ and Backspace back to root
|
||||
ctrl.handle_key('8', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::Gallery);
|
||||
assert(ctrl.state().gallery_items.size() == 1);
|
||||
assert(ctrl.state().gallery_items[0].type == cz::GalleryItemType::TimelapseFolder);
|
||||
view.render(ctrl.state(), &live, ctrl.gallery_preview());
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().gallery_in_session);
|
||||
assert(ctrl.state().gallery_items.size() == 1);
|
||||
view.render(ctrl.state(), &live, ctrl.gallery_preview());
|
||||
ctrl.handle_key(0, cz::KeyCode::Backspace, now);
|
||||
assert(!ctrl.state().gallery_in_session);
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
|
||||
// TimelapseCustomInput [C] editing interval/fps/stop mode
|
||||
ctrl.handle_key('3', cz::KeyCode::Char, now);
|
||||
ctrl.handle_key('c', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::TimelapseCustomInput);
|
||||
ctrl.handle_key('1', cz::KeyCode::Char, now);
|
||||
ctrl.handle_key('2', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().tl_custom_interval_sec == 12);
|
||||
ctrl.handle_key(0, cz::KeyCode::Down, now);
|
||||
ctrl.handle_key(0, cz::KeyCode::Right, now); // 24 -> 30 fps
|
||||
assert(ctrl.state().tl_custom_fps == 30);
|
||||
ctrl.handle_key(0, cz::KeyCode::Down, now);
|
||||
ctrl.handle_key(0, cz::KeyCode::Right, now); // manual -> shots
|
||||
assert(ctrl.state().tl_custom_stop_mode == "shots");
|
||||
view.render(ctrl.state(), &live, nullptr);
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::None);
|
||||
assert(ctrl.state().config.timelapse_interval_sec == 12);
|
||||
assert(ctrl.state().config.timelapse_fps == 30);
|
||||
assert(ctrl.state().config.timelapse_stop_mode == "shots");
|
||||
|
||||
// Settings -> DirPicker -> [T] TextInput manual directory entry
|
||||
ctrl.handle_key('s', cz::KeyCode::Char, now);
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::DirPicker);
|
||||
view.render(ctrl.state(), &live, nullptr);
|
||||
ctrl.handle_key('t', cz::KeyCode::Char, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::TextInput);
|
||||
for (char c : typed_dir) {
|
||||
ctrl.handle_key(c, cz::KeyCode::Char, now);
|
||||
}
|
||||
view.render(ctrl.state(), &live, nullptr);
|
||||
ctrl.handle_key(0, cz::KeyCode::Enter, now);
|
||||
assert(ctrl.state().modal == cz::OverlayModal::Settings);
|
||||
assert(ctrl.state().effective_output_dir == typed_dir);
|
||||
assert(fs::is_directory(typed_dir));
|
||||
ctrl.handle_key(0, cz::KeyCode::Esc, now);
|
||||
|
||||
// Software black screen when dimmed without hardware backlight
|
||||
cz::UiState dimmed_sw = ctrl.state();
|
||||
dimmed_sw.timelapse_dimmed = true;
|
||||
dimmed_sw.has_hardware_backlight = false;
|
||||
view.render(dimmed_sw, &live, nullptr);
|
||||
const uint32_t* px = view.pixels();
|
||||
for (int i = 0; i < cz::AppView::kWidth * cz::AppView::kHeight; ++i) {
|
||||
assert(px[i] == 0xff000000U);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
test_photo_controls_zoom_loupe_filters_and_timer();
|
||||
test_rail_side_and_theme_toggles_persist();
|
||||
test_video_mode_locks_transitions_while_recording();
|
||||
test_timelapse_dimmed_safe_wake();
|
||||
test_settings_dir_picker_camera_orient_and_gallery_delete();
|
||||
test_text_input_timelapse_custom_recovery_and_modal_renders();
|
||||
std::cout << "test_ui_controller: ALL PASSED\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user