]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/background.c
working host communication, new command: connect
[z180-stamp.git] / avr / background.c
index 37e4b02c12b9eaa50d42bce39844436bdd9f09d6..0e1ca40047c5c464fd944fc78873c6d014fb9f06 100644 (file)
@@ -4,15 +4,39 @@
 
 #define BG_FUNC_MAX 5
 
-static bg_func func_tab[BG_FUNC_MAX];
+static struct { 
+       bg_func fct;
+       int param;
+} func_tab[BG_FUNC_MAX];
+
 static int_fast8_t fcount;
 
-int bg_register(bg_func f)
+int bg_register(bg_func f, int initval)
 {
        if (fcount < BG_FUNC_MAX) { 
-               func_tab[fcount++] = f;
+               func_tab[fcount].fct = f;
+               func_tab[fcount].param = initval;
+               return ++fcount - 1;
+       }
+       return -1;
+}
+
+int bg_setstat(int handle, int val)
+{
+       if (handle < fcount) {
+               func_tab[handle].param = val;
                return 1;
        }
+       
+       return 0;
+}
+
+
+int bg_getstat(int handle)
+{
+       if (handle < fcount) {
+               return func_tab[handle].param;
+       }
        return 0;
 }
 
@@ -21,8 +45,9 @@ void bg_shed(void)
 {
        static int_fast8_t current;
        
-       if (func_tab[current]) {
-               func_tab[current](0);
+       if (func_tab[current].fct) {
+               int v = func_tab[current].fct(func_tab[current].param);
+               func_tab[current].param = v;
        }
        if (++current >= fcount)
                current = 0;