Closed aifer2007 closed 7 years ago
I make my own uart js api for ESP32.
api_uart.js: let Serial = { // setStdout: ffi('int mgos_set_stdout_uart(int)'), setDebug: ffi('int mgos_init_debug_uart(int)'), write: ffi('int mgos_uart_write(int, char *, int)'), enableWrite: ffi('void mgos_uart_set_write_enabled(int, bool)'), isInited: ffi('int mgos_uart_is_inited(int)'), };
in mos.yml: ffi_symbols:
and then, in init.js: // Load Mongoose OS API load('api_timer.js'); load('api_gpio.js'); load('api_uart.js');
let uartNo = 1; Serial.setDebug(uartNo); // baut: 115200 let str = "Hello from ESP32-Serial: " + JSON.stringify(uartNo) + "\r\n"; let isInited = Serial.isInited(uartNo);
// Blink built-in LED every second let PIN = ffi('int get_led_gpio_pin()')(); // Helper C function that returns a // built-in LED GPIO GPIO.set_mode(PIN, GPIO.MODE_OUTPUT); Timer.set(1000 / milliseconds /, 1 / repeat /, function(pin) { let value = GPIO.toggle(pin); print(value ? 'Tick' : 'Tock'); print(isInited); print(Serial.write(uartNo, str, str.length)); }, PIN);
It works well.
I can receive the string on my notebook with a UART-USB converter(FT232)。
on ESP32, the UART2 is not available yet.
And the pins of a UART can't be assigned by programmer.
RPC api has been added
Working on UART API now.
That's great!
Great!
发自我的 iPhone
在 2017年4月10日,上午12:27,Sergey Lyubka notifications@github.com 写道:
Done. https://mongoose-os.com/docs/#/js-api/api_uart.js/
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
mos has no javascript UART and SPI APIs? and RPCs?