#include "mbed.h"
#include "USBHost.h"
#include "Utils.h"
DigitalOut myled1(LED1);
DigitalOut myled4(LED4);
u8 ecobox_buf[8];
#define REQUEST_TYPE_VENDOR 0x40
#define ECOBOX_RANGE_3
#define ECOBOX_RANGE_6
#define ECOBOX_RANGE_9
#define ECOBOX_RANGE_12
void ecobox_range(int device, int value)
{
USBControlTransfer(device, HOST_TO_DEVICE|REQUEST_TYPE_VENDOR|RECIPIENT_ENDPOINT, 0x10, value, 0, 0, 0);
}
void ecobox_Callback(int device, int endpoint, int status, u8* data, int len, void* userData)
{
myled4 = data[4] & 1;
myled1 = !myled1;
USBInterruptTransfer(device, 0x81, ecobox_buf, sizeof(ecobox_buf), ecobox_Callback, userData);
}
int OnEcoboxInsert(int device)
{
printf("ECOBOX-NET inserted of %d\n", device);
ecobox_range(device, ECOBOX_RANGE_60CM);
USBInterruptTransfer(device, 0x81, ecobox_buf, sizeof(ecobox_buf), ecobox_Callback, (void*)0);
return 0;
}