spyro wrote:is it possible to post a running code, with the call of the IOWarriorSetInterruptCallback function
and the deklaration of your callback??
Here's the portion that I adapted from the IOWarrior24IRTest sample code. The "inRefCon" is used to pass a pointer to the object that receives the actual callback. This is not strictly necessary in all cases, but is very handy. For example, if the cbIOWarriorEndpoint0() function were able to do everything it needed by itself, there would be no need for the refCon value. However, this scheme works nicely here. The cbIOWarriorEndpoint0() function is just acting as a little glue to call back to a method of a "class" or "object" -- that way the callback can access member variables, call user interface elements, etc. It is also filtering out the callbacks that don't represent a changed state. That way the real callback handler (on the object) is only bothered when something changes.
This was a while ago, I'm certainly not an Objective C expert, and I ended up using a device with USB interface and PIC microcontroller for my project instead of the IOWarrior -- that allowed me to put a lot of the processing in the device rather than the application though development was certainly more tricky. There would be more proper ways to handle the pluggin in and unplugging of the USB device, etc. This was just a quick adaptation of the sample code to make it look for the IOWarrior 40 rather than 24.
Hopefully it will help you get started and see where to inject the IOWarrior related stuff amongst a fresh or existing XCode project. Probably you could create a fresh project, copy and paste much of this into it, and trim it down to just send some messages to the console (a.k.a. printf).
Erik
Code: Select all
// IOWatch.m
//
// Created by E on 8/26/05.
//
#import "IOWatch.h"
#import <WebKit/WebFrame.h>
#import <WebKit/WebView.h>
#import <AppKit/NSSound.h>
#import "IOWarriorLib.h"
UInt32 gInterruptBuf0 = 0;
UInt32 gInterruptBuf0Prior = 0;
IOWarriorHIDDeviceInterface** gWarrior = NULL;
void cbIOWarriorEndpoint0 (void *target, IOReturn result, void *refcon, void *sender, UInt32 bufSize) {
if ((result != kIOReturnSuccess) || (bufSize != 4)) return;
if ( *((UInt32*)target) == gInterruptBuf0Prior) return; // No change
gInterruptBuf0Prior = *((UInt32*)target);
[(IOWatch*)refcon cbEndpoint0:(*((UInt32*)target))];
}
void cbIOWarriorAddRemove(void *inRefCon) {
IOWatch* controller = inRefCon;
short interfaceCount, i;
gWarrior = NULL;
interfaceCount = IOWarriorCountInterfaces ();
for (i = 0; i < interfaceCount; i++) {
IOWarriorListNode* theNode;
theNode = IOWarriorInterfaceListNodeAtIndex(i);
if (kIOWarrior40Interface0 == theNode->interfaceType) {
IOWarriorSetInterruptCallback(theNode->ioWarriorHIDInterface, &gInterruptBuf0, 4, cbIOWarriorEndpoint0, controller);
UInt32 pout = 0x7F0000FF; // Pull unused outputs low to avoid "flutter"
IOWarriorWriteToInterface(theNode->ioWarriorHIDInterface, 4, &pout);
gWarrior = theNode->ioWarriorHIDInterface;
break;
}
}
}
@implementation IOWatch
- (void) awakeFromNib
{
mButtPrior = 0;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
//... other init stuff!
// Init IOWarrior stuff
IOWarriorInit();
IOWarriorSetDeviceCallback(cbIOWarriorAddRemove, self);
cbIOWarriorAddRemove(self);
}
- (void) cbEndpoint0:(UInt32)inVal
{
UInt8 buttons = (inVal >> 24) ^ 0x01; // Invert first button
UInt8 changes = buttons ^ mButtPrior;
short b;
//printf("INT: %d\n", buttons);
for (b = 0 ; b < 8 ; b++) {
if (changes >> b & 0x01) {
printf("*", b);
} else {
printf(" ");
}
if (buttons >> b & 0x01) {
printf("%d", b);
} else {
printf(".");
}
}
printf("\n");
for (b = 0 ; b < 8 ; b++) {
NSButtonCell *daCell = [buttMatrix cellWithTag:b];
if (!daCell) continue;
[daCell setHighlighted:((buttons >> b & 0x01) ? YES : NO)];
//[buttMatrix highlightCell:(buttons >> b & 0x01) atRow:0 column:(b-1)];
if (changes >> b & 0x01) {
if (buttons >> b & 0x01) {
NSSound *daSound = [NSSound soundNamed:@"Tink"];
if (daSound) [daSound play];
[daCell performClick:self];
} else {
NSSound *daSound = [NSSound soundNamed:@"Morse"];
if (daSound) [daSound play];
}
}
}
UInt32 pout = 0x7F000080 | (0x0000007F & ~buttons); // Pull unused outputs low to avoid "flutter"
IOWarriorWriteToInterface(gWarrior, 4, &pout);
[buttMatrix setHidden:NO];
[buttMatrix setNeedsDisplay:YES];
// [buttMatrix displayIfNeeded];
mButtPrior = buttons;
}
@end
...and...
Code: Select all
/* IOWatch.h */
#import <Cocoa/Cocoa.h>
@class WebView;
@interface IOWatch : NSObject
{
IBOutlet NSWindow *mainWindow;
IBOutlet NSProgressIndicator *progress;
IBOutlet NSMatrix *buttMatrix;
IBOutlet NSImageView *waitImage;
IBOutlet WebView *mainWeb;
UInt8 mButtPrior;
}
- (IBAction)doButtMatrix:(id)sender;
- (void) cbEndpoint0:(UInt32)inVal;
@end