2021-03-31 19:47:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2021-06-19 20:27:59 +02:00
|
|
|
#include <drivers/Bma421.h>
|
2021-10-17 08:23:44 +02:00
|
|
|
#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;
|
|
|
|
}
|
2021-04-26 22:29:48 +02:00
|
|
|
int16_t Y() const {
|
2021-04-18 19:28:14 +02:00
|
|
|
return y;
|
|
|
|
}
|
2021-04-26 22:29:48 +02:00
|
|
|
int16_t Z() const {
|
2021-04-18 19:28:14 +02:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
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
|
|
|
|
|
|
|
bool Should_ShakeWake(uint16_t thresh);
|
2021-09-27 03:20:44 +02:00
|
|
|
bool Should_RaiseWake(bool isSleeping);
|
2021-09-28 05:50:08 +02:00
|
|
|
int32_t currentShakeSpeed();
|
2021-04-02 16:56:14 +02:00
|
|
|
void IsSensorOk(bool isOk);
|
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);
|
2021-10-17 08:23:44 +02:00
|
|
|
void SetService(Pinetime::Controllers::MotionService* service);
|
2021-06-19 20:27:59 +02:00
|
|
|
|
2021-04-02 16:56:14 +02:00
|
|
|
private:
|
2021-03-31 19:47:27 +02:00
|
|
|
uint32_t nbSteps;
|
2021-10-22 05:37:35 +02:00
|
|
|
uint32_t currentTripSteps = 0;
|
2021-03-31 19:47:27 +02:00
|
|
|
int16_t x;
|
|
|
|
int16_t y;
|
|
|
|
int16_t z;
|
|
|
|
int16_t lastYForWakeUp = 0;
|
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-09-27 03:20:44 +02:00
|
|
|
|
|
|
|
int16_t lastXForShake = 0;
|
|
|
|
int16_t lastYForShake = 0;
|
|
|
|
int16_t lastZForShake = 0;
|
2021-09-27 05:30:49 +02:00
|
|
|
int32_t accumulatedspeed = 0;
|
2021-09-27 03:20:44 +02:00
|
|
|
uint32_t lastShakeTime = 0;
|
2021-03-31 19:47:27 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|