diff --git a/workspace/TS100/inc/hardware.h b/workspace/TS100/inc/hardware.h index 0b70f227..39d5a534 100644 --- a/workspace/TS100/inc/hardware.h +++ b/workspace/TS100/inc/hardware.h @@ -115,6 +115,7 @@ enum TipType { }; #endif +uint16_t lookupTipDefaultCalValue(enum TipType tipID); uint16_t getHandleTemperature(); uint16_t getTipRawTemp(uint8_t instant); uint16_t getInputVoltageX10(uint16_t divisor); diff --git a/workspace/TS100/src/Setup.c b/workspace/TS100/src/Setup.c index 202f98df..78707d4b 100644 --- a/workspace/TS100/src/Setup.c +++ b/workspace/TS100/src/Setup.c @@ -308,9 +308,12 @@ static void MX_TIM2_Init(void) { // in the PWM off time. htim2.Instance = TIM2; htim2.Init.Prescaler = - 2000; // pwm out is 10k, we want to run our PWM at around 100hz + 785; // pwm out is 10k from tim3, we want to run our PWM at around 10hz or slower on the output stage + // The input is 1mhz after the div/4, so divide this by 785 to give around 4Hz output change rate + //Trade off is the slower the PWM output the slower we can respond and we gain temperature accuracy in settling time, + //But it increases the time delay between the heat cycle and the measurement and calculate cycle htim2.Init.CounterMode = TIM_COUNTERMODE_UP; - htim2.Init.Period = 122; + htim2.Init.Period = 255+56; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before divide htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; HAL_TIM_Base_Init(&htim2); @@ -326,11 +329,11 @@ static void MX_TIM2_Init(void) { HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig); sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 118; + sConfigOC.Pulse = 255+47; //255 is the largest time period of the drive signal, and the 47 offsets this around 5ms afterwards /* * It takes 4 milliseconds for output to be stable after PWM turns off. * Assume ADC samples in 0.5ms - * We need to set this to 100% + 5.5ms + * We need to set this to 100% + 4.5ms * */ sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; diff --git a/workspace/TS100/src/gui.cpp b/workspace/TS100/src/gui.cpp index b57bf243..d6dfbb0d 100644 --- a/workspace/TS100/src/gui.cpp +++ b/workspace/TS100/src/gui.cpp @@ -103,7 +103,7 @@ static void settings_enterAdvancedMenu(void); * Reset Settings * */ -const menuitem rootSettingsMenu[]{ +const menuitem rootSettingsMenu[] { /* * Power Source * Soldering Menu @@ -113,142 +113,118 @@ const menuitem rootSettingsMenu[]{ * Exit */ #ifdef MODEL_TS100 - {(const char*)SettingsDescriptions[0], - {settings_setInputVRange}, - {settings_displayInputVRange}}, /*Voltage input*/ + { (const char*)SettingsDescriptions[0], + { settings_setInputVRange}, + { settings_displayInputVRange}}, /*Voltage input*/ #else - {(const char*)SettingsDescriptions[20], - {settings_setInputPRange}, - {settings_displayInputPRange}}, /*Voltage input*/ + { (const char*) SettingsDescriptions[20], { settings_setInputPRange }, { + settings_displayInputPRange } }, /*Voltage input*/ #endif - {(const char*)NULL, - {settings_enterSolderingMenu}, - {settings_displaySolderingMenu}}, /*Soldering*/ - {(const char*)NULL, - {settings_enterPowerMenu}, - {settings_displayPowerMenu}}, /*Sleep Options Menu*/ - {(const char*)NULL, - {settings_enterUIMenu}, - {settings_displayUIMenu}}, /*UI Menu*/ - {(const char*)NULL, - {settings_enterAdvancedMenu}, - {settings_displayAdvancedMenu}}, /*Advanced Menu*/ - {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE + { (const char*) NULL, { settings_enterSolderingMenu }, { + settings_displaySolderingMenu } }, /*Soldering*/ + { (const char*) NULL, { settings_enterPowerMenu }, { + settings_displayPowerMenu } }, /*Sleep Options Menu*/ + { (const char*) NULL, { settings_enterUIMenu }, + { settings_displayUIMenu } }, /*UI Menu*/ + { (const char*) NULL, { settings_enterAdvancedMenu }, { + settings_displayAdvancedMenu } }, /*Advanced Menu*/ + { NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE }; const menuitem solderingMenu[] = { - /* - * Boost Mode Enabled - * Boost Mode Temp - * Auto Start - */ - {(const char*)SettingsDescriptions[8], - {settings_setBoostModeEnabled}, - {settings_displayBoostModeEnabled}}, /*Enable Boost*/ - {(const char*)SettingsDescriptions[9], - {settings_setBoostTemp}, - {settings_displayBoostTemp}}, /*Boost Temp*/ - {(const char*)SettingsDescriptions[10], - {settings_setAutomaticStartMode}, - {settings_displayAutomaticStartMode}}, /*Auto start*/ - {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE +/* + * Boost Mode Enabled + * Boost Mode Temp + * Auto Start + */ +{ (const char*) SettingsDescriptions[8], { settings_setBoostModeEnabled }, { + settings_displayBoostModeEnabled } }, /*Enable Boost*/ +{ (const char*) SettingsDescriptions[9], { settings_setBoostTemp }, { + settings_displayBoostTemp } }, /*Boost Temp*/ +{ (const char*) SettingsDescriptions[10], { settings_setAutomaticStartMode }, { + settings_displayAutomaticStartMode } }, /*Auto start*/ +{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE }; const menuitem UIMenu[] = { - /* - // Language - * Scrolling Speed - * Temperature Unit - * Display orientation - * Cooldown blink - */ - {(const char*)SettingsDescriptions[5], - {settings_setTempF}, - {settings_displayTempF}}, /* Temperature units*/ - {(const char*)SettingsDescriptions[7], - {settings_setDisplayRotation}, - {settings_displayDisplayRotation}}, /*Display Rotation*/ - {(const char*)SettingsDescriptions[11], - {settings_setCoolingBlinkEnabled}, - {settings_displayCoolingBlinkEnabled}}, /*Cooling blink warning*/ - {(const char*)SettingsDescriptions[16], - {settings_setScrollSpeed}, - {settings_displayScrollSpeed}}, /*Scroll Speed for descriptions*/ - {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE +/* + // Language + * Scrolling Speed + * Temperature Unit + * Display orientation + * Cooldown blink + */ +{ (const char*) SettingsDescriptions[5], { settings_setTempF }, { + settings_displayTempF } }, /* Temperature units*/ +{ (const char*) SettingsDescriptions[7], { settings_setDisplayRotation }, { + settings_displayDisplayRotation } }, /*Display Rotation*/ +{ (const char*) SettingsDescriptions[11], { settings_setCoolingBlinkEnabled }, { + settings_displayCoolingBlinkEnabled } }, /*Cooling blink warning*/ +{ (const char*) SettingsDescriptions[16], { settings_setScrollSpeed }, { + settings_displayScrollSpeed } }, /*Scroll Speed for descriptions*/ +{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE }; const menuitem PowerMenu[] = { - /* - * Sleep Temp - * Sleep Time - * Shutdown Time - * Motion Sensitivity - */ - {(const char*)SettingsDescriptions[1], - {settings_setSleepTemp}, - {settings_displaySleepTemp}}, /*Sleep Temp*/ - {(const char*)SettingsDescriptions[2], - {settings_setSleepTime}, - {settings_displaySleepTime}}, /*Sleep Time*/ - {(const char*)SettingsDescriptions[3], - {settings_setShutdownTime}, - {settings_displayShutdownTime}}, /*Shutdown Time*/ - {(const char*)SettingsDescriptions[4], - {settings_setSensitivity}, - {settings_displaySensitivity}}, /* Motion Sensitivity*/ - {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE +/* + * Sleep Temp + * Sleep Time + * Shutdown Time + * Motion Sensitivity + */ +{ (const char*) SettingsDescriptions[1], { settings_setSleepTemp }, { + settings_displaySleepTemp } }, /*Sleep Temp*/ +{ (const char*) SettingsDescriptions[2], { settings_setSleepTime }, { + settings_displaySleepTime } }, /*Sleep Time*/ +{ (const char*) SettingsDescriptions[3], { settings_setShutdownTime }, { + settings_displayShutdownTime } }, /*Shutdown Time*/ +{ (const char*) SettingsDescriptions[4], { settings_setSensitivity }, { + settings_displaySensitivity } }, /* Motion Sensitivity*/ +{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE }; const menuitem advancedMenu[] = { - /* - * Detailed IDLE - * Detailed Soldering - * Logo Time - * Calibrate Temperature - * Calibrate Input V - * Reset Settings - */ - {(const char*)SettingsDescriptions[6], - {settings_setAdvancedIDLEScreens}, - {settings_displayAdvancedIDLEScreens}}, /* Advanced idle screen*/ - {(const char*)SettingsDescriptions[15], - {settings_setAdvancedSolderingScreens}, - {settings_displayAdvancedSolderingScreens}}, /* Advanced soldering screen*/ - {(const char*)SettingsDescriptions[13], - {settings_setResetSettings}, - {settings_displayResetSettings}}, /*Resets settings*/ - {(const char*)SettingsDescriptions[17], - {settings_setTipModel}, - {settings_displayTipModel}}, /*Select tip Model */ - {(const char*)SettingsDescriptions[12], - {settings_setCalibrate}, - {settings_displayCalibrate}}, /*Calibrate tip*/ - {(const char*)SettingsDescriptions[14], - {settings_setCalibrateVIN}, - {settings_displayCalibrateVIN}}, /*Voltage input cal*/ - {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE +/* + * Detailed IDLE + * Detailed Soldering + * Logo Time + * Calibrate Temperature + * Calibrate Input V + * Reset Settings + */ +{ (const char*) SettingsDescriptions[6], { settings_setAdvancedIDLEScreens }, { + settings_displayAdvancedIDLEScreens } }, /* Advanced idle screen*/ +{ (const char*) SettingsDescriptions[15], + { settings_setAdvancedSolderingScreens }, { + settings_displayAdvancedSolderingScreens } }, /* Advanced soldering screen*/ +{ (const char*) SettingsDescriptions[13], { settings_setResetSettings }, { + settings_displayResetSettings } }, /*Resets settings*/ +{ (const char*) SettingsDescriptions[17], { settings_setTipModel }, { + settings_displayTipModel } }, /*Select tip Model */ +{ (const char*) SettingsDescriptions[12], { settings_setCalibrate }, { + settings_displayCalibrate } }, /*Calibrate tip*/ +{ (const char*) SettingsDescriptions[14], { settings_setCalibrateVIN }, { + settings_displayCalibrateVIN } }, /*Voltage input cal*/ +{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE }; -const menuitem calibrationMenu[]{ - {(const char*)SettingsDescriptions[6], - {calibration_enterSimpleCal}, - {calibration_displaySimpleCal}}, - /* Simple Cal*/ - {(const char*)SettingsDescriptions[6], - {calibration_enterAdvancedCal}, - {calibration_displayAdvancedCal}}, /* Advanced Cal */ - {NULL, {NULL}, {NULL}}}; +const menuitem calibrationMenu[] { { (const char*) SettingsDescriptions[6], { + calibration_enterSimpleCal }, { calibration_displaySimpleCal } }, +/* Simple Cal*/ +{ (const char*) SettingsDescriptions[6], { calibration_enterAdvancedCal }, { + calibration_displayAdvancedCal } }, /* Advanced Cal */ +{ NULL, { NULL }, { NULL } } }; static void printShortDescriptionSingleLine(uint32_t shortDescIndex) { - OLED::setFont(0); - OLED::setCharCursor(0, 0); - OLED::print(SettingsShortNames[shortDescIndex][0]); + OLED::setFont(0); + OLED::setCharCursor(0, 0); + OLED::print(SettingsShortNames[shortDescIndex][0]); } static void printShortDescriptionDoubleLine(uint32_t shortDescIndex) { - OLED::setFont(1); - OLED::setCharCursor(0, 0); - OLED::print(SettingsShortNames[shortDescIndex][0]); - OLED::setCharCursor(0, 1); - OLED::print(SettingsShortNames[shortDescIndex][1]); + OLED::setFont(1); + OLED::setCharCursor(0, 0); + OLED::print(SettingsShortNames[shortDescIndex][0]); + OLED::setCharCursor(0, 1); + OLED::print(SettingsShortNames[shortDescIndex][1]); } /** @@ -259,497 +235,499 @@ static void printShortDescriptionDoubleLine(uint32_t shortDescIndex) { * description. */ static void printShortDescription(uint32_t shortDescIndex, - uint16_t cursorCharPosition) { - // print short description (default single line, explicit double line) - if (SettingsShortNameType == SHORT_NAME_DOUBLE_LINE) { - printShortDescriptionDoubleLine(shortDescIndex); - } else { - printShortDescriptionSingleLine(shortDescIndex); - } + uint16_t cursorCharPosition) { + // print short description (default single line, explicit double line) + if (SettingsShortNameType == SHORT_NAME_DOUBLE_LINE) { + printShortDescriptionDoubleLine(shortDescIndex); + } else { + printShortDescriptionSingleLine(shortDescIndex); + } - // prepare cursor for value - OLED::setFont(0); - OLED::setCharCursor(cursorCharPosition, 0); + // prepare cursor for value + OLED::setFont(0); + OLED::setCharCursor(cursorCharPosition, 0); } static int userConfirmation(const char* message) { - uint16_t messageWidth = FONT_12_WIDTH * (strlen(message) + 7); - uint32_t messageStart = xTaskGetTickCount(); + uint16_t messageWidth = FONT_12_WIDTH * (strlen(message) + 7); + uint32_t messageStart = xTaskGetTickCount(); - OLED::setFont(0); - OLED::setCursor(0, 0); - int16_t lastOffset = -1; - bool lcdRefresh = true; + OLED::setFont(0); + OLED::setCursor(0, 0); + int16_t lastOffset = -1; + bool lcdRefresh = true; - for (;;) { - int16_t messageOffset = - ((xTaskGetTickCount() - messageStart) / - (systemSettings.descriptionScrollSpeed == 1 ? 1 : 2)); - messageOffset %= messageWidth; // Roll around at the end + for (;;) { + int16_t messageOffset = ((xTaskGetTickCount() - messageStart) + / (systemSettings.descriptionScrollSpeed == 1 ? 1 : 2)); + messageOffset %= messageWidth; // Roll around at the end - if (lastOffset != messageOffset) { - OLED::clearScreen(); + if (lastOffset != messageOffset) { + OLED::clearScreen(); - //^ Rolling offset based on time - OLED::setCursor((OLED_WIDTH - messageOffset), 0); - OLED::print(message); - lastOffset = messageOffset; - lcdRefresh = true; - } + //^ Rolling offset based on time + OLED::setCursor((OLED_WIDTH - messageOffset), 0); + OLED::print(message); + lastOffset = messageOffset; + lcdRefresh = true; + } - ButtonState buttons = getButtonState(); - switch (buttons) { - case BUTTON_F_SHORT: - // User confirmed - return 1; + ButtonState buttons = getButtonState(); + switch (buttons) { + case BUTTON_F_SHORT: + // User confirmed + return 1; - case BUTTON_NONE: - break; - default: - case BUTTON_BOTH: - case BUTTON_B_SHORT: - case BUTTON_F_LONG: - case BUTTON_B_LONG: - return 0; - } + case BUTTON_NONE: + break; + default: + case BUTTON_BOTH: + case BUTTON_B_SHORT: + case BUTTON_F_LONG: + case BUTTON_B_LONG: + return 0; + } - if (lcdRefresh) { - OLED::refresh(); - osDelay(40); - lcdRefresh = false; - } - } - return 0; + if (lcdRefresh) { + OLED::refresh(); + osDelay(40); + lcdRefresh = false; + } + } + return 0; } #ifdef MODEL_TS100 static void settings_setInputVRange(void) { - systemSettings.cutoutSetting = (systemSettings.cutoutSetting + 1) % 5; + systemSettings.cutoutSetting = (systemSettings.cutoutSetting + 1) % 5; } static void settings_displayInputVRange(void) { - printShortDescription(0, 6); + printShortDescription(0, 6); - if (systemSettings.cutoutSetting) { - OLED::drawChar('0' + 2 + systemSettings.cutoutSetting); - OLED::drawChar('S'); - } else { - OLED::print("DC"); - } + if (systemSettings.cutoutSetting) { + OLED::drawChar('0' + 2 + systemSettings.cutoutSetting); + OLED::drawChar('S'); + } else { + OLED::print("DC"); + } } #else static void settings_setInputPRange(void) { - systemSettings.cutoutSetting = (systemSettings.cutoutSetting + 1) % 2; + systemSettings.cutoutSetting = (systemSettings.cutoutSetting + 1) % 2; } static void settings_displayInputPRange(void) { - printShortDescription(0, 5); + printShortDescription(0, 5); //0 = 18W, 1=24W - switch(systemSettings.cutoutSetting) - { - case 0: - OLED::print("18W"); - break; - case 1: - OLED::print("24W"); - break; - default: - break; - } + switch (systemSettings.cutoutSetting) { + case 0: + OLED::print("18W"); + break; + case 1: + OLED::print("24W"); + break; + default: + break; + } } #endif static void settings_setSleepTemp(void) { - // If in C, 10 deg, if in F 20 deg - if (systemSettings.temperatureInF) { - systemSettings.SleepTemp += 20; - if (systemSettings.SleepTemp > 580) systemSettings.SleepTemp = 120; - } else { - systemSettings.SleepTemp += 10; - if (systemSettings.SleepTemp > 300) systemSettings.SleepTemp = 50; - } + // If in C, 10 deg, if in F 20 deg + if (systemSettings.temperatureInF) { + systemSettings.SleepTemp += 20; + if (systemSettings.SleepTemp > 580) + systemSettings.SleepTemp = 120; + } else { + systemSettings.SleepTemp += 10; + if (systemSettings.SleepTemp > 300) + systemSettings.SleepTemp = 50; + } } static void settings_displaySleepTemp(void) { - printShortDescription(1, 5); - OLED::printNumber(systemSettings.SleepTemp, 3); + printShortDescription(1, 5); + OLED::printNumber(systemSettings.SleepTemp, 3); } static void settings_setSleepTime(void) { - systemSettings.SleepTime++; // Go up 1 minute at a time - if (systemSettings.SleepTime >= 16) { - systemSettings.SleepTime = 0; // can't set time over 10 mins - } - // Remember that ^ is the time of no movement - if (PCBVersion == 3) - systemSettings.SleepTime = 0; // Disable sleep on no accel + systemSettings.SleepTime++; // Go up 1 minute at a time + if (systemSettings.SleepTime >= 16) { + systemSettings.SleepTime = 0; // can't set time over 10 mins + } + // Remember that ^ is the time of no movement + if (PCBVersion == 3) + systemSettings.SleepTime = 0; // Disable sleep on no accel } static void settings_displaySleepTime(void) { - printShortDescription(2, 5); - if (systemSettings.SleepTime == 0) { - OLED::print(OffString); - } else if (systemSettings.SleepTime < 6) { - OLED::printNumber(systemSettings.SleepTime * 10, 2); - OLED::drawChar('S'); - } else { - OLED::printNumber(systemSettings.SleepTime - 5, 2); - OLED::drawChar('M'); - } + printShortDescription(2, 5); + if (systemSettings.SleepTime == 0) { + OLED::print(OffString); + } else if (systemSettings.SleepTime < 6) { + OLED::printNumber(systemSettings.SleepTime * 10, 2); + OLED::drawChar('S'); + } else { + OLED::printNumber(systemSettings.SleepTime - 5, 2); + OLED::drawChar('M'); + } } static void settings_setShutdownTime(void) { - systemSettings.ShutdownTime++; - if (systemSettings.ShutdownTime > 60) { - systemSettings.ShutdownTime = 0; // wrap to off - } - if (PCBVersion == 3) - systemSettings.ShutdownTime = 0; // Disable shutdown on no accel + systemSettings.ShutdownTime++; + if (systemSettings.ShutdownTime > 60) { + systemSettings.ShutdownTime = 0; // wrap to off + } + if (PCBVersion == 3) + systemSettings.ShutdownTime = 0; // Disable shutdown on no accel } static void settings_displayShutdownTime(void) { - printShortDescription(3, 5); - if (systemSettings.ShutdownTime == 0) { - OLED::print(OffString); - } else { - OLED::printNumber(systemSettings.ShutdownTime, 2); - OLED::drawChar('M'); - } + printShortDescription(3, 5); + if (systemSettings.ShutdownTime == 0) { + OLED::print(OffString); + } else { + OLED::printNumber(systemSettings.ShutdownTime, 2); + OLED::drawChar('M'); + } } static void settings_setTempF(void) { - systemSettings.temperatureInF = !systemSettings.temperatureInF; - if (systemSettings.temperatureInF) { - // Change sleep, boost and soldering temps to the F equiv - // C to F == F= ( (C*9) +160)/5 - systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5; - systemSettings.SolderingTemp = - ((systemSettings.SolderingTemp * 9) + 160) / 5; - systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5; - } else { - // Change sleep, boost and soldering temps to the C equiv - // F->C == C = ((F-32)*5)/9 - systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9; - systemSettings.SolderingTemp = - ((systemSettings.SolderingTemp - 32) * 5) / 9; - systemSettings.SleepTemp = ((systemSettings.SleepTemp - 32) * 5) / 9; - } - // Rescale both to be multiples of 10 - systemSettings.BoostTemp = systemSettings.BoostTemp / 10; - systemSettings.BoostTemp *= 10; - systemSettings.SolderingTemp = systemSettings.SolderingTemp / 10; - systemSettings.SolderingTemp *= 10; - systemSettings.SleepTemp = systemSettings.SleepTemp / 10; - systemSettings.SleepTemp *= 10; + systemSettings.temperatureInF = !systemSettings.temperatureInF; + if (systemSettings.temperatureInF) { + // Change sleep, boost and soldering temps to the F equiv + // C to F == F= ( (C*9) +160)/5 + systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5; + systemSettings.SolderingTemp = + ((systemSettings.SolderingTemp * 9) + 160) / 5; + systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5; + } else { + // Change sleep, boost and soldering temps to the C equiv + // F->C == C = ((F-32)*5)/9 + systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9; + systemSettings.SolderingTemp = ((systemSettings.SolderingTemp - 32) * 5) + / 9; + systemSettings.SleepTemp = ((systemSettings.SleepTemp - 32) * 5) / 9; + } + // Rescale both to be multiples of 10 + systemSettings.BoostTemp = systemSettings.BoostTemp / 10; + systemSettings.BoostTemp *= 10; + systemSettings.SolderingTemp = systemSettings.SolderingTemp / 10; + systemSettings.SolderingTemp *= 10; + systemSettings.SleepTemp = systemSettings.SleepTemp / 10; + systemSettings.SleepTemp *= 10; } static void settings_displayTempF(void) { - printShortDescription(5, 7); + printShortDescription(5, 7); - OLED::drawChar((systemSettings.temperatureInF) ? 'F' : 'C'); + OLED::drawChar((systemSettings.temperatureInF) ? 'F' : 'C'); } static void settings_setSensitivity(void) { - systemSettings.sensitivity++; - systemSettings.sensitivity = systemSettings.sensitivity % 10; + systemSettings.sensitivity++; + systemSettings.sensitivity = systemSettings.sensitivity % 10; } static void settings_displaySensitivity(void) { - printShortDescription(4, 7); - OLED::printNumber(systemSettings.sensitivity, 1); + printShortDescription(4, 7); + OLED::printNumber(systemSettings.sensitivity, 1); } static void settings_setAdvancedSolderingScreens(void) { - systemSettings.detailedSoldering = !systemSettings.detailedSoldering; + systemSettings.detailedSoldering = !systemSettings.detailedSoldering; } static void settings_displayAdvancedSolderingScreens(void) { - printShortDescription(15, 7); + printShortDescription(15, 7); - OLED::drawCheckbox(systemSettings.detailedSoldering); + OLED::drawCheckbox(systemSettings.detailedSoldering); } static void settings_setAdvancedIDLEScreens(void) { - systemSettings.detailedIDLE = !systemSettings.detailedIDLE; + systemSettings.detailedIDLE = !systemSettings.detailedIDLE; } static void settings_displayAdvancedIDLEScreens(void) { - printShortDescription(6, 7); + printShortDescription(6, 7); - OLED::drawCheckbox(systemSettings.detailedIDLE); + OLED::drawCheckbox(systemSettings.detailedIDLE); } static void settings_setScrollSpeed(void) { - if (systemSettings.descriptionScrollSpeed == 0) - systemSettings.descriptionScrollSpeed = 1; - else - systemSettings.descriptionScrollSpeed = 0; + if (systemSettings.descriptionScrollSpeed == 0) + systemSettings.descriptionScrollSpeed = 1; + else + systemSettings.descriptionScrollSpeed = 0; } static void settings_displayScrollSpeed(void) { - printShortDescription(16, 7); - OLED::drawChar((systemSettings.descriptionScrollSpeed) ? SettingFastChar - : SettingSlowChar); + printShortDescription(16, 7); + OLED::drawChar( + (systemSettings.descriptionScrollSpeed) ? + SettingFastChar : SettingSlowChar); } static void settings_setDisplayRotation(void) { - systemSettings.OrientationMode++; - systemSettings.OrientationMode = systemSettings.OrientationMode % 3; - switch (systemSettings.OrientationMode) { - case 0: - OLED::setRotation(false); - break; - case 1: - OLED::setRotation(true); - break; - case 2: - // do nothing on auto - break; - default: - break; - } + systemSettings.OrientationMode++; + systemSettings.OrientationMode = systemSettings.OrientationMode % 3; + switch (systemSettings.OrientationMode) { + case 0: + OLED::setRotation(true); + break; + case 1: + OLED::setRotation(false); + break; + case 2: + // do nothing on auto + break; + default: + break; + } } static void settings_displayDisplayRotation(void) { - printShortDescription(7, 7); + printShortDescription(7, 7); - switch (systemSettings.OrientationMode) { - case 0: - OLED::drawChar(SettingRightChar); - break; - case 1: - OLED::drawChar(SettingLeftChar); - break; - case 2: - OLED::drawChar(SettingAutoChar); - break; - default: - OLED::drawChar(SettingRightChar); - break; - } + switch (systemSettings.OrientationMode) { + case 0: + OLED::drawChar(SettingRightChar); + break; + case 1: + OLED::drawChar(SettingLeftChar); + break; + case 2: + OLED::drawChar(SettingAutoChar); + break; + default: + OLED::drawChar(SettingRightChar); + break; + } } static void settings_setBoostModeEnabled(void) { - systemSettings.boostModeEnabled = !systemSettings.boostModeEnabled; + systemSettings.boostModeEnabled = !systemSettings.boostModeEnabled; } static void settings_displayBoostModeEnabled(void) { - printShortDescription(8, 7); + printShortDescription(8, 7); - OLED::drawCheckbox(systemSettings.boostModeEnabled); + OLED::drawCheckbox(systemSettings.boostModeEnabled); } static void settings_setBoostTemp(void) { - if (systemSettings.temperatureInF) { - systemSettings.BoostTemp += 20; // Go up 20F at a time - if (systemSettings.BoostTemp > 850) { - systemSettings.BoostTemp = 480; // loop back at 250 - } - } else { - systemSettings.BoostTemp += 10; // Go up 10C at a time - if (systemSettings.BoostTemp > 450) { - systemSettings.BoostTemp = 250; // loop back at 250 - } - } + if (systemSettings.temperatureInF) { + systemSettings.BoostTemp += 20; // Go up 20F at a time + if (systemSettings.BoostTemp > 850) { + systemSettings.BoostTemp = 480; // loop back at 250 + } + } else { + systemSettings.BoostTemp += 10; // Go up 10C at a time + if (systemSettings.BoostTemp > 450) { + systemSettings.BoostTemp = 250; // loop back at 250 + } + } } static void settings_displayBoostTemp(void) { - printShortDescription(9, 5); - OLED::printNumber(systemSettings.BoostTemp, 3); + printShortDescription(9, 5); + OLED::printNumber(systemSettings.BoostTemp, 3); } static void settings_setAutomaticStartMode(void) { - systemSettings.autoStartMode++; - systemSettings.autoStartMode %= 2; + systemSettings.autoStartMode++; + systemSettings.autoStartMode %= 2; } static void settings_displayAutomaticStartMode(void) { - printShortDescription(10, 7); - OLED::drawCheckbox(systemSettings.autoStartMode); + printShortDescription(10, 7); + OLED::drawCheckbox(systemSettings.autoStartMode); } static void settings_setCoolingBlinkEnabled(void) { - systemSettings.coolingTempBlink = !systemSettings.coolingTempBlink; + systemSettings.coolingTempBlink = !systemSettings.coolingTempBlink; } static void settings_displayCoolingBlinkEnabled(void) { - printShortDescription(11, 7); + printShortDescription(11, 7); - OLED::drawCheckbox(systemSettings.coolingTempBlink); + OLED::drawCheckbox(systemSettings.coolingTempBlink); } static void settings_setResetSettings(void) { - if (userConfirmation(SettingsResetWarning)) { - resetSettings(); + if (userConfirmation(SettingsResetWarning)) { + resetSettings(); - OLED::setFont(0); - OLED::setCursor(0, 0); - OLED::print("RESET OK"); - OLED::refresh(); + OLED::setFont(0); + OLED::setCursor(0, 0); + OLED::print("RESET OK"); + OLED::refresh(); - waitForButtonPressOrTimeout(200); // 2 second timeout - } + waitForButtonPressOrTimeout(200); // 2 second timeout + } } static void settings_displayResetSettings(void) { - printShortDescription(13, 7); + printShortDescription(13, 7); } static void settings_setTipModel(void) { - systemSettings.tipType++; - systemSettings.tipType %= (Tip_Custom + 1); // Wrap after custom + systemSettings.tipType++; + systemSettings.tipType %= (Tip_Custom + 1); // Wrap after custom } static void settings_displayTipModel(void) { - printShortDescription(17, 4); - // Print in small text the tip model - OLED::setFont(1); - // set the cursor - // Print the mfg - OLED::setCursor(40, 0); - if (systemSettings.tipType < Tip_MiniWare) { + printShortDescription(17, 4); + // Print in small text the tip model + OLED::setFont(1); + // set the cursor + // Print the mfg + OLED::setCursor(40, 0); + if (systemSettings.tipType < Tip_MiniWare) { #ifdef MODEL_TS100 - OLED::print("TS100"); + OLED::print("TS100"); #else - OLED::print("TS80"); + OLED::print("TS80"); #endif - } + } #ifdef MODEL_TS100 - else if (systemSettings.tipType < Tip_Hakko) { - OLED::print("HAKKO"); - } + else if (systemSettings.tipType < Tip_Hakko) { + OLED::print("HAKKO"); + } #endif - else if (systemSettings.tipType == Tip_Custom) { - OLED::print("User"); - } - OLED::setCursor(40, 8); + else if (systemSettings.tipType == Tip_Custom) { + OLED::print("User"); + } + OLED::setCursor(40, 8); #ifdef MODEL_TS100 - switch ((enum TipType)systemSettings.tipType) { - case TS_B2: - OLED::print(" B2 "); - break; - case TS_D24: - OLED::print(" D24 "); - break; - case TS_BC2: - OLED::print(" BC2 "); - break; - case TS_C1: - OLED::print(" C1 "); - break; - case HAKKO_BC2: - OLED::print(" BC2 "); - break; - case Tip_Custom: - OLED::print("Tuned"); - break; - default: - OLED::print("????"); - break; - } + switch ((enum TipType)systemSettings.tipType) { + case TS_B2: + OLED::print(" B2 "); + break; + case TS_D24: + OLED::print(" D24 "); + break; + case TS_BC2: + OLED::print(" BC2 "); + break; + case TS_C1: + OLED::print(" C1 "); + break; + case HAKKO_BC2: + OLED::print(" BC2 "); + break; + case Tip_Custom: + OLED::print("Tuned"); + break; + default: + OLED::print("????"); + break; + } #endif #ifdef MODEL_TS80 - // only 2 tips atm - switch ((enum TipType)systemSettings.tipType) { - case TS_B02: - OLED::print(" B02 "); - break; - case TS_D25: - OLED::print(" D25 "); - break; - case Tip_Custom: - OLED::print("Tuned"); - break; - default: - OLED::print("????"); - break; - } + // only 2 tips atm + switch ((enum TipType) systemSettings.tipType) { + case TS_B02: + OLED::print(" B02 "); + break; + case TS_D25: + OLED::print(" D25 "); + break; + case Tip_Custom: + OLED::print("Tuned"); + break; + default: + OLED::print("????"); + break; + } #endif } -static void calibration_displaySimpleCal(void) { printShortDescription(18, 5); } +static void calibration_displaySimpleCal(void) { + printShortDescription(18, 5); +} static void dotDelay() { - for (uint8_t i = 0; i < 20; i++) { - getTipRawTemp( - 1); // cycle through the filter a fair bit to ensure we're stable. - OLED::clearScreen(); - OLED::setCursor(0, 0); - for (uint8_t x = 0; x < i / 4; x++) OLED::print("."); - OLED::refresh(); - osDelay(50); - } + for (uint8_t i = 0; i < 20; i++) { + getTipRawTemp(1); // cycle through the filter a fair bit to ensure we're stable. + OLED::clearScreen(); + OLED::setCursor(0, 0); + for (uint8_t x = 0; x < i / 4; x++) + OLED::print("."); + OLED::refresh(); + osDelay(50); + } } static void setTipOffset() { - setCalibrationOffset(0); // turn off the current offset - dotDelay(); + setCalibrationOffset(0); // turn off the current offset + dotDelay(); - // If the thermocouple at the end of the tip, and the handle are at - // equalibrium, then the output should be zero, as there is no temperature - // differential. + // If the thermocouple at the end of the tip, and the handle are at + // equalibrium, then the output should be zero, as there is no temperature + // differential. - int32_t offset = 0; - for (uint8_t i = 0; i < 15; i++) { - offset += getTipRawTemp( - 1); // cycle through the filter a fair bit to ensure we're stable. - - OLED::clearScreen(); - OLED::setCursor(0, 0); - - for (uint8_t x = 0; x < i / 4; x++) OLED::print("."); - OLED::refresh(); - osDelay(200); - } - systemSettings.CalibrationOffset = offset / 15; - setCalibrationOffset(systemSettings.CalibrationOffset); // store the error - osDelay(100); + int32_t offset = 0; + for (uint8_t i = 0; i < 15; i++) { + offset += getTipRawTemp(1); + // cycle through the filter a fair bit to ensure we're stable. + OLED::clearScreen(); + OLED::setCursor(0, 0); + for (uint8_t x = 0; x < i / 4; x++) + OLED::print("."); + OLED::refresh(); + osDelay(333); + } + systemSettings.CalibrationOffset = offset / 15; + setCalibrationOffset(systemSettings.CalibrationOffset); // store the error + osDelay(100); } static void calibration_enterSimpleCal(void) { - // User has entered into the simple cal routine - if (userConfirmation(SettingsCalibrationWarning)) { - // User has confirmed their handle is at ambient - // So take the offset measurement - setTipOffset(); - // Next we want the user to put the tip into 100C water so we can calculate - // their tip's gain Gain is the m term from rise/run plot of raw readings vs - // (tip-handle) Thus we want to calculate - // ([TipRawHot-TipRawCold])/(ActualHot-HandleHot)-(ActualCold-HandleCold) - // Thus we first need to store -> - // TiprawCold,HandleCold,ActualCold==HandleCold -> RawTipCold - uint32_t RawTipCold = getTipRawTemp(0) * 10; - OLED::clearScreen(); - OLED::setCursor(0, 0); - OLED::setFont(1); - OLED::print("Please Insert Tip\nInto Boiling Water"); - OLED::refresh(); - osDelay(200); - waitForButtonPress(); - dotDelay(); // cycle the filter a bit - // Now take the three hot measurements - // Assume water is boiling at 100C - uint32_t RawTipHot = getTipRawTemp(0) * 10; - uint32_t HandleTempHot = getHandleTemperature() / 10; + // User has entered into the simple cal routine + if (userConfirmation(SettingsCalibrationWarning)) { + // User has confirmed their handle is at ambient + // So take the offset measurement + setTipOffset(); + // Next we want the user to put the tip into 100C water so we can calculate + // their tip's gain Gain is the m term from rise/run plot of raw readings vs + // (tip-handle) Thus we want to calculate + // ([TipRawHot-TipRawCold])/(ActualHot-HandleHot)-(ActualCold-HandleCold) + // Thus we first need to store -> + // TiprawCold,HandleCold,ActualCold==HandleCold -> RawTipCold + uint32_t RawTipCold = getTipRawTemp(0) * 10; + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::setFont(1); + OLED::print("Please Insert Tip\nInto Boiling Water"); + OLED::refresh(); + osDelay(200); + waitForButtonPress(); + dotDelay(); // cycle the filter a bit + // Now take the three hot measurements + // Assume water is boiling at 100C + uint32_t RawTipHot = getTipRawTemp(0) * 10; + uint32_t HandleTempHot = getHandleTemperature() / 10; - uint32_t gain = (RawTipHot - RawTipCold) / (100 - HandleTempHot); + uint32_t gain = (RawTipHot - RawTipCold) / (100 - HandleTempHot); - // Show this to the user - OLED::clearScreen(); - OLED::setCursor(0, 0); - OLED::print("Your G: "); - OLED::printNumber(gain, 6); - OLED::print("\n~= 120-140"); - OLED::refresh(); - osDelay(2000); - waitForButtonPress(); - OLED::clearScreen(); - OLED::setCursor(0, 0); - OLED::print("H: "); - OLED::printNumber(RawTipHot, 8); - OLED::setCursor(0, 8); - OLED::print("C: "); - OLED::printNumber(RawTipCold, 8); - OLED::refresh(); - osDelay(2000); - waitForButtonPress(); - } + // Show this to the user + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::print("Your G: "); + OLED::printNumber(gain, 6); + OLED::print("\n~= 120-140"); + OLED::refresh(); + osDelay(2000); + waitForButtonPress(); + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::print("H: "); + OLED::printNumber(RawTipHot, 8); + OLED::setCursor(0, 8); + OLED::print("C: "); + OLED::printNumber(RawTipCold, 8); + OLED::refresh(); + osDelay(2000); + waitForButtonPress(); + } } static void calibration_displayAdvancedCal(void) { - printShortDescription(19, 5); + printShortDescription(19, 5); } static void calibration_enterAdvancedCal(void) { //Advanced cal @@ -765,7 +743,7 @@ static void calibration_enterAdvancedCal(void) { while (exit == false) { //Set tip to 350C - setTipType(Tip_Custom,systemSettings.customTipGain); + setTipType(Tip_Custom, systemSettings.customTipGain); currentlyActiveTemperatureTarget = ctoTipMeasurement(350); //Check if user has pressed button to change the gain ButtonState buttons = getButtonState(); @@ -816,213 +794,237 @@ static void calibration_enterAdvancedCal(void) { //Provide the user the option to tune their own tip if custom is selected //If not only do single point tuning as per usual static void settings_setCalibrate(void) { - if (systemSettings.tipType == Tip_Custom) { - // Two types of calibration - // 1. Basic, idle temp + hot water (100C) - // 2. Advanced, 100C + 350C, we keep PID tracking to a temperature target - return gui_Menu(calibrationMenu); - } - // Else - // Ask user if handle is at the tip temperature - // Any error between handle and the tip will be a direct offset in the control - // loop + if (systemSettings.tipType == Tip_Custom) { + // Two types of calibration + // 1. Basic, idle temp + hot water (100C) + // 2. Advanced, 100C + 350C, we keep PID tracking to a temperature target + return gui_Menu(calibrationMenu); + } + // Else + // Ask user if handle is at the tip temperature + // Any error between handle and the tip will be a direct offset in the control + // loop - else if (userConfirmation(SettingsCalibrationWarning)) { - // User confirmed - // So we now perform the actual calculation - setTipOffset(); - } + else if (userConfirmation(SettingsCalibrationWarning)) { + // User confirmed + // So we now perform the actual calculation + setTipOffset(); + } } -static void settings_displayCalibrate(void) { printShortDescription(12, 5); } +static void settings_displayCalibrate(void) { + printShortDescription(12, 5); +} static void settings_setCalibrateVIN(void) { - // Jump to the voltage calibration subscreen - OLED::setFont(0); - OLED::clearScreen(); - OLED::setCursor(0, 0); + // Jump to the voltage calibration subscreen + OLED::setFont(0); + OLED::clearScreen(); + OLED::setCursor(0, 0); - for (;;) { - OLED::setCursor(0, 0); - OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2); - OLED::print("."); - OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1); - OLED::print("V"); + for (;;) { + OLED::setCursor(0, 0); + OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, + 2); + OLED::print("."); + OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, + 1); + OLED::print("V"); - ButtonState buttons = getButtonState(); - switch (buttons) { - case BUTTON_F_SHORT: - systemSettings.voltageDiv++; - break; + ButtonState buttons = getButtonState(); + switch (buttons) { + case BUTTON_F_SHORT: + systemSettings.voltageDiv++; + break; - case BUTTON_B_SHORT: - systemSettings.voltageDiv--; - break; + case BUTTON_B_SHORT: + systemSettings.voltageDiv--; + break; - case BUTTON_BOTH: - case BUTTON_F_LONG: - case BUTTON_B_LONG: - saveSettings(); - return; - break; - case BUTTON_NONE: - default: - break; - } + case BUTTON_BOTH: + case BUTTON_F_LONG: + case BUTTON_B_LONG: + saveSettings(); + return; + break; + case BUTTON_NONE: + default: + break; + } - OLED::refresh(); - osDelay(40); + OLED::refresh(); + osDelay(40); - // Cap to sensible values + // Cap to sensible values #ifdef MODEL_TS80 - if (systemSettings.voltageDiv < 500) { - systemSettings.voltageDiv = 500; - } else if (systemSettings.voltageDiv > 900) { - systemSettings.voltageDiv = 900; - } + if (systemSettings.voltageDiv < 500) { + systemSettings.voltageDiv = 500; + } else if (systemSettings.voltageDiv > 900) { + systemSettings.voltageDiv = 900; + } #else - if (systemSettings.voltageDiv < 360) { - systemSettings.voltageDiv = 360; - } else if (systemSettings.voltageDiv > 520) { - systemSettings.voltageDiv = 520; - } + if (systemSettings.voltageDiv < 360) { + systemSettings.voltageDiv = 360; + } else if (systemSettings.voltageDiv > 520) { + systemSettings.voltageDiv = 520; + } #endif - } + } } static void displayMenu(size_t index) { - // Call into the menu - OLED::setFont(1); - OLED::setCursor(0, 0); - // Draw title - OLED::print(SettingsMenuEntries[index]); - // Draw symbol - // 16 pixel wide image - OLED::drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index])); + // Call into the menu + OLED::setFont(1); + OLED::setCursor(0, 0); + // Draw title + OLED::print(SettingsMenuEntries[index]); + // Draw symbol + // 16 pixel wide image + OLED::drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index])); } -static void settings_displayCalibrateVIN(void) { printShortDescription(14, 5); } -static void settings_displaySolderingMenu(void) { displayMenu(0); } -static void settings_enterSolderingMenu(void) { gui_Menu(solderingMenu); } -static void settings_displayPowerMenu(void) { displayMenu(1); } -static void settings_enterPowerMenu(void) { gui_Menu(PowerMenu); } -static void settings_displayUIMenu(void) { displayMenu(2); } -static void settings_enterUIMenu(void) { gui_Menu(UIMenu); } -static void settings_displayAdvancedMenu(void) { displayMenu(3); } -static void settings_enterAdvancedMenu(void) { gui_Menu(advancedMenu); } +static void settings_displayCalibrateVIN(void) { + printShortDescription(14, 5); +} +static void settings_displaySolderingMenu(void) { + displayMenu(0); +} +static void settings_enterSolderingMenu(void) { + gui_Menu(solderingMenu); +} +static void settings_displayPowerMenu(void) { + displayMenu(1); +} +static void settings_enterPowerMenu(void) { + gui_Menu(PowerMenu); +} +static void settings_displayUIMenu(void) { + displayMenu(2); +} +static void settings_enterUIMenu(void) { + gui_Menu(UIMenu); +} +static void settings_displayAdvancedMenu(void) { + displayMenu(3); +} +static void settings_enterAdvancedMenu(void) { + gui_Menu(advancedMenu); +} void gui_Menu(const menuitem* menu) { - // Draw the settings menu and provide iteration support etc - uint8_t currentScreen = 0; - uint32_t autoRepeatTimer = 0; - uint8_t autoRepeatAcceleration = 0; - bool earlyExit = false; - uint32_t descriptionStart = 0; - int16_t lastOffset = -1; - bool lcdRefresh = true; - ButtonState lastButtonState = BUTTON_NONE; + // Draw the settings menu and provide iteration support etc + uint8_t currentScreen = 0; + uint32_t autoRepeatTimer = 0; + uint8_t autoRepeatAcceleration = 0; + bool earlyExit = false; + uint32_t descriptionStart = 0; + int16_t lastOffset = -1; + bool lcdRefresh = true; + ButtonState lastButtonState = BUTTON_NONE; - while ((menu[currentScreen].draw.func != NULL) && earlyExit == false) { - OLED::setFont(0); - OLED::setCursor(0, 0); - // If the user has hesitated for >=3 seconds, show the long text - // Otherwise "draw" the option - if ((xTaskGetTickCount() - lastButtonTime < 300) || - menu[currentScreen].description == NULL) { - OLED::clearScreen(); - menu[currentScreen].draw.func(); - lastOffset = -1; - lcdRefresh = true; - } else { - // Draw description - if (descriptionStart == 0) descriptionStart = xTaskGetTickCount(); - // lower the value - higher the speed - int16_t descriptionWidth = - FONT_12_WIDTH * (strlen(menu[currentScreen].description) + 7); - int16_t descriptionOffset = - ((xTaskGetTickCount() - descriptionStart) / - (systemSettings.descriptionScrollSpeed == 1 ? 1 : 2)); - descriptionOffset %= descriptionWidth; // Roll around at the end + while ((menu[currentScreen].draw.func != NULL) && earlyExit == false) { + OLED::setFont(0); + OLED::setCursor(0, 0); + // If the user has hesitated for >=3 seconds, show the long text + // Otherwise "draw" the option + if ((xTaskGetTickCount() - lastButtonTime < 300) + || menu[currentScreen].description == NULL) { + OLED::clearScreen(); + menu[currentScreen].draw.func(); + lastOffset = -1; + lcdRefresh = true; + } else { + // Draw description + if (descriptionStart == 0) + descriptionStart = xTaskGetTickCount(); + // lower the value - higher the speed + int16_t descriptionWidth = + FONT_12_WIDTH * (strlen(menu[currentScreen].description) + 7); + int16_t descriptionOffset = + ((xTaskGetTickCount() - descriptionStart) + / (systemSettings.descriptionScrollSpeed == 1 ? + 1 : 2)); + descriptionOffset %= descriptionWidth; // Roll around at the end - if (lastOffset != descriptionOffset) { - OLED::clearScreen(); + if (lastOffset != descriptionOffset) { + OLED::clearScreen(); - //^ Rolling offset based on time - OLED::setCursor((OLED_WIDTH - descriptionOffset), 0); - OLED::print(menu[currentScreen].description); - lastOffset = descriptionOffset; - lcdRefresh = true; - } - } + //^ Rolling offset based on time + OLED::setCursor((OLED_WIDTH - descriptionOffset), 0); + OLED::print(menu[currentScreen].description); + lastOffset = descriptionOffset; + lcdRefresh = true; + } + } - ButtonState buttons = getButtonState(); + ButtonState buttons = getButtonState(); - if (buttons != lastButtonState) { - autoRepeatAcceleration = 0; - lastButtonState = buttons; - } + if (buttons != lastButtonState) { + autoRepeatAcceleration = 0; + lastButtonState = buttons; + } - switch (buttons) { - case BUTTON_BOTH: - earlyExit = true; // will make us exit next loop - descriptionStart = 0; - break; - case BUTTON_F_SHORT: - // increment - if (descriptionStart == 0) { - if (menu[currentScreen].incrementHandler.func != NULL) - menu[currentScreen].incrementHandler.func(); - else - earlyExit = true; - } else - descriptionStart = 0; - break; - case BUTTON_B_SHORT: - if (descriptionStart == 0) - currentScreen++; - else - descriptionStart = 0; - break; - case BUTTON_F_LONG: - if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > - PRESS_ACCEL_INTERVAL_MAX) { - menu[currentScreen].incrementHandler.func(); - autoRepeatTimer = xTaskGetTickCount(); - descriptionStart = 0; + switch (buttons) { + case BUTTON_BOTH: + earlyExit = true; // will make us exit next loop + descriptionStart = 0; + break; + case BUTTON_F_SHORT: + // increment + if (descriptionStart == 0) { + if (menu[currentScreen].incrementHandler.func != NULL) + menu[currentScreen].incrementHandler.func(); + else + earlyExit = true; + } else + descriptionStart = 0; + break; + case BUTTON_B_SHORT: + if (descriptionStart == 0) + currentScreen++; + else + descriptionStart = 0; + break; + case BUTTON_F_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > + PRESS_ACCEL_INTERVAL_MAX) { + menu[currentScreen].incrementHandler.func(); + autoRepeatTimer = xTaskGetTickCount(); + descriptionStart = 0; - autoRepeatAcceleration += PRESS_ACCEL_STEP; - } - break; - case BUTTON_B_LONG: - if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > - PRESS_ACCEL_INTERVAL_MAX) { - currentScreen++; - autoRepeatTimer = xTaskGetTickCount(); - descriptionStart = 0; + autoRepeatAcceleration += PRESS_ACCEL_STEP; + } + break; + case BUTTON_B_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > + PRESS_ACCEL_INTERVAL_MAX) { + currentScreen++; + autoRepeatTimer = xTaskGetTickCount(); + descriptionStart = 0; - autoRepeatAcceleration += PRESS_ACCEL_STEP; - } - break; - case BUTTON_NONE: - default: - break; - } + autoRepeatAcceleration += PRESS_ACCEL_STEP; + } + break; + case BUTTON_NONE: + default: + break; + } - if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < - PRESS_ACCEL_INTERVAL_MIN) { - autoRepeatAcceleration = - PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; - } + if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < + PRESS_ACCEL_INTERVAL_MIN) { + autoRepeatAcceleration = + PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; + } - if (lcdRefresh) { - OLED::refresh(); // update the LCD - osDelay(40); - lcdRefresh = false; - } - } + if (lcdRefresh) { + OLED::refresh(); // update the LCD + osDelay(40); + lcdRefresh = false; + } + } } void enterSettingsMenu() { - gui_Menu(rootSettingsMenu); // Call the root menu - saveSettings(); + gui_Menu(rootSettingsMenu); // Call the root menu + saveSettings(); } diff --git a/workspace/TS100/src/hardware.c b/workspace/TS100/src/hardware.c index 9b281cf2..32b55335 100644 --- a/workspace/TS100/src/hardware.c +++ b/workspace/TS100/src/hardware.c @@ -12,7 +12,6 @@ volatile uint16_t PWMSafetyTimer = 0; volatile int16_t CalibrationTempOffset = 0; uint16_t tipGainCalValue = 0; -uint16_t lookupTipDefaultCalValue(enum TipType tipID); void setTipType(enum TipType tipType, uint8_t manualCalGain) { if (manualCalGain) tipGainCalValue = manualCalGain; @@ -171,14 +170,14 @@ uint8_t QCMode = 0; uint8_t QCTries = 0; void seekQC(int16_t Vx10,uint16_t divisor) { if (QCMode == 5) - startQC(divisor); + startQC(divisor); if (QCMode == 0) - return; // NOT connected to a QC Charger + return; // NOT connected to a QC Charger if (Vx10 < 50) - return; + return; if(Vx10>130) - Vx10=130;//Cap max value at 13V + Vx10=130;//Cap max value at 13V // Seek the QC to the Voltage given if this adapter supports continuous mode // try and step towards the wanted value @@ -250,7 +249,7 @@ void startQC(uint16_t divisor) { // negotiating as someone is feeding in hv uint16_t vin = getInputVoltageX10(divisor); if (vin > 150) - return; // Over voltage + return;// Over voltage if (vin > 100) { QCMode = 1; // ALready at ~12V return; @@ -292,7 +291,7 @@ void startQC(uint16_t divisor) { } // 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); @@ -312,7 +311,7 @@ void startQC(uint16_t divisor) { for (uint8_t i = 0; i < 10; i++) { if (getInputVoltageX10(divisor) > 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); @@ -323,14 +322,14 @@ void startQC(uint16_t divisor) { QCMode = 5; QCTries++; if (QCTries > 10) // 10 goes to get it going - QCMode = 0; + QCMode = 0; } else { // no QC QCMode = 0; } if (QCTries > 10) - QCMode = 0; + QCMode = 0; } // Get tip resistance in milliohms uint32_t calculateTipR(uint8_t useFilter) { @@ -344,7 +343,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(); @@ -358,8 +357,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) { @@ -377,7 +376,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; @@ -385,10 +384,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; } } @@ -399,26 +398,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; } @@ -430,9 +429,10 @@ uint8_t getTipPWM() { void setTipPWM(uint8_t pulse) { PWMSafetyTimer = 2; // This is decremented in the handler for PWM so that the tip pwm is // disabled if the PID task is not scheduled often enough. - if (pulse > 100) - pulse = 100; - + if (pulse > 255) + pulse = 255; + if (pulse == 0) // Need to have some pulse to keep the PID controller moving forward as these end of cycle completions move the thread along + pulse = 1; pendingPWM = pulse; } diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index 94599d85..9d89efeb 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -259,34 +259,37 @@ static void gui_drawBatteryIcon() { // User is on a lithium battery // we need to calculate which of the 10 levels they are on uint8_t cellCount = systemSettings.cutoutSetting + 2; - uint16_t cellV = getInputVoltageX10(systemSettings.voltageDiv) / cellCount; + uint16_t cellV = getInputVoltageX10(systemSettings.voltageDiv) + / cellCount; // Should give us approx cell voltage X10 // Range is 42 -> 33 = 9 steps therefore we will use battery 1-10 - if (cellV < 33) cellV = 33; - cellV -= 33;// Should leave us a number of 0-9 - if (cellV > 9) cellV = 9; + if (cellV < 33) + cellV = 33; + cellV -= 33; // Should leave us a number of 0-9 + if (cellV > 9) + cellV = 9; OLED::drawBattery(cellV + 1); } else - OLED::drawSymbol(15); // Draw the DC Logo + OLED::drawSymbol(15); // Draw the DC Logo #else - // On TS80 we replace this symbol with the voltage we are operating on - // If <9V then show single digit, if not show duals - uint8_t V = getInputVoltageX10(systemSettings.voltageDiv); - if (V % 10 >= 5) - V = V / 10 + 1; // round up - else - V = V / 10; - if (V >= 10) { - int16_t xPos = OLED::getCursorX(); - OLED::setFont(1); - 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); - } + // On TS80 we replace this symbol with the voltage we are operating on + // If <9V then show single digit, if not show duals + uint8_t V = getInputVoltageX10(systemSettings.voltageDiv); + if (V % 10 >= 5) + V = V / 10 + 1;// round up + else + V = V / 10; + if (V >= 10) { + int16_t xPos = OLED::getCursorX(); + OLED::setFont(1); + 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); + } #endif } static void gui_solderingTempAdjust() { @@ -309,7 +312,7 @@ static void gui_solderingTempAdjust() { // exit return; break; - case BUTTON_F_LONG: + case BUTTON_B_LONG: if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { systemSettings.SolderingTemp -= 10; // sub 10 @@ -317,7 +320,7 @@ static void gui_solderingTempAdjust() { autoRepeatAcceleration += PRESS_ACCEL_STEP; } break; - case BUTTON_B_LONG: + case BUTTON_F_LONG: if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { systemSettings.SolderingTemp += 10; @@ -325,10 +328,10 @@ static void gui_solderingTempAdjust() { autoRepeatAcceleration += PRESS_ACCEL_STEP; } break; - case BUTTON_B_SHORT: + case BUTTON_F_SHORT: systemSettings.SolderingTemp += 10; // add 10 break; - case BUTTON_F_SHORT: + case BUTTON_B_SHORT: systemSettings.SolderingTemp -= 10; // sub 10 break; default: @@ -355,7 +358,11 @@ static void gui_solderingTempAdjust() { if (xTaskGetTickCount() - lastChange > 200) return; // exit if user just doesn't press anything for a bit +#ifdef MODEL_TS80 + if (!OLED::getRotation()) +#else if (OLED::getRotation()) +#endif OLED::drawChar('-'); else OLED::drawChar('+'); @@ -367,7 +374,11 @@ static void gui_solderingTempAdjust() { else OLED::drawSymbol(1); OLED::drawChar(' '); +#ifdef MODEL_TS80 + if (!OLED::getRotation()) +#else if (OLED::getRotation()) +#endif OLED::drawChar('+'); else OLED::drawChar('-'); @@ -393,7 +404,8 @@ static int gui_SolderingSleepingMode() { || (xTaskGetTickCount() - lastButtonTime < 100)) return 0; // user moved or pressed a button, go back to soldering #ifdef MODEL_TS100 - if (checkVoltageForExit()) return 1; // return non-zero on error + if (checkVoltageForExit()) + return 1; // return non-zero on error #endif if (systemSettings.temperatureInF) { currentlyActiveTemperatureTarget = ftoTipMeasurement( @@ -654,9 +666,9 @@ void showVersion(void) { OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) OLED::setFont(1); // small font #ifdef MODEL_TS100 - OLED::print((char *)"V2.06 TS100"); // Print version number + OLED::print((char *) "V2.06 TS100"); // Print version number #else - OLED::print((char *) "V2.06 TS80"); // Print version number + OLED::print((char *) "V2.06 TS80"); // Print version number #endif OLED::setCursor(0, 8); // second line OLED::print(HEADERS[screen]); @@ -724,7 +736,7 @@ void startGUITask(void const *argument __unused) { bool buttonLockout = false; bool tempOnDisplay = false; getTipRawTemp(2); // reset filter - OLED::setRotation(systemSettings.OrientationMode & 1); + OLED::setRotation(!(systemSettings.OrientationMode & 1)); uint32_t ticks = xTaskGetTickCount(); ticks += 400; // 4 seconds from now while (xTaskGetTickCount() < ticks) { @@ -784,11 +796,11 @@ 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 - seekQC(idealQCVoltage,systemSettings.voltageDiv); + //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 + seekQC(idealQCVoltage,systemSettings.voltageDiv); #endif gui_solderingMode(0); // enter soldering mode buttonLockout = true; @@ -850,7 +862,7 @@ void startGUITask(void const *argument __unused) { #ifdef MODEL_TS80 if (!OLED::getRotation()) { #else - if (OLED::getRotation()) { + if (OLED::getRotation()) { #endif OLED::drawArea(12, 0, 84, 16, idleScreenBG); OLED::setCursor(0, 0); @@ -869,7 +881,7 @@ void startGUITask(void const *argument __unused) { // draw temp over the start soldering button // Location changes on screen rotation #ifdef MODEL_TS80 - if (!OLED::getRotation()) { + if (!OLED::getRotation()) { #else if (OLED::getRotation()) { #endif @@ -908,11 +920,11 @@ void startPIDTask(void const *argument __unused) { */ setTipPWM(0); // disable the output driver if the output is set to be off #ifdef MODEL_TS100 - for (uint8_t i = 0; i < 50; i++) { - osDelay(10); - getTipRawTemp(1); // cycle up the tip temp filter - HAL_IWDG_Refresh(&hiwdg); - } + for (uint8_t i = 0; i < 50; i++) { + osDelay(10); + getTipRawTemp(1); // cycle up the tip temp filter + HAL_IWDG_Refresh(&hiwdg); + } #else // On the TS80 we can measure the tip resistance before cycling the filter a // bit @@ -1009,20 +1021,20 @@ void startPIDTask(void const *argument __unused) { } #define MOVFilter 8 void startMOVTask(void const *argument __unused) { - OLED::setRotation(false); + OLED::setRotation(true); #ifdef MODEL_TS80 startQC(systemSettings.voltageDiv); while (idealQCVoltage == 0) - osDelay(20); // To ensure we return after idealQCVoltage is setup + osDelay(20); // To ensure we return after idealQCVoltage is setup - seekQC(idealQCVoltage,systemSettings.voltageDiv); // this will move the QC output to the preferred voltage to start with + seekQC(idealQCVoltage,systemSettings.voltageDiv);// this will move the QC output to the preferred voltage to start with #else osDelay(250); // wait for accelerometer to stabilize #endif - OLED::setRotation(systemSettings.OrientationMode & 1); + OLED::setRotation(!(systemSettings.OrientationMode & 1)); lastMovementTime = 0; int16_t datax[MOVFilter] = { 0 }; int16_t datay[MOVFilter] = { 0 }; @@ -1102,9 +1114,9 @@ void startMOVTask(void const *argument __unused) { osDelay(100); // Slow down update rate #ifdef MODEL_TS80 - if (currentlyActiveTemperatureTarget) { - seekQC(idealQCVoltage,systemSettings.voltageDiv); // Run the QC seek again to try and compensate for cable V drop - } + if (currentlyActiveTemperatureTarget) { + seekQC(idealQCVoltage,systemSettings.voltageDiv); // Run the QC seek again to try and compensate for cable V drop + } #endif } } diff --git a/workspace/TS100A/.cproject b/workspace/TS100A/.cproject index e652f4fe..3f045f55 100644 --- a/workspace/TS100A/.cproject +++ b/workspace/TS100A/.cproject @@ -50,6 +50,7 @@