Haven't been able to test yet as my PiFace has been loaned. With the latest build I think this is the basic script to manage polling the inputs. Next step is to implement the WebServiceCallReceived functionality to change the outputs. I will get to it later this week.
Nick
var moduleDomain = "Components.PiFaceDigital";
// This examples will add 16 modules of type "Switch"
// corresponding to piFace Input and Output pins
//
var piFace = new PiFaceDigitalDevice();
var ip_OnStateChanged = new InputPinChangedHandler ( (object sender, InputPinChangedArgs e) =>
{
var moduleName = "Input" + e.pin.Id;
if (e.pin.State)
{
Modules.InDomain(moduleDomain).WithName(moduleName).On();
}
else
{
Modules.InDomain(moduleDomain).WithName(moduleName).Off();
}
}
);
When.ProgramStopping(()=>{
((IDisposable)piFace).Dispose();
return true;
});
foreach (var inputPin in piFace.InputPins)
{
inputPin.OnStateChanged += ip_OnStateChanged;
Program.AddVirtualModule(moduleDomain, "Input" + inputPin.Id, "Sensor", "homegenie/generic/sensor");
}
foreach (var outputPin in piFace.OutputPins)
{
Program.AddVirtualModule(moduleDomain, "Output" + outputPin.Id, "Switch", "");
}
// status polling loop
while (Program.IsEnabled)
{
Pause(0.5); // 500 ms poll resolution
//
piFace.PollInputPins();
}