fix(lua): Re-implement luaSetSerialBaudrate (#4501)
This commit is contained in:
@@ -356,7 +356,7 @@ void DebugViewPage::build(FormWindow* window)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(INTERNAL_GPS)
|
#if defined(INTERNAL_GPS)
|
||||||
if (hasSerialMode(UART_MODE_GPS) != -1) {
|
if (serialGetModePort(UART_MODE_GPS) >= 0) {
|
||||||
line = form->newLine(&grid);
|
line = form->newLine(&grid);
|
||||||
line->padAll(2);
|
line->padAll(2);
|
||||||
|
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ class InternalGPSWidget: public TopBarWidget
|
|||||||
|
|
||||||
void refresh(BitmapBuffer * dc) override
|
void refresh(BitmapBuffer * dc) override
|
||||||
{
|
{
|
||||||
if (hasSerialMode(UART_MODE_GPS) != -1) {
|
if (serialGetModePort(UART_MODE_GPS) >= 0) {
|
||||||
if (gpsData.fix) {
|
if (gpsData.fix) {
|
||||||
char s[10];
|
char s[10];
|
||||||
sprintf(s, "%d", gpsData.numSat);
|
sprintf(s, "%d", gpsData.numSat);
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ bool isSourceAvailable(int source)
|
|||||||
if (source >= MIXSRC_FIRST_SPACEMOUSE && source <= MIXSRC_LAST_SPACEMOUSE)
|
if (source >= MIXSRC_FIRST_SPACEMOUSE && source <= MIXSRC_LAST_SPACEMOUSE)
|
||||||
return false;
|
return false;
|
||||||
#elif defined(PCBHORUS) && defined(SPACEMOUSE)
|
#elif defined(PCBHORUS) && defined(SPACEMOUSE)
|
||||||
if ((hasSerialMode(UART_MODE_SPACEMOUSE) == -1) &&
|
if ((serialGetModePort(UART_MODE_SPACEMOUSE) < 0) &&
|
||||||
(source >= MIXSRC_FIRST_SPACEMOUSE && source <= MIXSRC_LAST_SPACEMOUSE))
|
(source >= MIXSRC_FIRST_SPACEMOUSE && source <= MIXSRC_LAST_SPACEMOUSE))
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
@@ -424,14 +424,6 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hasSerialMode(int mode)
|
|
||||||
{
|
|
||||||
for (int p = 0; p < MAX_SERIAL_PORTS; p++) {
|
|
||||||
if (serialGetMode(p) == mode) return p;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSerialModeAvailable(uint8_t port_nr, int mode)
|
bool isSerialModeAvailable(uint8_t port_nr, int mode)
|
||||||
{
|
{
|
||||||
#if defined(USB_SERIAL)
|
#if defined(USB_SERIAL)
|
||||||
@@ -492,7 +484,7 @@ bool isSerialModeAvailable(uint8_t port_nr, int mode)
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto p = hasSerialMode(mode);
|
auto p = serialGetModePort(mode);
|
||||||
if (p >= 0 && p != port_nr) return false;
|
if (p >= 0 && p != port_nr) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1014,7 +1006,7 @@ bool isTrainerModeAvailable(int mode)
|
|||||||
|
|
||||||
if (mode == TRAINER_MODE_MASTER_SERIAL) {
|
if (mode == TRAINER_MODE_MASTER_SERIAL) {
|
||||||
#if defined(SBUS_TRAINER)
|
#if defined(SBUS_TRAINER)
|
||||||
return hasSerialMode(UART_MODE_SBUS_TRAINER) >= 0;
|
return serialGetModePort(UART_MODE_SBUS_TRAINER) >= 0;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ bool isSourceAvailableInResetSpecialFunction(int index);
|
|||||||
bool isSourceAvailableInGlobalResetSpecialFunction(int index);
|
bool isSourceAvailableInGlobalResetSpecialFunction(int index);
|
||||||
bool isSwitchAvailable(int swtch, SwitchContext context);
|
bool isSwitchAvailable(int swtch, SwitchContext context);
|
||||||
bool isSerialModeAvailable(uint8_t port_nr, int mode);
|
bool isSerialModeAvailable(uint8_t port_nr, int mode);
|
||||||
int hasSerialMode(int mode);
|
|
||||||
bool isSwitchAvailableInLogicalSwitches(int swtch);
|
bool isSwitchAvailableInLogicalSwitches(int swtch);
|
||||||
bool isSwitchAvailableInCustomFunctions(int swtch);
|
bool isSwitchAvailableInCustomFunctions(int swtch);
|
||||||
bool isSwitchAvailableInMixes(int swtch);
|
bool isSwitchAvailableInMixes(int swtch);
|
||||||
|
|||||||
@@ -2258,24 +2258,13 @@ Set baudrate for serial port(s) affected to LUA
|
|||||||
*/
|
*/
|
||||||
static int luaSetSerialBaudrate(lua_State * L)
|
static int luaSetSerialBaudrate(lua_State * L)
|
||||||
{
|
{
|
||||||
// #if defined(AUX_SERIAL) || defined(AUX2_SERIAL)
|
int port_nr = serialGetModePort(UART_MODE_LUA);
|
||||||
// unsigned int baudrate = luaL_checkunsigned(L, 1);
|
if (port_nr < 0) return 0;
|
||||||
// #endif
|
|
||||||
|
|
||||||
// TODO: add some callbacks for serial settings
|
uint32_t baudrate = luaL_checkunsigned(L, 1);
|
||||||
// #if defined(AUX_SERIAL)
|
serialSetBaudrate(port_nr, baudrate);
|
||||||
// if (auxSerialMode == UART_MODE_LUA) {
|
|
||||||
// auxSerialStop();
|
return 0;
|
||||||
// auxSerialSetup(baudrate, false);
|
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
// #if defined(AUX2_SERIAL)
|
|
||||||
// if (aux2SerialMode == UART_MODE_LUA) {
|
|
||||||
// aux2SerialStop();
|
|
||||||
// aux2SerialSetup(baudrate, false);
|
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*luadoc
|
/*luadoc
|
||||||
|
|||||||
@@ -379,6 +379,38 @@ void serialSetPower(uint8_t port_nr, bool enabled)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uint32_t serialGetBaudrate(uint8_t port_nr)
|
||||||
|
{
|
||||||
|
auto state = getSerialPortState(port_nr);
|
||||||
|
if (!state || !state->port || !state->usart_ctx)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
auto port = state->port;
|
||||||
|
if (!port->uart || !port->uart->getBaudrate) return 0;
|
||||||
|
|
||||||
|
return port->uart->getBaudrate(state->usart_ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void serialSetBaudrate(uint8_t port_nr, uint32_t baudrate)
|
||||||
|
{
|
||||||
|
auto state = getSerialPortState(port_nr);
|
||||||
|
if (!state || !state->port || !state->usart_ctx)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto port = state->port;
|
||||||
|
if (!port->uart || !port->uart->setBaudrate) return;
|
||||||
|
|
||||||
|
port->uart->setBaudrate(state->usart_ctx, baudrate);
|
||||||
|
}
|
||||||
|
|
||||||
|
int serialGetModePort(int mode)
|
||||||
|
{
|
||||||
|
for (int p = 0; p < MAX_SERIAL_PORTS; p++) {
|
||||||
|
if (serialGetMode(p) == mode) return p;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void serialInit(uint8_t port_nr, int mode)
|
void serialInit(uint8_t port_nr, int mode)
|
||||||
{
|
{
|
||||||
auto state = getSerialPortState(port_nr);
|
auto state = getSerialPortState(port_nr);
|
||||||
|
|||||||
@@ -30,11 +30,18 @@
|
|||||||
#define SERIAL_CONF_POWER_BIT 7 /* MSBit of the configuration byte */
|
#define SERIAL_CONF_POWER_BIT 7 /* MSBit of the configuration byte */
|
||||||
|
|
||||||
const etx_serial_port_t* serialGetPort(uint8_t port_nr);
|
const etx_serial_port_t* serialGetPort(uint8_t port_nr);
|
||||||
|
|
||||||
int serialGetMode(uint8_t port_nr);
|
int serialGetMode(uint8_t port_nr);
|
||||||
void serialSetMode(uint8_t port_nr, int mode);
|
void serialSetMode(uint8_t port_nr, int mode);
|
||||||
|
|
||||||
bool serialGetPower(uint8_t port_nr);
|
bool serialGetPower(uint8_t port_nr);
|
||||||
void serialSetPower(uint8_t port_nr, bool enabled);
|
void serialSetPower(uint8_t port_nr, bool enabled);
|
||||||
|
|
||||||
|
uint32_t serialGetBaudrate(uint8_t port_nr);
|
||||||
|
void serialSetBaudrate(uint8_t port_nr, uint32_t baudrate);
|
||||||
|
|
||||||
|
int serialGetModePort(int mode);
|
||||||
|
|
||||||
void initSerialPorts();
|
void initSerialPorts();
|
||||||
void serialInit(uint8_t port_nr, int mode);
|
void serialInit(uint8_t port_nr, int mode);
|
||||||
void serialStop(uint8_t port_nr);
|
void serialStop(uint8_t port_nr);
|
||||||
|
|||||||
Reference in New Issue
Block a user