FluxSand 1.0
FluxSand - Interactive Digital Hourglass
Loading...
Searching...
No Matches
InputHandler Class Reference
Collaboration diagram for InputHandler:

Public Member Functions

void Init (Gpio *btn1, Gpio *btn2, PWM *buzzer, CompGuiX *gui, ModeManager *mode_manager, std::function< void()> onStopwatchToggle, std::function< void()> onTimerStop)
 

Private Attributes

ModeManagermode_manager_ = nullptr
 
CompGuiXgui_ = nullptr
 
PWMbuzzer_ = nullptr
 
std::function< void()> onStopwatchToggle_
 
std::function< void()> onTimerStop_
 
std::binary_semaphore gpio_int_sem_1_ {0}
 
std::binary_semaphore gpio_int_sem_2_ {0}
 

Detailed Description

Definition at line 13 of file input_handler.hpp.

Member Function Documentation

◆ Init()

void InputHandler::Init ( Gpio btn1,
Gpio btn2,
PWM buzzer,
CompGuiX gui,
ModeManager mode_manager,
std::function< void()>  onStopwatchToggle,
std::function< void()>  onTimerStop 
)
inline

Definition at line 16 of file input_handler.hpp.

18 {
19 mode_manager_ = mode_manager;
20 gui_ = gui;
21 buzzer_ = buzzer;
22 onStopwatchToggle_ = std::move(onStopwatchToggle);
23 onTimerStop_ = std::move(onTimerStop);
24
25 // Configure Button 1 interrupt callback:
26 // - Switches to next mode
27 // - Disables sand animation (if any)
28 // - Plays a short beep
30 gpio_int_sem_1_.release(); // Release semaphore to indicate interrupt
31 mode_manager_->NextMode(); // Cycle to the next mode
32 gui_->SandDisable(); // Turn off sand effect
33 std::cout << "Button 1\n";
34 buzzer_->PlayNote(PWM::NoteName::C, 7, 50); // Feedback sound
35 });
36
37 // Configure Button 2 interrupt callback:
38 // - Plays a short beep
39 // - Depending on the current mode:
40 // - In stopwatch mode: toggle start/stop
41 // - In timer mode: stop timer and disable sand animation
43 gpio_int_sem_2_.release(); // Release semaphore to indicate interrupt
44 std::cout << "Button 2\n";
45 buzzer_->PlayNote(PWM::NoteName::C, 7, 50); // Feedback sound
46
47 auto mode = mode_manager_->GetMode();
48 if (mode == ModeManager::Mode::STOPWATCH) {
49 onStopwatchToggle_(); // Toggle stopwatch (start/stop)
50 } else if (mode == ModeManager::Mode::TIMER &&
51 mode_manager_->IsTimerRunning()) {
52 onTimerStop_(); // Stop timer
53 gui_->SandDisable(); // Stop sand animation
54 }
55 });
56 }
void SandDisable()
Disable sand simulation.
Definition comp_gui.hpp:77
void EnableInterruptRisingEdgeWithCallback(Callback cb)
Definition bsp_gpio.hpp:109
void PlayNote(NoteName note, uint32_t octave, uint32_t duration_ms)
Play a musical note based on note name and octave.
Definition bsp_pwm.hpp:121

Field Documentation

◆ buzzer_

PWM* InputHandler::buzzer_ = nullptr
private

Definition at line 61 of file input_handler.hpp.

◆ gpio_int_sem_1_

std::binary_semaphore InputHandler::gpio_int_sem_1_ {0}
private

Definition at line 68 of file input_handler.hpp.

68{0};

◆ gpio_int_sem_2_

std::binary_semaphore InputHandler::gpio_int_sem_2_ {0}
private

Definition at line 69 of file input_handler.hpp.

69{0};

◆ gui_

CompGuiX* InputHandler::gui_ = nullptr
private

Definition at line 60 of file input_handler.hpp.

◆ mode_manager_

ModeManager* InputHandler::mode_manager_ = nullptr
private

Definition at line 59 of file input_handler.hpp.

◆ onStopwatchToggle_

std::function<void()> InputHandler::onStopwatchToggle_
private

Definition at line 63 of file input_handler.hpp.

◆ onTimerStop_

std::function<void()> InputHandler::onTimerStop_
private

Definition at line 64 of file input_handler.hpp.


The documentation for this class was generated from the following file: