Created
January 4, 2017 04:05
-
-
Save jianingy/47d943152c683f9a0e434b3b106f36f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* filename : background.cpp | |
* created at : 2016-10-21 11:28:31 | |
* author : Jianing Yang <[email protected]> | |
*/ | |
#include "background.h" | |
task_t TASKS[10] = {NULL}; | |
int register_bg_task(int id, task_t cb) { | |
if (id > 20) | |
return -1; | |
LOG("register task %d with %p", id, cb); | |
TASKS[id] = cb; | |
return 0; | |
} | |
int schedule(void *userargs) { | |
yield(); | |
for (int i = 0; i < sizeof(TASKS) / sizeof(task_t); i++) { | |
task_t task = TASKS[i]; | |
if (task) { | |
task(userargs); | |
} | |
} | |
} | |
void sleep_ms(unsigned long ms, void *userargs) { | |
unsigned long start = millis(); | |
while (millis() - start < ms) | |
schedule(userargs); | |
} | |
void sleep_ms(unsigned long ms) { | |
sleep_ms(ms, NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment