mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Handle tip connect & disconnect in detection
This commit is contained in:
@@ -76,6 +76,18 @@ void log_system_state(int32_t PWMWattsx10);
|
|||||||
|
|
||||||
// Returns true if the tip is disconnected
|
// Returns true if the tip is disconnected
|
||||||
bool isTipDisconnected();
|
bool isTipDisconnected();
|
||||||
|
|
||||||
|
// Status LED controls
|
||||||
|
|
||||||
|
enum StatusLED {
|
||||||
|
LED_OFF = 0, // Turn off status led
|
||||||
|
LED_STANDBY, // unit is in sleep /standby
|
||||||
|
LED_HEATING, // The unit is heating up to temperature
|
||||||
|
LED_HOT, // The unit is at operating temperature
|
||||||
|
LED_COOLING_STILL_HOT, // The unit is off and cooling but still hot
|
||||||
|
};
|
||||||
|
void setStatusLED(const enum StatusLED state);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ uint16_t totalPWM = 255;
|
|||||||
const uint16_t powerPWM = 255;
|
const uint16_t powerPWM = 255;
|
||||||
|
|
||||||
history<uint16_t, PID_TIM_HZ> rawTempFilter = { { 0 }, 0, 0 };
|
history<uint16_t, PID_TIM_HZ> rawTempFilter = { { 0 }, 0, 0 };
|
||||||
void resetWatchdog() { HAL_IWDG_Refresh(&hiwdg); }
|
void resetWatchdog() {
|
||||||
|
HAL_IWDG_Refresh(&hiwdg);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TEMP_NTC
|
#ifdef TEMP_NTC
|
||||||
// Lookup table for the NTC
|
// Lookup table for the NTC
|
||||||
@@ -185,7 +187,8 @@ static const uint16_t NTCHandleLookup[] = {
|
|||||||
29104, 20, //
|
29104, 20, //
|
||||||
29272, 10, //
|
29272, 10, //
|
||||||
};
|
};
|
||||||
const int NTCHandleLookupItems = sizeof(NTCHandleLookup) / (2 * sizeof(uint16_t));
|
const int NTCHandleLookupItems = sizeof(NTCHandleLookup)
|
||||||
|
/ (2 * sizeof(uint16_t));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// These are called by the HAL after the corresponding events from the system
|
// These are called by the HAL after the corresponding events from the system
|
||||||
@@ -200,10 +203,13 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
|||||||
}
|
}
|
||||||
uint16_t getHandleTemperature() {
|
uint16_t getHandleTemperature() {
|
||||||
int32_t result = getADC(0);
|
int32_t result = getADC(0);
|
||||||
return Utils::InterpolateLookupTable(NTCHandleLookup, NTCHandleLookupItems, result);
|
return Utils::InterpolateLookupTable(NTCHandleLookup, NTCHandleLookupItems,
|
||||||
|
result);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getTipInstantTemperature() { return getADC(2); }
|
uint16_t getTipInstantTemperature() {
|
||||||
|
return getADC(2);
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t getTipRawTemp(uint8_t refresh) {
|
uint16_t getTipRawTemp(uint8_t refresh) {
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
@@ -321,14 +327,25 @@ void unstick_I2C() {
|
|||||||
HAL_I2C_Init(&hi2c1);
|
HAL_I2C_Init(&hi2c1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
uint8_t getButtonA() {
|
||||||
uint8_t getButtonB() { return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ?
|
||||||
|
1 : 0;
|
||||||
|
}
|
||||||
|
uint8_t getButtonB() {
|
||||||
|
return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ?
|
||||||
|
1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
void BSPInit(void) {}
|
void BSPInit(void) {
|
||||||
|
}
|
||||||
|
|
||||||
void reboot() { NVIC_SystemReset(); }
|
void reboot() {
|
||||||
|
NVIC_SystemReset();
|
||||||
|
}
|
||||||
|
|
||||||
void delay_ms(uint16_t count) { HAL_Delay(count); }
|
void delay_ms(uint16_t count) {
|
||||||
|
HAL_Delay(count);
|
||||||
|
}
|
||||||
|
|
||||||
void setPlatePullup(bool pullingUp) {
|
void setPlatePullup(bool pullingUp) {
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
@@ -337,11 +354,13 @@ void setPlatePullup(bool pullingUp) {
|
|||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
if (pullingUp) {
|
if (pullingUp) {
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port, PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port,
|
||||||
|
PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_SET);
|
||||||
} else {
|
} else {
|
||||||
// Hi-z
|
// Hi-z
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||||
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port, PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(PLATE_SENSOR_PULLUP_GPIO_Port,
|
||||||
|
PLATE_SENSOR_PULLUP_Pin, GPIO_PIN_RESET);
|
||||||
}
|
}
|
||||||
HAL_GPIO_Init(PLATE_SENSOR_PULLUP_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(PLATE_SENSOR_PULLUP_GPIO_Port, &GPIO_InitStruct);
|
||||||
}
|
}
|
||||||
@@ -358,11 +377,10 @@ bool isTipDisconnected() {
|
|||||||
* plate_sensor_res = ((adc5_value_PD1_set - adc5_value_PD1_cleared) / (adc5_value_PD1_cleared + 4096 - adc5_value_PD1_set)) * 1000.0;
|
* plate_sensor_res = ((adc5_value_PD1_set - adc5_value_PD1_cleared) / (adc5_value_PD1_cleared + 4096 - adc5_value_PD1_set)) * 1000.0;
|
||||||
* */
|
* */
|
||||||
|
|
||||||
uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5;
|
bool tipDisconnected = getADC(2) > 4090;
|
||||||
uint32_t tipTemp = TipThermoModel::getTipInC();
|
|
||||||
bool tipDisconnected = tipTemp > tipDisconnectedThres;
|
|
||||||
// We have to handle here that this ^ will trip while measuring the gain resistor
|
// We have to handle here that this ^ will trip while measuring the gain resistor
|
||||||
if (xTaskGetTickCount() - lastMeas < (TICKS_100MS * 2 + (TICKS_100MS / 2))) {
|
if (xTaskGetTickCount() - lastMeas
|
||||||
|
< (TICKS_100MS * 2 + (TICKS_100MS / 2))) {
|
||||||
tipDisconnected = false;
|
tipDisconnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,13 +408,22 @@ bool isTipDisconnected() {
|
|||||||
} else {
|
} else {
|
||||||
// We have taken reading one
|
// We have taken reading one
|
||||||
uint16_t adcReadingPD1Cleared = getADC(3);
|
uint16_t adcReadingPD1Cleared = getADC(3);
|
||||||
uint32_t a = ((int)adcReadingPD1Set - (int)adcReadingPD1Cleared);
|
uint32_t a = ((int) adcReadingPD1Set
|
||||||
|
- (int) adcReadingPD1Cleared);
|
||||||
a *= 10000;
|
a *= 10000;
|
||||||
uint32_t b = ((int)adcReadingPD1Cleared + (32768 - (int)adcReadingPD1Set));
|
uint32_t b = ((int) adcReadingPD1Cleared
|
||||||
|
+ (32768 - (int) adcReadingPD1Set));
|
||||||
if (b) {
|
if (b) {
|
||||||
tipSenseResistancex10Ohms = a / b;
|
tipSenseResistancex10Ohms = a / b;
|
||||||
} else {
|
} else {
|
||||||
tipSenseResistancex10Ohms = adcReadingPD1Set = lastMeas = 0;
|
tipSenseResistancex10Ohms = adcReadingPD1Set =
|
||||||
|
lastMeas = 0;
|
||||||
|
}
|
||||||
|
if (tipSenseResistancex10Ohms > 1100
|
||||||
|
|| tipSenseResistancex10Ohms < 900) {
|
||||||
|
tipSenseResistancex10Ohms = 0; // out of range
|
||||||
|
adcReadingPD1Set = 0;
|
||||||
|
lastMeas = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,3 +433,6 @@ bool isTipDisconnected() {
|
|||||||
|
|
||||||
return tipDisconnected;
|
return tipDisconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setStatusLED(const enum StatusLED state) {
|
||||||
|
}
|
||||||
|
|||||||
@@ -347,3 +347,5 @@ bool isTipDisconnected() {
|
|||||||
uint32_t tipTemp = TipThermoModel::getTipInC();
|
uint32_t tipTemp = TipThermoModel::getTipInC();
|
||||||
return tipTemp > tipDisconnectedThres;
|
return tipTemp > tipDisconnectedThres;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setStatusLED(const enum StatusLED state) {}
|
||||||
|
|||||||
@@ -129,3 +129,5 @@ bool isTipDisconnected() {
|
|||||||
uint32_t tipTemp = TipThermoModel::getTipInC();
|
uint32_t tipTemp = TipThermoModel::getTipInC();
|
||||||
return tipTemp > tipDisconnectedThres;
|
return tipTemp > tipDisconnectedThres;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setStatusLED(const enum StatusLED state) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user