new mixed mode

This commit is contained in:
CrazyRedMachine
2020-08-14 13:32:56 +02:00
parent bc47b562ff
commit a94218da01
6 changed files with 45 additions and 22 deletions
+8 -3
View File
@@ -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);
}
}
+9 -2
View File
@@ -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;
+16 -9
View File
@@ -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