From 113965729e65609ac9bf4f3b9175a13f7da1b58c Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Sun, 27 Oct 2024 08:25:32 +0100 Subject: [PATCH 1/2] Fixes analog read for pins A6 and A7 (#338) * correct pin assignement for A6 and A7 for analog read * add comment for required changes --- src/MF_Analog/MFAnalog.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/MF_Analog/MFAnalog.cpp b/src/MF_Analog/MFAnalog.cpp index 6fb31cba..72c34953 100644 --- a/src/MF_Analog/MFAnalog.cpp +++ b/src/MF_Analog/MFAnalog.cpp @@ -18,6 +18,15 @@ void MFAnalog::attach(uint8_t pin, const char *name, uint8_t sensitivity) _sensitivity = sensitivity; _pin = pin; _name = name; +#if defined(ARDUINO_AVR_PROMICRO16) + // ProMicro has a special pin assignment for analog pins + // therefore reading from A6 and A7 does not work + // via "digital" pins. See also pins_arduino.h + if (_pin == 4) + _pin = A6; + else if (_pin == 6) + _pin = A7; +#endif pinMode(_pin, INPUT_PULLUP); // set pin to input. Could use OUTPUT for analog, but shows the intention :-) // Fill averaging buffers with initial reading for (uint8_t i = 0; i < ADC_MAX_AVERAGE; i++) { From 5fa8163f870b46c5c76d9204e9deaa67c507da28 Mon Sep 17 00:00:00 2001 From: elral <3263285+elral@users.noreply.github.com> Date: Sun, 27 Oct 2024 08:31:48 +0100 Subject: [PATCH 2/2] Power saving lcd (#340) * Turning the display on/off in case of power saving mode --- src/MF_LCDDisplay/LCDDisplay.cpp | 7 +++++++ src/MF_LCDDisplay/LCDDisplay.h | 1 + src/MF_LCDDisplay/MFLCDDisplay.cpp | 8 ++++++-- src/mobiflight.cpp | 6 ++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/MF_LCDDisplay/LCDDisplay.cpp b/src/MF_LCDDisplay/LCDDisplay.cpp index cae89c71..e1601625 100644 --- a/src/MF_LCDDisplay/LCDDisplay.cpp +++ b/src/MF_LCDDisplay/LCDDisplay.cpp @@ -53,6 +53,13 @@ namespace LCDDisplay cmdMessenger.unescape(output); lcd_I2C[address].display(output); } + + void PowerSave(bool state) + { + for (uint8_t i = 0; i < lcd_12cRegistered; ++i) { + lcd_I2C[i].powerSavingMode(state); + } + } } // namespace // LCDDisplay.cpp diff --git a/src/MF_LCDDisplay/LCDDisplay.h b/src/MF_LCDDisplay/LCDDisplay.h index 12bcf2db..6d8ba5e9 100644 --- a/src/MF_LCDDisplay/LCDDisplay.h +++ b/src/MF_LCDDisplay/LCDDisplay.h @@ -13,6 +13,7 @@ namespace LCDDisplay void Add(uint8_t address = 0x24, uint8_t cols = 16, uint8_t lines = 2); void Clear(); void OnSet(); + void PowerSave(bool state); } // LCDDisplay.h diff --git a/src/MF_LCDDisplay/MFLCDDisplay.cpp b/src/MF_LCDDisplay/MFLCDDisplay.cpp index 2c34601a..1e45531c 100644 --- a/src/MF_LCDDisplay/MFLCDDisplay.cpp +++ b/src/MF_LCDDisplay/MFLCDDisplay.cpp @@ -42,10 +42,14 @@ void MFLCDDisplay::detach() void MFLCDDisplay::powerSavingMode(bool state) { - if (state) + if (state) { _lcdDisplay.noBacklight(); - else + _lcdDisplay.noDisplay(); + } + else { _lcdDisplay.backlight(); + _lcdDisplay.display(); + } } void MFLCDDisplay::test() diff --git a/src/mobiflight.cpp b/src/mobiflight.cpp index 2d0a9b3d..33fc8f76 100644 --- a/src/mobiflight.cpp +++ b/src/mobiflight.cpp @@ -25,6 +25,9 @@ #if MF_SERVO_SUPPORT == 1 #include "Servos.h" #endif +#if MF_LCD_SUPPORT == 1 +#include "LCDDisplay.h" +#endif #if MF_OUTPUT_SHIFTER_SUPPORT == 1 #include "OutputShifter.h" #endif @@ -126,6 +129,9 @@ void SetPowerSavingMode(bool state) #if MF_OUTPUT_SHIFTER_SUPPORT == 1 OutputShifter::PowerSave(state); #endif +#if MF_LCD_SUPPORT == 1 + LCDDisplay::PowerSave(state); +#endif #ifdef DEBUG2CMDMESSENGER if (state)