diff --git a/.gitignore b/.gitignore
index cd5ac8d9..939c05f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,3 +43,4 @@ Logo GUI/TS100 Logo Editor/TS100 Logo Editor/bin/
workspace/ts100/ts100.xml
workspace/ts100_old/*
*.cache
+workspace/TS100/.settings/language.settings.xml
diff --git a/workspace/TS100/.settings/language.settings.xml b/workspace/TS100/.settings/language.settings.xml
index 5bb564a4..ee99e4da 100644
--- a/workspace/TS100/.settings/language.settings.xml
+++ b/workspace/TS100/.settings/language.settings.xml
@@ -6,7 +6,7 @@
-
+
@@ -18,7 +18,7 @@
-
+
diff --git a/workspace/TS100/inc/LIS2DH12.hpp b/workspace/TS100/inc/LIS2DH12.hpp
new file mode 100644
index 00000000..c23e0712
--- /dev/null
+++ b/workspace/TS100/inc/LIS2DH12.hpp
@@ -0,0 +1,27 @@
+/*
+ * LIS2DH12.hpp
+ *
+ * Created on: 27Feb.,2018
+ * Author: Ralim
+ */
+
+#ifndef LIS2DH12_HPP_
+#define LIS2DH12_HPP_
+#include "stm32f1xx_hal.h"
+#include "LIS2DH12_defines.hpp"
+class LIS2DH12 {
+public:
+ LIS2DH12(I2C_HandleTypeDef* i2cHandle);
+ void initalize();
+ uint8_t getOrientation();
+ void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
+
+private:
+ void setSensitivity(uint8_t threshold, uint8_t filterTime); // Sets the sensitivity of the unit
+
+ void I2C_RegisterWrite(uint8_t reg, uint8_t data);
+ uint8_t I2C_RegisterRead(uint8_t reg);
+ I2C_HandleTypeDef* i2c;
+};
+
+#endif /* LIS2DH12_HPP_ */
diff --git a/workspace/TS100/inc/LIS2DH12_defines.hpp b/workspace/TS100/inc/LIS2DH12_defines.hpp
new file mode 100644
index 00000000..f317fbca
--- /dev/null
+++ b/workspace/TS100/inc/LIS2DH12_defines.hpp
@@ -0,0 +1,28 @@
+/*
+ * LIS2DH12_defines.hpp
+ *
+ * Created on: 27Feb.,2018
+ * Author: Ralim
+ */
+
+#ifndef LIS2DH12_DEFINES_HPP_
+#define LIS2DH12_DEFINES_HPP_
+
+
+#define LIS2DH_I2C_ADDRESS (25<<1)
+
+#define LIS_CTRL_REG1 0x20|0x80
+#define LIS_CTRL_REG2 0x21|0x80
+#define LIS_CTRL_REG3 0x22|0x80
+#define LIS_CTRL_REG4 0x23|0x80
+#define LIS_CTRL_REG5 0x24|0x80
+#define LIS_CTRL_REG6 0x25|0x80
+#define LIS_INT1_CFG 0xB0|0x80
+#define LIS_INT2_CFG 0xB4|0x80
+#define LIS_INT1_DURATION 0x33|0x80
+#define LIS_INT1_THS 0x32|0x80
+#define LIS_INT1_SRC 0x31|0x80
+#define LIS_INT2_DURATION 0x37|0x80
+#define LIS_INT2_THS 0x36|0x80
+#define LIS_INT2_SRC 0x35|0x80
+#endif /* LIS2DH12_DEFINES_HPP_ */
diff --git a/workspace/TS100/inc/MMA8652FC.hpp b/workspace/TS100/inc/MMA8652FC.hpp
index 0818ddf3..271ff686 100644
--- a/workspace/TS100/inc/MMA8652FC.hpp
+++ b/workspace/TS100/inc/MMA8652FC.hpp
@@ -15,7 +15,7 @@ public:
MMA8652FC(I2C_HandleTypeDef* i2cHandle);
void initalize(); // Initalize the system
- bool getOrientation();// Reads the I2C register and returns the orientation (true == left)
+ uint8_t getOrientation();// Reads the I2C register and returns the orientation (true == left)
void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
private:
diff --git a/workspace/TS100/src/LIS2DH12.cpp b/workspace/TS100/src/LIS2DH12.cpp
new file mode 100644
index 00000000..a004200e
--- /dev/null
+++ b/workspace/TS100/src/LIS2DH12.cpp
@@ -0,0 +1,73 @@
+/*
+ * LIS2DH12.cpp
+ *
+ * Created on: 27Feb.,2018
+ * Author: Ralim
+ */
+
+#include
+#include "cmsis_os.h"
+LIS2DH12::LIS2DH12(I2C_HandleTypeDef* i2cHandle) {
+ i2c = i2cHandle;
+}
+
+void LIS2DH12::initalize() {
+ I2C_RegisterWrite(LIS_CTRL_REG1, 0x17); //25Hz
+ I2C_RegisterWrite(LIS_CTRL_REG2, 0b00001000); //Highpass filter off
+ I2C_RegisterWrite(LIS_CTRL_REG3, 0b01100000); //Setup interrupt pins
+ I2C_RegisterWrite(LIS_CTRL_REG4, 0b00001000); //Block update mode off,HR on
+ I2C_RegisterWrite(LIS_CTRL_REG5, 0b00000010);
+ I2C_RegisterWrite(LIS_CTRL_REG6, 0b01100010);
+
+ //Basically setup the unit to run, and enable 4D orientation detection
+ I2C_RegisterWrite(LIS_INT2_CFG, 0b01111110); //setup for movement detection
+ I2C_RegisterWrite(LIS_INT2_THS, 0x28);
+ I2C_RegisterWrite(LIS_INT2_DURATION, 64);
+ I2C_RegisterWrite(LIS_INT1_CFG, 0b01111110); //setup for movement detection
+ I2C_RegisterWrite(LIS_INT1_THS, 0x28);
+ I2C_RegisterWrite(LIS_INT1_DURATION, 64);
+
+}
+
+//0=no change, 1= right handed, 2= left handed
+uint8_t LIS2DH12::getOrientation() {
+ // 8=right handed,4=left,16=flat
+ //So we ignore if not 8/4
+ uint8_t pos = I2C_RegisterRead(LIS_INT2_SRC);
+ if (pos == 8)
+ return 1;
+ else if (pos == 4)
+ return 2;
+ else
+ return 0;
+}
+
+void LIS2DH12::getAxisReadings(int16_t* x, int16_t* y, int16_t* z) {
+ uint8_t tempArr[6];
+ taskENTER_CRITICAL();
+ while (HAL_I2C_Mem_Read(i2c, LIS2DH_I2C_ADDRESS, 0xA8,
+ I2C_MEMADD_SIZE_8BIT, (uint8_t*) tempArr, 6, 5000) != HAL_OK) {
+ HAL_Delay(5);
+ }
+ taskEXIT_CRITICAL();
+ (*x) = ((uint16_t) (tempArr[1] << 8 | tempArr[0]));
+ (*y) = ((uint16_t) (tempArr[3] << 8 | tempArr[2]));
+ (*z) = ((uint16_t) (tempArr[5] << 8 | tempArr[4]));
+}
+
+void LIS2DH12::setSensitivity(uint8_t threshold, uint8_t filterTime) {
+}
+
+void LIS2DH12::I2C_RegisterWrite(uint8_t reg, uint8_t data) {
+
+ HAL_I2C_Mem_Write(i2c, LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data,
+ 1, 500);
+}
+
+uint8_t LIS2DH12::I2C_RegisterRead(uint8_t reg) {
+ uint8_t tx_data[1];
+ HAL_I2C_Mem_Read(i2c, LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT,
+ tx_data, 1, 500);
+
+ return tx_data[0];
+}
diff --git a/workspace/TS100/src/MMA8652FC.cpp b/workspace/TS100/src/MMA8652FC.cpp
index 678995c3..4e1b6d56 100644
--- a/workspace/TS100/src/MMA8652FC.cpp
+++ b/workspace/TS100/src/MMA8652FC.cpp
@@ -58,17 +58,20 @@ void MMA8652FC::setSensitivity(uint8_t threshold, uint8_t filterTime) {
taskEXIT_CRITICAL();
}
-bool MMA8652FC::getOrientation() {
- //First read the PL_STATUS registertaskENTER_CRITICAL();
+uint8_t MMA8652FC::getOrientation() {
+ //First read the PL_STATUS register
taskENTER_CRITICAL();
uint8_t plStatus = I2C_RegisterRead(PL_STATUS_REG);
taskEXIT_CRITICAL();
- plStatus >>= 1; //We don't need the up/down bit
- plStatus &= 0x03; //mask to the two lower bits
- //0 == left handed
- //1 == right handed
+ 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 !plStatus;
+ return plStatus==0?2:1;
+ } else
+ return 0;
}
void MMA8652FC::getAxisReadings(int16_t *x, int16_t *y, int16_t *z) {
uint8_t tempArr[6];
diff --git a/workspace/TS100/src/Setup.c b/workspace/TS100/src/Setup.c
index 858a8b5c..51e7c772 100644
--- a/workspace/TS100/src/Setup.c
+++ b/workspace/TS100/src/Setup.c
@@ -165,7 +165,7 @@ static void MX_IWDG_Init(void) {
hiwdg.Instance = IWDG;
hiwdg.Init.Prescaler = IWDG_PRESCALER_256;
- hiwdg.Init.Reload = 4095;
+ hiwdg.Init.Reload = 50;
HAL_IWDG_Init(&hiwdg);
}
diff --git a/workspace/TS100/src/gui.cpp b/workspace/TS100/src/gui.cpp
index f3709361..8c4e3faa 100644
--- a/workspace/TS100/src/gui.cpp
+++ b/workspace/TS100/src/gui.cpp
@@ -103,13 +103,13 @@ static void printShortDescription(uint32_t shortDescIndex,
static int userConfirmation(const char* message) {
uint8_t maxOffset = strlen(message) + 7;
- uint32_t messageStart = HAL_GetTick();
+ uint32_t messageStart = xTaskGetTickCount();
lcd.setFont(0);
lcd.setCursor(0, 0);
for (;;) {
- int16_t messageOffset = (((HAL_GetTick() - messageStart) / 150) % maxOffset);
+ int16_t messageOffset = (((xTaskGetTickCount() - messageStart) / 15) % maxOffset);
lcd.clearScreen();
lcd.setCursor(12 * (7 - messageOffset), 0);
@@ -329,7 +329,7 @@ static void settings_setResetSettings(void) {
lcd.print("RESET OK");
lcd.refresh();
- waitForButtonPressOrTimeout(2000);
+ waitForButtonPressOrTimeout(200);
}
}
diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp
index 8056f2a9..5ef21e3c 100644
--- a/workspace/TS100/src/main.cpp
+++ b/workspace/TS100/src/main.cpp
@@ -9,12 +9,13 @@
#include "stdlib.h"
#include "stm32f1xx_hal.h"
#include "string.h"
+#include "LIS2DH12.hpp"
-//#define I2CTest
#define ACCELDEBUG 0
// C++ objects
OLED lcd(&hi2c1);
MMA8652FC accel(&hi2c1);
+LIS2DH12 accel2(&hi2c1);
uint8_t PCBVersion = 0;
// File local variables
uint16_t currentlyActiveTemperatureTarget = 0;
@@ -46,38 +47,21 @@ int main(void) {
lcd.setFont(0); // default to bigger font
//Testing for new weird board version
uint8_t buffer[1];
- if (HAL_I2C_Mem_Read(&hi2c1, 29 << 1, 0, 0, buffer, 1, 1000) == HAL_OK) {
+ if (HAL_I2C_Mem_Read(&hi2c1, 29 << 1, 0x0F, I2C_MEMADD_SIZE_8BIT, buffer, 1,
+ 1000) == HAL_OK) {
PCBVersion = 1;
accel.initalize(); // this sets up the I2C registers and loads up the default
// settings
- } else
+ } else {
PCBVersion = 2;
-
+ //Setup the ST Accelerometer
+ accel2.initalize(); //startup the accelerometer
+ }
HAL_IWDG_Refresh(&hiwdg);
restoreSettings(); // load the settings from flash
setCalibrationOffset(systemSettings.CalibrationOffset);
HAL_IWDG_Refresh(&hiwdg);
-#ifdef I2CTest
- for (;;) {
- //We dont load the RTOS here, and test stuff instead
- //Scan all of the I2C address space and see who answers
- lcd.setFont(1);
- lcd.clearScreen();
- if (HAL_I2C_Mem_Read(&hi2c1, 25 << 1, 0x00, 0, buffer, 1, 1000)
- == HAL_OK) {
- //this ID was okay
- lcd.printNumber(buffer[0], 3);
- lcd.print(".");
- lcd.refresh();
- }
- for (;;) {
- //hang out here
- }
- }
-
-#endif
-
/* Create the thread(s) */
/* definition and creation of GUITask */
osThreadDef(GUITask, startGUITask, osPriorityBelowNormal, 0, 512);
@@ -137,7 +121,7 @@ ButtonState getButtonState() {
*/
static uint8_t previousState = 0;
static uint32_t previousStateChange = 0;
- const uint16_t timeout = 400;
+ const uint16_t timeout = 40;
uint8_t currentState;
currentState = (
HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ?
@@ -147,11 +131,11 @@ ButtonState getButtonState() {
1 : 0) << 1;
if (currentState)
- lastButtonTime = HAL_GetTick();
+ lastButtonTime = xTaskGetTickCount();
if (currentState == previousState) {
if (currentState == 0)
return BUTTON_NONE;
- if ((HAL_GetTick() - previousStateChange) > timeout) {
+ if ((xTaskGetTickCount() - previousStateChange) > timeout) {
// User has been holding the button down
// We want to send a buttong is held message
if (currentState == 0x01)
@@ -172,7 +156,7 @@ ButtonState getButtonState() {
// 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 ((HAL_GetTick() - previousStateChange) < timeout) {
+ if ((xTaskGetTickCount() - previousStateChange) < timeout) {
// The user didn't hold the button for long
// So we send button press
@@ -185,7 +169,7 @@ ButtonState getButtonState() {
}
}
previousState = currentState;
- previousStateChange = HAL_GetTick();
+ previousStateChange = xTaskGetTickCount();
return retVal;
}
return BUTTON_NONE;
@@ -208,13 +192,13 @@ static void waitForButtonPress() {
}
void waitForButtonPressOrTimeout(uint32_t timeout) {
- timeout += HAL_GetTick();
+ timeout += xTaskGetTickCount();
// Make timeout our exit value
for (;;) {
ButtonState buttons = getButtonState();
if (buttons)
return;
- if (HAL_GetTick() > timeout)
+ if (xTaskGetTickCount() > timeout)
return;
GUIDelay();
}
@@ -269,7 +253,7 @@ static void gui_drawBatteryIcon() {
lcd.drawSymbol(16); // Draw the DC Logo
}
static void gui_solderingTempAdjust() {
- uint32_t lastChange = HAL_GetTick();
+ uint32_t lastChange = xTaskGetTickCount();
currentlyActiveTemperatureTarget = 0;
for (;;) {
lcd.setCursor(0, 0);
@@ -277,7 +261,7 @@ static void gui_solderingTempAdjust() {
lcd.setFont(0);
ButtonState buttons = getButtonState();
if (buttons)
- lastChange = HAL_GetTick();
+ lastChange = xTaskGetTickCount();
switch (buttons) {
case BUTTON_NONE:
// stay
@@ -326,7 +310,7 @@ static void gui_solderingTempAdjust() {
systemSettings.SolderingTemp = 50;
}
- if (HAL_GetTick() - lastChange > 1500)
+ if (xTaskGetTickCount() - lastChange > 200)
return; // exit if user just doesn't press anything for a bit
lcd.drawChar('<');
lcd.drawChar(' ');
@@ -353,7 +337,7 @@ static void gui_settingsMenu() {
lcd.clearScreen();
lcd.setCursor(0, 0);
- if (HAL_GetTick() - lastButtonTime < 4000) {
+ if (xTaskGetTickCount() - lastButtonTime < 400) {
settingsMenu[currentScreen].draw.func();
} else {
@@ -364,11 +348,12 @@ static void gui_settingsMenu() {
if (descriptionStart == 0)
descriptionStart = HAL_GetTick();
- int16_t descriptionOffset =
- (((HAL_GetTick() - descriptionStart) / 3) % (maxOffset * 12));
+ int16_t descriptionOffset = ((((HAL_GetTick() - descriptionStart)
+ / 10) % (maxOffset * 3))) * 4;
//^ Rolling offset based on time
lcd.setCursor(((7 * 12) - descriptionOffset), 0);
lcd.print(settingsMenu[currentScreen].description);
+
}
ButtonState buttons = getButtonState();
@@ -392,16 +377,16 @@ static void gui_settingsMenu() {
descriptionStart = 0;
break;
case BUTTON_F_LONG:
- if (HAL_GetTick() - autoRepeatTimer > 200) {
+ if (xTaskGetTickCount() - autoRepeatTimer > 30) {
settingsMenu[currentScreen].incrementHandler.func();
- autoRepeatTimer = HAL_GetTick();
+ autoRepeatTimer = xTaskGetTickCount();
descriptionStart = 0;
}
break;
case BUTTON_B_LONG:
- if (HAL_GetTick() - autoRepeatTimer > 200) {
+ if (xTaskGetTickCount() - autoRepeatTimer > 30) {
currentScreen++;
- autoRepeatTimer = HAL_GetTick();
+ autoRepeatTimer = xTaskGetTickCount();
descriptionStart = 0;
}
break;
@@ -450,7 +435,7 @@ static int gui_showTipTempWarning() {
}
}
if (systemSettings.coolingTempBlink && tipTemp > 70) {
- if (HAL_GetTick() % 500 < 250)
+ if (xTaskGetTickCount() % 50 < 25)
lcd.clearScreen();
}
lcd.refresh();
@@ -480,8 +465,8 @@ static int gui_SolderingSleepingMode() {
ButtonState buttons = getButtonState();
if (buttons)
return 0;
- if ((HAL_GetTick() - lastMovementTime < 1000)
- || (HAL_GetTick() - lastButtonTime < 1000))
+ if ((xTaskGetTickCount() - lastMovementTime < 100)
+ || (xTaskGetTickCount() - lastButtonTime < 100))
return 0; // user moved or pressed a button, go back to soldering
if (checkVoltageForExit())
return 1; // return non-zero on error
@@ -532,8 +517,8 @@ static int gui_SolderingSleepingMode() {
}
if (systemSettings.ShutdownTime) // only allow shutdown exit if time > 0
if (lastMovementTime)
- if (((uint32_t) (HAL_GetTick() - lastMovementTime))
- > (uint32_t) (systemSettings.ShutdownTime * 60 * 1000)) {
+ if (((uint32_t) (xTaskGetTickCount() - lastMovementTime))
+ > (uint32_t) (systemSettings.ShutdownTime * 60 * 100)) {
// shutdown
currentlyActiveTemperatureTarget = 0;
return 1; // we want to exit soldering mode
@@ -560,9 +545,9 @@ static void gui_solderingMode() {
bool boostModeOn = false;
uint32_t sleepThres = 0;
if (systemSettings.SleepTime < 6)
- sleepThres = systemSettings.SleepTime * 10 * 1000;
+ sleepThres = systemSettings.SleepTime * 10 * 100;
else
- sleepThres = (systemSettings.SleepTime - 5) * 60 * 1000;
+ sleepThres = (systemSettings.SleepTime - 5) * 60 * 100;
for (;;) {
uint16_t tipTemp = getTipRawTemp(0);
@@ -685,8 +670,8 @@ static void gui_solderingMode() {
lcd.refresh();
if (systemSettings.sensitivity)
- if (HAL_GetTick() - lastMovementTime > sleepThres
- && HAL_GetTick() - lastButtonTime > sleepThres) {
+ if (xTaskGetTickCount() - lastMovementTime > sleepThres
+ && xTaskGetTickCount() - lastButtonTime > sleepThres) {
if (gui_SolderingSleepingMode()) {
return; // If the function returns non-0 then exit
}
@@ -735,14 +720,24 @@ void startGUITask(void const *argument) {
default:
break;
}
- if (showBootLogoIfavailable())
- waitForButtonPressOrTimeout(2000);
+ uint32_t ticks = xTaskGetTickCount();
+ ticks += 400; //4 seconds
+ while (xTaskGetTickCount() < ticks) {
+ if (showBootLogoIfavailable() == false)
+ ticks = xTaskGetTickCount();
+ ButtonState buttons = getButtonState();
+ if (buttons)
+ ticks = xTaskGetTickCount();
+ GUIDelay();
+ }
+
HAL_IWDG_Refresh(&hiwdg);
if (systemSettings.autoStartMode) {
// jump directly to the autostart mode
if (systemSettings.autoStartMode == 1)
gui_solderingMode();
}
+
#if ACCELDEBUG
for (;;) {
@@ -751,7 +746,6 @@ void startGUITask(void const *argument) {
}
//^ Kept here for a way to block this thread
#endif
-//Show warning : No accel
for (;;) {
ButtonState buttons = getButtonState();
@@ -804,11 +798,11 @@ void startGUITask(void const *argument) {
uint16_t tipTemp = tipMeasurementToC(getTipRawTemp(0));
if (tipTemp > 50)
if (systemSettings.sensitivity) {
- if ((HAL_GetTick() - lastMovementTime) > 60000
- && (HAL_GetTick() - lastButtonTime) > 60000)
+ if ((xTaskGetTickCount() - lastMovementTime) > 6000
+ && (xTaskGetTickCount() - lastButtonTime) > 6000)
lcd.displayOnOff(false); // turn lcd off when no movement
- else if (HAL_GetTick() - lastMovementTime < 1000
- || HAL_GetTick() - lastButtonTime < 1000) /*Use short time for test, and prevent lots of I2C
+ else if (xTaskGetTickCount() - lastMovementTime < 100
+ || xTaskGetTickCount() - lastButtonTime < 100) /*Use short time for test, and prevent lots of I2C
writes for no need*/
lcd.displayOnOff(true); // turn lcd back on
}
@@ -950,15 +944,7 @@ void startPIDTask(void const *argument) {
#define MOVFilter 8
void startMOVTask(void const *argument) {
osDelay(4000); // wait for accel to stabilize
- if (PCBVersion == 2) {
- //on PCB rev 2, accel does not work yet.
- //So trigger wakeup timer events so the iron doesnt randomly sleep on people
- for (;;) {
- osDelay(1000);
- lastMovementTime = HAL_GetTick();
- }
- }
int16_t datax[MOVFilter];
int16_t datay[MOVFilter];
int16_t dataz[MOVFilter];
@@ -977,7 +963,10 @@ void startMOVTask(void const *argument) {
for (;;) {
int32_t threshold = 1200 + (9 * 200);
threshold -= systemSettings.sensitivity * 200; // 200 is the step size
- accel.getAxisReadings(&tx, &ty, &tz);
+ if (PCBVersion == 2)
+ accel2.getAxisReadings(&tx, &ty, &tz);
+ else
+ accel.getAxisReadings(&tx, &ty, &tz);
datax[currentPointer] = (int32_t) tx;
datay[currentPointer] = (int32_t) ty;
@@ -997,18 +986,19 @@ void startMOVTask(void const *argument) {
avgz /= MOVFilter;
lcd.setFont(1);
lcd.setCursor(0, 0);
- lcd.printNumber(abs(avgx - (int32_t)tx), 5);
+ lcd.printNumber(abs(avgx - (int32_t) tx), 5);
lcd.print(" ");
- lcd.printNumber(abs(avgy - (int32_t)ty), 5);
+ lcd.printNumber(abs(avgy - (int32_t) ty), 5);
if ((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)) > max)
- max = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
+ max = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
lcd.setCursor(0, 8);
lcd.printNumber(max, 5);
lcd.print(" ");
lcd.printNumber((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)), 5);
lcd.refresh();
- if (HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET) max = 0;
+ if (HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET)
+ max = 0;
#endif
// Only run the actual processing if the sensitivity is set (aka we are
// enabled)
@@ -1029,7 +1019,7 @@ void startMOVTask(void const *argument) {
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz));
// If error has occured then we update the tick timer
if (error > threshold) {
- lastMovementTime = HAL_GetTick();
+ lastMovementTime = xTaskGetTickCount();
}
}
@@ -1056,43 +1046,23 @@ void startRotationTask(void const *argument) {
break;
}
osDelay(500); // wait for accel to stabilize
- if (PCBVersion == 2) {
- //Accelerometer not supported yet
- //Disable this feature for now :(
- for (;;) {
- osDelay(1000);
- }
- }
- HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI3_IRQn);
- HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
- //^ We hold off enabling these until now to ensure the semaphore is available
- // to be used first
for (;;) {
- if (xSemaphoreTake(rotationChangedSemaphore, portMAX_DELAY) == pdTRUE
- || (HAL_GPIO_ReadPin(INT_Orientation_GPIO_Port,
- INT_Orientation_Pin) == GPIO_PIN_RESET)) {
- // a rotation event has occured
- bool rotation = accel.getOrientation();
- if (systemSettings.OrientationMode == 2)
- lcd.setRotation(rotation); // link the data through
- }
- osDelay(300);
- }
-}
-// Handler called by HAL when a EXTI occurs, but after IRQ bit is cleared
-void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
- static signed long xHigherPriorityTaskWoken;
- if (GPIO_Pin == INT_Orientation_Pin) {
- xSemaphoreGiveFromISR(rotationChangedSemaphore,
- &xHigherPriorityTaskWoken);
- } else if (GPIO_Pin == INT_Movement_Pin) {
- // New data is available for reading from the unit
- // xSemaphoreGiveFromISR(accelDataAvailableSemaphore,
- // &xHigherPriorityTaskWoken);
+ // a rotation event has occurred
+ uint8_t rotation;
+ if (PCBVersion == 2) {
+ rotation = accel2.getOrientation();
+ } else {
+ rotation = accel.getOrientation();
+ }
+ if (systemSettings.OrientationMode == 2) {
+ if (rotation != 0) {
+ lcd.setRotation(rotation == 2); // link the data through
+ }
+ }
+
+ osDelay(500);
}
}