mirror of
https://github.com/m5stack/StackChan.git
synced 2026-04-27 19:12:40 +00:00
5001b7081b
* add firmware source code
82 lines
1.7 KiB
C++
82 lines
1.7 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
#include "app_launcher.h"
|
|
#include <hal/hal.h>
|
|
#include <mooncake.h>
|
|
#include <mooncake_log.h>
|
|
#include <stackchan/stackchan.h>
|
|
#include <cstdint>
|
|
|
|
using namespace mooncake;
|
|
|
|
void AppLauncher::onLauncherCreate()
|
|
{
|
|
mclog::tagInfo(getAppInfo().name, "on create");
|
|
|
|
// 打开自己
|
|
open();
|
|
}
|
|
|
|
void AppLauncher::onLauncherOpen()
|
|
{
|
|
mclog::tagInfo(getAppInfo().name, "on open");
|
|
|
|
LvglLockGuard lock;
|
|
|
|
_view = std::make_unique<view::LauncherView>();
|
|
_view->init(getAppProps());
|
|
_view->onAppClicked = [&](int appID) {
|
|
mclog::tagInfo(getAppInfo().name, "handle open app, app id: {}", appID);
|
|
openApp(appID);
|
|
};
|
|
}
|
|
|
|
void AppLauncher::onLauncherRunning()
|
|
{
|
|
LvglLockGuard lock;
|
|
|
|
_view->update();
|
|
|
|
screensaver_update();
|
|
|
|
GetStackChan().update();
|
|
}
|
|
|
|
void AppLauncher::onLauncherClose()
|
|
{
|
|
mclog::tagInfo(getAppInfo().name, "on close");
|
|
|
|
LvglLockGuard lock;
|
|
|
|
_view.reset();
|
|
}
|
|
|
|
void AppLauncher::onLauncherDestroy()
|
|
{
|
|
mclog::tagInfo(getAppInfo().name, "on close");
|
|
}
|
|
|
|
void AppLauncher::screensaver_update()
|
|
{
|
|
const uint32_t SCREENSAVER_TIMEOUT_MS = 30000;
|
|
|
|
uint32_t idle_time = lv_display_get_inactive_time(NULL);
|
|
if (idle_time >= SCREENSAVER_TIMEOUT_MS) {
|
|
if (!_screensaver) {
|
|
_screensaver = std::make_unique<view::Screensaver>();
|
|
_screensaver->init();
|
|
}
|
|
} else if (_screensaver) {
|
|
_screensaver.reset();
|
|
}
|
|
|
|
// Update in 30ms interval
|
|
if (_screensaver && GetHAL().millis() - _screensaver_timecount > 30) {
|
|
_screensaver_timecount = GetHAL().millis();
|
|
_screensaver->update();
|
|
}
|
|
}
|