Skip to content

Commit f45437a

Browse files
committed
Add a warning message for binary output mode, and add text-mode example
1 parent 28d1d8c commit f45437a

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
TelemetryJet Arduino SDK
3+
Chris Dalke <[email protected]>
4+
https://github.com/telemetryjet/telemetryjet-arduino-sdk
5+
6+
Lightweight communication library for hardware telemetry data.
7+
Handles bidirectional communication and state management for data points.
8+
-------------------------------------------------------------------------
9+
Part of the TelemetryJet platform -- Collect, analyze, and share
10+
data from your hardware. Code not required.
11+
12+
Distributed "as is" under the MIT License. See LICENSE.md for details.
13+
*/
14+
15+
#include <TelemetryJet.h>
16+
17+
// Initialize an instance of the TelemetryJet SDK.
18+
TelemetryJet telemetry(&Serial, 100);
19+
Dimension testValue1 = telemetry.createDimension(1);
20+
Dimension testValue2 = telemetry.createDimension(2);
21+
22+
void setup() {
23+
// Send data in "text mode", which can be useful for debugging in the Arduino IDE.
24+
// In text mode, all data points are sent as text in a list at the write interval.
25+
//
26+
// The output for this program will look something like:
27+
// 68.21 186.08
28+
// 60.57 189.51
29+
// 52.32 192.50
30+
// ...
31+
//
32+
// Notes:
33+
// - In text mode, values cannot be sent to the device.
34+
// - Text mode is highly inefficient for data transmission, and should only be used
35+
// for debugging purposes!
36+
telemetry.setTextMode(true);
37+
38+
// Initialize the serial stream.
39+
Serial.begin(115200);
40+
while (!Serial);
41+
}
42+
43+
void loop() {
44+
// Process new data if available, and periodically send data points.
45+
telemetry.update();
46+
47+
// Update the dimensions with an oscillating signal.
48+
testValue1.setFloat32(sin(millis() / 1000.0) * 100.0);
49+
testValue2.setFloat32(sin(millis() / 2000.0) * 200.0);
50+
}

src/TelemetryJet.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ size_t UnStuffData(const uint8_t *ptr, size_t length, uint8_t *dst) {
9393
}
9494

9595
void TelemetryJet::update() {
96+
if (!isInitialized) {
97+
if (hasBinaryWarningMessage && !isTextMode) {
98+
transport->println(F("Started streaming data in Binary mode. This data is not human-readable."));
99+
transport->println(F("For usage information, please see https://docs.telemetryjet.com/."));
100+
}
101+
isInitialized = true;
102+
}
103+
96104
if (isTextMode) {
97105
// Text mode
98106
// Don't read inputs; just log as text output to the serial stream
@@ -152,7 +160,7 @@ void TelemetryJet::update() {
152160
break;
153161
}
154162
case DataPointType::FLOAT32: {
155-
transport->print((double)(dimensions[i]->value.v_float32));
163+
transport->print((float)(dimensions[i]->value.v_float32));
156164
break;
157165
}
158166
default: {

src/TelemetryJet.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class TelemetryJet {
167167
bool isInitialized = false;
168168
bool isTextMode = false;
169169
bool isDeltaMode = true;
170+
bool hasBinaryWarningMessage = true;
170171
uint32_t lastSent;
171172
uint32_t transmitRate;
172173

@@ -208,6 +209,9 @@ class TelemetryJet {
208209
void setDeltaMode(bool deltaMode = false) {
209210
isDeltaMode = deltaMode;
210211
}
212+
void setBinaryWarningMessage(bool message = false) {
213+
hasBinaryWarningMessage = message;
214+
}
211215

212216
friend class Dimension;
213217
};

0 commit comments

Comments
 (0)