mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
added writeJSON
This commit is contained in:
parent
a224ada957
commit
7455a7a7d8
@ -72,6 +72,11 @@ void BridgeClass::writeMessage(const String& str) {
|
|||||||
writeMessage((uint8_t*) str.c_str(), str.length());
|
writeMessage((uint8_t*) str.c_str(), str.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BridgeClass::writeJSON(const String& str) {
|
||||||
|
uint8_t cmd[] = {'J'};
|
||||||
|
transfer(cmd, 1, (uint8_t*) str.c_str(), str.length(), NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int BridgeClass::messageAvailable() {
|
unsigned int BridgeClass::messageAvailable() {
|
||||||
uint8_t tmp[] = {'n'};
|
uint8_t tmp[] = {'n'};
|
||||||
uint8_t res[2];
|
uint8_t res[2];
|
||||||
|
@ -31,6 +31,7 @@ public:
|
|||||||
unsigned int readMessage(uint8_t *buffer, unsigned int size);
|
unsigned int readMessage(uint8_t *buffer, unsigned int size);
|
||||||
void writeMessage(const uint8_t *buffer, unsigned int size);
|
void writeMessage(const uint8_t *buffer, unsigned int size);
|
||||||
void writeMessage(const String& str);
|
void writeMessage(const String& str);
|
||||||
|
void writeJSON(const String& str);
|
||||||
unsigned int messageAvailable();
|
unsigned int messageAvailable();
|
||||||
|
|
||||||
// Methods to handle key/value datastore
|
// Methods to handle key/value datastore
|
||||||
|
@ -90,23 +90,23 @@ void modeCommand(String command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reportPinMode(int pin, String mode) {
|
void reportPinMode(int pin, String mode) {
|
||||||
String message = "{\"pin\":";
|
String json = "{\"pin\":";
|
||||||
message += pin;
|
json += pin;
|
||||||
message += ", \"mode\": \"";
|
json += ", \"mode\": \"";
|
||||||
message += mode;
|
json += mode;
|
||||||
message += "\"}";
|
json += "\"}";
|
||||||
Bridge.writeMessage(message);
|
Bridge.writeJSON(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reportDigitalRead(int pin, boolean dataset) {
|
void reportDigitalRead(int pin, boolean dataset) {
|
||||||
int value = digitalRead(pin);
|
int value = digitalRead(pin);
|
||||||
|
|
||||||
String message = "{\"pin\":";
|
String json = "{\"pin\":";
|
||||||
message += pin;
|
json += pin;
|
||||||
message += ", \"value\": ";
|
json += ", \"value\": ";
|
||||||
message += value;
|
json += value;
|
||||||
message += "}";
|
json += "}";
|
||||||
Bridge.writeMessage(message);
|
Bridge.writeJSON(json);
|
||||||
|
|
||||||
if (dataset) {
|
if (dataset) {
|
||||||
String key = "D";
|
String key = "D";
|
||||||
@ -118,12 +118,12 @@ void reportDigitalRead(int pin, boolean dataset) {
|
|||||||
void reportAnalogRead(int pin, boolean dataset) {
|
void reportAnalogRead(int pin, boolean dataset) {
|
||||||
int value = analogRead(pin);
|
int value = analogRead(pin);
|
||||||
|
|
||||||
String message = "{\"pin\":";
|
String json = "{\"pin\":";
|
||||||
message += pin;
|
json += pin;
|
||||||
message += ", \"value\": ";
|
json += ", \"value\": ";
|
||||||
message += value;
|
json += value;
|
||||||
message += "}";
|
json += "}";
|
||||||
Bridge.writeMessage(message);
|
Bridge.writeJSON(json);
|
||||||
|
|
||||||
if (dataset) {
|
if (dataset) {
|
||||||
String key = "A";
|
String key = "A";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user