mirror of
https://github.com/m5stack/StackChan.git
synced 2026-04-27 11:02:40 +00:00
122 lines
2.8 KiB
C++
122 lines
2.8 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
#include "hal_bridge.h"
|
|
#include "stackchan_display.h"
|
|
#include <esp_log.h>
|
|
#include <esp_err.h>
|
|
#include <nvs.h>
|
|
#include <nvs_flash.h>
|
|
#include <driver/gpio.h>
|
|
#include <esp_event.h>
|
|
#include <application.h>
|
|
#include <board.h>
|
|
#include <display.h>
|
|
#include <mutex>
|
|
#include <assets.h>
|
|
|
|
static const char* _tag = "HAL_BRIDGE";
|
|
|
|
namespace hal_bridge {
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* State and touch point */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
static std::mutex _mutex;
|
|
static Data_t _data;
|
|
|
|
void lock()
|
|
{
|
|
_mutex.lock();
|
|
}
|
|
|
|
void unlock()
|
|
{
|
|
_mutex.unlock();
|
|
}
|
|
|
|
Data_t& get_data()
|
|
{
|
|
return _data;
|
|
}
|
|
|
|
void set_touch_point(int num, int x, int y)
|
|
{
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
_data.touchPoint.num = num;
|
|
_data.touchPoint.x = x;
|
|
_data.touchPoint.y = y;
|
|
}
|
|
|
|
TouchPoint_t get_touch_point()
|
|
{
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
return _data.touchPoint;
|
|
}
|
|
|
|
bool is_xiaozhi_mode()
|
|
{
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
return _data.isXiaozhiMode;
|
|
}
|
|
|
|
void set_xiaozhi_mode(bool mode)
|
|
{
|
|
std::lock_guard<std::mutex> lock(_mutex);
|
|
_data.isXiaozhiMode = mode;
|
|
}
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* Display */
|
|
/* -------------------------------------------------------------------------- */
|
|
#define DISPLAY_TYPE StackChanAvatarDisplay
|
|
|
|
lv_disp_t* display_get_lvgl_display()
|
|
{
|
|
auto display = static_cast<DISPLAY_TYPE*>(Board::GetInstance().GetDisplay());
|
|
return display->GetLvglDisplay();
|
|
}
|
|
|
|
void disply_lvgl_lock()
|
|
{
|
|
auto display = static_cast<DISPLAY_TYPE*>(Board::GetInstance().GetDisplay());
|
|
display->LvglLock();
|
|
}
|
|
|
|
void disply_lvgl_unlock()
|
|
{
|
|
auto display = static_cast<DISPLAY_TYPE*>(Board::GetInstance().GetDisplay());
|
|
display->LvglUnlock();
|
|
}
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* Application */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
void xiaozhi_board_init()
|
|
{
|
|
// Init board
|
|
auto& board = Board::GetInstance();
|
|
}
|
|
|
|
void start_xiaozhi_app()
|
|
{
|
|
set_xiaozhi_mode(true);
|
|
|
|
// Initialize and run the application
|
|
auto& app = Application::GetInstance();
|
|
app.Initialize();
|
|
app.Run(); // This function runs the main event loop and never returns
|
|
}
|
|
|
|
void app_play_sound(const std::string_view& sound)
|
|
{
|
|
auto& app = Application::GetInstance();
|
|
app.PlaySound(sound);
|
|
}
|
|
|
|
} // namespace hal_bridge
|