Display BLE MAC address in sysinfo Screen.
This commit is contained in:
parent
9115c49bba
commit
47851fb3b4
|
@ -2,12 +2,15 @@
|
||||||
|
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
#include <queue.h>
|
#include <queue.h>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
namespace Controllers {
|
namespace Controllers {
|
||||||
class Ble {
|
class Ble {
|
||||||
public:
|
public:
|
||||||
|
using BleAddress = std::array<uint8_t, 6>;
|
||||||
enum class FirmwareUpdateStates {Idle, Running, Validated, Error};
|
enum class FirmwareUpdateStates {Idle, Running, Validated, Error};
|
||||||
|
enum class AddressTypes { Public, Random };
|
||||||
|
|
||||||
Ble() = default;
|
Ble() = default;
|
||||||
bool IsConnected() const {return isConnected;}
|
bool IsConnected() const {return isConnected;}
|
||||||
|
@ -24,12 +27,18 @@ namespace Pinetime {
|
||||||
uint32_t FirmwareUpdateTotalBytes() const { return firmwareUpdateTotalBytes; }
|
uint32_t FirmwareUpdateTotalBytes() const { return firmwareUpdateTotalBytes; }
|
||||||
uint32_t FirmwareUpdateCurrentBytes() const { return firmwareUpdateCurrentBytes; }
|
uint32_t FirmwareUpdateCurrentBytes() const { return firmwareUpdateCurrentBytes; }
|
||||||
FirmwareUpdateStates State() const { return firmwareUpdateState; }
|
FirmwareUpdateStates State() const { return firmwareUpdateState; }
|
||||||
|
|
||||||
|
void Address(BleAddress&& addr) { address = addr; }
|
||||||
|
const BleAddress& Address() const { return address; }
|
||||||
|
void AddressType(AddressTypes t) { addressType = t;}
|
||||||
private:
|
private:
|
||||||
bool isConnected = false;
|
bool isConnected = false;
|
||||||
bool isFirmwareUpdating = false;
|
bool isFirmwareUpdating = false;
|
||||||
uint32_t firmwareUpdateTotalBytes = 0;
|
uint32_t firmwareUpdateTotalBytes = 0;
|
||||||
uint32_t firmwareUpdateCurrentBytes = 0;
|
uint32_t firmwareUpdateCurrentBytes = 0;
|
||||||
FirmwareUpdateStates firmwareUpdateState = FirmwareUpdateStates::Idle;
|
FirmwareUpdateStates firmwareUpdateState = FirmwareUpdateStates::Idle;
|
||||||
|
BleAddress address;
|
||||||
|
AddressTypes addressType;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,8 +90,13 @@ void NimbleController::Init() {
|
||||||
res = ble_hs_id_infer_auto(0, &addrType);
|
res = ble_hs_id_infer_auto(0, &addrType);
|
||||||
ASSERT(res == 0);
|
ASSERT(res == 0);
|
||||||
res = ble_svc_gap_device_name_set(deviceName);
|
res = ble_svc_gap_device_name_set(deviceName);
|
||||||
|
|
||||||
ASSERT(res == 0);
|
ASSERT(res == 0);
|
||||||
|
Pinetime::Controllers::Ble::BleAddress address;
|
||||||
|
res = ble_hs_id_copy_addr(addrType, address.data(), nullptr);
|
||||||
|
ASSERT(res == 0);
|
||||||
|
bleController.AddressType((addrType == 0) ? Ble::AddressTypes::Public : Ble::AddressTypes::Random);
|
||||||
|
bleController.Address(std::move(address));
|
||||||
|
|
||||||
res = ble_gatts_start();
|
res = ble_gatts_start();
|
||||||
ASSERT(res == 0);
|
ASSERT(res == 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace Pinetime {
|
||||||
AlertNotificationClient alertNotificationClient;
|
AlertNotificationClient alertNotificationClient;
|
||||||
CurrentTimeService currentTimeService;
|
CurrentTimeService currentTimeService;
|
||||||
|
|
||||||
uint8_t addrType;
|
uint8_t addrType; // 1 = Random, 0 = PUBLIC
|
||||||
uint16_t connectionHandle;
|
uint16_t connectionHandle;
|
||||||
|
|
||||||
ble_uuid128_t dfuServiceUuid {
|
ble_uuid128_t dfuServiceUuid {
|
||||||
|
|
|
@ -185,7 +185,7 @@ void DisplayApp::RunningState() {
|
||||||
onClockApp = true;
|
onClockApp = true;
|
||||||
break;
|
break;
|
||||||
// case Apps::Test: currentScreen.reset(new Screens::Message(this)); break;
|
// case Apps::Test: currentScreen.reset(new Screens::Message(this)); break;
|
||||||
case Apps::SysInfo: currentScreen.reset(new Screens::ScreenList(this, dateTimeController, batteryController, brightnessController, watchdog)); break;
|
case Apps::SysInfo: currentScreen.reset(new Screens::ScreenList(this, dateTimeController, batteryController, brightnessController, bleController, watchdog)); break;
|
||||||
case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break;
|
case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break;
|
||||||
case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break;
|
case Apps::Gauge: currentScreen.reset(new Screens::Gauge(this)); break;
|
||||||
case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break;
|
case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break;
|
||||||
|
|
|
@ -8,10 +8,15 @@ using namespace Pinetime::Applications::Screens;
|
||||||
// move operation.
|
// move operation.
|
||||||
// It should accept many type of "sub screen" (it only supports Label for now).
|
// It should accept many type of "sub screen" (it only supports Label for now).
|
||||||
// The number of sub screen it supports must be dynamic.
|
// The number of sub screen it supports must be dynamic.
|
||||||
ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController,
|
ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app,
|
||||||
Pinetime::Controllers::Battery& batteryController, Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Drivers::WatchdogView& watchdog) :
|
Pinetime::Controllers::DateTime &dateTimeController,
|
||||||
|
Pinetime::Controllers::Battery& batteryController,
|
||||||
|
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||||
|
Pinetime::Controllers::Ble& bleController,
|
||||||
|
Pinetime::Drivers::WatchdogView& watchdog) :
|
||||||
Screen(app),
|
Screen(app),
|
||||||
dateTimeController{dateTimeController}, batteryController{batteryController}, brightnessController{brightnessController}, watchdog{watchdog} {
|
dateTimeController{dateTimeController}, batteryController{batteryController},
|
||||||
|
brightnessController{brightnessController}, bleController{bleController}, watchdog{watchdog} {
|
||||||
screens.reserve(3);
|
screens.reserve(3);
|
||||||
|
|
||||||
// TODO all of this is far too heavy (string processing). This should be improved.
|
// TODO all of this is far too heavy (string processing). This should be improved.
|
||||||
|
@ -75,10 +80,13 @@ ScreenList::ScreenList(Pinetime::Applications::DisplayApp *app, Pinetime::Contro
|
||||||
|
|
||||||
screens.emplace_back(t1);
|
screens.emplace_back(t1);
|
||||||
|
|
||||||
strncpy(t2, "Hello from\nthe developper!", 27);
|
auto& bleAddr = bleController.Address();
|
||||||
|
sprintf(t2, "BLE MAC: \n %2x:%2x:%2x:%2x:%2x:%2x",
|
||||||
|
bleAddr[5], bleAddr[4], bleAddr[3], bleAddr[2], bleAddr[1], bleAddr[0]);
|
||||||
screens.emplace_back(t2);
|
screens.emplace_back(t2);
|
||||||
|
|
||||||
strncpy(t3, "Place holder\nin case we need\nmore room!", 40);
|
strncpy(t3, "Hello from\nthe developper!", 27);
|
||||||
|
|
||||||
screens.emplace_back(t3);
|
screens.emplace_back(t3);
|
||||||
|
|
||||||
auto &screen = screens[screenIndex];
|
auto &screen = screens[screenIndex];
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <Components/Ble/NimbleController.h>
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
#include "Label.h"
|
#include "Label.h"
|
||||||
|
|
||||||
|
@ -13,6 +14,7 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::DateTime& dateTimeController,
|
Pinetime::Controllers::DateTime& dateTimeController,
|
||||||
Pinetime::Controllers::Battery& batteryController,
|
Pinetime::Controllers::Battery& batteryController,
|
||||||
Pinetime::Controllers::BrightnessController& brightnessController,
|
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||||
|
Pinetime::Controllers::Ble& bleController,
|
||||||
Pinetime::Drivers::WatchdogView& watchdog);
|
Pinetime::Drivers::WatchdogView& watchdog);
|
||||||
~ScreenList() override;
|
~ScreenList() override;
|
||||||
bool Refresh() override;
|
bool Refresh() override;
|
||||||
|
@ -27,11 +29,13 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::DateTime& dateTimeController;
|
Pinetime::Controllers::DateTime& dateTimeController;
|
||||||
Pinetime::Controllers::Battery& batteryController;
|
Pinetime::Controllers::Battery& batteryController;
|
||||||
Pinetime::Controllers::BrightnessController& brightnessController;
|
Pinetime::Controllers::BrightnessController& brightnessController;
|
||||||
|
Pinetime::Controllers::Ble& bleController;
|
||||||
Pinetime::Drivers::WatchdogView& watchdog;
|
Pinetime::Drivers::WatchdogView& watchdog;
|
||||||
|
|
||||||
|
|
||||||
char t1[200];
|
char t1[200];
|
||||||
char t2[30];
|
char t2[200];
|
||||||
char t3[42];
|
char t3[30];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue