Well, I still cannot figure it out but I found that setting output 0 to 0 at the beginning makes everything else (except the timers) work. The code below is a cleaned up version of that posted earlier. If anyone is playing with Linux and FB v3, can you test it/play with it? Thanks. I am still wondering what is going on.
Alex
PS The way to compile it is:
1) Install libusb-1.0 (you probably have to compile it but it is easy).
2) Do
Code:
gcc linfb.c -o linfb -I/usr/local/include/libusb-1.0/ -L/usr/local/lib/ -lusb-1.0 -Wl,-rpath -Wl,/usr/local/lib/ && sudo ./linfb 5 1
where linfb is the name of the program (give it your own name if you would like). If you do it as root, you do not need the last sudo.
Code:
nclude <stdlib.h>
#include <string.h>
#include <libusb.h>
#include <iso646.h>
#define EP_OUT 0x01
#define EP_IN 0x81
#define TIMER_OUT_OF_BOUNDS -2
#define IO_PORT_OUT_OF_BOUNDS -1
libusb_device **devs;
libusb_context *context;
unsigned char data_recv[64];
unsigned char data_sent[64];
int setsingleio(int ionum, int active, libusb_device_handle *handle)
{
int timer = 0;
int i, j, k;
if ((ionum < 0) || (ionum > 11)){ return IO_PORT_OUT_OF_BOUNDS; }
if ((timer < 0) || (timer > 63)){ return TIMER_OUT_OF_BOUNDS; }
for ( i=0; i < 64; i++ ){ data_sent[i]=0; }
data_sent[61] = 0xff; // set wake-up
data_sent[ionum] |= (timer<<2) | ( active ? 1 : 0 ); // set the port and the timer
for ( i=0; i < 5; i++ )
{
data_sent[ionum] ^= (1<<1); //flip the flop
//send and receive
libusb_interrupt_transfer(handle, EP_OUT, data_sent, 64, &j, 500);
libusb_interrupt_transfer(handle, EP_IN, data_recv, 64, &j, 500);
// sleep .3 sec
usleep(30000);
//part below only for debugging, no USB transfers
printf("********* SENT ************ ");
printf("********* RECEIVED ************\n");
for( j = 0; j < 8; j++ ){
for( k = 1; k <= 8; k++ ){
printf("%3i ", data_sent[ j*8 + k - 1 ]);
} printf(" ");
for( k = 1; k <= 8; k++ ){
printf("%3i ", data_recv[ j*8 + k - 1 ]);
}
printf("\n");
}
}
return 0;
}
int main(int argc, char **argv){
libusb_device_handle *handle;
libusb_device *dev;
int input, active;
int i = 0;
libusb_init(&context);
libusb_set_debug(context,3);
libusb_get_device_list(NULL,&devs);
if ( argc < 2 ){
input = 0;
active = 1;
} else {
input = atoi(argv[1]);
active = atoi(argv[2]);
}
while ( (dev = devs[i++]) != NULL )
{
struct libusb_device_descriptor desc;
libusb_get_device_descriptor(dev,&desc);
if ((desc.idVendor == 0x04d8) && (desc.idProduct == 0x000C))
{
printf("Found Fusion Brain v3\n"); break;
}
}
printf("Trying to open...\n");
if ( libusb_open(dev, &handle) )
{
printf("Error opening device\n"); return -100;
}
printf("Opened... trying to claim...\n");
if ( libusb_claim_interface(handle,0) )
{
printf("Error claiming interface 0\n"); return -100;
}
setsingleio(0, 0, handle); // set everything to 0
if (setsingleio(input, active, handle))
{
printf("Error on set\n");
}
}
Bookmarks