2021-03-31 13:47:27 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2021-06-19 14:27:59 -04:00
|
|
|
#include <drivers/Bma421.h>
|
2021-10-17 02:23:44 -04:00
|
|
|
#include <components/ble/MotionService.h>
|
2021-03-31 13:47:27 -04:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
|
|
|
class MotionController {
|
|
|
|
public:
|
2021-10-31 11:53:13 -04:00
|
|
|
enum class DeviceTypes {
|
2021-06-19 14:27:59 -04:00
|
|
|
Unknown,
|
|
|
|
BMA421,
|
|
|
|
BMA425,
|
|
|
|
};
|
|
|
|
|
2021-03-31 13:47:27 -04:00
|
|
|
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
|
|
|
|
|
2021-04-26 16:29:48 -04:00
|
|
|
int16_t X() const {
|
2021-04-18 13:28:14 -04:00
|
|
|
return x;
|
|
|
|
}
|
2021-04-26 16:29:48 -04:00
|
|
|
int16_t Y() const {
|
2021-04-18 13:28:14 -04:00
|
|
|
return y;
|
|
|
|
}
|
2021-04-26 16:29:48 -04:00
|
|
|
int16_t Z() const {
|
2021-04-18 13:28:14 -04:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
uint32_t NbSteps() const {
|
|
|
|
return nbSteps;
|
|
|
|
}
|
2021-10-31 11:53:13 -04:00
|
|
|
|
2021-10-21 23:37:35 -04:00
|
|
|
void ResetTrip() {
|
|
|
|
currentTripSteps = 0;
|
2021-10-19 23:42:48 -04:00
|
|
|
}
|
2021-10-20 14:29:10 -04:00
|
|
|
uint32_t GetTripSteps() const {
|
2021-10-21 23:37:35 -04:00
|
|
|
return currentTripSteps;
|
2021-10-19 23:42:48 -04:00
|
|
|
}
|
2021-09-26 22:52:02 -04:00
|
|
|
|
|
|
|
bool Should_ShakeWake(uint16_t thresh);
|
2021-09-26 21:20:44 -04:00
|
|
|
bool Should_RaiseWake(bool isSleeping);
|
2021-09-27 23:50:08 -04:00
|
|
|
int32_t currentShakeSpeed();
|
2021-04-02 10:56:14 -04:00
|
|
|
void IsSensorOk(bool isOk);
|
2021-04-18 13:28:14 -04:00
|
|
|
bool IsSensorOk() const {
|
|
|
|
return isSensorOk;
|
|
|
|
}
|
2021-04-02 10:56:14 -04:00
|
|
|
|
2021-06-19 14:27:59 -04:00
|
|
|
DeviceTypes DeviceType() const {
|
|
|
|
return deviceType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init(Pinetime::Drivers::Bma421::DeviceTypes types);
|
2021-10-17 02:23:44 -04:00
|
|
|
void SetService(Pinetime::Controllers::MotionService* service);
|
2021-06-19 14:27:59 -04:00
|
|
|
|
2021-04-02 10:56:14 -04:00
|
|
|
private:
|
2021-03-31 13:47:27 -04:00
|
|
|
uint32_t nbSteps;
|
2021-10-21 23:37:35 -04:00
|
|
|
uint32_t currentTripSteps = 0;
|
2021-03-31 13:47:27 -04:00
|
|
|
int16_t x;
|
|
|
|
int16_t y;
|
|
|
|
int16_t z;
|
|
|
|
int16_t lastYForWakeUp = 0;
|
2021-04-02 10:56:14 -04:00
|
|
|
bool isSensorOk = false;
|
2021-06-19 14:27:59 -04:00
|
|
|
DeviceTypes deviceType = DeviceTypes::Unknown;
|
2021-10-17 02:23:44 -04:00
|
|
|
Pinetime::Controllers::MotionService* service = nullptr;
|
2021-09-26 21:20:44 -04:00
|
|
|
|
|
|
|
int16_t lastXForShake = 0;
|
|
|
|
int16_t lastYForShake = 0;
|
|
|
|
int16_t lastZForShake = 0;
|
2021-09-26 23:30:49 -04:00
|
|
|
int32_t accumulatedspeed = 0;
|
2021-09-26 21:20:44 -04:00
|
|
|
uint32_t lastShakeTime = 0;
|
2021-03-31 13:47:27 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|