1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-14 03:49:52 +03:00

Allow setting serial baurate for LUA (#8228)

This commit is contained in:
3djc 2021-01-19 14:57:45 +01:00 committed by GitHub
parent 42a82d5b71
commit c38e513c7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 67 additions and 15 deletions

View file

@ -1598,13 +1598,38 @@ static int luaMultiBuffer(lua_State * L)
}
#endif
/*luadoc
@function setSerialBaudrate(baudrate)
@param baudrate Desired baurate
Set baudrate for serial port(s) affected to LUA
@status current Introduced in 2.3.12
*/
static int luaSetSerialBaudrate(lua_State * L)
{
unsigned int baudrate = luaL_checkunsigned(L, 1);
#if defined(AUX_SERIAL)
if (auxSerialMode == UART_MODE_LUA) {
auxSerialSetup(baudrate, true);
}
#endif
#if defined(AUX2_SERIAL)
if (aux2SerialMode == UART_MODE_LUA) {
aux2SerialSetup(baudrate, true);
}
#endif
return 1;
}
/*luadoc
@function serialWrite(str)
@param str (string) String to be written to the serial port.
Writes a string to the serial port. The string is allowed to contain any character, including 0.
@status current Introduced in TODO
@status current Introduced in 2.3.10
*/
static int luaSerialWrite(lua_State * L)
{
@ -1614,21 +1639,22 @@ static int luaSerialWrite(lua_State * L)
if (!str || len < 1)
return 0;
#if !defined(SIMU)
#if defined(USB_SERIAL)
#if defined(USB_SERIAL)
if (getSelectedUsbMode() == USB_SERIAL_MODE) {
size_t wr_len = len;
const char* p = str;
while(wr_len--) usbSerialPutc(*p++);
}
#endif
#if defined(AUX_SERIAL)
#endif
#if defined(AUX_SERIAL)
if (auxSerialMode == UART_MODE_LUA) {
size_t wr_len = len;
const char* p = str;
while(wr_len--) auxSerialPutc(*p++);
}
#endif
#endif
#if defined(AUX2_SERIAL)
if (aux2SerialMode == UART_MODE_LUA) {
size_t wr_len = len;
@ -1636,9 +1662,6 @@ static int luaSerialWrite(lua_State * L)
while(wr_len--) aux2SerialPutc(*p++);
}
#endif
#else
debugPrintf("luaSerialWrite: %.*s",len,str);
#endif
return 0;
}
@ -1742,6 +1765,7 @@ const luaL_Reg opentxLib[] = {
#if defined(MULTIMODULE)
{ "multiBuffer", luaMultiBuffer },
#endif
{ "setSerialBaudrate", luaSetSerialBaudrate },
{ "serialWrite", luaSerialWrite },
{ "serialRead", luaSerialRead },
{ nullptr, nullptr } /* sentinel */