Pull out more QC hooks

This commit is contained in:
Ben V. Brown
2020-05-30 12:05:11 +10:00
parent 2bcebd473e
commit 5bb85a4a32
6 changed files with 739 additions and 782 deletions

View File

@@ -1,8 +1,8 @@
#include "Defines.h"
#include "stdint.h"
#include "UnitSettings.h"
#include "BSP_QC.h"
#include "BSP_Flash.h"
#include "BSP_QC.h"
#include "Defines.h"
#include "UnitSettings.h"
#include "stdint.h"
/*
* BSP.h -- Board Support
*
@@ -15,20 +15,20 @@
extern "C" {
#endif
//Called first thing in main() to init the hardware
// Called first thing in main() to init the hardware
void preRToSInit();
//Called once the RToS has started for any extra work
// Called once the RToS has started for any extra work
void postRToSInit();
// Called to reset the hardware watchdog unit
void resetWatchdog();
//Accepts a output level of 0.. to use to control the tip output PWM
// Accepts a output level of 0.. to use to control the tip output PWM
void setTipPWM(uint8_t pulse);
//Returns the Handle temp in C, X10
// Returns the Handle temp in C, X10
uint16_t getHandleTemperature();
//Returns the Tip temperature ADC reading in raw units
// Returns the Tip temperature ADC reading in raw units
uint16_t getTipRawTemp(uint8_t refresh);
//Returns the main DC input voltage, using the adjustable divisor + sample flag
// Returns the main DC input voltage, using the adjustable divisor + sample flag
uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample);
// Readers for the two buttons
@@ -40,11 +40,11 @@ uint8_t getButtonB();
// This should toggle the SCL line until SDA goes high to end the current transaction
void unstick_I2C();
//Reboot the IC when things go seriously wrong
// Reboot the IC when things go seriously wrong
void reboot();
//If the user has programmed in a bootup logo, draw it to the screen from flash
//Returns 1 if the logo was printed so that the unit waits for the timeout or button
// If the user has programmed in a bootup logo, draw it to the screen from flash
// Returns 1 if the logo was printed so that the unit waits for the timeout or button
uint8_t showBootLogoIfavailable();
void delay_ms(uint16_t count);

View File

@@ -32,6 +32,9 @@ void QC_Post_Probe_En();
// Check if DM was pulled down
// 1=Pulled down, 0 == pulled high
uint8_t QC_DM_PulledDown();
// Re-sync if required
void QC_resync();
#ifdef __cplusplus
}
#endif

View File

@@ -6,6 +6,8 @@
*/
#include "BSP.h"
#include "Pins.h"
#include "QC3.h"
#include "Settings.h"
#include "stm32f1xx_hal.h"
void QC_DPlusZero_Six() {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); // pull down D+
@@ -63,3 +65,10 @@ void QC_Post_Probe_En() {
}
uint8_t QC_DM_PulledDown() { return HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET ? 1 : 0; }
void QC_resync() {
#ifdef MODEL_TS80
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // Run the QC seek again if we have drifted too much
#endif
}

View File

@@ -0,0 +1,23 @@
#include "BSP.h"
#include "FreeRTOS.h"
#include "QC3.h"
#include "Settings.h"
#include "cmsis_os.h"
#include "main.hpp"
#include "power.hpp"
#include "stdlib.h"
#include "task.h"
void postRToSInit() {
#ifdef MODEL_TS80
startQC(systemSettings.voltageDiv);
while (pidTaskNotification == 0) osDelay(30); // Wait for PID to start
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // this will move the QC output to the preferred voltage to start with
#else
while (pidTaskNotification == 0) osDelay(30); // Wait for PID to start
osDelay(200); // wait for accelerometer to stabilize
#endif
}

View File

@@ -9,19 +9,20 @@ extern "C" {
}
#include <MMA8652FC.hpp>
#include <gui.hpp>
#include <main.hpp>
#include "LIS2DH12.hpp"
#include <history.hpp>
#include <main.hpp>
#include <power.hpp>
#include "../../configuration.h"
#include "Buttons.hpp"
#include "LIS2DH12.hpp"
#include "Settings.h"
#include "TipThermoModel.h"
#include "Translation.h"
#include "cmsis_os.h"
#include "stdlib.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;
@@ -32,8 +33,8 @@ extern osThreadId GUITaskHandle;
extern osThreadId MOVTaskHandle;
extern osThreadId PIDTaskHandle;
#define MOVEMENT_INACTIVITY_TIME (60*configTICK_RATE_HZ)
#define BUTTON_INACTIVITY_TIME (60*configTICK_RATE_HZ)
#define MOVEMENT_INACTIVITY_TIME (60 * configTICK_RATE_HZ)
#define BUTTON_INACTIVITY_TIME (60 * configTICK_RATE_HZ)
static uint16_t min(uint16_t a, uint16_t b) {
if (a > b)
@@ -62,26 +63,26 @@ void gui_drawTipTemp(bool symbol) {
if (systemSettings.temperatureInF)
Temp = TipThermoModel::getTipInF();
else
#endif
#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
// Big font, can draw nice symbols
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
else
#endif
#endif
OLED::drawSymbol(1);
} else {
//Otherwise fall back to chars
// Otherwise fall back to chars
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
OLED::print(SymbolDegF);
else
#endif
#endif
OLED::print(SymbolDegC);
}
}
@@ -92,7 +93,7 @@ void gui_drawTipTemp(bool symbol) {
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
// 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();
@@ -126,15 +127,12 @@ 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;
uint32_t cellV = getInputVoltageX10(systemSettings.voltageDiv, 0)
/ cellCount;
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;
if (cellV < 33) cellV = 33;
cellV -= 33; // Should leave us a number of 0-9
if (cellV > 9)
cellV = 9;
if (cellV > 9) cellV = 9;
OLED::drawBattery(cellV + 1);
} else
OLED::drawSymbol(15); // Draw the DC Logo
@@ -169,8 +167,7 @@ static void gui_solderingTempAdjust() {
OLED::clearScreen();
OLED::setFont(0);
ButtonState buttons = getButtonState();
if (buttons)
lastChange = xTaskGetTickCount();
if (buttons) lastChange = xTaskGetTickCount();
switch (buttons) {
case BUTTON_NONE:
// stay
@@ -180,14 +177,11 @@ static void gui_solderingTempAdjust() {
return;
break;
case BUTTON_B_LONG:
if (xTaskGetTickCount() - autoRepeatTimer
+ autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) {
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp +=
systemSettings.TempChangeLongStep;
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
} else
systemSettings.SolderingTemp -=
systemSettings.TempChangeLongStep;
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
autoRepeatTimer = xTaskGetTickCount();
autoRepeatAcceleration += PRESS_ACCEL_STEP;
@@ -195,73 +189,54 @@ static void gui_solderingTempAdjust() {
break;
case BUTTON_B_SHORT:
if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp +=
systemSettings.TempChangeShortStep;
systemSettings.SolderingTemp += systemSettings.TempChangeShortStep;
} else
systemSettings.SolderingTemp -=
systemSettings.TempChangeShortStep;
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep;
break;
case BUTTON_F_LONG:
if (xTaskGetTickCount() - autoRepeatTimer
+ autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) {
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp -=
systemSettings.TempChangeLongStep;
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
} else
systemSettings.SolderingTemp +=
systemSettings.TempChangeLongStep;
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
autoRepeatTimer = xTaskGetTickCount();
autoRepeatAcceleration += PRESS_ACCEL_STEP;
}
break;
case BUTTON_F_SHORT:
if (systemSettings.ReverseButtonTempChangeEnabled) {
systemSettings.SolderingTemp -=
systemSettings.TempChangeShortStep; // add 10
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep; // add 10
} else
systemSettings.SolderingTemp +=
systemSettings.TempChangeShortStep; // add 10
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;
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 > 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 (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
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);
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus);
} else {
OLED::print(
systemSettings.ReverseButtonTempChangeEnabled ?
SymbolMinus : SymbolPlus);
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus);
}
OLED::print(SymbolSpace);
@@ -270,7 +245,7 @@ static void gui_solderingTempAdjust() {
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
else
#endif
#endif
{
OLED::drawSymbol(1);
}
@@ -280,13 +255,9 @@ static void gui_solderingTempAdjust() {
#else
if (OLED::getRotation()) {
#endif
OLED::print(
systemSettings.ReverseButtonTempChangeEnabled ?
SymbolMinus : SymbolPlus);
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus);
} else {
OLED::print(
systemSettings.ReverseButtonTempChangeEnabled ?
SymbolPlus : SymbolMinus);
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus);
}
OLED::refresh();
GUIDelay();
@@ -298,29 +269,18 @@ static int gui_SolderingSleepingMode(bool stayOff) {
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
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
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));
currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(systemSettings.SleepTemp, systemSettings.SolderingTemp));
} else
#endif
{
currentTempTargetDegC =
stayOff ?
0 :
min(systemSettings.SleepTemp,
systemSettings.SolderingTemp);
currentTempTargetDegC = stayOff ? 0 : min(systemSettings.SleepTemp, systemSettings.SolderingTemp);
}
// draw the lcd
uint16_t tipTemp;
@@ -368,8 +328,7 @@ static int gui_SolderingSleepingMode(bool stayOff) {
}
if (systemSettings.ShutdownTime) // only allow shutdown exit if time > 0
if (lastMovementTime)
if (((uint32_t) (xTaskGetTickCount() - lastMovementTime))
> (uint32_t) (systemSettings.ShutdownTime * 60 * 100)) {
if (((uint32_t)(xTaskGetTickCount() - lastMovementTime)) > (uint32_t)(systemSettings.ShutdownTime * 60 * 100)) {
// shutdown
currentTempTargetDegC = 0;
return 1; // we want to exit soldering mode
@@ -385,9 +344,7 @@ 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 lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime;
int downCount = sleepThres - xTaskGetTickCount() + lastEventTime;
if (downCount > 9900) {
OLED::printNumber(downCount / 6000 + 1, 2);
@@ -426,7 +383,6 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
}
}
for (;;) {
ButtonState buttons = getButtonState();
switch (buttons) {
case BUTTON_NONE:
@@ -442,8 +398,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
break;
case BUTTON_F_LONG:
// if boost mode is enabled turn it on
if (systemSettings.boostModeEnabled)
boostModeOn = true;
if (systemSettings.boostModeEnabled) boostModeOn = true;
break;
case BUTTON_F_SHORT:
case BUTTON_B_SHORT: {
@@ -452,8 +407,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
if (oldTemp != systemSettings.SolderingTemp) {
saveSettings(); // only save on change
}
}
break;
} break;
default:
break;
}
@@ -461,7 +415,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::setCursor(0, 0);
OLED::clearScreen();
OLED::setFont(0);
//Draw in the screen details
// Draw in the screen details
if (systemSettings.detailedSoldering) {
OLED::setFont(1);
OLED::print(SolderingAdvancedPowerPrompt); // Power:
@@ -477,7 +431,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
OLED::setCursor(0, 8);
OLED::print(SleepingTipAdvancedString);
//OLED::printNumber(
// OLED::printNumber(
// TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0)), 5); // Draw the tip temp out finally
gui_drawTipTemp(true);
@@ -524,8 +478,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
if (boostModeOn) {
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
currentTempTargetDegC = TipThermoModel::convertFtoC(
systemSettings.BoostTemp);
currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.BoostTemp);
else
#endif
{
@@ -534,8 +487,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
} else {
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
currentTempTargetDegC = TipThermoModel::convertFtoC(
systemSettings.SolderingTemp);
currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.SolderingTemp);
else
#endif
{
@@ -559,13 +511,12 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
#endif
if (systemSettings.sensitivity && systemSettings.SleepTime)
if (xTaskGetTickCount() - lastMovementTime > sleepThres
&& xTaskGetTickCount() - lastButtonTime > sleepThres) {
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
// slow down ui update rate
GUIDelay();
}
}
@@ -581,48 +532,47 @@ void showDebugMenu(void) {
OLED::setCursor(0, 8); // second line
OLED::print(DebugMenu[screen]);
switch (screen) {
case 0: //Just prints date
case 0: // Just prints date
break;
case 1:
//High water mark for GUI
// High water mark for GUI
OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5);
break;
case 2:
//High water mark for the Movement task
// High water mark for the Movement task
OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5);
break;
case 3:
//High water mark for the PID task
// High water mark for the PID task
OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5);
break;
case 4:
//system up time stamp
// system up time stamp
OLED::printNumber(xTaskGetTickCount() / 100, 5);
break;
case 5:
//Movement time stamp
// Movement time stamp
OLED::printNumber(lastMovementTime / 100, 5);
break;
case 6:
//Raw Tip
// Raw Tip
{
uint32_t temp = systemSettings.CalibrationOffset;
systemSettings.CalibrationOffset = 0;
OLED::printNumber(
TipThermoModel::convertTipRawADCTouV(getTipRawTemp(1)), 6);
OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(1)), 6);
systemSettings.CalibrationOffset = temp;
}
break;
case 7:
//Temp in C
// Temp in C
OLED::printNumber(TipThermoModel::getTipInC(1), 5);
break;
case 8:
//Handle Temp
// Handle Temp
OLED::printNumber(getHandleTemperature(), 3);
break;
case 9:
//Voltage input
// Voltage input
printVoltage();
break;
case 10:
@@ -656,23 +606,20 @@ void startGUITask(void const *argument __unused) {
uint32_t ticks = xTaskGetTickCount();
ticks += 400; // 4 seconds from now
while (xTaskGetTickCount() < ticks) {
if (showBootLogoIfavailable() == false)
ticks = xTaskGetTickCount();
if (showBootLogoIfavailable() == false) ticks = xTaskGetTickCount();
ButtonState buttons = getButtonState();
if (buttons)
ticks = xTaskGetTickCount(); // make timeout now so we will exit
if (buttons) ticks = xTaskGetTickCount(); // make timeout now so we will exit
GUIDelay();
}
if (settingsWereReset) {
//Display alert settings were reset
// Display alert settings were reset
OLED::clearScreen();
OLED::setFont(1);
OLED::setCursor(0, 0);
OLED::print(SettingsResetMessage);
OLED::refresh();
waitForButtonPressOrTimeout(1000);
}
if (systemSettings.autoStartMode) {
@@ -695,8 +642,7 @@ void startGUITask(void const *argument __unused) {
OLED::setDisplayState(OLED::DisplayState::ON);
OLED::setFont(0);
}
if (tempWarningState == 2)
buttons = BUTTON_F_SHORT;
if (tempWarningState == 2) buttons = BUTTON_F_SHORT;
if (buttons != BUTTON_NONE && buttonLockout)
buttons = BUTTON_NONE;
else
@@ -742,11 +688,7 @@ void startGUITask(void const *argument __unused) {
// 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))) {
if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
OLED::setDisplayState(OLED::DisplayState::OFF);
}
@@ -805,9 +747,7 @@ void startGUITask(void const *argument __unused) {
OLED::setCursor(0, 0);
}
// draw in the temp
if (!(systemSettings.coolingTempBlink
&& (xTaskGetTickCount() % 25 < 16)))
gui_drawTipTemp(false); // draw in the temp
if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 25 < 16))) gui_drawTipTemp(false); // draw in the temp
}
}
OLED::refresh();

View File

@@ -5,51 +5,36 @@
* Author: Ralim
*/
#include "main.hpp"
#include "BSP.h"
#include "power.hpp"
#include "history.hpp"
#include "FreeRTOS.h"
#include "I2C_Wrapper.hpp"
#include "LIS2DH12.hpp"
#include "MMA8652FC.hpp"
#include "QC3.h"
#include "Settings.h"
#include "TipThermoModel.h"
#include "cmsis_os.h"
#include "FreeRTOS.h"
#include "task.h"
#include "Settings.h"
#include "I2C_Wrapper.hpp"
#include "history.hpp"
#include "main.hpp"
#include "power.hpp"
#include "stdlib.h"
#include "LIS2DH12.hpp"
#include <MMA8652FC.hpp>
#include "QC3.h"
#include "task.h"
#define MOVFilter 8
uint8_t accelInit = 0;
uint32_t lastMovementTime = 0;
void startMOVTask(void const *argument __unused) {
OLED::setRotation(true);
#ifdef MODEL_TS80
startQC(systemSettings.voltageDiv);
while (pidTaskNotification == 0)
osDelay(30); // To ensure we return after idealQCVoltage/tip resistance
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // this will move the QC output to the preferred voltage to start with
#else
osDelay(250); // wait for accelerometer to stabilize
#endif
postRToSInit();
OLED::setRotation(systemSettings.OrientationMode & 1);
lastMovementTime = 0;
int16_t datax[MOVFilter] = { 0 };
int16_t datay[MOVFilter] = { 0 };
int16_t dataz[MOVFilter] = { 0 };
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 = 0, avgy = 0, avgz = 0;
if (systemSettings.sensitivity > 9)
systemSettings.sensitivity = 9;
#ifdef ACCELDEBUG
uint32_t max = 0;
#endif
int32_t avgx, avgy, avgz;
if (systemSettings.sensitivity > 9) systemSettings.sensitivity = 9;
Orientation rotation = ORIENTATION_FLAT;
for (;;) {
int32_t threshold = 1500 + (9 * 200);
@@ -67,14 +52,14 @@ void startMOVTask(void const *argument __unused) {
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;
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;
datax[i] = (int32_t)tx;
datay[i] = (int32_t)ty;
dataz[i] = (int32_t)tz;
}
accelInit = 1;
}
@@ -101,9 +86,6 @@ void startMOVTask(void const *argument __unused) {
}
osDelay(100); // Slow down update rate
#ifdef MODEL_TS80
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // Run the QC seek again if we have drifted too much
#endif
QC_resync();
}
}