Skip to content

Instantly share code, notes, and snippets.

@schmurfy
Created October 4, 2019 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmurfy/7f6fc20b192ec13af20ca9477b2e8f23 to your computer and use it in GitHub Desktop.
Save schmurfy/7f6fc20b192ec13af20ca9477b2e8f23 to your computer and use it in GitHub Desktop.
#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