/
TlStatus.cpp
164 lines (140 loc) · 4.55 KB
/
TlStatus.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/************************************************
* Settings tile
*************************************************/
#include "Gui.h"
#include "TlStatus.h"
#include "Version.h"
LV_FONT_DECLARE(Ubuntu_16px);
TlStatus::TlStatus( TileView *parent, TileView *cloned ) :
Container( parent, cloned )
{
this->_battery = new Label( this );
this->_battery->setLongTextMode( LV_LABEL_LONG_BREAK ); // Has to be done BEFORE setWidth()
this->_battery->setWidth( parent->getWidth() ); // otherwise, it is ignored
this->_battery->Align( LV_ALIGN_IN_TOP_LEFT, (const lv_obj_t *)NULL, 0,5 );
this->updAXP( true ); // Initial update otherwise alignment will be wrong
this->_ram = new Label( this );
this->_ram->setLongTextMode( LV_LABEL_LONG_SROLL_CIRC );
this->_ram->setWidth( parent->getWidth()/2 - 5 );
this->_ram->Align( LV_ALIGN_OUT_BOTTOM_LEFT, this->_battery, 0,10 );
this->_ramg = new BarGauge( gaugeStyle, this );
this->_ramg->setSize( parent->getWidth()/2 -10, 16 );
this->_ramg->setPosXY( parent->getWidth()/2 +5, this->_ram->getY() );
this->updRam( true );
this->_PSram = new Label( this );
this->_PSram->setLongTextMode( LV_LABEL_LONG_SROLL_CIRC );
this->_PSram->setWidth( parent->getWidth()/2 - 5 );
this->_PSram->Align( LV_ALIGN_OUT_BOTTOM_LEFT, this->_ram );
this->_PSramg = new BarGauge( gaugeStyle, this );
this->_PSramg->setSize( parent->getWidth()/2 -10, 16 );
this->_PSramg->setPosXY( parent->getWidth()/2 +5, this->_PSram->getY() );
this->updPSRam( true );
/* Display version */
this->_version = new Label( this );
this->_version->seTexttFont( &Ubuntu_16px );
this->_version->setText( "DomoWatch " VERSION_H );
this->_version->Align( LV_ALIGN_IN_BOTTOM_MID );
this->_version->AutoRealign();
/* Display last boot time and reason
* This information will be set once at GUI creation
*/
this->_bootreason = new Label( this );
this->_bootreason->seTexttFont( &Ubuntu_16px );
this->_bootreason->setText( getResetCause() );
this->_bootreason->Align( LV_ALIGN_OUT_TOP_MID, this->_version );
this->_bootreason->AutoRealign();
static char buf[29];
time_t now;
struct tm info;
time( &now );
localtime_r( &now, &info );
strftime( buf, sizeof(buf), "Boot at %H:%M on %d %b %Y", &info );
this->_boottime = new Label( this );
this->_boottime->seTexttFont( &Ubuntu_16px );
this->_boottime->setText( buf );
this->_boottime->Align( LV_ALIGN_OUT_TOP_MID, this->_bootreason );
this->_boottime->AutoRealign();
}
void TlStatus::updAXP( bool init ){
String val = "Voltage : ";
if( init )
val += "?.??";
else
val += ttgo->power->getBattVoltage()/1000;
val += "V\n";
val += (ttgo->power->isChargeing() and !init) ? "Charging :" : "Discharging : ";
if( init )
val += "???.??";
else
val += ttgo->power->isChargeing() ? ttgo->power->getBattChargeCurrent() : ttgo->power->getBattDischargeCurrent();
val += "mA\n";
val += "Temp : ";
if( init )
val += "??.??";
else
val += ttgo->power->getTemp();
#if 0 // Seems note used on TWatch 2020
val += " / TSTemp : ";
if( init )
val += "??.??";
else
val += ttgo->power->getTSTemp();
#else // From BMA chip
val += " / Amb : ";
if( init )
val += "??.??";
else
val += ttgo->bma->temperature();
#endif
val += "\nVBus : ";
if( init )
val += "??.??V / ???.??mA";
else if( ttgo->power->isVBUSPlug() ){
val += ttgo->power->getVbusVoltage() / 1000;
val += "V / ";
val += ttgo->power->getVbusCurrent();
val += "mA";
}
this->_battery->setText( val.c_str() );
}
void TlStatus::updRam( bool init ){
String val = "Ram : ";
if( init )
val += "???8/???? (???%)";
else {
val += String( ESP.getFreeHeap() / 1024 );
val += "/";
val += String( ESP.getHeapSize() / 1024 );
val += " (";
val += String( 100 - ESP.getFreeHeap()*100/ESP.getHeapSize(), DEC);
val += "%)";
}
this->_ram->setText( val.c_str() );
this->_ramg->setValue( 100 - ESP.getFreeHeap()*100/ESP.getHeapSize() );
}
void TlStatus::updPSRam( bool init ){
String val = "PSRam : ";
if( init )
val += "???8/???? (???%)";
else {
val += String( ESP.getFreePsram() / 1024 );
val += "/";
val += String( ESP.getPsramSize() / 1024 );
val += " (";
val += String( 100 - ESP.getFreePsram()*100/ESP.getPsramSize(), DEC);
val += "%)";
}
this->_PSram->setText( val.c_str() );
this->_PSramg->setValue( 100 - ESP.getFreePsram()*100/ESP.getPsramSize() );
}
void TlStatus::updatefields( void ){
this->updAXP();
this->updRam();
this->updPSRam();
}
static void cbUpd( lv_task_t *tsk ){
((TlStatus *)(tsk->user_data))->updatefields();
}
void TlStatus::initAutomation( void ){
this->upd_task = lv_task_create( cbUpd, 1500, LV_TASK_PRIO_LOW, this );
}