Change to using setting to control power pulse

This commit is contained in:
Ben V. Brown
2020-05-22 23:30:20 +10:00
parent 4ec62f8c8f
commit 3287ee9d78

View File

@@ -36,15 +36,13 @@ uint32_t MOVTaskBuffer[MOVTaskStackSize];
osStaticThreadDef_t MOVTaskControlBlock; osStaticThreadDef_t MOVTaskControlBlock;
static TaskHandle_t pidTaskNotification = NULL; static TaskHandle_t pidTaskNotification = NULL;
static TickType_t powerPulseRate = 1000;
static TickType_t powerPulseDuration = 50;
void startGUITask(void const *argument); void startGUITask(void const *argument);
void startPIDTask(void const *argument); void startPIDTask(void const *argument);
void startMOVTask(void const *argument); void startMOVTask(void const *argument);
// End FreeRTOS // End FreeRTOS
static const int maxPowerIdleTicks = 1000;
static const int powerPulseTicks = 50;
static const int x10PowerPulseWatts = 3;
// Main sets up the hardware then hands over to the FreeRTOS kernel // Main sets up the hardware then hands over to the FreeRTOS kernel
int main(void) { int main(void) {
@@ -117,7 +115,8 @@ void startPIDTask(void const *argument __unused) {
#ifdef MODEL_TS80 #ifdef MODEL_TS80
//Set power management code to the tip resistance in ohms * 10 //Set power management code to the tip resistance in ohms * 10
TickType_t lastPowerPulse = 0; TickType_t lastPowerPulseStart = 0;
TickType_t lastPowerPulseEnd = 0;
#else #else
#endif #endif
@@ -183,18 +182,23 @@ void startPIDTask(void const *argument __unused) {
// Unfortunately, our temp signal is too noisy to really help. // Unfortunately, our temp signal is too noisy to really help.
} }
#ifdef MODEL_TS80 //If the user turns on the option of using an occasional pulse to keep the power bank on
//If its a TS80, we want to have the option of using an occasional pulse to keep the power bank on if (systemSettings.KeepAwakePulse) {
if (((xTaskGetTickCount() - lastPowerPulse) > maxPowerIdleTicks)
&& (x10WattsOut < x10PowerPulseWatts)) { if (xTaskGetTickCount() - lastPowerPulseStart
x10WattsOut = x10PowerPulseWatts; > powerPulseRate) {
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
if (x10WattsOut < systemSettings.KeepAwakePulse
&& xTaskGetTickCount() < lastPowerPulseEnd) {
x10WattsOut = systemSettings.KeepAwakePulse;
}
} }
if (((xTaskGetTickCount() - lastPowerPulse)
> (maxPowerIdleTicks + powerPulseTicks))
&& (x10WattsOut >= x10PowerPulseWatts)) {
lastPowerPulse = xTaskGetTickCount();
}
#endif
//Secondary safety check to forcefully disable header when within ADC noise of top of ADC //Secondary safety check to forcefully disable header when within ADC noise of top of ADC
if (getTipRawTemp(0) > (0x7FFF - 150)) { if (getTipRawTemp(0) > (0x7FFF - 150)) {
x10WattsOut = 0; x10WattsOut = 0;
@@ -263,8 +267,7 @@ void startMOVTask(void const *argument __unused) {
datax[currentPointer] = (int32_t) tx; datax[currentPointer] = (int32_t) tx;
datay[currentPointer] = (int32_t) ty; datay[currentPointer] = (int32_t) ty;
dataz[currentPointer] = (int32_t) tz; dataz[currentPointer] = (int32_t) tz;
if (!accelInit) if (!accelInit) {
{
for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) { for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) {
datax[i] = (int32_t) tx; datax[i] = (int32_t) tx;
datay[i] = (int32_t) ty; datay[i] = (int32_t) ty;
@@ -309,14 +312,15 @@ void startMOVTask(void const *argument __unused) {
#define LOGO_HEADER_VALUE 0xF00DAA55 #define LOGO_HEADER_VALUE 0xF00DAA55
bool showBootLogoIfavailable() { bool showBootLogoIfavailable() {
// Do not show logo data if signature is not found. // Do not show logo data if signature is not found.
if (LOGO_HEADER_VALUE != *(reinterpret_cast<const uint32_t *>(FLASH_LOGOADDR))) { if (LOGO_HEADER_VALUE
return false; != *(reinterpret_cast<const uint32_t*>(FLASH_LOGOADDR))) {
} return false;
}
OLED::drawAreaSwapped(0, 0, 96, 16, (uint8_t*) (FLASH_LOGOADDR + 4)); OLED::drawAreaSwapped(0, 0, 96, 16, (uint8_t*) (FLASH_LOGOADDR + 4));
OLED::refresh(); OLED::refresh();
return true; return true;
} }
/* /*
@@ -344,12 +348,10 @@ void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
FRToSI2C::CpltCallback(); FRToSI2C::CpltCallback();
} }
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) { void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) {
asm("bkpt");
FRToSI2C::CpltCallback(); FRToSI2C::CpltCallback();
} }
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) { void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
//asm("bkpt");
FRToSI2C::CpltCallback(); FRToSI2C::CpltCallback();
} }
@@ -358,7 +360,7 @@ void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
} }
void vApplicationStackOverflowHook(xTaskHandle *pxTask __unused, void vApplicationStackOverflowHook(xTaskHandle *pxTask __unused,
signed portCHAR *pcTaskName __unused) { signed portCHAR *pcTaskName __unused) {
asm("bkpt");
// We dont have a good way to handle a stack overflow at this point in time // We dont have a good way to handle a stack overflow at this point in time
NVIC_SystemReset(); NVIC_SystemReset();
} }