diff --git a/popnWithKeypad/POPNHID.cpp b/popnController/POPNHID.cpp similarity index 99% rename from popnWithKeypad/POPNHID.cpp rename to popnController/POPNHID.cpp index e8c7541..5b855fc 100644 --- a/popnWithKeypad/POPNHID.cpp +++ b/popnController/POPNHID.cpp @@ -252,7 +252,7 @@ static const byte PROGMEM _hidReportPOPN[] = { HIDDescriptor hidInterface = { D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), D_HIDREPORT(sizeof(_hidReportPOPN)), - D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 16) + D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) // this last parameter is the bInterval (requested polling rate) }; return USB_SendControl(0, &hidInterface, sizeof(hidInterface)); } diff --git a/popnWithKeypad/POPNHID.h b/popnController/POPNHID.h similarity index 100% rename from popnWithKeypad/POPNHID.h rename to popnController/POPNHID.h diff --git a/popnWithKeypad/popnWithKeypad.ino b/popnController/popnController.ino similarity index 98% rename from popnWithKeypad/popnWithKeypad.ino rename to popnController/popnController.ino index bc4e4e0..bf1a1cd 100644 --- a/popnWithKeypad/popnWithKeypad.ino +++ b/popnController/popnController.ino @@ -7,7 +7,7 @@ #include #endif #include "POPNHID.h" -/* 125µs delay is 1 frame on highspeed USB spec */ +/* 1 frame (as declared in POPNHID.cpp) on highspeed USB spec is 125µs */ #define REPORT_DELAY 125 #define MILLIDEBOUNCE 15 POPNHID_ POPNHID; @@ -118,7 +118,7 @@ void loop() { } /* USB DATA */ - if ( ( (micros() - lastReport) >= REPORT_DELAY) )//&& (buttonsState != prevButtonsState) ) + if ( ( (micros() - lastReport) >= REPORT_DELAY) ) { POPNHID.sendState(buttonsState); lastReport = micros(); @@ -196,6 +196,40 @@ void loop() { } } +/* Light up button lights according to bitfield */ +void but_lights(uint16_t lightDesc) { + for (int i = 0; i < 9; i++) { + if ((lightDesc >> i) & 1) { + digitalWrite(LightPins[i], HIGH); + } else { + digitalWrite(LightPins[i], LOW); + } + } +} + +/* Light up pillars and top neons according to bitfield */ +void neon_lights(uint16_t lightDesc) { + for (int i = 0; i < 9; i++) { + if ((lightDesc >> i) & 1) { + digitalWrite(LightPins[i + 9], HIGH); + } else { + digitalWrite(LightPins[i + 9], LOW); + } + } +} + +/* Display animation on the cab according to a bitfield array */ +void animate(uint16_t* tab, uint8_t n, int mswait) { + for (int i = 0; i < n; i++) { + but_lights(tab[i]); +#if defined(ARDUINO_ARCH_SAM) + neon_lights(tab[i]); +#endif + delay(mswait); + } +} + +/* ARDUINO DUE ONLY FUNCTIONS */ #if defined(ARDUINO_ARCH_SAM) /* Manage pillars and top neons in reactive mode */ @@ -286,37 +320,5 @@ if (pillar_lit) } #endif -/* Light up button lights according to bitfield */ -void but_lights(uint16_t lightDesc) { - for (int i = 0; i < 9; i++) { - if ((lightDesc >> i) & 1) { - digitalWrite(LightPins[i], HIGH); - } else { - digitalWrite(LightPins[i], LOW); - } - } -} - -/* Light up pillars and top neons according to bitfield */ -void neon_lights(uint16_t lightDesc) { - for (int i = 0; i < 9; i++) { - if ((lightDesc >> i) & 1) { - digitalWrite(LightPins[i + 9], HIGH); - } else { - digitalWrite(LightPins[i + 9], LOW); - } - } -} - -/* Display animation on the cab according to a bitfield array */ -void animate(uint16_t* tab, uint8_t n, int mswait) { - for (int i = 0; i < n; i++) { - but_lights(tab[i]); -#if defined(ARDUINO_ARCH_SAM) - neon_lights(tab[i]); -#endif - delay(mswait); - } -}