Skip to content

Commit

Permalink
multiple registrations should now be OK
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Mar 4, 2018
1 parent 70b89f0 commit 20dc653
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
20 changes: 13 additions & 7 deletions USBComposite.cpp
Expand Up @@ -127,14 +127,20 @@ void USBCompositeDevice::clear() {
numParts = 0;
}

bool USBCompositeDevice::add(USBCompositePart* part, USBPartInitializer _init, USBPartStopper _stop, void* _plugin) {
if (numParts >= USB_COMPOSITE_MAX_PARTS)
bool USBCompositeDevice::add(USBCompositePart* part, void* _plugin, USBPartInitializer _init, USBPartStopper _stop) {
unsigned i;

for (i = 0; i<numParts; i++)
if (plugin[numParts] == _plugin && parts[i] == part)
break;
if (i >= USB_COMPOSITE_MAX_PARTS)
return false;
parts[numParts] = part;
init[numParts] = _init;
stop[numParts] = _stop;
plugin[numParts] = _plugin;
numParts++;
parts[i] = part;
init[i] = _init;
stop[i] = _stop;
plugin[i] = _plugin;
if (i >= numParts)
numParts++;
return true;
}

Expand Down
4 changes: 1 addition & 3 deletions USBComposite.h
Expand Up @@ -21,8 +21,6 @@ class USBCompositeDevice;

#define DEFAULT_SERIAL_STRING "00000000000000000001"

//typedef std::function<bool()> USBPartInitializer;
//typedef std::function<void()> USBPartStopper;
typedef bool(*USBPartInitializer)(void*);
typedef void(*USBPartStopper)(void*);

Expand Down Expand Up @@ -50,7 +48,7 @@ class USBCompositeDevice {
bool begin(void);
void end(void);
void clear();
bool add(USBCompositePart* part, USBPartInitializer init = NULL, USBPartStopper stop = NULL, void* plugin = NULL);
bool add(USBCompositePart* part, void* plugin, USBPartInitializer init = NULL, USBPartStopper stop = NULL);
};

extern USBCompositeDevice USBComposite;
Expand Down
2 changes: 1 addition & 1 deletion USBCompositeSerial.cpp
Expand Up @@ -105,7 +105,7 @@ int USBCompositeSerial::peek(void)
}

bool USBCompositeSerial::registerComponent() {
return USBComposite.add(&usbSerialPart, (USBPartInitializer)&USBCompositeSerial::init);
return USBComposite.add(&usbSerialPart, this, (USBPartInitializer)&USBCompositeSerial::init);
}

void USBCompositeSerial::flush(void)
Expand Down
2 changes: 1 addition & 1 deletion USBHID.cpp
Expand Up @@ -34,7 +34,7 @@
*/

bool USBHIDDevice::registerComponent() {
return USBComposite.add(&usbHIDPart);
return USBComposite.add(&usbHIDPart, this);
}

void USBHIDDevice::setReportDescriptor(const uint8_t* report_descriptor, uint16_t report_descriptor_length) {
Expand Down
2 changes: 1 addition & 1 deletion USBMIDI.cpp
Expand Up @@ -65,7 +65,7 @@ void USBMidi::setChannel(unsigned int channel) {
}*/

bool USBMidi::registerComponent() {
return USBComposite.add(&usbMIDIPart); // (USBPartInitializer)&USBMidi::init, NULL, this);
return USBComposite.add(&usbMIDIPart, this);
}

void USBMidi::begin(unsigned channel) {
Expand Down
2 changes: 1 addition & 1 deletion USBMassStorage.cpp
Expand Up @@ -23,7 +23,7 @@ void USBMassStorageDevice::loop() {
}

bool USBMassStorageDevice::registerComponent() {
return USBComposite.add(&usbMassPart);
return USBComposite.add(&usbMassPart, this);
}

void USBMassStorageDevice::setDrive(uint32 driveNumber, uint32 byteSize, MassStorageReader reader,
Expand Down
2 changes: 1 addition & 1 deletion USBXBox360.cpp
Expand Up @@ -52,7 +52,7 @@ bool USBXBox360::init(void* ignore) {
}

bool USBXBox360::registerComponent() {
return USBComposite.add(&usbX360Part, init);
return USBComposite.add(&usbX360Part, this, init);
}

void USBXBox360::begin(void){
Expand Down

0 comments on commit 20dc653

Please sign in to comment.