Skip to content

Commit eb769fb

Browse files
committed
Merge branch 'motion-sensor' into develop
2 parents 57b4c3f + 15b3b8e commit eb769fb

33 files changed

Lines changed: 12470 additions & 254 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(pinetime VERSION 0.15.0 LANGUAGES C CXX ASM)
2+
project(pinetime VERSION 0.16.0 LANGUAGES C CXX ASM)
33

44
set(CMAKE_C_STANDARD 99)
55
set(CMAKE_CXX_STANDARD 14)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ As of now, here is the list of achievements of this project:
3434
- Rich user interface via display, touchscreen and pushbutton
3535
- Time synchronization via BLE
3636
- Notification via BLE
37+
- Heart rate measurements
38+
- Step counting
39+
- Wake-up on wrist rotation
3740
- Multiple 'apps' :
3841
* Clock (displays the date, time, battery level, ble connection status, heart rate)
3942
* System info (displays various info : BLE MAC, build date/time, uptime, version,...)

src/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ set(SDK_SOURCE_FILES
8383
"${NRF5_SDK_PATH}/external/fprintf/nrf_fprintf_format.c"
8484

8585
# TWI
86-
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_twi.c"
86+
"${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_twim.c"
8787

8888
# GPIOTE
8989
"${NRF5_SDK_PATH}/components/libraries/gpiote/app_gpiote.c"
@@ -396,11 +396,13 @@ list(APPEND SOURCE_FILES
396396
displayapp/screens/FirmwareUpdate.cpp
397397
displayapp/screens/Music.cpp
398398
displayapp/screens/Navigation.cpp
399+
displayapp/screens/Motion.cpp
399400
displayapp/screens/FirmwareValidation.cpp
400401
displayapp/screens/ApplicationList.cpp
401402
displayapp/screens/Notifications.cpp
402403
displayapp/screens/Twos.cpp
403404
displayapp/screens/HeartRate.cpp
405+
displayapp/screens/Motion.cpp
404406
displayapp/screens/FlashLight.cpp
405407
displayapp/screens/List.cpp
406408
displayapp/screens/BatteryInfo.cpp
@@ -429,11 +431,15 @@ list(APPEND SOURCE_FILES
429431
drivers/DebugPins.cpp
430432
drivers/InternalFlash.cpp
431433
drivers/Hrs3300.cpp
434+
drivers/Bma421.cpp
435+
drivers/Bma421_C/bma4.c
436+
drivers/Bma421_C/bma423.c
432437
components/battery/BatteryController.cpp
433438
components/ble/BleController.cpp
434439
components/ble/NotificationManager.cpp
435440
components/datetime/DateTimeController.cpp
436441
components/brightness/BrightnessController.cpp
442+
components/motion/MotionController.cpp
437443
components/ble/NimbleController.cpp
438444
components/ble/DeviceInformationService.cpp
439445
components/ble/CurrentTimeClient.cpp
@@ -487,11 +493,15 @@ list(APPEND RECOVERY_SOURCE_FILES
487493
drivers/DebugPins.cpp
488494
drivers/InternalFlash.cpp
489495
drivers/Hrs3300.cpp
496+
drivers/Bma421.cpp
497+
drivers/Bma421_C/bma4.c
498+
drivers/Bma421_C/bma423.c
490499
components/battery/BatteryController.cpp
491500
components/ble/BleController.cpp
492501
components/ble/NotificationManager.cpp
493502
components/datetime/DateTimeController.cpp
494503
components/brightness/BrightnessController.cpp
504+
components/motion/MotionController.cpp
495505
components/ble/NimbleController.cpp
496506
components/ble/DeviceInformationService.cpp
497507
components/ble/CurrentTimeClient.cpp
@@ -576,6 +586,7 @@ set(INCLUDE_FILES
576586
displayapp/Apps.h
577587
displayapp/screens/Notifications.h
578588
displayapp/screens/HeartRate.h
589+
displayapp/screens/Motion.h
579590
drivers/St7789.h
580591
drivers/SpiNorFlash.h
581592
drivers/SpiMaster.h
@@ -584,11 +595,15 @@ set(INCLUDE_FILES
584595
drivers/DebugPins.h
585596
drivers/InternalFlash.h
586597
drivers/Hrs3300.h
598+
drivers/Bma421.h
599+
drivers/Bma421_C/bma4.c
600+
drivers/Bma421_C/bma423.c
587601
components/battery/BatteryController.h
588602
components/ble/BleController.h
589603
components/ble/NotificationManager.h
590604
components/datetime/DateTimeController.h
591605
components/brightness/BrightnessController.h
606+
components/motion/MotionController.h
592607
components/ble/NimbleController.h
593608
components/ble/DeviceInformationService.h
594609
components/ble/CurrentTimeClient.h

src/components/datetime/DateTimeController.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#include "DateTimeController.h"
22
#include <date/date.h>
33
#include <libraries/log/nrf_log.h>
4+
#include <systemtask/SystemTask.h>
45

56
using namespace Pinetime::Controllers;
67

8+
DateTime::DateTime(System::SystemTask& systemTask) : systemTask{systemTask} {
9+
10+
}
11+
712

813
void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute,
914
uint8_t second, uint32_t systickCounter) {
@@ -62,6 +67,14 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
6267
hour = time.hours().count();
6368
minute = time.minutes().count();
6469
second = time.seconds().count();
70+
71+
// Notify new day to SystemTask
72+
if(hour == 0 and not isMidnightAlreadyNotified) {
73+
isMidnightAlreadyNotified = true;
74+
systemTask.PushMessage(System::SystemTask::Messages::OnNewDay);
75+
} else if (hour != 0) {
76+
isMidnightAlreadyNotified = false;
77+
}
6578
}
6679

6780
const char *DateTime::MonthShortToString() {

src/components/datetime/DateTimeController.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
#include <chrono>
55

66
namespace Pinetime {
7+
namespace System {
8+
class SystemTask;
9+
}
710
namespace Controllers {
811
class DateTime {
912
public:
1013
enum class Days : uint8_t {Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};
1114
enum class Months : uint8_t {Unknown, January, February, March, April, May, June, July, August, September, October, November, December};
1215

16+
DateTime(System::SystemTask& systemTask);
17+
1318
void SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter);
1419
void UpdateTime(uint32_t systickCounter);
1520
uint16_t Year() const { return year; }
@@ -31,6 +36,7 @@ namespace Pinetime {
3136
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; }
3237
std::chrono::seconds Uptime() const { return uptime; }
3338
private:
39+
System::SystemTask& systemTask;
3440
uint16_t year = 0;
3541
Months month = Months::Unknown;
3642
uint8_t day = 0;
@@ -43,6 +49,8 @@ namespace Pinetime {
4349
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
4450
std::chrono::seconds uptime {0};
4551

52+
bool isMidnightAlreadyNotified = false;
53+
4654
static char const *DaysString[];
4755
static char const *DaysStringShort[];
4856
static char const *DaysStringLow[];
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "MotionController.h"
2+
3+
using namespace Pinetime::Controllers;
4+
5+
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
6+
this->x = x;
7+
this->y = y;
8+
this->z = z;
9+
this->nbSteps = nbSteps;
10+
}
11+
12+
bool MotionController::ShouldWakeUp(bool isSleeping) {
13+
if ((x + 335) <= 670 && z < 0) {
14+
if (not isSleeping) {
15+
if (y <= 0) {
16+
return false;
17+
} else {
18+
lastYForWakeUp = 0;
19+
return false;
20+
}
21+
}
22+
23+
if (y >= 0) {
24+
lastYForWakeUp = 0;
25+
return false;
26+
}
27+
if (y + 230 < lastYForWakeUp) {
28+
lastYForWakeUp = y;
29+
return true;
30+
}
31+
}
32+
return false;
33+
}
34+
void MotionController::IsSensorOk(bool isOk) {
35+
isSensorOk = isOk;
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
namespace Pinetime {
6+
namespace Controllers {
7+
class MotionController {
8+
public:
9+
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
10+
11+
uint16_t X() const { return x; }
12+
uint16_t Y() const { return y; }
13+
uint16_t Z() const { return z; }
14+
uint32_t NbSteps() const { return nbSteps; }
15+
bool ShouldWakeUp(bool isSleeping);
16+
17+
void IsSensorOk(bool isOk);
18+
bool IsSensorOk() const { return isSensorOk; }
19+
20+
private:
21+
uint32_t nbSteps;
22+
int16_t x;
23+
int16_t y;
24+
int16_t z;
25+
int16_t lastYForWakeUp = 0;
26+
bool isSensorOk = false;
27+
};
28+
}
29+
}

src/displayapp/Apps.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Pinetime {
44
namespace Applications {
5-
enum class Apps {
5+
enum class Apps {
66
None, Launcher, Clock, SysInfo, FirmwareUpdate, FirmwareValidation, NotificationsPreview, Notifications, FlashLight, BatteryInfo,
7-
Music, Paint, Paddle, Twos, HeartRate, Navigation, StopWatch,
7+
Music, Paint, Paddle, Twos, HeartRate, Navigation, StopWatch, Motion,
88
QuickSettings, Settings, SettingWatchFace, SettingTimeFormat, SettingDisplay, SettingWakeUp
99
};
1010
}

src/displayapp/DisplayApp.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "DisplayApp.h"
22
#include <libraries/log/nrf_log.h>
33
#include <displayapp/screens/HeartRate.h>
4+
#include <displayapp/screens/Motion.h>
45
#include "components/battery/BatteryController.h"
56
#include "components/ble/BleController.h"
67
#include "components/datetime/DateTimeController.h"
78
#include "components/ble/NotificationManager.h"
9+
#include "components/motion/MotionController.h"
810
#include "displayapp/screens/ApplicationList.h"
911
#include "displayapp/screens/Brightness.h"
1012
#include "displayapp/screens/Clock.h"
@@ -43,7 +45,8 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver
4345
System::SystemTask &systemTask,
4446
Pinetime::Controllers::NotificationManager& notificationManager,
4547
Pinetime::Controllers::HeartRateController& heartRateController,
46-
Controllers::Settings &settingsController) :
48+
Controllers::Settings &settingsController,
49+
Pinetime::Controllers::MotionController& motionController) :
4750
lcd{lcd},
4851
lvgl{lvgl},
4952
touchPanel{touchPanel},
@@ -54,7 +57,8 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver
5457
systemTask{systemTask},
5558
notificationManager{notificationManager},
5659
heartRateController{heartRateController},
57-
settingsController{settingsController} {
60+
settingsController{settingsController},
61+
motionController{motionController} {
5862
msgQueue = xQueueCreate(queueSize, itemSize);
5963
// Start clock when smartwatch boots
6064
LoadApp( Apps::Clock, DisplayApp::FullRefreshDirections::None );
@@ -174,7 +178,7 @@ void DisplayApp::Refresh() {
174178
break;
175179
case Messages::UpdateDateTime:
176180
// Added to remove warning
177-
// What should happen here?
181+
// What should happen here?
178182
break;
179183
}
180184
}
@@ -220,7 +224,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
220224
break;
221225
case Apps::None:
222226
case Apps::Clock:
223-
currentScreen = std::make_unique<Screens::Clock>(this, dateTimeController, batteryController, bleController, notificationManager, settingsController, heartRateController);
227+
currentScreen = std::make_unique<Screens::Clock>(this, dateTimeController, batteryController, bleController, notificationManager, settingsController, heartRateController, motionController);
224228
break;
225229

226230
case Apps::FirmwareValidation:
@@ -232,7 +236,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
232236
break;
233237

234238
case Apps::Notifications:
235-
currentScreen = std::make_unique<Screens::Notifications>(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal);
239+
currentScreen = std::make_unique<Screens::Notifications>(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal);
236240
returnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
237241
break;
238242
case Apps::NotificationsPreview:
@@ -245,61 +249,65 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
245249
currentScreen = std::make_unique<Screens::QuickSettings>(this, batteryController, dateTimeController, brightnessController, settingsController);
246250
returnApp(Apps::Clock, FullRefreshDirections::LeftAnim, TouchEvents::SwipeLeft);
247251
break;
248-
case Apps::Settings:
252+
case Apps::Settings:
249253
currentScreen = std::make_unique<Screens::Settings>(this, settingsController);
250254
returnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
251255
break;
252-
case Apps::SettingWatchFace:
256+
case Apps::SettingWatchFace:
253257
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController);
254258
returnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
255259
break;
256-
case Apps::SettingTimeFormat:
260+
case Apps::SettingTimeFormat:
257261
currentScreen = std::make_unique<Screens::SettingTimeFormat>(this, settingsController);
258262
returnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
259263
break;
260-
case Apps::SettingWakeUp:
264+
case Apps::SettingWakeUp:
261265
currentScreen = std::make_unique<Screens::SettingWakeUp>(this, settingsController);
262266
returnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
263267
break;
264-
case Apps::SettingDisplay:
268+
case Apps::SettingDisplay:
265269
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
266270
returnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
267271
break;
268272
case Apps::BatteryInfo:
269273
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
270-
returnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
274+
returnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
271275
break;
272276
case Apps::SysInfo:
273277
currentScreen = std::make_unique<Screens::SystemInfo>(this, dateTimeController, batteryController, brightnessController, bleController, watchdog);
274278
returnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
275279
break;
276280
//
277-
278-
case Apps::FlashLight:
281+
282+
case Apps::FlashLight:
279283
currentScreen = std::make_unique<Screens::FlashLight>(this, systemTask, brightnessController);
280284
returnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
281285
break;
282286
case Apps::StopWatch:
283287
currentScreen = std::make_unique<Screens::StopWatch>(this);
284288
break;
285289
case Apps::Twos:
286-
currentScreen = std::make_unique<Screens::Twos>(this);
290+
currentScreen = std::make_unique<Screens::Twos>(this);
287291
break;
288292
case Apps::Paint:
289-
currentScreen = std::make_unique<Screens::InfiniPaint>(this, lvgl);
293+
currentScreen = std::make_unique<Screens::InfiniPaint>(this, lvgl);
290294
break;
291295
case Apps::Paddle:
292-
currentScreen = std::make_unique<Screens::Paddle>(this, lvgl);
296+
currentScreen = std::make_unique<Screens::Paddle>(this, lvgl);
293297
break;
294298
case Apps::Music:
295-
currentScreen = std::make_unique<Screens::Music>(this, systemTask.nimble().music());
299+
currentScreen = std::make_unique<Screens::Music>(this, systemTask.nimble().music());
296300
break;
297301
case Apps::Navigation:
298-
currentScreen = std::make_unique<Screens::Navigation>(this, systemTask.nimble().navigation());
302+
currentScreen = std::make_unique<Screens::Navigation>(this, systemTask.nimble().navigation());
299303
break;
300304
case Apps::HeartRate:
301-
currentScreen = std::make_unique<Screens::HeartRate>(this, heartRateController, systemTask);
305+
currentScreen = std::make_unique<Screens::HeartRate>(this, heartRateController, systemTask);
302306
break;
307+
case Apps::Motion:
308+
currentScreen = std::make_unique<Screens::Motion>(this, motionController);
309+
break;
310+
303311
}
304312
currentApp = app;
305313
}

0 commit comments

Comments
 (0)