#define MSG_SDS_UPD 'u'
#define MSG_SPEC 'c'
+#define LOOPDELAY 100
+
void read_message(void)
{
//Find next task
default:
debug("Unknown message: %X", c);
}
+ } else {
+// debug("No input");
}
}
+unsigned long loopmillis = 0;
void loop(void)
{
- int ct;
+#ifdef ARDUINO_ESP8266_NODEMCU
+ if(getmillis()-loopmillis < LOOPDELAY){
+ return;
+ }
+ loopmillis = getmillis();
+#endif
+ debug("Loop");
+
+ struct task *t;
long cyclestart;
- struct task *curtask;
read_message();
//Run tasks
cyclestart = getmillis();
- for(ct = 0; ct<MAXTASKS; ct++){
- //See whether the task is even in use
- if((curtask = task_get(ct)) == NULL){
-// debug("Task %d not implemented\n", ct);
- continue;
- }
+ for(struct task *t = task_head(); t != NULL; t = task_next(t)){
//interrupt task
- if(is_interrupt_task(curtask) && had_interrupt(curtask)){
- debug("Interrupt task %d not implemented", ct);
- run_task(curtask);
+ if(is_interrupt_task(t) && had_interrupt(t)){
+ debug("Interrupt task %d not implemented", t->taskid);
+ run_task(t);
//Interval task, and interval passed
- } else if(cyclestart-curtask->lastrun > curtask->interval){
- debug("Running interval task: %d", ct);
- run_task(curtask);
+ } else if(cyclestart-t->lastrun > t->interval){
+ debug("Running interval task: %d", t->taskid);
+ run_task(t);
//Oneshot task, thus disable
- if(curtask->interval == 0){
- curtask->used = false;
- }
- curtask->lastrun = cyclestart;
+// if(t->interval == 0){
+// curtask->used = false;
+// }
+ t->lastrun = cyclestart;
}
}
}
#endif
//Initialize systems
- setup();
+ real_setup();
sds_init();
task_init();
debug("sending device spec");
+
+#ifndef ARDUINO_ESP8266_NODEMCU
while(true){
//Check for newtasks
loop();
- msdelay(100);
+ msdelay(LOOPDELAY);
}
-#ifndef ARDUINO_ESP8266_NODEMCU
return 0;
#endif
}