Skip to content

Commit 9c9c331

Browse files
committed
display/screen experiment - not enabled
1 parent 82ebe1c commit 9c9c331

File tree

4 files changed

+344
-0
lines changed

4 files changed

+344
-0
lines changed

sfeDataLoggerIoT/sfeDLDisplay.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
*---------------------------------------------------------------------------------
3+
*
4+
* Copyright (c) 2022-2023, SparkFun Electronics Inc. All rights reserved.
5+
* This software includes information which is proprietary to and a
6+
* trade secret of SparkFun Electronics Inc. It is not to be disclosed
7+
* to anyone outside of this organization. Reproduction by any means
8+
* whatsoever is prohibited without express written permission.
9+
*
10+
*---------------------------------------------------------------------------------
11+
*/
12+
#pragma once
13+
14+
#include "sfeDLGraphx.h"
15+
#include "sfeDLGrWiFi.h"
16+
#include "sfeDLGrBattery.h"
17+
18+
#include <Flux/flxCoreEvent.h>
19+
#include <Flux/flxDevMicroOLED.h>
20+
#include <Flux/flxWiFiESP32.h>
21+
#include <Flux/flxDevMAX17048.h>
22+
#include <Flux/flxFSSDMMCard.h>
23+
24+
25+
class sfeDLDisplay : public sfeDLGrView
26+
{
27+
28+
public:
29+
30+
sfeDLDisplay() : _battery{nullptr}, _screen{nullptr}, _wifi{nullptr}, _card{nullptr}
31+
{
32+
}
33+
34+
void initialize(flxDevMicroOLED *screen, flxWiFiESP32 *wifi, flxDevMAX17048 *fuel, flxFSSDMMCard *card)
35+
{
36+
_screen = screen;
37+
_wifi = wifi;
38+
_battery = fuel;
39+
_card = card;
40+
41+
// Setup our WiFi graphic
42+
_grWiFi.origin(4, 1);
43+
_grWiFi.listenForUpdate(_on_wifi);
44+
add(&_grWiFi);
45+
_grWiFi.update();
46+
47+
// // Setup our Battery graphic
48+
// _grBattery.origin(24, 1);
49+
// _grBattery.listenForUpdate(_on_battery);
50+
// add(&_grBattery);
51+
// _grBattery.update();
52+
53+
}
54+
55+
void onGrUpdate(void)
56+
{
57+
if (!_screen)
58+
return;
59+
60+
if (_wifi)
61+
_on_wifi.emit(_wifi->rating());
62+
63+
if (_battery)
64+
{
65+
float batterySOC = _battery->getSOC();
66+
uint level = batterySOC > 70. ? 4 : batterySOC > 40. ? 3 : batterySOC > 15. ? 2 : 1;
67+
_on_battery.emit(level);
68+
}
69+
70+
draw(_screen);
71+
}
72+
73+
void update(void)
74+
{
75+
if (_screen)
76+
sfeDLGrView::update(_screen);
77+
}
78+
79+
private:
80+
81+
flxDevMAX17048 *_battery;
82+
flxDevMicroOLED *_screen;
83+
flxWiFiESP32 *_wifi;
84+
flxFSSDMMCard *_card;
85+
86+
flxSignalUInt _on_wifi;
87+
sfeDLGrWiFi _grWiFi;
88+
89+
flxSignalUInt _on_battery;
90+
sfeDLGrBattery _grBattery;
91+
92+
};
93+

sfeDataLoggerIoT/sfeDLGrBattery.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
*---------------------------------------------------------------------------------
3+
*
4+
* Copyright (c) 2022-2023, SparkFun Electronics Inc. All rights reserved.
5+
* This software includes information which is proprietary to and a
6+
* trade secret of SparkFun Electronics Inc. It is not to be disclosed
7+
* to anyone outside of this organization. Reproduction by any means
8+
* whatsoever is prohibited without express written permission.
9+
*
10+
*---------------------------------------------------------------------------------
11+
*/
12+
#pragma once
13+
14+
#include "sfeDLGraphx.h"
15+
16+
// Icons
17+
const int kIconBatteryHeight = 12;
18+
const int kIconBatteryWidth = 19;
19+
20+
const uint8_t kIconsBattery[4][38] = {
21+
// Dead
22+
{0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x08, 0xF8,
23+
0x0F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x01, 0x01},
24+
// 1
25+
{0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x08, 0xF8,
26+
0x0F, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x01, 0x01},
27+
// 2
28+
{0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F, 0x08, 0xF8,
29+
0x0F, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x01, 0x01},
30+
// FULL
31+
{0xFF, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x01, 0xFD, 0xFD, 0xFD, 0x01, 0x0F, 0x08, 0xF8,
32+
0x0F, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x08, 0x0B, 0x0B, 0x0B, 0x08, 0x0F, 0x01, 0x01}
33+
};
34+
35+
class sfeDLGrBattery : public sfeDLGraphic
36+
{
37+
38+
public:
39+
40+
sfeDLGrBattery() : _currentBitmap{3}
41+
{
42+
rect.width = kIconBatteryWidth + 2;
43+
rect.height = kIconBatteryHeight + 2;
44+
}
45+
46+
void onDraw(flxDevMicroOLED *screen)
47+
{
48+
erase(screen);
49+
screen->bitmap(rect.x+1, rect.y+1, (uint8_t*)kIconsBattery[_currentBitmap], kIconBatteryWidth, kIconBatteryHeight);
50+
}
51+
52+
void updateValue(uint value)
53+
{
54+
if (value < 4 && _currentBitmap != value)
55+
{
56+
_currentBitmap = value;
57+
update();
58+
}
59+
}
60+
void listenForUpdate(flxSignalUInt &theEvent){
61+
theEvent.call(this, &sfeDLGrBattery::updateValue);
62+
}
63+
64+
private:
65+
uint16_t _currentBitmap;
66+
67+
};
68+

sfeDataLoggerIoT/sfeDLGrWiFi.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
*---------------------------------------------------------------------------------
3+
*
4+
* Copyright (c) 2022-2023, SparkFun Electronics Inc. All rights reserved.
5+
* This software includes information which is proprietary to and a
6+
* trade secret of SparkFun Electronics Inc. It is not to be disclosed
7+
* to anyone outside of this organization. Reproduction by any means
8+
* whatsoever is prohibited without express written permission.
9+
*
10+
*---------------------------------------------------------------------------------
11+
*/
12+
#pragma once
13+
14+
#include "sfeDLGraphx.h"
15+
16+
// Icons
17+
const int kIconWiFiHeight = 9;
18+
const int kIconWiFiWidth = 13;
19+
20+
const uint8_t kIconsWiFi[4][26] = {
21+
// Off
22+
{0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
23+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
24+
// Poor
25+
{0x00, 0x00, 0x00, 0x00, 0x20, 0x90, 0xD0, 0x90, 0x20, 0x00, 0x00, 0x00, 0x00,
26+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
27+
// Good
28+
{0x00, 0x00, 0x10, 0x08, 0x24, 0x94, 0xD4, 0x94, 0x24, 0x08, 0x10, 0x00, 0x00,
29+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
30+
// FULL
31+
{0x08, 0x04, 0x12, 0x09, 0x25, 0x95, 0xD5, 0x95, 0x25, 0x09, 0x12, 0x04, 0x08,
32+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
33+
};
34+
35+
class sfeDLGrWiFi : public sfeDLGraphic
36+
{
37+
38+
public:
39+
40+
sfeDLGrWiFi() : _currentBitmap{3}
41+
{
42+
rect.width = kIconWiFiWidth + 2;
43+
rect.height = kIconWiFiHeight + 2;
44+
}
45+
46+
void onDraw(flxDevMicroOLED *screen)
47+
{
48+
erase(screen);
49+
screen->bitmap(rect.x+1, rect.y+1, (uint8_t*)kIconsWiFi[_currentBitmap], kIconWiFiWidth, kIconWiFiHeight);
50+
}
51+
52+
void updateValue(uint value)
53+
{
54+
if (value < 4 && _currentBitmap != value)
55+
{
56+
_currentBitmap = value;
57+
update();
58+
}
59+
}
60+
void listenForUpdate(flxSignalUInt &theEvent){
61+
theEvent.call(this, &sfeDLGrWiFi::updateValue);
62+
}
63+
64+
private:
65+
uint16_t _currentBitmap;
66+
67+
};
68+

sfeDataLoggerIoT/sfeDLGraphx.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
*---------------------------------------------------------------------------------
3+
*
4+
* Copyright (c) 2022-2023, SparkFun Electronics Inc. All rights reserved.
5+
* This software includes information which is proprietary to and a
6+
* trade secret of SparkFun Electronics Inc. It is not to be disclosed
7+
* to anyone outside of this organization. Reproduction by any means
8+
* whatsoever is prohibited without express written permission.
9+
*
10+
*---------------------------------------------------------------------------------
11+
*/
12+
#pragma once
13+
14+
#include <cstdint>
15+
#include <vector>
16+
17+
#include <Flux/flxCore.h>
18+
19+
// OLED
20+
#include <Flux/flxDevMicroOLED.h>
21+
22+
struct grRect {
23+
uint16_t x;
24+
uint16_t y;
25+
uint16_t width;
26+
uint16_t height;
27+
};
28+
29+
class sfeDLGrView;
30+
31+
class sfeDLGraphic
32+
{
33+
34+
public:
35+
36+
sfeDLGraphic() : rect{0,0,0,0}, _needsUpdate{false}
37+
{
38+
}
39+
sfeDLGraphic(uint16_t x, uint16_t y)
40+
{
41+
rect.x = x;
42+
rect.y = y;
43+
}
44+
sfeDLGraphic(uint16_t x, uint16_t y, uint16_t width, uint16_t height) : sfeDLGraphic(x,y)
45+
{
46+
rect.width = width;
47+
rect.height = height;
48+
}
49+
50+
grRect rect;
51+
52+
void origin(uint16_t x, uint16_t y)
53+
{
54+
rect.x = x;
55+
rect.y = y;
56+
}
57+
58+
void erase(flxDevMicroOLED *screen){
59+
screen->rectangleFill(rect.x, rect.y, rect.width, rect.height, 0);
60+
}
61+
62+
virtual void onDraw(flxDevMicroOLED *screen)
63+
{
64+
65+
}
66+
void draw(flxDevMicroOLED *screen)
67+
{
68+
if (_needsUpdate)
69+
{
70+
onDraw(screen);
71+
_needsUpdate = false;
72+
}
73+
}
74+
75+
void update(void)
76+
{
77+
_needsUpdate = true;
78+
}
79+
80+
private:
81+
bool _needsUpdate;
82+
};
83+
84+
class sfeDLGrView : public sfeDLGraphic
85+
{
86+
87+
public:
88+
void add(sfeDLGraphic *gr)
89+
{
90+
if (gr)
91+
_children.push_back(gr);
92+
}
93+
94+
void draw(flxDevMicroOLED *screen)
95+
{
96+
for (sfeDLGraphic *pChild: _children)
97+
pChild->draw(screen);
98+
screen->display();
99+
}
100+
101+
void update(flxDevMicroOLED *screen)
102+
{
103+
// do a full screen update
104+
screen->erase();
105+
106+
// set update flags
107+
for (sfeDLGraphic *pChild: _children)
108+
pChild->update();
109+
110+
draw(screen);
111+
}
112+
113+
private:
114+
std::vector<sfeDLGraphic*> _children;
115+
};

0 commit comments

Comments
 (0)