SMlib edge detection example?

Hi.

Does anyone have an example of edge detection RE,FE with SMlib?

/c

Here is my usage so far of SMlib.

SM AssetOperational(AssetInitialLoop);

State AssetInitialLoop()
{
  if (digitalRead(CONTROLLINO_I18)) {
    AssetOperational.Set(AssetNotRunningEntry,AssetNotRunningLoop);
  } else {
    AssetOperational.Set(AssetRunningEntry,AssetRunningLoop);
  }
}

State AssetNotRunningEntry()
{
  StaticJsonBuffer<MAX_MQTT_PAYLOAD> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["t"] = "E";
  root["n"] = "ASSET_OPERATION";
  root["v"] = "OFF"
  char buffer[128];
  root.printTo(buffer, sizeof(buffer));

  mqttClient.publish(concatTopics(CHAN_ROOT, CHAN_DEVICES, DEVICE_ID), buffer);
}

State AssetNotRunningLoop()
{
  if (digitalRead(CONTROLLINO_I18)) {
    AssetOperational.Set(AssetRunningEntry,AssetRunningLoop);
  }
}

State AssetRunningEntry()
{
  StaticJsonBuffer<MAX_MQTT_PAYLOAD> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["t"] = "E";
  root["n"] = "ASSET_OPERATION";
  root["v"] = "ON"
  char buffer[128];
  root.printTo(buffer, sizeof(buffer));

  mqttClient.publish(concatTopics(CHAN_ROOT, CHAN_DEVICES, DEVICE_ID), buffer);
}

State AssetRunningLoop()
{
  if (!digitalRead(CONTROLLINO_I18)) {
    AssetOperational.Set(AssetNotRunningEntry,AssetNotRunningLoop);
  }
}


void userSetup()
{
  pinMode(CONTROLLINO_I17, INPUT);
}

void userLoop()
{
  EXEC(AssetOperational);
}

First of all, im not sure why you would need the edge detection in your code since the states handle both set and reset of the signal. If you still decide that you need edge detection you will need a global integer type variable to hold the state of the signal between reads:

int bState
...
if(RE((digitalRead(CONTROLLINO_I18), bState)) AssetOperational.Set(..)

This would be justified if you want a for example a button press to toggle the states.

Secondly, do you really need the AssetInitialLoop? The only reason i can see for it is that you want to prevent the not running activity when starting with the io set.

Also you are reffering to CONTROLLINO_I17 in setup() and CONTROLLINO_I18 in the program

Thank You. That clarifies it.