-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault_mode.cpp
81 lines (77 loc) · 4.58 KB
/
default_mode.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
/* ********************************************************************************************** */
/* */
/* Smart Watch Firmware ::::::::: ::: */
/* default_mode.cpp :+: :+: :+: :+: */
/* +:+ +:+ +:+ +:+ */
/* By: Roman Alexandrov <r.aleksandroff@gmail.com> +#++:++#: +#++:++#++: */
/* +#+ +#+ +#+ +#+ */
/* Created: 2023/06/28 14:49:16 #+# #+# #+# #+# */
/* Updated: 2023/11/12 13:48:41 ### ### ### ### */
/* */
/* */
/* Default working mode. Calls necessary functions to gather or manage information, then */
/* outputs that information onto a screen in a shape of 64x64 pixels widgets. */
/* */
/* ********************************************************************************************** */
#include "header.h"
void ft_default_mode(void)
{
unsigned long millis_counter_1;
unsigned long millis_counter_2;
short battery_charge;
millis_counter_1 = 0;
millis_counter_2 = 0;
system_rtc_mem_read(RTCMEMORYSTART, &rtcValues, sizeof(rtcValues)); // restore variables from RTC memory
ft_wifi_init();
// ft_get_location();
ft_get_weather();
ft_get_time();
ft_setup_ota("Roman's Watch", WiFi.SSID().c_str(), WiFi.psk().c_str());
while (1)
{
if (millis() - millis_counter_1 > 995)
{
ft_system_clock();
rtcMng.program_cycles++;
millis_counter_1 = millis();
}
if (millis() - millis_counter_2 > 350) // loop & display update delay
{
ft_encoder_handle();
display.clearDisplay();
if (rtcMng.program_cycles % 1200 == 0) // toggle these functions once every 20 mins
{
// ft_get_location();
ft_get_weather();
ft_get_time();
}
// ft_battery_level_ui(ft_battery_level());
if (rtcMng.second == 0)
{
battery_charge = ft_battery_level();
if (battery_charge < 10)
rtcMng.state_switch = LOWCHARGE;
}
switch (rtcMng.encoder_counter)
{
case 1: ft_mini_analog_clock_ui(); ft_mini_digital_clock_ui(); break;
case 2: ft_mini_analog_clock_ui(); ft_calendar_ui(); break;
case 3: ft_mini_analog_clock_ui(); ft_weather_ui(); break;
case 4: ft_mini_analog_clock_ui(); ft_moon_phases_ui(); break;
case 5: ft_mini_analog_clock_ui(); ft_ota_start_and_ui(battery_charge); break;
case 6: ft_mini_analog_clock_ui(); ft_diagnostic_screen_ui(); break;
}
display.display();
rtcMng.controls_tracker++;
ft_encoder_handle();
millis_counter_2 = millis();
}
if (rtcMng.controls_tracker == INACTIVITY || rtcMng.state_switch == LOWCHARGE) // Go to Sleep Mode if inactive or low battery
{
rtcMng.state_switch = SLEEP;
system_rtc_mem_write(64, &rtcMng, sizeof(rtcMng)); // save variables for Sleep Mode in RTC memory
system_rtc_mem_write(RTCMEMORYSTART, &rtcValues, sizeof(rtcValues)); // save variables for Work Mode in RTC memory
ESP.deepSleep(100, WAKE_RF_DEFAULT); // exit infinite while loop with reboot, no Wi-Fi sync needed
}
}
}