PikaStdDevice_BaseDev.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "PikaStdDevice_BaseDev.h"
  2. #include "PikaStdDevice_common.h"
  3. #if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 10, 4)
  4. #error "This library requires PikaScript version 1.10.4 or higher"
  5. #endif
  6. PikaEventListener* g_pika_device_event_listener;
  7. void PikaStdDevice_BaseDev_addEventCallback(PikaObj* self, Arg* eventCallBack) {
  8. #if PIKA_EVENT_ENABLE
  9. /* init event_listener for the first time */
  10. if (NULL == g_pika_device_event_listener) {
  11. pika_eventListener_init(&g_pika_device_event_listener);
  12. }
  13. if (PIKA_RES_OK != obj_runNativeMethod(self, "platformGetEventId", NULL)) {
  14. obj_setErrorCode(self, 1);
  15. __platform_printf("Error: Method %s no found.\r\n",
  16. "platformGetEventId");
  17. }
  18. uint32_t eventId = obj_getInt(self, "eventId");
  19. pika_eventListener_registEventCallback(g_pika_device_event_listener,
  20. eventId, eventCallBack);
  21. #else
  22. obj_setErrorCode(self, 1);
  23. obj_setSysOut(self, "[error] PIKA_EVENT_ENABLE is disabled.");
  24. #endif
  25. }
  26. void PikaStdDevice_BaseDev_addEventCallBack(PikaObj* self, Arg* eventCallBack) {
  27. pika_platform_printf("Warning: Method %s is deprecated, please use %s.\r\n",
  28. "addEventCallBack", "addEventCallback");
  29. PikaStdDevice_BaseDev_addEventCallback(self, eventCallBack);
  30. }
  31. void PikaStdDevice_BaseDev_platformGetEventId(PikaObj* self) {
  32. ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
  33. }