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