implement LED strip brightness and blinker

This commit is contained in:
Peter Poetzi
2021-09-30 12:38:21 +02:00
parent 4f185fcd11
commit 3c38348cf2
13 changed files with 80 additions and 1 deletions

View File

@ -88,4 +88,5 @@ set(BOBBYCAR_BUILDFLAGS
-DPINS_LEDSTRIP=33
-DLEDSTRIP_LENGTH=121
-DHEAP_LRGST_CRASH_TEXT_FIX
-DLEDSTRIP_WRONG_DIRECTION
)

View File

@ -87,4 +87,5 @@ set(BOBBYCAR_BUILDFLAGS
-DFEATURE_LEDSTRIP
-DPINS_LEDSTRIP=26
-DLEDSTRIP_LENGTH=200
# -DLEDSTRIP_WRONG_DIRECTION
)

View File

@ -88,4 +88,5 @@ set(BOBBYCAR_BUILDFLAGS
-DPINS_LEDSTRIP=33
-DLEDSTRIP_LENGTH=121
-DLEDSTRIP_DEFAULT_BRIGHTNESS=100
# -DLEDSTRIP_WRONG_DIRECTION
)

View File

@ -86,4 +86,5 @@ set(BOBBYCAR_BUILDFLAGS
-DFEATURE_WIRELESS_CONFIG
# -DFEATURE_LEDSTRIP
# -DPINS_LEDSTRIP=26
# -DLEDSTRIP_WRONG_DIRECTION
)

View File

@ -91,4 +91,5 @@ set(BOBBYCAR_BUILDFLAGS
-DFEATURE_LEDSTRIP
-DPINS_LEDSTRIP=33
-DLEDSTRIP_LENGTH=288
# -DLEDSTRIP_WRONG_DIRECTION
)

View File

@ -157,6 +157,7 @@ struct LedsCountAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &ge
struct CenterOffsetAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.ledstrip.centerOffset; } };
struct SmallOffsetAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.ledstrip.smallOffset; } };
struct BigOffsetAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.ledstrip.bigOffset; } };
struct DeziampereAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.ledstrip.deziampere; } };
#endif
struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } };

View File

@ -9,6 +9,10 @@
// local includes
#include "settingsutils.h"
#ifdef FEATURE_LEDSTRIP
#include "ledstrip.h"
#endif
namespace {
int rotated{};
@ -133,5 +137,56 @@ public:
switchProfile(index);
}
static void blinkLeftButton(bool pressed){
if(!pressed)return;
#ifdef FEATURE_LEDSTRIP
#ifdef LEDSTRIP_WRONG_DIRECTION
const auto target_blinkAnimation = 1;
#else
const auto target_blinkAnimation = 2;
#endif
if(blinkAnimation == 0){ //transition from off to left
blinkAnimation = target_blinkAnimation;
}
else if(blinkAnimation == 3 - target_blinkAnimation){ // transition to warning
blinkAnimation = 3;
}
else{ // transition to off
blinkAnimation = 0;
}
#endif
}
static void blinkRightButton(bool pressed){
if(!pressed)return;
#ifdef FEATURE_LEDSTRIP
#ifdef LEDSTRIP_WRONG_DIRECTION
const auto target_blinkAnimation = 2;
#else
const auto target_blinkAnimation = 1;
#endif
if(blinkAnimation == 0){ //transition from off to left
blinkAnimation = target_blinkAnimation;
}
else if(blinkAnimation == 3 - target_blinkAnimation){ // transition to warning
blinkAnimation = 3;
}
else{ // transition to off
blinkAnimation = 0;
}
#endif
}
static void quickActionButtonDown(bool pressed){
}
static void quickActionButtonUp(bool pressed){
}
};
}

View File

@ -68,6 +68,14 @@ using BigOffsetChangeScreen = makeComponent<
SwitchScreenAction<LedstripMenu>
>;
using DeziampereChangeScreen = makeComponent<
ChangeValueDisplay<int16_t>,
StaticText<TEXT_LEDSTRIP_MILLIAMP>,
DeziampereAccessor,
BackActionInterface<SwitchScreenAction<LedstripMenu>>,
SwitchScreenAction<LedstripMenu>
>;
class LedstripMenu :
public MenuDisplay,
public StaticText<TEXT_LEDSTRIP>,
@ -83,6 +91,7 @@ public:
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CENTEROFFSET, CenterOffsetAccessor>, SwitchScreenAction<CenterOffsetChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_SMALLOFFSET, SmallOffsetAccessor>, SwitchScreenAction<SmallOffsetChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BIGOFFSET, BigOffsetAccessor>, SwitchScreenAction<BigOffsetChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_LEDSTRIP_MILLIAMP, DeziampereAccessor>, SwitchScreenAction<DeziampereChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<MainMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
}
};

View File

@ -227,24 +227,28 @@ void update()
if (lastState.blink_left != newState.blink_left && now - debounceBlinkLeft > dpadDebounce)
{
lastState.blink_left = newState.blink_left;
InputDispatcher::blinkLeftButton(newState.blink_left);
debounceBlinkLeft = now;
}
if (lastState.blink_right != newState.blink_right && now - debounceBlinkRight > dpadDebounce)
{
lastState.blink_right = newState.blink_right;
InputDispatcher::blinkRightButton(newState.blink_right);
debounceBlinkRight = now;
}
if (lastState.quickaction_down != newState.quickaction_down && now - debounceQuickactionDown > dpadDebounce)
{
lastState.quickaction_down = newState.quickaction_down;
InputDispatcher::quickActionButtonDown(newState.quickaction_down);
debounceQuickactionDown = now;
}
if (lastState.quickaction_up != newState.quickaction_up && now - debounceQuickactionUp > dpadDebounce)
{
lastState.quickaction_up = newState.quickaction_up;
InputDispatcher::quickActionButtonUp(newState.quickaction_up);
debounceQuickactionUp = now;
}
}

View File

@ -77,6 +77,7 @@ void updateLedStrip()
}
}
FastLED.setMaxPowerInVoltsAndMilliamps(5,settings.ledstrip.deziampere * 100);
FastLED.show();
}

View File

@ -229,7 +229,8 @@ constexpr Settings::Ledstrip defaultLedstrip {
.ledsCount = LEDSTRIP_LENGTH,
.centerOffset = 1,
.smallOffset = 4,
.bigOffset = 10
.bigOffset = 10,
.deziampere = 30
};
#endif

View File

@ -160,6 +160,7 @@ struct Settings
int16_t centerOffset;
int16_t smallOffset;
int16_t bigOffset;
int16_t deziampere;
} ledstrip;
#endif
@ -258,6 +259,7 @@ void Settings::executeForEveryCommonSetting(T &&callable)
callable("centerOffset", ledstrip.centerOffset);
callable("smallOffset", ledstrip.smallOffset);
callable("bigOffset", ledstrip.bigOffset);
callable("deziampere", ledstrip.deziampere);
#endif
callable("lockAlwPresetSw", lockscreen.allowPresetSwitch);

View File

@ -247,6 +247,7 @@ constexpr char TEXT_LEDSCOUNT[] = "LEDs Count";
constexpr char TEXT_CENTEROFFSET[] = "Center Offset";
constexpr char TEXT_SMALLOFFSET[] = "Small Offset";
constexpr char TEXT_BIGOFFSET[] = "Big Offset";
constexpr char TEXT_LEDSTRIP_MILLIAMP[] = "Ledstrip 0.1A";
//constexpr char TEXT_BACK[] = "Back";
//LockscreenSettingsMenu