Work on user based control
[matches/MCTX3420.git] / server / actuator.c
index 04938ba..9b9a1a8 100644 (file)
@@ -36,12 +36,17 @@ int Actuator_Add(const char * name, int user_id, SetFn set, InitFn init, CleanFn
        a->name = name;
        a->set = set; // Set read function
        a->init = init; // Set init function
-       if (init != NULL)
-               init(name, user_id); // Call it
+
        a->sanity = sanity;
 
        pthread_mutex_init(&(a->mutex), NULL);
 
+       if (init != NULL)
+       {
+               if (!init(name, user_id))
+                       Fatal("Couldn't initialise actuator %s", name);
+       }
+
        Actuator_SetValue(a, initial_value, false);
 
        return g_num_actuators;
@@ -349,7 +354,7 @@ void Actuator_Handler(FCGIContext * context, char * params)
                FCGI_RejectJSON(context, "No id or name supplied");
                return;
        }
-       else if (id < 0 || id >= ACTUATORS_MAX)
+       else if (id < 0 || id >= g_num_actuators)
        {
                FCGI_RejectJSON(context, "Invalid Actuator id");
                return;
@@ -386,7 +391,6 @@ void Actuator_Handler(FCGIContext * context, char * params)
                        return;
                }
                Actuator_SetControl(a, &c);
-
        }
        
        // Begin response

UCC git Repository :: git.ucc.asn.au