PikaStdDevice_BaseDev.c 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. obj_setArg(self, "eventCallBack", eventCallBack);
  10. /* init event_listener for the first time */
  11. if (NULL == g_pika_device_event_listener) {
  12. pks_eventListener_init(&g_pika_device_event_listener);
  13. }
  14. if (PIKA_RES_OK != obj_runNativeMethod(self, "platformGetEventId", NULL)) {
  15. obj_setErrorCode(self, 1);
  16. __platform_printf("Error: Method %s no found.\r\n",
  17. "platformGetEventId");
  18. }
  19. uint32_t eventId = obj_getInt(self, "eventId");
  20. pks_eventListener_registEvent(g_pika_device_event_listener, eventId, self);
  21. #else
  22. obj_setErrorCode(self, 1);
  23. obj_setSysOut(self, "[error] PIKA_EVENT_ENABLE is disabled.");
  24. #endif
  25. }
  26. void PikaStdDevice_BaseDev_platformGetEventId(PikaObj* self) {
  27. ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
  28. }