1
0
forked from me/IronOS

Fix build for MSA

This commit is contained in:
Ben V. Brown
2021-01-04 21:37:04 +11:00
parent cfb92396c2
commit a5a7463178
3 changed files with 95 additions and 98 deletions

View File

@@ -34,8 +34,9 @@ Orientation MSA301::getOrientation() {
return Orientation::ORIENTATION_LEFT_HAND; return Orientation::ORIENTATION_LEFT_HAND;
case 96: case 96:
return Orientation::ORIENTATION_RIGHT_HAND; return Orientation::ORIENTATION_RIGHT_HAND;
default:
return Orientation::ORIENTATION_FLAT;
} }
return Orientation::ORIENTATION_FLAT;
} }
void MSA301::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) { void MSA301::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {

View File

@@ -394,8 +394,8 @@ static void display_countdown(int sleepThres) {
* mode is triggered. * mode is triggered.
*/ */
int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime; int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime;
int downCount = sleepThres - xTaskGetTickCount() + lastEventTime; TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime;
if (downCount > 99000) { if (downCount > (99 * TICKS_SECOND)) {
OLED::printNumber(downCount / 60000 + 1, 2); OLED::printNumber(downCount / 60000 + 1, 2);
OLED::print(SymbolMinutes); OLED::print(SymbolMinutes);
} else { } else {
@@ -645,10 +645,10 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
void showDebugMenu(void) { void showDebugMenu(void) {
uint8_t screen = 0; uint8_t screen = 0;
ButtonState b; ButtonState b;
OLED::setFont(1); // small font
for (;;) { for (;;) {
OLED::clearScreen(); // Ensure the buffer starts clean OLED::clearScreen(); // Ensure the buffer starts clean
OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) 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::print(SymbolVersionNumber); // Print version number
OLED::setCursor(0, 8); // second line OLED::setCursor(0, 8); // second line
OLED::print(DebugMenu[screen]); OLED::print(DebugMenu[screen]);
@@ -717,7 +717,6 @@ void showDebugMenu(void) {
} }
#endif #endif
if (poweredbyPD) { if (poweredbyPD) {
OLED::printNumber(2, 1); OLED::printNumber(2, 1);
} else { } else {

View File

@@ -25,51 +25,49 @@
uint8_t accelInit = 0; uint8_t accelInit = 0;
TickType_t lastMovementTime = 0; TickType_t lastMovementTime = 0;
void detectAccelerometerVersion() { void detectAccelerometerVersion() {
PCBVersion = 99; DetectedAccelerometerVersion = 99;
#ifdef ACCEL_MMA #ifdef ACCEL_MMA
if (MMA8652FC::detect()) { if (MMA8652FC::detect()) {
if (MMA8652FC::initalize()) { if (MMA8652FC::initalize()) {
PCBVersion = 1; DetectedAccelerometerVersion = 1;
} }
} else } else
#endif #endif
#ifdef ACCEL_LIS #ifdef ACCEL_LIS
if (LIS2DH12::detect()) { if (LIS2DH12::detect()) {
// Setup the ST Accelerometer // Setup the ST Accelerometer
if (LIS2DH12::initalize()) { if (LIS2DH12::initalize()) {
PCBVersion = 2; DetectedAccelerometerVersion = 2;
} }
} else } else
#endif #endif
#ifdef ACCEL_BMA #ifdef ACCEL_BMA
if (BMA223::detect()) { if (BMA223::detect()) {
// Setup the ST Accelerometer // Setup the ST Accelerometer
if (BMA223::initalize()) { if (BMA223::initalize()) {
PCBVersion = 3; DetectedAccelerometerVersion = 3;
} }
} else } else
#endif #endif
#ifdef ACCEL_MSA #ifdef ACCEL_MSA
if (MSA301::detect()) { if (MSA301::detect()) {
// Setup the MSA301 Accelerometer // Setup the MSA301 Accelerometer
if (MSA301::initalize()) { if (MSA301::initalize()) {
PCBVersion = 4; DetectedAccelerometerVersion = 4;
} }
} else } else
#endif #endif
{ {
// disable imu sensitivity // disable imu sensitivity
systemSettings.sensitivity = 0; systemSettings.sensitivity = 0;
} }
} }
inline void readAccelerometer(int16_t &tx, int16_t &ty, int16_t &tz, inline void readAccelerometer(int16_t &tx, int16_t &ty, int16_t &tz, Orientation &rotation) {
Orientation &rotation) {
#ifdef ACCEL_LIS #ifdef ACCEL_LIS
if (DetectedAccelerometerVersion == 2) { if (DetectedAccelerometerVersion == 2) {
LIS2DH12::getAxisReadings(tx, ty, tz); LIS2DH12::getAxisReadings(tx, ty, tz);
rotation = LIS2DH12::getOrientation(); rotation = LIS2DH12::getOrientation();
} else } else
#endif #endif
#ifdef ACCEL_MMA #ifdef ACCEL_MMA
if (DetectedAccelerometerVersion == 1) { if (DetectedAccelerometerVersion == 1) {
@@ -84,78 +82,77 @@ inline void readAccelerometer(int16_t &tx, int16_t &ty, int16_t &tz,
} else } else
#endif #endif
#ifdef ACCEL_MSA #ifdef ACCEL_MSA
if (PCBVersion == 3) { if (DetectedAccelerometerVersion == 4) {
MSA301::getAxisReadings(tx, ty, tz); MSA301::getAxisReadings(tx, ty, tz);
rotation = MSA301::getOrientation(); rotation = MSA301::getOrientation();
} else } else
#endif #endif
{ {
// do nothing :( // do nothing :(
} }
} }
void startMOVTask(void const *argument __unused) { void startMOVTask(void const *argument __unused) {
postRToSInit(); postRToSInit();
detectAccelerometerVersion(); detectAccelerometerVersion();
osDelay(50); // wait ~50ms for setup of accel to finalise osDelay(TICKS_100MS / 2); // wait ~50ms for setup of accel to finalise
lastMovementTime = 0; lastMovementTime = 0;
// Mask 2 seconds if we are in autostart so that if user is plugging in and // Mask 2 seconds if we are in autostart so that if user is plugging in and
// then putting in stand it doesnt wake instantly // then putting in stand it doesnt wake instantly
if (systemSettings.autoStartMode) if (systemSettings.autoStartMode)
osDelay(2 * TICKS_SECOND); osDelay(2 * TICKS_SECOND);
int16_t datax[MOVFilter] = {0}; int16_t datax[MOVFilter] = { 0 };
int16_t datay[MOVFilter] = {0}; int16_t datay[MOVFilter] = { 0 };
int16_t dataz[MOVFilter] = {0}; int16_t dataz[MOVFilter] = { 0 };
uint8_t currentPointer = 0; uint8_t currentPointer = 0;
int16_t tx = 0, ty = 0, tz = 0; int16_t tx = 0, ty = 0, tz = 0;
int32_t avgx, avgy, avgz; int32_t avgx, avgy, avgz;
if (systemSettings.sensitivity > 9) if (systemSettings.sensitivity > 9)
systemSettings.sensitivity = 9; systemSettings.sensitivity = 9;
Orientation rotation = ORIENTATION_FLAT; Orientation rotation = ORIENTATION_FLAT;
for (;;) { for (;;) {
int32_t threshold = 1500 + (9 * 200); int32_t threshold = 1500 + (9 * 200);
threshold -= systemSettings.sensitivity * 200; // 200 is the step size threshold -= systemSettings.sensitivity * 200; // 200 is the step size
readAccelerometer(tx, ty, tz, rotation); readAccelerometer(tx, ty, tz, rotation);
if (systemSettings.OrientationMode == 2) { if (systemSettings.OrientationMode == 2) {
if (rotation != ORIENTATION_FLAT) { if (rotation != ORIENTATION_FLAT) {
OLED::setRotation(rotation == OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through
ORIENTATION_LEFT_HAND); // link the data through }
} }
} datax[currentPointer] = (int32_t) tx;
datax[currentPointer] = (int32_t)tx; datay[currentPointer] = (int32_t) ty;
datay[currentPointer] = (int32_t)ty; dataz[currentPointer] = (int32_t) tz;
dataz[currentPointer] = (int32_t)tz; if (!accelInit) {
if (!accelInit) { for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) {
for (uint8_t i = currentPointer + 1; i < MOVFilter; i++) { datax[i] = (int32_t) tx;
datax[i] = (int32_t)tx; datay[i] = (int32_t) ty;
datay[i] = (int32_t)ty; dataz[i] = (int32_t) tz;
dataz[i] = (int32_t)tz; }
} accelInit = 1;
accelInit = 1; }
} currentPointer = (currentPointer + 1) % MOVFilter;
currentPointer = (currentPointer + 1) % MOVFilter; avgx = avgy = avgz = 0;
avgx = avgy = avgz = 0; // calculate averages
// calculate averages for (uint8_t i = 0; i < MOVFilter; i++) {
for (uint8_t i = 0; i < MOVFilter; i++) { avgx += datax[i];
avgx += datax[i]; avgy += datay[i];
avgy += datay[i]; avgz += dataz[i];
avgz += dataz[i]; }
} avgx /= MOVFilter;
avgx /= MOVFilter; avgy /= MOVFilter;
avgy /= MOVFilter; avgz /= MOVFilter;
avgz /= MOVFilter;
// Sum the deltas // Sum the deltas
int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)); 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 // So now we have averages, we want to look if these are different by more
// than the threshold // than the threshold
// If movement has occurred then we update the tick timer // If movement has occurred then we update the tick timer
if (error > threshold) { if (error > threshold) {
lastMovementTime = xTaskGetTickCount(); lastMovementTime = xTaskGetTickCount();
} }
osDelay(100); // Slow down update rate osDelay(TICKS_100MS); // Slow down update rate
power_check(); power_check();
} }
} }