-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatuspanel.cpp
More file actions
478 lines (434 loc) · 18.7 KB
/
Copy pathstatuspanel.cpp
File metadata and controls
478 lines (434 loc) · 18.7 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/***************************************************************************
* Copyright (C) 2012 by Jonathan Duddington *
* email: jonsd@users.sourceforge.net *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see: *
* <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include <wx/aboutdlg.h>
#include <wx/colordlg.h>
#include <wx/filename.h>
#include <wx/sizer.h>
#include "auroramon.h"
#pragma region Declarations
wxFont font_big(24, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
wxFont font_medium(19, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
#ifdef __WXMSW__
#define TE_BIG wxTE_RICH | wxTE_DONTWRAP
#define HT_PW0 33
#else
#define TE_BIG wxTE_MULTILINE | wxTE_DONTWRAP
#define HT_PW0 34
#endif
#pragma endregion
void DrawStatusPulse(int pulse)
{//============================
int state;
int colour;
int inv;
int y;
wxClientDC dc(status_panel);
static wxColour red(0x0000d0);
static wxColour red2(0x0010ff);
static wxColour yellow(0x00a0c0);
static wxColour yellow2(0x00d0ff);
static wxColour green(0x087808);
static wxColour green2(0x00e800);
static int colour_on[3] = {0x0020ff, 0x00e800, 0x12c0ff}; // red, green, yellow
static int colour_off[3] = {0x0000c0, 0x087808, 0x00aacc};
static int x = 124;
static int y_inv[2] = {4, 26};
for(inv = 0; inv < 2; inv++)
{
if(inverter_address[inv] > 0)
{
y = y_inv[inv];
if((state = inverters[inv].alive) > 0)
{
if(inverters[inv].alarm != 0)
state = 2;
}
if(pulse & (1 << inv))
{
colour = colour_on[state];
if(inverters[inv].comms_error)
{
if(state == 1)
colour = 0x12c0ff; // green, flashes yellow = retry
inverters[inv].comms_error = 0;
}
else
if((retrieving_data > 0) && (retrieving_inv == inv))
{
if(state == 1)
colour = 0xffe838; // green, flashes cyan = retrieving data
}
dc.SetBrush(wxColour(colour));
dc.DrawRectangle(x+1, y+1, 16, 16);
}
else
{
dc.SetBrush(wxColour(colour_off[state]));
dc.DrawRectangle(x, y, 18, 18);
}
}
}
}
void Mainframe::OnPulseTimer(wxTimerEvent& WXUNUSED(event))
{//==============================================
DrawStatusPulse(0);
}
void Mainframe::OnLogStatusTimer(wxTimerEvent& WXUNUSED(event))
{//==============================================
wxLogStatus(wxEmptyString);
}
// Done 03/08/2022 review layout, re-arrange so that inverter 2 readings are shown below 'stacked' (inverter 1 readings) rather than to the right side
// replaced wxDefaultCoord for Y axis on all SetSize commands
// Added new sytle 'All (v)' to allow inverter data in status panel to be 'stacked' vertically
// Added PlaceReadings instuction to show extra readings fields for second inverter
// FUTURE Maybe make as scrollable field to allow for multiple inverters
void Mainframe::PlaceReadings(int type, int inv, int x, int y, bool show)
{//===============================================================
// type: 1 Inverter power output and Name
// type: 2 Inverter power, voltage, current, input. Temperature
// type: 3 Inverter energy totals
// type: 4 Inverter extra Readings eg Grid volts, frequency
// type: 5 Today energy, both inverters
int ix;
// y = wxDefaultCoord;
int posn;
wxString label;
// type: 1 Inverter power output and Name
if(type == 1)
{
if(show == true)
{
txt_power[inv]->SetSize(x, y, 82, HT_PW0);
txt_static[inv][0]->SetSize(x+15, y+33, wxDefaultCoord, wxDefaultCoord);
}
txt_power[inv]->Show(show);
txt_static[inv][0]->Show(show);
}
// type: 2 Inverter power, voltage, current, input. Temperature
if(type == 2)
{
if(show == true)
{
txt_power1[inv]->SetSize(x, y, 46, 20);
txt_power2[inv]->SetSize(x, y + 22, 46, 20);
txt_volts1[inv]->SetSize(x+66, y, 41, 20);
txt_volts2[inv]->SetSize(x+66, y + 22, 41, 20);
txt_current1[inv]->SetSize(x+126, y, 41, 20);
txt_current2[inv]->SetSize(x+126, y + 22, 41, 20);
txt_efficiency[inv]->SetSize(x+186, y, 41, 20);
txt_temperature[inv]->SetSize(x+186, y + 22, 41, 20);
txt_static[inv][2]->SetSize(x+49, y, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][3]->SetSize(x+49, y + 22, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][4]->SetSize(x+110, y, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][5]->SetSize(x+110, y + 22, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][6]->SetSize(x+170, y, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][7]->SetSize(x+170, y + 22, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][8]->SetSize(x+230, y, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][9]->SetSize(x+230, y + 22, wxDefaultCoord, wxDefaultCoord);
}
txt_power1[inv]->Show(show);
txt_power2[inv]->Show(show);
txt_volts1[inv]->Show(show);
txt_volts2[inv]->Show(show);
txt_current1[inv]->Show(show);
txt_current2[inv]->Show(show);
txt_efficiency[inv]->Show(show);
txt_temperature[inv]->Show(show);
txt_static[inv][2]->Show(show);
txt_static[inv][3]->Show(show);
txt_static[inv][4]->Show(show);
txt_static[inv][5]->Show(show);
txt_static[inv][6]->Show(show);
txt_static[inv][7]->Show(show);
txt_static[inv][8]->Show(show);
txt_static[inv][9]->Show(show);
}
// type: 3 Inverter energy totals
if(type == 3)
{
if(show == true)
{
txt_energy[inv][0]->SetSize(x+24, y, 53, 20);
txt_energy[inv][1]->SetSize(x+24, y + 22, 53, 20);
txt_energy[inv][2]->SetSize(x+117, y, 53, 20);
txt_energy[inv][3]->SetSize(x+117, y + 22, 53, 20);
txt_energy[inv][4]->SetSize(x+210, y, 53, 20);
txt_energy[inv][5]->SetSize(x+210, y + 22, 53, 20);
txt_static[inv][10]->SetSize(x, y, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][11]->SetSize(x+79, y, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][12]->SetSize(x+79, y + 22, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][13]->SetSize(x+172, y, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][14]->SetSize(x+172, y + 22, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][15]->SetSize(x+265, y, wxDefaultCoord, wxDefaultCoord);
txt_static[inv][16]->SetSize(x+265, y + 22, wxDefaultCoord, wxDefaultCoord);
}
txt_energy[inv][0]->Show(show);
txt_energy[inv][1]->Show(show);
txt_energy[inv][2]->Show(show);
txt_energy[inv][3]->Show(show);
txt_energy[inv][4]->Show(show);
txt_energy[inv][5]->Show(show);
txt_static[inv][10]->Show(show);
txt_static[inv][11]->Show(show);
txt_static[inv][12]->Show(show);
txt_static[inv][13]->Show(show);
txt_static[inv][14]->Show(show);
txt_static[inv][15]->Show(show);
txt_static[inv][16]->Show(show);
}
// type: 4 Inverter extra Readings eg Grid volts, frequency
if(type == 4)
{
posn = 0;
for(ix=0; ix < N_EXTRA_READINGS; ix++)
{
if(extra_readings[ix].status_slot != 0)
{
if (ix & 1)
{
txt_dsp_param[inv][posn]->SetSize(x + 92 * (posn / 2), y + 22, 46, 20);
txt_dsp_label[inv][posn]->SetSize(x + 48 + 92 * (posn / 2), y + 22, wxDefaultCoord, wxDefaultCoord);
}
else
{
txt_dsp_param[inv][posn]->SetSize(x + 92 * (posn / 2), y, 46, 20);
txt_dsp_label[inv][posn]->SetSize(x + 48 + 92 * (posn / 2), y, wxDefaultCoord, wxDefaultCoord);
}
label = wxString(extra_reading_types[extra_readings[ix].type].mnemonic, wxConvLocal);
label.Replace(_T("_"), _T(" "));
txt_dsp_label[inv][posn]->SetLabel(label);
txt_dsp_param[inv][posn]->Show(show);
txt_dsp_label[inv][posn]->Show(show);
extra_readings[ix].status_slot = posn+1;
posn++;
}
}
while(posn < N_EXTRA_READINGS)
{
txt_dsp_param[inv][posn]->Show(false);
txt_dsp_label[inv][posn]->Show(false);
posn++;
}
}
// type: 5 Today energy, both inverters
if(type == 5)
{
if(show == true)
{
txt_energy[0][0]->SetSize(x, 1, 52, 20);
txt_energy[1][0]->SetSize(x, 23, 52, 20);
}
txt_energy[0][0]->Show(show);
txt_energy[1][0]->Show(show);
}
} // end of PlaceReadings
void Mainframe::SetupStatusPanel(int control)
{//=========================================
// resize status_panel based on number of inverters configured
if (inverter_address[1] == 0)
{
// only one inverter
status_panel->SetSize(GetSize().GetWidth(), 52);
status_panel->Layout();
status_panel->Refresh();
mainframe->Layout();
}
else
{
// two inverters
status_panel->SetClientSize(GetSize().GetWidth(), 104);
status_panel->Layout();
status_panel->Refresh();
mainframe->Layout();
}
// control bit 0: inverter addresses may have changed
// style 0: show all - horizontal
// 1: show all - stacked vertical
// 2: show all inverter 0
// 3: show all inverter 1
// 4: show some
int ix;
int style;
// Show Inverter ID
if(control & 1)
{
for(ix=0; ix<N_INV; ix++)
{
if(inverter_address[ix] == 0)
{
power_total[ix] = 0;
inverters[ix].alive = 0;
}
else
{
txt_static[ix][0]->SetLabel(wxString::Format(_T("Inverter #%d"), inverter_address[ix]));
}
}
}
if(control & 2)
{
for(ix=0; ix < N_EXTRA_READINGS; ix++)
{
txt_dsp_param[0][ix]->Clear();
txt_dsp_param[1][ix]->Clear();
}
}
// set via settings | charts | Status Bar | {All, Some, Inv A, Inv B}
style = chart_pages[graph_panel->page].status_type;
if(inverter_address[1] == 0)
{
// only one inverter;
// PlaceReadings(int type, int inv, int x, bool show
PlaceReadings(1, 0, 0, 1, false);
PlaceReadings(1, 1, 0, 23, false);
PlaceReadings(2, 0, 149, 1, true);
PlaceReadings(2, 1, 0, 23, false);
PlaceReadings(3, 0, 423, 1, true);
PlaceReadings(3, 1, 0, 23, false);
PlaceReadings(4, 0, 749, 1, true);
PlaceReadings(4, 1, 0, 23, false);
}
else
{
// PlaceReadings(int type, int inv, int x, bool show
// PlaceReadings(1, 0, 149, true);
if(style == 0)
{
// all - horizontal
PlaceReadings(1, 0, 149, 1, true);
PlaceReadings(1, 1, 518, 1, true);
PlaceReadings(2, 0, 239, 1, true);
PlaceReadings(2, 1, 608, 1, true);
PlaceReadings(3, 0, 887, 1, true);
PlaceReadings(3, 1, 1207, 1, true);
PlaceReadings(4, 0, 1527, 1, true);
PlaceReadings(4, 1, 1727, 1, true);
}
if(style == 1)
{
// All - vertical eg stacked
PlaceReadings(1, 0, 149, 1, true);
PlaceReadings(1, 1, 149, 50, true);
PlaceReadings(2, 0, 239, 1, true);
PlaceReadings(2, 1, 239, 50, true);
PlaceReadings(3, 0, 518, 1, true);
PlaceReadings(3, 1, 518, 50, true);
PlaceReadings(4, 0, 849, 1, true);
PlaceReadings(4, 1, 849, 50, true);
}
if(style == 2)
{
// inverter A
PlaceReadings(1, 0, 149, 1, true);
PlaceReadings(1, 1, 0, 1, false);
PlaceReadings(2, 0, 239, 1, true);
PlaceReadings(2, 1, 0, 1, false);
PlaceReadings(3, 0, 518, 1, true);
PlaceReadings(3, 1, 0, 1, false);
PlaceReadings(4, 0, 849, 1, true);
PlaceReadings(4, 1, 0, 1, false);
}
if(style == 3)
{
// inverter B
PlaceReadings(1, 0, 0, 1, false);
PlaceReadings(1, 1, 149, 1, true);
PlaceReadings(2, 0, 0, 1, false);
PlaceReadings(2, 1, 239, 1, true);
PlaceReadings(3, 0, 0, 1, false);
PlaceReadings(3, 1, 518, 1, true);
PlaceReadings(4, 0, 0, 1, false);
PlaceReadings(4, 1, 849, 1, true);
}
if (style == 4)
{
// some
PlaceReadings(1, 0, 149, 1, true);
PlaceReadings(1, 1, 518, 1, true);
PlaceReadings(2, 0, 239, 1, true);
PlaceReadings(2, 1, 608, 1, true);
PlaceReadings(3, 0, 0, 1, false);
PlaceReadings(3, 1, 0, 1, false);
PlaceReadings(4, 0, 0, 1, false);
PlaceReadings(4, 1, 0, 1, false);
PlaceReadings(5, 0, 961, 1, false); // type: 5 Today energy, both inverters
}
}
for(ix=0; ix<2; ix++)
{
ShowEnergy(ix);
txt_energy[ix][1]->ChangeValue(wxString::Format(_T("%d"), inverters[ix].peak));
}
}
void Mainframe::MakeStatusPanel(void)
{//==================================
int ix;
int inv;
int y;
// Sets out the various controls to show Inverter data, only Y coord used, X over written in PlaceReadings() by data passed from SetupStatusPanel()
// Show Total instantaneous energy, sum both inverters
txt_powertot = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0,2), wxSize(116,42), TE_BIG | wxTE_READONLY | wxTE_CENTRE);
txt_powertot->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, font_big));
// for each inverter
for(inv=0; inv<2; inv++)
{
// Inverter output and name
txt_power[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0,1), wxSize(82,HT_PW0), TE_BIG | wxTE_READONLY | wxTE_CENTRE);
txt_power[inv]->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, font_medium));
txt_static[inv][0] = new wxStaticText(status_panel, -1, _T(""), wxPoint(0, 33));
// adds controls to 'status_panel' show key values from inverters
txt_power1[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, 1), wxSize(46, 20), wxTE_READONLY | wxTE_CENTRE);
txt_power2[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, 23), wxSize(46, 20), wxTE_READONLY | wxTE_CENTRE);
txt_volts1[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, 1), wxSize(40, 20), wxTE_READONLY | wxTE_CENTRE);
txt_volts2[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, 23), wxSize(40, 20), wxTE_READONLY | wxTE_CENTRE);
txt_current1[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, 1), wxSize(40, 20), wxTE_READONLY | wxTE_CENTRE);
txt_current2[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, 23), wxSize(40, 20), wxTE_READONLY | wxTE_CENTRE);
txt_efficiency[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, 1), wxSize(40, 20), wxTE_READONLY | wxTE_CENTRE);
txt_temperature[inv] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, 23), wxSize(40, 20), wxTE_READONLY | wxTE_CENTRE);
// Adds labels for respective fields
txt_static[inv][2] = new wxStaticText(status_panel, -1, _T("W"), wxPoint(0, 4));
txt_static[inv][3] = new wxStaticText(status_panel, -1, _T("W"), wxPoint(0, 26));
txt_static[inv][4] = new wxStaticText(status_panel, -1, _T("V"), wxPoint(0, 4));
txt_static[inv][5] = new wxStaticText(status_panel, -1, _T("V"), wxPoint(0, 26));
txt_static[inv][6] = new wxStaticText(status_panel, -1, _T("A"), wxPoint(0, 4));
txt_static[inv][7] = new wxStaticText(status_panel, -1, _T("A"), wxPoint(0, 26));
txt_static[inv][8] = new wxStaticText(status_panel, -1, _T("%"), wxPoint(0, 4));
txt_static[inv][9] = new wxStaticText(status_panel, -1, _T("deg"), wxPoint(0, 26));
// adds Inverter Energy Summary
txt_static[inv][10] = new wxStaticText(status_panel, -1, _T("kWh"), wxPoint(0, 4));
for(ix=0; ix<6; ix++)
{
static const wxString energy_names[] = {_T("today"), _T("peakW"), _T("month"), _T("year"), _T("total"), _T("partial")};
y = 1;
if(ix & 1)
y = 23;
txt_energy[inv][ix] = new wxTextCtrl(status_panel, -1, _T(""), wxPoint(0, y), wxSize(46, 20), wxTE_READONLY | wxTE_CENTRE);
txt_static[inv][ix+11] = new wxStaticText(status_panel, -1, energy_names[ix], wxPoint(0, y+3));
}
// adds controls for defined extra readings
for(ix=0; ix<N_EXTRA_READINGS; ix++)
{
y = 1;
if(ix & 1)
y = 23;
txt_dsp_param[inv][ix] = new wxTextCtrl(status_panel, -1, wxEmptyString, wxPoint(0, y), wxSize(46, 20), wxTE_READONLY | wxTE_CENTRE);
txt_dsp_label[inv][ix] = new wxStaticText(status_panel, -1, wxEmptyString, wxPoint(0, y+3));
}
}
} // end of MakeStatusPanal