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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# M5Cardputer-UserDemo
M5Cardputer user demo for hardware evaluation.

Press **Q** on the startup screen to enable quiet mode, or press **Q** in the
launcher to toggle it. Quiet mode silences startup audio and UI/keyboard sounds,
shows a muted speaker icon in the status bar, and is remembered across restarts.
Recorded audio playback is unaffected. To silence the first startup sound, hold
**Q** while powering on.

> **Note: If you are using Cardputer ADV, please use the [CardputerADV branch](https://github.com/m5stack/M5Cardputer-UserDemo/tree/CardputerADV).**

#### Tool Chains
Expand Down
6 changes: 6 additions & 0 deletions main/apps/launcher/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ void Launcher::onCreate()
startApp();
}

void Launcher::onResume()
{
// A Q held while returning from an app must not toggle quiet mode.
_data.hal->keyboard()->updateKeyList();
_data.quiet_key_was_pressed = _data.hal->keyboard()->isKeyPressing(_data.hal->keyboard()->getKeyNum({1, 1}));
}

void Launcher::onRunning()
{
Expand Down
3 changes: 3 additions & 0 deletions main/apps/launcher/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace MOONCAKE
SMOOTH_MENU::Simple_Menu* menu = nullptr;
SMOOTH_MENU::SimpleMenuCallback_t* menu_render_cb = nullptr;
APP_BASE* _opened_app = nullptr;
bool quiet_key_was_pressed = false;

// System bar
uint32_t system_bar_update_preiod = 1000;
Expand Down Expand Up @@ -98,12 +99,14 @@ namespace MOONCAKE
bool _port_check_next_pressed();
bool _port_check_last_pressed();
bool _port_check_enter_pressed();
bool _port_check_quiet_pressed();
void _port_update_keyboard_state();
void _port_update_system_state();


public:
void onCreate() override;
void onResume() override;
void onRunning() override;
void onRunningBG() override;
};
Expand Down
29 changes: 27 additions & 2 deletions main/apps/launcher/port/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ void Launcher::_port_wait_enter()
{
// delay(600);

_data.hal->Speaker()->setVolume(255);
_data.hal->Speaker()->setVolume(90);
// bool shit = false;

_data.hal->keyboard()->updateKeyList();
const int quiet_key = _data.hal->keyboard()->getKeyNum({1, 1}); // Q
const bool quiet_pressed = _data.hal->keyboard()->isKeyPressing(quiet_key);
if (quiet_pressed)
_data.hal->setQuietMode(true);
if (_data.hal->keyboard()->keyList().size())
{
// _data.hal->Speaker()->playWav(boot_sound_1, sizeof(boot_sound_1));
Expand All @@ -33,24 +37,36 @@ void Launcher::_port_wait_enter()
{
// shit = true;
#ifndef NO_BOOT_PLAY_SHIT
_data.hal->Speaker()->playWav(boot_sound_2, sizeof(boot_sound_2));
if (!_data.hal->isQuietMode())
_data.hal->Speaker()->playWav(boot_sound_2, sizeof(boot_sound_2));
#endif
}

// Hold till release
while (_data.hal->keyboard()->keyList().size())
{
_data.hal->keyboard()->updateKeyList();
delay(1);
}

if (quiet_pressed)
return;

while (1)
{
_data.hal->keyboard()->updateKeyList();
if (_data.hal->keyboard()->keyList().size())
{
if (_data.hal->keyboard()->isKeyPressing(quiet_key))
_data.hal->setQuietMode(true);
_data.hal->playNextSound();

// Hold till release
while (_data.hal->keyboard()->keyList().size())
{
_data.hal->keyboard()->updateKeyList();
delay(1);
}

break;
}
Expand All @@ -64,6 +80,15 @@ void Launcher::_port_wait_enter()
// _data.hal->Speaker()->playWav(boot_sound_1, sizeof(boot_sound_1));
}

bool Launcher::_port_check_quiet_pressed()
{
_data.hal->keyboard()->updateKeyList();
const bool pressed = _data.hal->keyboard()->isKeyPressing(_data.hal->keyboard()->getKeyNum({1, 1}));
const bool newly_pressed = pressed && !_data.quiet_key_was_pressed;
_data.quiet_key_was_pressed = pressed;
return newly_pressed;
}

bool Launcher::_port_check_next_pressed()
{
if (_data.hal->keyboard()->isKeyPressing(55) || _data.hal->keyboard()->isKeyPressing(54))
Expand Down
3 changes: 3 additions & 0 deletions main/apps/launcher/views/boot_anim/boot_anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ void Launcher::_boot_anim()

// Show logo
_data.hal->display()->pushImage(0, 0, 240, 135, image_data_logo);
_data.hal->display()->setFont(&fonts::Font0);
_data.hal->display()->setTextColor((uint32_t)0x999999, (uint32_t)0xE6E6E6);
_data.hal->display()->drawString("Q=quiet", 6, 122);
_port_wait_enter();
}
7 changes: 7 additions & 0 deletions main/apps/launcher/views/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ void Launcher::_update_menu()
{
if ((millis() - _data.menu_update_count) > _data.menu_update_preiod)
{
if (_port_check_quiet_pressed())
{
_data.hal->setQuietMode(!_data.hal->isQuietMode());
_data.system_bar_update_count = millis() - _data.system_bar_update_preiod - 1;
_update_system_bar();
}

// Navigate
if (_port_check_last_pressed())
_data.menu->goLast();
Expand Down
52 changes: 52 additions & 0 deletions main/apps/launcher/views/system_bar/assets/quiet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

/*******************************************************************************
* name: quiet
*
* preset name: Color R5G6B5
* data block size: 16 bit(s), uint16_t
* RLE compression enabled: no
* conversion type: Color, not_used not_used
* split to rows: yes
* bits per pixel: 16
*
* preprocess:
* main scan direction: top_to_bottom
* line scan direction: forward
* inverse: no
*******************************************************************************/

/*
typedef struct {
const uint16_t *data;
uint16_t width;
uint16_t height;
uint8_t dataSize;
} tImage;
*/
#include <stdint.h>

static const uint16_t image_data_quiet[256] = {
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x82e0, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x82e0, 0x82e0, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x0000, 0xe09f, 0x82e0,
0x82e0, 0x82e0, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0x0000, 0x0000, 0x82e0, 0x82e0, 0x82e0, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0x0000, 0x0000, 0x0000, 0x82e0, 0x82e0, 0x82e0, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x82e0, 0x82e0, 0x82e0, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x0000, 0x0000, 0x0000, 0x0000, 0x82e0,
0x82e0, 0x82e0, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x0000,
0x0000, 0x0000, 0x82e0, 0x82e0, 0x82e0, 0x0000, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0x0000, 0x0000, 0x82e0, 0x82e0, 0x82e0, 0x0000, 0x0000, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x82e0, 0x82e0, 0x82e0, 0x0000,
0x0000, 0x0000, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x82e0,
0x82e0, 0x82e0, 0xe09f, 0xe09f, 0x0000, 0x0000, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0x82e0, 0x82e0, 0x82e0, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x0000, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0x82e0, 0x82e0, 0x82e0, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f, 0xe09f,
0xe09f, 0xe09f, 0xe09f, 0xe09f};
// const tImage quiet = { image_data_quiet, 16, 16,
// 16 };
7 changes: 3 additions & 4 deletions main/apps/launcher/views/system_bar/system_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "assets/wifi3.h"
#include "assets/wifi4.h"
#include "assets/wifi5.h"
#include "assets/quiet.h"

using namespace MOONCAKE::APPS;

Expand Down Expand Up @@ -79,10 +80,8 @@ void Launcher::_update_system_bar()
else if (_data.system_state.wifi_state == 5)
_data.hal->canvas_system_bar()->pushImage(x, y, 16, 16, image_data_wifi5);





if (_data.hal->isQuietMode())
_data.hal->canvas_system_bar()->pushImage(x + 18, y, 16, 16, image_data_quiet);

// Bat shit
x = _data.hal->canvas_system_bar()->width() - 45;
Expand Down
6 changes: 5 additions & 1 deletion main/hal/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ namespace HAL
SDCard* _sdcard;

bool _sntp_adjusted;
bool _quiet_mode;

public:
Hal()
: _display(nullptr), _canvas(nullptr), _canvas_system_bar(nullptr), _canvas_keyboard_bar(nullptr),
_keyboard(nullptr), _mic(nullptr), _speaker(nullptr), _homeButton(nullptr), _sdcard(nullptr),
_sntp_adjusted(false)
_sntp_adjusted(false), _quiet_mode(false)
{
}

Expand All @@ -62,6 +63,9 @@ namespace HAL
inline void setSntpAdjusted(bool isAdjusted) { _sntp_adjusted = isAdjusted; }
inline bool isSntpAdjusted(void) { return _sntp_adjusted; }

inline bool isQuietMode() const { return _quiet_mode; }
virtual void setQuietMode(bool quiet) { _quiet_mode = quiet; }

// Canvas
inline void canvas_system_bar_update() { _canvas_system_bar->pushSprite(_canvas_keyboard_bar->width(), 0); }
inline void canvas_keyboard_bar_update() { _canvas_keyboard_bar->pushSprite(0, 0); }
Expand Down
56 changes: 56 additions & 0 deletions main/hal/hal_cardputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <mooncake.h>
#include "../apps/utils/common_define.h"
#include "bat/adc_read.h"
#include "nvs.h"
#include "nvs_flash.h"

using namespace HAL;

Expand Down Expand Up @@ -91,6 +93,59 @@ void HalCardputer::_bat_init() { adc_read_init(); }

void HalCardputer::_sdcard_init() { _sdcard = new SDCard; }

void HalCardputer::_load_quiet_mode()
{
esp_err_t err = nvs_flash_init();
if (err != ESP_OK)
{
spdlog::warn("cannot initialize settings: {}", esp_err_to_name(err));
return;
}

nvs_handle_t handle;
err = nvs_open("cardputer", NVS_READONLY, &handle);
if (err == ESP_ERR_NVS_NOT_FOUND)
return;
if (err != ESP_OK)
{
spdlog::warn("cannot open settings: {}", esp_err_to_name(err));
return;
}

uint8_t quiet = 0;
err = nvs_get_u8(handle, "quiet_mode", &quiet);
nvs_close(handle);
if (err == ESP_OK)
_quiet_mode = quiet != 0;
else if (err != ESP_ERR_NVS_NOT_FOUND)
spdlog::warn("cannot load quiet mode: {}", esp_err_to_name(err));
}

void HalCardputer::setQuietMode(bool quiet)
{
if (_quiet_mode == quiet)
return;

_quiet_mode = quiet;
if (quiet && _speaker)
_speaker->stop();

nvs_handle_t handle;
// Wi-Fi scanning may have deinitialized NVS since startup.
esp_err_t err = nvs_flash_init();
if (err == ESP_OK)
err = nvs_open("cardputer", NVS_READWRITE, &handle);
if (err == ESP_OK)
{
err = nvs_set_u8(handle, "quiet_mode", quiet);
if (err == ESP_OK)
err = nvs_commit(handle);
nvs_close(handle);
}
if (err != ESP_OK)
spdlog::warn("cannot save quiet mode: {}", esp_err_to_name(err));
}

void HalCardputer::init()
{
spdlog::info("hal init");
Expand All @@ -102,6 +157,7 @@ void HalCardputer::init()
_button_init();
_bat_init();
_sdcard_init();
_load_quiet_mode();
}

// double getBatVolBfb(double batVcc) //获取电压的百分比,经过换算并非线性关系
Expand Down
29 changes: 26 additions & 3 deletions main/hal/hal_cardputer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,36 @@ namespace HAL
void _button_init();
void _bat_init();
void _sdcard_init();
void _load_quiet_mode();

public:
std::string type() override { return "cardputer"; }
void init() override;
void playKeyboardSound() override { _speaker->setVolume(72); _speaker->tone(5000, 20); }
void playLastSound() override { _speaker->setVolume(32); _speaker->tone(6000, 20); }
void playNextSound() override { _speaker->setVolume(64); _speaker->tone(7000, 20); }
void setQuietMode(bool quiet) override;
void playKeyboardSound() override
{
if (!isQuietMode())
{
_speaker->setVolume(72);
_speaker->tone(5000, 20);
}
}
void playLastSound() override
{
if (!isQuietMode())
{
_speaker->setVolume(32);
_speaker->tone(6000, 20);
}
}
void playNextSound() override
{
if (!isQuietMode())
{
_speaker->setVolume(64);
_speaker->tone(7000, 20);
}
}
uint8_t getBatLevel() override;

public:
Expand Down
Loading