Hi,
Now that I've managed to get the MCP23017 working correctly, I started writing a SmartControl module to use the inputs of the MCP23017 as control buttons :
1 button mode :
short press (<2seconds) -> Toggle On and Off
long press (>2seconds) -> change the level by +5 or -5, changing bright and dim every time i release the button
(sensors are working inversed for now : so they are at 1 all the time and a key press sets them to 0)
The program I made so far work without errors but when it is entering the long press loop it changes the module level by 5 every 10 seconds or more instead of the pause of 1 second.
Am I doing it right or do i loch up some other triggers by programming this way?
var SMART_CONTROL_ENABLE = "HomeGenie.SmartControl.Enable";
var SENSOR_NAME = "HomeGenie.SmartControl.PushSensor";
var smart_devices = Modules.WithFeature(SMART_CONTROL_ENABLE);
//
When.ModuleParameterIsChanging((module, parameter) => {
if (module.IsOfDeviceType("Sensor"))
{
if (parameter.Name == "Status.Level")
{
var motionlevel = parameter.DecimalValue;
if (motionlevel < 1)
{
smart_devices.Each((mod)=>
{
if (mod.Parameter(SENSOR_NAME).Value == module.Instance.Name)
{
Pause(1);
if (module.Level == 0)
{
while(module.Level == 0)
{
mod.Level = (mod.Level - 5);
// If i set a pause of 1 second it somhow takes 10 seconds
//Pause(1);
}
}
else {
mod.Toggle();
}
//if (mod.Level == 0)
//{
//Program.Notify("Smart Control", module.Instance.Name + "<br> Toggled " + mod.Instance.Address + " " + mod.Instance.Name);
//}
}
//
return false;
});
}
else
{
// timeout before turning it off
}
}
}
return true;
});
Program.GoBackground();
Thanks,
Christophe