Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for !IN and Status.Level #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
<?xml version="1.0" encoding="utf-16"?>
<ProgramBlock xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ConditionType>OnTrue</ConditionType>
<Conditions>
<ProgramCondition>
<Domain>HomeAutomation.ZWave</Domain>
<Target>37</Target>
<Property>Sensor.DoorWindow</Property>
<ComparisonOperator>Equals</ComparisonOperator>
<ComparisonValue>255</ComparisonValue>
</ProgramCondition>
</Conditions>
<Commands>
<ProgramCommand>
<Domain>HomeAutomation.ZWave</Domain>
<Target>4</Target>
<CommandString>Control.Off</CommandString>
<CommandArguments />
</ProgramCommand>
</Commands>
<ScriptCondition>Program.AddOption("GPIO4", "OUT", "GPIO04 (IN, OUT or OFF)", "text");
<ProgramBlock xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ScriptSetup>
Program.AddOption("GPIO4", "OFF", "GPIO04 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO17", "OFF", "GPIO17 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO18", "OFF", "GPIO18 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO21", "OUT", "GPIO21 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO22", "OUT", "GPIO22 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO23", "OUT", "GPIO23 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO24", "OUT", "GPIO24 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO25", "OUT", "GPIO25 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO21", "OFF", "GPIO21 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO22", "OFF", "GPIO22 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO23", "OFF", "GPIO23 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO24", "OFF", "GPIO24 (IN, OUT or OFF)", "text");
Program.AddOption("GPIO25", "OFF", "GPIO25 (IN, OUT or OFF)", "text");
Program.Run();
</ScriptCondition>
</ScriptSetup>
<ScriptSource>var moduleDomain = "RaspberryPi.Gpio";

var pinMapping = new List&lt;dynamic&gt;();
Expand Down Expand Up @@ -59,6 +42,7 @@ for (int p = 0; p &lt; pinMapping.Count; p++)
if (pc.Direction == PinDirection.Input)
{
configuration[p] = new InputPinConfiguration(PinMapping.ToProcessor(pc.Pin));
((InputPinConfiguration)configuration[p]).Reversed = pc.Reversed;
if (pc.Config.EndsWith("+"))
{
((InputPinConfiguration)configuration[p]).Resistor = PinResistor.PullUp;
Expand Down Expand Up @@ -94,9 +78,7 @@ catch
var pinChanged = new EventHandler&lt;PinStatusEventArgs&gt;((sender, args) =&gt; {
var address = args.Configuration.Name;
var module = Modules.InDomain(moduleDomain).WithAddress(address).Get();
Program.RaiseEvent(module, "Status.Level",
args.Enabled == !args.Configuration.Reversed ? "1" : "0",
address);
module.RaiseEvent("Status.Level", args.Enabled ? "1" : "0", "Update GPIO Status.Level");

});
connection.PinStatusChanged += pinChanged;
Expand All @@ -113,7 +95,7 @@ for (int p = 0; p &lt; pinMapping.Count; p++)
var pc = pinMapping[p];
var address = pc.Address;
var module = Modules.InDomain(moduleDomain).WithAddress(address).Get();
module.Parameter("Status.Level").Value = (connection[address] == !pc.Reversed ? "1" : "0");
module.Parameter("Status.Level").Value = (connection[address] ? "1" : "0");
}

// implement web serice API Control.On, Control.Off, Control.Toggle
Expand Down Expand Up @@ -153,21 +135,22 @@ When.WebServiceCallReceived(moduleDomain, ( args ) =&gt; {
});

Program.GoBackground();</ScriptSource>
<ScriptErrors />
<ScriptErrors>[]</ScriptErrors>
<Domain>HomeAutomation.HomeGenie.Automation</Domain>
<Address>100</Address>
<Name>GPIO Modules</Name>
<Description>Raspberry Pi GPIO mapped to HG modules.
Each GPIO can be configured as input (IN), output (OUT) or can be disabled (OFF).
Use IN+ to activate the internal PullUp resistor or IN- to activate the internal PullDown resistor.
Use !OUT or !IN to Reverse the pin level On = 0 and Off = 1.
GPIOs configured as IN are mapped to a Sensor module with a Status.Level field displaying current pin level (0, 1).
Use !OUT or !IN+ or !IN- to Reverse the pin level On = 0 and Off = 1.
GPIOs configured as IN are mapped to a Sensor module with a Status.Level field displaying current pin level (0, 1) or inverted in case of !IN.
GPIOs configured as OUT are mapped to a Switch module that can be controlled with on/off commands.
</Description>
<Group>Raspberry Pi</Group>
<Features />
<AutoRestartEnabled>false</AutoRestartEnabled>
<ActivationTime xsi:nil="true" />
<TriggerTime>2016-04-16T01:12:51.89715Z</TriggerTime>
<TriggerTime xsi:nil="true" />
<Type>CSharp</Type>
<IsEnabled>true</IsEnabled>
</ProgramBlock>
<IsEnabled>false</IsEnabled>
</ProgramBlock>
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Raspberry Pi GPIO mapped to HG modules.

From the program options, each GPIO can be configured as input (IN), output (OUT) or can be disabled (OFF).

Use IN+ to activate the internal PullUp resistor or IN- to activate the internal PullDown resistor.
Use `IN+` to activate the internal PullUp resistor or `IN-` to activate the internal PullDown resistor.

Use !OUT to Reverse the pin level On = 0 and Off = 1.
Use `!OUT` or `!IN+` or `!IN-` to Reverse the pin level `On = 0` and `Off = 1`.

GPIOs configured as IN are mapped to a Sensor module with a Status.Level field displaying current pin level (0, 1).
GPIOs configured as IN are mapped to a *Sensor module* with a `Status.Level` field displaying current pin level (0, 1) or inverted in case of `!IN`.

GPIOs configured as OUT are mapped to a *Switch module* that can be controlled with on/off commands.

GPIOs configured as OUT are mapped to a Switch module that can be controlled with on/off commands.

## Videos

Expand All @@ -21,3 +22,10 @@ GPIOs configured as OUT are mapped to a Switch module that can be controlled wit
<a href="https://www.youtube.com/watch?v=VEwVNfFiodQ" target="_blank">HomeGenie meets Banana Pi</a>


## Changes

### v1.1 - Fixes for !IN and Status.Level

- Fix reverted change for `!IN` commit [c95cd6e](https://github.com/genielabs/homegenie-packages/commit/c95cd6e359b7bde04cf1a49a8b878aa6d21f211d)
- Status.Level logic has been changes for `!IN` and `!OUT`, but is wrong as they only change the pin level not the logical level (i.e. `!OUT Status.Level = On` pin level` = 0`).
- Update deprecated api call from `Program.RaiseEvent()` to `module.RaiseEvent()`
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"author": "genielabs",
"version": "v1.0",
"version": "v1.1",
"title": "GPIO Modules",
"description": "Raspberry Pi GPIO mapped to HG modules",
"published": "2015-02-12T00:00:00Z",
"published": "2019-09-16T00:00:00Z",
"sourcecode": "",
"homepage": "",
"widgets": [ ],
Expand Down