FluxSand 1.0
FluxSand - Interactive Digital Hourglass
Loading...
Searching...
No Matches
ModeManager Class Reference

Public Types

enum class  Mode : uint8_t {
  TIME , HUMIDITY , TEMPERATURE , STOPWATCH ,
  TIMER , MODE_NUM
}
 

Public Member Functions

void NextMode ()
 
Mode GetMode () const
 
void SetMode (Mode mode)
 
void SetLandscape (bool val)
 
bool IsLandscape () const
 
void StartStopwatch ()
 
void StopStopwatch ()
 
int64_t GetStopwatchSeconds () const
 
bool IsStopwatchRunning () const
 
void StartTimer (int duration_sec)
 
void StopTimer ()
 
int64_t GetRemainingTimerSeconds ()
 
bool IsTimerRunning () const
 
int GetMaxTimerDuration () const
 
void AdjustTimer (int delta_sec)
 

Private Attributes

Mode mode_
 
bool landscape_ = false
 
bool stopwatch_running_ = false
 
std::chrono::steady_clock::time_point stopwatch_start_time_
 
int64_t stopwatch_elapsed_sec_ = 0
 
bool timer_active_ = false
 
std::chrono::steady_clock::time_point timer_start_time_
 
int timer_duration_sec_ = 0
 
int max_duration_sec_ = 0
 

Detailed Description

Definition at line 7 of file mode_manager.hpp.

Member Enumeration Documentation

◆ Mode

enum class ModeManager::Mode : uint8_t
strong

Definition at line 10 of file mode_manager.hpp.

10 : uint8_t {
11 TIME, // Clock display
12 HUMIDITY, // Humidity display
13 TEMPERATURE, // Temperature display
14 STOPWATCH, // Stopwatch mode
15 TIMER, // Countdown timer mode
16 MODE_NUM // Total number of modes (used for cycling)
17 };

Constructor & Destructor Documentation

◆ ModeManager()

ModeManager::ModeManager ( )
inline

Definition at line 20 of file mode_manager.hpp.

20: mode_(Mode::TIME) {}

Member Function Documentation

◆ AdjustTimer()

void ModeManager::AdjustTimer ( int  delta_sec)
inline

Definition at line 118 of file mode_manager.hpp.

118 {
119 if (!timer_active_) {
120 timer_duration_sec_ = std::clamp(timer_duration_sec_ + delta_sec, 0,
121 60 * 99 - 1); // max 99 minutes
122 }
123 }

◆ GetMaxTimerDuration()

int ModeManager::GetMaxTimerDuration ( ) const
inline

Definition at line 115 of file mode_manager.hpp.

115{ return max_duration_sec_; }

◆ GetMode()

Mode ModeManager::GetMode ( ) const
inline

Definition at line 29 of file mode_manager.hpp.

29{ return mode_; }

◆ GetRemainingTimerSeconds()

int64_t ModeManager::GetRemainingTimerSeconds ( )
inline

Definition at line 94 of file mode_manager.hpp.

94 {
95 int64_t remaining = timer_duration_sec_;
96 if (timer_active_) {
97 auto now = std::chrono::steady_clock::now();
98 int64_t elapsed = std::chrono::duration_cast<std::chrono::seconds>(
99 now - timer_start_time_)
100 .count();
101 if (elapsed >= timer_duration_sec_) {
102 remaining = 0;
103 std::cout << "Timer finished\n";
104 } else {
105 remaining -= elapsed;
106 }
107 }
108 return remaining;
109 }

◆ GetStopwatchSeconds()

int64_t ModeManager::GetStopwatchSeconds ( ) const
inline

Definition at line 60 of file mode_manager.hpp.

60 {
61 int64_t display_sec = stopwatch_elapsed_sec_;
62 if (stopwatch_running_) {
63 auto now = std::chrono::steady_clock::now();
64 display_sec += std::chrono::duration_cast<std::chrono::seconds>(
65 now - stopwatch_start_time_)
66 .count();
67 }
68 return display_sec;
69 }

◆ IsLandscape()

bool ModeManager::IsLandscape ( ) const
inline

Definition at line 36 of file mode_manager.hpp.

36{ return landscape_; }

◆ IsStopwatchRunning()

bool ModeManager::IsStopwatchRunning ( ) const
inline

Definition at line 72 of file mode_manager.hpp.

72{ return stopwatch_running_; }

◆ IsTimerRunning()

bool ModeManager::IsTimerRunning ( ) const
inline

Definition at line 112 of file mode_manager.hpp.

112{ return timer_active_; }

◆ NextMode()

void ModeManager::NextMode ( )
inline

Definition at line 23 of file mode_manager.hpp.

23 {
24 mode_ = static_cast<Mode>((static_cast<int>(mode_) + 1) %
25 static_cast<int>(Mode::MODE_NUM));
26 }

◆ SetLandscape()

void ModeManager::SetLandscape ( bool  val)
inline

Definition at line 35 of file mode_manager.hpp.

35{ landscape_ = val; }

◆ SetMode()

void ModeManager::SetMode ( Mode  mode)
inline

Definition at line 32 of file mode_manager.hpp.

32{ mode_ = mode; }

◆ StartStopwatch()

void ModeManager::StartStopwatch ( )
inline

Definition at line 41 of file mode_manager.hpp.

41 {
42 if (!stopwatch_running_) {
43 stopwatch_start_time_ = std::chrono::steady_clock::now();
44 stopwatch_running_ = true;
45 mode_ = Mode::STOPWATCH;
46 std::cout << "Stopwatch started\n";
47 }
48 }

◆ StartTimer()

void ModeManager::StartTimer ( int  duration_sec)
inline

Definition at line 77 of file mode_manager.hpp.

77 {
78 timer_duration_sec_ = duration_sec;
79 max_duration_sec_ = duration_sec;
80 timer_start_time_ = std::chrono::steady_clock::now();
81 timer_active_ = true;
82 mode_ = Mode::TIMER;
83 std::cout << "Timer started for " << duration_sec << " seconds\n";
84 }

◆ StopStopwatch()

void ModeManager::StopStopwatch ( )
inline

Definition at line 51 of file mode_manager.hpp.

51 {
52 if (stopwatch_running_) {
53 stopwatch_running_ = false;
54 stopwatch_elapsed_sec_ = 0;
55 std::cout << "Stopwatch stopped\n";
56 }
57 }

◆ StopTimer()

void ModeManager::StopTimer ( )
inline

Definition at line 87 of file mode_manager.hpp.

87 {
88 timer_active_ = false;
89 timer_duration_sec_ = 0;
90 std::cout << "Timer stopped\n";
91 }

Field Documentation

◆ landscape_

bool ModeManager::landscape_ = false
private

Definition at line 127 of file mode_manager.hpp.

◆ max_duration_sec_

int ModeManager::max_duration_sec_ = 0
private

Definition at line 138 of file mode_manager.hpp.

◆ mode_

Mode ModeManager::mode_
private

Definition at line 126 of file mode_manager.hpp.

◆ stopwatch_elapsed_sec_

int64_t ModeManager::stopwatch_elapsed_sec_ = 0
private

Definition at line 132 of file mode_manager.hpp.

◆ stopwatch_running_

bool ModeManager::stopwatch_running_ = false
private

Definition at line 130 of file mode_manager.hpp.

◆ stopwatch_start_time_

std::chrono::steady_clock::time_point ModeManager::stopwatch_start_time_
private

Definition at line 131 of file mode_manager.hpp.

◆ timer_active_

bool ModeManager::timer_active_ = false
private

Definition at line 135 of file mode_manager.hpp.

◆ timer_duration_sec_

int ModeManager::timer_duration_sec_ = 0
private

Definition at line 137 of file mode_manager.hpp.

◆ timer_start_time_

std::chrono::steady_clock::time_point ModeManager::timer_start_time_
private

Definition at line 136 of file mode_manager.hpp.


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