-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisplay.h
170 lines (139 loc) · 3.96 KB
/
Display.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#ifndef DISPLAY_H
#define DISPLAY_H
#include <ArduinoJson.h>
#if defined(ESP8266)
#include <ESP8266HTTPClient.h>
#else
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#endif
#include "Settings.h"
void displayFish(int size);
void displaySpace(int size);
void displayUsername(int size);
void displayHashrate(int size);
void displayDifficulty(int size);
void displayRigID(int size);
void displayShareCount(int size);
void displayNodeID(int size);
void displayUserBalance(int size);
void displayUserMinerCount(int size);
String httpGetString(String URL);
void updateDisplay() {
display.clearDisplay();
display.setCursor(0,0);
display.setTextColor(SSD1306_WHITE);
// Actual rendering here; Uncomment things and configure how you want
//displayFish(1);
displayRigID(2);
displaySpace(1);
displayHashrate(1);
displayDifficulty(1);
displayShareCount(1);
displayNodeID(1);
//displayRigID(1);
//displayUsername(1);
//displayUserBalance(1);
//displayUserMinerCount(1);
/////////////////////////////////////////////////////////////////////
display.display();
}
// Displays fish as requested by @KD BRUHLAG
void displayFish(int size) {
display.setTextSize(size);
display.println("><> ><> ><> ><> ><> ><> ><> ><> ><> ><>");
}
// Displays space
void displaySpace(int size) {
display.setTextSize(size);
display.println("");
}
// Displays username
void displayUsername(int size) {
display.setTextSize(size);
#if defined(USE_DISPLAY_128x64)
display.println("Username: " + String(DUCO_USER));
#endif
#if defined(USE_DISPLAY_128x32)
display.println("User:" + String(DUCO_USER));
#endif
}
// Displays hashrate
void displayHashrate(int size) {
display.setTextSize(size);
#if defined(USE_DISPLAY_128x64)
display.println("Hashrate: " + String(hashrate / 1000) + " kH/s");
#endif
#if defined(USE_DISPLAY_128x32)
display.println("H/R:" + String(hashrate / 1000) + "kH/s");
#endif
}
// Displays difficulty
void displayDifficulty(int size) {
display.setTextSize(size);
#if defined(USE_DISPLAY_128x64)
display.println("Difficulty: " + String(difficulty / 100));
#endif
#if defined(USE_DISPLAY_128x32)
display.println("Diff:" + String(difficulty / 100));
#endif
}
// Displays rig ID
void displayRigID(int size) {
display.setTextSize(size);
display.setTextColor(SSD1306_WHITE);
display.println(String(RIG_IDENTIFIER));
}
// Displays share count
void displayShareCount(int size) {
display.setTextSize(size);
display.println("Shares: " + String(share_count));
}
// Displays node ID
void displayNodeID(int size) {
display.setTextSize(size);
display.println("Node: " + String(node_id));
}
// Displays user balance
void displayUserBalance(int size) {
String input = httpGetString("https://server.duinocoin.com/balances/"+String(DUCO_USER));
DynamicJsonDocument doc(1024);
deserializeJson(doc, input);
double balance = doc["result"]["balance"];
display.setTextSize(size);
#if defined(USE_DISPLAY_128x64)
display.println("Balance: " + String(balance));
#endif
#if defined(USE_DISPLAY_128x32)
display.println("Bal:" + String(balance));
#endif
}
// Displays user miner count
void displayUserMinerCount(int size) {
String input = httpGetString("https://server.duinocoin.com/miners/"+String(DUCO_USER));
DynamicJsonDocument doc(32768); // TODO: <= toto
deserializeJson(doc, input);
JsonArray result = doc["result"];
size_t miners = result.size();
display.setTextSize(size);
display.println("Miners: " + String(miners));
}
// Helper function; fetches a HTTP string
String httpGetString(String URL) {
String payload = "";
WiFiClientSecure client;
client.setInsecure();
HTTPClient http;
if (http.begin(client, URL)) {
int httpCode = http.GET();
if (httpCode == HTTP_CODE_OK) payload = http.getString();
else {
#if defined(SERIAL_PRINTING)
Serial.printf("Error fetching HTTP string: %s\n", http.errorToString(httpCode).c_str());
#endif
}
http.end();
}
return payload;
}
#endif