Skip to content

Commit c2c98c7

Browse files
committed
ui: move data display function to ui.cpp
1 parent a62068c commit c2c98c7

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

src/normal_mode.cpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Dht.h"
77
#include "config.h"
88
#include "send.h"
9+
#include "ui.h"
910

1011
extern pcd8544::Pcd8544 display;
1112
extern expander::Expander expand;
@@ -16,54 +17,8 @@ dht::Dht dht22(14);
1617
Ticker timer1;
1718
Ticker timer2;
1819

19-
static const int PM25_NORM=25;
20-
static const int PM10_NORM=40;
2120
static const int SAMPLES=10;
2221

23-
static String val_to_str(uint16_t v)
24-
{
25-
String r;
26-
27-
r = String(v/10);
28-
if (v < 1000 && v%10) {
29-
r += String(".") + String(v%10);
30-
}
31-
32-
for (int i = 4 - r.length(); i > 0; i--) {
33-
r = String(" ") + r;
34-
}
35-
36-
return r;
37-
}
38-
39-
static void display_data(uint16_t pm25, uint16_t pm10, int16_t t, uint16_t h)
40-
{
41-
display.clear();
42-
display.setCursor(0, 0);
43-
44-
display.println(" 2.5 10");
45-
46-
display.print("ug ");
47-
display.print(val_to_str(pm25).c_str());
48-
49-
display.setCursor(8*7, 1);
50-
display.println(val_to_str(pm10).c_str());
51-
52-
display.print("% ");
53-
display.print(val_to_str((10*pm25/PM25_NORM)*10).c_str());
54-
display.setCursor(8*7, 2);
55-
display.print(val_to_str((10*pm10/PM10_NORM)*10).c_str());
56-
57-
display.setCursor(0, 3);
58-
display.print("t: ");
59-
display.print(val_to_str(t).c_str());
60-
display.print("C");
61-
display.setCursor(0, 4);
62-
display.print("h: ");
63-
display.print(val_to_str(h).c_str());
64-
display.println("%");
65-
}
66-
6722
static void turnOff(void)
6823
{
6924
expand.digitalWrite(0, HIGH);

src/ui.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "Pcd8544.h"
2+
3+
static const int PM25_NORM=25;
4+
static const int PM10_NORM=40;
5+
6+
extern pcd8544::Pcd8544 display;
7+
8+
static String val_to_str(uint16_t v)
9+
{
10+
String r;
11+
12+
r = String(v/10);
13+
if (v < 1000 && v%10) {
14+
r += String(".") + String(v%10);
15+
}
16+
17+
for (int i = 4 - r.length(); i > 0; i--) {
18+
r = String(" ") + r;
19+
}
20+
21+
return r;
22+
}
23+
24+
void display_data(uint16_t pm25, uint16_t pm10, int16_t t, uint16_t h)
25+
{
26+
display.clear();
27+
display.setCursor(0, 0);
28+
29+
display.println(" 2.5 10");
30+
31+
display.print("ug ");
32+
display.print(val_to_str(pm25).c_str());
33+
34+
display.setCursor(8*7, 1);
35+
display.println(val_to_str(pm10).c_str());
36+
37+
display.print("% ");
38+
display.print(val_to_str((10*pm25/PM25_NORM)*10).c_str());
39+
display.setCursor(8*7, 2);
40+
display.print(val_to_str((10*pm10/PM10_NORM)*10).c_str());
41+
42+
display.setCursor(0, 3);
43+
display.print("t: ");
44+
display.print(val_to_str(t).c_str());
45+
display.print("C");
46+
display.setCursor(0, 4);
47+
display.print("h: ");
48+
display.print(val_to_str(h).c_str());
49+
display.println("%");
50+
}
51+

src/ui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
void display_data(uint16_t pm25, uint16_t pm10, int16_t t, uint16_t h);

0 commit comments

Comments
 (0)