Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity notifications #1675

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FintasticMan
Copy link
Member

@FintasticMan FintasticMan commented Mar 7, 2023

Depends on #1696.

This adds a feature that sends the user a notification if they haven't walked a certain number of steps within the past hour. It works by keeping track of the number of steps every half hour, storing them in a circular buffer. It checks whether difference between the number of steps from the last half hour and the number of steps from an hour before that is lower than the threshold.

The majority of the size increase comes from the settings screen, so if I can make that smaller, that would be good.

I'm not sure if a notification is the best way to handle alerting the user. Suggestions welcome.

@FintasticMan FintasticMan added the enhancement Enhancement to an existing app/feature label Mar 7, 2023
@github-actions
Copy link

github-actions bot commented Mar 7, 2023

Build size and comparison to main:

Section Size Difference
text 397104B 1324B
data 1020B 24B
bss 63428B 8B

Copy link
Contributor

@Riksu9000 Riksu9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality of ActivityController is hard to understand. Consider giving the variables and functions better names, and extracting functions to give labels to the steps.

src/components/activity/ActivityController.cpp Outdated Show resolved Hide resolved
Comment on lines 206 to 201
if (activityController.UpdateSteps(motionController.NbSteps()) &&
settingsController.GetActivity() == Controllers::Settings::Activity::On) {
NRF_LOG_INFO("activity");
Controllers::NotificationManager::Notification notif;
constexpr char message[] = "Low activity\0Fewer steps than threshold in last hour. Try walking around.";
constexpr uint8_t messageSize =
std::min(sizeof message / sizeof(char), Pinetime::Controllers::NotificationManager::MaximumMessageSize());
std::memcpy(notif.message.data(), message, messageSize * sizeof(char));
notif.size = messageSize;
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
notificationManager.Push(std::move(notif));
PushMessage(Messages::OnNewNotification);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to at least one function. Also I'm wondering if this should be part of DisplayApp. What DisplayApp and SystemTask should do is not defined at all, but considering that DisplayAppRecovery does not benefit from this, it probably should not be part of the "system", but rather the "application". I'm working on fixing the ambiguity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this should be moved to a function, but as you say, I'm not sure whether that function should be in NotificationManager, DisplayApp or even SystemTask. Because of this I won't move this to a function yet.

#1482 makes constructing a notification a lot simpler as well, so when that gets cleaned up and merged it might not even need to be moved to its own function.

src/components/activity/ActivityController.cpp Outdated Show resolved Hide resolved
@FintasticMan FintasticMan marked this pull request as draft March 12, 2023 23:16
@FintasticMan FintasticMan marked this pull request as ready for review March 14, 2023 18:12
@FintasticMan FintasticMan force-pushed the activity_notifications branch 3 times, most recently from c3c15b1 to fbefb52 Compare March 14, 2023 20:10
@FintasticMan FintasticMan force-pushed the activity_notifications branch 2 times, most recently from 1f9d941 to 8458383 Compare March 17, 2023 13:42
@Riksu9000
Copy link
Contributor

Riksu9000 commented Mar 18, 2023

Actually I was mistaken. This is not quite like a circular buffer. A class that tracks the changes made to a variable, with template parameters specifying the resolution and how much history is stored would be more appropriate for this use case. You would access the value an hour ago through a function that you pass a time point or duration to.

@FintasticMan FintasticMan added new feature This thread is about a new feature and removed enhancement Enhancement to an existing app/feature labels Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This thread is about a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants