Skip to content

Commit 2fec8b0

Browse files
committed
Finish DisplayNetworkHealth.
1 parent f348cbf commit 2fec8b0

6 files changed

Lines changed: 449 additions & 11 deletions

File tree

firmware-display/components/GFX/Adafruit_GFX.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ Adafruit_GFX_Button::Adafruit_GFX_Button(void) { _gfx = 0; }
15471547
void Adafruit_GFX_Button::initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
15481548
uint16_t w, uint16_t h, uint16_t outline,
15491549
uint16_t fill, uint16_t textcolor,
1550-
char *label, uint8_t textsize) {
1550+
const char *label, uint8_t textsize) {
15511551
// Tweak arguments and pass to the newer initButtonUL() function...
15521552
initButtonUL(gfx, x - (w / 2), y - (h / 2), w, h, outline, fill, textcolor,
15531553
label, textsize);
@@ -1573,7 +1573,7 @@ void Adafruit_GFX_Button::initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
15731573
void Adafruit_GFX_Button::initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
15741574
uint16_t w, uint16_t h, uint16_t outline,
15751575
uint16_t fill, uint16_t textcolor,
1576-
char *label, uint8_t textsize_x,
1576+
const char *label, uint8_t textsize_x,
15771577
uint8_t textsize_y) {
15781578
// Tweak arguments and pass to the newer initButtonUL() function...
15791579
initButtonUL(gfx, x - (w / 2), y - (h / 2), w, h, outline, fill, textcolor,
@@ -1599,7 +1599,7 @@ void Adafruit_GFX_Button::initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
15991599
void Adafruit_GFX_Button::initButtonUL(Adafruit_GFX *gfx, int16_t x1,
16001600
int16_t y1, uint16_t w, uint16_t h,
16011601
uint16_t outline, uint16_t fill,
1602-
uint16_t textcolor, char *label,
1602+
uint16_t textcolor, const char *label,
16031603
uint8_t textsize) {
16041604
initButtonUL(gfx, x1, y1, w, h, outline, fill, textcolor, label, textsize,
16051605
textsize);
@@ -1625,7 +1625,7 @@ void Adafruit_GFX_Button::initButtonUL(Adafruit_GFX *gfx, int16_t x1,
16251625
void Adafruit_GFX_Button::initButtonUL(Adafruit_GFX *gfx, int16_t x1,
16261626
int16_t y1, uint16_t w, uint16_t h,
16271627
uint16_t outline, uint16_t fill,
1628-
uint16_t textcolor, char *label,
1628+
uint16_t textcolor, const char *label,
16291629
uint8_t textsize_x, uint8_t textsize_y) {
16301630
_x1 = x1;
16311631
_y1 = y1;

firmware-display/components/GFX/include/Adafruit_GFX.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,18 @@ class Adafruit_GFX_Button {
246246
// "Classic" initButton() uses center & size
247247
void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w,
248248
uint16_t h, uint16_t outline, uint16_t fill,
249-
uint16_t textcolor, char *label, uint8_t textsize);
249+
uint16_t textcolor, const char *label, uint8_t textsize);
250250
void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w,
251251
uint16_t h, uint16_t outline, uint16_t fill,
252-
uint16_t textcolor, char *label, uint8_t textsize_x,
252+
uint16_t textcolor, const char *label, uint8_t textsize_x,
253253
uint8_t textsize_y);
254254
// New/alt initButton() uses upper-left corner & size
255255
void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w,
256256
uint16_t h, uint16_t outline, uint16_t fill,
257-
uint16_t textcolor, char *label, uint8_t textsize);
257+
uint16_t textcolor, const char *label, uint8_t textsize);
258258
void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w,
259259
uint16_t h, uint16_t outline, uint16_t fill,
260-
uint16_t textcolor, char *label, uint8_t textsize_x,
260+
uint16_t textcolor, const char *label, uint8_t textsize_x,
261261
uint8_t textsize_y);
262262
void drawButton(bool inverted = false);
263263
bool contains(int16_t x, int16_t y);

firmware-display/main/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Author : $Author$
99
# Created By : Robert Heller
1010
# Created : Tue Sep 3 16:51:09 2024
11-
# Last Modified : <240906.1514>
11+
# Last Modified : <240909.0939>
1212
#
1313
# Description
1414
#
@@ -65,6 +65,7 @@ set(deps
6565
)
6666

6767
idf_component_register(SRCS esp32networkhealth.cpp NetworkHealthScan.cpp
68+
DisplayNetworkHealth.cpp
6869
REQUIRES "${deps}")
6970

7071

@@ -81,6 +82,7 @@ set(CDI_VERSION "0x0100")
8182

8283
set_source_files_properties(esp32networkhealth.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=maybe-uninitialized -Wno-implicit-fallthrough -Wno-ignored-qualifiers")
8384
set_source_files_properties(NetworkHealthScan.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=maybe-uninitialized -Wno-implicit-fallthrough -Wno-ignored-qualifiers")
85+
set_source_files_properties(DisplayNetworkHealth.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=maybe-uninitialized -Wno-implicit-fallthrough -Wno-ignored-qualifiers")
8486
set_source_files_properties(esp32networkhealth.cpp PROPERTIES COMPILE_DEFINITIONS "SNIP_PROJECT_PAGE=\"${SNIP_PROJECT_PAGE}\"; SNIP_HW_VERSION=\"${SNIP_HW_VERSION}\"; SNIP_SW_VERSION=\"${SNIP_SW_VERSION}\"; SNIP_PROJECT_NAME=\"${SNIP_PROJECT_NAME}\"; CDI_VERSION=${CDI_VERSION}")
8587

8688
set(CDIDEPS
Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
// -!- C++ -!- //////////////////////////////////////////////////////////////
2+
//
3+
// System :
4+
// Module :
5+
// Object Name : $RCSfile$
6+
// Revision : $Revision$
7+
// Date : $Date$
8+
// Author : $Author$
9+
// Created By : Robert Heller
10+
// Created : Mon Sep 9 09:39:50 2024
11+
// Last Modified : <240909.1520>
12+
//
13+
// Description
14+
//
15+
// Notes
16+
//
17+
// History
18+
//
19+
/////////////////////////////////////////////////////////////////////////////
20+
//
21+
// Copyright (C) 2024 Robert Heller D/B/A Deepwoods Software
22+
// 51 Locke Hill Road
23+
// Wendell, MA 01379-9728
24+
//
25+
// This program is free software; you can redistribute it and/or modify
26+
// it under the terms of the GNU General Public License as published by
27+
// the Free Software Foundation; either version 2 of the License, or
28+
// (at your option) any later version.
29+
//
30+
// This program is distributed in the hope that it will be useful,
31+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33+
// GNU General Public License for more details.
34+
//
35+
// You should have received a copy of the GNU General Public License
36+
// along with this program; if not, write to the Free Software
37+
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38+
//
39+
//
40+
//
41+
//////////////////////////////////////////////////////////////////////////////
42+
43+
static const char rcsid[] = "@(#) : $Id$";
44+
45+
#include "openlcb/RefreshLoop.hxx"
46+
#include "Adafruit_HX8357.h"
47+
#include "Adafruit_GFX.h"
48+
#include "Adafruit_TSC2007.h"
49+
#include "hardware.hxx"
50+
#include "DisplayNetworkHealth.hxx"
51+
#include "NetworkHealthScan.hxx"
52+
#include "StringUtils.hxx"
53+
54+
namespace Arduino
55+
{
56+
static long map(long x, long in_min, long in_max, long out_min, long out_max)
57+
{
58+
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
59+
}
60+
}
61+
62+
namespace DisplayNetworkHealth
63+
{
64+
65+
DisplayNetworkHealth::DisplayNetworkHealth(Adafruit_HX8357 *display,
66+
Adafruit_TSC2007 *touch,
67+
NetworkHealthScan *healthScan)
68+
: display_(display)
69+
, touch_(touch)
70+
, healthScan_(healthScan)
71+
, lastTotal_(0)
72+
, nodelist_(display,LISTBOX_X,LISTBOX_Y,LISTBOX_TSIZE,LISTBOX_ITEMS)
73+
{
74+
rescan_.initButtonUL(display_,BUTTON1_X,BUTTONS_Y,BUTTONS_W,BUTTONS_H,
75+
HX8357_WHITE,HX8357_BLACK,HX8357_MAGENTA,
76+
BUTTON1,BUTTONS_TXSZ);
77+
resetDB_.initButtonUL(display_,BUTTON2_X,BUTTONS_Y,BUTTONS_W,BUTTONS_H,
78+
HX8357_WHITE,HX8357_BLACK,HX8357_MAGENTA,
79+
BUTTON2,BUTTONS_TXSZ);
80+
refreshDisplay_();
81+
}
82+
83+
void DisplayNetworkHealth::poll_33hz(openlcb::WriteHelper *helper,
84+
Notifiable *done)
85+
{
86+
if (healthScan_->Total() != lastTotal_)
87+
{
88+
nodelist_.RedrawList(healthScan_->NodeDB_Begin(),
89+
healthScan_->NodeDB_End());
90+
redrawTotals_();
91+
}
92+
processButons_();
93+
done->notify();
94+
}
95+
96+
void DisplayNetworkHealth::refreshDisplay_()
97+
{
98+
display_->fillScreen(HX8357_BLACK);
99+
redrawHeading_();
100+
nodelist_.RedrawList(healthScan_->NodeDB_Begin(),
101+
healthScan_->NodeDB_End());
102+
redrawTotals_();
103+
redrawButtons_();
104+
}
105+
106+
void DisplayNetworkHealth::redrawHeading_()
107+
{
108+
display_->setCursor(HEADING_X,HEADING_Y);
109+
display_->setTextSize(HEADING_TXSZ);
110+
display_->setTextColor(HEADING_COLOR,HEADING_BG);
111+
display_->print(HEADING);
112+
}
113+
114+
void DisplayNetworkHealth::redrawTotals_()
115+
{
116+
char buffer[20];
117+
display_->setCursor(TOTALS_X,TOTALS_Y);
118+
display_->setTextSize(TOTALS_TXSZ);
119+
display_->setTextColor(TOTALS_COLOR,TOTALS_BG);
120+
snprintf(buffer,sizeof(buffer),TOTALS_FORMAT,
121+
healthScan_->Total(),healthScan_->Found(),
122+
healthScan_->Missing(),healthScan_->Added());
123+
display_->print(buffer);
124+
}
125+
126+
void DisplayNetworkHealth::redrawButtons_()
127+
{
128+
rescan_.drawButton();
129+
resetDB_.drawButton();
130+
}
131+
132+
133+
void DisplayNetworkHealth::processButons_()
134+
{
135+
TS_Point p = touch_->getPoint();
136+
if (((p.x == 0) && (p.y == 0)) || (p.z < 10))
137+
{
138+
// this is our way of tracking touch 'release'!
139+
p.x = p.y = p.z = -1;
140+
}
141+
// Scale from ~0->4000 to tft.width using the calibration #'s
142+
if (p.z != -1)
143+
{
144+
int py = Arduino::map(p.x, TSMax_x, TSMin_x, 0, display_->height());
145+
int px = Arduino::map(p.y, TSMin_y, TSMax_y, 0, display_->width());
146+
p.x = px;
147+
p.y = py;
148+
}
149+
if (rescan_.contains(p.x, p.y))
150+
{
151+
rescan_.press(true);
152+
153+
}
154+
else
155+
{
156+
rescan_.press(false);
157+
}
158+
if (resetDB_.contains(p.x, p.y))
159+
{
160+
resetDB_.press(true);
161+
}
162+
else
163+
{
164+
resetDB_.press(false);
165+
}
166+
if (rescan_.justReleased())
167+
{
168+
rescan_.drawButton(false);
169+
healthScan_->ScanNetwork();
170+
}
171+
if (rescan_.justPressed())
172+
{
173+
rescan_.drawButton(true);
174+
return;
175+
}
176+
if (resetDB_.justReleased())
177+
{
178+
resetDB_.drawButton(false);
179+
healthScan_->ResetNodeDB();
180+
}
181+
if (resetDB_.justPressed())
182+
{
183+
resetDB_.drawButton(true);
184+
return;
185+
}
186+
nodelist_.CheckButtons(p.x, p.y);
187+
}
188+
189+
DisplayNetworkHealth::ListBox::ListBox(Adafruit_GFX *gfx,int16_t x, int16_t y,
190+
uint8_t textSize, uint8_t items)
191+
: gfx_(gfx)
192+
, x_(x)
193+
, y_(y)
194+
, textSize_(textSize)
195+
, items_(items)
196+
, itemOffset_(0)
197+
, havePrev_(false)
198+
, haveNext_(false)
199+
{
200+
uint16_t w_2 = gfx_->width()/2;
201+
prev_.initButtonUL(gfx_,x_,y_+(items_*(textSize_*8)),w_2,(textSize_*8),
202+
HX8357_WHITE,HX8357_BLACK,HX8357_MAGENTA,
203+
"Prev",textSize_);
204+
next_.initButtonUL(gfx_,x_+w_2,y_+(items_*(textSize_*8)),w_2,
205+
(textSize_*8),HX8357_WHITE,HX8357_BLACK,HX8357_MAGENTA,
206+
"Next",textSize_);
207+
}
208+
void DisplayNetworkHealth::ListBox::RedrawList(
209+
NetworkHealthScan::NodeDB_ConstIterator begin,
210+
NetworkHealthScan::NodeDB_ConstIterator end)
211+
{
212+
begin_ = begin;
213+
end_ = end;
214+
RedrawList(0);
215+
}
216+
217+
void DisplayNetworkHealth::ListBox::RedrawList(uint8_t itemOffset)
218+
{
219+
itemOffset_ = itemOffset;
220+
RedrawList();
221+
}
222+
223+
void DisplayNetworkHealth::ListBox::RedrawList()
224+
{
225+
gfx_->fillRect(x_,y_,gfx_->width(),(textSize_*8)*(items_+1),HX8357_BLACK);
226+
int16_t y=y_;
227+
gfx_->setTextSize(textSize_);
228+
gfx_->setTextColor(HX8357_CYAN,HX8357_BLACK);
229+
auto it = begin_;
230+
std::advance(it, itemOffset_);
231+
havePrev_ = itemOffset_ > 0;
232+
haveNext_ = std::distance(it,end_) > items_;
233+
for (uint8_t i = 0; i < items_; i++)
234+
{
235+
if (it == end_) break;
236+
string nodeidstring = utils::node_id_to_string(it->second.node_id);
237+
gfx_->setCursor(x_,y);
238+
gfx_->print(nodeidstring.c_str());
239+
y += textSize_*8;
240+
it++;
241+
}
242+
if (havePrev_) prev_.drawButton();
243+
if (haveNext_) next_.drawButton();
244+
}
245+
246+
void DisplayNetworkHealth::ListBox::CheckButtons(int16_t x, int16_t y)
247+
{
248+
if (havePrev_)
249+
{
250+
if (prev_.contains(x,y))
251+
{
252+
prev_.press(true);
253+
}
254+
else
255+
{
256+
prev_.press(false);
257+
}
258+
if (prev_.justReleased())
259+
{
260+
prev_.drawButton(false);
261+
if (itemOffset_ >= items_)
262+
{
263+
RedrawList(itemOffset_-items_);
264+
}
265+
}
266+
if (prev_.justPressed())
267+
{
268+
prev_.drawButton(true);
269+
return;
270+
}
271+
}
272+
if (haveNext_)
273+
{
274+
if (next_.contains(x,y))
275+
{
276+
next_.press(true);
277+
}
278+
else
279+
{
280+
next_.press(false);
281+
}
282+
if (next_.justReleased())
283+
{
284+
next_.drawButton(false);
285+
if (std::distance(begin_,end_) > itemOffset_+items_)
286+
{
287+
RedrawList(itemOffset_+items_);
288+
}
289+
}
290+
if (next_.justPressed())
291+
{
292+
next_.drawButton(true);
293+
return;
294+
}
295+
}
296+
}
297+
298+
}

0 commit comments

Comments
 (0)