That’s the original post, which I couldn’t post a couple of days back when the forum was down a lot:
As I always like the idea of patch cables, I just did some tests with it.
Basically you hook the sockets up to GND and a DIN pin. You’ll need cross-over cables for this though - when you plug in one side of a cable nothing happens. When you plug in the other side, you’re closing 2 switches rather rapidly, invoking 2 DIN_NotifyToggle. Same for unplugging a cable - you get 2 DIN_NotifyToggle.
Set up some vars:
unsigned char tick, count, one;
“tick” is the internal timer that counts the “ticks” between two DIN events. “count” counts the number of events in a pair, so it’s either 0 (no event yet) or 1 (one connection has been closed). “one” just stores the pin of the first event so we know which pair has been connected. What I did is I set up the timer to something rather slow:
MIOS_TIMER_Init(0x03, 65535);
The timer function increments a small helper variable:
void Timer(void) __wparam
{
tick++;
}[/code]
Finally the DIN event handler:
[code]void DIN\_NotifyToggle(unsigned char pin, unsigned char pin\_value) \_\_wparam
{
if (pin\_value == 0) {
// something was put in
if (count == 0) {
// and it was the first one
tick = 0;
count = 1;
one = pin;
} else
if (tick \< 10) {
// good one
MIOS\_LCD\_Clear();
MIOS\_LCD\_CursorSet(0x00);
MIOS\_LCD\_PrintCString("+ ");
MIOS\_LCD\_PrintBCD2(one);
MIOS\_LCD\_PrintCString(" ");
MIOS\_LCD\_PrintBCD2(pin);
// reset
count = 0;
}
} else {
// something was removed
if (count == 0) {
// and it was the first one
tick = 0;
count = 1;
one = pin;
} else
if (tick \< 10) {
// good one
MIOS\_LCD\_Clear();
MIOS\_LCD\_CursorSet(0x00);
MIOS\_LCD\_PrintCString("- ");
MIOS\_LCD\_PrintBCD2(one);
MIOS\_LCD\_PrintCString(" ");
MIOS\_LCD\_PrintBCD2(pin);
// reset
count = 0;
}
}
}
All it really does is:
* check if the button is pressed or depressed (basically does the same thing for both, so I’ll only go into detail for the “pressed” part)
* check if “count” is 0 which means this is the first event, if so
* increment count, memorize the pin number and reset the tick
* if count == 1 then it’s the second button IF the tick (which is incremented by the timer) is < 10 (basically some nasty debouncing to allow regular buttons to be used along with the patch field)
* second button means: we’ve got a connection. Display that on the LCD, reset the count
* done
Working really good for me. And it’s fun. Only thing I’m wondering now is - how could I use this ;D
DrBunsen: Does that answer you question?