more G-Labs products

Author Topic: PiFace Digital Driver  (Read 5711 times)

January 05, 2015, 03:09:11 AM
Read 5711 times

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
Hello

I started looking into obtaining or building a driver for Piface; below is my train of thought and am hoping somebody point me in the right direction or correct me if I have something wrong.


I looked at several posts about Piface and MCP23017 but they reference i2c and unless I am completely off track PiFace uses SPI; I have used Kingsland.PiFaceSharp successfully and it uses SPI.

HomeGenie uses raspberry sharp which supports i2c and spi but only has an extender for MCP23017 using I2C. So I wrote an equivalent to the Mcp23017I2cConnection class but using SPI connection i.e. Mcp23017SpiConnection.

How do I get my class into HomeGenie? I could rebuild raspberry sharp and overwrite the copy on my PI. Would I then have to rebuild HomeGenie or will it find the new class dynamically?

Assuming I get the class available to programs under HomeGenie. It should be a simple change to the existing MCP23017 program to switch to my SPI connection (which has all the same function calls as the I2C one). How do you develop and test those add in programs, they don't seem to be complete classes that I can paste into Visual Studio?

Thanks in advance
Nick

January 05, 2015, 03:19:55 AM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
If you already wrote the class for RaspberrySharp, you can attach it here so I will include it in the RaspberrySharp fork used for HG.
I could also push to the master RaspberrySharp repo. If you're familiar with github, suggest create your own fork as push it to the master repo.

But if you didn't write this yet, I suggest trying to implement it as a simple csharp automation program inside the HG program editor.
To see an example app using a SPI connection you can import and look the source code of the EdenV2_Module_1_1.hgx that is available for download here:

https://sourceforge.net/projects/homegenie/files/testing/

For importing it into HG use the "Import Program" option available from the Actions menu when inside any automation section group.

Cheers,
g.


January 05, 2015, 03:31:44 AM
Reply #2

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
To answer to your last two question as well:

- if you update raspberrysharp libraries, implemented classes will be available to automation programs as well, but you will have to reference them with complete namespace as long these are not referenced here:
https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Automation/CSharpAppFactory.cs#L50

- hg csharp programs are not classes and you can't add classes there, they are most likely code snippet (see the hgx example that I pointed in the previous post), you can't use Visual Studio to develop them, but HG program editor.

g.
« Last Edit: January 05, 2015, 03:35:10 AM by Gene »

January 08, 2015, 03:37:00 AM
Reply #3

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
Thanks.

I will test the class with a standalone program then upload it here.

Nick

January 19, 2015, 11:50:14 PM
Reply #4

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
Attached is a solution with a PiFace Digital SPI driver, and a standalone demo app.
I had a go at building a new version of HomeGenie for the Pi with the PiFace dll but couldn't get the packager to work; vs2012 says "Unsupported...". I tried  a few things and ended up having to restore my Pi  :(

If you could add the dll or point me in the right direction to build a new Pi release that would be great.

Nick

February 11, 2015, 12:48:56 AM
Reply #5

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
Trying to figure out how to build the Linux version of HG. I can build the windows version with VS; do I need to build the Linux version on Linux?

February 11, 2015, 06:25:02 PM
Reply #6

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
When I have used the source to build HG, I was just modifying segments in one package or another.  As a result, I simply copied the different compiled file over to my Raspi installation path.  That approach worked fine.  I don't know how to create a distributable installation.

February 19, 2015, 08:40:13 PM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi NickP,

please fork the HG RaspberrySharp-IO repository:

https://github.com/genielabs/raspberry-sharp-io

add the code there and make a pull request. That way it will be included in HG.

Cheers,
g.

February 28, 2015, 09:54:28 PM
Reply #8

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
Pull request created :)

March 01, 2015, 04:40:19 PM
Reply #9

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
PiFace Digital support is now included in HG r482.

http://www.homegenie.it/download.php

It could be useful to have an automation program using it (eg. virtual modules).

Cheers,
g.

March 12, 2015, 02:54:06 AM
Reply #10

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
I'm working on one  :)

March 14, 2015, 06:08:00 PM
Reply #11

enterprised

  • ****
  • Information
  • Sr. Member
  • Posts: 101
  • Things are only impossible until they are not
NickP,
Can you give me some pointers on how to get my Piface Digital to work with HG.

4a 75 73 74 20 61 20 70 65 72 73 6f 6e 20 68 61 76 69 6e 67 20 66 75 6e 20 77 69 74 68 20 68 6f 6d 65 20 61 75 74 6f 6d 61 74 69 6f 6e
enterprised == guytpetj

March 16, 2015, 03:57:44 AM
Reply #12

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
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

Code: [Select]
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();
}


March 17, 2015, 03:20:00 AM
Reply #13

NickP

  • *
  • Information
  • Newbie
  • Posts: 24
HGX - adds modules for the piFace inputs and outputs.
Note that you must enable native SPI as per the PiFace documentation. Input pin are considered on when grounded / buttons pushed.

March 17, 2015, 04:11:43 AM
Reply #14

enterprised

  • ****
  • Information
  • Sr. Member
  • Posts: 101
  • Things are only impossible until they are not
Thanks mate, works like a charm on my PiFace Digital 2
4a 75 73 74 20 61 20 70 65 72 73 6f 6e 20 68 61 76 69 6e 67 20 66 75 6e 20 77 69 74 68 20 68 6f 6d 65 20 61 75 74 6f 6d 61 74 69 6f 6e
enterprised == guytpetj