CheeseBoard
A library for use with the CheeseBoard Cheddar platform
GfxNetInfo.cpp
1 #include <MutilaDebug.h>
2 #include <Millis.h>
3 #include "GfxNetInfo.h"
4 #include "GfxTextBox.h"
5 #include "GfxSignalStrength.h"
6 #include "CbOledDisplay.h"
7 #include "CheeseboardConfig.h"
8 
9 GfxNetInfo::GfxNetInfo(String newSsid, int8_t newChannel, uint8_t newSignal) :
10  _ssid(newSsid),
11  _channel(newChannel),
12  _signal(newSignal),
13  _lastSeenMs(Millis())
14 {
15 }
16 
17 GfxNetInfo::~GfxNetInfo()
18 {
19 }
20 
21 GfxNetInfo::GfxNetInfo(const GfxNetInfo& other)
22 {
23  _ssid = other._ssid;
24  _channel = other._channel;
25  _signal = other._signal;
26  _lastSeenMs = other._lastSeenMs;
27 }
28 
29 GfxNetInfo& GfxNetInfo::operator=(const GfxNetInfo& other)
30 {
31  _ssid = other._ssid;
32  _channel = other._channel;
33  _signal = other._signal;
34  _lastSeenMs = other._lastSeenMs;
35  return *this;
36 }
37 
38 void GfxNetInfo::draw(uint16_t xOffset, uint16_t yOffset)
39 {
40  GfxSignalStrength gfxSig;
41  GfxTextBox gfxSeen(20, lastSeen());
42  GfxTextBox gfxSsid(width() - 20 - gfxSig.width(), ssid());
43 
44  gfxSig.setSignal(signal());
45 
46  gfxSig.draw(xOffset, yOffset);
47  gfxSeen.draw(xOffset+gfxSig.width(), yOffset);
48  gfxSsid.draw(xOffset+gfxSig.width()+gfxSeen.width(), yOffset);
49 }
50 
52 {
53  return CBOLED_MESSAGE_FONT_HEIGHT + (2*CBOLED_MESSAGE_FONT_VSEP);
54 }
55 
57 {
58  return 128;
59 }
60 
62 {
63  return _ssid;
64 }
65 
67 {
68  return _channel;
69 }
70 
72 {
73  return _signal;
74 }
75 
77 {
78  return _lastSeenMs;
79 }
80 
82 {
83  uint32_t ago = (Millis() - _lastSeenMs) / 1000;
84  String s;
85  if (ago >= 3600) {
86  s += String(ago/3600);
87  s += 'h';
88  } else if (ago >= 60) {
89  s += String(ago/60);
90  s += 'm';
91  } else {
92  s += String(ago);
93  s += 's';
94  }
95  return s;
96 }
97 
98 void GfxNetInfo::update(int8_t newChannel, uint8_t newSignal)
99 {
100  _channel = newChannel;
101  _signal = newSignal;
102  _lastSeenMs = Millis();
103 }
104 
105 bool GfxNetInfo::operator==(const GfxNetInfo& other)
106 {
107  return _ssid == other._ssid;
108 }
109 
void draw(uint16_t xOffset=0, uint16_t yOffset=0)
Definition: GfxNetInfo.cpp:38
virtual uint16_t width()=0
uint16_t height()
Definition: GfxNetInfo.cpp:51
int8_t channel()
get the channel
Definition: GfxNetInfo.cpp:66
void update(int8_t newChannel, uint8_t newSignal)
Updates the ephemeral details for this ssid.
Definition: GfxNetInfo.cpp:98
uint8_t signal()
get the last signal strength
Definition: GfxNetInfo.cpp:71
uint16_t width()
Definition: GfxTextBox.cpp:33
uint32_t lastSeenMs()
get last seen ms
Definition: GfxNetInfo.cpp:76
uint16_t width()
Definition: GfxNetInfo.cpp:56
String lastSeen()
get last seen in human readable form
Definition: GfxNetInfo.cpp:81
String ssid()
get the ssid
Definition: GfxNetInfo.cpp:61
void draw(uint16_t xOffset=0, uint16_t yOffset=0)
Definition: GfxTextBox.cpp:12
void draw(uint16_t xOffset=0, uint16_t yOffset=0)