Formatting the C/C++ files
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "BMA223.hpp"
|
||||
#include "SC7A20.hpp"
|
||||
#include "BSP.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
@@ -14,6 +13,7 @@
|
||||
#include "MMA8652FC.hpp"
|
||||
#include "MSA301.h"
|
||||
#include "QC3.h"
|
||||
#include "SC7A20.hpp"
|
||||
#include "Settings.h"
|
||||
#include "TipThermoModel.h"
|
||||
#include "cmsis_os.h"
|
||||
@@ -23,60 +23,60 @@
|
||||
#include "stdlib.h"
|
||||
#include "task.h"
|
||||
#define MOVFilter 8
|
||||
uint8_t accelInit = 0;
|
||||
uint8_t accelInit = 0;
|
||||
TickType_t lastMovementTime = 0;
|
||||
void detectAccelerometerVersion() {
|
||||
DetectedAccelerometerVersion = 99;
|
||||
void detectAccelerometerVersion() {
|
||||
DetectedAccelerometerVersion = 99;
|
||||
#ifdef ACCEL_MMA
|
||||
if (MMA8652FC::detect()) {
|
||||
if (MMA8652FC::initalize()) {
|
||||
DetectedAccelerometerVersion = 1;
|
||||
DetectedAccelerometerVersion = 1;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_LIS
|
||||
if (LIS2DH12::detect()) {
|
||||
// Setup the ST Accelerometer
|
||||
if (LIS2DH12::initalize()) {
|
||||
DetectedAccelerometerVersion = 2;
|
||||
}
|
||||
} else
|
||||
if (LIS2DH12::detect()) {
|
||||
// Setup the ST Accelerometer
|
||||
if (LIS2DH12::initalize()) {
|
||||
DetectedAccelerometerVersion = 2;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_BMA
|
||||
if (BMA223::detect()) {
|
||||
// Setup the ST Accelerometer
|
||||
if (BMA223::initalize()) {
|
||||
DetectedAccelerometerVersion = 3;
|
||||
DetectedAccelerometerVersion = 3;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_MSA
|
||||
if (MSA301::detect()) {
|
||||
// Setup the MSA301 Accelerometer
|
||||
if (MSA301::initalize()) {
|
||||
DetectedAccelerometerVersion = 4;
|
||||
}
|
||||
} else
|
||||
if (MSA301::detect()) {
|
||||
// Setup the MSA301 Accelerometer
|
||||
if (MSA301::initalize()) {
|
||||
DetectedAccelerometerVersion = 4;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_SC7
|
||||
if (SC7A20::detect()) {
|
||||
// Setup the SC7A20 Accelerometer
|
||||
if (SC7A20::initalize()) {
|
||||
DetectedAccelerometerVersion = 5;
|
||||
}
|
||||
} else
|
||||
if (SC7A20::detect()) {
|
||||
// Setup the SC7A20 Accelerometer
|
||||
if (SC7A20::initalize()) {
|
||||
DetectedAccelerometerVersion = 5;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
// disable imu sensitivity
|
||||
systemSettings.sensitivity = 0;
|
||||
}
|
||||
{
|
||||
// disable imu sensitivity
|
||||
systemSettings.sensitivity = 0;
|
||||
}
|
||||
}
|
||||
inline void readAccelerometer(int16_t &tx, int16_t &ty, int16_t &tz, Orientation &rotation) {
|
||||
#ifdef ACCEL_LIS
|
||||
if (DetectedAccelerometerVersion == 2) {
|
||||
LIS2DH12::getAxisReadings(tx, ty, tz);
|
||||
rotation = LIS2DH12::getOrientation();
|
||||
} else
|
||||
if (DetectedAccelerometerVersion == 2) {
|
||||
LIS2DH12::getAxisReadings(tx, ty, tz);
|
||||
rotation = LIS2DH12::getOrientation();
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_MMA
|
||||
if (DetectedAccelerometerVersion == 1) {
|
||||
@@ -91,81 +91,81 @@ inline void readAccelerometer(int16_t &tx, int16_t &ty, int16_t &tz, Orientation
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_MSA
|
||||
if (DetectedAccelerometerVersion == 4) {
|
||||
MSA301::getAxisReadings(tx, ty, tz);
|
||||
rotation = MSA301::getOrientation();
|
||||
} else
|
||||
if (DetectedAccelerometerVersion == 4) {
|
||||
MSA301::getAxisReadings(tx, ty, tz);
|
||||
rotation = MSA301::getOrientation();
|
||||
} else
|
||||
#endif
|
||||
#ifdef ACCEL_SC7
|
||||
if (DetectedAccelerometerVersion == 5) {
|
||||
SC7A20::getAxisReadings(tx, ty, tz);
|
||||
rotation = SC7A20::getOrientation();
|
||||
} else
|
||||
if (DetectedAccelerometerVersion == 5) {
|
||||
SC7A20::getAxisReadings(tx, ty, tz);
|
||||
rotation = SC7A20::getOrientation();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
// do nothing :(
|
||||
}
|
||||
{
|
||||
// do nothing :(
|
||||
}
|
||||
}
|
||||
void startMOVTask(void const *argument __unused) {
|
||||
detectAccelerometerVersion();
|
||||
osDelay(TICKS_100MS / 2); // wait ~50ms for setup of accel to finalise
|
||||
lastMovementTime = 0;
|
||||
// Mask 2 seconds if we are in autostart so that if user is plugging in and
|
||||
// then putting in stand it doesnt wake instantly
|
||||
if (systemSettings.autoStartMode)
|
||||
osDelay(2 * TICKS_SECOND);
|
||||
detectAccelerometerVersion();
|
||||
osDelay(TICKS_100MS / 2); // wait ~50ms for setup of accel to finalise
|
||||
lastMovementTime = 0;
|
||||
// Mask 2 seconds if we are in autostart so that if user is plugging in and
|
||||
// then putting in stand it doesnt wake instantly
|
||||
if (systemSettings.autoStartMode)
|
||||
osDelay(2 * TICKS_SECOND);
|
||||
|
||||
int16_t datax[MOVFilter] = { 0 };
|
||||
int16_t datay[MOVFilter] = { 0 };
|
||||
int16_t dataz[MOVFilter] = { 0 };
|
||||
uint8_t currentPointer = 0;
|
||||
int16_t tx = 0, ty = 0, tz = 0;
|
||||
int32_t avgx, avgy, avgz;
|
||||
if (systemSettings.sensitivity > 9)
|
||||
systemSettings.sensitivity = 9;
|
||||
Orientation rotation = ORIENTATION_FLAT;
|
||||
for (;;) {
|
||||
int32_t threshold = 1500 + (9 * 200);
|
||||
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
|
||||
readAccelerometer(tx, ty, tz, rotation);
|
||||
if (systemSettings.OrientationMode == 2) {
|
||||
if (rotation != ORIENTATION_FLAT) {
|
||||
OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
|
||||
}
|
||||
}
|
||||
datax[currentPointer] = (int32_t) tx;
|
||||
datay[currentPointer] = (int32_t) ty;
|
||||
dataz[currentPointer] = (int32_t) tz;
|
||||
if (!accelInit) {
|
||||
for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) {
|
||||
datax[i] = (int32_t) tx;
|
||||
datay[i] = (int32_t) ty;
|
||||
dataz[i] = (int32_t) tz;
|
||||
}
|
||||
accelInit = 1;
|
||||
}
|
||||
currentPointer = (currentPointer + 1) % MOVFilter;
|
||||
avgx = avgy = avgz = 0;
|
||||
// calculate averages
|
||||
for (uint8_t i = 0; i < MOVFilter; i++) {
|
||||
avgx += datax[i];
|
||||
avgy += datay[i];
|
||||
avgz += dataz[i];
|
||||
}
|
||||
avgx /= MOVFilter;
|
||||
avgy /= MOVFilter;
|
||||
avgz /= MOVFilter;
|
||||
int16_t datax[MOVFilter] = {0};
|
||||
int16_t datay[MOVFilter] = {0};
|
||||
int16_t dataz[MOVFilter] = {0};
|
||||
uint8_t currentPointer = 0;
|
||||
int16_t tx = 0, ty = 0, tz = 0;
|
||||
int32_t avgx, avgy, avgz;
|
||||
if (systemSettings.sensitivity > 9)
|
||||
systemSettings.sensitivity = 9;
|
||||
Orientation rotation = ORIENTATION_FLAT;
|
||||
for (;;) {
|
||||
int32_t threshold = 1500 + (9 * 200);
|
||||
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
|
||||
readAccelerometer(tx, ty, tz, rotation);
|
||||
if (systemSettings.OrientationMode == 2) {
|
||||
if (rotation != ORIENTATION_FLAT) {
|
||||
OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
|
||||
}
|
||||
}
|
||||
datax[currentPointer] = (int32_t)tx;
|
||||
datay[currentPointer] = (int32_t)ty;
|
||||
dataz[currentPointer] = (int32_t)tz;
|
||||
if (!accelInit) {
|
||||
for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) {
|
||||
datax[i] = (int32_t)tx;
|
||||
datay[i] = (int32_t)ty;
|
||||
dataz[i] = (int32_t)tz;
|
||||
}
|
||||
accelInit = 1;
|
||||
}
|
||||
currentPointer = (currentPointer + 1) % MOVFilter;
|
||||
avgx = avgy = avgz = 0;
|
||||
// calculate averages
|
||||
for (uint8_t i = 0; i < MOVFilter; i++) {
|
||||
avgx += datax[i];
|
||||
avgy += datay[i];
|
||||
avgz += dataz[i];
|
||||
}
|
||||
avgx /= MOVFilter;
|
||||
avgy /= MOVFilter;
|
||||
avgz /= MOVFilter;
|
||||
|
||||
// Sum the deltas
|
||||
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
|
||||
// So now we have averages, we want to look if these are different by more
|
||||
// than the threshold
|
||||
// Sum the deltas
|
||||
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
|
||||
// So now we have averages, we want to look if these are different by more
|
||||
// than the threshold
|
||||
|
||||
// If movement has occurred then we update the tick timer
|
||||
if (error > threshold) {
|
||||
lastMovementTime = xTaskGetTickCount();
|
||||
}
|
||||
// If movement has occurred then we update the tick timer
|
||||
if (error > threshold) {
|
||||
lastMovementTime = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
osDelay(TICKS_100MS); // Slow down update rate
|
||||
}
|
||||
osDelay(TICKS_100MS); // Slow down update rate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,124 +5,119 @@
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include "main.hpp"
|
||||
#include "BSP.h"
|
||||
#include "power.hpp"
|
||||
#include "history.hpp"
|
||||
#include "FreeRTOS.h"
|
||||
#include "Settings.h"
|
||||
#include "TipThermoModel.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "history.hpp"
|
||||
#include "main.hpp"
|
||||
#include "power.hpp"
|
||||
#include "task.h"
|
||||
#include "Settings.h"
|
||||
static TickType_t powerPulseRate = 10000;
|
||||
static TickType_t powerPulseDuration = 250;
|
||||
TaskHandle_t pidTaskNotification = NULL;
|
||||
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
|
||||
static TickType_t powerPulseRate = 10000;
|
||||
static TickType_t powerPulseDuration = 250;
|
||||
TaskHandle_t pidTaskNotification = NULL;
|
||||
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
|
||||
|
||||
/* 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;
|
||||
/*
|
||||
* 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 (;;) {
|
||||
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
|
||||
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);
|
||||
// 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!
|
||||
// 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.
|
||||
// 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;
|
||||
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();
|
||||
// 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.
|
||||
// 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 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 (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;
|
||||
}
|
||||
}
|
||||
|
||||
//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.powerLimit && x10WattsOut > (systemSettings.powerLimit * 10)) {
|
||||
setTipX10Watts(systemSettings.powerLimit * 10);
|
||||
} else {
|
||||
setTipX10Watts(x10WattsOut);
|
||||
}
|
||||
|
||||
//Secondary safety check to forcefully disable header when within ADC noise of top of ADC
|
||||
if (getTipRawTemp(0) > (0x7FFF - 150)) {
|
||||
x10WattsOut = 0;
|
||||
}
|
||||
if (systemSettings.powerLimit
|
||||
&& x10WattsOut > (systemSettings.powerLimit * 10)) {
|
||||
setTipX10Watts(systemSettings.powerLimit * 10);
|
||||
} else {
|
||||
setTipX10Watts(x10WattsOut);
|
||||
}
|
||||
|
||||
resetWatchdog();
|
||||
} else {
|
||||
//ADC interrupt timeout
|
||||
setTipPWM(0);
|
||||
}
|
||||
}
|
||||
resetWatchdog();
|
||||
} else {
|
||||
// ADC interrupt timeout
|
||||
setTipPWM(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
// Small worker thread to handle power (mostly QC) related steps
|
||||
|
||||
void startPOWTask(void const *argument __unused) {
|
||||
postRToSInit();
|
||||
for (;;) {
|
||||
osDelay(TICKS_100MS); // Slow down update rate
|
||||
power_check();
|
||||
}
|
||||
postRToSInit();
|
||||
for (;;) {
|
||||
osDelay(TICKS_100MS); // Slow down update rate
|
||||
power_check();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user