-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock_machine.hpp
69 lines (60 loc) · 2.06 KB
/
clock_machine.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef _INCLUDE_CLOCK_MACHINE_HPP_
#define _INCLUDE_CLOCK_MACHINE_HPP_
#include "clock_machine_states.hpp"
#include <rotary_encoder.hpp>
#include <wifi_time.hpp>
#include <display.hpp>
#include <DF_player.hpp>
#define NVS_STORAGE "storage"
#define NVS_ALARM_HOUR "alarm_hour"
#define NVS_ALARM_MINUTE "alarm_minute"
#define NVS_WIFI_CREDENTIALS "credentials"
// Forward declaration to resolve circular dependency/include
class ClockState;
class ClockMachine {
public:
ClockMachine(RotaryEncoder* encoder_ref);
void saveAlarmTimeInNVS();
void saveWifiCredentialsInNVS();
void setState(ClockState& newState);
clock_time_t getTimeToAlarm(clock_time_t current_time, clock_time_t alarm_time);
WifiTime* getWifiTime();
Display* getDisplay();
RotaryEncoder* getEncoder();
DFPlayer* getPlayer();
void triggerTimer(uint16_t timer_ms);
void checkWifiStatus(bool force_update);
void run();
void buttonShortPressed();
void buttonLongPressed();
void encoderRotated(rotary_encoder_pos_t position, rotary_encoder_dir_t direction);
~ClockMachine();
clock_time_t stored_time;
bool is_alarm_set = false;
clock_time_t alarm_time;
bool time_has_changed;
struct {
uint8_t crescendo_factor = 6; // "crescendo_factor" half-seconds per volume step. If factor == 2 -> 30 seconds until maximum volume
uint16_t snooze_time_s = 300; // Snooze time in seconds (must be a factor of 5!)
bool alarm_set_confirmation_sound = false;
uint8_t melody_nr = 1;
} settings;
private:
esp_err_t readNVSValues();
void writeNVSDefaultValues();
void checkTimeUpdate(void);
ClockState* state;
WifiTime wifi_time;
Display display;
RotaryEncoder* encoder;
DFPlayer audio_player;
int64_t active_timer_us;
int64_t trigger_timestamp_us;
wifi_credentials_t wifi_credentials;
bool last_wifi_connected_status;
bool last_audio_online_status;
#ifdef MQTT_ACTIVE
bool last_mqtt_connected_status;
#endif
};
#endif /* _INCLUDE_CLOCK_MACHINE_HPP_ */