2022-01-20 18:16:08 +08:00
|
|
|
#include "PikaStdTask_Task.h"
|
2022-01-20 21:50:38 +08:00
|
|
|
#include "BaseObj.h"
|
2022-01-20 18:16:08 +08:00
|
|
|
#include "PikaVM.h"
|
|
|
|
|
|
|
|
extern PikaObj* __pikaMain;
|
|
|
|
void PikaStdTask_Task___init__(PikaObj* self) {
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"calls.__init__()\n"
|
|
|
|
"is_period = 0\n");
|
|
|
|
obj_setPtr(__pikaMain, "__calls", obj_getPtr(self, "calls"));
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
2022-01-20 21:50:38 +08:00
|
|
|
|
2022-01-20 18:16:08 +08:00
|
|
|
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"calls.append('always')\n"
|
|
|
|
"calls.append(fun_todo)\n");
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
2022-01-20 21:50:38 +08:00
|
|
|
|
2022-01-20 22:24:08 +08:00
|
|
|
void PikaStdTask_Task_call_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
|
|
|
obj_setArg(self, "fun_when", fun_when);
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"calls.append('when')\n"
|
|
|
|
"calls.append(fun_when)\n"
|
|
|
|
"calls.append(fun_todo)\n");
|
2022-01-23 21:50:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdTask_Task_call_period_ms(PikaObj* self,
|
|
|
|
Arg* fun_todo,
|
|
|
|
int period_ms) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
|
|
|
obj_setInt(self, "period_ms", period_ms);
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"calls.append('period_ms')\n"
|
|
|
|
"calls.append(period_ms)\n"
|
|
|
|
"calls.append(fun_todo)\n"
|
2022-01-24 19:08:33 +08:00
|
|
|
"calls.append(0)\n"
|
2022-01-24 18:50:20 +08:00
|
|
|
"is_period = 1\n");
|
2022-01-20 22:24:08 +08:00
|
|
|
}
|
2022-01-20 18:16:08 +08:00
|
|
|
|
|
|
|
void PikaStdTask_Task_run_once(PikaObj* self) {
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(self,
|
|
|
|
"if is_period:\n"
|
|
|
|
" platformGetTick()\n");
|
2022-01-23 21:50:05 +08:00
|
|
|
/* transfer the tick to pikaMain */
|
|
|
|
obj_setInt(__pikaMain, "__tick", obj_getInt(self, "tick"));
|
2022-01-24 18:50:20 +08:00
|
|
|
obj_run(__pikaMain,
|
|
|
|
"len = __calls.len()\n"
|
|
|
|
"mode = 'none'\n"
|
|
|
|
"info_index = 0\n"
|
|
|
|
"for i in range(0, len):\n"
|
|
|
|
" if len == 0:\n"
|
|
|
|
" break\n"
|
|
|
|
" if info_index == 0:\n"
|
|
|
|
" mode = __calls[i]\n"
|
|
|
|
" info_index = 1\n"
|
|
|
|
" elif info_index == 1:\n"
|
|
|
|
" if mode == 'always':\n"
|
|
|
|
" todo = __calls[i]\n"
|
|
|
|
" todo()\n"
|
|
|
|
" info_index = 0\n"
|
|
|
|
" elif mode == 'when':\n"
|
|
|
|
" when = __calls[i]\n"
|
|
|
|
" info_index = 2\n"
|
2022-01-24 19:08:33 +08:00
|
|
|
" elif mode == 'period_ms':\n"
|
|
|
|
" period_ms = __calls[i]\n"
|
|
|
|
" info_index = 2\n"
|
2022-01-24 18:50:20 +08:00
|
|
|
" elif info_index == 2:\n"
|
|
|
|
" if mode == 'when':\n"
|
|
|
|
" if when():\n"
|
|
|
|
" todo = __calls[i]\n"
|
|
|
|
" todo()\n"
|
2022-01-24 19:08:33 +08:00
|
|
|
" info_index = 0\n"
|
|
|
|
" elif mode == 'period_ms':\n"
|
|
|
|
" todo = __calls[i]\n"
|
|
|
|
" info_index = 3\n"
|
|
|
|
" elif info_index == 3:\n"
|
|
|
|
" if mode == 'period_ms':\n"
|
|
|
|
" if __tick > __calls[i]:\n"
|
|
|
|
" todo()\n"
|
|
|
|
" __calls[i] = __tick + period_ms\n"
|
|
|
|
" info_index = 0\n"
|
2022-01-24 18:50:20 +08:00
|
|
|
"\n");
|
2022-01-23 21:50:05 +08:00
|
|
|
/* Python
|
|
|
|
__len = __calls_period.len()
|
|
|
|
for i in range(0, __len):
|
|
|
|
if __len == 0:
|
|
|
|
break
|
|
|
|
time = __time_period[i]
|
|
|
|
if __tick > __time_period[i]:
|
|
|
|
todo = __calls_period[i]
|
|
|
|
todo()
|
|
|
|
__time_period[i] = __tick + __assert_period[i]
|
|
|
|
*/
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
|
|
|
|
2022-01-20 21:50:38 +08:00
|
|
|
void PikaStdTask_Task_run_always(PikaObj* self) {
|
|
|
|
while (1) {
|
2022-01-20 18:16:08 +08:00
|
|
|
PikaStdTask_Task_run_once(self);
|
|
|
|
}
|
|
|
|
}
|
2022-01-23 21:50:05 +08:00
|
|
|
|
|
|
|
void PikaStdTask_Task_platformGetTick(PikaObj* self) {
|
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|