Drivers + Threads
This commit is contained in:
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Buttons.c
|
||||
*
|
||||
* Created on: 29 May 2020
|
||||
* Author: Ralim
|
||||
*/
|
||||
#include <Buttons.hpp>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "gui.hpp"
|
||||
uint32_t lastButtonTime = 0;
|
||||
|
||||
ButtonState getButtonState() {
|
||||
/*
|
||||
* Read in the buttons and then determine if a state change needs to occur
|
||||
*/
|
||||
|
||||
/*
|
||||
* If the previous state was 00 Then we want to latch the new state if
|
||||
* different & update time
|
||||
* If the previous state was !00 Then we want to search if we trigger long
|
||||
* press (buttons still down), or if release we trigger press
|
||||
* (downtime>filter)
|
||||
*/
|
||||
static uint8_t previousState = 0;
|
||||
static uint32_t previousStateChange = 0;
|
||||
const uint16_t timeout = 40;
|
||||
uint8_t currentState;
|
||||
currentState = (getButtonA()) << 0;
|
||||
currentState |= (getButtonB()) << 1;
|
||||
|
||||
if (currentState)
|
||||
lastButtonTime = xTaskGetTickCount();
|
||||
if (currentState == previousState) {
|
||||
if (currentState == 0)
|
||||
return BUTTON_NONE;
|
||||
if ((xTaskGetTickCount() - previousStateChange) > timeout) {
|
||||
// User has been holding the button down
|
||||
// We want to send a button is held message
|
||||
if (currentState == 0x01)
|
||||
return BUTTON_F_LONG;
|
||||
else if (currentState == 0x02)
|
||||
return BUTTON_B_LONG;
|
||||
else
|
||||
return BUTTON_NONE; // Both being held case, we dont long hold this
|
||||
} else
|
||||
return BUTTON_NONE;
|
||||
} else {
|
||||
// A change in button state has occurred
|
||||
ButtonState retVal = BUTTON_NONE;
|
||||
if (currentState) {
|
||||
// User has pressed a button down (nothing done on down)
|
||||
if (currentState != previousState) {
|
||||
// There has been a change in the button states
|
||||
// If there is a rising edge on one of the buttons from double press we
|
||||
// want to mask that out As users are having issues with not release
|
||||
// both at once
|
||||
if (previousState == 0x03)
|
||||
currentState = 0x03;
|
||||
}
|
||||
} else {
|
||||
// User has released buttons
|
||||
// If they previously had the buttons down we want to check if they were <
|
||||
// long hold and trigger a press
|
||||
if ((xTaskGetTickCount() - previousStateChange) < timeout) {
|
||||
// The user didn't hold the button for long
|
||||
// So we send button press
|
||||
|
||||
if (previousState == 0x01)
|
||||
retVal = BUTTON_F_SHORT;
|
||||
else if (previousState == 0x02)
|
||||
retVal = BUTTON_B_SHORT;
|
||||
else
|
||||
retVal = BUTTON_BOTH; // Both being held case
|
||||
}
|
||||
}
|
||||
previousState = currentState;
|
||||
previousStateChange = xTaskGetTickCount();
|
||||
return retVal;
|
||||
}
|
||||
return BUTTON_NONE;
|
||||
}
|
||||
|
||||
void waitForButtonPress() {
|
||||
// we are just lazy and sleep until user confirms button press
|
||||
// This also eats the button press event!
|
||||
ButtonState buttons = getButtonState();
|
||||
while (buttons) {
|
||||
buttons = getButtonState();
|
||||
GUIDelay();
|
||||
}
|
||||
while (!buttons) {
|
||||
buttons = getButtonState();
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
|
||||
void waitForButtonPressOrTimeout(uint32_t timeout) {
|
||||
timeout += xTaskGetTickCount();
|
||||
// calculate the exit point
|
||||
|
||||
ButtonState buttons = getButtonState();
|
||||
while (buttons) {
|
||||
buttons = getButtonState();
|
||||
GUIDelay();
|
||||
if (xTaskGetTickCount() > timeout)
|
||||
return;
|
||||
}
|
||||
while (!buttons) {
|
||||
buttons = getButtonState();
|
||||
GUIDelay();
|
||||
if (xTaskGetTickCount() > timeout)
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,809 +0,0 @@
|
||||
/*
|
||||
* GUIThread.cpp
|
||||
*
|
||||
* Created on: 19 Aug 2019
|
||||
* Author: ralim
|
||||
*/
|
||||
#include <MMA8652FC.hpp>
|
||||
#include <gui.hpp>
|
||||
#include <main.hpp>
|
||||
#include "LIS2DH12.hpp"
|
||||
#include <history.hpp>
|
||||
#include <power.hpp>
|
||||
#include "Settings.h"
|
||||
#include "Translation.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "stdlib.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "string.h"
|
||||
#include "TipThermoModel.h"
|
||||
#include "unit.h"
|
||||
#include "../../configuration.h"
|
||||
#include "Buttons.hpp"
|
||||
extern uint8_t PCBVersion;
|
||||
// File local variables
|
||||
extern uint32_t currentTempTargetDegC;
|
||||
extern uint8_t accelInit;
|
||||
extern uint32_t lastMovementTime;
|
||||
extern int16_t idealQCVoltage;
|
||||
extern osThreadId GUITaskHandle;
|
||||
extern osThreadId MOVTaskHandle;
|
||||
extern osThreadId PIDTaskHandle;
|
||||
|
||||
// TODO: express time constants in terms of dividends of portTICK_RATE_MS
|
||||
|
||||
#define MOVEMENT_INACTIVITY_TIME 6000
|
||||
#define BUTTON_INACTIVITY_TIME 6000
|
||||
|
||||
static uint16_t min(uint16_t a, uint16_t b) {
|
||||
if (a > b)
|
||||
return b;
|
||||
else
|
||||
return a;
|
||||
}
|
||||
|
||||
void printVoltage() {
|
||||
uint32_t volt = getInputVoltageX10(systemSettings.voltageDiv, 0);
|
||||
OLED::printNumber(volt / 10, 2);
|
||||
OLED::print(SymbolDot);
|
||||
OLED::printNumber(volt % 10, 1);
|
||||
}
|
||||
void GUIDelay() {
|
||||
// Called in all UI looping tasks,
|
||||
// This limits the re-draw rate to the LCD and also lets the DMA run
|
||||
// As the gui task can very easily fill this bus with transactions, which will
|
||||
// prevent the movement detection from running
|
||||
osDelay(50);
|
||||
}
|
||||
void gui_drawTipTemp(bool symbol) {
|
||||
// Draw tip temp handling unit conversion & tolerance near setpoint
|
||||
uint16_t Temp = 0;
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
Temp = TipThermoModel::getTipInF();
|
||||
else
|
||||
#endif
|
||||
Temp = TipThermoModel::getTipInC();
|
||||
|
||||
OLED::printNumber(Temp, 3); // Draw the tip temp out finally
|
||||
if (symbol) {
|
||||
if (OLED::getFont() == 0) {
|
||||
//Big font, can draw nice symbols
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
OLED::drawSymbol(0);
|
||||
else
|
||||
#endif
|
||||
OLED::drawSymbol(1);
|
||||
} else {
|
||||
//Otherwise fall back to chars
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
OLED::print(SymbolDegF);
|
||||
else
|
||||
#endif
|
||||
OLED::print(SymbolDegC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef MODEL_TS100
|
||||
// returns true if undervoltage has occured
|
||||
static bool checkVoltageForExit() {
|
||||
uint16_t v = getInputVoltageX10(systemSettings.voltageDiv, 0);
|
||||
|
||||
//Dont check for first 1.5 seconds while the ADC stabilizes and the DMA fills the buffer
|
||||
if (xTaskGetTickCount() > 150) {
|
||||
if ((v < lookupVoltageLevel(systemSettings.cutoutSetting))) {
|
||||
GUIDelay();
|
||||
OLED::clearScreen();
|
||||
OLED::setCursor(0, 0);
|
||||
if (systemSettings.detailedSoldering) {
|
||||
OLED::setFont(1);
|
||||
OLED::print(UndervoltageString);
|
||||
OLED::setCursor(0, 8);
|
||||
OLED::print(InputVoltageString);
|
||||
printVoltage();
|
||||
OLED::print(SymbolVolts);
|
||||
|
||||
} else {
|
||||
OLED::setFont(0);
|
||||
OLED::print(UVLOWarningString);
|
||||
}
|
||||
|
||||
OLED::refresh();
|
||||
currentTempTargetDegC = 0;
|
||||
waitForButtonPress();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
static void gui_drawBatteryIcon() {
|
||||
#ifdef MODEL_TS100
|
||||
if (systemSettings.cutoutSetting) {
|
||||
// User is on a lithium battery
|
||||
// we need to calculate which of the 10 levels they are on
|
||||
uint8_t cellCount = systemSettings.cutoutSetting + 2;
|
||||
uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0)
|
||||
/ 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;
|
||||
OLED::drawBattery(cellV + 1);
|
||||
} else
|
||||
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, 0);
|
||||
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() {
|
||||
uint32_t lastChange = xTaskGetTickCount();
|
||||
currentTempTargetDegC = 0;
|
||||
uint32_t autoRepeatTimer = 0;
|
||||
uint8_t autoRepeatAcceleration = 0;
|
||||
for (;;) {
|
||||
OLED::setCursor(0, 0);
|
||||
OLED::clearScreen();
|
||||
OLED::setFont(0);
|
||||
ButtonState buttons = getButtonState();
|
||||
if (buttons)
|
||||
lastChange = xTaskGetTickCount();
|
||||
switch (buttons) {
|
||||
case BUTTON_NONE:
|
||||
// stay
|
||||
break;
|
||||
case BUTTON_BOTH:
|
||||
// exit
|
||||
return;
|
||||
break;
|
||||
case BUTTON_B_LONG:
|
||||
if (xTaskGetTickCount() - autoRepeatTimer
|
||||
+ autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if(systemSettings.ReverseButtonTempChangeEnabled) {
|
||||
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
|
||||
} else systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
|
||||
|
||||
autoRepeatTimer = xTaskGetTickCount();
|
||||
autoRepeatAcceleration += PRESS_ACCEL_STEP;
|
||||
}
|
||||
break;
|
||||
case BUTTON_B_SHORT:
|
||||
if(systemSettings.ReverseButtonTempChangeEnabled) {
|
||||
systemSettings.SolderingTemp += systemSettings.TempChangeShortStep;
|
||||
} else systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep;
|
||||
break;
|
||||
case BUTTON_F_LONG:
|
||||
if (xTaskGetTickCount() - autoRepeatTimer
|
||||
+ autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if(systemSettings.ReverseButtonTempChangeEnabled) {
|
||||
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
|
||||
} else systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
|
||||
autoRepeatTimer = xTaskGetTickCount();
|
||||
autoRepeatAcceleration += PRESS_ACCEL_STEP;
|
||||
}
|
||||
break;
|
||||
case BUTTON_F_SHORT:
|
||||
if(systemSettings.ReverseButtonTempChangeEnabled) {
|
||||
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10
|
||||
} else systemSettings.SolderingTemp += systemSettings.TempChangeShortStep; // add 10
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration)
|
||||
< PRESS_ACCEL_INTERVAL_MIN) {
|
||||
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX
|
||||
- PRESS_ACCEL_INTERVAL_MIN;
|
||||
}
|
||||
// constrain between 10-450 C
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF) {
|
||||
if (systemSettings.SolderingTemp > 850)
|
||||
systemSettings.SolderingTemp = 850;
|
||||
if (systemSettings.SolderingTemp < 60)
|
||||
systemSettings.SolderingTemp = 60;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (systemSettings.SolderingTemp > 450)
|
||||
systemSettings.SolderingTemp = 450;
|
||||
if (systemSettings.SolderingTemp < 10)
|
||||
systemSettings.SolderingTemp = 10;
|
||||
}
|
||||
|
||||
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::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus:SymbolMinus);
|
||||
} else {
|
||||
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus:SymbolPlus);
|
||||
}
|
||||
|
||||
|
||||
OLED::print(SymbolSpace);
|
||||
OLED::printNumber(systemSettings.SolderingTemp, 3);
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
OLED::drawSymbol(0);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
OLED::drawSymbol(1);
|
||||
}
|
||||
OLED::print(SymbolSpace);
|
||||
#ifdef MODEL_TS80
|
||||
if (!OLED::getRotation()) {
|
||||
#else
|
||||
if (OLED::getRotation()) {
|
||||
#endif
|
||||
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus:SymbolPlus);
|
||||
} else {
|
||||
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus:SymbolMinus);
|
||||
}
|
||||
OLED::refresh();
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
|
||||
static int gui_SolderingSleepingMode(bool stayOff) {
|
||||
// Drop to sleep temperature and display until movement or button press
|
||||
|
||||
for (;;) {
|
||||
ButtonState buttons = getButtonState();
|
||||
if (buttons)
|
||||
return 0;
|
||||
if ((xTaskGetTickCount() > 100)
|
||||
&& ((accelInit && (xTaskGetTickCount() - lastMovementTime < 100))
|
||||
|| (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
|
||||
#endif
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF) {
|
||||
currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(
|
||||
min(systemSettings.SleepTemp,
|
||||
systemSettings.SolderingTemp));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
currentTempTargetDegC = stayOff ? 0 : min(systemSettings.SleepTemp,
|
||||
systemSettings.SolderingTemp);
|
||||
}
|
||||
// draw the lcd
|
||||
uint16_t tipTemp;
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
tipTemp = TipThermoModel::getTipInF();
|
||||
else
|
||||
#endif
|
||||
{
|
||||
tipTemp = TipThermoModel::getTipInC();
|
||||
}
|
||||
|
||||
OLED::clearScreen();
|
||||
OLED::setCursor(0, 0);
|
||||
if (systemSettings.detailedSoldering) {
|
||||
OLED::setFont(1);
|
||||
OLED::print(SleepingAdvancedString);
|
||||
OLED::setCursor(0, 8);
|
||||
OLED::print(SleepingTipAdvancedString);
|
||||
OLED::printNumber(tipTemp, 3);
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
OLED::print(SymbolDegF);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
OLED::print(SymbolDegC);
|
||||
}
|
||||
|
||||
OLED::print(SymbolSpace);
|
||||
printVoltage();
|
||||
OLED::print(SymbolVolts);
|
||||
} else {
|
||||
OLED::setFont(0);
|
||||
OLED::print(SleepingSimpleString);
|
||||
OLED::printNumber(tipTemp, 3);
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
OLED::drawSymbol(0);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
OLED::drawSymbol(1);
|
||||
}
|
||||
}
|
||||
if (systemSettings.ShutdownTime) // only allow shutdown exit if time > 0
|
||||
if (lastMovementTime)
|
||||
if (((uint32_t) (xTaskGetTickCount() - lastMovementTime))
|
||||
> (uint32_t) (systemSettings.ShutdownTime * 60 * 100)) {
|
||||
// shutdown
|
||||
currentTempTargetDegC = 0;
|
||||
return 1; // we want to exit soldering mode
|
||||
}
|
||||
OLED::refresh();
|
||||
GUIDelay();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void display_countdown(int sleepThres) {
|
||||
/*
|
||||
* Print seconds or minutes (if > 99 seconds) until sleep
|
||||
* mode is triggered.
|
||||
*/
|
||||
int lastEventTime =
|
||||
lastButtonTime < lastMovementTime ?
|
||||
lastMovementTime : lastButtonTime;
|
||||
int downCount = sleepThres - xTaskGetTickCount() + lastEventTime;
|
||||
if (downCount > 9900) {
|
||||
OLED::printNumber(downCount / 6000 + 1, 2);
|
||||
OLED::print(SymbolMinutes);
|
||||
} else {
|
||||
OLED::printNumber(downCount / 100 + 1, 2);
|
||||
OLED::print(SymbolSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
static void gui_solderingMode(uint8_t jumpToSleep) {
|
||||
/*
|
||||
* * Soldering (gui_solderingMode)
|
||||
* -> Main loop where we draw temp, and animations
|
||||
* --> User presses buttons and they goto the temperature adjust screen
|
||||
* ---> Display the current setpoint temperature
|
||||
* ---> Use buttons to change forward and back on temperature
|
||||
* ---> Both buttons or timeout for exiting
|
||||
* --> Long hold front button to enter boost mode
|
||||
* ---> Just temporarily sets the system into the alternate temperature for
|
||||
* PID control
|
||||
* --> Long hold back button to exit
|
||||
* --> Double button to exit
|
||||
*/
|
||||
bool boostModeOn = false;
|
||||
|
||||
uint32_t sleepThres = 0;
|
||||
if (systemSettings.SleepTime < 6)
|
||||
sleepThres = systemSettings.SleepTime * 10 * 100;
|
||||
else
|
||||
sleepThres = (systemSettings.SleepTime - 5) * 60 * 100;
|
||||
if (jumpToSleep) {
|
||||
if (gui_SolderingSleepingMode(jumpToSleep == 2)) {
|
||||
lastButtonTime = xTaskGetTickCount();
|
||||
return; // If the function returns non-0 then exit
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
|
||||
ButtonState buttons = getButtonState();
|
||||
switch (buttons) {
|
||||
case BUTTON_NONE:
|
||||
// stay
|
||||
boostModeOn = false;
|
||||
break;
|
||||
case BUTTON_BOTH:
|
||||
// exit
|
||||
return;
|
||||
break;
|
||||
case BUTTON_B_LONG:
|
||||
return; // exit on back long hold
|
||||
break;
|
||||
case BUTTON_F_LONG:
|
||||
// if boost mode is enabled turn it on
|
||||
if (systemSettings.boostModeEnabled)
|
||||
boostModeOn = true;
|
||||
break;
|
||||
case BUTTON_F_SHORT:
|
||||
case BUTTON_B_SHORT: {
|
||||
uint16_t oldTemp = systemSettings.SolderingTemp;
|
||||
gui_solderingTempAdjust(); // goto adjust temp mode
|
||||
if (oldTemp != systemSettings.SolderingTemp) {
|
||||
saveSettings(); // only save on change
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// else we update the screen information
|
||||
OLED::setCursor(0, 0);
|
||||
OLED::clearScreen();
|
||||
OLED::setFont(0);
|
||||
//Draw in the screen details
|
||||
if (systemSettings.detailedSoldering) {
|
||||
OLED::setFont(1);
|
||||
OLED::print(SolderingAdvancedPowerPrompt); // Power:
|
||||
OLED::printNumber(x10WattHistory.average() / 10, 2);
|
||||
OLED::print(SymbolDot);
|
||||
OLED::printNumber(x10WattHistory.average() % 10, 1);
|
||||
OLED::print(SymbolWatts);
|
||||
|
||||
if (systemSettings.sensitivity && systemSettings.SleepTime) {
|
||||
OLED::print(SymbolSpace);
|
||||
display_countdown(sleepThres);
|
||||
}
|
||||
|
||||
OLED::setCursor(0, 8);
|
||||
OLED::print(SleepingTipAdvancedString);
|
||||
//OLED::printNumber(
|
||||
// TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0)), 5); // Draw the tip temp out finally
|
||||
|
||||
gui_drawTipTemp(true);
|
||||
OLED::print(SymbolSpace);
|
||||
printVoltage();
|
||||
OLED::print(SymbolVolts);
|
||||
} else {
|
||||
// We switch the layout direction depending on the orientation of the
|
||||
// OLED::
|
||||
if (OLED::getRotation()) {
|
||||
// battery
|
||||
gui_drawBatteryIcon();
|
||||
OLED::print(SymbolSpace); // Space out gap between battery <-> temp
|
||||
gui_drawTipTemp(true); // Draw current tip temp
|
||||
|
||||
// We draw boost arrow if boosting, or else gap temp <-> heat
|
||||
// indicator
|
||||
if (boostModeOn)
|
||||
OLED::drawSymbol(2);
|
||||
else
|
||||
OLED::print(SymbolSpace);
|
||||
|
||||
// Draw heating/cooling symbols
|
||||
OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average()));
|
||||
} else {
|
||||
// Draw heating/cooling symbols
|
||||
OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average()));
|
||||
// We draw boost arrow if boosting, or else gap temp <-> heat
|
||||
// indicator
|
||||
if (boostModeOn)
|
||||
OLED::drawSymbol(2);
|
||||
else
|
||||
OLED::print(SymbolSpace);
|
||||
gui_drawTipTemp(true); // Draw current tip temp
|
||||
|
||||
OLED::print(SymbolSpace); // Space out gap between battery <-> temp
|
||||
|
||||
gui_drawBatteryIcon();
|
||||
}
|
||||
}
|
||||
OLED::refresh();
|
||||
|
||||
// Update the setpoints for the temperature
|
||||
if (boostModeOn) {
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
currentTempTargetDegC = TipThermoModel::convertFtoC(
|
||||
systemSettings.BoostTemp);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
currentTempTargetDegC = (systemSettings.BoostTemp);
|
||||
}
|
||||
} else {
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
currentTempTargetDegC = TipThermoModel::convertFtoC(
|
||||
systemSettings.SolderingTemp);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
currentTempTargetDegC = (systemSettings.SolderingTemp);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MODEL_TS100
|
||||
// Undervoltage test
|
||||
if (checkVoltageForExit()) {
|
||||
lastButtonTime = xTaskGetTickCount();
|
||||
return;
|
||||
}
|
||||
#else
|
||||
// on the TS80 we only want to check for over voltage to prevent tip damage
|
||||
/*if (getInputVoltageX10(systemSettings.voltageDiv, 1) > 150) {
|
||||
lastButtonTime = xTaskGetTickCount();
|
||||
currentlyActiveTemperatureTarget = 0;
|
||||
return; // Over voltage
|
||||
}*/
|
||||
#endif
|
||||
|
||||
if (systemSettings.sensitivity && systemSettings.SleepTime)
|
||||
if (xTaskGetTickCount() - lastMovementTime > sleepThres
|
||||
&& xTaskGetTickCount() - lastButtonTime > sleepThres) {
|
||||
if (gui_SolderingSleepingMode(false)) {
|
||||
return; // If the function returns non-0 then exit
|
||||
}
|
||||
}
|
||||
//slow down ui update rate
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
|
||||
void showDebugMenu(void) {
|
||||
uint8_t screen = 0;
|
||||
ButtonState b;
|
||||
for (;;) {
|
||||
OLED::clearScreen(); // Ensure the buffer starts clean
|
||||
OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left)
|
||||
OLED::setFont(1); // small font
|
||||
OLED::print(SymbolVersionNumber); // Print version number
|
||||
OLED::setCursor(0, 8); // second line
|
||||
OLED::print(DebugMenu[screen]);
|
||||
switch (screen) {
|
||||
case 0: //Just prints date
|
||||
break;
|
||||
case 1:
|
||||
//High water mark for GUI
|
||||
OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5);
|
||||
break;
|
||||
case 2:
|
||||
//High water mark for the Movement task
|
||||
OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5);
|
||||
break;
|
||||
case 3:
|
||||
//High water mark for the PID task
|
||||
OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5);
|
||||
break;
|
||||
case 4:
|
||||
//system up time stamp
|
||||
OLED::printNumber(xTaskGetTickCount() / 100, 5);
|
||||
break;
|
||||
case 5:
|
||||
//Movement time stamp
|
||||
OLED::printNumber(lastMovementTime / 100, 5);
|
||||
break;
|
||||
case 6:
|
||||
//Raw Tip
|
||||
{
|
||||
uint32_t temp = systemSettings.CalibrationOffset;
|
||||
systemSettings.CalibrationOffset = 0;
|
||||
OLED::printNumber(
|
||||
TipThermoModel::convertTipRawADCTouV(getTipRawTemp(1)), 6);
|
||||
systemSettings.CalibrationOffset = temp;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
//Temp in C
|
||||
OLED::printNumber(TipThermoModel::getTipInC(1), 5);
|
||||
break;
|
||||
case 8:
|
||||
//Handle Temp
|
||||
OLED::printNumber(getHandleTemperature(), 3);
|
||||
break;
|
||||
case 9:
|
||||
//Voltage input
|
||||
printVoltage();
|
||||
break;
|
||||
case 10:
|
||||
// Print PCB ID number
|
||||
OLED::printNumber(PCBVersion, 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
OLED::refresh();
|
||||
b = getButtonState();
|
||||
if (b == BUTTON_B_SHORT)
|
||||
return;
|
||||
else if (b == BUTTON_F_SHORT) {
|
||||
screen++;
|
||||
screen = screen % 11;
|
||||
}
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
|
||||
/* StartGUITask function */
|
||||
void startGUITask(void const *argument __unused) {
|
||||
FRToSI2C::FRToSInit();
|
||||
uint8_t tempWarningState = 0;
|
||||
bool buttonLockout = false;
|
||||
bool tempOnDisplay = false;
|
||||
getTipRawTemp(1); // reset filter
|
||||
OLED::setRotation(systemSettings.OrientationMode & 1);
|
||||
uint32_t ticks = xTaskGetTickCount();
|
||||
ticks += 400; // 4 seconds from now
|
||||
while (xTaskGetTickCount() < ticks) {
|
||||
if (showBootLogoIfavailable() == false)
|
||||
ticks = xTaskGetTickCount();
|
||||
ButtonState buttons = getButtonState();
|
||||
if (buttons)
|
||||
ticks = xTaskGetTickCount(); // make timeout now so we will exit
|
||||
GUIDelay();
|
||||
}
|
||||
|
||||
if (settingsWereReset) {
|
||||
//Display alert settings were reset
|
||||
OLED::clearScreen();
|
||||
OLED::setFont(1);
|
||||
OLED::setCursor(0, 0);
|
||||
OLED::print(SettingsResetMessage);
|
||||
OLED::refresh();
|
||||
waitForButtonPressOrTimeout(1000);
|
||||
|
||||
}
|
||||
|
||||
if (systemSettings.autoStartMode) {
|
||||
// jump directly to the autostart mode
|
||||
if (systemSettings.autoStartMode == 1)
|
||||
{
|
||||
gui_solderingMode(0);
|
||||
buttonLockout = true;
|
||||
}
|
||||
else if (systemSettings.autoStartMode == 2)
|
||||
{
|
||||
gui_solderingMode(1);
|
||||
buttonLockout = true;
|
||||
}
|
||||
else if (systemSettings.autoStartMode == 3)
|
||||
{
|
||||
gui_solderingMode(2);
|
||||
buttonLockout = true;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ACCELDEBUG
|
||||
|
||||
for (;;) {
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
osDelay(100);
|
||||
}
|
||||
//^ Kept here for a way to block this thread
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
ButtonState buttons = getButtonState();
|
||||
if (buttons != BUTTON_NONE) {
|
||||
OLED::setDisplayState(OLED::DisplayState::ON);
|
||||
OLED::setFont(0);
|
||||
}
|
||||
if (tempWarningState == 2)
|
||||
buttons = BUTTON_F_SHORT;
|
||||
if (buttons != BUTTON_NONE && buttonLockout)
|
||||
buttons = BUTTON_NONE;
|
||||
else
|
||||
buttonLockout = false;
|
||||
|
||||
switch (buttons) {
|
||||
case BUTTON_NONE:
|
||||
// Do nothing
|
||||
break;
|
||||
case BUTTON_BOTH:
|
||||
// Not used yet
|
||||
// In multi-language this might be used to reset language on a long hold
|
||||
// or some such
|
||||
break;
|
||||
|
||||
case BUTTON_B_LONG:
|
||||
// Show the version information
|
||||
showDebugMenu();
|
||||
break;
|
||||
case BUTTON_F_LONG:
|
||||
gui_solderingTempAdjust();
|
||||
saveSettings();
|
||||
break;
|
||||
case BUTTON_F_SHORT:
|
||||
gui_solderingMode(0); // enter soldering mode
|
||||
buttonLockout = true;
|
||||
break;
|
||||
case BUTTON_B_SHORT:
|
||||
enterSettingsMenu(); // enter the settings menu
|
||||
buttonLockout = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
currentTempTargetDegC = 0; // ensure tip is off
|
||||
getInputVoltageX10(systemSettings.voltageDiv, 0);
|
||||
uint16_t tipTemp = TipThermoModel::getTipInC();
|
||||
|
||||
// Preemptively turn the display on. Turn it off if and only if
|
||||
// the tip temperature is below 50 degrees C *and* motion sleep
|
||||
// detection is enabled *and* there has been no activity (movement or
|
||||
// button presses) in a while.
|
||||
OLED::setDisplayState(OLED::DisplayState::ON);
|
||||
|
||||
if ((tipTemp < 50) && systemSettings.sensitivity
|
||||
&& (((xTaskGetTickCount() - lastMovementTime)
|
||||
> MOVEMENT_INACTIVITY_TIME)
|
||||
&& ((xTaskGetTickCount() - lastButtonTime)
|
||||
> BUTTON_INACTIVITY_TIME))) {
|
||||
OLED::setDisplayState(OLED::DisplayState::OFF);
|
||||
}
|
||||
|
||||
// Clear the lcd buffer
|
||||
OLED::clearScreen();
|
||||
OLED::setCursor(0, 0);
|
||||
if (systemSettings.detailedIDLE) {
|
||||
OLED::setFont(1);
|
||||
if (tipTemp > 470) {
|
||||
OLED::print(TipDisconnectedString);
|
||||
} else {
|
||||
OLED::print(IdleTipString);
|
||||
gui_drawTipTemp(false);
|
||||
OLED::print(IdleSetString);
|
||||
OLED::printNumber(systemSettings.SolderingTemp, 3);
|
||||
}
|
||||
OLED::setCursor(0, 8);
|
||||
|
||||
OLED::print(InputVoltageString);
|
||||
printVoltage();
|
||||
|
||||
} else {
|
||||
OLED::setFont(0);
|
||||
#ifdef MODEL_TS80
|
||||
if (!OLED::getRotation()) {
|
||||
#else
|
||||
if (OLED::getRotation()) {
|
||||
#endif
|
||||
OLED::drawArea(12, 0, 84, 16, idleScreenBG);
|
||||
OLED::setCursor(0, 0);
|
||||
gui_drawBatteryIcon();
|
||||
} else {
|
||||
OLED::drawArea(0, 0, 84, 16, idleScreenBGF); // Needs to be flipped so button ends up
|
||||
// on right side of screen
|
||||
OLED::setCursor(84, 0);
|
||||
gui_drawBatteryIcon();
|
||||
}
|
||||
if (tipTemp > 55)
|
||||
tempOnDisplay = true;
|
||||
else if (tipTemp < 45)
|
||||
tempOnDisplay = false;
|
||||
if (tempOnDisplay) {
|
||||
// draw temp over the start soldering button
|
||||
// Location changes on screen rotation
|
||||
#ifdef MODEL_TS80
|
||||
if (!OLED::getRotation()) {
|
||||
#else
|
||||
if (OLED::getRotation()) {
|
||||
#endif
|
||||
// in right handed mode we want to draw over the first part
|
||||
OLED::fillArea(55, 0, 41, 16, 0); // clear the area for the temp
|
||||
OLED::setCursor(56, 0);
|
||||
|
||||
} else {
|
||||
OLED::fillArea(0, 0, 41, 16, 0); // clear the area
|
||||
OLED::setCursor(0, 0);
|
||||
}
|
||||
// draw in the temp
|
||||
if (!(systemSettings.coolingTempBlink
|
||||
&& (xTaskGetTickCount() % 25 < 16)))
|
||||
gui_drawTipTemp(false); // draw in the temp
|
||||
}
|
||||
}
|
||||
OLED::refresh();
|
||||
GUIDelay();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* LIS2DH12.cpp
|
||||
*
|
||||
* Created on: 27Feb.,2018
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "LIS2DH12.hpp"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
typedef struct {
|
||||
const uint8_t reg;
|
||||
const uint8_t value;
|
||||
} LIS_REG;
|
||||
|
||||
static const LIS_REG i2c_registers[] = { { LIS_CTRL_REG1, 0x17 }, // 25Hz
|
||||
{ LIS_CTRL_REG2, 0b00001000 }, // Highpass filter off
|
||||
{ LIS_CTRL_REG3, 0b01100000 }, // Setup interrupt pins
|
||||
{ LIS_CTRL_REG4, 0b00001000 }, // Block update mode off, HR on
|
||||
{ LIS_CTRL_REG5, 0b00000010 }, { LIS_CTRL_REG6, 0b01100010 },
|
||||
//Basically setup the unit to run, and enable 4D orientation detection
|
||||
{ LIS_INT2_CFG, 0b01111110 }, //setup for movement detection
|
||||
{ LIS_INT2_THS, 0x28 }, { LIS_INT2_DURATION, 64 }, {
|
||||
LIS_INT1_CFG, 0b01111110 }, { LIS_INT1_THS, 0x28 }, {
|
||||
LIS_INT1_DURATION, 64 } };
|
||||
|
||||
void LIS2DH12::initalize() {
|
||||
for (size_t index = 0;
|
||||
index < (sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
index++) {
|
||||
FRToSI2C::I2C_RegisterWrite(LIS2DH_I2C_ADDRESS,
|
||||
i2c_registers[index].reg, i2c_registers[index].value);
|
||||
}
|
||||
}
|
||||
|
||||
void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
std::array<int16_t, 3> sensorData;
|
||||
|
||||
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, I2C_MEMADD_SIZE_8BIT,
|
||||
reinterpret_cast<uint8_t*>(sensorData.begin()),
|
||||
sensorData.size() * sizeof(int16_t));
|
||||
|
||||
x = sensorData[0];
|
||||
y = sensorData[1];
|
||||
z = sensorData[2];
|
||||
}
|
||||
|
||||
bool LIS2DH12::detect() {
|
||||
return FRToSI2C::probe(LIS2DH_I2C_ADDRESS);
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* MMA8652FC.cpp
|
||||
*
|
||||
* Created on: 31Aug.,2017
|
||||
* Author: Ben V. Brown
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "MMA8652FC.hpp"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
typedef struct {
|
||||
const uint8_t reg;
|
||||
const uint8_t val;
|
||||
} MMA_REG;
|
||||
|
||||
static const MMA_REG i2c_registers[] = { { CTRL_REG2, 0 }, //Normal mode
|
||||
{ CTRL_REG2, 0x40 }, // Reset all registers to POR values
|
||||
{ FF_MT_CFG_REG, 0x78 }, // Enable motion detection for X, Y, Z axis, latch disabled
|
||||
{ PL_CFG_REG, 0x40 }, //Enable the orientation detection
|
||||
{ PL_COUNT_REG, 200 }, //200 count debounce
|
||||
{ PL_BF_ZCOMP_REG, 0b01000111 }, //Set the threshold to 42 degrees
|
||||
{ P_L_THS_REG, 0b10011100 }, //Up the trip angles
|
||||
{ CTRL_REG4, 0x01 | (1 << 4) }, // Enable dataready interrupt & orientation interrupt
|
||||
{ CTRL_REG5, 0x01 }, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2
|
||||
{ CTRL_REG2, 0x12 }, //Set maximum resolution oversampling
|
||||
{ XYZ_DATA_CFG_REG, (1 << 4) }, //select high pass filtered data
|
||||
{ HP_FILTER_CUTOFF_REG, 0x03 }, //select high pass filtered data
|
||||
{ CTRL_REG1, 0x19 } // ODR=12 Hz, Active mode
|
||||
};
|
||||
|
||||
void MMA8652FC::initalize() {
|
||||
size_t index = 0;
|
||||
|
||||
//send all the init commands to the unit
|
||||
|
||||
FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS, i2c_registers[index].reg,
|
||||
i2c_registers[index].val);
|
||||
index++;
|
||||
FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS, i2c_registers[index].reg,
|
||||
i2c_registers[index].val);
|
||||
index++;
|
||||
|
||||
HAL_Delay(2); // ~1ms delay
|
||||
|
||||
while (index < (sizeof(i2c_registers) / sizeof(i2c_registers[0]))) {
|
||||
FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS,
|
||||
i2c_registers[index].reg, i2c_registers[index].val);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
Orientation MMA8652FC::getOrientation() {
|
||||
//First read the PL_STATUS register
|
||||
uint8_t plStatus = FRToSI2C::I2C_RegisterRead(MMA8652FC_I2C_ADDRESS,
|
||||
PL_STATUS_REG);
|
||||
if ((plStatus & 0b10000000) == 0b10000000) {
|
||||
plStatus >>= 1; //We don't need the up/down bit
|
||||
plStatus &= 0x03; //mask to the two lower bits
|
||||
|
||||
//0 == left handed
|
||||
//1 == right handed
|
||||
|
||||
return static_cast<Orientation>(plStatus);
|
||||
}
|
||||
|
||||
return ORIENTATION_FLAT;
|
||||
}
|
||||
|
||||
void MMA8652FC::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
std::array<int16_t, 3> sensorData;
|
||||
|
||||
FRToSI2C::Mem_Read(MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG,
|
||||
I2C_MEMADD_SIZE_8BIT, reinterpret_cast<uint8_t*>(sensorData.begin()),
|
||||
sensorData.size() * sizeof(int16_t));
|
||||
|
||||
x = static_cast<int16_t>(__builtin_bswap16(
|
||||
*reinterpret_cast<uint16_t*>(&sensorData[0])));
|
||||
y = static_cast<int16_t>(__builtin_bswap16(
|
||||
*reinterpret_cast<uint16_t*>(&sensorData[1])));
|
||||
z = static_cast<int16_t>(__builtin_bswap16(
|
||||
*reinterpret_cast<uint16_t*>(&sensorData[2])));
|
||||
}
|
||||
|
||||
bool MMA8652FC::detect() {
|
||||
return FRToSI2C::probe(MMA8652FC_I2C_ADDRESS);
|
||||
}
|
||||
@@ -1,486 +0,0 @@
|
||||
/*
|
||||
* OLED.cpp
|
||||
*
|
||||
* Created on: 29Aug.,2017
|
||||
* Author: Ben V. Brown
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <OLED.hpp>
|
||||
#include <stdlib.h>
|
||||
#include "Translation.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "../../configuration.h"
|
||||
|
||||
const uint8_t *OLED::currentFont; // Pointer to the current font used for
|
||||
// rendering to the buffer
|
||||
uint8_t *OLED::firstStripPtr; // Pointers to the strips to allow for buffer
|
||||
// having extra content
|
||||
uint8_t *OLED::secondStripPtr; // Pointers to the strips
|
||||
bool OLED::inLeftHandedMode; // Whether the screen is in left or not (used for
|
||||
// offsets in GRAM)
|
||||
OLED::DisplayState OLED::displayState;
|
||||
uint8_t OLED::fontWidth, OLED::fontHeight;
|
||||
int16_t OLED::cursor_x, OLED::cursor_y;
|
||||
uint8_t OLED::displayOffset;
|
||||
uint8_t OLED::screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
|
||||
uint8_t OLED::secondFrameBuffer[OLED_WIDTH * 2];
|
||||
|
||||
/*Setup params for the OLED screen*/
|
||||
/*http://www.displayfuture.com/Display/datasheet/controller/SSD1307.pdf*/
|
||||
/*All commands are prefixed with 0x80*/
|
||||
/*Data packets are prefixed with 0x40*/
|
||||
uint8_t OLED_Setup_Array[] = {
|
||||
/**/
|
||||
0x80, 0xAE, /*Display off*/
|
||||
0x80, 0xD5, /*Set display clock divide ratio / osc freq*/
|
||||
0x80, 0x52, /*Divide ratios*/
|
||||
0x80, 0xA8, /*Set Multiplex Ratio*/
|
||||
0x80, 0x0F, /*16 == max brightness,39==dimmest*/
|
||||
0x80, 0xC0, /*Set COM Scan direction*/
|
||||
0x80, 0xD3, /*Set vertical Display offset*/
|
||||
0x80, 0x00, /*0 Offset*/
|
||||
0x80, 0x40, /*Set Display start line to 0*/
|
||||
0x80, 0xA0, /*Set Segment remap to normal*/
|
||||
0x80, 0x8D, /*Charge Pump*/
|
||||
0x80, 0x14, /*Charge Pump settings*/
|
||||
0x80, 0xDA, /*Set VCOM Pins hardware config*/
|
||||
0x80, 0x02, /*Combination 2*/
|
||||
0x80, 0x81, /*Contrast*/
|
||||
0x80, 0x33, /*^51*/
|
||||
0x80, 0xD9, /*Set pre-charge period*/
|
||||
0x80, 0xF1, /*Pre charge period*/
|
||||
0x80, 0xDB, /*Adjust VCOMH regulator ouput*/
|
||||
0x80, 0x30, /*VCOM level*/
|
||||
0x80, 0xA4, /*Enable the display GDDR*/
|
||||
0x80, 0XA6, /*Normal display*/
|
||||
0x80, 0x20, /*Memory Mode*/
|
||||
0x80, 0x00, /*Wrap memory*/
|
||||
0x80, 0xAF /*Display on*/
|
||||
};
|
||||
// Setup based on the SSD1307 and modified for the SSD1306
|
||||
|
||||
const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80,
|
||||
0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40 };
|
||||
|
||||
|
||||
/*
|
||||
* Animation timing function that follows a bezier curve.
|
||||
* @param t A given percentage value [0..<100]
|
||||
* Returns a new percentage value with ease in and ease out.
|
||||
* Original floating point formula: t * t * (3.0f - 2.0f * t);
|
||||
*/
|
||||
static uint8_t easeInOutTiming(uint8_t t) {
|
||||
return t * t * (300 - 2 * t) / 10000;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the value between a and b, using a percentage value t.
|
||||
* @param a The value associated with 0%
|
||||
* @param b The value associated with 100%
|
||||
* @param t The percentage [0..<100]
|
||||
*/
|
||||
static uint8_t lerp(uint8_t a, uint8_t b, uint8_t t) {
|
||||
return a + t * (b - a) / 100;
|
||||
}
|
||||
|
||||
void OLED::initialize() {
|
||||
cursor_x = cursor_y = 0;
|
||||
currentFont = USER_FONT_12;
|
||||
fontWidth = 12;
|
||||
inLeftHandedMode = false;
|
||||
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
|
||||
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
|
||||
fontHeight = 16;
|
||||
displayOffset = 0;
|
||||
memcpy(&screenBuffer[0], &REFRESH_COMMANDS[0], sizeof(REFRESH_COMMANDS));
|
||||
|
||||
// Set the display to be ON once the settings block is sent and send the
|
||||
// initialisation data to the OLED.
|
||||
|
||||
setDisplayState(DisplayState::ON);
|
||||
FRToSI2C::Transmit(DEVICEADDR_OLED, &OLED_Setup_Array[0],
|
||||
sizeof(OLED_Setup_Array));
|
||||
}
|
||||
|
||||
void OLED::setFramebuffer(uint8_t *buffer) {
|
||||
if (buffer == NULL) {
|
||||
firstStripPtr = &screenBuffer[FRAMEBUFFER_START];
|
||||
secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH];
|
||||
return;
|
||||
}
|
||||
|
||||
firstStripPtr = &buffer[0];
|
||||
secondStripPtr = &buffer[OLED_WIDTH];
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints a char to the screen.
|
||||
* UTF font handling is done using the two input chars.
|
||||
* Precursor is the command char that is used to select the table.
|
||||
*/
|
||||
void OLED::drawChar(char c) {
|
||||
if (c == '\x01' && cursor_y == 0) { // 0x01 is used as new line char
|
||||
cursor_x = 0;
|
||||
cursor_y = 8;
|
||||
return;
|
||||
} else if (c == 0) {
|
||||
return;
|
||||
}
|
||||
uint16_t index = c - 2; //First index is \x02
|
||||
uint8_t *charPointer;
|
||||
charPointer = ((uint8_t*) currentFont)
|
||||
+ ((fontWidth * (fontHeight / 8)) * index);
|
||||
drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer);
|
||||
cursor_x += fontWidth;
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws a one pixel wide scrolling indicator. y is the upper vertical position
|
||||
* of the indicator in pixels (0..<16).
|
||||
*/
|
||||
void OLED::drawScrollIndicator(uint8_t y, uint8_t height) {
|
||||
union u_type {
|
||||
uint16_t whole;
|
||||
uint8_t strips[2];
|
||||
} column;
|
||||
|
||||
column.whole = (1 << height) - 1;
|
||||
column.whole <<= y;
|
||||
|
||||
// Draw a one pixel wide bar to the left with a single pixel as
|
||||
// the scroll indicator.
|
||||
fillArea(OLED_WIDTH - 1, 0, 1, 8, column.strips[0]);
|
||||
fillArea(OLED_WIDTH - 1, 8, 1, 8, column.strips[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a transition animation between two framebuffers.
|
||||
* @param forwardNavigation Direction of the navigation animation.
|
||||
*
|
||||
* If forward is true, this displays a forward navigation to the second framebuffer contents.
|
||||
* Otherwise a rewinding navigation animation is shown to the second framebuffer contents.
|
||||
*/
|
||||
void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) {
|
||||
uint8_t *firstBackStripPtr = &secondFrameBuffer[0];
|
||||
uint8_t *secondBackStripPtr = &secondFrameBuffer[OLED_WIDTH];
|
||||
|
||||
uint32_t totalDuration = 50; // 500ms
|
||||
uint32_t duration = 0;
|
||||
uint32_t start = xTaskGetTickCount();
|
||||
uint8_t offset = 0;
|
||||
|
||||
while (duration <= totalDuration) {
|
||||
duration = xTaskGetTickCount() - start;
|
||||
uint8_t progress = duration * 100 / totalDuration;
|
||||
progress = easeInOutTiming(progress);
|
||||
progress = lerp(0, OLED_WIDTH, progress);
|
||||
if (progress > OLED_WIDTH) {
|
||||
progress = OLED_WIDTH;
|
||||
}
|
||||
|
||||
// When forward, current contents move to the left out.
|
||||
// Otherwise the contents move to the right out.
|
||||
uint8_t oldStart = forwardNavigation ? 0 : progress;
|
||||
uint8_t oldPrevious = forwardNavigation ? progress - offset : offset;
|
||||
|
||||
// Content from the second framebuffer moves in from the right (forward)
|
||||
// or from the left (not forward).
|
||||
uint8_t newStart = forwardNavigation ? OLED_WIDTH - progress : 0;
|
||||
uint8_t newEnd = forwardNavigation ? 0 : OLED_WIDTH - progress;
|
||||
|
||||
offset = progress;
|
||||
|
||||
memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious], OLED_WIDTH - progress);
|
||||
memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious], OLED_WIDTH - progress);
|
||||
|
||||
memmove(&firstStripPtr[newStart], &firstBackStripPtr[newEnd], progress);
|
||||
memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd], progress);
|
||||
|
||||
refresh();
|
||||
osDelay(40);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::useSecondaryFramebuffer(bool useSecondary) {
|
||||
if (useSecondary) {
|
||||
setFramebuffer(secondFrameBuffer);
|
||||
} else {
|
||||
setFramebuffer(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::setRotation(bool leftHanded) {
|
||||
#ifdef MODEL_TS80
|
||||
leftHanded = !leftHanded;
|
||||
#endif
|
||||
if (inLeftHandedMode == leftHanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
// send command struct again with changes
|
||||
if (leftHanded) {
|
||||
OLED_Setup_Array[11] = 0xC8; // c1?
|
||||
OLED_Setup_Array[19] = 0xA1;
|
||||
} else {
|
||||
OLED_Setup_Array[11] = 0xC0;
|
||||
OLED_Setup_Array[19] = 0xA0;
|
||||
}
|
||||
FRToSI2C::Transmit(DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array,
|
||||
sizeof(OLED_Setup_Array));
|
||||
inLeftHandedMode = leftHanded;
|
||||
|
||||
screenBuffer[5] = inLeftHandedMode ? 0 : 32; // display is shifted by 32 in left handed
|
||||
// mode as driver ram is 128 wide
|
||||
screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; // End address of the ram segment we are writing to (96 wide)
|
||||
screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0;
|
||||
}
|
||||
|
||||
// print a string to the current cursor location
|
||||
void OLED::print(const char *str) {
|
||||
while (str[0]) {
|
||||
drawChar(str[0]);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::setFont(uint8_t fontNumber) {
|
||||
if (fontNumber == 1) {
|
||||
// small font
|
||||
currentFont = USER_FONT_6x8;
|
||||
fontHeight = 8;
|
||||
fontWidth = 6;
|
||||
} else if (fontNumber == 2) {
|
||||
currentFont = ExtraFontChars;
|
||||
fontHeight = 16;
|
||||
fontWidth = 12;
|
||||
} else {
|
||||
currentFont = USER_FONT_12;
|
||||
fontHeight = 16;
|
||||
fontWidth = 12;
|
||||
}
|
||||
}
|
||||
uint8_t OLED::getFont() {
|
||||
if (currentFont == USER_FONT_6x8)
|
||||
return 1;
|
||||
else if (currentFont == ExtraFontChars)
|
||||
return 2;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
inline void stripLeaderZeros(char *buffer, uint8_t places) {
|
||||
//Removing the leading zero's by swapping them to SymbolSpace
|
||||
// Stop 1 short so that we dont blank entire number if its zero
|
||||
for (int i = 0; i < (places-1); i++) {
|
||||
if (buffer[i] == 2) {
|
||||
buffer[i] = SymbolSpace[0];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// maximum places is 5
|
||||
void OLED::printNumber(uint16_t number, uint8_t places, bool noLeaderZeros) {
|
||||
char buffer[7] = { 0 };
|
||||
|
||||
if (places >= 5) {
|
||||
buffer[5] = 2 + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
if (places > 4) {
|
||||
buffer[4] = 2 + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
if (places > 3) {
|
||||
buffer[3] = 2 + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
if (places > 2) {
|
||||
buffer[2] = 2 + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
if (places > 1) {
|
||||
buffer[1] = 2 + number % 10;
|
||||
number /= 10;
|
||||
}
|
||||
|
||||
buffer[0] = 2 + number % 10;
|
||||
if (noLeaderZeros)
|
||||
stripLeaderZeros(buffer, places);
|
||||
print(buffer);
|
||||
}
|
||||
|
||||
void OLED::debugNumber(int32_t val) {
|
||||
if (abs(val) > 99999) {
|
||||
OLED::print(SymbolSpace); // out of bounds
|
||||
return;
|
||||
}
|
||||
if (val >= 0) {
|
||||
OLED::print(SymbolSpace);
|
||||
OLED::printNumber(val, 5);
|
||||
} else {
|
||||
OLED::print(SymbolMinus);
|
||||
OLED::printNumber(-val, 5);
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::drawSymbol(uint8_t symbolID) {
|
||||
// draw a symbol to the current cursor location
|
||||
setFont(2);
|
||||
drawChar(symbolID + 2);
|
||||
setFont(0);
|
||||
}
|
||||
|
||||
// Draw an area, but y must be aligned on 0/8 offset
|
||||
void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t *ptr) {
|
||||
// Splat this from x->x+wide in two strides
|
||||
if (x <= -wide)
|
||||
return; // cutoffleft
|
||||
if (x > 96)
|
||||
return; // cutoff right
|
||||
|
||||
uint8_t visibleStart = 0;
|
||||
uint8_t visibleEnd = wide;
|
||||
|
||||
// trimming to draw partials
|
||||
if (x < 0) {
|
||||
visibleStart -= x; // subtract negative value == add absolute value
|
||||
}
|
||||
if (x + wide > 96) {
|
||||
visibleEnd = 96 - x;
|
||||
}
|
||||
|
||||
if (y == 0) {
|
||||
// Splat first line of data
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
firstStripPtr[xx + x] = ptr[xx];
|
||||
}
|
||||
}
|
||||
if (y == 8 || height == 16) {
|
||||
// Splat the second line
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw an area, but y must be aligned on 0/8 offset
|
||||
// For data which has octets swapped in a 16-bit word.
|
||||
void OLED::drawAreaSwapped(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t *ptr) {
|
||||
// Splat this from x->x+wide in two strides
|
||||
if (x <= -wide)
|
||||
return; // cutoffleft
|
||||
if (x > 96)
|
||||
return; // cutoff right
|
||||
|
||||
uint8_t visibleStart = 0;
|
||||
uint8_t visibleEnd = wide;
|
||||
|
||||
// trimming to draw partials
|
||||
if (x < 0) {
|
||||
visibleStart -= x; // subtract negative value == add absolute value
|
||||
}
|
||||
if (x + wide > 96) {
|
||||
visibleEnd = 96 - x;
|
||||
}
|
||||
|
||||
if (y == 0) {
|
||||
// Splat first line of data
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx += 2) {
|
||||
firstStripPtr[xx + x] = ptr[xx + 1];
|
||||
firstStripPtr[xx + x + 1] = ptr[xx];
|
||||
}
|
||||
}
|
||||
if (y == 8 || height == 16) {
|
||||
// Splat the second line
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx += 2) {
|
||||
secondStripPtr[x + xx] = ptr[xx + 1 + (height == 16 ? wide : 0)];
|
||||
secondStripPtr[x + xx + 1] = ptr[xx + (height == 16 ? wide : 0)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t value) {
|
||||
// Splat this from x->x+wide in two strides
|
||||
if (x <= -wide)
|
||||
return; // cutoffleft
|
||||
if (x > 96)
|
||||
return; // cutoff right
|
||||
|
||||
uint8_t visibleStart = 0;
|
||||
uint8_t visibleEnd = wide;
|
||||
|
||||
// trimming to draw partials
|
||||
if (x < 0) {
|
||||
visibleStart -= x; // subtract negative value == add absolute value
|
||||
}
|
||||
if (x + wide > 96) {
|
||||
visibleEnd = 96 - x;
|
||||
}
|
||||
|
||||
if (y == 0) {
|
||||
// Splat first line of data
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
firstStripPtr[xx + x] = value;
|
||||
}
|
||||
}
|
||||
if (y == 8 || height == 16) {
|
||||
// Splat the second line
|
||||
for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) {
|
||||
secondStripPtr[x + xx] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OLED::drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
|
||||
bool clear) {
|
||||
// Draw this in 3 sections
|
||||
// This is basically a N wide version of vertical line
|
||||
|
||||
// Step 1 : Draw in the top few pixels that are not /8 aligned
|
||||
// LSB is at the top of the screen
|
||||
uint8_t mask = 0xFF;
|
||||
if (y0) {
|
||||
mask = mask << (y0 % 8);
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
if (clear)
|
||||
firstStripPtr[(y0 / 8) * 96 + col] &= ~mask;
|
||||
else
|
||||
firstStripPtr[(y0 / 8) * 96 + col] |= mask;
|
||||
}
|
||||
// Next loop down the line the total number of solids
|
||||
if (y0 / 8 != y1 / 8)
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
for (uint8_t r = (y0 / 8); r < (y1 / 8); r++) {
|
||||
// This gives us the row index r
|
||||
if (clear)
|
||||
firstStripPtr[(r * 96) + col] = 0;
|
||||
else
|
||||
firstStripPtr[(r * 96) + col] = 0xFF;
|
||||
}
|
||||
|
||||
// Finally draw the tail
|
||||
mask = ~(mask << (y1 % 8));
|
||||
for (uint8_t col = x0; col < x1; col++)
|
||||
if (clear)
|
||||
firstStripPtr[(y1 / 8) * 96 + col] &= ~mask;
|
||||
else
|
||||
firstStripPtr[(y1 / 8) * 96 + col] |= mask;
|
||||
}
|
||||
|
||||
void OLED::drawHeatSymbol(uint8_t state) {
|
||||
// Draw symbol 14
|
||||
// Then draw over it, the bottom 5 pixels always stay. 8 pixels above that are
|
||||
// the levels masks the symbol nicely
|
||||
state /= 31; // 0-> 8 range
|
||||
// Then we want to draw down (16-(5+state)
|
||||
uint8_t cursor_x_temp = cursor_x;
|
||||
drawSymbol(14);
|
||||
drawFilledRect(cursor_x_temp, 0, cursor_x_temp + 12, 2 + (8 - state), true);
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* TipThermoModel.cpp
|
||||
*
|
||||
* Created on: 7 Oct 2019
|
||||
* Author: ralim
|
||||
*/
|
||||
|
||||
#include "TipThermoModel.h"
|
||||
#include "Settings.h"
|
||||
#include "BSP.h"
|
||||
#include "../../configuration.h"
|
||||
|
||||
/*
|
||||
* The hardware is laid out as a non-inverting op-amp
|
||||
* There is a pullup of 39k(TS100) from the +ve input to 3.9V (1M pulup on TS100)
|
||||
*
|
||||
* The simplest case to model this, is to ignore the pullup resistors influence, and assume that its influence is mostly constant
|
||||
* -> Tip resistance *does* change with temp, but this should be much less than the rest of the system.
|
||||
*
|
||||
* When a thermocouple is equal temperature at both sides (hot and cold junction), then the output should be 0uV
|
||||
* Therefore, by measuring the uV when both are equal, the measured reading is the offset value.
|
||||
* This is a mix of the pull-up resistor, combined with tip manufacturing differences.
|
||||
*
|
||||
* All of the thermocouple readings are based on this expired patent
|
||||
* - > https://patents.google.com/patent/US6087631A/en
|
||||
*
|
||||
* This was bought to my attention by <Kuba Sztandera>
|
||||
*/
|
||||
|
||||
|
||||
uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
|
||||
// This takes the raw ADC samples, converts these to uV
|
||||
// Then divides this down by the gain to convert to the uV on the input to the op-amp (A+B terminals)
|
||||
// Then remove the calibration value that is stored as a tip offset
|
||||
uint32_t vddRailmVX10 = 33000; //The vreg is +-2%, but we have no higher accuracy available
|
||||
// 4096 * 8 readings for full scale
|
||||
// Convert the input ADC reading back into mV times 10 format.
|
||||
uint32_t rawInputmVX10 = (rawADC * vddRailmVX10) / (4096 * 8);
|
||||
|
||||
uint32_t valueuV = rawInputmVX10 * 100; // shift into uV
|
||||
//Now to divide this down by the gain
|
||||
valueuV = (valueuV) / OP_AMP_GAIN_STAGE;
|
||||
//Remove uV tipOffset
|
||||
if (valueuV >= systemSettings.CalibrationOffset)
|
||||
valueuV -= systemSettings.CalibrationOffset;
|
||||
else
|
||||
valueuV = 0;
|
||||
|
||||
return valueuV;
|
||||
}
|
||||
|
||||
uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) {
|
||||
return convertuVToDegC(convertTipRawADCTouV(rawADC));
|
||||
}
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) {
|
||||
return convertuVToDegF(convertTipRawADCTouV(rawADC));
|
||||
}
|
||||
#endif
|
||||
|
||||
//Table that is designed to be walked to find the best sample for the lookup
|
||||
|
||||
//Extrapolate between two points
|
||||
// [x1, y1] = point 1
|
||||
// [x2, y2] = point 2
|
||||
// x = input value
|
||||
// output is x's extrapolated y value
|
||||
int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2,
|
||||
int32_t x) {
|
||||
return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000;
|
||||
}
|
||||
|
||||
uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
|
||||
//based on new measurements, tip is quite linear
|
||||
//
|
||||
tipuVDelta *= 10;
|
||||
tipuVDelta /= systemSettings.TipGain;
|
||||
|
||||
#ifdef MODEL_TS80
|
||||
tipuVDelta /= OP_AMP_GAIN_STAGE_TS100 / OP_AMP_GAIN_STAGE_TS80;
|
||||
#endif
|
||||
|
||||
return tipuVDelta;
|
||||
}
|
||||
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) {
|
||||
return convertCtoF(convertuVToDegC(tipuVDelta));
|
||||
}
|
||||
|
||||
uint32_t TipThermoModel::convertCtoF(uint32_t degC) {
|
||||
//(Y °C × 9/5) + 32 =Y°F
|
||||
return 32 + ((degC * 9) / 5);
|
||||
}
|
||||
|
||||
uint32_t TipThermoModel::convertFtoC(uint32_t degF) {
|
||||
//(Y°F − 32) × 5/9 = Y°C
|
||||
if (degF < 32)
|
||||
return 0;
|
||||
return ((degF - 32) * 5) / 9;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t TipThermoModel::getTipInC(bool sampleNow) {
|
||||
uint32_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(
|
||||
getTipRawTemp(sampleNow));
|
||||
currentTipTempInC += getHandleTemperature() / 10; //Add handle offset
|
||||
return currentTipTempInC;
|
||||
}
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
uint32_t TipThermoModel::getTipInF(bool sampleNow) {
|
||||
uint32_t currentTipTempInF = TipThermoModel::convertTipRawADCToDegF(
|
||||
getTipRawTemp(sampleNow));
|
||||
currentTipTempInF += convertCtoF(getHandleTemperature() / 10); //Add handle offset
|
||||
return currentTipTempInF;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t TipThermoModel::getTipMaxInC() {
|
||||
uint32_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(
|
||||
0x7FFF - (80 * 5)); //back off approx 5 deg c from ADC max
|
||||
maximumTipTemp += getHandleTemperature() / 10; //Add handle offset
|
||||
return maximumTipTemp - 1;
|
||||
}
|
||||
@@ -38,12 +38,6 @@ static const size_t MOVTaskStackSize = 512 / 4;
|
||||
uint32_t MOVTaskBuffer[MOVTaskStackSize];
|
||||
osStaticThreadDef_t MOVTaskControlBlock;
|
||||
|
||||
static TaskHandle_t pidTaskNotification = NULL;
|
||||
static TickType_t powerPulseRate = 1000;
|
||||
static TickType_t powerPulseDuration = 50;
|
||||
void startGUITask(void const *argument);
|
||||
void startPIDTask(void const *argument);
|
||||
void startMOVTask(void const *argument);
|
||||
// End FreeRTOS
|
||||
|
||||
// Main sets up the hardware then hands over to the FreeRTOS kernel
|
||||
@@ -51,7 +45,7 @@ int main(void) {
|
||||
preRToSInit();
|
||||
|
||||
setTipX10Watts(0); // force tip off
|
||||
FRToSI2C::init (&hi2c1);
|
||||
FRToSI2C::init(&hi2c1);
|
||||
OLED::initialize(); // start up the LCD
|
||||
OLED::setFont(0); // default to bigger font
|
||||
// Testing for which accelerometer is mounted
|
||||
@@ -100,114 +94,6 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/* StartPIDTask function */
|
||||
void startPIDTask(void const *argument __unused) {
|
||||
/*
|
||||
* We take the current tip temperature & evaluate the next step for the tip
|
||||
* control PWM.
|
||||
*/
|
||||
setTipX10Watts(0); // disable the output driver if the output is set to be off
|
||||
TickType_t lastPowerPulseStart = 0;
|
||||
TickType_t lastPowerPulseEnd = 0;
|
||||
|
||||
history<int32_t, PID_TIM_HZ> tempError = { { 0 }, 0, 0 };
|
||||
currentTempTargetDegC = 0; // Force start with no output (off). If in sleep / soldering this will
|
||||
// be over-ridden rapidly
|
||||
pidTaskNotification = xTaskGetCurrentTaskHandle();
|
||||
uint32_t PIDTempTarget = 0;
|
||||
for (;;) {
|
||||
|
||||
if (ulTaskNotifyTake(pdTRUE, 2000)) {
|
||||
// This is a call to block this thread until the ADC does its samples
|
||||
int32_t x10WattsOut = 0;
|
||||
// Do the reading here to keep the temp calculations churning along
|
||||
uint32_t currentTipTempInC = TipThermoModel::getTipInC(true);
|
||||
PIDTempTarget = currentTempTargetDegC;
|
||||
if (PIDTempTarget) {
|
||||
// Cap the max set point to 450C
|
||||
if (PIDTempTarget > (450)) {
|
||||
//Maximum allowed output
|
||||
PIDTempTarget = (450);
|
||||
}
|
||||
//Safety check that not aiming higher than current tip can measure
|
||||
if (PIDTempTarget > TipThermoModel::getTipMaxInC()) {
|
||||
PIDTempTarget = TipThermoModel::getTipMaxInC();
|
||||
}
|
||||
// Convert the current tip to degree's C
|
||||
|
||||
// As we get close to our target, temp noise causes the system
|
||||
// to be unstable. Use a rolling average to dampen it.
|
||||
// We overshoot by roughly 1 degree C.
|
||||
// This helps stabilize the display.
|
||||
int32_t tError = PIDTempTarget - currentTipTempInC + 1;
|
||||
tError = tError > INT16_MAX ? INT16_MAX : tError;
|
||||
tError = tError < INT16_MIN ? INT16_MIN : tError;
|
||||
tempError.update(tError);
|
||||
|
||||
// Now for the PID!
|
||||
|
||||
// P term - total power needed to hit target temp next cycle.
|
||||
// thermal mass = 1690 milliJ/*C for my tip.
|
||||
// = Watts*Seconds to raise Temp from room temp to +100*C, divided by 100*C.
|
||||
// we divide milliWattsNeeded by 20 to let the I term dominate near the set point.
|
||||
// This is necessary because of the temp noise and thermal lag in the system.
|
||||
// Once we have feed-forward temp estimation we should be able to better tune this.
|
||||
|
||||
int32_t x10WattsNeeded = tempToX10Watts(tError);
|
||||
// tempError.average());
|
||||
// note that milliWattsNeeded is sometimes negative, this counters overshoot
|
||||
// from I term's inertia.
|
||||
x10WattsOut += x10WattsNeeded;
|
||||
|
||||
// I term - energy needed to compensate for heat loss.
|
||||
// We track energy put into the system over some window.
|
||||
// Assuming the temp is stable, energy in = energy transfered.
|
||||
// (If it isn't, P will dominate).
|
||||
x10WattsOut += x10WattHistory.average();
|
||||
|
||||
// D term - use sudden temp change to counter fast cooling/heating.
|
||||
// In practice, this provides an early boost if temp is dropping
|
||||
// and counters extra power if the iron is no longer losing temp.
|
||||
// basically: temp - lastTemp
|
||||
// Unfortunately, our temp signal is too noisy to really help.
|
||||
|
||||
}
|
||||
//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;
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
//Secondary safety check to forcefully disable header when within ADC noise of top of ADC
|
||||
if (getTipRawTemp(0) > (0x7FFF - 150)) {
|
||||
x10WattsOut = 0;
|
||||
}
|
||||
if (systemSettings.powerLimitEnable
|
||||
&& x10WattsOut > (systemSettings.powerLimit * 10)) {
|
||||
setTipX10Watts(systemSettings.powerLimit * 10);
|
||||
} else {
|
||||
setTipX10Watts(x10WattsOut);
|
||||
}
|
||||
|
||||
HAL_IWDG_Refresh (&hiwdg);
|
||||
} else {
|
||||
//ADC interrupt timeout
|
||||
setTipPWM(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MOVFilter 8
|
||||
void startMOVTask(void const *argument __unused) {
|
||||
OLED::setRotation(true);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* power.cpp
|
||||
*
|
||||
* Created on: 28 Oct, 2018
|
||||
* Authors: Ben V. Brown, David Hilton
|
||||
* Authors: Ben V. Brown, David Hilton <- Mostly David
|
||||
*/
|
||||
|
||||
#include <power.hpp>
|
||||
|
||||
Reference in New Issue
Block a user