new mixed mode
This commit is contained in:
@@ -286,6 +286,7 @@ static const byte PROGMEM _hidReportPOPN[] = {
|
||||
if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) {
|
||||
if (request == HID_SET_REPORT) {
|
||||
if(setup.wValueH == HID_REPORT_TYPE_OUTPUT && setup.wLength == 5){
|
||||
lastHidUpdate = millis();
|
||||
USB_RecvControl(led_data, 5);
|
||||
return true;
|
||||
}
|
||||
@@ -309,9 +310,13 @@ static const byte PROGMEM _hidReportPOPN[] = {
|
||||
uint8_t POPNHID_::getLightMode(){
|
||||
return lightMode;
|
||||
}
|
||||
|
||||
|
||||
unsigned long POPNHID_::getLastHidUpdate(){
|
||||
return lastHidUpdate;
|
||||
}
|
||||
|
||||
void POPNHID_::setLightMode(uint8_t mode){
|
||||
if ((mode > 3) || (mode < 0)) {
|
||||
if ((mode > 4) || (mode < 0)) {
|
||||
lightMode = 2;
|
||||
return;
|
||||
}
|
||||
@@ -355,4 +360,4 @@ static const byte PROGMEM _hidReportPOPN[] = {
|
||||
data[1] = (uint8_t) (buttonsState & 0xFF);
|
||||
data[2] = (uint8_t) (buttonsState >> 8) & 0xFF;
|
||||
return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,16 @@ class POPNHID_ : public PluggableUSBModule {
|
||||
uint8_t getLightMode();
|
||||
void setLightMode(uint8_t mode);
|
||||
|
||||
/**
|
||||
* getter for lastHidUpdate protected field.
|
||||
*/
|
||||
unsigned long getLastHidUpdate();
|
||||
|
||||
protected:
|
||||
/* current lightMode (0 = reactive, 1 = HID only, 2 = mixed (HID+button presses), 3 = mixed invert) */
|
||||
/* current lightMode (0 = reactive, 1 = HID only, 2 = mixed (HID+reactive auto-switch), 3 = combined (HID+button presses), 4 = combined invert) */
|
||||
uint8_t lightMode = 2;
|
||||
/* timestamp of last received HID report for lightMode 3 */
|
||||
unsigned long lastHidUpdate = 0;
|
||||
/* byte array to receive HID reports from the PC */
|
||||
byte led_data[5];
|
||||
|
||||
@@ -69,4 +76,4 @@ class POPNHID_ : public PluggableUSBModule {
|
||||
uint8_t getShortName(char *name);
|
||||
};
|
||||
|
||||
extern POPNHID_ POPNHID;
|
||||
extern POPNHID_ POPNHID;
|
||||
|
||||
@@ -129,7 +129,15 @@ void loop() {
|
||||
}
|
||||
|
||||
/* LAMPS */
|
||||
switch (POPNHID.getLightMode())
|
||||
uint8_t mode = POPNHID.getLightMode();
|
||||
/* mixed mode will behave sometimes like HID, sometimes like reactive */
|
||||
if (mode == 2){
|
||||
if ((millis()-POPNHID.getLastHidUpdate()) > 3000)
|
||||
mode = 0;
|
||||
else
|
||||
mode = 1;
|
||||
}
|
||||
switch (mode)
|
||||
{
|
||||
/* Reactive mode, locally determined lamp data */
|
||||
case 0:
|
||||
@@ -142,14 +150,16 @@ void loop() {
|
||||
case 1:
|
||||
POPNHID.updateLeds(0, false);
|
||||
break;
|
||||
/* Mixed inverse mode, received HID data and button state are combined then inverted */
|
||||
case 3:
|
||||
/* Combined inverse mode, received HID data and button state are combined then inverted */
|
||||
case 4:
|
||||
POPNHID.updateLeds(buttonsState & 0x1ff, true);
|
||||
break;
|
||||
/* Mixed mode, received HID data and button state are combined */
|
||||
default:
|
||||
/* Combined mode, received HID data and button state are combined */
|
||||
case 3:
|
||||
POPNHID.updateLeds(buttonsState & 0x1ff, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_SAM)
|
||||
@@ -184,7 +194,7 @@ void loop() {
|
||||
if ( (buttonsState & 2) && (modeChanged == false)) {
|
||||
modeChanged = true;
|
||||
uint8_t mode = POPNHID.getLightMode()+1;
|
||||
if (mode > 3) mode = 0;
|
||||
if (mode > 4) mode = 0;
|
||||
POPNHID.setLightMode(mode);
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
EEPROM.put(0, mode);
|
||||
@@ -319,6 +329,3 @@ if (pillar_lit)
|
||||
neon_lights(neons);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user