-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathother.cpp
91 lines (80 loc) · 4.05 KB
/
other.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
82
83
84
85
86
87
88
89
90
91
/* ********************************************************************************************** */
/* */
/* Smart Watch Firmware ::::::::: ::: */
/* other.cpp :+: :+: :+: :+: */
/* +:+ +:+ +:+ +:+ */
/* By: Roman Alexandrov <r.aleksandroff@gmail.com> +#++:++#: +#++:++#++: */
/* +#+ +#+ +#+ +#+ */
/* Created: 2023/06/28 14:49:16 #+# #+# #+# #+# */
/* Updated: 2023/11/12 13:48:41 ### ### ### ### */
/* */
/* */
/* This file contains all the little utility functions that are not too important to have */
/* their own personal files. They are not necesarrily connected with each other logically. */
/* */
/* ********************************************************************************************** */
#include "header.h"
void ft_button_handle(void)
{
rtcMng.controls_tracker = 0; // Wakes up the system
rtcMng.encoder_counter += 1;
if (rtcMng.encoder_counter >= 7) rtcMng.encoder_counter = 1;
}
void ft_encoder_handle(void)
{
volatile long newPosition = myEnc.read();
if (newPosition != rtcValues.old_position)
{
if (newPosition > rtcValues.old_position)
{
rtcMng.encoder_counter += 1;
if (rtcMng.encoder_counter >= 7) rtcMng.encoder_counter = 1;
}
if (newPosition < rtcValues.old_position)
{
rtcMng.encoder_counter -= 1;
if (rtcMng.encoder_counter <= 0) rtcMng.encoder_counter = 6;
}
rtcValues.old_position = newPosition;
rtcMng.controls_tracker = 0; // Wakes up the system
}
}
void ft_tilt_detector_handle(void)
{
rtcMng.tilt_switch = !rtcMng.tilt_switch;
if (rtcMng.tilt_switch)
rtcMng.controls_tracker = 0; // Wakes up the system
if (!rtcMng.tilt_switch)
rtcMng.controls_tracker = INACTIVITY; // Puts the system to sleep
}
// ADC measures VCC level internally. Do not connect ADC pin to anything and leave it floating!
// Full formula to convert ADC measurements into Battery charge percentage %:
// 100 * (ADC_Reading - Battery_Minimal_Reading) / (Battery_Maximal_Reading - Battery_Minimal_Reading).
// For LiPol Battery, 230mAh, 3.7V: Battery_Maximal_Reading = 4264, Battery_Minimal_Reading = 3235;
// For LiPol Battery, 230mAh, 3.7V: after ADC_Reading decends to the level of Battery_Minimal_Reading, there are 2 mins 12 sec before the battery turns off
short ft_battery_level(void)
{
short battery;
battery = ceil((ESP.getVcc() - 3235) / 10.29); // Removes fractual part from raw % and makes it a whole number
if (battery <= 0)
battery = 0;
if (battery >= 100)
battery = 100;
return (battery);
}
void ft_battery_level_ui(short battery)
{
short oldBattery;
// if (oldBattery != battery)
// { // Charging icon toggle on/off
// if (oldBattery < battery)
// { ПОКАЗАТЬ_ИКОНКУ_ЗАРЯДКИ; }
// else
// { УБРАТЬ_ИКОНКУ_ЗАРЯДКИ; }
// oldBattery = battery;
// }
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println(int(battery));
}