From c13991cd252458e4453ac02395f3923b791a2184 Mon Sep 17 00:00:00 2001 From: Devydd <68201914+devydd@users.noreply.github.com> Date: Tue, 16 Mar 2021 01:15:05 +0100 Subject: [PATCH] Add user-adjustable "time between Power Pulses" and "Power Pulse duration" --- Translations/translation_EN.json | 14 +++++++++ Translations/translations_def.js | 10 +++++++ source/Core/Inc/Settings.h | 4 ++- source/Core/Inc/Translation.h | 4 +-- source/Core/Src/Settings.cpp | 4 ++- source/Core/Src/gui.cpp | 47 +++++++++++++++++++++++++++++++ source/Core/Threads/PIDThread.cpp | 17 +++++------ source/configuration.h | 10 +++++-- 8 files changed, 95 insertions(+), 15 deletions(-) diff --git a/Translations/translation_EN.json b/Translations/translation_EN.json index 7606eae8..ffc6a66d 100644 --- a/Translations/translation_EN.json +++ b/Translations/translation_EN.json @@ -305,6 +305,20 @@ "speed" ], "desc": "Speed of icon animations in menu " + }, + "PowerPulseWait": { + "text2": [ + "Power pulse", + "wait time" + ], + "desc": "Time to wait before triggering every keep-awake pulse (x 2.5s)" + }, + "PowerPulseDuration": { + "text2": [ + "Power pulse", + "duration" + ], + "desc": "Keep-awake-pulse duration (x 250ms)" } } } diff --git a/Translations/translations_def.js b/Translations/translations_def.js index ded42f08..a8d14089 100644 --- a/Translations/translations_def.js +++ b/Translations/translations_def.js @@ -376,6 +376,16 @@ var def = "id": "AnimSpeed", "maxLen": 6, "maxLen2": 13 + }, + { + "id": "PowerPulseWait", + "maxLen": 6, + "maxLen2": 13 + }, + { + "id": "PowerPulseDuration", + "maxLen": 6, + "maxLen2": 13 } ] } diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index 6c74720d..1a854366 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -10,7 +10,7 @@ #ifndef SETTINGS_H_ #define SETTINGS_H_ #include -#define SETTINGSVERSION (0x28) +#define SETTINGSVERSION (0x29) /*Change this if you change the struct below to prevent people getting \ out of sync*/ @@ -43,6 +43,8 @@ typedef struct { uint8_t descriptionScrollSpeed : 1; // Description scroll speed uint8_t lockingMode : 2; // Store the locking mode uint8_t KeepAwakePulse; // Keep Awake pulse power in 0.1 watts (10 = 1Watt) + uint8_t KeepAwakePulseWait; // Time between Keep Awake pulses in 2500 ms = 2.5 s increments + uint8_t KeepAwakePulseDuration; // Duration of the Keep Awake pusle in 250 ms increments uint16_t voltageDiv; // Voltage divisor factor uint16_t BoostTemp; // Boost mode set point for the iron diff --git a/source/Core/Inc/Translation.h b/source/Core/Inc/Translation.h index b1b1b2c4..38c24f73 100644 --- a/source/Core/Inc/Translation.h +++ b/source/Core/Inc/Translation.h @@ -12,8 +12,8 @@ extern const uint8_t USER_FONT_12[]; extern const uint8_t USER_FONT_6x8[]; extern const bool HasFahrenheit; -extern const char *SettingsShortNames[31][2]; -extern const char *SettingsDescriptions[31]; +extern const char *SettingsShortNames[33][2]; +extern const char *SettingsDescriptions[33]; extern const char *SettingsMenuEntries[5]; extern const char *SettingsCalibrationDone; diff --git a/source/Core/Src/Settings.cpp b/source/Core/Src/Settings.cpp index 81d59ec5..c82a1eb6 100644 --- a/source/Core/Src/Settings.cpp +++ b/source/Core/Src/Settings.cpp @@ -77,7 +77,9 @@ void resetSettings() { systemSettings.ReverseButtonTempChangeEnabled = REVERSE_BUTTON_TEMP_CHANGE; // systemSettings.TempChangeShortStep = TEMP_CHANGE_SHORT_STEP; // systemSettings.TempChangeLongStep = TEMP_CHANGE_LONG_STEP; // - systemSettings.KeepAwakePulse = POWER_PULSE_DEFAULT; + systemSettings.KeepAwakePulse = POWER_PULSE_DEFAULT; // Power of the power pulse + systemSettings.KeepAwakePulseWait = POWER_PULSE_WAIT_DEFAULT; // Time between Keep Awake pulses in 2.5 second increments + systemSettings.KeepAwakePulseDuration = POWER_PULSE_DURATION_DEFAULT; // Duration of the Keep Awake pusle in 250ms increments systemSettings.hallEffectSensitivity = 1; systemSettings.accelMissingWarningCounter = 0; systemSettings.pdMissingWarningCounter = 0; diff --git a/source/Core/Src/gui.cpp b/source/Core/Src/gui.cpp index cba85ccd..95dcc580 100644 --- a/source/Core/Src/gui.cpp +++ b/source/Core/Src/gui.cpp @@ -74,6 +74,10 @@ static void settings_displayAnimationSpeed(void); static bool settings_setAnimationSpeed(void); static void settings_displayAnimationLoop(void); static bool settings_setAnimationLoop(void); +static void settings_displayPowerPulseWait(void); +static bool settings_setPowerPulseWait(void); +static void settings_displayPowerPulseDuration(void); +static bool settings_setPowerPulseDuration(void); #ifdef HALL_SENSOR static void settings_displayHallEffect(void); static bool settings_setHallEffect(void); @@ -221,6 +225,8 @@ const menuitem advancedMenu[] = { * Power Pulse * Animation Loop * Animation Speed + * Power Pulse Wait + * Power Pulse Duration */ {(const char *)SettingsDescriptions[20], settings_setPowerLimit, settings_displayPowerLimit}, /*Power limit*/ {(const char *)SettingsDescriptions[6], settings_setAdvancedIDLEScreens, settings_displayAdvancedIDLEScreens}, /* Advanced idle screen*/ @@ -229,6 +235,8 @@ const menuitem advancedMenu[] = { {(const char *)SettingsDescriptions[11], settings_setCalibrate, settings_displayCalibrate}, /*Calibrate tip*/ {(const char *)SettingsDescriptions[13], settings_setCalibrateVIN, settings_displayCalibrateVIN}, /*Voltage input cal*/ {(const char *)SettingsDescriptions[24], settings_setPowerPulse, settings_displayPowerPulse}, /*Power Pulse adjustment */ + {(const char *)SettingsDescriptions[31], settings_setPowerPulseWait, settings_displayPowerPulseWait}, /*Power Pulse Wait adjustment*/ + {(const char *)SettingsDescriptions[32], settings_setPowerPulseDuration, settings_displayPowerPulseDuration}, /*Power Pulse Duration adjustment*/ //{ (const char *) SettingsDescriptions[25], settings_setTipGain, settings_displayTipGain }, /*TipGain*/ {NULL, NULL, NULL} // end of menu marker. DO NOT REMOVE }; @@ -936,6 +944,45 @@ static void settings_displayAnimationSpeed(void) { break; } } + +static bool settings_setPowerPulseWait(void) { + // Constrain to range 1 to POWER_PULSE_WAIT_MAX inclusive + auto &wait = systemSettings.KeepAwakePulseWait; + if (++wait > POWER_PULSE_WAIT_MAX) { + wait = 1; + } + + return wait == POWER_PULSE_WAIT_MAX; +} + +static void settings_displayPowerPulseWait(void) { + printShortDescription(31, 7); + if (systemSettings.KeepAwakePulse) { + OLED::printNumber(systemSettings.KeepAwakePulseWait, 1); + } else { + OLED::print(SymbolMinus); + } +} + +static bool settings_setPowerPulseDuration(void) { + // Constrain to range 1 to POWER_PULSE_DURATION_MAX inclusive + auto &duration = systemSettings.KeepAwakePulseDuration; + if (++duration > POWER_PULSE_DURATION_MAX) { + duration = 1; + } + + return duration == POWER_PULSE_DURATION_MAX; +} + +static void settings_displayPowerPulseDuration(void) { + printShortDescription(32, 7); + if (systemSettings.KeepAwakePulse) { + OLED::printNumber(systemSettings.KeepAwakePulseDuration, 1); + } else { + OLED::print(SymbolMinus); + } +} + #ifdef HALL_SENSOR static void settings_displayHallEffect(void) { printShortDescription(26, 7); diff --git a/source/Core/Threads/PIDThread.cpp b/source/Core/Threads/PIDThread.cpp index f16b9b2b..66302f99 100644 --- a/source/Core/Threads/PIDThread.cpp +++ b/source/Core/Threads/PIDThread.cpp @@ -14,10 +14,10 @@ #include "main.hpp" #include "power.hpp" #include "task.h" -static TickType_t powerPulseRate = 10 * TICKS_SECOND; -static TickType_t powerPulseDuration = 3 * TICKS_100MS; -TaskHandle_t pidTaskNotification = NULL; -uint32_t currentTempTargetDegC = 0; // Current temperature target in C +static TickType_t powerPulseWaitUnit = 25 * TICKS_100MS; // 2.5 s +static TickType_t powerPulseDurationUnit = (5 * TICKS_100MS) / 2; // 250 ms +TaskHandle_t pidTaskNotification = NULL; +uint32_t currentTempTargetDegC = 0; // Current temperature target in C /* StartPIDTask function */ void startPIDTask(void const *argument __unused) { @@ -92,10 +92,11 @@ void startPIDTask(void const *argument __unused) { } // If the user turns on the option of using an occasional pulse to keep the power bank on if (systemSettings.KeepAwakePulse) { - - if (xTaskGetTickCount() - lastPowerPulseStart > powerPulseRate) { - lastPowerPulseStart = xTaskGetTickCount(); - lastPowerPulseEnd = lastPowerPulseStart + powerPulseDuration; + const TickType_t powerPulseWait = powerPulseWaitUnit * systemSettings.KeepAwakePulseWait; + if (xTaskGetTickCount() - lastPowerPulseStart > powerPulseWait) { + const TickType_t powerPulseDuration = powerPulseDurationUnit * systemSettings.KeepAwakePulseDuration; + lastPowerPulseStart = xTaskGetTickCount(); + lastPowerPulseEnd = lastPowerPulseStart + powerPulseDuration; } // If current PID is less than the pulse level, check if we want to constrain to the pulse as the floor diff --git a/source/configuration.h b/source/configuration.h index 5db8e736..43d76ce1 100644 --- a/source/configuration.h +++ b/source/configuration.h @@ -68,14 +68,18 @@ #define TEMP_CHANGE_LONG_STEP_MAX 90 // Temp change long step MAX value /* Power pulse for keeping power banks awake*/ -#define POWER_PULSE_INCREMENT 1 -#define POWER_PULSE_MAX 50 // x10 max watts -#define POWER_PULSE_MAX 100 // x10 max watts +#define POWER_PULSE_INCREMENT 1 +#define POWER_PULSE_MAX 100 // x10 max watts +#define POWER_PULSE_WAIT_MAX 9 // 9*2.5s = 22.5 seconds +#define POWER_PULSE_DURATION_MAX 9 // 9*250ms = 2.25 seconds + #ifdef MODEL_TS100 #define POWER_PULSE_DEFAULT 0 #else #define POWER_PULSE_DEFAULT 5 #endif +#define POWER_PULSE_WAIT_DEFAULT 4; // Default rate of the power pulse: 4*2500 = 10000 ms = 10 s +#define POWER_PULSE_DURATION_DEFAULT 1; // Default duration of the power pulse: 1*250 = 250 ms /** * OLED Orientation Sensitivity on Automatic mode!