From 8eb947a2239d431146de9295e281ee0163fa20e2 Mon Sep 17 00:00:00 2001 From: Niall Cooling Date: Mon, 22 Mar 2021 17:56:26 +0000 Subject: [PATCH] replaced all unique_ptr.reset calls with std::make_unique --- src/displayapp/DisplayApp.cpp | 40 ++++++++++++---------- src/displayapp/screens/ApplicationList.cpp | 6 ++-- src/displayapp/screens/Clock.cpp | 8 ++--- src/displayapp/screens/Notifications.cpp | 16 ++++----- src/displayapp/screens/SystemInfo.cpp | 6 ++-- src/main.cpp | 6 ++-- src/systemtask/SystemTask.cpp | 2 +- 7 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 2e81c99b..3de26991 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -123,7 +123,7 @@ void DisplayApp::Refresh() { currentScreen.reset(nullptr); lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); onClockApp = false; - currentScreen.reset(new Screens::Notifications(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview)); + currentScreen = std::make_unique(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview); } } break; @@ -161,10 +161,10 @@ void DisplayApp::Refresh() { // lvgl.SetFullRefresh(components::LittleVgl::FullRefreshDirections::Down); // currentScreen.reset(nullptr); // if(toggle) { -// currentScreen.reset(new Screens::Tile(this)); +// currentScreen = std::make_unique(this); // toggle = false; // } else { -// currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController)); +// currentScreen = std::make_unique(this, dateTimeController, batteryController, bleController); // toggle = true; // } @@ -172,10 +172,14 @@ void DisplayApp::Refresh() { case Messages::BleFirmwareUpdateStarted: lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Down); currentScreen.reset(nullptr); - currentScreen.reset(new Screens::FirmwareUpdate(this, bleController)); + currentScreen = std::make_unique(this, bleController); onClockApp = false; break; + case Messages::UpdateDateTime: + // Added to remove warning + // What should happen here? + break; } } @@ -198,23 +202,23 @@ void DisplayApp::RunningState() { onClockApp = false; switch(nextApp) { case Apps::None: - case Apps::Launcher: currentScreen.reset(new Screens::ApplicationList(this, settingsController)); break; + case Apps::Launcher: currentScreen = std::make_unique(this, settingsController); break; case Apps::Clock: - currentScreen.reset(new Screens::Clock(this, dateTimeController, batteryController, bleController, notificationManager, settingsController, heartRateController)); + currentScreen = std::make_unique(this, dateTimeController, batteryController, bleController, notificationManager, settingsController, heartRateController); onClockApp = true; break; - case Apps::SysInfo: currentScreen.reset(new Screens::SystemInfo(this, dateTimeController, batteryController, brightnessController, bleController, watchdog)); break; - case Apps::Meter: currentScreen.reset(new Screens::Meter(this)); break; - case Apps::StopWatch: currentScreen.reset(new Screens::StopWatch(this)); break; - case Apps::Twos: currentScreen.reset(new Screens::Twos(this)); break; - case Apps::Paint: currentScreen.reset(new Screens::InfiniPaint(this, lvgl)); break; - case Apps::Paddle: currentScreen.reset(new Screens::Paddle(this, lvgl)); break; - case Apps::Brightness : currentScreen.reset(new Screens::Brightness(this, brightnessController)); break; - case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; - case Apps::Navigation : currentScreen.reset(new Screens::Navigation(this, systemTask.nimble().navigation())); break; - case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; - case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal)); break; - case Apps::HeartRate: currentScreen.reset(new Screens::HeartRate(this, heartRateController)); break; + case Apps::SysInfo: currentScreen = std::make_unique(this, dateTimeController, batteryController, brightnessController, bleController, watchdog); break; + case Apps::Meter: currentScreen = std::make_unique(this);break; + case Apps::StopWatch: currentScreen = std::make_unique(this); break; + case Apps::Twos: currentScreen = std::make_unique(this); break; + case Apps::Paint: currentScreen = std::make_unique(this, lvgl); break; + case Apps::Paddle: currentScreen = std::make_unique(this, lvgl); break; + case Apps::Brightness : currentScreen = std::make_unique(this, brightnessController); break; + case Apps::Music : currentScreen = std::make_unique(this, systemTask.nimble().music()); break; + case Apps::Navigation : currentScreen = std::make_unique(this, systemTask.nimble().navigation()); break; + case Apps::FirmwareValidation: currentScreen = std::make_unique(this, validator); break; + case Apps::Notifications: currentScreen = std::make_unique(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal); break; + case Apps::HeartRate: currentScreen = std::make_unique(this, heartRateController); break; } nextApp = Apps::None; } diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index dd9cb2a8..60039045 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -56,7 +56,7 @@ std::unique_ptr ApplicationList::CreateScreen1() { }; - return std::unique_ptr(new Screens::Tile(0, app, settingsController, applications)); + return std::make_unique(0, app, settingsController, applications); } std::unique_ptr ApplicationList::CreateScreen2() { @@ -70,7 +70,7 @@ std::unique_ptr ApplicationList::CreateScreen2() { } }; - return std::unique_ptr(new Screens::Tile(1, app, settingsController, applications)); + return std::make_unique(1, app, settingsController, applications); } std::unique_ptr ApplicationList::CreateScreen3() { @@ -84,6 +84,6 @@ std::unique_ptr ApplicationList::CreateScreen3() { } }; - return std::unique_ptr(new Screens::Tile(2, app, settingsController, applications)); + return std::make_unique(2, app, settingsController, applications); } diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 342dd222..69180370 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -64,20 +64,20 @@ bool Clock::OnTouchEvent(Pinetime::Applications::TouchEvents event) { } std::unique_ptr Clock::WatchFaceDigitalScreen() { - return std::unique_ptr(new Screens::WatchFaceDigital(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController, heartRateController)); + return std::make_unique(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController, heartRateController); } std::unique_ptr Clock::WatchFaceAnalogScreen() { - return std::unique_ptr(new Screens::WatchFaceAnalog(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController)); + return std::make_unique(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController); } /* // Examples for more watch faces std::unique_ptr Clock::WatchFaceMinimalScreen() { - return std::unique_ptr(new Screens::WatchFaceMinimal(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController)); + return std::make_unique(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController); } std::unique_ptr Clock::WatchFaceCustomScreen() { - return std::unique_ptr(new Screens::WatchFaceCustom(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController)); + return std::make_unique(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController); } */ \ No newline at end of file diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 4219bac7..c903ed0f 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -17,22 +17,22 @@ Notifications::Notifications(DisplayApp *app, auto notification = notificationManager.GetLastNotification(); if(notification.valid) { currentId = notification.id; - currentItem.reset(new NotificationItem("\nNotification", + currentItem = std::make_unique("\nNotification", notification.message.data(), notification.index, notification.category, notificationManager.NbNotifications(), mode, - alertNotificationService)); + alertNotificationService); validDisplay = true; } else { - currentItem.reset(new NotificationItem("\nNotification", + currentItem = std::make_unique("\nNotification", "No notification to display", 0, notification.category, notificationManager.NbNotifications(), Modes::Preview, - alertNotificationService)); + alertNotificationService); } if(mode == Modes::Preview) { @@ -87,13 +87,13 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = previousNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); - currentItem.reset(new NotificationItem("\nNotification", + currentItem = std::make_unique("\nNotification", previousNotification.message.data(), previousNotification.index, previousNotification.category, notificationManager.NbNotifications(), mode, - alertNotificationService)); + alertNotificationService); } return true; case Pinetime::Applications::TouchEvents::SwipeDown: { @@ -109,13 +109,13 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = nextNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); - currentItem.reset(new NotificationItem("\nNotification", + currentItem = std::make_unique("\nNotification", nextNotification.message.data(), nextNotification.index, nextNotification.category, notificationManager.NbNotifications(), mode, - alertNotificationService)); + alertNotificationService); } return true; case Pinetime::Applications::TouchEvents::LongTap: { diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 0d6f8e5a..949fd345 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -104,14 +104,14 @@ std::unique_ptr SystemInfo::CreateScreen1() { uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds, batteryPercent, brightness, resetReason); - return std::unique_ptr(new Screens::Label(app, t1)); + return std::make_unique(app, t1); } std::unique_ptr SystemInfo::CreateScreen2() { auto& bleAddr = bleController.Address(); sprintf(t2, "BLE MAC: \n %02x:%02x:%02x:%02x:%02x:%02x", bleAddr[5], bleAddr[4], bleAddr[3], bleAddr[2], bleAddr[1], bleAddr[0]); - return std::unique_ptr(new Screens::Label(app, t2)); + return std::make_unique(app, t2); } std::unique_ptr SystemInfo::CreateScreen3() { @@ -123,5 +123,5 @@ std::unique_ptr SystemInfo::CreateScreen3() { "Source code:\n" "https://github.com/\n" " JF002/InfiniTime"); - return std::unique_ptr(new Screens::Label(app, t3)); + return std::make_unique(app, t3); } diff --git a/src/main.cpp b/src/main.cpp index b29aac71..bd4bbe79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,6 +49,8 @@ Pinetime::Logging::NrfLogger logger; Pinetime::Logging::DummyLogger logger; #endif +#include + static constexpr uint8_t pinSpiSck = 2; static constexpr uint8_t pinSpiMosi = 3; static constexpr uint8_t pinSpiMiso = 4; @@ -254,8 +256,8 @@ int main(void) { debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback); - systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, spiNorFlash, twiMaster, touchPanel, lvgl, batteryController, bleController, - dateTimeController, motorController, heartRateSensor, settingsController)); + systemTask = std::make_unique(spi, lcd, spiNorFlash, twiMaster, touchPanel, lvgl, batteryController, bleController, + dateTimeController, motorController, heartRateSensor, settingsController); systemTask->Start(); nimble_port_init(); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 3557c1be..7b137f55 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -98,7 +98,7 @@ void SystemTask::Work() { heartRateSensor.Init(); heartRateSensor.Disable(); - heartRateApp.reset(new Pinetime::Applications::HeartRateTask(heartRateSensor, heartRateController)); + heartRateApp = std::make_unique(heartRateSensor, heartRateController); heartRateApp->Start();