Created
October 4, 2019 09:12
-
-
Save schmurfy/7f6fc20b192ec13af20ca9477b2e8f23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mgos.h" | |
#define UART 2 | |
static void _test_cb(struct mg_rpc_request_info *ri, void *cb_arg, | |
struct mg_rpc_frame_info *fi, struct mg_str args) { | |
size_t sz | |
sz = mgos_uart_write(UART, "\x0C", 1); | |
if( sz != 1 ){ | |
LOG(LL_ERROR, ("failed to write cmd: %d", sz)); | |
return; | |
} | |
while( mgos_uart_read_avail(uart_no) == 0 ){ | |
// how to yield to event loop ? | |
} | |
sz = mgos_uart_read(...); | |
} | |
enum mgos_app_init_result mgos_app_init(void) { | |
struct mgos_uart_config ucfg; | |
// setup serial communication | |
mgos_uart_config_set_defaults(UART, &ucfg); | |
ucfg.baud_rate = 76800; | |
ucfg.rx_buf_size = 1500; | |
ucfg.tx_buf_size = 1500; | |
if( !mgos_uart_configure(UART, &ucfg) ){ | |
LOG(LL_ERROR, ("Failed to configure UART%d", UART)); | |
return; | |
} | |
mg_rpc_add_handler(mgos_rpc_get_global(), "_test", "{}", _test_cb, NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment