From 7992af82000c20f60e78c1e5adb54f33cecd0e80 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Mon, 21 Oct 2024 21:30:41 +0200 Subject: [PATCH] add power saving mode for outputsifter (#339) --- src/MF_OutputShifter/MFOutputShifter.cpp | 13 +++++++++++++ src/MF_OutputShifter/MFOutputShifter.h | 1 + src/MF_OutputShifter/OutputShifter.cpp | 7 +++++++ src/MF_OutputShifter/OutputShifter.h | 1 + src/mobiflight.cpp | 3 +++ 5 files changed, 25 insertions(+) diff --git a/src/MF_OutputShifter/MFOutputShifter.cpp b/src/MF_OutputShifter/MFOutputShifter.cpp index c4d827e8..59cf0566 100644 --- a/src/MF_OutputShifter/MFOutputShifter.cpp +++ b/src/MF_OutputShifter/MFOutputShifter.cpp @@ -84,4 +84,17 @@ void MFOutputShifter::update() digitalWrite(_latchPin, HIGH); } +void MFOutputShifter::powerSavingMode(bool state) +{ + if (state) { + digitalWrite(_latchPin, LOW); + for (uint8_t i = _moduleCount; i > 0; i--) { + shiftOut(_dataPin, _clockPin, MSBFIRST, 0xFF * MF_LOW); + } + digitalWrite(_latchPin, HIGH); + } else { + update(); + } +} + // MFOutputShifter.cpp diff --git a/src/MF_OutputShifter/MFOutputShifter.h b/src/MF_OutputShifter/MFOutputShifter.h index 5f8ea737..1720a416 100644 --- a/src/MF_OutputShifter/MFOutputShifter.h +++ b/src/MF_OutputShifter/MFOutputShifter.h @@ -26,6 +26,7 @@ class MFOutputShifter void detach(); void clear(); void update(); + void powerSavingMode(bool state); private: uint8_t _latchPin; // Latch pin diff --git a/src/MF_OutputShifter/OutputShifter.cpp b/src/MF_OutputShifter/OutputShifter.cpp index 34305c5a..3d3282df 100644 --- a/src/MF_OutputShifter/OutputShifter.cpp +++ b/src/MF_OutputShifter/OutputShifter.cpp @@ -60,6 +60,13 @@ namespace OutputShifter int value = cmdMessenger.readInt16Arg(); outputShifter[module].setPins(pins, value); } + + void PowerSave(bool state) + { + for (uint8_t i = 0; i < outputShifterRegistered; ++i) { + outputShifter[i].powerSavingMode(state); + } + } } // namespace // OutputShifter.cpp diff --git a/src/MF_OutputShifter/OutputShifter.h b/src/MF_OutputShifter/OutputShifter.h index 257247d2..b3917029 100644 --- a/src/MF_OutputShifter/OutputShifter.h +++ b/src/MF_OutputShifter/OutputShifter.h @@ -12,6 +12,7 @@ namespace OutputShifter void Add(uint8_t latchPin, uint8_t clockPin, uint8_t dataPin, uint8_t modules); void Clear(); void OnSet(); + void PowerSave(bool state); } // OutputShifter.h \ No newline at end of file diff --git a/src/mobiflight.cpp b/src/mobiflight.cpp index 45ebae74..2d0a9b3d 100644 --- a/src/mobiflight.cpp +++ b/src/mobiflight.cpp @@ -123,6 +123,9 @@ void SetPowerSavingMode(bool state) #if MF_CUSTOMDEVICE_SUPPORT == 1 CustomDevice::PowerSave(state); #endif +#if MF_OUTPUT_SHIFTER_SUPPORT == 1 + OutputShifter::PowerSave(state); +#endif #ifdef DEBUG2CMDMESSENGER if (state)