-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from m5stack/dev_ble_keyboard
Add App Keyboard
- Loading branch information
Showing
34 changed files
with
4,505 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
menu "USB HID Device Example" | ||
|
||
choice HID_SUBCLASS | ||
prompt "HID Device" | ||
default SUBCLASS_MOUSE | ||
|
||
config SUBCLASS_MOUSE | ||
bool "Mouse" | ||
config SUBCLASS_KEYBOARD | ||
bool "Keyboard" | ||
endchoice | ||
|
||
config TUSB_VID | ||
hex "USB Device VID" | ||
default 0x303A | ||
config TUSB_PID | ||
hex "USB Device PID" | ||
default 0x8000 | ||
config TUSB_MANUFACTURER | ||
string "USB Device Manufacture" | ||
default "Espressif" | ||
config TUSB_PRODUCT | ||
string "Product Name" | ||
default "HID Demo" | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* @file app_keyboard.cpp | ||
* @author Forairaaaaa | ||
* @brief | ||
* @version 0.1 | ||
* @date 2023-12-07 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
*/ | ||
#include "app_keyboard.h" | ||
#include "spdlog/spdlog.h" | ||
#include "../utils/wifi_common_test/wifi_common_test.h" | ||
#include "../utils/theme/theme_define.h" | ||
|
||
|
||
using namespace MOONCAKE::APPS; | ||
|
||
|
||
// #define TEST_USE_BLE | ||
// #define TEST_USE_USB | ||
|
||
|
||
void AppKeyboard::onCreate() | ||
{ | ||
spdlog::info("{} onCreate", getAppName()); | ||
|
||
// Get hal | ||
_data.hal = mcAppGetDatabase()->Get("HAL")->value<HAL::Hal *>(); | ||
} | ||
|
||
|
||
void AppKeyboard::onResume() | ||
{ | ||
ANIM_APP_OPEN(); | ||
|
||
{ | ||
_data.hal->canvas()->fillScreen(THEME_COLOR_BG); | ||
_data.hal->canvas()->setFont(FONT_REPL); | ||
_data.hal->canvas()->setTextColor(TFT_ORANGE, THEME_COLOR_BG); | ||
_data.hal->canvas()->setTextSize(1); | ||
_data.hal->canvas_update(); | ||
|
||
// Start ble keyboard | ||
spdlog::info("remain before: {}", uxTaskGetStackHighWaterMark(NULL)); | ||
} | ||
|
||
_select_kb_type(); | ||
|
||
// #ifdef TEST_USE_BLE | ||
// _ble_kb_init(); | ||
// #endif | ||
// #ifdef TEST_USE_USB | ||
// _usb_kb_init(); | ||
// #endif | ||
|
||
if (_data.kb_type == kb_type_ble) | ||
_ble_kb_init(); | ||
else if (_data.kb_type == kb_type_usb) | ||
_usb_kb_init(); | ||
} | ||
|
||
|
||
void AppKeyboard::onRunning() | ||
{ | ||
if (_data.hal->homeButton()->pressed()) | ||
{ | ||
_data.hal->playNextSound(); | ||
spdlog::info("quit app {}", getAppName()); | ||
destroyApp(); | ||
} | ||
|
||
// #ifdef TEST_USE_BLE | ||
// _ble_kb_update_infos(); | ||
// _ble_kb_update_kb_input(); | ||
// #endif | ||
// #ifdef TEST_USE_USB | ||
// _usb_kb_update_infos(); | ||
// _usb_kb_update_kb_input(); | ||
// #endif | ||
|
||
if (_data.kb_type == kb_type_ble) | ||
{ | ||
_ble_kb_update_infos(); | ||
_ble_kb_update_kb_input(); | ||
} | ||
else if (_data.kb_type == kb_type_usb) | ||
{ | ||
_usb_kb_update_infos(); | ||
_usb_kb_update_kb_input(); | ||
} | ||
} | ||
|
||
|
||
void AppKeyboard::onDestroy() | ||
{ | ||
spdlog::info("{} onDestroy", getAppName()); | ||
// ble_keyboard_wrap_deinit(); | ||
|
||
delay(200); | ||
esp_restart(); | ||
delay(10000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* @file app_keyboard.h | ||
* @author Forairaaaaa | ||
* @brief | ||
* @version 0.1 | ||
* @date 2023-12-07 | ||
* | ||
* @copyright Copyright (c) 2023 | ||
* | ||
*/ | ||
#pragma once | ||
#include <mooncake.h> | ||
#include "../../hal/hal.h" | ||
#include "../utils/theme/theme_define.h" | ||
#include "../utils/anim/anim_define.h" | ||
#include "../utils/icon/icon_define.h" | ||
|
||
#include "assets/keyboard_big.h" | ||
#include "assets/keyboard_small.h" | ||
|
||
|
||
namespace MOONCAKE | ||
{ | ||
namespace APPS | ||
{ | ||
class AppKeyboard : public APP_BASE | ||
{ | ||
private: | ||
enum KeyboardType_t | ||
{ | ||
kb_type_ble = 0, | ||
kb_type_usb, | ||
}; | ||
|
||
struct Data_t | ||
{ | ||
HAL::Hal* hal = nullptr; | ||
uint32_t update_infos_time_count = 0; | ||
uint32_t update_kb_time_count = 0; | ||
KeyboardType_t kb_type = kb_type_ble; | ||
}; | ||
Data_t _data; | ||
void _select_kb_type(); | ||
void _ble_kb_init(); | ||
void _ble_kb_update_infos(); | ||
void _ble_kb_update_kb_input(); | ||
void _usb_kb_init(); | ||
void _usb_kb_update_infos(); | ||
void _usb_kb_update_kb_input(); | ||
|
||
public: | ||
void onCreate() override; | ||
void onResume() override; | ||
void onRunning() override; | ||
void onDestroy() override; | ||
}; | ||
|
||
class AppKeyboard_Packer : public APP_PACKER_BASE | ||
{ | ||
std::string getAppName() override { return "KEYBOARD"; } | ||
void* getAppIcon() override { return (void*)(new AppIcon_t(image_data_keyboard_big, image_data_keyboard_small)); } | ||
void* newApp() override { return new AppKeyboard; } | ||
void deleteApp(void *app) override { delete (AppKeyboard*)app; } | ||
}; | ||
} | ||
} |
Oops, something went wrong.