-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplaySSD1306.h
96 lines (75 loc) · 3 KB
/
DisplaySSD1306.h
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
#pragma once
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Pzem004t.h"
namespace hw
{
enum class ViewValueType
{
Voltage = 0,
Current = 1,
Power = 2,
Energy = 3,
Frequency = 4,
PowerFactor = 5
};
struct ViewConfiguration
{
ViewValueType value1;
ViewValueType value2;
ViewValueType value3;
};
class DisplaySSD1306
{
public:
DisplaySSD1306();
virtual ~DisplaySSD1306() = default;
void initialize();
void update(const hw::pzem004tvalues& phasesCombined, const hw::pzem004tvalues& phase1Values, const hw::pzem004tvalues& phase2Values, const hw::pzem004tvalues& phase3Values);
void setCustomViewConfiguration(const ViewConfiguration& customViewConfiguration);
void switchView();
void switchPhase();
void showMessage(char* message, int duration = -1);
void clearMessage();
void changeView(int value);
void changePhase(int value);
void setEnergyOffsetPhase1(const float& value);
void setEnergyOffsetPhase2(const float& value);
void setEnergyOffsetPhase3(const float& value);
const byte selectedPhase();
const int selectedView();
const ViewConfiguration& customViewConfiguration();
private:
void drawSelectedPhase();
void drawMessage();
void drawBarGraph(const int16_t& x, const int16_t& y, const int16_t& width, const int16_t& height, const float& min, const float& max, const float& value);
void drawValueByType(int16_t x, int16_t y, const ViewValueType& type, const pzem004tvalues& values);
const hw::pzem004tvalues& getSelectedValues(const hw::pzem004tvalues& phasesCombined, const hw::pzem004tvalues& phase1Values, const hw::pzem004tvalues& phase2Values, const hw::pzem004tvalues& phase3Values);
float getEnergyOffset();
#define NUM_VIEW_CONFIGURATIONS 4
ViewConfiguration _viewConfigurations[NUM_VIEW_CONFIGURATIONS]
{
{ ViewValueType::Voltage, ViewValueType::Power, ViewValueType::Frequency },
{ ViewValueType::Voltage, ViewValueType::Current, ViewValueType::Frequency },
{ ViewValueType::Current, ViewValueType::Power, ViewValueType::Energy },
{ ViewValueType::Voltage, ViewValueType::Frequency, ViewValueType::PowerFactor },
};
ViewConfiguration _customViewConfiguration;
bool _isInitialized = false;
char* _message = nullptr;
float _maxCurrent = 1;
long _expiresAt = 0;
long _clearMessageTs = -1;
int16_t col1x = 35;
const int16_t col1y = 16;
const int16_t colHeight = 23;
byte _selectedPhase = 0; // 0 = all; 1-3 = phase1,2,3
int _selectedView = 0;
float _energyOffsetPhase1 = 0;
float _energyOffsetPhase2 = 0;
float _energyOffsetPhase3 = 0;
Adafruit_SSD1306 _ssd1306;
};
}