2019-12-27 16:05:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-06-08 19:51:34 +00:00
|
|
|
#include <array>
|
2020-11-15 14:05:51 +00:00
|
|
|
#include <cstdint>
|
2020-03-25 20:23:40 +00:00
|
|
|
|
2019-12-27 16:05:49 +00:00
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
|
|
|
class Ble {
|
2021-04-18 17:28:14 +00:00
|
|
|
public:
|
|
|
|
using BleAddress = std::array<uint8_t, 6>;
|
|
|
|
enum class FirmwareUpdateStates { Idle, Running, Validated, Error };
|
|
|
|
enum class AddressTypes { Public, Random };
|
2020-03-25 20:23:40 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
Ble() = default;
|
|
|
|
bool IsConnected() const {
|
|
|
|
return isConnected;
|
|
|
|
}
|
|
|
|
void Connect();
|
|
|
|
void Disconnect();
|
2020-05-02 12:16:57 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
void StartFirmwareUpdate();
|
|
|
|
void StopFirmwareUpdate();
|
|
|
|
void FirmwareUpdateTotalBytes(uint32_t totalBytes);
|
|
|
|
void FirmwareUpdateCurrentBytes(uint32_t currentBytes);
|
|
|
|
void State(FirmwareUpdateStates state) {
|
|
|
|
firmwareUpdateState = state;
|
|
|
|
}
|
2020-05-02 12:16:57 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
bool IsFirmwareUpdating() const {
|
|
|
|
return isFirmwareUpdating;
|
|
|
|
}
|
|
|
|
uint32_t FirmwareUpdateTotalBytes() const {
|
|
|
|
return firmwareUpdateTotalBytes;
|
|
|
|
}
|
|
|
|
uint32_t FirmwareUpdateCurrentBytes() const {
|
|
|
|
return firmwareUpdateCurrentBytes;
|
|
|
|
}
|
|
|
|
FirmwareUpdateStates State() const {
|
|
|
|
return firmwareUpdateState;
|
|
|
|
}
|
2020-06-08 19:51:34 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
void Address(BleAddress&& addr) {
|
|
|
|
address = addr;
|
|
|
|
}
|
|
|
|
const BleAddress& Address() const {
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
void AddressType(AddressTypes t) {
|
|
|
|
addressType = t;
|
|
|
|
}
|
2020-03-25 20:23:40 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
private:
|
|
|
|
bool isConnected = false;
|
|
|
|
bool isFirmwareUpdating = false;
|
|
|
|
uint32_t firmwareUpdateTotalBytes = 0;
|
|
|
|
uint32_t firmwareUpdateCurrentBytes = 0;
|
|
|
|
FirmwareUpdateStates firmwareUpdateState = FirmwareUpdateStates::Idle;
|
|
|
|
BleAddress address;
|
|
|
|
AddressTypes addressType;
|
2019-12-27 16:05:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|