From 60a951f56feedeacec2291ba4102006ce1314f30 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 17 Oct 2018 08:22:04 +1100 Subject: [PATCH] Fix temperature getting bumped off screen This fixes the temp gettting bumped because I forgot to reset OLED::cursor_y after writing. Fixes #376 (hopefully) --- workspace/TS100/src/hardware.c | 65 +++++++++++++++++++--------------- workspace/TS100/src/main.cpp | 6 ++-- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/workspace/TS100/src/hardware.c b/workspace/TS100/src/hardware.c index 6d70fc03..603cb04b 100644 --- a/workspace/TS100/src/hardware.c +++ b/workspace/TS100/src/hardware.c @@ -88,30 +88,30 @@ uint16_t getTipInstantTemperature() { uint16_t lookupTipDefaultCalValue(enum TipType tipID) { #ifdef MODEL_TS100 switch (tipID) { - case TS_D24: + case TS_D24: return 141; break; - case TS_BC2: + case TS_BC2: return (133 + 129) / 2; break; - case TS_C1: + case TS_C1: return 133; break; - case TS_B2: + case TS_B2: return 133; - default: + default: return 132; // make this the average of all break; } #else switch (tipID) { - case TS_D25: + case TS_D25: return 154; break; - case TS_B02: + case TS_B02: return 154; break; - default: + default: return 154; // make this the average of all break; } @@ -168,11 +168,15 @@ uint16_t getInputVoltageX10(uint16_t divisor) { } #ifdef MODEL_TS80 uint8_t QCMode = 0; +uint8_t QCTries = 0; void seekQC(int16_t Vx10) { - if (QCMode <= 1) - return; // NOT connected to a QC Charger + if (QCMode == 5) + startQC(); + if (QCMode == 0) + return; // NOT connected to a QC Charger + if (Vx10 < 50) - return; + return; // Seek the QC to the Voltage given if this adapter supports continuous mode // try and step towards the wanted value @@ -244,7 +248,7 @@ void startQC() { // negotiating as someone is feeding in hv uint16_t vin = getInputVoltageX10(780); if (vin > 150) - return;// Over voltage + return; // Over voltage if (vin > 100) { QCMode = 1; // ALready at ~12V return; @@ -286,7 +290,7 @@ void startQC() { } // Check if D- is low to spot a QC charger if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET) - enteredQC = 1; + enteredQC = 1; if (enteredQC) { // We have a QC capable charger HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); @@ -306,7 +310,7 @@ void startQC() { for (uint8_t i = 0; i < 10; i++) { if (getInputVoltageX10(195) > 80) { // yay we have at least QC2.0 or QC3.0 - QCMode = 3;// We have at least QC2, pray for 3 + QCMode = 3; // We have at least QC2, pray for 3 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); @@ -314,12 +318,17 @@ void startQC() { } vTaskDelay(10); // 100mS } - QCMode = 0; - // No QC / not working to us - + QCMode = 5; + QCTries++; + if (QCTries > 10) // 10 goes to get it going + QCMode = 0; } else { // no QC + QCMode = 0; + } + if (QCTries > 10) + QCMode = 0; } // Get tip resistance in milliohms uint32_t calculateTipR(uint8_t useFilter) { @@ -333,7 +342,7 @@ uint32_t calculateTipR(uint8_t useFilter) { GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);// Set low first + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET); // Set low first setTipPWM(0); vTaskDelay(1); uint32_t offReading = getTipInstantTemperature(); @@ -347,8 +356,8 @@ uint32_t calculateTipR(uint8_t useFilter) { } // Turn on - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);// Set low first - vTaskDelay(1);// delay to allow it too stabilize + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET); // Set low first + vTaskDelay(1); // delay to allow it too stabilize uint32_t onReading = getTipInstantTemperature(); for (uint8_t i = 0; i < 24; i++) { if (useFilter == 0) { @@ -366,7 +375,7 @@ uint32_t calculateTipR(uint8_t useFilter) { // 4688 milliohms (Measured using 4 terminal measurement) 25x oversampling // reads this as around 47490 Almost perfectly 10x the milliohms value This // will drift massively with tip temp However we really only need 10x ohms - return (difference / 10) + 1;// ceil + return (difference / 10) + 1; // ceil } static unsigned int sqrt32(unsigned long n) { unsigned int c = 0x8000; @@ -374,10 +383,10 @@ static unsigned int sqrt32(unsigned long n) { for (;;) { if (g * g > n) - g ^= c; + g ^= c; c >>= 1; if (c == 0) - return g; + return g; g |= c; } } @@ -388,26 +397,26 @@ int16_t calculateMaxVoltage(uint8_t useFilter, uint8_t useHP) { uint32_t milliOhms = calculateTipR(useFilter); // Check no tip if (milliOhms > 10000) - return -1; + return -1; // // V = sqrt(18W*R) // Convert this to sqrt(18W)*sqrt(milli ohms)*sqrt(1/1000) uint32_t Vx = sqrt32(milliOhms); if (useHP) - Vx *= 1549;//sqrt(24)*sqrt(1/1000) + Vx *= 1549; //sqrt(24)*sqrt(1/1000) else - Vx *= 1342;// sqrt(18) * sqrt(1/1000) + Vx *= 1342; // sqrt(18) * sqrt(1/1000) // Round to nearest 200mV, // So divide by 100 to start, to get in Vxx Vx /= 100; if (Vx % 10 >= 5) - Vx += 10; + Vx += 10; Vx /= 10; // Round to nearest increment of 2 if (Vx % 2 == 1) - Vx++; + Vx++; return Vx; } diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index 427ec19a..0eb15a87 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -282,8 +282,8 @@ static void gui_drawBatteryIcon() { OLED::printNumber(1, 1); OLED::setCursor(xPos, 8); OLED::printNumber(V % 10, 1); - OLED::setFont(0); + OLED::setCursor(xPos+12,0); // need to reset this as if we drew a wide char } else { OLED::printNumber(V, 1); } @@ -537,7 +537,6 @@ static void gui_solderingMode(uint8_t jumpToSleep) { OLED::print(SolderingAdvancedPowerPrompt); // Power: OLED::printNumber(getTipPWM(), 3); OLED::print("%"); - // OLED::printNumber(getTipRawTemp(0), 6); if (systemSettings.sensitivity && systemSettings.SleepTime) { OLED::print(" "); @@ -784,6 +783,7 @@ void startGUITask(void const *argument __unused) { OLED::setFont(0); OLED::displayOnOff(true); // turn lcd on #ifdef MODEL_TS80 + //Here we re-check for tip presence if (idealQCVoltage < 90) idealQCVoltage = calculateMaxVoltage(1, systemSettings.cutoutSetting); // 1 means use filtered values rather than do its own @@ -1008,6 +1008,8 @@ void startPIDTask(void const *argument __unused) { } #define MOVFilter 8 void startMOVTask(void const *argument __unused) { + OLED::setRotation(false); + #ifdef MODEL_TS80 startQC(); while (idealQCVoltage == 0)