 void irqh1()
 {
   _counters[1]++;
+}
+
+
+int resetVariable(char *name)
+{
+  for (int i=0;i<sizeof(variables) / sizeof(struct variable);i++) {
+    if (!strcmp(variables[i].name,name)) {
+      variables[i].value=origVariables[i].value;
+      return 0;
+    }
+  }
+  return 1;
 }
 
 void processSensors()

  time_t last_change;
};

// simple conditions for logical operations.
struct condition {
  int id;
  struct ad *source;
  char op;
  dig2a value;
  struct outIo *target;
  int state;
};


struct variable variables[]= {
  {"boilTemp",60.0},
  {"radiatorTemp",20.0}
};

// in future this table shall be stored mainly in eeprom.
// and so is it's size

{
  float value;
  float limit;
  float off;
  struct outIo *targetIo;
  struct variable *var;


  for (int i=0;i<sizeof(conditions) / sizeof(struct condition);i++) {
    if (conditions[i].source == source) {
      value=source->measured.analog;
      limit=conditions[i].limit->value;
      switch (conditions[i].method) {
      case METHOD_TURNON:
	targetIo=(struct outIo *) conditions[i].target;
	off=limit + conditions[i].limit2->value;
	if (value < limit && targetIo->state == 0) {
	  targetIo->state = 1;
	  targetIo->last_change = ts;
	  digitalWrite(targetIo->port,1);
	}
	else if (value > off && targetIo->state == 1 ) {
	  targetIo->state = 0;
	  targetIo->last_change = ts;
	  digitalWrite(targetIo->port,0);
	}
	break;

      case METHOD_CHANGELIMIT:
	var=(struct variable *) conditions[i].target;
	if (value < limit) {
	  conditions[i].limit2->value=var->value;
	  Serial.print("changed ");
	  Serial.print(conditions[i].limit2->name);
	  Serial.print(" limit to ");
	  Serial.print(conditions[i].limit2->value);
          Serial.print(" = ");
          Serial.println(var->name);
	}
	else {
	  resetVariable(conditions[i].limit2->name);
	  Serial.print("resetted ");
	  Serial.print(conditions[i].limit2->name);
	  Serial.print(" limit to ");
	  Serial.println(conditions[i].limit2->value);
	}
	break;
      }
    }
  }
