+/**
+ * Handles control of the actuators.
+ */
+void ActuatorHandler(FCGIContext *context, int id, const char *set_value) {
+ char *ptr;
+
+ switch(id) { //Add new actuators here
+ case ACT_PREG: //Suppose is pressure regulator. 0-700 input (kPa)
+ {
+ int value = strtol(set_value, &ptr, 10);
+ if (*ptr == '\0' && value >= 0 && value <= 700) {
+ FCGI_BeginJSON(context, STATUS_OK);
+ FCGI_JSONKey("description");
+ FCGI_JSONValue("\"Set pressure to %d kPa!\"", value);
+ FCGI_EndJSON();
+ } else {
+ FCGI_RejectJSONEx(context,
+ STATUS_ERROR, "Invalid pressure specified.");
+ }
+ } break;
+ case ACT_SOLENOID1:
+ {
+ int value = strtol(set_value, &ptr, 10);
+ if (*ptr == '\0') {
+ const char *state = "off";
+ if (value)
+ state = "on";
+ FCGI_BeginJSON(context, STATUS_OK);
+ FCGI_JSONKey("description");
+ FCGI_JSONValue("\"Solenoid 1 turned %s!\"", state);
+ FCGI_EndJSON();
+ } else {
+ FCGI_RejectJSON(context);
+ }
+ } break;
+ default:
+ FCGI_RejectJSONEx(context,
+ STATUS_ERROR, "Invalid actuator id specified.");
+ }
+}
+