2021-03-31 19:47:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2023-03-05 14:40:01 +01:00
|
|
|
|
2023-03-05 15:19:52 +01:00
|
|
|
#include <FreeRTOS.h>
|
|
|
|
|
2023-03-05 14:40:01 +01:00
|
|
|
#include "drivers/Bma421.h"
|
|
|
|
#include "components/ble/MotionService.h"
|
2021-03-31 19:47:27 +02:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
|
|
|
class MotionController {
|
|
|
|
public:
|
2021-10-31 16:53:13 +01:00
|
|
|
enum class DeviceTypes {
|
2021-06-19 20:27:59 +02:00
|
|
|
Unknown,
|
|
|
|
BMA421,
|
|
|
|
BMA425,
|
|
|
|
};
|
|
|
|
|
2021-03-31 19:47:27 +02:00
|
|
|
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
|
|
|
|
|
2021-04-26 22:29:48 +02:00
|
|
|
int16_t X() const {
|
2021-04-18 19:28:14 +02:00
|
|
|
return x;
|
|
|
|
}
|
2023-01-07 21:23:15 +01:00
|
|
|
|
2021-04-26 22:29:48 +02:00
|
|
|
int16_t Y() const {
|
2021-04-18 19:28:14 +02:00
|
|
|
return y;
|
|
|
|
}
|
2023-01-07 21:23:15 +01:00
|
|
|
|
2021-04-26 22:29:48 +02:00
|
|
|
int16_t Z() const {
|
2021-04-18 19:28:14 +02:00
|
|
|
return z;
|
|
|
|
}
|
2023-01-07 21:23:15 +01:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
uint32_t NbSteps() const {
|
|
|
|
return nbSteps;
|
|
|
|
}
|
2021-10-31 16:53:13 +01:00
|
|
|
|
2021-10-22 05:37:35 +02:00
|
|
|
void ResetTrip() {
|
|
|
|
currentTripSteps = 0;
|
2021-10-20 05:42:48 +02:00
|
|
|
}
|
2023-01-07 21:23:15 +01:00
|
|
|
|
2021-10-20 20:29:10 +02:00
|
|
|
uint32_t GetTripSteps() const {
|
2021-10-22 05:37:35 +02:00
|
|
|
return currentTripSteps;
|
2021-10-20 05:42:48 +02:00
|
|
|
}
|
2021-09-27 04:52:02 +02:00
|
|
|
|
2023-03-05 14:53:49 +01:00
|
|
|
bool ShouldShakeWake(uint16_t thresh);
|
2021-09-27 03:20:44 +02:00
|
|
|
bool Should_RaiseWake(bool isSleeping);
|
2023-03-05 14:53:49 +01:00
|
|
|
|
|
|
|
int32_t CurrentShakeSpeed() const {
|
|
|
|
return accumulatedSpeed;
|
|
|
|
}
|
|
|
|
|
2023-03-05 15:24:06 +01:00
|
|
|
void IsSensorOk(bool isOk) {
|
|
|
|
isSensorOk = isOk;
|
|
|
|
}
|
2023-01-07 21:23:15 +01:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
bool IsSensorOk() const {
|
|
|
|
return isSensorOk;
|
|
|
|
}
|
2021-04-02 16:56:14 +02:00
|
|
|
|
2021-06-19 20:27:59 +02:00
|
|
|
DeviceTypes DeviceType() const {
|
|
|
|
return deviceType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(Pinetime::Drivers::Bma421::DeviceTypes types);
|
2023-03-05 15:24:06 +01:00
|
|
|
|
|
|
|
void SetService(Pinetime::Controllers::MotionService* service) {
|
|
|
|
this->service = service;
|
|
|
|
}
|
2021-06-19 20:27:59 +02:00
|
|
|
|
2021-04-02 16:56:14 +02:00
|
|
|
private:
|
2023-03-05 15:24:06 +01:00
|
|
|
uint32_t nbSteps = 0;
|
2021-10-22 05:37:35 +02:00
|
|
|
uint32_t currentTripSteps = 0;
|
2023-03-05 14:40:01 +01:00
|
|
|
|
2023-03-05 15:19:52 +01:00
|
|
|
TickType_t lastTime = 0;
|
|
|
|
TickType_t time = 0;
|
|
|
|
|
2023-03-05 15:24:06 +01:00
|
|
|
int16_t x = 0;
|
2023-03-05 14:40:01 +01:00
|
|
|
int16_t lastYForWakeUp = 0;
|
|
|
|
int16_t lastY = 0;
|
2023-03-05 15:24:06 +01:00
|
|
|
int16_t y = 0;
|
2023-03-05 14:40:01 +01:00
|
|
|
int16_t lastZ = 0;
|
2023-03-05 15:24:06 +01:00
|
|
|
int16_t z = 0;
|
2023-03-05 15:19:52 +01:00
|
|
|
int32_t accumulatedSpeed = 0;
|
2023-03-05 14:40:01 +01:00
|
|
|
|
2021-04-02 16:56:14 +02:00
|
|
|
bool isSensorOk = false;
|
2021-06-19 20:27:59 +02:00
|
|
|
DeviceTypes deviceType = DeviceTypes::Unknown;
|
2021-10-17 08:23:44 +02:00
|
|
|
Pinetime::Controllers::MotionService* service = nullptr;
|
2021-03-31 19:47:27 +02:00
|
|
|
};
|
|
|
|
}
|
2023-03-05 14:53:49 +01:00
|
|
|
}
|