Merge remote-tracking branch 'upstream/develop' into pinetimestyle
This commit is contained in:
		
						commit
						565601ef50
					
				@ -1,5 +1,5 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.10)
 | 
			
		||||
project(pinetime VERSION 1.0.0 LANGUAGES C CXX ASM)
 | 
			
		||||
project(pinetime VERSION 1.1.0 LANGUAGES C CXX ASM)
 | 
			
		||||
 | 
			
		||||
set(CMAKE_C_STANDARD 99)
 | 
			
		||||
set(CMAKE_CXX_STANDARD 14)
 | 
			
		||||
 | 
			
		||||
@ -407,6 +407,7 @@ list(APPEND SOURCE_FILES
 | 
			
		||||
        displayapp/screens/List.cpp
 | 
			
		||||
        displayapp/screens/BatteryInfo.cpp
 | 
			
		||||
        displayapp/screens/Steps.cpp
 | 
			
		||||
        displayapp/screens/Timer.cpp
 | 
			
		||||
 | 
			
		||||
        ## Settings
 | 
			
		||||
        displayapp/screens/settings/QuickSettings.cpp
 | 
			
		||||
@ -460,6 +461,7 @@ list(APPEND SOURCE_FILES
 | 
			
		||||
        components/firmwarevalidator/FirmwareValidator.cpp
 | 
			
		||||
        components/motor/MotorController.cpp
 | 
			
		||||
        components/settings/Settings.cpp
 | 
			
		||||
        components/timer/TimerController.cpp
 | 
			
		||||
        drivers/Cst816s.cpp
 | 
			
		||||
        FreeRTOS/port.c
 | 
			
		||||
        FreeRTOS/port_cmsis_systick.c
 | 
			
		||||
@ -522,6 +524,7 @@ list(APPEND RECOVERY_SOURCE_FILES
 | 
			
		||||
        components/ble/HeartRateService.cpp
 | 
			
		||||
        components/firmwarevalidator/FirmwareValidator.cpp
 | 
			
		||||
        components/settings/Settings.cpp
 | 
			
		||||
        components/timer/TimerController.cpp
 | 
			
		||||
        drivers/Cst816s.cpp
 | 
			
		||||
        FreeRTOS/port.c
 | 
			
		||||
        FreeRTOS/port_cmsis_systick.c
 | 
			
		||||
@ -592,6 +595,7 @@ set(INCLUDE_FILES
 | 
			
		||||
        displayapp/screens/Notifications.h
 | 
			
		||||
        displayapp/screens/HeartRate.h
 | 
			
		||||
        displayapp/screens/Motion.h
 | 
			
		||||
        displayapp/screens/Timer.h
 | 
			
		||||
        drivers/St7789.h
 | 
			
		||||
        drivers/SpiNorFlash.h
 | 
			
		||||
        drivers/SpiMaster.h
 | 
			
		||||
@ -621,6 +625,7 @@ set(INCLUDE_FILES
 | 
			
		||||
        components/ble/BleClient.h
 | 
			
		||||
        components/ble/HeartRateService.h
 | 
			
		||||
        components/settings/Settings.h
 | 
			
		||||
        components/timer/TimerController.h
 | 
			
		||||
        drivers/Cst816s.h
 | 
			
		||||
        FreeRTOS/portmacro.h
 | 
			
		||||
        FreeRTOS/portmacro_cmsis.h
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,6 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
 | 
			
		||||
void MotorController::Init() {
 | 
			
		||||
  nrf_gpio_cfg_output(pinMotor);
 | 
			
		||||
  nrf_gpio_pin_set(pinMotor);
 | 
			
		||||
  app_timer_init();
 | 
			
		||||
  app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										64
									
								
								src/components/timer/TimerController.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/components/timer/TimerController.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,64 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by florian on 16.05.21.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include "TimerController.h"
 | 
			
		||||
#include "systemtask/SystemTask.h"
 | 
			
		||||
#include "app_timer.h"
 | 
			
		||||
#include "task.h"
 | 
			
		||||
 | 
			
		||||
using namespace Pinetime::Controllers;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
APP_TIMER_DEF(timerAppTimer);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TimerController::TimerController(System::SystemTask& systemTask) : systemTask{systemTask} {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void TimerController::Init() {
 | 
			
		||||
  app_timer_create(&timerAppTimer, APP_TIMER_MODE_SINGLE_SHOT, timerEnd);
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimerController::StartTimer(uint32_t duration) {
 | 
			
		||||
  app_timer_stop(timerAppTimer);
 | 
			
		||||
  auto currentTicks = xTaskGetTickCount();
 | 
			
		||||
  app_timer_start(timerAppTimer, APP_TIMER_TICKS(duration), this);
 | 
			
		||||
  endTicks = currentTicks + APP_TIMER_TICKS(duration);
 | 
			
		||||
  timerRunning = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t TimerController::GetTimeRemaining() {
 | 
			
		||||
  if (!timerRunning) {
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  auto currentTicks = xTaskGetTickCount();
 | 
			
		||||
  
 | 
			
		||||
  TickType_t deltaTicks = 0;
 | 
			
		||||
  if (currentTicks > endTicks) {
 | 
			
		||||
    deltaTicks = 0xffffffff - currentTicks;
 | 
			
		||||
    deltaTicks += (endTicks + 1);
 | 
			
		||||
  } else {
 | 
			
		||||
    deltaTicks = endTicks - currentTicks;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  return (static_cast<TickType_t>(deltaTicks) / static_cast<TickType_t>(configTICK_RATE_HZ)) * 1000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimerController::timerEnd(void* p_context) {
 | 
			
		||||
  
 | 
			
		||||
  auto* controller = static_cast<Controllers::TimerController*> (p_context);
 | 
			
		||||
  controller->timerRunning = false;
 | 
			
		||||
  controller->systemTask.PushMessage(System::SystemTask::Messages::OnTimerDone);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimerController::StopTimer() {
 | 
			
		||||
  app_timer_stop(timerAppTimer);
 | 
			
		||||
  timerRunning = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool TimerController::IsRunning() {
 | 
			
		||||
  return timerRunning;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										36
									
								
								src/components/timer/TimerController.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/components/timer/TimerController.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <cstdint>
 | 
			
		||||
#include "app_timer.h"
 | 
			
		||||
#include "portmacro_cmsis.h"
 | 
			
		||||
 | 
			
		||||
namespace Pinetime {
 | 
			
		||||
  namespace System {
 | 
			
		||||
    class SystemTask;
 | 
			
		||||
  }
 | 
			
		||||
  namespace Controllers {
 | 
			
		||||
    
 | 
			
		||||
    class TimerController {
 | 
			
		||||
    public:
 | 
			
		||||
      TimerController(Pinetime::System::SystemTask& systemTask);
 | 
			
		||||
      
 | 
			
		||||
      void Init();
 | 
			
		||||
      
 | 
			
		||||
      void StartTimer(uint32_t duration);
 | 
			
		||||
      
 | 
			
		||||
      void StopTimer();
 | 
			
		||||
      
 | 
			
		||||
      uint32_t GetTimeRemaining();
 | 
			
		||||
      
 | 
			
		||||
      bool IsRunning();
 | 
			
		||||
    
 | 
			
		||||
    private:
 | 
			
		||||
      System::SystemTask& systemTask;
 | 
			
		||||
      
 | 
			
		||||
      static void timerEnd(void* p_context);
 | 
			
		||||
  
 | 
			
		||||
      TickType_t endTicks;
 | 
			
		||||
      bool timerRunning = false;
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -11,6 +11,7 @@ namespace Pinetime {
 | 
			
		||||
      FirmwareValidation,
 | 
			
		||||
      NotificationsPreview,
 | 
			
		||||
      Notifications,
 | 
			
		||||
      Timer,
 | 
			
		||||
      FlashLight,
 | 
			
		||||
      BatteryInfo,
 | 
			
		||||
      Music,
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@
 | 
			
		||||
#include <libraries/log/nrf_log.h>
 | 
			
		||||
#include <displayapp/screens/HeartRate.h>
 | 
			
		||||
#include <displayapp/screens/Motion.h>
 | 
			
		||||
#include <displayapp/screens/Timer.h>
 | 
			
		||||
#include "components/battery/BatteryController.h"
 | 
			
		||||
#include "components/ble/BleController.h"
 | 
			
		||||
#include "components/datetime/DateTimeController.h"
 | 
			
		||||
@ -55,7 +56,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
 | 
			
		||||
                       Pinetime::Controllers::HeartRateController& heartRateController,
 | 
			
		||||
                       Controllers::Settings& settingsController,
 | 
			
		||||
                       Pinetime::Controllers::MotorController& motorController,
 | 
			
		||||
                       Pinetime::Controllers::MotionController& motionController)
 | 
			
		||||
                       Pinetime::Controllers::MotionController& motionController,
 | 
			
		||||
                       Pinetime::Controllers::TimerController& timerController)
 | 
			
		||||
  : lcd {lcd},
 | 
			
		||||
    lvgl {lvgl},
 | 
			
		||||
    touchPanel {touchPanel},
 | 
			
		||||
@ -68,7 +70,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
 | 
			
		||||
    heartRateController {heartRateController},
 | 
			
		||||
    settingsController {settingsController},
 | 
			
		||||
    motorController {motorController},
 | 
			
		||||
    motionController {motionController} {
 | 
			
		||||
    motionController {motionController},
 | 
			
		||||
    timerController {timerController} {
 | 
			
		||||
  msgQueue = xQueueCreate(queueSize, itemSize);
 | 
			
		||||
  // Start clock when smartwatch boots
 | 
			
		||||
  LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
 | 
			
		||||
@ -148,6 +151,14 @@ void DisplayApp::Refresh() {
 | 
			
		||||
      case Messages::NewNotification:
 | 
			
		||||
        LoadApp(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
 | 
			
		||||
        break;
 | 
			
		||||
      case Messages::TimerDone:
 | 
			
		||||
        if (currentApp == Apps::Timer) {
 | 
			
		||||
          auto *timer = dynamic_cast<Screens::Timer*>(currentScreen.get());
 | 
			
		||||
          timer->setDone();
 | 
			
		||||
        } else {
 | 
			
		||||
          LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
      case Messages::TouchEvent: {
 | 
			
		||||
        if (state != States::Running)
 | 
			
		||||
          break;
 | 
			
		||||
@ -264,6 +275,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
 | 
			
		||||
        this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview);
 | 
			
		||||
      ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
 | 
			
		||||
      break;
 | 
			
		||||
    case Apps::Timer:
 | 
			
		||||
      currentScreen = std::make_unique<Screens::Timer>(this, timerController);
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
    // Settings
 | 
			
		||||
    case Apps::QuickSettings:
 | 
			
		||||
 | 
			
		||||
@ -12,6 +12,7 @@
 | 
			
		||||
#include "components/firmwarevalidator/FirmwareValidator.h"
 | 
			
		||||
#include "components/settings/Settings.h"
 | 
			
		||||
#include "displayapp/screens/Screen.h"
 | 
			
		||||
#include "components/timer/TimerController.h"
 | 
			
		||||
#include "Messages.h"
 | 
			
		||||
 | 
			
		||||
namespace Pinetime {
 | 
			
		||||
@ -53,7 +54,8 @@ namespace Pinetime {
 | 
			
		||||
                 Pinetime::Controllers::HeartRateController& heartRateController,
 | 
			
		||||
                 Controllers::Settings& settingsController,
 | 
			
		||||
                 Pinetime::Controllers::MotorController& motorController,
 | 
			
		||||
                 Pinetime::Controllers::MotionController& motionController);
 | 
			
		||||
                 Pinetime::Controllers::MotionController& motionController,
 | 
			
		||||
                 Pinetime::Controllers::TimerController& timerController);
 | 
			
		||||
      void Start();
 | 
			
		||||
      void PushMessage(Display::Messages msg);
 | 
			
		||||
 | 
			
		||||
@ -76,6 +78,7 @@ namespace Pinetime {
 | 
			
		||||
      Pinetime::Controllers::Settings& settingsController;
 | 
			
		||||
      Pinetime::Controllers::MotorController& motorController;
 | 
			
		||||
      Pinetime::Controllers::MotionController& motionController;
 | 
			
		||||
      Pinetime::Controllers::TimerController& timerController;
 | 
			
		||||
 | 
			
		||||
      Pinetime::Controllers::FirmwareValidator validator;
 | 
			
		||||
      Controllers::BrightnessController brightnessController;
 | 
			
		||||
 | 
			
		||||
@ -17,9 +17,10 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
 | 
			
		||||
                       System::SystemTask& systemTask,
 | 
			
		||||
                       Pinetime::Controllers::NotificationManager& notificationManager,
 | 
			
		||||
                       Pinetime::Controllers::HeartRateController& heartRateController,
 | 
			
		||||
                       Pinetime::Controllers::Settings& settingsController,
 | 
			
		||||
                       Controllers::Settings& settingsController,
 | 
			
		||||
                       Pinetime::Controllers::MotorController& motorController,
 | 
			
		||||
                       Pinetime::Controllers::MotionController& motionController)
 | 
			
		||||
                       Pinetime::Controllers::MotionController& motionController,
 | 
			
		||||
                       Pinetime::Controllers::TimerController& timerController)
 | 
			
		||||
  : lcd {lcd}, bleController {bleController} {
 | 
			
		||||
  msgQueue = xQueueCreate(queueSize, itemSize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,7 @@
 | 
			
		||||
#include "Apps.h"
 | 
			
		||||
#include "Messages.h"
 | 
			
		||||
#include "DummyLittleVgl.h"
 | 
			
		||||
#include "components/timer/TimerController.h"
 | 
			
		||||
 | 
			
		||||
namespace Pinetime {
 | 
			
		||||
  namespace System {
 | 
			
		||||
@ -41,9 +42,10 @@ namespace Pinetime {
 | 
			
		||||
                 System::SystemTask& systemTask,
 | 
			
		||||
                 Pinetime::Controllers::NotificationManager& notificationManager,
 | 
			
		||||
                 Pinetime::Controllers::HeartRateController& heartRateController,
 | 
			
		||||
                 Pinetime::Controllers::Settings& settingsController,
 | 
			
		||||
                 Controllers::Settings& settingsController,
 | 
			
		||||
                 Pinetime::Controllers::MotorController& motorController,
 | 
			
		||||
                 Pinetime::Controllers::MotionController& motionController);
 | 
			
		||||
                 Pinetime::Controllers::MotionController& motionController,
 | 
			
		||||
                 Pinetime::Controllers::TimerController& timerController);
 | 
			
		||||
      void Start();
 | 
			
		||||
      void PushMessage(Pinetime::Applications::Display::Messages msg);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@ namespace Pinetime {
 | 
			
		||||
        TouchEvent,
 | 
			
		||||
        ButtonPushed,
 | 
			
		||||
        NewNotification,
 | 
			
		||||
        TimerDone,
 | 
			
		||||
        BleFirmwareUpdateStarted,
 | 
			
		||||
        UpdateTimeOut
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,7 @@
 | 
			
		||||
* Do not enable font compression and horizontal subpixel hinting
 | 
			
		||||
* Load the file `JetBrainsMono-Bold.tff` and specify the following range : `0x20-0x7f, 0x410-0x44f`
 | 
			
		||||
* Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following
 | 
			
		||||
  range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024`
 | 
			
		||||
  range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252`
 | 
			
		||||
* Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts`
 | 
			
		||||
 | 
			
		||||
Add new symbols:
 | 
			
		||||
 | 
			
		||||
@ -900,6 +900,13 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = {
 | 
			
		||||
    0x7, 0xe0, 0x0, 0x7, 0xf0, 0x0, 0x3, 0xff,
 | 
			
		||||
    0xff, 0xff, 0xcf, 0xff, 0xff, 0xe0,
 | 
			
		||||
 | 
			
		||||
    /* U+F252 "" */
 | 
			
		||||
    0xff, 0xff, 0xff, 0xfd, 0x80, 0x33, 0x80, 0xe7,
 | 
			
		||||
    0xff, 0xc7, 0xff, 0xf, 0xfe, 0xf, 0xf8, 0xf,
 | 
			
		||||
    0xe0, 0xf, 0x80, 0x7f, 0xc0, 0xe3, 0x83, 0x83,
 | 
			
		||||
    0x86, 0x3, 0x1f, 0xff, 0x3f, 0xfe, 0x7f, 0xfd,
 | 
			
		||||
    0xff, 0xff, 0xff, 0xf8,
 | 
			
		||||
 | 
			
		||||
    /* U+F293 "" */
 | 
			
		||||
    0x7, 0xe0, 0x3f, 0xe0, 0xfb, 0xe3, 0xf3, 0xe7,
 | 
			
		||||
    0xe3, 0xdf, 0xd3, 0xf9, 0xb3, 0xf9, 0x4f, 0xf8,
 | 
			
		||||
@ -1184,17 +1191,18 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
 | 
			
		||||
    {.bitmap_index = 3380, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
 | 
			
		||||
    {.bitmap_index = 3418, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
 | 
			
		||||
    {.bitmap_index = 3456, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
 | 
			
		||||
    {.bitmap_index = 3494, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3},
 | 
			
		||||
    {.bitmap_index = 3532, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
 | 
			
		||||
    {.bitmap_index = 3561, .adv_w = 280, .box_w = 16, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3599, .adv_w = 400, .box_w = 25, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
 | 
			
		||||
    {.bitmap_index = 3665, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
 | 
			
		||||
    {.bitmap_index = 3714, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3764, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3824, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
 | 
			
		||||
    {.bitmap_index = 3877, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3932, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3985, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0}
 | 
			
		||||
    {.bitmap_index = 3494, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3530, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3},
 | 
			
		||||
    {.bitmap_index = 3568, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
 | 
			
		||||
    {.bitmap_index = 3597, .adv_w = 280, .box_w = 16, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3635, .adv_w = 400, .box_w = 25, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
 | 
			
		||||
    {.bitmap_index = 3701, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
 | 
			
		||||
    {.bitmap_index = 3750, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3800, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3860, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
 | 
			
		||||
    {.bitmap_index = 3913, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 3968, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
 | 
			
		||||
    {.bitmap_index = 4021, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*---------------------
 | 
			
		||||
@ -1205,8 +1213,8 @@ static const uint16_t unicode_list_2[] = {
 | 
			
		||||
    0x0, 0x16, 0x23, 0x26, 0x27, 0x28, 0x39, 0x47,
 | 
			
		||||
    0x4a, 0x4b, 0x4c, 0x50, 0x68, 0x94, 0x128, 0x184,
 | 
			
		||||
    0x1e5, 0x1fb, 0x21d, 0x23f, 0x240, 0x241, 0x242, 0x243,
 | 
			
		||||
    0x292, 0x293, 0x2f1, 0x3dc, 0x3fc, 0x45c, 0x54a, 0x55f,
 | 
			
		||||
    0x59e, 0x59f, 0x6a8
 | 
			
		||||
    0x251, 0x292, 0x293, 0x2f1, 0x3dc, 0x3fc, 0x45c, 0x54a,
 | 
			
		||||
    0x55f, 0x59e, 0x59f, 0x6a8
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*Collect the unicode lists and glyph_id offsets*/
 | 
			
		||||
@ -1222,7 +1230,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .range_start = 61441, .range_length = 1705, .glyph_id_start = 160,
 | 
			
		||||
        .unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 35, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
 | 
			
		||||
        .unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 36, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -51,7 +51,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
 | 
			
		||||
    {Symbols::map, Apps::Navigation},
 | 
			
		||||
    {Symbols::shoe, Apps::Steps},
 | 
			
		||||
    {Symbols::heartBeat, Apps::HeartRate},
 | 
			
		||||
    {"", Apps::None},
 | 
			
		||||
    {Symbols::hourGlass, Apps::Timer},
 | 
			
		||||
  }};
 | 
			
		||||
 | 
			
		||||
  return std::make_unique<Screens::Tile>(0, 2, app, settingsController, batteryController, dateTimeController, applications);
 | 
			
		||||
 | 
			
		||||
@ -180,7 +180,6 @@ Notifications::NotificationItem::NotificationItem(const char* title,
 | 
			
		||||
  pchar = strchr(title, '\n');
 | 
			
		||||
  while (pchar != nullptr) {
 | 
			
		||||
    *pchar = ' ';
 | 
			
		||||
    pchar =
 | 
			
		||||
    pchar = strchr(pchar + 1, '\n');
 | 
			
		||||
  }
 | 
			
		||||
  lv_label_set_text(alert_type, title);
 | 
			
		||||
 | 
			
		||||
@ -38,6 +38,7 @@ namespace Pinetime {
 | 
			
		||||
        static constexpr const char* pause = "\xEF\x81\x8C";
 | 
			
		||||
        static constexpr const char* stop = "\xEF\x81\x8D";
 | 
			
		||||
        static constexpr const char* stopWatch = "\xEF\x8B\xB2";
 | 
			
		||||
        static constexpr const char* hourGlass = "\xEF\x89\x92";
 | 
			
		||||
        static constexpr const char* lapsFlag = "\xEF\x80\xA4";
 | 
			
		||||
 | 
			
		||||
        // lv_font_sys_48.c
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										173
									
								
								src/displayapp/screens/Timer.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								src/displayapp/screens/Timer.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,173 @@
 | 
			
		||||
#include "Timer.h"
 | 
			
		||||
 | 
			
		||||
#include "Screen.h"
 | 
			
		||||
#include "Symbols.h"
 | 
			
		||||
#include "lvgl/lvgl.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
using namespace Pinetime::Applications::Screens;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
 | 
			
		||||
  Timer* screen = static_cast<Timer*>(obj->user_data);
 | 
			
		||||
  screen->OnButtonEvent(obj, event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Timer::createButtons() {
 | 
			
		||||
  btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr);
 | 
			
		||||
  btnMinutesUp->user_data = this;
 | 
			
		||||
  lv_obj_set_event_cb(btnMinutesUp, btnEventHandler);
 | 
			
		||||
  lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -80);
 | 
			
		||||
  lv_obj_set_height(btnMinutesUp, 40);
 | 
			
		||||
  lv_obj_set_width(btnMinutesUp, 60);
 | 
			
		||||
  txtMUp = lv_label_create(btnMinutesUp, nullptr);
 | 
			
		||||
  lv_label_set_text(txtMUp, "+");
 | 
			
		||||
  
 | 
			
		||||
  btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr);
 | 
			
		||||
  btnMinutesDown->user_data = this;
 | 
			
		||||
  lv_obj_set_event_cb(btnMinutesDown, btnEventHandler);
 | 
			
		||||
  lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, +40);
 | 
			
		||||
  lv_obj_set_height(btnMinutesDown, 40);
 | 
			
		||||
  lv_obj_set_width(btnMinutesDown, 60);
 | 
			
		||||
  txtMDown = lv_label_create(btnMinutesDown, nullptr);
 | 
			
		||||
  lv_label_set_text(txtMDown, "-");
 | 
			
		||||
  
 | 
			
		||||
  btnSecondsUp = lv_btn_create(lv_scr_act(), nullptr);
 | 
			
		||||
  btnSecondsUp->user_data = this;
 | 
			
		||||
  lv_obj_set_event_cb(btnSecondsUp, btnEventHandler);
 | 
			
		||||
  lv_obj_align(btnSecondsUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 10, -80);
 | 
			
		||||
  lv_obj_set_height(btnSecondsUp, 40);
 | 
			
		||||
  lv_obj_set_width(btnSecondsUp, 60);
 | 
			
		||||
  txtSUp = lv_label_create(btnSecondsUp, nullptr);
 | 
			
		||||
  lv_label_set_text(txtSUp, "+");
 | 
			
		||||
  
 | 
			
		||||
  btnSecondsDown = lv_btn_create(lv_scr_act(), nullptr);
 | 
			
		||||
  btnSecondsDown->user_data = this;
 | 
			
		||||
  lv_obj_set_event_cb(btnSecondsDown, btnEventHandler);
 | 
			
		||||
  lv_obj_align(btnSecondsDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 10, +40);
 | 
			
		||||
  lv_obj_set_height(btnSecondsDown, 40);
 | 
			
		||||
  lv_obj_set_width(btnSecondsDown, 60);
 | 
			
		||||
  txtSDown = lv_label_create(btnSecondsDown, nullptr);
 | 
			
		||||
  lv_label_set_text(txtSDown, "-");
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController)
 | 
			
		||||
    : Screen(app),
 | 
			
		||||
      running{true},
 | 
			
		||||
      timerController{timerController} {
 | 
			
		||||
  
 | 
			
		||||
  time = lv_label_create(lv_scr_act(), nullptr);
 | 
			
		||||
  lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
 | 
			
		||||
  lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
 | 
			
		||||
  
 | 
			
		||||
  uint32_t seconds = timerController.GetTimeRemaining() / 1000;
 | 
			
		||||
  lv_label_set_text_fmt(time, "%02d:%02d", seconds / 60, seconds % 60);
 | 
			
		||||
  
 | 
			
		||||
  lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20);
 | 
			
		||||
  
 | 
			
		||||
  btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
 | 
			
		||||
  btnPlayPause->user_data = this;
 | 
			
		||||
  lv_obj_set_event_cb(btnPlayPause, btnEventHandler);
 | 
			
		||||
  lv_obj_align(btnPlayPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -10);
 | 
			
		||||
  lv_obj_set_height(btnPlayPause, 40);
 | 
			
		||||
  txtPlayPause = lv_label_create(btnPlayPause, nullptr);
 | 
			
		||||
  if (timerController.IsRunning()) {
 | 
			
		||||
    lv_label_set_text(txtPlayPause, Symbols::pause);
 | 
			
		||||
  } else {
 | 
			
		||||
    lv_label_set_text(txtPlayPause, Symbols::play);
 | 
			
		||||
    createButtons();
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Timer::~Timer() {
 | 
			
		||||
  lv_obj_clean(lv_scr_act());
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Timer::Refresh() {
 | 
			
		||||
  if (timerController.IsRunning()) {
 | 
			
		||||
    uint32_t seconds = timerController.GetTimeRemaining() / 1000;
 | 
			
		||||
    lv_label_set_text_fmt(time, "%02d:%02d", seconds / 60, seconds % 60);
 | 
			
		||||
  }
 | 
			
		||||
  return running;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
 | 
			
		||||
  if (event == LV_EVENT_CLICKED) {
 | 
			
		||||
    if (obj == btnPlayPause) {
 | 
			
		||||
      if (timerController.IsRunning()) {
 | 
			
		||||
        lv_label_set_text(txtPlayPause, Symbols::play);
 | 
			
		||||
        uint32_t seconds = timerController.GetTimeRemaining() / 1000;
 | 
			
		||||
        minutesToSet = seconds / 60;
 | 
			
		||||
        secondsToSet = seconds % 60;
 | 
			
		||||
        timerController.StopTimer();
 | 
			
		||||
        createButtons();
 | 
			
		||||
        
 | 
			
		||||
      } else if (secondsToSet + minutesToSet > 0) {
 | 
			
		||||
        lv_label_set_text(txtPlayPause, Symbols::pause);
 | 
			
		||||
        timerController.StartTimer((secondsToSet + minutesToSet * 60) * 1000);
 | 
			
		||||
        
 | 
			
		||||
        lv_obj_del(btnSecondsDown);
 | 
			
		||||
        btnSecondsDown = nullptr;
 | 
			
		||||
        lv_obj_del(btnSecondsUp);
 | 
			
		||||
        btnSecondsUp = nullptr;
 | 
			
		||||
        lv_obj_del(btnMinutesDown);
 | 
			
		||||
        btnMinutesDown = nullptr;
 | 
			
		||||
        lv_obj_del(btnMinutesUp);
 | 
			
		||||
        btnMinutesUp = nullptr;
 | 
			
		||||
        
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      if (!timerController.IsRunning()) {
 | 
			
		||||
        if (obj == btnMinutesUp) {
 | 
			
		||||
          if (minutesToSet >= 59) {
 | 
			
		||||
            minutesToSet = 0;
 | 
			
		||||
          } else {
 | 
			
		||||
            minutesToSet++;
 | 
			
		||||
          }
 | 
			
		||||
          lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
 | 
			
		||||
          
 | 
			
		||||
        } else if (obj == btnMinutesDown) {
 | 
			
		||||
          if (minutesToSet == 0) {
 | 
			
		||||
            minutesToSet = 59;
 | 
			
		||||
          } else {
 | 
			
		||||
            minutesToSet--;
 | 
			
		||||
          }
 | 
			
		||||
          lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
 | 
			
		||||
          
 | 
			
		||||
        } else if (obj == btnSecondsUp) {
 | 
			
		||||
          if (secondsToSet >= 59) {
 | 
			
		||||
            secondsToSet = 0;
 | 
			
		||||
          } else {
 | 
			
		||||
            secondsToSet++;
 | 
			
		||||
          }
 | 
			
		||||
          lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
 | 
			
		||||
          
 | 
			
		||||
        } else if (obj == btnSecondsDown) {
 | 
			
		||||
          if (secondsToSet == 0) {
 | 
			
		||||
            secondsToSet = 59;
 | 
			
		||||
          } else {
 | 
			
		||||
            secondsToSet--;
 | 
			
		||||
          }
 | 
			
		||||
          lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
 | 
			
		||||
          
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void Timer::setDone() {
 | 
			
		||||
  lv_label_set_text(time, "00:00");
 | 
			
		||||
  lv_label_set_text(txtPlayPause, Symbols::play);
 | 
			
		||||
  secondsToSet = 0;
 | 
			
		||||
  minutesToSet = 0;
 | 
			
		||||
  createButtons();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								src/displayapp/screens/Timer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/displayapp/screens/Timer.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,42 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "Screen.h"
 | 
			
		||||
#include "components/datetime/DateTimeController.h"
 | 
			
		||||
#include "systemtask/SystemTask.h"
 | 
			
		||||
#include "../LittleVgl.h"
 | 
			
		||||
 | 
			
		||||
#include "components/timer/TimerController.h"
 | 
			
		||||
 | 
			
		||||
namespace Pinetime::Applications::Screens {
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  class Timer : public Screen {
 | 
			
		||||
  public:
 | 
			
		||||
    
 | 
			
		||||
    enum class Modes {
 | 
			
		||||
      Normal, Done
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    Timer(DisplayApp* app, Controllers::TimerController& timerController);
 | 
			
		||||
    
 | 
			
		||||
    ~Timer() override;
 | 
			
		||||
    
 | 
			
		||||
    bool Refresh() override;
 | 
			
		||||
    
 | 
			
		||||
    void setDone();
 | 
			
		||||
    
 | 
			
		||||
    void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
 | 
			
		||||
  
 | 
			
		||||
  private:
 | 
			
		||||
    
 | 
			
		||||
    bool running;
 | 
			
		||||
    uint8_t secondsToSet = 0;
 | 
			
		||||
    uint8_t minutesToSet = 0;
 | 
			
		||||
    Controllers::TimerController& timerController;
 | 
			
		||||
    
 | 
			
		||||
    void createButtons();
 | 
			
		||||
    
 | 
			
		||||
    lv_obj_t* time, * msecTime, * btnPlayPause, * txtPlayPause, * btnMinutesUp, * btnMinutesDown, * btnSecondsUp, * btnSecondsDown, * txtMUp,
 | 
			
		||||
        * txtMDown, * txtSUp, * txtSDown;
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
@ -56,6 +56,7 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
 | 
			
		||||
    heartRateController {*this},
 | 
			
		||||
    bleController {bleController},
 | 
			
		||||
    dateTimeController {*this},
 | 
			
		||||
    timerController {*this},
 | 
			
		||||
    watchdog {},
 | 
			
		||||
    watchdogView {watchdog},
 | 
			
		||||
    motorController {motorController},
 | 
			
		||||
@ -83,6 +84,8 @@ void SystemTask::Work() {
 | 
			
		||||
  NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
 | 
			
		||||
  APP_GPIOTE_INIT(2);
 | 
			
		||||
 | 
			
		||||
  app_timer_init();
 | 
			
		||||
  
 | 
			
		||||
  spi.Init();
 | 
			
		||||
  spiNorFlash.Init();
 | 
			
		||||
  spiNorFlash.Wakeup();
 | 
			
		||||
@ -96,6 +99,7 @@ void SystemTask::Work() {
 | 
			
		||||
  batteryController.Init();
 | 
			
		||||
  motorController.Init();
 | 
			
		||||
  motionSensor.SoftReset();
 | 
			
		||||
  timerController.Init();
 | 
			
		||||
 | 
			
		||||
  // Reset the TWI device because the motion sensor chip most probably crashed it...
 | 
			
		||||
  twiMaster.Sleep();
 | 
			
		||||
@ -116,7 +120,8 @@ void SystemTask::Work() {
 | 
			
		||||
                                                                    heartRateController,
 | 
			
		||||
                                                                    settingsController,
 | 
			
		||||
                                                                    motorController,
 | 
			
		||||
                                                                    motionController);
 | 
			
		||||
                                                                    motionController,
 | 
			
		||||
                                                                    timerController);
 | 
			
		||||
  displayApp->Start();
 | 
			
		||||
 | 
			
		||||
  displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
 | 
			
		||||
@ -233,11 +238,19 @@ void SystemTask::Work() {
 | 
			
		||||
          displayApp->PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime);
 | 
			
		||||
          break;
 | 
			
		||||
        case Messages::OnNewNotification:
 | 
			
		||||
          if (isSleeping && !isWakingUp)
 | 
			
		||||
          if (isSleeping && !isWakingUp) {
 | 
			
		||||
            GoToRunning();
 | 
			
		||||
          }
 | 
			
		||||
          motorController.SetDuration(35);
 | 
			
		||||
          displayApp->PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
 | 
			
		||||
          break;
 | 
			
		||||
        case Messages::OnTimerDone:
 | 
			
		||||
          if (isSleeping && !isWakingUp) {
 | 
			
		||||
            GoToRunning();
 | 
			
		||||
          }
 | 
			
		||||
          motorController.SetDuration(35);
 | 
			
		||||
          displayApp->PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
 | 
			
		||||
          break;
 | 
			
		||||
        case Messages::BleConnected:
 | 
			
		||||
          ReloadIdleTimer();
 | 
			
		||||
          isBleDiscoveryTimerRunning = true;
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,7 @@
 | 
			
		||||
#include "components/ble/NimbleController.h"
 | 
			
		||||
#include "components/ble/NotificationManager.h"
 | 
			
		||||
#include "components/motor/MotorController.h"
 | 
			
		||||
#include "components/timer/TimerController.h"
 | 
			
		||||
#ifdef PINETIME_IS_RECOVERY
 | 
			
		||||
  #include "displayapp/DisplayAppRecovery.h"
 | 
			
		||||
  #include "displayapp/DummyLittleVgl.h"
 | 
			
		||||
@ -45,6 +46,7 @@ namespace Pinetime {
 | 
			
		||||
        TouchWakeUp,
 | 
			
		||||
        OnNewTime,
 | 
			
		||||
        OnNewNotification,
 | 
			
		||||
        OnTimerDone,
 | 
			
		||||
        OnNewCall,
 | 
			
		||||
        BleConnected,
 | 
			
		||||
        UpdateTimeOut,
 | 
			
		||||
@ -100,6 +102,7 @@ namespace Pinetime {
 | 
			
		||||
 | 
			
		||||
      Pinetime::Controllers::Ble& bleController;
 | 
			
		||||
      Pinetime::Controllers::DateTime dateTimeController;
 | 
			
		||||
      Pinetime::Controllers::TimerController timerController;
 | 
			
		||||
      QueueHandle_t systemTasksMsgQueue;
 | 
			
		||||
      std::atomic<bool> isSleeping {false};
 | 
			
		||||
      std::atomic<bool> isGoingToSleep {false};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user