Skip to content

Commit e468acc

Browse files
authored
Merge branch 'develop' into update_touch_driver
2 parents 8f07711 + 5855906 commit e468acc

24 files changed

Lines changed: 644 additions & 15 deletions

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ name: Build PineTime Firmware
99
# When to run this Workflow...
1010
on:
1111

12-
# Run this Workflow when files are updated (Pushed) in the "master" Branch
12+
# Run this Workflow when files are updated (Pushed) in the "master" and "develop" Branch
1313
push:
14-
branches: [ master ]
14+
branches: [ master, develop ]
1515

16-
# Also run this Workflow when a Pull Request is created or updated in the "master" Branch
16+
# Also run this Workflow when a Pull Request is created or updated in the "master" and "develop" Branch
1717
pull_request:
18-
branches: [ master ]
18+
branches: [ master, develop ]
1919

2020
# Steps to run for the Workflow
2121
jobs:

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ Testing/Temporary/
3838
**/.DS_Store
3939

4040
# Windows
41-
**/thumbs.db
41+
**/thumbs.db
42+
43+
#VSCODE
44+
.vscode/.cortex-debug.registers.state.json
45+
.vscode/.cortex-debug.peripherals.state.json

.vscode/settings.json

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,55 @@
55
"-DNRF5_SDK_PATH=${env:NRF5_SDK_PATH}",
66
],
77
"cmake.generator": "Unix Makefiles",
8-
"clang-tidy.buildPath": "build/compile_commands.json"
8+
"clang-tidy.buildPath": "build/compile_commands.json",
9+
"files.associations": {
10+
"array": "cpp",
11+
"atomic": "cpp",
12+
"bit": "cpp",
13+
"*.tcc": "cpp",
14+
"bitset": "cpp",
15+
"cctype": "cpp",
16+
"chrono": "cpp",
17+
"clocale": "cpp",
18+
"cmath": "cpp",
19+
"cstdarg": "cpp",
20+
"cstddef": "cpp",
21+
"cstdint": "cpp",
22+
"cstdio": "cpp",
23+
"cstdlib": "cpp",
24+
"ctime": "cpp",
25+
"cwchar": "cpp",
26+
"cwctype": "cpp",
27+
"deque": "cpp",
28+
"unordered_map": "cpp",
29+
"vector": "cpp",
30+
"exception": "cpp",
31+
"algorithm": "cpp",
32+
"functional": "cpp",
33+
"iterator": "cpp",
34+
"memory": "cpp",
35+
"memory_resource": "cpp",
36+
"numeric": "cpp",
37+
"optional": "cpp",
38+
"random": "cpp",
39+
"ratio": "cpp",
40+
"string": "cpp",
41+
"string_view": "cpp",
42+
"system_error": "cpp",
43+
"tuple": "cpp",
44+
"type_traits": "cpp",
45+
"utility": "cpp",
46+
"fstream": "cpp",
47+
"initializer_list": "cpp",
48+
"iosfwd": "cpp",
49+
"istream": "cpp",
50+
"limits": "cpp",
51+
"new": "cpp",
52+
"ostream": "cpp",
53+
"sstream": "cpp",
54+
"stdexcept": "cpp",
55+
"streambuf": "cpp",
56+
"cinttypes": "cpp",
57+
"typeinfo": "cpp"
58+
}
959
}

gcc_nrf52-mcuboot.ld

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ GROUP(-lgcc -lc -lnosys)
66
MEMORY
77
{
88
FLASH (rx) : ORIGIN = 0x08020, LENGTH = 0x78000
9-
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
9+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
1010
}
1111

1212
SECTIONS
1313
{
14-
}
14+
.noinit(NOLOAD):
15+
{
16+
PROVIDE(__start_noinit_data = .);
17+
*(.noinit)
18+
PROVIDE(__stop_noinit_data = .);
19+
} > RAM
20+
} INSERT AFTER .bss
1521

1622
SECTIONS
1723
{

gcc_nrf52.ld

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ GROUP(-lgcc -lc -lnosys)
66
MEMORY
77
{
88
FLASH (rx) : ORIGIN = 0x00000, LENGTH = 0x78000
9-
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
9+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
1010
}
1111

1212
SECTIONS
1313
{
14-
}
14+
.noinit(NOLOAD):
15+
{
16+
PROVIDE(__start_noinit_data = .);
17+
*(.noinit)
18+
PROVIDE(__stop_noinit_data = .);
19+
} > RAM
20+
} INSERT AFTER .bss
1521

1622
SECTIONS
1723
{
@@ -44,6 +50,7 @@ SECTIONS
4450
PROVIDE(__stop_log_filter_data = .);
4551
} > RAM
4652

53+
4754
} INSERT AFTER .data;
4855

4956
SECTIONS

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ list(APPEND SOURCE_FILES
422422
displayapp/screens/Steps.cpp
423423
displayapp/screens/Timer.cpp
424424
displayapp/screens/Error.cpp
425+
displayapp/screens/Alarm.cpp
425426
displayapp/Colors.cpp
426427

427428
## Settings
@@ -478,6 +479,7 @@ list(APPEND SOURCE_FILES
478479
components/motor/MotorController.cpp
479480
components/settings/Settings.cpp
480481
components/timer/TimerController.cpp
482+
components/alarm/AlarmController.cpp
481483
components/fs/FS.cpp
482484
drivers/Cst816s.cpp
483485
FreeRTOS/port.c
@@ -544,6 +546,7 @@ list(APPEND RECOVERY_SOURCE_FILES
544546
components/firmwarevalidator/FirmwareValidator.cpp
545547
components/settings/Settings.cpp
546548
components/timer/TimerController.cpp
549+
components/alarm/AlarmController.cpp
547550
drivers/Cst816s.cpp
548551
FreeRTOS/port.c
549552
FreeRTOS/port_cmsis_systick.c
@@ -616,6 +619,7 @@ set(INCLUDE_FILES
616619
displayapp/screens/Metronome.h
617620
displayapp/screens/Motion.h
618621
displayapp/screens/Timer.h
622+
displayapp/screens/Alarm.h
619623
displayapp/Colors.h
620624
drivers/St7789.h
621625
drivers/SpiNorFlash.h
@@ -648,6 +652,7 @@ set(INCLUDE_FILES
648652
components/ble/HeartRateService.h
649653
components/settings/Settings.h
650654
components/timer/TimerController.h
655+
components/alarm/AlarmController.h
651656
drivers/Cst816s.h
652657
FreeRTOS/portmacro.h
653658
FreeRTOS/portmacro_cmsis.h
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* Copyright (C) 2021 mruss77, Florian
2+
3+
This file is part of InfiniTime.
4+
5+
InfiniTime is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
InfiniTime is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
#include "AlarmController.h"
19+
#include "systemtask/SystemTask.h"
20+
#include "app_timer.h"
21+
#include "task.h"
22+
#include <chrono>
23+
24+
using namespace Pinetime::Controllers;
25+
using namespace std::chrono_literals;
26+
27+
AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
28+
}
29+
30+
APP_TIMER_DEF(alarmAppTimer);
31+
32+
namespace {
33+
void SetOffAlarm(void* p_context) {
34+
auto* controller = static_cast<Pinetime::Controllers::AlarmController*>(p_context);
35+
if (controller != nullptr) {
36+
controller->SetOffAlarmNow();
37+
}
38+
}
39+
}
40+
41+
void AlarmController::Init(System::SystemTask* systemTask) {
42+
app_timer_create(&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm);
43+
this->systemTask = systemTask;
44+
}
45+
46+
void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) {
47+
hours = alarmHr;
48+
minutes = alarmMin;
49+
}
50+
51+
void AlarmController::ScheduleAlarm() {
52+
// Determine the next time the alarm needs to go off and set the app_timer
53+
app_timer_stop(alarmAppTimer);
54+
55+
auto now = dateTimeController.CurrentDateTime();
56+
alarmTime = now;
57+
time_t ttAlarmTime = std::chrono::system_clock::to_time_t(alarmTime);
58+
tm* tmAlarmTime = std::localtime(&ttAlarmTime);
59+
60+
// If the time being set has already passed today,the alarm should be set for tomorrow
61+
if (hours < dateTimeController.Hours() || (hours == dateTimeController.Hours() && minutes <= dateTimeController.Minutes())) {
62+
tmAlarmTime->tm_mday += 1;
63+
// tm_wday doesn't update automatically
64+
tmAlarmTime->tm_wday = (tmAlarmTime->tm_wday + 1) % 7;
65+
}
66+
67+
tmAlarmTime->tm_hour = hours;
68+
tmAlarmTime->tm_min = minutes;
69+
tmAlarmTime->tm_sec = 0;
70+
71+
// if alarm is in weekday-only mode, make sure it shifts to the next weekday
72+
if (recurrence == RecurType::Weekdays) {
73+
if (tmAlarmTime->tm_wday == 0) { // Sunday, shift 1 day
74+
tmAlarmTime->tm_mday += 1;
75+
} else if (tmAlarmTime->tm_wday == 6) { // Saturday, shift 2 days
76+
tmAlarmTime->tm_mday += 2;
77+
}
78+
}
79+
tmAlarmTime->tm_isdst = -1; // use system timezone setting to determine DST
80+
81+
// now can convert back to a time_point
82+
alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime));
83+
auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count();
84+
app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this);
85+
86+
state = AlarmState::Set;
87+
}
88+
89+
uint32_t AlarmController::SecondsToAlarm() {
90+
return std::chrono::duration_cast<std::chrono::seconds>(alarmTime - dateTimeController.CurrentDateTime()).count();
91+
}
92+
93+
void AlarmController::DisableAlarm() {
94+
app_timer_stop(alarmAppTimer);
95+
state = AlarmState::Not_Set;
96+
}
97+
98+
void AlarmController::SetOffAlarmNow() {
99+
state = AlarmState::Alerting;
100+
systemTask->PushMessage(System::Messages::SetOffAlarm);
101+
}
102+
103+
void AlarmController::StopAlerting() {
104+
systemTask->PushMessage(System::Messages::StopRinging);
105+
106+
// Alarm state is off unless this is a recurring alarm
107+
if (recurrence == RecurType::None) {
108+
state = AlarmState::Not_Set;
109+
} else {
110+
state = AlarmState::Set;
111+
// set next instance
112+
ScheduleAlarm();
113+
}
114+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* Copyright (C) 2021 mruss77, Florian
2+
3+
This file is part of InfiniTime.
4+
5+
InfiniTime is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
InfiniTime is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
#pragma once
19+
20+
#include <cstdint>
21+
#include "app_timer.h"
22+
#include "components/datetime/DateTimeController.h"
23+
24+
namespace Pinetime {
25+
namespace System {
26+
class SystemTask;
27+
}
28+
namespace Controllers {
29+
class AlarmController {
30+
public:
31+
AlarmController(Controllers::DateTime& dateTimeController);
32+
33+
void Init(System::SystemTask* systemTask);
34+
void SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin);
35+
void ScheduleAlarm();
36+
void DisableAlarm();
37+
void SetOffAlarmNow();
38+
uint32_t SecondsToAlarm();
39+
void StopAlerting();
40+
enum class AlarmState { Not_Set, Set, Alerting };
41+
enum class RecurType { None, Daily, Weekdays };
42+
uint8_t Hours() const {
43+
return hours;
44+
}
45+
uint8_t Minutes() const {
46+
return minutes;
47+
}
48+
AlarmState State() const {
49+
return state;
50+
}
51+
RecurType Recurrence() const {
52+
return recurrence;
53+
}
54+
void SetRecurrence(RecurType recurType) {
55+
recurrence = recurType;
56+
}
57+
58+
private:
59+
Controllers::DateTime& dateTimeController;
60+
System::SystemTask* systemTask = nullptr;
61+
uint8_t hours = 7;
62+
uint8_t minutes = 0;
63+
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime;
64+
AlarmState state = AlarmState::Not_Set;
65+
RecurType recurrence = RecurType::None;
66+
};
67+
}
68+
}

src/components/datetime/DateTimeController.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
using namespace Pinetime::Controllers;
77

8+
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
9+
this->currentDateTime = t;
10+
}
11+
812
void DateTime::SetTime(
913
uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second, uint32_t systickCounter) {
1014
std::tm tm = {
@@ -67,7 +71,7 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
6771
// Notify new day to SystemTask
6872
if (hour == 0 and not isMidnightAlreadyNotified) {
6973
isMidnightAlreadyNotified = true;
70-
if(systemTask != nullptr)
74+
if (systemTask != nullptr)
7175
systemTask->PushMessage(System::Messages::OnNewDay);
7276
} else if (hour != 0) {
7377
isMidnightAlreadyNotified = false;

src/components/datetime/DateTimeController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace Pinetime {
7474
}
7575

7676
void Register(System::SystemTask* systemTask);
77+
void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
7778

7879
private:
7980
uint16_t year = 0;

0 commit comments

Comments
 (0)