-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.cpp
141 lines (113 loc) · 2.75 KB
/
View.cpp
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
#include "View.h"
#include <Arduino.h>
View::View(): lcd(0x27,16,2), vlc(&lcd, 16, 1, 0, 1){}
void View::init()
{
pinMode(REDLED, OUTPUT); //Red 200 Ohm 14 mA
pinMode(GREENLED, OUTPUT); //Green 200 Ohm 7.5 mA
pinMode(BLUELED, OUTPUT); //Blue 200 Ohm 7.5 mA
vlc.setDelayTime(333);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(F("Auto mode:"));
}
void View::displayVoltage(uint16_t mV)
{
checkDisplayMode(DVOLTAGE);
previousDisplayMode = DVOLTAGE;
char fvalue[6] = {0};
this->red();
dtostrf(mV/1000.0, 5, 2, fvalue);
sprintf(container, "%14s %c", fvalue, 'V');
vlc.displayString(container);
}
void View::displayResistance(long ohms)
{
checkDisplayMode(DRESISTANCE);
previousDisplayMode = DRESISTANCE;
char fvalue[8] = {0};
if (ohms < 0) {
this->black();
sprintf(container, "%13s%c %c", "", 0xF3, 0xF4);
vlc.displayString(container);
return;
}
if (ohms == 0) {
this->blue();
} else {
this->green();
}
if (ohms > 1000) {
dtostrf(ohms/1000.0, 7, 2, fvalue);
sprintf(container, "%13s K%c", fvalue, 0xF4);
vlc.displayString(container);
return;
}
sprintf(container, "%14lu %c", ohms, 0xF4);
vlc.displayString(container);
}
void View::displayCurrent(float mA, bool newMeasure = false)
{
checkDisplayMode(DCURRENT);
previousDisplayMode = DCURRENT;
static int16_t avarage[5] = {};
static unsigned long previuosChangeTime = 0; //Debounce
uint8_t i = 0;
int16_t result = 0;
if (newMeasure) {
for (i = 0; i < 5; ++i) {
avarage[i] = 0;
}
}
for (i = 0; i < 4; ++i) {
avarage[i] = avarage[i+1];
result += avarage[i];
}
avarage[4] = mA;
result += mA;
result /= 5;
if (result > 10000) {
result /= 1000;
sprintf(container, "%14d %c", result, 'A');
} else {
sprintf(container, "%13d %s", result, "mA");
}
vlc.displayString(container);
}
void View::red()
{
digitalWrite(REDLED, HIGH);
digitalWrite(GREENLED, LOW);
digitalWrite(BLUELED, LOW);
}
void View::green()
{
digitalWrite(REDLED, LOW);
digitalWrite(GREENLED, HIGH);
digitalWrite(BLUELED, LOW);
}
void View::blue()
{
digitalWrite(REDLED, LOW);
digitalWrite(GREENLED, LOW);
digitalWrite(BLUELED, HIGH);
}
void View::magenta()
{
digitalWrite(REDLED, HIGH);
digitalWrite(GREENLED, LOW);
digitalWrite(BLUELED, HIGH);
}
void View::black()
{
digitalWrite(REDLED, LOW);
digitalWrite(GREENLED, LOW);
digitalWrite(BLUELED, LOW);
}
void View::checkDisplayMode(uint8_t currentMode)
{
if (previousDisplayMode != currentMode) {
vlc.resetDelayCounter();
}
}