Skip to content

Commit

Permalink
feat: add mute button and update espp accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
finger563 committed Jul 4, 2024
1 parent 0174c2e commit 24aa5da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/box-emu/include/box-emu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "aw9523.hpp"
#include "base_component.hpp"
#include "button.hpp"
#include "events.hpp"
#include "high_resolution_timer.hpp"
#include "keypad_input.hpp"
Expand Down Expand Up @@ -283,6 +284,9 @@ class BoxEmu : public espp::BaseComponent {
// memory
uint8_t *romdata_{nullptr};

// audio
std::shared_ptr<espp::Button> mute_button_;

// gamepad
std::atomic<bool> can_read_gamepad_{true};
std::recursive_mutex gamepad_state_mutex_;
Expand Down
30 changes: 30 additions & 0 deletions components/box-emu/src/box-emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@ bool BoxEmu::initialize_box() {
return false;
}

// initialize the mute button to broadcast the mute state
logger_.info("Initializing mute button");
mute_button_ = std::make_shared<espp::Button>(espp::Button::Config{
.name = "mute button",
.interrupt_config =
{
.gpio_num = espp::EspBox::get_mute_pin(),
.callback =
[](const espp::Interrupt::Event &event) {
espp::EspBox::get().mute(event.active);
// simply publish that the mute button was presssed
espp::EventManager::get().publish(mute_button_topic, {});
},
.active_level = espp::Interrupt::ActiveLevel::LOW,
.interrupt_type = espp::Interrupt::Type::ANY_EDGE,
.pullup_enabled = true,
.pulldown_enabled = false,
},
.task_config =
{
.name = "mute button task",
.stack_size_bytes = 4 * 1024,
.priority = 5,
},
.log_level = espp::Logger::Verbosity::WARN,
});

// update the mute state (since it's a flip-flop and may have been set if we
// restarted without power loss)
espp::EspBox::get().mute(mute_button_->is_pressed());
return true;
}

Expand Down

0 comments on commit 24aa5da

Please sign in to comment.