build C support for interrupts
authorMart Lubbers <mart@martlubbers.net>
Thu, 2 Mar 2017 17:29:42 +0000 (18:29 +0100)
committerMart Lubbers <mart@martlubbers.net>
Thu, 2 Mar 2017 17:29:42 +0000 (18:29 +0100)
client/main.c
client/task.c
client/task.h

index f86beff..1818238 100644 (file)
@@ -74,17 +74,19 @@ void loop(void)
 //                     debug("Task %d not implemented\n", ct);
                        continue;
                }
-               //Onshot task
-               if(curtask->interval == 0){
-                       run_task(curtask);
-                       curtask->used = false;
-               //Interrupt task
-               } else if(curtask->interval & 32768){
+               //interrupt task
+               if(is_interrupt_task(curtask) && had_interrupt(curtask)){
                        debug("Interrupt task %d not implemented", ct);
-               //Interval task, check if interval is passed
+                       run_task(curtask);
+               //Interval task, and interval passed
                } else if(cyclestart-curtask->lastrun > curtask->interval){
                        debug("Running interval task: %d", ct);
                        run_task(curtask);
+
+                       //Oneshot task, thus disable
+                       if(curtask->interval == 0){
+                               curtask->used = false;
+                       }
                        curtask->lastrun = cyclestart;
                }
        }
index 1dd8ffb..dfdb71b 100644 (file)
@@ -30,6 +30,12 @@ void task_register(void)
        memset(&tasks[ct], 0, sizeof(struct task));
        //Read interval
        tasks[ct].interval = read16();
+
+       //Interrupt task
+       if(is_interrupt_task(&tasks[ct])) {
+
+       }
+
        //Read tasklength
        tasks[ct].tlen = read16();
        debug("task interval: %d, length: %d\n",
@@ -53,6 +59,18 @@ void task_register(void)
        write_byte('\n');
 }
 
+bool is_interrupt_task(struct task *t)
+{
+       return t->interval & (2 <<14);
+}
+
+bool had_interrupt(struct task* t)
+{
+       //Not implemented yet...
+       return false;
+       (void)t;
+}
+
 void task_delete(void)
 {
        uint8_t c = read16();
index 0ea1b99..6c7dfd3 100644 (file)
@@ -15,6 +15,9 @@ struct task {
        bool used;
 };
 
+bool is_interrupt_task(struct task* t);
+bool had_interrupt(struct task* t);
+
 void task_init(void);
 void task_register(void);
 void task_delete(void);