Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/apps/app_launcher/view/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <smooth_lvgl.h>
#include <smooth_ui_toolkit.h>

#include "integration/cctv_controller.h"
#include "integration/settings_controller.h"
#include "ui/pages/ui_page_settings.h"
#include "ui/ui_root.h"
Expand Down Expand Up @@ -65,6 +66,7 @@ void LauncherView::init()

if (_ui_root != nullptr)
{
_cctv_controller.reset();
_settings_controller.reset();
ui_root_destroy(_ui_root);
_ui_root = nullptr;
Expand All @@ -73,6 +75,7 @@ void LauncherView::init()
if (_ui_root != nullptr)
{
_settings_controller = std::make_unique<SettingsController>();
_cctv_controller = std::make_unique<CctvController>();

ui_page_settings_actions_t actions{};
actions.run_connection_test = [](const char* tester_id, void* user_data)
Expand Down Expand Up @@ -182,6 +185,10 @@ void LauncherView::init()

ui_page_settings_set_actions(&actions, _settings_controller.get());
_settings_controller->PublishInitialState();
if (_cctv_controller != nullptr)
{
_cctv_controller->PublishInitialState();
}
}
}

Expand All @@ -197,6 +204,7 @@ void LauncherView::update()

LauncherView::~LauncherView()
{
_cctv_controller.reset();
_settings_controller.reset();
if (_ui_root != nullptr)
{
Expand Down
6 changes: 6 additions & 0 deletions app/apps/app_launcher/view/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

#include "integration/settings_controller.h"

namespace custom::integration
{
class CctvController;
}

struct ui_root_t;

namespace launcher_view
Expand Down Expand Up @@ -319,6 +324,7 @@ namespace launcher_view
std::vector<std::unique_ptr<PanelBase>> _panels;
ui_root_t* _ui_root = nullptr;
std::unique_ptr<custom::integration::SettingsController> _settings_controller;
std::unique_ptr<custom::integration::CctvController> _cctv_controller;

void update_anim();
};
Expand Down
246 changes: 246 additions & 0 deletions custom/integration/cctv_controller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#include "integration/cctv_controller.h"

#include <algorithm>
#include <array>

#include "core/app_trace.h"

namespace custom::integration
{

namespace
{

constexpr const char* kTag = "cctv-controller";

constexpr std::array<const char*, 3> kQualityOptions = {
"1080p60",
"720p30",
"360p15",
};

constexpr ui_page_cctv_camera_t kCameras[] = {
{
.camera_id = "front_porch",
.name = "Front Porch",
.status = "Streaming · 1080p60",
.stream_url = "rtsp://frigate/front_porch/stream",
.snapshot_url = "https://frigate.local/api/front_porch.jpg",
.audio_supported = true,
},
{
.camera_id = "garage",
.name = "Garage Bay",
.status = "Idle · Door closed",
.stream_url = "rtsp://frigate/garage/stream",
.snapshot_url = "https://frigate.local/api/garage.jpg",
.audio_supported = false,
},
{
.camera_id = "backyard",
.name = "Backyard",
.status = "Streaming · 1440p30",
.stream_url = "rtsp://frigate/backyard/stream",
.snapshot_url = "https://frigate.local/api/backyard.jpg",
.audio_supported = true,
},
};

constexpr ui_page_cctv_event_t kEvents[] = {
{
.event_id = "evt_front_1742",
.camera_id = "front_porch",
.title = "Front Porch",
.description = "Person detected · 2m ago",
.timestamp = "Today · 17:42",
.clip_url = "https://frigate.local/api/front_porch/event/evt_front_1742.mp4",
.snapshot_url = "https://frigate.local/api/front_porch/event/evt_front_1742.jpg",
},
{
.event_id = "evt_drive_1737",
.camera_id = "garage",
.title = "Driveway",
.description = "Vehicle detected",
.timestamp = "Today · 17:37",
.clip_url = "https://frigate.local/api/garage/event/evt_drive_1737.mp4",
.snapshot_url = "https://frigate.local/api/garage/event/evt_drive_1737.jpg",
},
{
.event_id = "evt_gate_1715",
.camera_id = "backyard",
.title = "Backyard Gate",
.description = "Package drop-off",
.timestamp = "Today · 17:15",
.clip_url = "https://frigate.local/api/backyard/event/evt_gate_1715.mp4",
.snapshot_url = "https://frigate.local/api/backyard/event/evt_gate_1715.jpg",
},
};

constexpr std::size_t CameraCount = sizeof(kCameras) / sizeof(kCameras[0]);
constexpr std::size_t EventCount = sizeof(kEvents) / sizeof(kEvents[0]);

} // namespace

CctvController::CctvController()
{
page_ = ui_page_cctv_get_obj();
if (page_ != nullptr)
{
lv_obj_add_event_cb(page_, PageEventCb, UI_PAGE_CCTV_EVENT_ACTION, this);
lv_obj_add_event_cb(page_, PageEventCb, UI_PAGE_CCTV_EVENT_OPEN_CLIP, this);
}
}

CctvController::~CctvController()
{
if (page_ != nullptr)
{
lv_obj_remove_event_cb_with_user_data(page_, PageEventCb, this);
}
}

void CctvController::PublishInitialState()
{
PushState();
}

void CctvController::PageEventCb(lv_event_t* event)
{
if (event == nullptr)
{
return;
}

auto* controller = static_cast<CctvController*>(lv_event_get_user_data(event));
if (controller == nullptr)
{
return;
}

lv_event_code_t code = lv_event_get_code(event);

if (code == UI_PAGE_CCTV_EVENT_ACTION)
{
const auto* action =
static_cast<const ui_page_cctv_action_event_t*>(lv_event_get_param(event));
if (action != nullptr)
{
controller->HandleAction(*action);
}
}
+else if (code == UI_PAGE_CCTV_EVENT_OPEN_CLIP) +
{
+const auto* clip =
static_cast<const ui_page_cctv_clip_event_t*>(lv_event_get_param(event));
+if (clip != nullptr) +
Comment on lines +136 to +140
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] Remove diff markers from clip event handler

The PageEventCb branch that should react to UI_PAGE_CCTV_EVENT_OPEN_CLIP still contains the literal + prefixes from the patch (+else if, +const auto* clip, etc.). These stray characters make the file fail to compile, so the launcher cannot build and the controller never receives clip-open events. Drop the + markers and keep a normal else if block.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex fix comments

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Testing

  • ⚠️ idf.py build (not run; environment does not provide ESP-IDF tooling for this quick fix)

View task →

{
+controller->HandleClipRequest(*clip);
+
}
+
}
}

void CctvController::HandleAction(const ui_page_cctv_action_event_t& action)
{
if (CameraCount == 0)
{
return;
}

switch (action.action)
{
case UI_PAGE_CCTV_ACTION_PREVIOUS:
if (CameraCount > 0)
{
if (active_index_ == 0)
{
active_index_ = CameraCount - 1;
}
else
{
active_index_--;
}
PushState();
}
break;

case UI_PAGE_CCTV_ACTION_NEXT:
if (CameraCount > 0)
{
active_index_ = (active_index_ + 1) % CameraCount;
PushState();
}
break;

case UI_PAGE_CCTV_ACTION_QUALITY:
quality_index_ = (quality_index_ + 1) % kQualityOptions.size();
PushState();
break;

case UI_PAGE_CCTV_ACTION_TOGGLE_MUTE:
muted_ = !muted_;
PushState();
break;

case UI_PAGE_CCTV_ACTION_OPEN_GATE:
APP_TRACEI(kTag,
"Requested gate open for camera %s",
action.camera_id != nullptr ? action.camera_id : "(none)");
break;

case UI_PAGE_CCTV_ACTION_TALK:
APP_TRACEI(kTag,
"Initiating talkback on %s",
action.camera_id != nullptr ? action.camera_id : "(none)");
break;

case UI_PAGE_CCTV_ACTION_SNAPSHOT:
APP_TRACEI(kTag,
"Snapshot requested for %s",
action.camera_id != nullptr ? action.camera_id : "(none)");
break;

case UI_PAGE_CCTV_ACTION_TIMELINE:
APP_TRACEI(kTag, "Timeline requested (events=%u)", (unsigned int)EventCount);
break;
}
}

void CctvController::HandleClipRequest(const ui_page_cctv_clip_event_t& clip)
{
if (clip.event == nullptr)
{
return;
}

const char* clip_id = clip.event->event_id != nullptr ? clip.event->event_id : "(unknown)";
APP_TRACEI(kTag, "Open clip %s", clip_id);
}

void CctvController::PushState()
{
if (page_ == nullptr)
{
return;
}

ui_page_cctv_state_t state = {
.cameras = kCameras,
.camera_count = CameraCount,
.active_index = std::min(active_index_, CameraCount > 0 ? CameraCount - 1 : 0),
.events = kEvents,
.event_count = EventCount,
.quality_label = kQualityOptions[quality_index_],
.muted = muted_,
};

ui_page_cctv_set_state(&state);
}

} // namespace custom::integration
53 changes: 53 additions & 0 deletions custom/integration/cctv_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
#pragma once

#include <cstddef>

#ifdef __has_include
# if __has_include("lvgl.h")
# ifndef LV_LVGL_H_INCLUDE_SIMPLE
# define LV_LVGL_H_INCLUDE_SIMPLE
# endif
# endif
#endif

#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
# include "lvgl.h"
#else
# include "lvgl/lvgl.h"
#endif

#include "ui/pages/ui_page_cctv.h"

namespace custom::integration
{

class CctvController
{
public:
CctvController();
~CctvController();

CctvController(const CctvController&) = delete;
CctvController& operator=(const CctvController&) = delete;

void PublishInitialState();

private:
static void PageEventCb(lv_event_t* event);

void HandleAction(const ui_page_cctv_action_event_t& action);
void HandleClipRequest(const ui_page_cctv_clip_event_t& clip);
void PushState();

lv_obj_t* page_ = nullptr;
std::size_t active_index_ = 0;
std::size_t quality_index_ = 0;
bool muted_ = false;
};

} // namespace custom::integration
Loading
Loading