clib.lua 871 B

1234567891011121314151617181920212223242526272829303132333435
  1. --- 模块功能 完善luat的c库接口
  2. -- @module clib
  3. -- @author 小强
  4. -- @license MIT
  5. -- @copyright openLuat.com
  6. -- @release 2017.9.20
  7. local uartReceiveCallbacks = {}
  8. local uartSentCallbacks = {}
  9. --- uart.on
  10. -- @param id uart id: (uart.ATC, 1, 2)
  11. -- @param event uart event: "recieve", "sent"
  12. -- @param callback uart event callback function
  13. -- @return 无
  14. -- @usage uart.on()
  15. uart.on = function(id, event, callback)
  16. if event == "receive" then
  17. uartReceiveCallbacks[id] = callback
  18. elseif event == "sent" then
  19. uartSentCallbacks[id] = callback
  20. end
  21. end
  22. rtos.on(rtos.MSG_UART_RXDATA, function(id)
  23. if uartReceiveCallbacks[id] then
  24. uartReceiveCallbacks[id]()
  25. end
  26. end)
  27. rtos.on(rtos.MSG_UART_TX_DONE, function(id)
  28. if uartSentCallbacks[id] then
  29. uartSentCallbacks[id]()
  30. end
  31. end)