GHI 400 Microframework example with InterruptPort

Hi all,

I’m trying my brand new GHI 400… I’m using standard MFWindowApplication for NET MF, pointed not to Emulator but USB.

I changed Cpu.Pin definitions from Emulator standard to GHI ones in GPIOButtonInputProvider, but no luck, it’s like this:

Cpu.Pin pinLeft = GHI.Pins.G400.PD7;
Cpu.Pin pinRight = GHI.Pins.G400.PD9;
Cpu.Pin pinUp = GHI.Pins.G400.PA24;
Cpu.Pin pinSelect = GHI.Pins.G400.PD8;
Cpu.Pin pinDown = GHI.Pins.G400.PA4;

Interrupts doesn’t raise. Nothing appear in the console, it works only with emulator not the ghi400.

Do you know probably what I do wrong?

Thank you.

Try something like this. You need Interrupt handlers.



//This is for a FEZ Raptor (G400) so you will need to change to your pin numbers and Port names...

private static InterruptPort LDR0;
private static InterruptPort LDR1;

private static void setupButtons()
{
	LDR0 = new InterruptPort((Cpu.Pin)24, true,
			Port.ResistorMode.PullUp,
			Port.InterruptMode.InterruptEdgeLow);

	//Interrupt handler
	LDR0.OnInterrupt += new NativeEventHandler(LDR0_OnInterrupt);

	LDR1 = new InterruptPort((Cpu.Pin)4, true,
			Port.ResistorMode.PullUp,
			Port.InterruptMode.InterruptEdgeLow);

	//Interrupt handler
	LDR1.OnInterrupt += new NativeEventHandler(LDR1_OnInterrupt);

	//Exception when using Port.ResistorMode.PullDown
	Socket9Button = new InterruptPort((Cpu.Pin)50, true,
		Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);

	//Interrupt handler
	Socket9Button.OnInterrupt += new NativeEventHandler(Socket9Button_OnInterrupt);
}
//

static void Socket9Button_OnInterrupt(uint port, uint state, DateTime time)
{
	if (myBitmap != null)
	{
		myBitmap.Dispose();
	}
	Debug.Print("Socket 9 Button Pressed");
}
//

private static void LDR0_OnInterrupt(uint port, uint state, DateTime time)
{
	Debug.Print("LDR0 Button Pressed");
}
//
private static void LDR1_OnInterrupt(uint port, uint state, DateTime time)
{
	Debug.Print("LDR1 Button Pressed");
}
//


Hope it is of some help to you.

I think that you mean a Console Application… To build it for a GHI400 do like this:


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using GHI.IO;
using GHI.Pins;


namespace MFGHI400
{
    public class Program
    {
        public static void Main()
        {
            Debug.Print("Program Started");
            InterruptPort buttonUp = new InterruptPort(G400.PA24, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            buttonUp.OnInterrupt += ButtonUp_OnInterrupt;
            InterruptPort buttonRight = new InterruptPort(G400.PD9, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            buttonRight.OnInterrupt += ButtonRight_OnInterrupt;
            InterruptPort buttonDown = new InterruptPort(G400.PA4, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            buttonDown.OnInterrupt += ButtonDown_OnInterrupt;
            InterruptPort buttonLeft = new InterruptPort(G400.PD7, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            buttonLeft.OnInterrupt += ButtonLeft_OnInterrupt;
            InterruptPort buttonSelect = new InterruptPort(G400.PD8, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            buttonSelect.OnInterrupt += ButtonSelect_OnInterrupt;

            

            Thread.Sleep(Timeout.Infinite);
        }

        static void ButtonUp_OnInterrupt(uint pin, uint state, DateTime time)
        {
            Debug.Print("Pressed Up " + pin.ToString());
        }

        static void ButtonRight_OnInterrupt(uint pin, uint state, DateTime time)
        {
            Debug.Print("Pressed Right " + pin.ToString());
        }

        static void ButtonDown_OnInterrupt(uint pin, uint state, DateTime time)
        {
            Debug.Print("Pressed Down " + pin.ToString());
        }

        static void ButtonLeft_OnInterrupt(uint pin, uint state, DateTime time)
        {
            Debug.Print("Pressed Left " + pin.ToString());
        }

        static void ButtonSelect_OnInterrupt(uint pin,uint state,DateTime time)
        {
            Debug.Print("Pressed Select " + pin.ToString());
        }
    }
}


What I need instead is make work the ApplicationWindow application, the standard NET MF example that comes with MF SDK… It’s the application that is coded by the sdk when you create a new NET WindowApplication in Visual Studio.

OK, so I’ll ask. Why do you need that application? Why aren’t you just building your own console app? What are you actually trying to achieve?

@ gremlinc5 - In GPIOButtonProvider, comment out the code startinG on line 60 and see if that helps:


if ((pinLeft = hwProvider.GetButtonPins(Button.VK_LEFT)) ==
	Cpu.Pin.GPIO_NONE)
	pinLeft = Cpu.Pin.GPIO_Pin0;
else {
	pinRight = hwProvider.GetButtonPins(Button.VK_RIGHT);
	pinUp = hwProvider.GetButtonPins(Button.VK_UP);
	pinSelect = hwProvider.GetButtonPins(Button.VK_SELECT);
	pinDown = hwProvider.GetButtonPins(Button.VK_DOWN);
}

@ John - That’s it, it works thank you. So the code was over writing my Cpu.Pin settings… Copy that. :wink:

@ Brett - I want to understand which way is better for my app :wink: I will try building console and window app.