rpc_keyboard_stub.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #include "rpc_keyboard.h"
  2. #include <furi.h>
  3. static bool rpc_keyboard_functions_check_version(RpcKeyboardFunctions *stub)
  4. {
  5. furi_check(stub);
  6. if (stub->major == 1 && stub->minor > 2)
  7. {
  8. return true;
  9. }
  10. FURI_LOG_D("RpcKeyboard", "Unsupported version %d.%d", stub->major, stub->minor);
  11. return false;
  12. }
  13. /**
  14. * @brief Get the pubsub object for the remote keyboard.
  15. * @details This function returns the pubsub object, use to subscribe to keyboard events.
  16. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  17. * @return FuriPubSub* pointer to the pubsub object.
  18. */
  19. FuriPubSub *rpc_keyboard_get_pubsub(RpcKeyboard *rpc_keyboard)
  20. {
  21. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  22. if (!rpc_keyboard_functions_check_version(stub))
  23. {
  24. return NULL;
  25. }
  26. return stub->fn_get_pubsub((RpcKeyboard *)rpc_keyboard);
  27. }
  28. /**
  29. * @brief Enable or disable newline character submitting the text.
  30. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  31. * @param[in] enable true to enable, false to disable.
  32. */
  33. void rpc_keyboard_newline_enable(RpcKeyboard *rpc_keyboard, bool enable)
  34. {
  35. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  36. if (!rpc_keyboard_functions_check_version(stub))
  37. {
  38. return;
  39. }
  40. stub->fn_newline_enable((RpcKeyboard *)rpc_keyboard, enable);
  41. }
  42. /**
  43. * @brief Publish a single key pressed on the remote keyboard.
  44. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  45. * @param[in] character the character that was pressed.
  46. */
  47. void rpc_keyboard_publish_char(RpcKeyboard *rpc_keyboard, char character)
  48. {
  49. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  50. if (!rpc_keyboard_functions_check_version(stub))
  51. {
  52. return;
  53. }
  54. stub->fn_publish_char((RpcKeyboard *)rpc_keyboard, character);
  55. }
  56. /**
  57. * @brief Publish a macro key pressed on the remote keyboard.
  58. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  59. * @param[in] character the macro key that was pressed.
  60. */
  61. void rpc_keyboard_publish_macro(RpcKeyboard *rpc_keyboard, char macro)
  62. {
  63. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  64. if (!rpc_keyboard_functions_check_version(stub))
  65. {
  66. return;
  67. }
  68. stub->fn_publish_macro((RpcKeyboard *)rpc_keyboard, macro);
  69. }
  70. /**
  71. * @brief Get the macro text associated with a macro key.
  72. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  73. * @param[in] macro the macro key.
  74. * @return char* pointer to the macro text. NULL if the macro key is not set. User must free the memory.
  75. */
  76. char *rpc_keyboard_get_macro(RpcKeyboard *rpc_keyboard, char macro)
  77. {
  78. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  79. if (!rpc_keyboard_functions_check_version(stub))
  80. {
  81. return NULL;
  82. }
  83. return stub->fn_get_macro((RpcKeyboard *)rpc_keyboard, macro);
  84. }
  85. /**
  86. * @brief Set the macro text associated with a macro key.
  87. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  88. * @param[in] macro the macro key.
  89. * @param[in] value the macro text.
  90. */
  91. void rpc_keyboard_set_macro(RpcKeyboard *rpc_keyboard, char macro, char *value)
  92. {
  93. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  94. if (!rpc_keyboard_functions_check_version(stub))
  95. {
  96. return;
  97. }
  98. stub->fn_set_macro((RpcKeyboard *)rpc_keyboard, macro, value);
  99. }
  100. /**
  101. * @brief Initializes the chatpad and starts listening for keypresses.
  102. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  103. */
  104. void rpc_keyboard_chatpad_start(RpcKeyboard *rpc_keyboard)
  105. {
  106. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  107. if (!rpc_keyboard_functions_check_version(stub))
  108. {
  109. return;
  110. }
  111. stub->fn_chatpad_start((RpcKeyboard *)rpc_keyboard);
  112. }
  113. /**
  114. * @brief Stops the chatpad & frees resources.
  115. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  116. */
  117. void rpc_keyboard_chatpad_stop(RpcKeyboard *rpc_keyboard)
  118. {
  119. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  120. if (!rpc_keyboard_functions_check_version(stub))
  121. {
  122. return;
  123. }
  124. stub->fn_chatpad_stop((RpcKeyboard *)rpc_keyboard);
  125. }
  126. /**
  127. * @brief Get the status of the chatpad.
  128. * @param[in] rpc_keyboard pointer to the RECORD_RPC_KEYBOARD.
  129. * @return RpcKeyboardChatpadStatus the status of the chatpad.
  130. */
  131. RpcKeyboardChatpadStatus rpc_keyboard_chatpad_status(RpcKeyboard *rpc_keyboard)
  132. {
  133. RpcKeyboardFunctions *stub = (RpcKeyboardFunctions *)rpc_keyboard;
  134. if (!rpc_keyboard_functions_check_version(stub))
  135. {
  136. return RpcKeyboardChatpadStatusError;
  137. }
  138. return stub->fn_chatpad_status((RpcKeyboard *)rpc_keyboard);
  139. }