Skip to content

Commit

Permalink
Add Squelch and Gain to usermods rotary encoder and four line display
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudwijma committed Sep 28, 2021
1 parent d0224f2 commit b344ae1
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ typedef enum {
FLD_LINE_PALETTE,
FLD_LINE_PRESET, //WLEDSR
FLD_LINE_TIME,
FLD_LINE_SQUELCH,
FLD_LINE_GAIN,
FLD_LINE_OTHER, //WLEDSR: no Line4Type
FLD_LINE_NULL //WLEDSR: no Line4Type
} Line4Type;
Expand Down Expand Up @@ -154,6 +156,8 @@ class FourLineDisplayUsermod : public Usermod {
uint8_t knownPalette = 0;
uint8_t knownMinute = 99;
uint8_t knownHour = 99;
uint8_t knownSquelch = 99;
uint8_t knownGain = 99;

uint8_t knownClockMode = 0;

Expand Down Expand Up @@ -302,7 +306,7 @@ class FourLineDisplayUsermod : public Usermod {
// Note wakeDispay (used by rotaty) triggers its own redraw
if (millis() - lastUpdate >= (clockMode?1000:refreshRate)) {
lastUpdate = millis();
if ( ((forceAutoRedraw || !strip.isUpdating()) && !noAutoRedraw) || checkChangedType() != FLD_LINE_NULL || sleepMode && (millis() - lastRedraw > screenTimeout))
if ( ((forceAutoRedraw || !strip.isUpdating()) && !noAutoRedraw) || checkChangedType() != FLD_LINE_NULL || (sleepMode && (millis() - lastRedraw > screenTimeout)))
redraw(false);
}
}
Expand Down Expand Up @@ -370,6 +374,10 @@ class FourLineDisplayUsermod : public Usermod {
return FLD_LINE_MODE;
else if (knownPalette != strip.getSegment(0).palette)
return FLD_LINE_PALETTE;
else if (knownSquelch != soundSquelch)
return FLD_LINE_SQUELCH;
else if (knownGain != sampleGain)
return FLD_LINE_GAIN;
else if (knownClockMode != clockMode || (clockMode && (knownHour != hour(localTime) || knownMinute != minute(localTime))))
return FLD_LINE_OTHER;
else
Expand Down Expand Up @@ -446,6 +454,12 @@ class FourLineDisplayUsermod : public Usermod {
lineType = FLD_LINE_PRESET;
break;
case FLD_LINE_PRESET:
lineType = FLD_LINE_SQUELCH;
break;
case FLD_LINE_SQUELCH:
lineType = FLD_LINE_GAIN;
break;
case FLD_LINE_GAIN:
lineType = FLD_LINE_PALETTE;
break;
default:
Expand All @@ -465,7 +479,7 @@ class FourLineDisplayUsermod : public Usermod {
if (lineType == FLD_LINE_EFFECT_FFT3 && strlen_P(sliderNames[4]) == 0)
lineType = FLD_LINE_PRESET;
if (lineType == FLD_LINE_PRESET && currentPreset == -1)
lineType = FLD_LINE_PALETTE;
lineType = FLD_LINE_SQUELCH;

knownHour = 99; // force time update
} // do not update lastRedraw marker if just switching row content
Expand Down Expand Up @@ -497,6 +511,8 @@ class FourLineDisplayUsermod : public Usermod {
knownEffectFFT1 = effectFFT1; //WLEDSR
knownEffectFFT2 = effectFFT2; //WLEDSR
knownEffectFFT3 = effectFFT3; //WLEDSR
knownSquelch = soundSquelch;
knownGain = sampleGain;

knownClockMode = clockMode;

Expand Down Expand Up @@ -565,6 +581,12 @@ class FourLineDisplayUsermod : public Usermod {
case FLD_LINE_TIME:
drawGlyph(0, (clockMode?2:3)*lineHeight, 65, u8x8_font_open_iconic_embedded_1x1); // clock icon
break;
case FLD_LINE_SQUELCH:
drawGlyph(0, (clockMode?2:3)*lineHeight, 65, u8x8_font_open_iconic_embedded_1x1); // clock icon
break;
case FLD_LINE_GAIN:
drawGlyph(0, (clockMode?2:3)*lineHeight, 65, u8x8_font_open_iconic_embedded_1x1); // clock icon
break;
default:
// drawGlyph(0, (clockMode?2:3)*lineHeight, 72, u8x8_font_open_iconic_play_1x1); // icon
break;
Expand Down Expand Up @@ -610,6 +632,14 @@ class FourLineDisplayUsermod : public Usermod {
case FLD_LINE_PALETTE:
showCurrentEffectOrPalette(knownPalette, JSON_palette_names, line);
break;
case FLD_LINE_SQUELCH:
sprintf_P(lineBuffer, PSTR("Squelch %3d"), soundSquelch);
drawString(1, line*lineHeight, lineBuffer);
break;
case FLD_LINE_GAIN:
sprintf_P(lineBuffer, PSTR("Gain %3d"), sampleGain);
drawString(1, line*lineHeight, lineBuffer);
break;
case FLD_LINE_TIME:
default:
showTime(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
#define FLD_LINE_EFFECT_FFT2 0 //WLEDSR
#define FLD_LINE_EFFECT_FFT3 0 //WLEDSR
#define FLD_LINE_PALETTE 0
#define FLD_LINE_SQUELCH 0 //WLEDSR
#define FLD_LINE_GAIN 0 //WLEDSR

char sliderNames[5][LINE_BUFFER_SIZE*2] = {"FX Speed", "FX Intens.", "FX Custom1", "FX Custom2", "FX Custom3"}; //WLEDSR

#endif


// The last UI state
#define LAST_UI_STATE 7
#define LAST_UI_STATE 9 //brightness until sample gain


class RotaryEncoderUIUsermod : public Usermod {
Expand All @@ -66,7 +68,7 @@ class RotaryEncoderUIUsermod : public Usermod {
int8_t pinA = ENCODER_DT_PIN; // DT from encoder
int8_t pinB = ENCODER_CLK_PIN; // CLK from encoder
int8_t pinC = ENCODER_SW_PIN; // SW from encoder
unsigned char select_state = 0; // 0: brightness, 1: effect, 2: effect speed
unsigned char select_state = 0; // 0: brightness, 1: effect, 2: effect speed, ...
unsigned char button_state = HIGH;
unsigned char prev_button_state = HIGH;

Expand Down Expand Up @@ -225,6 +227,12 @@ class RotaryEncoderUIUsermod : public Usermod {
case 7:
changedState = changeState("Palette", FLD_LINE_PALETTE, 3);
break;
case 8:
changedState = changeState("Squelch", FLD_LINE_SQUELCH, 3);
break;
case 9:
changedState = changeState("Gain", FLD_LINE_GAIN, 3);
break;
}
}
if (changedState) {
Expand Down Expand Up @@ -267,6 +275,12 @@ class RotaryEncoderUIUsermod : public Usermod {
case 7:
changePalette(true);
break;
case 8:
changeSquelch(true);
break;
case 9:
changeGain(true);
break;
}
}
else if (Enc_B == LOW)
Expand Down Expand Up @@ -296,6 +310,12 @@ class RotaryEncoderUIUsermod : public Usermod {
case 7:
changePalette(false);
break;
case 8:
changeSquelch(false);
break;
case 9:
changeGain(false);
break;
}
}
}
Expand Down Expand Up @@ -483,6 +503,38 @@ class RotaryEncoderUIUsermod : public Usermod {
lampUdated();
}

void changeSquelch(bool increase) {
#ifdef USERMOD_FOUR_LINE_DISPLAY
if (display && display->wakeDisplay()) {
// Throw away wake up input
return;
}
#endif
if (increase) {
soundSquelch = (soundSquelch + 1 <= 255) ? (soundSquelch + 1) : 255;
}
else {
soundSquelch = (soundSquelch - 1 >= 0) ? (soundSquelch - 1) : 0;
}
lampUdated();
}

void changeGain(bool increase) {
#ifdef USERMOD_FOUR_LINE_DISPLAY
if (display && display->wakeDisplay()) {
// Throw away wake up input
return;
}
#endif
if (increase) {
sampleGain = (sampleGain + 1 <= 255) ? (sampleGain + 1) : 255;
}
else {
sampleGain = (sampleGain - 1 >= 0) ? (sampleGain - 1) : 0;
}
lampUdated();
}

/*
* addToJsonInfo() can be used to add custom entries to the /json/info part of the JSON API.
* Creating an "u" object allows you to add custom key/value pairs to the Info section of the WLED web UI.
Expand Down

0 comments on commit b344ae1

Please sign in to comment.