mirror of
https://github.com/xodio/xod.git
synced 2026-02-20 02:01:20 +01:00
chore(workspace, xod-client-electron): add clang-format config, format new library and node implementations
This commit is contained in:
6
.clang-format
Normal file
6
.clang-format
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
BasedOnStyle: WebKit
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
NamespaceIndentation: None
|
||||||
|
...
|
||||||
113
packages/xod-client-electron/arduino-libraries/ESP8266UART/ESP8266UART.h
vendored
Executable file → Normal file
113
packages/xod-client-electron/arduino-libraries/ESP8266UART/ESP8266UART.h
vendored
Executable file → Normal file
@@ -48,7 +48,7 @@ namespace xod {
|
|||||||
class Uart;
|
class Uart;
|
||||||
}
|
}
|
||||||
class ESP8266 {
|
class ESP8266 {
|
||||||
private:
|
private:
|
||||||
xod::Uart* _uart;
|
xod::Uart* _uart;
|
||||||
#ifdef ESP8266_DEBUG
|
#ifdef ESP8266_DEBUG
|
||||||
Stream* _debug = nullptr;
|
Stream* _debug = nullptr;
|
||||||
@@ -67,9 +67,9 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void debugChar(char ch) {
|
void debugChar(char ch) {
|
||||||
if (_debug) {
|
if (_debug) {
|
||||||
_debug->print(ch);
|
_debug->print(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -206,31 +206,30 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void ESP8266::begin() {
|
void ESP8266::begin() {
|
||||||
_uart->begin();
|
_uart->begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::kick() {
|
bool ESP8266::kick() {
|
||||||
writeCmd(AT, EOL);
|
writeCmd(AT, EOL);
|
||||||
return cmdOK(OK, ERROR, 5000);
|
return cmdOK(OK, ERROR, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::setStationMode() {
|
bool ESP8266::setStationMode() {
|
||||||
writeCmd(CWMODE_SET);
|
writeCmd(CWMODE_SET);
|
||||||
println("1");
|
println("1");
|
||||||
return cmdOK(OK, ERROR, 1000);
|
return cmdOK(OK, ERROR, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::connect(const char* ssid, const char* password) {
|
bool ESP8266::connect(const char* ssid, const char* password) {
|
||||||
writeCmd(CWJAP);
|
writeCmd(CWJAP);
|
||||||
print(ssid);
|
print(ssid);
|
||||||
writeCmd(COMMA_2);
|
writeCmd(COMMA_2);
|
||||||
print(password);
|
print(password);
|
||||||
writeCmd(DOUBLE_QUOTE, EOL);
|
writeCmd(DOUBLE_QUOTE, EOL);
|
||||||
cmdOK(OK, FAIL, 15000);
|
cmdOK(OK, FAIL, 15000);
|
||||||
return isConnectedToAP();
|
return isConnectedToAP();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ESP8266::isConnectedToAP() {
|
bool ESP8266::isConnectedToAP() {
|
||||||
writeCmd(CIFSR, EOL);
|
writeCmd(CIFSR, EOL);
|
||||||
uint8_t code = readCmd(NO_IP, ERROR, 350);
|
uint8_t code = readCmd(NO_IP, ERROR, 350);
|
||||||
@@ -257,38 +256,42 @@ uint32_t ESP8266::getIP() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::createTCP(const char* addr, uint32_t port) {
|
bool ESP8266::createTCP(const char* addr, uint32_t port) {
|
||||||
char _port[32];
|
char _port[32];
|
||||||
writeCmd(CIPSTART);
|
writeCmd(CIPSTART);
|
||||||
writeCmd(TCP);
|
writeCmd(TCP);
|
||||||
writeCmd(COMMA_2);
|
writeCmd(COMMA_2);
|
||||||
print(addr);
|
print(addr);
|
||||||
writeCmd(COMMA_1);
|
writeCmd(COMMA_1);
|
||||||
dtostrf(port, 0, 0, _port);
|
dtostrf(port, 0, 0, _port);
|
||||||
println(_port);
|
println(_port);
|
||||||
|
|
||||||
bool ok = cmdOK(OK, ERROR, 5000);
|
bool ok = cmdOK(OK, ERROR, 5000);
|
||||||
if (ok) _connected = true;
|
if (ok)
|
||||||
return ok;
|
_connected = true;
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::releaseTCP() {
|
bool ESP8266::releaseTCP() {
|
||||||
if (!_connected) return true;
|
if (!_connected)
|
||||||
writeCmd(CIPCLOSE, EOL);
|
return true;
|
||||||
bool ok = cmdOK(OK, ERROR, 5000);
|
writeCmd(CIPCLOSE, EOL);
|
||||||
if (ok) _connected = false;
|
bool ok = cmdOK(OK, ERROR, 5000);
|
||||||
return ok;
|
if (ok)
|
||||||
|
_connected = false;
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::send(char* message) {
|
bool ESP8266::send(char* message) {
|
||||||
writeCmd(CIPSEND);
|
writeCmd(CIPSEND);
|
||||||
|
|
||||||
size_t len = sprintf(message, "%s", message);
|
size_t len = sprintf(message, "%s", message);
|
||||||
char reqLen[len];
|
char reqLen[len];
|
||||||
dtostrf(len, 0, 0, reqLen);
|
dtostrf(len, 0, 0, reqLen);
|
||||||
println(reqLen);
|
println(reqLen);
|
||||||
|
|
||||||
bool prompt = cmdOK(PROMPT, LINK_IS_NOT);
|
bool prompt = cmdOK(PROMPT, LINK_IS_NOT);
|
||||||
if (!prompt) return false;
|
if (!prompt)
|
||||||
|
return false;
|
||||||
|
|
||||||
print(message);
|
print(message);
|
||||||
bool ok = cmdOK(SEND_OK, nullptr, 5000);
|
bool ok = cmdOK(SEND_OK, nullptr, 5000);
|
||||||
@@ -296,15 +299,15 @@ bool ESP8266::send(char* message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::read(char* outBuff) {
|
bool ESP8266::read(char* outBuff) {
|
||||||
if(_uart->available()) {
|
if (_uart->available()) {
|
||||||
*outBuff = _uart->toStream()->read();
|
*outBuff = _uart->toStream()->read();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::isSocketOpen() {
|
bool ESP8266::isSocketOpen() {
|
||||||
return _connected;
|
return _connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESP8266::receive(char* r) {
|
bool ESP8266::receive(char* r) {
|
||||||
@@ -320,16 +323,16 @@ bool ESP8266::receive(char* r) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pkgSize > 0) {
|
if (_pkgSize > 0) {
|
||||||
if (_uart->available()) {
|
if (_uart->available()) {
|
||||||
if (read(r)) {
|
if (read(r)) {
|
||||||
_pkgSize--;
|
_pkgSize--;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* #ifndef __ESP8266_UART_H__ */
|
#endif /* #ifndef __ESP8266_UART_H__ */
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
// clang-format off
|
||||||
{{#global}}
|
{{#global}}
|
||||||
#include <ESP8266UART.h>
|
#include <ESP8266UART.h>
|
||||||
{{/global}}
|
{{/global}}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
uint8_t mem[sizeof(ESP8266)];
|
uint8_t mem[sizeof(ESP8266)];
|
||||||
@@ -11,7 +13,9 @@ struct Type {
|
|||||||
ESP8266* wifi;
|
ESP8266* wifi;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_INIT>(ctx))
|
if (!isInputDirty<input_INIT>(ctx))
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
// clang-format off
|
||||||
{{#global}}
|
{{#global}}
|
||||||
#include <ESP8266UART.h>
|
#include <ESP8266UART.h>
|
||||||
{{/global}}
|
{{/global}}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
@@ -10,7 +12,9 @@ struct Type {
|
|||||||
ESP8266* wifi;
|
ESP8266* wifi;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto dev = getValue<input_DEV>(ctx);
|
auto dev = getValue<input_DEV>(ctx);
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_KICK>(ctx))
|
if (!isInputDirty<input_KICK>(ctx))
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto inet = getValue<input_INET>(ctx);
|
auto inet = getValue<input_INET>(ctx);
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
@@ -12,7 +14,7 @@ void evaluate(Context ctx) {
|
|||||||
char _host[length(host) + 1] = { 0 };
|
char _host[length(host) + 1] = { 0 };
|
||||||
dump(host, _host);
|
dump(host, _host);
|
||||||
|
|
||||||
uint32_t port = (uint32_t) getValue<input_PORT>(ctx);
|
uint32_t port = (uint32_t)getValue<input_PORT>(ctx);
|
||||||
|
|
||||||
auto inet = getValue<input_INET>(ctx);
|
auto inet = getValue<input_INET>(ctx);
|
||||||
bool res = inet.wifi->createTCP(_host, port);
|
bool res = inet.wifi->createTCP(_host, port);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
struct State {};
|
struct State {};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
@@ -15,7 +17,7 @@ void evaluate(Context ctx) {
|
|||||||
|
|
||||||
char r = '\0';
|
char r = '\0';
|
||||||
if (inet.wifi->receive(&r)) {
|
if (inet.wifi->receive(&r)) {
|
||||||
emitValue<output_RES>(ctx, (uint8_t) r);
|
emitValue<output_RES>(ctx, (uint8_t)r);
|
||||||
emitValue<output_DONE>(ctx, 1);
|
emitValue<output_DONE>(ctx, 1);
|
||||||
} else {
|
} else {
|
||||||
emitValue<output_ERR>(ctx, 1);
|
emitValue<output_ERR>(ctx, 1);
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -2,14 +2,16 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto uart = getValue<input_UART>(ctx);
|
auto uart = getValue<input_UART>(ctx);
|
||||||
long baud = (long) getValue<input_BAUD>(ctx);
|
long baud = (long)getValue<input_BAUD>(ctx);
|
||||||
uart->changeBaudRate(baud);
|
uart->changeBaudRate(baud);
|
||||||
emitValue<output_DONE>(ctx, 1);
|
emitValue<output_DONE>(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_UPD>(ctx))
|
if (!isInputDirty<input_UPD>(ctx))
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void emitErr(Context ctx) {
|
void emitErr(Context ctx) {
|
||||||
emitValue<output_ERR>(ctx, 1);
|
emitValue<output_ERR>(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_SEND>(ctx))
|
if (!isInputDirty<input_SEND>(ctx))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto uart = getValue<input_UART>(ctx);
|
auto uart = getValue<input_UART>(ctx);
|
||||||
@@ -16,10 +18,13 @@ if (!isInputDirty<input_SEND>(ctx))
|
|||||||
|
|
||||||
for (auto it = data.iterate(); it; ++it) {
|
for (auto it = data.iterate(); it; ++it) {
|
||||||
bool err = !(uart->writeByte((char)*it));
|
bool err = !(uart->writeByte((char)*it));
|
||||||
if (err) return emitErr(ctx);
|
if (err)
|
||||||
|
return emitErr(ctx);
|
||||||
}
|
}
|
||||||
if (!uart->writeByte('\r')) return emitErr(ctx);
|
if (!uart->writeByte('\r'))
|
||||||
if (!uart->writeByte('\n')) return emitErr(ctx);
|
return emitErr(ctx);
|
||||||
|
if (!uart->writeByte('\n'))
|
||||||
|
return emitErr(ctx);
|
||||||
uart->flush();
|
uart->flush();
|
||||||
emitValue<output_DONE>(ctx, 1);
|
emitValue<output_DONE>(ctx, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_READ>(ctx))
|
if (!isInputDirty<input_READ>(ctx))
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
|
// clang-format off
|
||||||
{{#global}}
|
{{#global}}
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
{{/global}}
|
{{/global}}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
class SoftwareUart : public Uart {
|
class SoftwareUart : public Uart {
|
||||||
private:
|
private:
|
||||||
SoftwareSerial _serial;
|
SoftwareSerial _serial;
|
||||||
uint8_t _rx;
|
uint8_t _rx;
|
||||||
uint8_t _tx;
|
uint8_t _tx;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SoftwareUart(uint8_t rx, uint8_t tx, long baud = 9600) : Uart(baud), _serial(rx, tx) {
|
SoftwareUart(uint8_t rx, uint8_t tx, long baud = 9600)
|
||||||
|
: Uart(baud)
|
||||||
|
, _serial(rx, tx) {
|
||||||
_rx = rx;
|
_rx = rx;
|
||||||
_tx = tx;
|
_tx = tx;
|
||||||
}
|
}
|
||||||
@@ -20,18 +23,19 @@ class SoftwareUart : public Uart {
|
|||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
bool available() {
|
bool available() {
|
||||||
return (bool) _serial.available();
|
return (bool)_serial.available();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool writeByte(uint8_t byte) {
|
bool writeByte(uint8_t byte) {
|
||||||
return (bool) _serial.write(byte);
|
return (bool)_serial.write(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool readByte(uint8_t* out) {
|
bool readByte(uint8_t* out) {
|
||||||
int data = _serial.read();
|
int data = _serial.read();
|
||||||
if (data == -1) return false;
|
if (data == -1)
|
||||||
*out = data;
|
return false;
|
||||||
return true;
|
*out = data;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getRX() {
|
uint8_t getRX() {
|
||||||
@@ -43,20 +47,20 @@ class SoftwareUart : public Uart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SoftwareSerial* toSoftwareSerial() {
|
SoftwareSerial* toSoftwareSerial() {
|
||||||
return &_serial;
|
return &_serial;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void SoftwareUart::begin() {
|
void SoftwareUart::begin() {
|
||||||
_started = true;
|
_started = true;
|
||||||
_serial.begin(getBaudRate());
|
_serial.begin(getBaudRate());
|
||||||
};
|
};
|
||||||
void SoftwareUart::end() {
|
void SoftwareUart::end() {
|
||||||
_started = false;
|
_started = false;
|
||||||
_serial.end();
|
_serial.end();
|
||||||
};
|
};
|
||||||
void SoftwareUart::flush() {
|
void SoftwareUart::flush() {
|
||||||
_serial.flush();
|
_serial.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
@@ -64,13 +68,15 @@ struct State {
|
|||||||
SoftwareUart* uart;
|
SoftwareUart* uart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto state = getState(ctx);
|
auto state = getState(ctx);
|
||||||
uint8_t rx = getValue<input_RX>(ctx);
|
uint8_t rx = getValue<input_RX>(ctx);
|
||||||
uint8_t tx = getValue<input_TX>(ctx);
|
uint8_t tx = getValue<input_TX>(ctx);
|
||||||
long baud = (long) getValue<input_BAUD>(ctx);
|
long baud = (long)getValue<input_BAUD>(ctx);
|
||||||
state->uart = new (state->mem) SoftwareUart(rx, tx, baud);
|
state->uart = new (state->mem) SoftwareUart(rx, tx, baud);
|
||||||
emitValue<output_UART>(ctx, state->uart);
|
emitValue<output_UART>(ctx, state->uart);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ struct State {
|
|||||||
HardwareUart* uart;
|
HardwareUart* uart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto state = getState(ctx);
|
auto state = getState(ctx);
|
||||||
state->uart = new (state->mem) HardwareUart(Serial, (uint32_t) getValue<input_BAUD>(ctx));
|
state->uart = new (state->mem) HardwareUart(Serial, (uint32_t)getValue<input_BAUD>(ctx));
|
||||||
emitValue<output_UART>(ctx, state->uart);
|
emitValue<output_UART>(ctx, state->uart);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ struct State {
|
|||||||
HardwareUart* uart;
|
HardwareUart* uart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto state = getState(ctx);
|
auto state = getState(ctx);
|
||||||
state->uart = new (state->mem) HardwareUart(Serial1, (uint32_t) getValue<input_BAUD>(ctx));
|
state->uart = new (state->mem) HardwareUart(Serial1, (uint32_t)getValue<input_BAUD>(ctx));
|
||||||
emitValue<output_UART>(ctx, state->uart);
|
emitValue<output_UART>(ctx, state->uart);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ struct State {
|
|||||||
HardwareUart* uart;
|
HardwareUart* uart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto state = getState(ctx);
|
auto state = getState(ctx);
|
||||||
state->uart = new (state->mem) HardwareUart(Serial2, (uint32_t) getValue<input_BAUD>(ctx));
|
state->uart = new (state->mem) HardwareUart(Serial2, (uint32_t)getValue<input_BAUD>(ctx));
|
||||||
emitValue<output_UART>(ctx, state->uart);
|
emitValue<output_UART>(ctx, state->uart);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ struct State {
|
|||||||
HardwareUart* uart;
|
HardwareUart* uart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto state = getState(ctx);
|
auto state = getState(ctx);
|
||||||
state->uart = new (state->mem) HardwareUart(Serial3, (uint32_t) getValue<input_BAUD>(ctx));
|
state->uart = new (state->mem) HardwareUart(Serial3, (uint32_t)getValue<input_BAUD>(ctx));
|
||||||
emitValue<output_UART>(ctx, state->uart);
|
emitValue<output_UART>(ctx, state->uart);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ private:
|
|||||||
uint8_t _tx;
|
uint8_t _tx;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UsbUart(Serial_ serial, long baud = 9600) : Uart(baud) {
|
UsbUart(Serial_ serial, long baud = 9600)
|
||||||
|
: Uart(baud) {
|
||||||
_serial = serial;
|
_serial = serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,13 +55,13 @@ void UsbUart::flush() {
|
|||||||
_serial.flush();
|
_serial.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
struct ChooseUartWrapper {
|
struct ChooseUartWrapper {
|
||||||
using UartT = HardwareUart;
|
using UartT = HardwareUart;
|
||||||
};
|
};
|
||||||
template<>
|
template <>
|
||||||
struct ChooseUartWrapper<Serial_> {
|
struct ChooseUartWrapper<Serial_> {
|
||||||
using UartT = UsbUart;
|
using UartT = UsbUart;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
@@ -68,7 +69,9 @@ struct State {
|
|||||||
ChooseUartWrapper<typeof SerialUSB>::UartT* uart;
|
ChooseUartWrapper<typeof SerialUSB>::UartT* uart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto state = getState(ctx);
|
auto state = getState(ctx);
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ struct State {
|
|||||||
HardwareUart* uart;
|
HardwareUart* uart;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
auto state = getState(ctx);
|
auto state = getState(ctx);
|
||||||
state->uart = new (state->mem) HardwareUart(SERIAL_PORT_HARDWARE_OPEN, (uint32_t) getValue<input_BAUD>(ctx));
|
state->uart = new (state->mem) HardwareUart(SERIAL_PORT_HARDWARE_OPEN, (uint32_t)getValue<input_BAUD>(ctx));
|
||||||
emitValue<output_UART>(ctx, state->uart);
|
emitValue<output_UART>(ctx, state->uart);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
struct State {
|
struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
{{ GENERATED_CODE }}
|
{{ GENERATED_CODE }}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
void evaluate(Context ctx) {
|
void evaluate(Context ctx) {
|
||||||
if (!isInputDirty<input_SEND>(ctx))
|
if (!isInputDirty<input_SEND>(ctx))
|
||||||
|
|||||||
Reference in New Issue
Block a user