Skip to content

Commit 25e8145

Browse files
committed
Convenience function for printing integers
1 parent b75de2c commit 25e8145

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

EmbAJAX.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ void EmbAJAXOutputDriverBase::printAttribute(const char* name, const int32_t val
8888
printContent(" ");
8989
printContent(name);
9090
printContent("=");
91+
printInt(value);
92+
}
93+
94+
void EmbAJAXOutputDriverBase::printInt(int32_t value) {
9195
char buf[12];
9296
printContent(itoa(value, buf, 10));
9397
}
@@ -402,7 +406,7 @@ void EmbAJAXMomentaryButton::print() const {
402406
_driver->printFiltered(_id, EmbAJAXOutputDriverBase::JSQuoted, false);
403407
_driver->printContent(");\n"
404408
"btn.onmousedown = btn.ontouchstart = function() { clearInterval(this.pinger); this.pinger=setInterval(function() {doRequest(this.id, 'p');}.bind(this),");
405-
_driver->printContent(itoa(_timeout / 1.5, itoa_buf, 10));
409+
_driver->printInt(_timeout / 1.5);
406410
_driver->printContent("); doRequest(this.id, 'p'); return false; };\n"
407411
"btn.onmouseup = btn.ontouchend = btn.onmouseleave = function() { clearInterval(this.pinger); doRequest(this.id, 'r'); return false;};}\n"
408412
"</script>");
@@ -540,7 +544,7 @@ void EmbAJAXBase::printPage(EmbAJAXBase** _children, size_t NUM, const char* _ti
540544
"var prev_request = 0;\n"
541545
"function sendQueued() {\n"
542546
" var now = new Date().getTime();\n"
543-
" if (num_waiting > 0 || (now - prev_request < "); _driver->printContent(itoa(_min_interval, itoa_buf, 10)); _driver->printContent(")) return;\n"
547+
" if (num_waiting > 0 || (now - prev_request < "); _driver->printInt(_min_interval); _driver->printContent(")) return;\n"
544548
" var e = request_queue.shift();\n"
545549
" if (!e && (now - prev_request < 1000)) return;\n"
546550
" if (!e) e = {id: '', value: ''};\n" //Nothing in queue, but last request more than 1000 ms ago? Send a ping to query for updates
@@ -560,7 +564,7 @@ void EmbAJAXBase::printPage(EmbAJAXBase** _children, size_t NUM, const char* _ti
560564
" req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');\n"
561565
" req.send('id=' + e.id + '&value=' + encodeURIComponent(e.value) + '&revision=' + serverrevision);\n"
562566
"}\n"
563-
"window.setInterval(sendQueued, "); _driver->printContent(itoa(_min_interval, itoa_buf, 10)); _driver->printContent(");\n");
567+
"window.setInterval(sendQueued, "); _driver->printInt(_min_interval/2+1); _driver->printContent(");\n");
564568

565569
_driver->printContent("function doUpdates(response) {\n"
566570
" serverrevision = response.revision;\n"
@@ -634,7 +638,7 @@ void EmbAJAXBase::handleRequest(EmbAJAXBase** _children, size_t NUM, void (*chan
634638
// then relay value changes that have occured in the server (possibly in response to those sent)
635639
_driver->printHeader(false);
636640
_driver->printContent("{\"revision\": ");
637-
_driver->printContent(itoa(_driver->revision(), conversion_buf, 10));
641+
_driver->printInt(_driver->revision());
638642
_driver->printContent(",\n\"updates\": [\n");
639643
sendUpdates(_children, NUM, client_revision, true);
640644
_driver->printContent("\n]}\n");

EmbAJAX.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class EmbAJAXOutputDriverBase {
157157
inline void printJSQuoted (const char* value) { printFiltered (value, JSQuoted, false); }
158158
/** Shorthand for printFiltered(value, HTMLQuoted, false); */
159159
inline void printHTMLQuoted (const char* value) { printFiltered (value, HTMLQuoted, false); }
160+
/** Helper function to write integer number */
161+
void printInt(int32_t);
160162
/** Convenience function to print an attribute inside an HTML tag.
161163
* This function adds a space _in front of_ the printed attribute.
162164
*

0 commit comments

Comments
 (0)