The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
I thought it would be nice to use this as input device for a specific project so I got one and wrote a library.
Code sample:
WearableKeypad Keypad = new WearableKeypad(Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D6);
while (true)
{
switch (Keypad.Read())
{
case 1: Debug.Print("Up"); break;
case 2: Debug.Print("Right"); break;
case 3: Debug.Print("Down"); break;
case 4: Debug.Print("Left"); break;
case 5: Debug.Print("Logo"); break;
}
Thread.Sleep(100);
}
Or in VB.NET:
Dim Keypad As WearableKeypad = New WearableKeypad(Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D6)
Do
Select Case Keypad.Read()
Case 1 : Debug.Print("Up")
Case 2 : Debug.Print("Right")
Case 3 : Debug.Print("Down")
Case 4 : Debug.Print("Left")
Case 5 : Debug.Print("Logo")
End Select
Thread.Sleep(100)
Loop
I'm also considering to make the Read() return an enumerated value
I wouldn't do it, because the enum is not extensible. E.g. if tomorrow you'll create the 8-ways joystick (which may be compatible), the user must change his/her code.
Cheers
Biggest fault of Netduino? It runs by electricity.
I wouldn't do it, because the enum is not extensible. E.g. if tomorrow you'll create the 8-ways joystick (which may be compatible), the user must change his/her code.
To be honest, I hope regular joysticks use better logics. Reading a value of this keypad is not according to an existing standard I had the feeling.
Great!
A good reason to wear the driver as it was a better joystick!
I mean, look at the datasheet. It doesn't use a common method to read the device as far as I know. I'm not speaking about the software but the hardware
If I would have designed the hardware, and wanted to read 5 buttons over 3 pins, I would use a binary mode (0 to 7 = 000 to 111). That way, a reading could be done much faster.
I mean, look at the datasheet. It doesn't use a common method to read the device as far as I know. I'm not speaking about the software but the hardware
If I would have designed the hardware, and wanted to read 5 buttons over 3 pins, I would use a binary mode (0 to 7 = 000 to 111). That way, a reading could be done much faster.
Okay, but that's about the hardware, and should keep a question between this specific joystick and the related driver.
Now consider an user who's writing a game, requiring a joystick.
Other users may purchase several kind of joysticks: joypad, a set of raw buttons, analog, even a mouse. The game should require a generic IGameAdapter interface, then *any* of the proprietary driver should implement that interface.
Along this way, you may choose any game adapter you want without touching the base game. BTW, it would a nonsense task, indeed.
Cheers
Biggest fault of Netduino? It runs by electricity.
Along this way, you may choose any game adapter you want without touching the base game. BTW, it would a nonsense task, indeed.
Cheers
Ah you mean a joystick interface. I read you
Too bad this acts more as a keyboard then as a joystick; with a joystick for example it's possible to press both up and left at the same time. This uses only a single button at the same time.
But I'll stay with the numbers, it's more generic compared to my other keypad-class. Perhaps I should interface it as a keypad, which could really use your AutoRepeatInputPort code
I was also going to suggest using an Enum when I first saw this post, but originally decided against commenting. But since you mention it :-)
[Flags]
public enum Buttons
{
None = 0,
Up = 1,
Right = 2,
Down = 4,
Left = 8,
Select = 16
}
This would provide support for a 8 key joystick or pressing multiple keys ... or simulating 8 key joystick by pressing multiple keys. This may lack some extensibility, but given the benefit I would be inclined to be ok with that. You could make it more extensible (using generics perhaps similar to EventArgs<T>) but I think the overhead is unnecessary at this time. Alternatively, you can just provide constants for WearableKeypad which has the added benefit of readability with a smaller increase than the enum.