Skip to content

Commit 12b459b

Browse files
committed
can print json with unit, update readme
1 parent 3202ea3 commit 12b459b

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ Prints data to Blinker app
108108
```
109109
Blinker.print(data);
110110
```
111-
Prints a Json data to Blinkrt app, eg: {text1:data}
111+
Prints a Json data to Blinkrt app, eg: {"temp":30.2}
112112
```
113-
Blinker.print(text1, data);
113+
Blinker.print("temp", 30.2);
114114
```
115+
Prints a Json data with unit to Blinkrt app, eg: {"temp":"30.2 °C"}
116+
```
117+
Blinker.print("temp", 30.2, "°C");
118+
```
119+
>Json data can display in the Blinker TEXT widget
120+
115121
## App Widgets
116122
### Blinker.button()
117123
Device receives an update of **Button** state from app, return true when **Pressed**, return false when **Released**.
@@ -263,6 +269,12 @@ Blinker.print(data);
263269
```
264270
Blinker.print(text1, data);
265271
```
272+
发送一个带单位的Json数据, eg: {"temp":"30.2 °C"}
273+
```
274+
Blinker.print("temp", 30.2, "°C");
275+
```
276+
>发送的Json数据可以在 Blinker APP 的 TEXT 组件中显示
277+
266278
## App Widgets
267279
### Blinker.button()
268280
读取开关/按键数据, 按下(Pressed)时返回true, 松开(Released)时返回false

src/Blinker/BlinkerConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
#define BLINKER_CMD_NEWLINE "\n"
4141

42+
#define BLINKER_CMD_INTERSPACE " "
43+
4244
#define BLINKER_JOYSTICK_VALUE_DEFAULT 128
4345

4446
#endif

src/Blinker/BlinkerProtocol.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,26 @@ class BlinkerProtocol
6262
}
6363
}
6464

65-
void print(const String &s) { conn.print(s + BLINKER_CMD_NEWLINE); }
66-
void print(const char str[]) { print(STRING_format(str)); }
67-
void print(char c) { print(STRING_format(c)); }
68-
void print(unsigned char b) { print(STRING_format(b)); }
69-
void print(int n) { print(STRING_format(n)); }
70-
void print(unsigned int n) { print(STRING_format(n)); }
71-
void print(long n) { print(STRING_format(n)); }
72-
void print(unsigned long n) { print(STRING_format(n)); }
73-
void print(double n) { print(STRING_format(n)); }
74-
void print() { print(""); }
75-
void println(const String &s) { print(s); }
76-
void println(const char str[]) { print(str); }
77-
void println(char c) { print(c); }
78-
void println(unsigned char b) { print(b); }
79-
void println(int n) { print(n); }
80-
void println(unsigned int n) { print(n); }
81-
void println(long n) { print(n); }
82-
void println(unsigned long n) { print(n); }
83-
void println(double n) { print(n); }
84-
void println() { print(); }
65+
template <typename T>
66+
void print(T n) { conn.print(STRING_format(n) + BLINKER_CMD_NEWLINE); }
67+
void print() { print(""); }
68+
69+
template <typename T>
70+
void println(T n) { print(n); }
71+
void println() { print(); }
72+
73+
template <typename T1, typename T2, typename T3>
74+
void print(T1 n1, T2 n2, T3 n3) { print("{\"" + STRING_format(n1) + "\":\"" + STRING_format(n2) + BLINKER_CMD_INTERSPACE + STRING_format(n3) + "\"}"); }
75+
76+
template <typename T1, typename T2, typename T3>
77+
void println(T1 n1, T2 n2, T3 n3) { print("{\"" + STRING_format(n1) + "\":\"" + STRING_format(n2) + BLINKER_CMD_INTERSPACE + STRING_format(n3) + "\"}"); }
78+
79+
// template <typename T1, typename T2>
80+
// void print(T1 n1, T2 n2) { print("{\"" + STRING_format(n1) + "\":\"" + STRING_format(n2) + "\"}"); }
81+
82+
// template <typename T1, typename T2>
83+
// void println(T1 n1, T2 n2) { print("{\"" + STRING_format(n1) + "\":\"" + STRING_format(n2) + "\"}"); }
84+
8585
void print(const String &s1, const String &s2) { print("{\"" + s1 + "\":\"" + s2 + "\"}"); }
8686
void print(const char str1[], const char str2[]) { print("{\"" + STRING_format(str1) + "\":\"" + STRING_format(str2) + "\"}"); }
8787
void print(const char str[], char c) { print("{\"" + STRING_format(str) + "\":" + STRING_format(c) + "}"); }
@@ -100,7 +100,7 @@ class BlinkerProtocol
100100
void println(const char str[], long n) { print(str, n); }
101101
void println(const char str[], unsigned long n) { print(str, n); }
102102
void println(const char str[], double n) { print(str, n); }
103-
103+
104104
void flush() {
105105
isFresh = false;
106106
}

0 commit comments

Comments
 (0)