-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDashboardClient.cpp
More file actions
182 lines (160 loc) · 6.15 KB
/
Copy pathDashboardClient.cpp
File metadata and controls
182 lines (160 loc) · 6.15 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
//
//
//
#include "DashboardClient.h"
DashboardClient::DashboardClient() {
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::open() {
// this is a common syntax, to "open" something for reading
thisItem = headItem; // set our linked list item to the first (header) item
}
//**************************************************************************************************************
//
//**************************************************************************************************************
bool DashboardClient::available() {
return !(thisItem == NULL) ; // the default "next item" is NULL, so when thisItem == NULL, we no longer have data "available" to read
}
//**************************************************************************************************************
//
//**************************************************************************************************************
int readCounter = 0;
String DashboardClient::read() {
return read(-1);
}
String DashboardClient::read(int displayLine) {
String result = "";
if (thisItem == NULL) { return result; } // return blank if there's no item
switch (readCounter)
{
case 0:
result = thisItem->dashboard_short_summary;
readCounter++;
break;
case 1:
result = thisItem->current_value_display;
readCounter++;
break;
case 2:
result = thisItem->units;
readCounter = 0;
thisItem = thisItem->next; // when reading last item, go to next one
break;
default:
break;
}
return result;
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::whitespace(char c) {
//Serial.print(thisDashboardID);
//Serial.println(" whitespace");
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::startDocument() {
itemCount = 0; // at the beginning, we have no items (other than our header)
thisItem = headItem; // set out linked list to the first (header) item
//
// Serial.println(" start document");
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::key(String key) {
#include <vector>
currentKey = String(key);
if (key == "dashboard_id") {
if (!foundNewObject) {
Serial.println("Warning: dashboard id found at position other than start of object!");
}
//else { Serial.println("ID OK!"); }
}
foundNewObject = false;
//Serial.print(thisDashboardID);
//Serial.println(" key: " + key);
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::value(String value) {
// Serial.println("value: " + value);
if (currentKey == "dashboard_id") {
thisDashboardID = value.toInt();
//std::vector<int> array;
//DashboardItemArray.push_back(thisDashboardID);
itemCount++;
if (thisItem->next == NULL) {
//Serial.print("Creating item ");
//Serial.println(itemCount);
nextItem = new DashboardItem;
thisItem->next = nextItem;
}
// else { Serial.println("Item already exists"); }
thisItem->itemID = itemCount;
thisItem->dashboard_id = thisDashboardID;
}
if (currentKey == "dashboard_short_summary") {
thisItem->dashboard_short_summary = value;
}
if (currentKey == "current_value_display") {
thisItem->current_value_display = value;
}
if (currentKey == "current_value") {
thisItem->current_value = value;
}
if (currentKey == "units") {
thisItem->units = value;
}
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::endArray() {
//Serial.print(thisDashboardID);
//Serial.println(" end array. ");
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::endObject() {
foundNewObject = false;
thisItem = thisItem->next; // or thisItem = NextItem
//Serial.print(thisDashboardID);
//Serial.println(" end object. ");
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::endDocument() {
thisItem = headItem;
//Serial.print(thisDashboardID);
//Serial.println(" end document. ");
//while (thisItem != NULL) {
// Serial.print("Found: ID=");
// Serial.print(thisItem->dashboard_id);
// Serial.print(" text = ");
// Serial.println(thisItem->dashboard_short_summary);
// thisItem = thisItem->next;
//}
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::startArray() {
//Serial.print(thisDashboardID);
//Serial.println(" start array. ");
}
//**************************************************************************************************************
//
//**************************************************************************************************************
void DashboardClient::startObject() {
foundNewObject = true;
//Serial.print(thisDashboardID);
//Serial.println(" start object. ");
}