Sending structs as reports
Posted: Sat Jan 24, 2009 6:22 am
Hello guys, first thanks for this excellent piece of code!
I'm trying to send a struct as a report. You can see the main part of the code right now. I can send straight bytes no problem. I was able to send two bytes from a buffer and reconstruct it in a struct as a uint16_t on the host side. How ever, when I pass along the pointer for the struct, the data on the host site is garbage (never changes). The struct is malloc'ed so it's definitely available at all time. I really don't get this 0.o
Thanks
I'm trying to send a struct as a report. You can see the main part of the code right now. I can send straight bytes no problem. I was able to send two bytes from a buffer and reconstruct it in a struct as a uint16_t on the host side. How ever, when I pass along the pointer for the struct, the data on the host site is garbage (never changes). The struct is malloc'ed so it's definitely available at all time. I really don't get this 0.o
Code: Select all
typedef struct t_configHolder {
uint8_t tempWanted;
uint8_t selectMode;
uint8_t lowHeatDifference;
uint8_t saverDifference;
uint8_t saverEnabled;
uint8_t lightDarkThreshold;
int8_t saverThreshold;
}configHolder;
usbMsgLen_t usbFunctionSetup(uint8_t data[8])
{
usbRequest_t *rq = (usbRequest_t *)((void *)data);
/* HID class request */
if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) {
if (rq->bRequest == USBRQ_HID_GET_REPORT) {
/* wValue: ReportType (highbyte), ReportID (lowbyte) */
switch (rq->wValue.bytes[0]) {
case USB_REPORTID_CALENDAR:
bytesRemaining = EEPROM_CALENDAR_SIZE;
currentAddress = (uint16_t) &EECalendar;
return USB_NO_MSG; /* use usbFunctionRead() to obtain data */
break;
case USB_REPORTID_STATUS:
usbMsgPtr = (uint8_t*)&systemStatus;
return sizeof(t_statusHolder);
break;
case USB_REPORTID_CONFIG:
usbMsgPtr = (uint8_t *)&systemConfig;
return sizeof(t_configHolder);
break;
}
}
} else {
/* ignore vendor type requests, we don't use any */
}
return 0;
}
Thanks