From c77634ce320cdb9bbd9de136e409bd9a0ca64153 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:11:20 +0200 Subject: Added new screen: SettingSetTime diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp new file mode 100644 index 0000000..22d1c01 --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -0,0 +1,174 @@ +#include "SettingSetTime.h" +#include +#include +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t * obj, lv_event_t event) { + SettingSetTime* screen = static_cast(obj->user_data); + screen->HandleButtonPress(obj, event); + } +} + +SettingSetTime::SettingSetTime( + Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : + Screen(app), + dateTimeController {dateTimeController} +{ + + lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr); + + //lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + lv_obj_set_pos(container1, 30, 60); + lv_obj_set_width(container1, LV_HOR_RES - 50); + lv_obj_set_height(container1, LV_VER_RES - 60); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text_static(title, "Set current time"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + + lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + + lv_label_set_text_static(icon, Symbols::clock); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + hoursValue = static_cast(dateTimeController.Hours()); + lblHours = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + + lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblColon1, ":"); + lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, -36, -8); + + minutesValue = static_cast(dateTimeController.Minutes()); + lblMinutes = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + + lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblColon2, ":"); + lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, 36, -8); + + lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_static(lblSeconds, "00"); + lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, 72, -6); + + btnHoursPlus = lv_btn_create(lv_scr_act(), NULL); + btnHoursPlus->user_data = this; + lv_obj_set_size(btnHoursPlus, 50, 40); + lv_obj_align(btnHoursPlus, lv_scr_act(), LV_ALIGN_CENTER, -72, -50); + lv_obj_set_style_local_value_str(btnHoursPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnHoursPlus, event_handler); + + btnHoursMinus = lv_btn_create(lv_scr_act(), NULL); + btnHoursMinus->user_data = this; + lv_obj_set_size(btnHoursMinus, 50, 40); + lv_obj_align(btnHoursMinus, lv_scr_act(), LV_ALIGN_CENTER, -72, 40); + lv_obj_set_style_local_value_str(btnHoursMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnHoursMinus, event_handler); + + btnMinutesPlus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesPlus->user_data = this; + lv_obj_set_size(btnMinutesPlus, 50, 40); + lv_obj_align(btnMinutesPlus, lv_scr_act(), LV_ALIGN_CENTER, 0, -50); + lv_obj_set_style_local_value_str(btnMinutesPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnMinutesPlus, event_handler); + + btnMinutesMinus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesMinus->user_data = this; + lv_obj_set_size(btnMinutesMinus, 50, 40); + lv_obj_align(btnMinutesMinus, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); + lv_obj_set_style_local_value_str(btnMinutesMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnMinutesMinus, event_handler); + + btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime->user_data = this; + lv_obj_set_size(btnSetTime, 70, 40); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); + lv_obj_set_event_cb(btnSetTime, event_handler); +} + +SettingSetTime::~SettingSetTime() { + lv_obj_clean(lv_scr_act()); +} + +bool SettingSetTime::Refresh() { + return running; +} + + +void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { + + if(object == btnHoursPlus && (event == LV_EVENT_PRESSED)) { + hoursValue++; + if (hoursValue > 23) + hoursValue = 0; + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnHoursMinus && (event == LV_EVENT_PRESSED)) { + hoursValue--; + if (hoursValue < 0) + hoursValue = 23; + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnMinutesPlus && (event == LV_EVENT_PRESSED)) { + minutesValue++; + if (minutesValue > 59) + minutesValue = 0; + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnMinutesMinus && (event == LV_EVENT_PRESSED)) { + minutesValue--; + if (minutesValue < 0) + minutesValue = 59; + lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); + dateTimeController.SetTime(dateTimeController.Year(), + static_cast(dateTimeController.Month()), + dateTimeController.Day(), + static_cast(dateTimeController.DayOfWeek()), + static_cast(hoursValue), + static_cast(minutesValue), + 0, + nrf_rtc_counter_get(portNRF_RTC_REG)); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED); + } +} diff --git a/src/displayapp/screens/settings/SettingSetTime.h b/src/displayapp/screens/settings/SettingSetTime.h new file mode 100644 index 0000000..da92d6e --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetTime.h @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include "components/datetime/DateTimeController.h" +#include "displayapp/screens/Screen.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingSetTime : public Screen{ + public: + SettingSetTime(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController); + ~SettingSetTime() override; + + bool Refresh() override; + void HandleButtonPress(lv_obj_t *object, lv_event_t event); + + private: + + Controllers::DateTime& dateTimeController; + + int hoursValue; + int minutesValue; + lv_obj_t * lblHours; + lv_obj_t * lblMinutes; + lv_obj_t * btnHoursPlus; + lv_obj_t * btnHoursMinus; + lv_obj_t * btnMinutesPlus; + lv_obj_t * btnMinutesMinus; + lv_obj_t * btnSetTime; + + }; + } + } +} -- cgit v0.10.2 From c396925766ebfd05f3f345bf426a4fa59305ec74 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:12:26 +0200 Subject: Added new screen: SettingSetDate diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp new file mode 100644 index 0000000..5c1aec5 --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -0,0 +1,272 @@ +#include "SettingSetDate.h" +#include +#include +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" + +#define POS_X_DAY -72 +#define POS_X_MONTH 0 +#define POS_X_YEAR 72 +#define POS_Y_PLUS -50 +#define POS_Y_TEXT -6 +#define POS_Y_MINUS 40 + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t * obj, lv_event_t event) { + SettingSetDate* screen = static_cast(obj->user_data); + screen->HandleButtonPress(obj, event); + } +} + +SettingSetDate::SettingSetDate( + Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : + Screen(app), + dateTimeController {dateTimeController} +{ + + lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr); + + //lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + lv_obj_set_pos(container1, 30, 60); + lv_obj_set_width(container1, LV_HOR_RES - 50); + lv_obj_set_height(container1, LV_VER_RES - 60); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text_static(title, "Set current date"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + + lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + + lv_label_set_text_static(icon, Symbols::clock); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + dayValue = static_cast(dateTimeController.Day()); + lblDay = lv_label_create(lv_scr_act(), NULL); + //lv_obj_set_style_local_text_font(lblDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblDay, "%d", dayValue); + lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + + monthValue = static_cast(dateTimeController.Month()); + lblMonth = lv_label_create(lv_scr_act(), NULL); + //lv_obj_set_style_local_text_font(lblMonth, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + UpdateMonthLabel(); + + yearValue = static_cast(dateTimeController.Year()); + if (yearValue < 2021) + yearValue = 2021; + lblYear = lv_label_create(lv_scr_act(), NULL); + //lv_obj_set_style_local_text_font(lblYear, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_label_set_text_fmt(lblYear, "%d", yearValue); + lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + + btnDayPlus = lv_btn_create(lv_scr_act(), NULL); + btnDayPlus->user_data = this; + lv_obj_set_size(btnDayPlus, 50, 40); + lv_obj_align(btnDayPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_PLUS); + lv_obj_set_style_local_value_str(btnDayPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnDayPlus, event_handler); + + btnDayMinus = lv_btn_create(lv_scr_act(), NULL); + btnDayMinus->user_data = this; + lv_obj_set_size(btnDayMinus, 50, 40); + lv_obj_align(btnDayMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_MINUS); + lv_obj_set_style_local_value_str(btnDayMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnDayMinus, event_handler); + + btnMonthPlus = lv_btn_create(lv_scr_act(), NULL); + btnMonthPlus->user_data = this; + lv_obj_set_size(btnMonthPlus, 50, 40); + lv_obj_align(btnMonthPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_PLUS); + lv_obj_set_style_local_value_str(btnMonthPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnMonthPlus, event_handler); + + btnMonthMinus = lv_btn_create(lv_scr_act(), NULL); + btnMonthMinus->user_data = this; + lv_obj_set_size(btnMonthMinus, 50, 40); + lv_obj_align(btnMonthMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_MINUS); + lv_obj_set_style_local_value_str(btnMonthMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnMonthMinus, event_handler); + + btnYearPlus = lv_btn_create(lv_scr_act(), NULL); + btnYearPlus->user_data = this; + lv_obj_set_size(btnYearPlus, 50, 40); + lv_obj_align(btnYearPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_PLUS); + lv_obj_set_style_local_value_str(btnYearPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); + lv_obj_set_event_cb(btnYearPlus, event_handler); + + btnYearMinus = lv_btn_create(lv_scr_act(), NULL); + btnYearMinus->user_data = this; + lv_obj_set_size(btnYearMinus, 50, 40); + lv_obj_align(btnYearMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_MINUS); + lv_obj_set_style_local_value_str(btnYearMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); + lv_obj_set_event_cb(btnYearMinus, event_handler); + + btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime->user_data = this; + lv_obj_set_size(btnSetTime, 70, 40); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); + lv_obj_set_event_cb(btnSetTime, event_handler); +} + +SettingSetDate::~SettingSetDate() { + lv_obj_clean(lv_scr_act()); +} + +bool SettingSetDate::Refresh() { + return running; +} + + +void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { + + if(object == btnDayPlus && (event == LV_EVENT_PRESSED)) { + dayValue++; + if (dayValue > MaximumDayOfMonth()) + dayValue = 1; + lv_label_set_text_fmt(lblDay, "%d", dayValue); + lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnDayMinus && (event == LV_EVENT_PRESSED)) { + dayValue--; + if (dayValue < 1) + dayValue = MaximumDayOfMonth(); + lv_label_set_text_fmt(lblDay, "%d", dayValue); + lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + } + + if(object == btnMonthPlus && (event == LV_EVENT_PRESSED)) { + monthValue++; + if (monthValue > 12) + monthValue = 1; + UpdateMonthLabel(); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + CheckDay(); + } + + if(object == btnMonthMinus && (event == LV_EVENT_PRESSED)) { + monthValue--; + if (monthValue < 1) + monthValue = 12; + UpdateMonthLabel(); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + CheckDay(); + } + + if(object == btnYearPlus && (event == LV_EVENT_PRESSED)) { + yearValue++; + lv_label_set_text_fmt(lblYear, "%d", yearValue); + lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + CheckDay(); + } + + if(object == btnYearMinus && (event == LV_EVENT_PRESSED)) { + yearValue--; + lv_label_set_text_fmt(lblYear, "%d", yearValue); + lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); + CheckDay(); + } + + if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue); + dateTimeController.SetTime(static_cast(yearValue), + static_cast(monthValue), + static_cast(dayValue), + 0, + dateTimeController.Hours(), + dateTimeController.Minutes(), + dateTimeController.Seconds(), + nrf_rtc_counter_get(portNRF_RTC_REG)); + lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED); + } +} + +int SettingSetDate::MaximumDayOfMonth() const { + switch (monthValue) { + case 2: + if ((((yearValue % 4) == 0) && ((yearValue % 100) != 0)) || ((yearValue % 400) == 0)) + return 29; + return 28; + case 4: + case 6: + case 9: + case 11: + return 30; + default: + return 31; + } +} + +void SettingSetDate::CheckDay() { + int maxDay = MaximumDayOfMonth(); + if (dayValue > maxDay) { + dayValue = maxDay; + lv_label_set_text_fmt(lblDay, "%d", dayValue); + lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + } +} + +void SettingSetDate::UpdateMonthLabel() { + switch (monthValue) { + case 1: + lv_label_set_text_static(lblMonth, "Jan"); + break; + case 2: + lv_label_set_text_static(lblMonth, "Feb"); + break; + case 3: + lv_label_set_text_static(lblMonth, "Mar"); + break; + case 4: + lv_label_set_text_static(lblMonth, "Apr"); + break; + case 5: + lv_label_set_text_static(lblMonth, "May"); + break; + case 6: + lv_label_set_text_static(lblMonth, "Jun"); + break; + case 7: + lv_label_set_text_static(lblMonth, "Jul"); + break; + case 8: + lv_label_set_text_static(lblMonth, "Aug"); + break; + case 9: + lv_label_set_text_static(lblMonth, "Sep"); + break; + case 10: + lv_label_set_text_static(lblMonth, "Oct"); + break; + case 11: + lv_label_set_text_static(lblMonth, "Nov"); + break; + case 12: + lv_label_set_text_static(lblMonth, "Dec"); + break; + default: + lv_label_set_text_static(lblMonth, "---"); + break; + } + lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); +} + diff --git a/src/displayapp/screens/settings/SettingSetDate.h b/src/displayapp/screens/settings/SettingSetDate.h new file mode 100644 index 0000000..0944e98 --- /dev/null +++ b/src/displayapp/screens/settings/SettingSetDate.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include "components/datetime/DateTimeController.h" +#include "displayapp/screens/Screen.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingSetDate : public Screen{ + public: + SettingSetDate(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController); + ~SettingSetDate() override; + + bool Refresh() override; + void HandleButtonPress(lv_obj_t *object, lv_event_t event); + + private: + + Controllers::DateTime& dateTimeController; + + int dayValue; + int monthValue; + int yearValue; + lv_obj_t * lblDay; + lv_obj_t * lblMonth; + lv_obj_t * lblYear; + lv_obj_t * btnDayPlus; + lv_obj_t * btnDayMinus; + lv_obj_t * btnMonthPlus; + lv_obj_t * btnMonthMinus; + lv_obj_t * btnYearPlus; + lv_obj_t * btnYearMinus; + lv_obj_t * btnSetTime; + + int MaximumDayOfMonth() const; + void CheckDay(); + void UpdateMonthLabel(); + }; + } + } +} -- cgit v0.10.2 From 07b3a507b4c685d54d21eb858f84aac23fa8ac1a Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:14:17 +0200 Subject: Include new screens in CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aca8654..8c6f964 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -420,6 +420,8 @@ list(APPEND SOURCE_FILES displayapp/screens/settings/SettingWakeUp.cpp displayapp/screens/settings/SettingDisplay.cpp displayapp/screens/settings/SettingSteps.cpp + displayapp/screens/settings/SettingSetDate.cpp + displayapp/screens/settings/SettingSetTime.cpp ## Watch faces displayapp/icons/bg_clock.c -- cgit v0.10.2 From 6b3be0f5a1c2793c24d00fc1c4473ca411b3f2e4 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:15:50 +0200 Subject: Added new screens to the list of applications diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 684e3a4..c65a1d7 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -30,7 +30,9 @@ namespace Pinetime { SettingTimeFormat, SettingDisplay, SettingWakeUp, - SettingSteps + SettingSteps, + SettingSetDate, + SettingSetTime }; } } -- cgit v0.10.2 From f3f5eb5739e1294e2953394a8744efd64ee58a28 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:19:38 +0200 Subject: Added new screens to DisplayApp.cpp diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 04ebd2d..5b78899 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -42,6 +42,8 @@ #include "displayapp/screens/settings/SettingWakeUp.h" #include "displayapp/screens/settings/SettingDisplay.h" #include "displayapp/screens/settings/SettingSteps.h" +#include "displayapp/screens/settings/SettingSetDate.h" +#include "displayapp/screens/settings/SettingSetTime.h" using namespace Pinetime::Applications; using namespace Pinetime::Applications::Display; @@ -323,6 +325,14 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, settingsController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; + case Apps::SettingSetDate: + currentScreen = std::make_unique(this, dateTimeController); + ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; + case Apps::SettingSetTime: + currentScreen = std::make_unique(this, dateTimeController); + ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; case Apps::BatteryInfo: currentScreen = std::make_unique(this, batteryController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); -- cgit v0.10.2 From 5ae4192d8d729c36b1a6713165913c7c40a23703 Mon Sep 17 00:00:00 2001 From: timaios Date: Fri, 9 Jul 2021 14:22:45 +0200 Subject: Added new menu entries to Settings page diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index e63a358..be8fb4b 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -18,6 +18,9 @@ Settings::Settings(Pinetime::Applications::DisplayApp* app, Pinetime::Controller }, [this]() -> std::unique_ptr { return CreateScreen2(); + }, + [this]() -> std::unique_ptr { + return CreateScreen3(); }}, Screens::ScreenListModes::UpDown} { } @@ -46,7 +49,7 @@ std::unique_ptr Settings::CreateScreen1() { {Symbols::clock, "Watch face", Apps::SettingWatchFace}, }}; - return std::make_unique(0, 2, app, settingsController, applications); + return std::make_unique(0, 3, app, settingsController, applications); } std::unique_ptr Settings::CreateScreen2() { @@ -58,5 +61,15 @@ std::unique_ptr Settings::CreateScreen2() { {Symbols::list, "About", Apps::SysInfo}, }}; - return std::make_unique(1, 2, app, settingsController, applications); + return std::make_unique(1, 3, app, settingsController, applications); +} + +std::unique_ptr Settings::CreateScreen3() { + + std::array applications {{ + {Symbols::clock, "Set date", Apps::SettingSetDate}, + {Symbols::clock, "Set time", Apps::SettingSetTime}, + }}; + + return std::make_unique(2, 3, app, settingsController, applications); } diff --git a/src/displayapp/screens/settings/Settings.h b/src/displayapp/screens/settings/Settings.h index 711a6be..12dd051 100644 --- a/src/displayapp/screens/settings/Settings.h +++ b/src/displayapp/screens/settings/Settings.h @@ -21,10 +21,11 @@ namespace Pinetime { private: Controllers::Settings& settingsController; - ScreenList<2> screens; + ScreenList<3> screens; std::unique_ptr CreateScreen1(); std::unique_ptr CreateScreen2(); + std::unique_ptr CreateScreen3(); }; } } -- cgit v0.10.2 From f78c9bfcab798b08491b15fe02d65211b824cfc8 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 16:57:59 +0200 Subject: Code optimizations in SettingSetDate diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index 5c1aec5..7fe0022 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -26,19 +26,6 @@ SettingSetDate::SettingSetDate( Screen(app), dateTimeController {dateTimeController} { - - lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr); - - //lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); - lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); - lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); - lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - lv_obj_set_pos(container1, 30, 60); - lv_obj_set_width(container1, LV_HOR_RES - 50); - lv_obj_set_height(container1, LV_VER_RES - 60); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); lv_label_set_text_static(title, "Set current date"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); @@ -116,8 +103,8 @@ SettingSetDate::SettingSetDate( btnSetTime = lv_btn_create(lv_scr_act(), NULL); btnSetTime->user_data = this; - lv_obj_set_size(btnSetTime, 70, 40); - lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_size(btnSetTime, 120, 48); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); lv_obj_set_event_cb(btnSetTime, event_handler); } @@ -133,7 +120,10 @@ bool SettingSetDate::Refresh() { void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if(object == btnDayPlus && (event == LV_EVENT_PRESSED)) { + if (event != LV_EVENT_CLICKED) + return; + + if (object == btnDayPlus) { dayValue++; if (dayValue > MaximumDayOfMonth()) dayValue = 1; @@ -141,8 +131,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnDayMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnDayMinus) { dayValue--; if (dayValue < 1) dayValue = MaximumDayOfMonth(); @@ -150,8 +139,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnMonthPlus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMonthPlus) { monthValue++; if (monthValue > 12) monthValue = 1; @@ -159,8 +147,7 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } - - if(object == btnMonthMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMonthMinus) { monthValue--; if (monthValue < 1) monthValue = 12; @@ -168,24 +155,21 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } - - if(object == btnYearPlus && (event == LV_EVENT_PRESSED)) { + else if (object == btnYearPlus) { yearValue++; lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } - - if(object == btnYearMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnYearMinus) { yearValue--; lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } - - if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + else if (object == btnSetTime) { NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue); dateTimeController.SetTime(static_cast(yearValue), static_cast(monthValue), -- cgit v0.10.2 From 06dfe1425173ffae81294cdce0fd271f1881f7ef Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:13:29 +0200 Subject: Code optimizations in SettingSetTime diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index 22d1c01..e8bc81e 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -19,19 +19,6 @@ SettingSetTime::SettingSetTime( Screen(app), dateTimeController {dateTimeController} { - - lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr); - - //lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); - lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); - lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); - lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - lv_obj_set_pos(container1, 30, 60); - lv_obj_set_width(container1, LV_HOR_RES - 50); - lv_obj_set_height(container1, LV_VER_RES - 60); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); lv_label_set_text_static(title, "Set current time"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); @@ -106,8 +93,8 @@ SettingSetTime::SettingSetTime( btnSetTime = lv_btn_create(lv_scr_act(), NULL); btnSetTime->user_data = this; - lv_obj_set_size(btnSetTime, 70, 40); - lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90); + lv_obj_set_size(btnSetTime, 120, 48); + lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); lv_obj_set_event_cb(btnSetTime, event_handler); } @@ -123,7 +110,10 @@ bool SettingSetTime::Refresh() { void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if(object == btnHoursPlus && (event == LV_EVENT_PRESSED)) { + if (event != LV_EVENT_CLICKED) + return; + + if (object == btnHoursPlus) { hoursValue++; if (hoursValue > 23) hoursValue = 0; @@ -131,8 +121,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnHoursMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnHoursMinus) { hoursValue--; if (hoursValue < 0) hoursValue = 23; @@ -140,8 +129,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnMinutesPlus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMinutesPlus) { minutesValue++; if (minutesValue > 59) minutesValue = 0; @@ -149,8 +137,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnMinutesMinus && (event == LV_EVENT_PRESSED)) { + else if (object == btnMinutesMinus) { minutesValue--; if (minutesValue < 0) minutesValue = 59; @@ -158,8 +145,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } - - if(object == btnSetTime && (event == LV_EVENT_PRESSED)) { + else if (object == btnSetTime) { NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); dateTimeController.SetTime(dateTimeController.Year(), static_cast(dateTimeController.Month()), -- cgit v0.10.2 From 899bee2cf57b658186806dfe0a834efb921b7fc5 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:32:48 +0200 Subject: Exposed Month and DayOfWeek texts in DateTimeController Added static methods to return the text of a given month or dayOfWeek. diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 28a70ab..0682f8f 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -75,31 +75,59 @@ void DateTime::UpdateTime(uint32_t systickCounter) { } const char* DateTime::MonthShortToString() { - return DateTime::MonthsString[(uint8_t) month]; + return DateTime::MonthsString[static_cast(month)]; } const char* DateTime::MonthShortToStringLow() { - return DateTime::MonthsStringLow[(uint8_t) month]; + return DateTime::MonthsStringLow[static_cast(month)]; } const char* DateTime::MonthsToStringLow() { - return DateTime::MonthsLow[(uint8_t) month]; + return DateTime::MonthsLow[static_cast(month)]; } const char* DateTime::DayOfWeekToString() { - return DateTime::DaysString[(uint8_t) dayOfWeek]; + return DateTime::DaysString[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekShortToString() { - return DateTime::DaysStringShort[(uint8_t) dayOfWeek]; + return DateTime::DaysStringShort[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekToStringLow() { - return DateTime::DaysStringLow[(uint8_t) dayOfWeek]; + return DateTime::DaysStringLow[static_cast(dayOfWeek)]; } const char* DateTime::DayOfWeekShortToStringLow() { - return DateTime::DaysStringShortLow[(uint8_t) dayOfWeek]; + return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; +} + +const char* DateTime::MonthShortToString(Months month) { + return DateTime::MonthsString[static_cast(month)]; +} + +const char* DateTime::MonthShortToStringLow(Months month) { + return DateTime::MonthsStringLow[static_cast(month)]; +} + +const char* DateTime::MonthsToStringLow(Months month) { + return DateTime::MonthsLow[static_cast(month)]; +} + +const char* DateTime::DayOfWeekToString(Days dayOfWeek) { + return DateTime::DaysString[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekShortToString(Days dayOfWeek) { + return DateTime::DaysStringShort[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekToStringLow(Days dayOfWeek) { + return DateTime::DaysStringLow[static_cast(dayOfWeek)]; +} + +const char* DateTime::DayOfWeekShortToStringLow(Days dayOfWeek) { + return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; } void DateTime::Register(Pinetime::System::SystemTask* systemTask) { @@ -119,4 +147,4 @@ char const* DateTime::MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", char const* DateTime::MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; char const* DateTime::MonthsLow[] = { - "--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; \ No newline at end of file + "--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h index 265d6e9..66ccaa9 100644 --- a/src/components/datetime/DateTimeController.h +++ b/src/components/datetime/DateTimeController.h @@ -66,6 +66,14 @@ namespace Pinetime { const char* DayOfWeekToStringLow(); const char* DayOfWeekShortToStringLow(); + static const char* MonthShortToString(Months month); + static const char* MonthShortToStringLow(Months month); + static const char* MonthsToStringLow(Months month); + static const char* DayOfWeekToString(Days dayOfWeek); + static const char* DayOfWeekShortToString(Days dayOfWeek); + static const char* DayOfWeekToStringLow(Days dayOfWeek); + static const char* DayOfWeekShortToStringLow(Days dayOfWeek); + std::chrono::time_point CurrentDateTime() const { return currentDateTime; } @@ -100,4 +108,4 @@ namespace Pinetime { static char const* MonthsLow[]; }; } -} \ No newline at end of file +} -- cgit v0.10.2 From 3e5ad49e3a27e0238dc8cd473f8743bf2e8d73b0 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:46:17 +0200 Subject: Code optimizations in SettingSetDate Using static method of DateTimeController for retrieving month texts instead of implementing it in SettingSetDate again. diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index 7fe0022..fe71cd8 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -209,47 +209,8 @@ void SettingSetDate::CheckDay() { } void SettingSetDate::UpdateMonthLabel() { - switch (monthValue) { - case 1: - lv_label_set_text_static(lblMonth, "Jan"); - break; - case 2: - lv_label_set_text_static(lblMonth, "Feb"); - break; - case 3: - lv_label_set_text_static(lblMonth, "Mar"); - break; - case 4: - lv_label_set_text_static(lblMonth, "Apr"); - break; - case 5: - lv_label_set_text_static(lblMonth, "May"); - break; - case 6: - lv_label_set_text_static(lblMonth, "Jun"); - break; - case 7: - lv_label_set_text_static(lblMonth, "Jul"); - break; - case 8: - lv_label_set_text_static(lblMonth, "Aug"); - break; - case 9: - lv_label_set_text_static(lblMonth, "Sep"); - break; - case 10: - lv_label_set_text_static(lblMonth, "Oct"); - break; - case 11: - lv_label_set_text_static(lblMonth, "Nov"); - break; - case 12: - lv_label_set_text_static(lblMonth, "Dec"); - break; - default: - lv_label_set_text_static(lblMonth, "---"); - break; - } + lv_label_set_text_static(lblMonth, + Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); } -- cgit v0.10.2 From 0842a1333966863b0a043b45c629b1f7b1d6c511 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 17:49:35 +0200 Subject: Modified Settings menu as per suggestion Moved "Set date" and "Set time" to the second page of the Settings menu. diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index be8fb4b..f4240ae 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -56,9 +56,9 @@ std::unique_ptr Settings::CreateScreen2() { std::array applications {{ {Symbols::shoe, "Steps", Apps::SettingSteps}, + {Symbols::clock, "Set date", Apps::SettingSetDate}, + {Symbols::clock, "Set time", Apps::SettingSetTime}, {Symbols::batteryHalf, "Battery", Apps::BatteryInfo}, - {Symbols::check, "Firmware", Apps::FirmwareValidation}, - {Symbols::list, "About", Apps::SysInfo}, }}; return std::make_unique(1, 3, app, settingsController, applications); @@ -67,8 +67,8 @@ std::unique_ptr Settings::CreateScreen2() { std::unique_ptr Settings::CreateScreen3() { std::array applications {{ - {Symbols::clock, "Set date", Apps::SettingSetDate}, - {Symbols::clock, "Set time", Apps::SettingSetTime}, + {Symbols::check, "Firmware", Apps::FirmwareValidation}, + {Symbols::list, "About", Apps::SysInfo}, }}; return std::make_unique(2, 3, app, settingsController, applications); -- cgit v0.10.2 From da36d4a5a1322dd7699dbe445bb25962b0819f0a Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 20:17:47 +0200 Subject: Code optimizations in SettingSetTime The positions of the labels are controlled by #define's, just like in SettingSetDate. diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index e8bc81e..122a537 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -5,6 +5,14 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" +#define POS_X_HOURS -72 +#define POS_X_MINUTES 0 +#define POS_X_SECONDS 72 +#define POS_Y_PLUS -50 +#define POS_Y_TEXT -6 +#define POS_Y_MINUS 40 +#define OFS_Y_COLON -2 + using namespace Pinetime::Applications::Screens; namespace { @@ -36,32 +44,32 @@ SettingSetTime::SettingSetTime( lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon1, ":"); lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, -36, -8); + lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_HOURS + POS_X_MINUTES) / 2, POS_Y_TEXT + OFS_Y_COLON); minutesValue = static_cast(dateTimeController.Minutes()); lblMinutes = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon2, ":"); lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, 36, -8); + lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_MINUTES + POS_X_SECONDS) / 2, POS_Y_TEXT + OFS_Y_COLON); lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblSeconds, "00"); lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, 72, -6); + lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT); btnHoursPlus = lv_btn_create(lv_scr_act(), NULL); btnHoursPlus->user_data = this; @@ -118,7 +126,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue > 23) hoursValue = 0; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnHoursMinus) { @@ -126,7 +134,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue < 0) hoursValue = 23; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6); + lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesPlus) { @@ -134,7 +142,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue > 59) minutesValue = 0; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesMinus) { @@ -142,7 +150,7 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue < 0) minutesValue = 59; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6); + lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnSetTime) { -- cgit v0.10.2 From ffa51612fc6884ccfeb4f23453acc451692c18b3 Mon Sep 17 00:00:00 2001 From: Tim Taenny Date: Fri, 9 Jul 2021 20:35:48 +0200 Subject: Code optimizations in SettingSetDate and SettingSetTime Instead of calling lv_obj_align after each button click, the labels have their auto_realign property set. diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index fe71cd8..69766a4 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -40,24 +40,26 @@ SettingSetDate::SettingSetDate( dayValue = static_cast(dateTimeController.Day()); lblDay = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); + lv_obj_set_auto_realign(lblDay, true); monthValue = static_cast(dateTimeController.Month()); lblMonth = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblMonth, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); UpdateMonthLabel(); + lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); + lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); + lv_obj_set_auto_realign(lblMonth, true); yearValue = static_cast(dateTimeController.Year()); if (yearValue < 2021) yearValue = 2021; lblYear = lv_label_create(lv_scr_act(), NULL); - //lv_obj_set_style_local_text_font(lblYear, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); + lv_obj_set_auto_realign(lblYear, true); btnDayPlus = lv_btn_create(lv_scr_act(), NULL); btnDayPlus->user_data = this; @@ -128,7 +130,6 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (dayValue > MaximumDayOfMonth()) dayValue = 1; lv_label_set_text_fmt(lblDay, "%d", dayValue); - lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnDayMinus) { @@ -136,7 +137,6 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (dayValue < 1) dayValue = MaximumDayOfMonth(); lv_label_set_text_fmt(lblDay, "%d", dayValue); - lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMonthPlus) { @@ -158,14 +158,12 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { else if (object == btnYearPlus) { yearValue++; lv_label_set_text_fmt(lblYear, "%d", yearValue); - lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } else if (object == btnYearMinus) { yearValue--; lv_label_set_text_fmt(lblYear, "%d", yearValue); - lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); } @@ -211,7 +209,5 @@ void SettingSetDate::CheckDay() { void SettingSetDate::UpdateMonthLabel() { lv_label_set_text_static(lblMonth, Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); - lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); - lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); } diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index 122a537..eae11f5 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -45,6 +45,7 @@ SettingSetTime::SettingSetTime( lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); + lv_obj_set_auto_realign(lblHours, true); lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); @@ -58,6 +59,7 @@ SettingSetTime::SettingSetTime( lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); + lv_obj_set_auto_realign(lblMinutes, true); lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); @@ -126,7 +128,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue > 23) hoursValue = 0; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnHoursMinus) { @@ -134,7 +135,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (hoursValue < 0) hoursValue = 23; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesPlus) { @@ -142,7 +142,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue > 59) minutesValue = 0; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesMinus) { @@ -150,7 +149,6 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { if (minutesValue < 0) minutesValue = 59; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); - lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnSetTime) { -- cgit v0.10.2 From 5bc40c9287f06d2c2bb24a5691175f1d29a17c1b Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 14 Jul 2021 17:11:16 +0300 Subject: Update touchpad driver diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 6d66afe..7949e70 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -336,7 +336,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) break; case Apps::SysInfo: currentScreen = - std::make_unique(this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController); + std::make_unique(this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController, touchPanel); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::FlashLight: @@ -395,7 +395,7 @@ void DisplayApp::PushMessage(Messages msg) { TouchEvents DisplayApp::OnTouchEvent() { auto info = touchPanel.GetTouchInfo(); - if (info.isTouch) { + if (info.isValid) { switch (info.gesture) { case Pinetime::Drivers::Cst816S::Gestures::SingleTap: if (touchMode == TouchModes::Gestures) { diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index f5bf0cc..d1df579 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -31,7 +31,8 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Controllers::Ble& bleController, Pinetime::Drivers::WatchdogView& watchdog, - Pinetime::Controllers::MotionController& motionController) + Pinetime::Controllers::MotionController& motionController, + Pinetime::Drivers::Cst816S& touchPanel) : Screen(app), dateTimeController {dateTimeController}, batteryController {batteryController}, @@ -39,6 +40,7 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app, bleController {bleController}, watchdog {watchdog}, motionController{motionController}, + touchPanel{touchPanel}, screens {app, 0, {[this]() -> std::unique_ptr { @@ -151,7 +153,8 @@ std::unique_ptr SystemInfo::CreateScreen2() { "#444444 Battery# %d%%/%03imV\n" "#444444 Backlight# %s\n" "#444444 Last reset# %s\n" - "#444444 Accel.# %s\n", + "#444444 Accel.# %s\n" + "#444444 Touch.# %x.%x.%x\n", dateTimeController.Day(), static_cast(dateTimeController.Month()), dateTimeController.Year(), @@ -166,7 +169,10 @@ std::unique_ptr SystemInfo::CreateScreen2() { batteryController.Voltage(), brightnessController.ToString(), resetReason, - ToString(motionController.DeviceType())); + ToString(motionController.DeviceType()), + touchPanel.GetChipId(), + touchPanel.GetVendorId(), + touchPanel.GetFwVersion()); lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); return std::make_unique(1, 5, app, label); } diff --git a/src/displayapp/screens/SystemInfo.h b/src/displayapp/screens/SystemInfo.h index 9d471f6..88984df 100644 --- a/src/displayapp/screens/SystemInfo.h +++ b/src/displayapp/screens/SystemInfo.h @@ -28,7 +28,8 @@ namespace Pinetime { Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Controllers::Ble& bleController, Pinetime::Drivers::WatchdogView& watchdog, - Pinetime::Controllers::MotionController& motionController); + Pinetime::Controllers::MotionController& motionController, + Pinetime::Drivers::Cst816S& touchPanel); ~SystemInfo() override; bool Refresh() override; bool OnButtonPushed() override; @@ -43,6 +44,7 @@ namespace Pinetime { Pinetime::Controllers::Ble& bleController; Pinetime::Drivers::WatchdogView& watchdog; Pinetime::Controllers::MotionController& motionController; + Pinetime::Drivers::Cst816S& touchPanel; ScreenList<5> screens; @@ -56,4 +58,4 @@ namespace Pinetime { }; } } -} \ No newline at end of file +} diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index fd9792b..2a6809b 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -40,38 +40,45 @@ void Cst816S::Init() { */ static constexpr uint8_t motionMask = 0b00000101; twiMaster.Write(twiAddress, 0xEC, &motionMask, 1); + + // There's mixed information about which register contains which information + if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { + chipId = 0xFF; + } + if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { + vendorId = 0xFF; + } + if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) { + fwVersion = 0xFF; + } } Cst816S::TouchInfos Cst816S::GetTouchInfo() { Cst816S::TouchInfos info; auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData)); - if (ret != TwiMaster::ErrorCodes::NoError) - return {}; - - auto nbTouchPoints = touchData[2] & 0x0f; - - uint8_t i = 0; - - uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4; - if (nbTouchPoints == 0 && pointId == lastTouchId) + if (ret != TwiMaster::ErrorCodes::NoError) { + info.isValid = false; return info; + } - info.isTouch = true; + // This can only be 0 or 1 + auto nbTouchPoints = touchData[touchPointNumIndex] & 0x0f; - auto xHigh = touchData[touchXHighIndex + (touchStep * i)] & 0x0f; - auto xLow = touchData[touchXLowIndex + (touchStep * i)]; + auto xHigh = touchData[touchXHighIndex] & 0x0f; + auto xLow = touchData[touchXLowIndex]; uint16_t x = (xHigh << 8) | xLow; - auto yHigh = touchData[touchYHighIndex + (touchStep * i)] & 0x0f; - auto yLow = touchData[touchYLowIndex + (touchStep * i)]; + auto yHigh = touchData[touchYHighIndex] & 0x0f; + auto yLow = touchData[touchYLowIndex]; uint16_t y = (yHigh << 8) | yLow; - auto action = touchData[touchEventIndex + (touchStep * i)] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/ + auto action = touchData[touchEventIndex] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/ info.x = x; info.y = y; info.action = action; + info.touching = (nbTouchPoints > 0); info.gesture = static_cast(touchData[gestureIndex]); return info; @@ -90,4 +97,4 @@ void Cst816S::Sleep() { void Cst816S::Wakeup() { Init(); NRF_LOG_INFO("[TOUCHPANEL] Wakeup"); -} \ No newline at end of file +} diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index 14c296e..394cc40 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -20,11 +20,9 @@ namespace Pinetime { uint16_t x = 0; uint16_t y = 0; uint8_t action = 0; - uint8_t finger = 0; - uint8_t pressure = 0; - uint8_t area = 0; + bool touching = false; Gestures gesture = Gestures::None; - bool isTouch = false; + bool isValid = true; }; Cst816S(TwiMaster& twiMaster, uint8_t twiAddress); @@ -38,26 +36,40 @@ namespace Pinetime { void Sleep(); void Wakeup(); + uint8_t GetChipId() const { + return chipId; + } + uint8_t GetVendorId() const { + return vendorId; + } + uint8_t GetFwVersion() const { + return fwVersion; + } private: static constexpr uint8_t pinIrq = 28; static constexpr uint8_t pinReset = 10; - static constexpr uint8_t lastTouchId = 0x0f; + + // Unused/Unavailable commented out + static constexpr uint8_t gestureIndex = 1; static constexpr uint8_t touchPointNumIndex = 2; - static constexpr uint8_t touchMiscIndex = 8; - static constexpr uint8_t touchXYIndex = 7; static constexpr uint8_t touchEventIndex = 3; static constexpr uint8_t touchXHighIndex = 3; static constexpr uint8_t touchXLowIndex = 4; + //static constexpr uint8_t touchIdIndex = 5; static constexpr uint8_t touchYHighIndex = 5; static constexpr uint8_t touchYLowIndex = 6; - static constexpr uint8_t touchIdIndex = 5; - static constexpr uint8_t touchStep = 6; - static constexpr uint8_t gestureIndex = 1; + //static constexpr uint8_t touchStep = 6; + //static constexpr uint8_t touchXYIndex = 7; + //static constexpr uint8_t touchMiscIndex = 8; - uint8_t touchData[10]; + uint8_t touchData[7]; TwiMaster& twiMaster; uint8_t twiAddress; + + uint8_t chipId; + uint8_t vendorId; + uint8_t fwVersion; }; } -} \ No newline at end of file +} diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index eb29638..6a851e7 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -231,7 +231,7 @@ void SystemTask::Work() { twiMaster.Wakeup(); auto touchInfo = touchPanel.GetTouchInfo(); twiMaster.Sleep(); - if (touchInfo.isTouch and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and + if (touchInfo.isValid and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::DoubleTap) or (touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::SingleTap))) { -- cgit v0.10.2 From 93893511f1e0bb224f5002dd9738738f92e25eb6 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 21 Jul 2021 14:41:29 +0300 Subject: Fit more tasks in SystemInfo diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index f5bf0cc..69a0d1a 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -210,11 +210,14 @@ bool SystemInfo::sortById(const TaskStatus_t& lhs, const TaskStatus_t& rhs) { } std::unique_ptr SystemInfo::CreateScreen4() { - TaskStatus_t tasksStatus[7]; + static constexpr uint8_t maxTaskCount = 9; + TaskStatus_t tasksStatus[maxTaskCount]; + lv_obj_t* infoTask = lv_table_create(lv_scr_act(), NULL); lv_table_set_col_cnt(infoTask, 3); - lv_table_set_row_cnt(infoTask, 8); - lv_obj_set_pos(infoTask, 10, 10); + lv_table_set_row_cnt(infoTask, maxTaskCount + 1); + lv_obj_set_style_local_pad_all(infoTask, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 0); + lv_obj_set_style_local_border_color(infoTask, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, LV_COLOR_GRAY); lv_table_set_cell_value(infoTask, 0, 0, "#"); lv_table_set_col_width(infoTask, 0, 50); @@ -223,8 +226,9 @@ std::unique_ptr SystemInfo::CreateScreen4() { lv_table_set_cell_value(infoTask, 0, 2, "Free"); lv_table_set_col_width(infoTask, 2, 90); - auto nb = uxTaskGetSystemState(tasksStatus, 7, nullptr); + auto nb = uxTaskGetSystemState(tasksStatus, maxTaskCount, nullptr); std::sort(tasksStatus, tasksStatus + nb, sortById); + for (uint8_t i = 0; i < nb; i++) { lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str()); -- cgit v0.10.2 From 12b14176ec965f2553e4cad16e291d54704128f3 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 21 Jul 2021 14:46:27 +0300 Subject: Fix diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 69a0d1a..3294ebe 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -228,8 +228,7 @@ std::unique_ptr SystemInfo::CreateScreen4() { auto nb = uxTaskGetSystemState(tasksStatus, maxTaskCount, nullptr); std::sort(tasksStatus, tasksStatus + nb, sortById); - - for (uint8_t i = 0; i < nb; i++) { + for (uint8_t i = 0; i < nb && i < maxTaskCount; i++) { lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str()); lv_table_set_cell_value(infoTask, i + 1, 1, tasksStatus[i].pcTaskName); -- cgit v0.10.2 From 54ccd2cc072d32563d01080ed21c5fd1bd7a695c Mon Sep 17 00:00:00 2001 From: Jonathan Vander Mey Date: Sat, 24 Jul 2021 11:07:06 -0400 Subject: Update Navigation UUID documentation Fixed mismatch between the service and characteristic IDs in the navigation service comments and documentation. They had old values not reflecting the current code and changes in doc/ble.md diff --git a/doc/NavigationService.md b/doc/NavigationService.md index d089981..fd81d0b 100644 --- a/doc/NavigationService.md +++ b/doc/NavigationService.md @@ -9,19 +9,19 @@ manDist (string) - Manouvre Distance, the distance to the upcoming change progress (uint8) - Percent complete of total route, value 0-100 ## Service -The service UUID is c7e60001-78fc-48fe-8e23-433b3a1942d0 +The service UUID is 00010000-78fc-48fe-8e23-433b3a1942d0 ## Characteristics -## Flags (UUID c7e60002-78fc-48fe-8e23-433b3a1942d0) +## Flags (UUID 00010001-78fc-48fe-8e23-433b3a1942d0) All included icons are from pure-maps, which provides the actual routing from the client. The icon names ultimately come from the mapbox project "direction-icons", See https://github.com/rinigus/pure-maps/tree/master/qml/icons/navigation See the end of this document for the full lsit of supported icon names. -## Narrative (UUID c7e60003-78fc-48fe-8e23-433b3a1942d0) +## Narrative (UUID 00010002-78fc-48fe-8e23-433b3a1942d0) This is a client supplied string describing the upcoming instruction such as "At the roundabout take the first exit". -## Man Dist (UUID c7e60004-78fc-48fe-8e23-433b3a1942d0) +## Man Dist (UUID 00010003-78fc-48fe-8e23-433b3a1942d0) This is a short string describing the distance to the upcoming instruction such as "50 m". -## Progress (UUID c7e60001=5-78fc-48fe-8e23-433b3a1942d0) +## Progress (UUID 00010004-78fc-48fe-8e23-433b3a1942d0) The percent complete in a uint8. The watch displays this as an overall progress in a progress bar. ## Full icon list diff --git a/src/components/ble/NavigationService.h b/src/components/ble/NavigationService.h index 5aab263..7972308 100644 --- a/src/components/ble/NavigationService.h +++ b/src/components/ble/NavigationService.h @@ -26,7 +26,7 @@ #undef max #undef min -// c7e60000-78fc-48fe-8e23-433b3a1942d0 +// 00010000-78fc-48fe-8e23-433b3a1942d0 #define NAVIGATION_SERVICE_UUID_BASE \ { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x00, 0x00 } -- cgit v0.10.2 From 6b95fd841f9a4fee3f2c07b620db182c46228177 Mon Sep 17 00:00:00 2001 From: Jonathan Vander Mey Date: Sat, 24 Jul 2021 11:09:56 -0400 Subject: Set navigation service id is base UUID macro Avoids the need to copy the same ID into every characteristic UUID genereated from it. diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index e1c20bf..b9d51d3 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -26,28 +26,17 @@ int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_acce } Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) { - navUuid.value[14] = navId[0]; - navUuid.value[15] = navId[1]; - navFlagCharUuid.value[12] = navFlagCharId[0]; navFlagCharUuid.value[13] = navFlagCharId[1]; - navFlagCharUuid.value[14] = navId[0]; - navFlagCharUuid.value[15] = navId[1]; navNarrativeCharUuid.value[12] = navNarrativeCharId[0]; navNarrativeCharUuid.value[13] = navNarrativeCharId[1]; - navNarrativeCharUuid.value[14] = navId[0]; - navNarrativeCharUuid.value[15] = navId[1]; navManDistCharUuid.value[12] = navManDistCharId[0]; navManDistCharUuid.value[13] = navManDistCharId[1]; - navManDistCharUuid.value[14] = navId[0]; - navManDistCharUuid.value[15] = navId[1]; navProgressCharUuid.value[12] = navProgressCharId[0]; navProgressCharUuid.value[13] = navProgressCharId[1]; - navProgressCharUuid.value[14] = navId[0]; - navProgressCharUuid.value[15] = navId[1]; characteristicDefinition[0] = { .uuid = (ble_uuid_t*) (&navFlagCharUuid), .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; diff --git a/src/components/ble/NavigationService.h b/src/components/ble/NavigationService.h index 7972308..caa194d 100644 --- a/src/components/ble/NavigationService.h +++ b/src/components/ble/NavigationService.h @@ -28,7 +28,7 @@ // 00010000-78fc-48fe-8e23-433b3a1942d0 #define NAVIGATION_SERVICE_UUID_BASE \ - { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x00, 0x00 } + { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x01, 0x00 } namespace Pinetime { namespace System { @@ -53,7 +53,6 @@ namespace Pinetime { int getProgress(); private: - static constexpr uint8_t navId[2] = {0x01, 0x00}; static constexpr uint8_t navFlagCharId[2] = {0x01, 0x00}; static constexpr uint8_t navNarrativeCharId[2] = {0x02, 0x00}; static constexpr uint8_t navManDistCharId[2] = {0x03, 0x00}; -- cgit v0.10.2 From 1bdaf581a3e58c33ceb8fd766cc5f25c978f9cb5 Mon Sep 17 00:00:00 2001 From: Jonathan Vander Mey Date: Sat, 24 Jul 2021 11:18:17 -0400 Subject: Update nav service UUID macro to constexpr functions diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index b9d51d3..0ab1fa9 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -20,24 +20,32 @@ #include "systemtask/SystemTask.h" +namespace { + // 0001yyxx-78fc-48fe-8e23-433b3a1942d0 + constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) { + return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128}, + .value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x01, 0x00}}; + } + + // 00010000-78fc-48fe-8e23-433b3a1942d0 + constexpr ble_uuid128_t BaseUuid() { + return CharUuid(0x00, 0x00); + } + + constexpr ble_uuid128_t navUuid {BaseUuid()}; + + constexpr ble_uuid128_t navFlagCharUuid {CharUuid(0x01, 0x00)}; + constexpr ble_uuid128_t navNarrativeCharUuid {CharUuid(0x02, 0x00)}; + constexpr ble_uuid128_t navManDistCharUuid {CharUuid(0x03, 0x00)}; + constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)}; +} // namespace + int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { auto navService = static_cast(arg); return navService->OnCommand(conn_handle, attr_handle, ctxt); } Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) { - navFlagCharUuid.value[12] = navFlagCharId[0]; - navFlagCharUuid.value[13] = navFlagCharId[1]; - - navNarrativeCharUuid.value[12] = navNarrativeCharId[0]; - navNarrativeCharUuid.value[13] = navNarrativeCharId[1]; - - navManDistCharUuid.value[12] = navManDistCharId[0]; - navManDistCharUuid.value[13] = navManDistCharId[1]; - - navProgressCharUuid.value[12] = navProgressCharId[0]; - navProgressCharUuid.value[13] = navProgressCharId[1]; - characteristicDefinition[0] = { .uuid = (ble_uuid_t*) (&navFlagCharUuid), .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; diff --git a/src/components/ble/NavigationService.h b/src/components/ble/NavigationService.h index caa194d..c0c77f3 100644 --- a/src/components/ble/NavigationService.h +++ b/src/components/ble/NavigationService.h @@ -26,10 +26,6 @@ #undef max #undef min -// 00010000-78fc-48fe-8e23-433b3a1942d0 -#define NAVIGATION_SERVICE_UUID_BASE \ - { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x01, 0x00 } - namespace Pinetime { namespace System { class SystemTask; @@ -53,18 +49,6 @@ namespace Pinetime { int getProgress(); private: - static constexpr uint8_t navFlagCharId[2] = {0x01, 0x00}; - static constexpr uint8_t navNarrativeCharId[2] = {0x02, 0x00}; - static constexpr uint8_t navManDistCharId[2] = {0x03, 0x00}; - static constexpr uint8_t navProgressCharId[2] = {0x04, 0x00}; - - ble_uuid128_t navUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE}; - - ble_uuid128_t navFlagCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE}; - ble_uuid128_t navNarrativeCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE}; - ble_uuid128_t navManDistCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE}; - ble_uuid128_t navProgressCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE}; - struct ble_gatt_chr_def characteristicDefinition[5]; struct ble_gatt_svc_def serviceDefinition[2]; -- cgit v0.10.2 From 487ae478adf4f4c8be0ff61f8433e7018426b661 Mon Sep 17 00:00:00 2001 From: Jonathan Vander Mey Date: Sat, 24 Jul 2021 11:40:06 -0400 Subject: Remove unnecessary C-style casts with BLE UUIDs Instead of casting the UUID object to the ble_uuid_t* used throughout the NimBLE API just pass the address of the ble_uuid_t member that's at the start of each of the UUID structs. diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp index c3d1d69..5e5c25c 100644 --- a/src/components/ble/AlertNotificationClient.cpp +++ b/src/components/ble/AlertNotificationClient.cpp @@ -55,7 +55,7 @@ bool AlertNotificationClient::OnDiscoveryEvent(uint16_t connectionHandle, const return true; } - if (service != nullptr && ble_uuid_cmp(((ble_uuid_t*) &ansServiceUuid), &service->uuid.u) == 0) { + if (service != nullptr && ble_uuid_cmp(&ansServiceUuid.u, &service->uuid.u) == 0) { NRF_LOG_INFO("ANS discovered : 0x%x - 0x%x", service->start_handle, service->end_handle); ansStartHandle = service->start_handle; ansEndHandle = service->end_handle; @@ -80,21 +80,21 @@ int AlertNotificationClient::OnCharacteristicsDiscoveryEvent(uint16_t connection } else onServiceDiscovered(connectionHandle); } else { - if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &supportedNewAlertCategoryUuid), &characteristic->uuid.u) == 0) { + if (characteristic != nullptr && ble_uuid_cmp(&supportedNewAlertCategoryUuid.u, &characteristic->uuid.u) == 0) { NRF_LOG_INFO("ANS Characteristic discovered : supportedNewAlertCategoryUuid"); supportedNewAlertCategoryHandle = characteristic->val_handle; - } else if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &supportedUnreadAlertCategoryUuid), &characteristic->uuid.u) == 0) { + } else if (characteristic != nullptr && ble_uuid_cmp(&supportedUnreadAlertCategoryUuid.u, &characteristic->uuid.u) == 0) { NRF_LOG_INFO("ANS Characteristic discovered : supportedUnreadAlertCategoryUuid"); supportedUnreadAlertCategoryHandle = characteristic->val_handle; - } else if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &newAlertUuid), &characteristic->uuid.u) == 0) { + } else if (characteristic != nullptr && ble_uuid_cmp(&newAlertUuid.u, &characteristic->uuid.u) == 0) { NRF_LOG_INFO("ANS Characteristic discovered : newAlertUuid"); newAlertHandle = characteristic->val_handle; newAlertDefHandle = characteristic->def_handle; isCharacteristicDiscovered = true; - } else if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &unreadAlertStatusUuid), &characteristic->uuid.u) == 0) { + } else if (characteristic != nullptr && ble_uuid_cmp(&unreadAlertStatusUuid.u, &characteristic->uuid.u) == 0) { NRF_LOG_INFO("ANS Characteristic discovered : unreadAlertStatusUuid"); unreadAlertStatusHandle = characteristic->val_handle; - } else if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &controlPointUuid), &characteristic->uuid.u) == 0) { + } else if (characteristic != nullptr && ble_uuid_cmp(&controlPointUuid.u, &characteristic->uuid.u) == 0) { NRF_LOG_INFO("ANS Characteristic discovered : controlPointUuid"); controlPointHandle = characteristic->val_handle; } else @@ -119,7 +119,7 @@ int AlertNotificationClient::OnDescriptorDiscoveryEventCallback(uint16_t connect uint16_t characteristicValueHandle, const ble_gatt_dsc* descriptor) { if (error->status == 0) { - if (characteristicValueHandle == newAlertHandle && ble_uuid_cmp(((ble_uuid_t*) &newAlertUuid), &descriptor->uuid.u)) { + if (characteristicValueHandle == newAlertHandle && ble_uuid_cmp(&newAlertUuid.u, &descriptor->uuid.u)) { if (newAlertDescriptorHandle == 0) { NRF_LOG_INFO("ANS Descriptor discovered : %d", descriptor->handle); newAlertDescriptorHandle = descriptor->handle; diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index d5fc7f6..56fc595 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -26,11 +26,8 @@ void AlertNotificationService::Init() { } AlertNotificationService::AlertNotificationService(System::SystemTask& systemTask, NotificationManager& notificationManager) - : characteristicDefinition {{.uuid = (ble_uuid_t*) &ansCharUuid, - .access_cb = AlertNotificationCallback, - .arg = this, - .flags = BLE_GATT_CHR_F_WRITE}, - {.uuid = (ble_uuid_t*) ¬ificationEventUuid, + : characteristicDefinition {{.uuid = &ansCharUuid.u, .access_cb = AlertNotificationCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE}, + {.uuid = ¬ificationEventUuid.u, .access_cb = AlertNotificationCallback, .arg = this, .flags = BLE_GATT_CHR_F_NOTIFY, @@ -39,7 +36,7 @@ AlertNotificationService::AlertNotificationService(System::SystemTask& systemTas serviceDefinition { {/* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t*) &ansUuid, + .uuid = &ansUuid.u, .characteristics = characteristicDefinition}, {0}, }, @@ -123,4 +120,4 @@ void AlertNotificationService::MuteIncomingCall() { } ble_gattc_notify_custom(connectionHandle, eventHandle, om); -} \ No newline at end of file +} diff --git a/src/components/ble/BatteryInformationService.cpp b/src/components/ble/BatteryInformationService.cpp index 7f17690..39f1895 100644 --- a/src/components/ble/BatteryInformationService.cpp +++ b/src/components/ble/BatteryInformationService.cpp @@ -14,7 +14,7 @@ int BatteryInformationServiceCallback(uint16_t conn_handle, uint16_t attr_handle BatteryInformationService::BatteryInformationService(Controllers::Battery& batteryController) : batteryController {batteryController}, - characteristicDefinition {{.uuid = (ble_uuid_t*) &batteryLevelUuid, + characteristicDefinition {{.uuid = &batteryLevelUuid.u, .access_cb = BatteryInformationServiceCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, @@ -23,7 +23,7 @@ BatteryInformationService::BatteryInformationService(Controllers::Battery& batte serviceDefinition { {/* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t*) &batteryInformationServiceUuid, + .uuid = &batteryInformationServiceUuid.u, .characteristics = characteristicDefinition}, {0}, } { diff --git a/src/components/ble/CurrentTimeClient.cpp b/src/components/ble/CurrentTimeClient.cpp index c6e6831..90d1f0c 100644 --- a/src/components/ble/CurrentTimeClient.cpp +++ b/src/components/ble/CurrentTimeClient.cpp @@ -47,7 +47,7 @@ bool CurrentTimeClient::OnDiscoveryEvent(uint16_t connectionHandle, const ble_ga return true; } - if (service != nullptr && ble_uuid_cmp(((ble_uuid_t*) &ctsServiceUuid), &service->uuid.u) == 0) { + if (service != nullptr && ble_uuid_cmp(&ctsServiceUuid.u, &service->uuid.u) == 0) { NRF_LOG_INFO("CTS discovered : 0x%x - 0x%x", service->start_handle, service->end_handle); isDiscovered = true; ctsStartHandle = service->start_handle; @@ -72,7 +72,7 @@ int CurrentTimeClient::OnCharacteristicDiscoveryEvent(uint16_t conn_handle, return 0; } - if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) ¤tTimeCharacteristicUuid), &characteristic->uuid.u) == 0) { + if (characteristic != nullptr && ble_uuid_cmp(¤tTimeCharacteristicUuid.u, &characteristic->uuid.u) == 0) { NRF_LOG_INFO("CTS Characteristic discovered : 0x%x", characteristic->val_handle); isCharacteristicDiscovered = true; currentTimeHandle = characteristic->val_handle; diff --git a/src/components/ble/CurrentTimeService.cpp b/src/components/ble/CurrentTimeService.cpp index b49be39..eefb7ec 100644 --- a/src/components/ble/CurrentTimeService.cpp +++ b/src/components/ble/CurrentTimeService.cpp @@ -53,7 +53,7 @@ int CurrentTimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handl } CurrentTimeService::CurrentTimeService(DateTime& dateTimeController) - : characteristicDefinition {{.uuid = (ble_uuid_t*) &ctChrUuid, + : characteristicDefinition {{.uuid = &ctChrUuid.u, .access_cb = CTSCallback, .arg = this, @@ -62,7 +62,7 @@ CurrentTimeService::CurrentTimeService(DateTime& dateTimeController) serviceDefinition { {/* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t*) &ctsUuid, + .uuid = &ctsUuid.u, .characteristics = characteristicDefinition}, {0}, }, diff --git a/src/components/ble/DeviceInformationService.cpp b/src/components/ble/DeviceInformationService.cpp index cf48207..778d6e3 100644 --- a/src/components/ble/DeviceInformationService.cpp +++ b/src/components/ble/DeviceInformationService.cpp @@ -56,37 +56,37 @@ int DeviceInformationService::OnDeviceInfoRequested(uint16_t conn_handle, uint16 DeviceInformationService::DeviceInformationService() : characteristicDefinition {{ - .uuid = (ble_uuid_t*) &manufacturerNameUuid, + .uuid = &manufacturerNameUuid.u, .access_cb = DeviceInformationCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ, }, { - .uuid = (ble_uuid_t*) &modelNumberUuid, + .uuid = &modelNumberUuid.u, .access_cb = DeviceInformationCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ, }, { - .uuid = (ble_uuid_t*) &serialNumberUuid, + .uuid = &serialNumberUuid.u, .access_cb = DeviceInformationCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ, }, { - .uuid = (ble_uuid_t*) &fwRevisionUuid, + .uuid = &fwRevisionUuid.u, .access_cb = DeviceInformationCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ, }, { - .uuid = (ble_uuid_t*) &hwRevisionUuid, + .uuid = &hwRevisionUuid.u, .access_cb = DeviceInformationCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ, }, { - .uuid = (ble_uuid_t*) &swRevisionUuid, + .uuid = &swRevisionUuid.u, .access_cb = DeviceInformationCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ, @@ -95,7 +95,7 @@ DeviceInformationService::DeviceInformationService() serviceDefinition { {/* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t*) &deviceInfoUuid, + .uuid = &deviceInfoUuid.u, .characteristics = characteristicDefinition}, {0}, } { diff --git a/src/components/ble/DfuService.cpp b/src/components/ble/DfuService.cpp index 4179994..3d6416f 100644 --- a/src/components/ble/DfuService.cpp +++ b/src/components/ble/DfuService.cpp @@ -33,21 +33,21 @@ DfuService::DfuService(Pinetime::System::SystemTask& systemTask, bleController {bleController}, dfuImage {spiNorFlash}, characteristicDefinition {{ - .uuid = (ble_uuid_t*) &packetCharacteristicUuid, + .uuid = &packetCharacteristicUuid.u, .access_cb = DfuServiceCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE_NO_RSP, .val_handle = nullptr, }, { - .uuid = (ble_uuid_t*) &controlPointCharacteristicUuid, + .uuid = &controlPointCharacteristicUuid.u, .access_cb = DfuServiceCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_NOTIFY, .val_handle = nullptr, }, { - .uuid = (ble_uuid_t*) &revisionCharacteristicUuid, + .uuid = &revisionCharacteristicUuid.u, .access_cb = DfuServiceCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ, @@ -60,7 +60,7 @@ DfuService::DfuService(Pinetime::System::SystemTask& systemTask, serviceDefinition { {/* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t*) &serviceUuid, + .uuid = &serviceUuid.u, .characteristics = characteristicDefinition}, {0}, } { @@ -81,9 +81,9 @@ int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandl xTimerStart(timeoutTimer, 0); } - ble_gatts_find_chr((ble_uuid_t*) &serviceUuid, (ble_uuid_t*) &packetCharacteristicUuid, nullptr, &packetCharacteristicHandle); - ble_gatts_find_chr((ble_uuid_t*) &serviceUuid, (ble_uuid_t*) &controlPointCharacteristicUuid, nullptr, &controlPointCharacteristicHandle); - ble_gatts_find_chr((ble_uuid_t*) &serviceUuid, (ble_uuid_t*) &revisionCharacteristicUuid, nullptr, &revisionCharacteristicHandle); + ble_gatts_find_chr(&serviceUuid.u, &packetCharacteristicUuid.u, nullptr, &packetCharacteristicHandle); + ble_gatts_find_chr(&serviceUuid.u, &controlPointCharacteristicUuid.u, nullptr, &controlPointCharacteristicHandle); + ble_gatts_find_chr(&serviceUuid.u, &revisionCharacteristicUuid.u, nullptr, &revisionCharacteristicHandle); if (attributeHandle == packetCharacteristicHandle) { if (context->op == BLE_GATT_ACCESS_OP_WRITE_CHR) @@ -164,10 +164,10 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) { if ((nbPacketReceived % nbPacketsToNotify) == 0 && bytesReceived != applicationSize) { uint8_t data[5] {static_cast(Opcodes::PacketReceiptNotification), - (uint8_t) (bytesReceived & 0x000000FFu), - (uint8_t) (bytesReceived >> 8u), - (uint8_t) (bytesReceived >> 16u), - (uint8_t) (bytesReceived >> 24u)}; + (uint8_t)(bytesReceived & 0x000000FFu), + (uint8_t)(bytesReceived >> 8u), + (uint8_t)(bytesReceived >> 16u), + (uint8_t)(bytesReceived >> 24u)}; NRF_LOG_INFO("[DFU] -> Send packet notification: %d bytes received", bytesReceived); notificationManager.Send(connectionHandle, controlPointCharacteristicHandle, data, 5); } @@ -422,9 +422,9 @@ uint16_t DfuService::DfuImage::ComputeCrc(uint8_t const* p_data, uint32_t size, uint16_t crc = (p_crc == NULL) ? 0xFFFF : *p_crc; for (uint32_t i = 0; i < size; i++) { - crc = (uint8_t) (crc >> 8) | (crc << 8); + crc = (uint8_t)(crc >> 8) | (crc << 8); crc ^= p_data[i]; - crc ^= (uint8_t) (crc & 0xFF) >> 4; + crc ^= (uint8_t)(crc & 0xFF) >> 4; crc ^= (crc << 8) << 4; crc ^= ((crc & 0xFF) << 4) << 1; } diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp index c556566..5b00f49 100644 --- a/src/components/ble/HeartRateService.cpp +++ b/src/components/ble/HeartRateService.cpp @@ -18,7 +18,7 @@ namespace { HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Controllers::HeartRateController& heartRateController) : system {system}, heartRateController {heartRateController}, - characteristicDefinition {{.uuid = (ble_uuid_t*) &heartRateMeasurementUuid, + characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u, .access_cb = HeartRateServiceServiceCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, @@ -27,7 +27,7 @@ HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Control serviceDefinition { {/* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t*) &heartRateServiceUuid, + .uuid = &heartRateServiceUuid.u, .characteristics = characteristicDefinition}, {0}, } { diff --git a/src/components/ble/ImmediateAlertService.cpp b/src/components/ble/ImmediateAlertService.cpp index 820d3b6..17ed1a9 100644 --- a/src/components/ble/ImmediateAlertService.cpp +++ b/src/components/ble/ImmediateAlertService.cpp @@ -32,7 +32,7 @@ ImmediateAlertService::ImmediateAlertService(Pinetime::System::SystemTask& syste Pinetime::Controllers::NotificationManager& notificationManager) : systemTask {systemTask}, notificationManager {notificationManager}, - characteristicDefinition {{.uuid = (ble_uuid_t*) &alertLevelUuid, + characteristicDefinition {{.uuid = &alertLevelUuid.u, .access_cb = AlertLevelCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE_NO_RSP, @@ -41,7 +41,7 @@ ImmediateAlertService::ImmediateAlertService(Pinetime::System::SystemTask& syste serviceDefinition { {/* Device Information Service */ .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid = (ble_uuid_t*) &immediateAlertServiceUuid, + .uuid = &immediateAlertServiceUuid.u, .characteristics = characteristicDefinition}, {0}, } { @@ -72,4 +72,4 @@ int ImmediateAlertService::OnAlertLevelChanged(uint16_t connectionHandle, uint16 } return 0; -} \ No newline at end of file +} diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index e1c20bf..d93c85d 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -50,24 +50,18 @@ Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::Sy navProgressCharUuid.value[15] = navId[1]; characteristicDefinition[0] = { - .uuid = (ble_uuid_t*) (&navFlagCharUuid), .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - - characteristicDefinition[1] = {.uuid = (ble_uuid_t*) (&navNarrativeCharUuid), - .access_cb = NAVCallback, - .arg = this, - .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - characteristicDefinition[2] = {.uuid = (ble_uuid_t*) (&navManDistCharUuid), - .access_cb = NAVCallback, - .arg = this, - .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; - characteristicDefinition[3] = {.uuid = (ble_uuid_t*) (&navProgressCharUuid), - .access_cb = NAVCallback, - .arg = this, - .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + .uuid = &navFlagCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + + characteristicDefinition[1] = { + .uuid = &navNarrativeCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + characteristicDefinition[2] = { + .uuid = &navManDistCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; + characteristicDefinition[3] = { + .uuid = &navProgressCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}; characteristicDefinition[4] = {0}; - serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = (ble_uuid_t*) &navUuid, .characteristics = characteristicDefinition}; + serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &navUuid.u, .characteristics = characteristicDefinition}; serviceDefinition[1] = {0}; m_progress = 0; @@ -90,13 +84,13 @@ int Pinetime::Controllers::NavigationService::OnCommand(uint16_t conn_handle, ui data[notifSize] = '\0'; os_mbuf_copydata(ctxt->om, 0, notifSize, data); char* s = (char*) &data[0]; - if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &navFlagCharUuid) == 0) { + if (ble_uuid_cmp(ctxt->chr->uuid, &navFlagCharUuid.u) == 0) { m_flag = s; - } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &navNarrativeCharUuid) == 0) { + } else if (ble_uuid_cmp(ctxt->chr->uuid, &navNarrativeCharUuid.u) == 0) { m_narrative = s; - } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &navManDistCharUuid) == 0) { + } else if (ble_uuid_cmp(ctxt->chr->uuid, &navManDistCharUuid.u) == 0) { m_manDist = s; - } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &navProgressCharUuid) == 0) { + } else if (ble_uuid_cmp(ctxt->chr->uuid, &navProgressCharUuid.u) == 0) { m_progress = data[0]; } } -- cgit v0.10.2 From 7cc73b7832d758e36a0f5b126aeb1e71a259a72d Mon Sep 17 00:00:00 2001 From: Jonathan Vander Mey Date: Sat, 24 Jul 2021 13:02:43 -0400 Subject: Move callback function into anonymous namespace diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp index 0ab1fa9..4bbe8b4 100644 --- a/src/components/ble/NavigationService.cpp +++ b/src/components/ble/NavigationService.cpp @@ -38,12 +38,12 @@ namespace { constexpr ble_uuid128_t navNarrativeCharUuid {CharUuid(0x02, 0x00)}; constexpr ble_uuid128_t navManDistCharUuid {CharUuid(0x03, 0x00)}; constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)}; -} // namespace -int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { - auto navService = static_cast(arg); - return navService->OnCommand(conn_handle, attr_handle, ctxt); -} + int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { + auto navService = static_cast(arg); + return navService->OnCommand(conn_handle, attr_handle, ctxt); + } +} // namespace Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) { characteristicDefinition[0] = { -- cgit v0.10.2 From faed0d49006605e33905f1914f04c90f6138bf6e Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 15 Aug 2021 16:47:41 +0200 Subject: Remove unnecessary pin_set, save 50ms diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index fd9792b..affc432 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -19,8 +19,8 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste void Cst816S::Init() { nrf_gpio_cfg_output(pinReset); - nrf_gpio_pin_set(pinReset); - vTaskDelay(50); + //nrf_gpio_pin_set(pinReset); + //vTaskDelay(5); nrf_gpio_pin_clear(pinReset); vTaskDelay(5); nrf_gpio_pin_set(pinReset); -- cgit v0.10.2 From 099364e619374c4ad9bc0ba9136c31c35a82faf7 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 15 Aug 2021 16:48:41 +0200 Subject: Remove LCD reset and more cmds, save over 200ms diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index 0f1dc02..74038b2 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -171,15 +171,15 @@ void St7789::Sleep() { void St7789::Wakeup() { nrf_gpio_cfg_output(pinDataCommand); // TODO why do we need to reset the controller? - HardwareReset(); - SoftwareReset(); + //HardwareReset(); + //SoftwareReset(); SleepOut(); - ColMod(); - MemoryDataAccessControl(); - ColumnAddressSet(); - RowAddressSet(); - DisplayInversionOn(); - NormalModeOn(); + //ColMod(); + //MemoryDataAccessControl(); + //ColumnAddressSet(); + //RowAddressSet(); + //DisplayInversionOn(); + //NormalModeOn(); VerticalScrollStartAddress(verticalScrollingStartAddress); DisplayOn(); NRF_LOG_INFO("[LCD] Wakeup") -- cgit v0.10.2 From 9c175e2f0cd90b56818953b748c8cad3eec2eb89 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 17 Aug 2021 16:01:18 +0300 Subject: Fix after merge diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 4b73a20..7fe6939 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -54,7 +54,7 @@ namespace { } TouchEvents Convert(Pinetime::Drivers::Cst816S::TouchInfos info) { - if (info.isTouch) { + if (info.isValid) { switch (info.gesture) { case Pinetime::Drivers::Cst816S::Gestures::SingleTap: return TouchEvents::Tap; -- cgit v0.10.2 From 780a811f0559a9abd000f36d3fe49cbbb233b632 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 18 Aug 2021 15:23:30 +0300 Subject: Automatic error detection diff --git a/src/BootErrors.h b/src/BootErrors.h new file mode 100644 index 0000000..d00418c --- /dev/null +++ b/src/BootErrors.h @@ -0,0 +1,10 @@ +#pragma once + +namespace Pinetime { + namespace System { + enum class BootErrors { + None, + TouchController, + }; + } +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 40e1f2a..0d41a24 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -418,6 +418,7 @@ list(APPEND SOURCE_FILES displayapp/screens/BatteryInfo.cpp displayapp/screens/Steps.cpp displayapp/screens/Timer.cpp + displayapp/screens/Error.cpp ## Settings displayapp/screens/settings/QuickSettings.cpp diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 684e3a4..0b10210 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -30,7 +30,8 @@ namespace Pinetime { SettingTimeFormat, SettingDisplay, SettingWakeUp, - SettingSteps + SettingSteps, + Error, }; } } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 7fe6939..41fa7d8 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -28,6 +28,7 @@ #include "displayapp/screens/FlashLight.h" #include "displayapp/screens/BatteryInfo.h" #include "displayapp/screens/Steps.h" +#include "displayapp/screens/Error.h" #include "drivers/Cst816s.h" #include "drivers/St7789.h" @@ -107,11 +108,16 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd, timerController {timerController} { } -void DisplayApp::Start() { +void DisplayApp::Start(System::BootErrors error) { msgQueue = xQueueCreate(queueSize, itemSize); - // Start clock when smartwatch boots - LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None); + bootError = error; + + if (error == System::BootErrors::TouchController) { + LoadApp(Apps::Error, DisplayApp::FullRefreshDirections::None); + } else { + LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None); + } if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); @@ -325,6 +331,11 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) motionController); break; + case Apps::Error: + currentScreen = std::make_unique(this, bootError); + ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None); + break; + case Apps::FirmwareValidation: currentScreen = std::make_unique(this, validator); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 574be63..ba11913 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -15,6 +15,7 @@ #include "displayapp/screens/Screen.h" #include "components/timer/TimerController.h" #include "Messages.h" +#include "BootErrors.h" namespace Pinetime { @@ -56,7 +57,7 @@ namespace Pinetime { Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotionController& motionController, Pinetime::Controllers::TimerController& timerController); - void Start(); + void Start(System::BootErrors error); void PushMessage(Display::Messages msg); void StartApp(Apps app, DisplayApp::FullRefreshDirections direction); @@ -114,6 +115,8 @@ namespace Pinetime { Apps nextApp = Apps::None; DisplayApp::FullRefreshDirections nextDirection; TickType_t lastWakeTime; + + System::BootErrors bootError; }; } } diff --git a/src/displayapp/screens/Error.cpp b/src/displayapp/screens/Error.cpp new file mode 100644 index 0000000..7ad52ad --- /dev/null +++ b/src/displayapp/screens/Error.cpp @@ -0,0 +1,54 @@ +#include "Error.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + void ButtonEventCallback(lv_obj_t* obj, lv_event_t /*event*/) { + auto* errorScreen = static_cast(obj->user_data); + errorScreen->ButtonEventHandler(); + } +} + +Error::Error(Pinetime::Applications::DisplayApp* app, System::BootErrors error) + : Screen(app) { + + lv_obj_t* warningLabel = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(warningLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_text_static(warningLabel, "Warning"); + lv_obj_align(warningLabel, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0); + + lv_obj_t* causeLabel = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(causeLabel, LV_LABEL_LONG_BREAK); + lv_obj_set_width(causeLabel, LV_HOR_RES); + lv_obj_align(causeLabel, warningLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + + if (error == System::BootErrors::TouchController) { + lv_label_set_text_static(causeLabel, "Touch controller error detected."); + } + + lv_obj_t* tipLabel = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(tipLabel, LV_LABEL_LONG_BREAK); + lv_obj_set_width(tipLabel, LV_HOR_RES); + lv_label_set_text_static(tipLabel, "If you encounter problems and your device is under warranty, contact the devices seller."); + lv_obj_align(tipLabel, causeLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + + btnOk = lv_btn_create(lv_scr_act(), nullptr); + btnOk->user_data = this; + lv_obj_set_event_cb(btnOk, ButtonEventCallback); + lv_obj_set_size(btnOk, LV_HOR_RES, 50); + lv_obj_align(btnOk, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_obj_set_style_local_value_str(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Proceed"); + lv_obj_set_style_local_bg_color(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); +} + +void Error::ButtonEventHandler() { + running = false; +} + +Error::~Error() { + lv_obj_clean(lv_scr_act()); +} + +bool Error::Refresh() { + return running; +} diff --git a/src/displayapp/screens/Error.h b/src/displayapp/screens/Error.h new file mode 100644 index 0000000..58016d8 --- /dev/null +++ b/src/displayapp/screens/Error.h @@ -0,0 +1,22 @@ +#pragma once + +#include "Screen.h" +#include "BootErrors.h" +#include + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Error : public Screen { + public: + Error(DisplayApp* app, System::BootErrors error); + ~Error() override; + + bool Refresh() override; + void ButtonEventHandler(); + private: + lv_obj_t* btnOk; + }; + } + } +} diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index 2a6809b..3db712e 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -17,7 +17,7 @@ using namespace Pinetime::Drivers; Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, twiAddress {twiAddress} { } -void Cst816S::Init() { +bool Cst816S::Init() { nrf_gpio_cfg_output(pinReset); nrf_gpio_pin_set(pinReset); vTaskDelay(50); @@ -44,13 +44,18 @@ void Cst816S::Init() { // There's mixed information about which register contains which information if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { chipId = 0xFF; + return false; } if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { vendorId = 0xFF; + return false; } if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) { fwVersion = 0xFF; + return false; } + + return chipId == 0xb4 && vendorId == 0 && fwVersion == 1; } Cst816S::TouchInfos Cst816S::GetTouchInfo() { diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index 394cc40..5b2e4e4 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -31,7 +31,7 @@ namespace Pinetime { Cst816S(Cst816S&&) = delete; Cst816S& operator=(Cst816S&&) = delete; - void Init(); + bool Init(); TouchInfos GetTouchInfo(); void Sleep(); void Wakeup(); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 500bc8b..718e6cc 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -22,6 +22,7 @@ #include "drivers/TwiMaster.h" #include "drivers/Hrs3300.h" #include "main.h" +#include "BootErrors.h" #include @@ -106,6 +107,8 @@ void SystemTask::Process(void* instance) { } void SystemTask::Work() { + BootErrors bootError = BootErrors::None; + watchdog.Setup(7); watchdog.Start(); NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); @@ -124,7 +127,9 @@ void SystemTask::Work() { lcd.Init(); twiMaster.Init(); - touchPanel.Init(); + if (!touchPanel.Init()) { + bootError = BootErrors::TouchController; + } dateTimeController.Register(this); batteryController.Init(); motorController.Init(); @@ -141,7 +146,7 @@ void SystemTask::Work() { settingsController.Init(); displayApp.Register(this); - displayApp.Start(); + displayApp.Start(bootError); displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel); -- cgit v0.10.2 From db50131ed49f2fdb639799ca12839862340f8396 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Mon, 23 Aug 2021 15:02:40 +0200 Subject: Remove commented commands completely diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index affc432..2e70a46 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -19,8 +19,6 @@ Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaste void Cst816S::Init() { nrf_gpio_cfg_output(pinReset); - //nrf_gpio_pin_set(pinReset); - //vTaskDelay(5); nrf_gpio_pin_clear(pinReset); vTaskDelay(5); nrf_gpio_pin_set(pinReset); diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index 74038b2..4d81cf2 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -170,16 +170,7 @@ void St7789::Sleep() { void St7789::Wakeup() { nrf_gpio_cfg_output(pinDataCommand); - // TODO why do we need to reset the controller? - //HardwareReset(); - //SoftwareReset(); SleepOut(); - //ColMod(); - //MemoryDataAccessControl(); - //ColumnAddressSet(); - //RowAddressSet(); - //DisplayInversionOn(); - //NormalModeOn(); VerticalScrollStartAddress(verticalScrollingStartAddress); DisplayOn(); NRF_LOG_INFO("[LCD] Wakeup") -- cgit v0.10.2 From e57ff28231cf0ace25c114b8768174087f288dc7 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 29 Aug 2021 12:40:48 +0300 Subject: Let lvgl control queueTimeout diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index d6100ec..675162a 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -141,19 +141,15 @@ uint32_t count = 0; bool toggle = true; void DisplayApp::Refresh() { TickType_t queueTimeout; - TickType_t delta; switch (state) { case States::Idle: - IdleState(); queueTimeout = portMAX_DELAY; break; case States::Running: - RunningState(); - delta = xTaskGetTickCount() - lastWakeTime; - if (delta > LV_DISP_DEF_REFR_PERIOD) { - delta = LV_DISP_DEF_REFR_PERIOD; + if (!currentScreen->IsRunning()) { + LoadApp(returnToApp, returnDirection); } - queueTimeout = LV_DISP_DEF_REFR_PERIOD - delta; + queueTimeout = lv_task_handler(); break; default: queueTimeout = portMAX_DELAY; @@ -161,9 +157,7 @@ void DisplayApp::Refresh() { } Messages msg; - bool messageReceived = xQueueReceive(msgQueue, &msg, queueTimeout); - lastWakeTime = xTaskGetTickCount(); - if (messageReceived) { + if (xQueueReceive(msgQueue, &msg, queueTimeout)) { switch (msg) { case Messages::DimScreen: // Backup brightness is the brightness to return to after dimming or sleeping @@ -275,13 +269,6 @@ void DisplayApp::Refresh() { } } -void DisplayApp::RunningState() { - if (!currentScreen->IsRunning()) { - LoadApp(returnToApp, returnDirection); - } - lv_task_handler(); -} - void DisplayApp::StartApp(Apps app, DisplayApp::FullRefreshDirections direction) { nextApp = app; nextDirection = direction; @@ -423,9 +410,6 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentApp = app; } -void DisplayApp::IdleState() { -} - void DisplayApp::PushMessage(Messages msg) { if (in_isr()) { BaseType_t xHigherPriorityTaskWoken; diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 96951d1..b9e471b 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -103,8 +103,6 @@ namespace Pinetime { TouchEvents returnTouchEvent = TouchEvents::None; TouchEvents GetGesture(); - void RunningState(); - void IdleState(); static void Process(void* instance); void InitHw(); void Refresh(); -- cgit v0.10.2 From fd52ca8fe6f42226ec32a001f4c61dc100ead94a Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 3 Sep 2021 14:35:38 +0300 Subject: Detect full charge and improve watchface display diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index f8a64ec..619e227 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -19,6 +19,12 @@ void Battery::Update() { isCharging = !nrf_gpio_pin_read(chargingPin); isPowerPresent = !nrf_gpio_pin_read(powerPresentPin); + if (isPowerPresent && !isCharging) { + isFull = true; + } else if (!isPowerPresent) { + isFull = false; + } + if (isReading) { return; } @@ -65,12 +71,12 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { // p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024 voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024; - if (voltage > battery_max) { + if (isFull) { percentRemaining = 100; } else if (voltage < battery_min) { percentRemaining = 0; } else { - percentRemaining = (voltage - battery_min) * 100 / (battery_max - battery_min); + percentRemaining = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), 99); } nrfx_saadc_uninit(); diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 6f09b73..164057c 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -23,13 +23,19 @@ namespace Pinetime { } bool IsCharging() const { - return isCharging; + // isCharging will go up and down when fully charged + // isFull makes sure this returns false while fully charged. + return isCharging && !isFull; } bool IsPowerPresent() const { return isPowerPresent; } + bool IsFull() const { + return isFull; + } + private: static Battery* instance; nrf_saadc_value_t saadc_value; @@ -40,6 +46,7 @@ namespace Pinetime { uint16_t voltage = 0; uint8_t percentRemaining = 0; + bool isFull = false; bool isCharging = false; bool isPowerPresent = false; diff --git a/src/displayapp/screens/BatteryInfo.cpp b/src/displayapp/screens/BatteryInfo.cpp index 91c2651..4dcf29c 100644 --- a/src/displayapp/screens/BatteryInfo.cpp +++ b/src/displayapp/screens/BatteryInfo.cpp @@ -60,10 +60,10 @@ void BatteryInfo::Refresh() { batteryPercent = batteryController.PercentRemaining(); batteryVoltage = batteryController.Voltage(); - if (batteryController.IsCharging() and batteryPercent < 100) { + if (batteryController.IsCharging()) { lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED); lv_label_set_text_static(status, "Charging"); - } else if (batteryPercent == 100) { + } else if (batteryController.IsFull()) { lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE); lv_label_set_text_static(status, "Fully charged"); } else if (batteryPercent < 10) { diff --git a/src/displayapp/screens/PineTimeStyle.cpp b/src/displayapp/screens/PineTimeStyle.cpp index 7a712f4..6766ecb 100644 --- a/src/displayapp/screens/PineTimeStyle.cpp +++ b/src/displayapp/screens/PineTimeStyle.cpp @@ -100,10 +100,7 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); lv_label_set_text(batteryIcon, Symbols::batteryFull); lv_obj_align(batteryIcon, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2); - - batteryPlug = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(batteryPlug, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - lv_obj_align(batteryPlug, sidebar, LV_ALIGN_IN_TOP_MID, 0, 2); + lv_obj_set_auto_realign(batteryIcon, true); bleIcon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(bleIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); @@ -205,18 +202,24 @@ PineTimeStyle::~PineTimeStyle() { lv_obj_clean(lv_scr_act()); } +void PineTimeStyle::SetBatteryIcon() { + auto batteryPercent = batteryPercentRemaining.Get(); + lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); +} + void PineTimeStyle::Refresh() { - batteryPercentRemaining = batteryController.PercentRemaining(); - if (batteryPercentRemaining.IsUpdated()) { - auto batteryPercent = batteryPercentRemaining.Get(); - if (batteryController.IsCharging()) { - auto isCharging = batteryController.IsCharging() || batteryController.IsPowerPresent(); - lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging)); - lv_obj_realign(batteryPlug); - lv_label_set_text(batteryIcon, ""); + isCharging = batteryController.IsCharging(); + if (isCharging.IsUpdated()) { + if (isCharging.Get()) { + lv_label_set_text(batteryIcon, Symbols::plug); } else { - lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); - lv_label_set_text(batteryPlug, ""); + SetBatteryIcon(); + } + } + if (!isCharging.Get()) { + batteryPercentRemaining = batteryController.PercentRemaining(); + if (batteryPercentRemaining.IsUpdated()) { + SetBatteryIcon(); } } diff --git a/src/displayapp/screens/PineTimeStyle.h b/src/displayapp/screens/PineTimeStyle.h index cb74ead..ba47380 100644 --- a/src/displayapp/screens/PineTimeStyle.h +++ b/src/displayapp/screens/PineTimeStyle.h @@ -41,6 +41,7 @@ namespace Pinetime { uint8_t currentDay = 0; DirtyValue batteryPercentRemaining {}; + DirtyValue isCharging {}; DirtyValue bleState {}; DirtyValue> currentDateTime {}; DirtyValue motionSensorOk {}; @@ -58,7 +59,6 @@ namespace Pinetime { lv_obj_t* backgroundLabel; lv_obj_t* batteryIcon; lv_obj_t* bleIcon; - lv_obj_t* batteryPlug; lv_obj_t* calendarOuter; lv_obj_t* calendarInner; lv_obj_t* calendarBar1; @@ -76,6 +76,8 @@ namespace Pinetime { Controllers::Settings& settingsController; Controllers::MotionController& motionController; + void SetBatteryIcon(); + lv_task_t* taskRefresh; }; } diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index 75e35c1..843e557 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -176,11 +176,31 @@ void WatchFaceAnalog::UpdateClock() { } } +void WatchFaceAnalog::SetBatteryIcon() { + auto batteryPercent = batteryPercentRemaining.Get(); + if (batteryPercent == 100) { + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); + } else { + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + } + lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); +} + void WatchFaceAnalog::Refresh() { - batteryPercentRemaining = batteryController.PercentRemaining(); - if (batteryPercentRemaining.IsUpdated()) { - auto batteryPercent = batteryPercentRemaining.Get(); - lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + isCharging = batteryController.IsCharging(); + if (isCharging.IsUpdated()) { + if (isCharging.Get()) { + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_label_set_text(batteryIcon, Symbols::plug); + } else { + SetBatteryIcon(); + } + } + if (!isCharging.Get()) { + batteryPercentRemaining = batteryController.PercentRemaining(); + if (batteryPercentRemaining.IsUpdated()) { + SetBatteryIcon(); + } } notificationState = notificationManager.AreNewNotificationsAvailable(); diff --git a/src/displayapp/screens/WatchFaceAnalog.h b/src/displayapp/screens/WatchFaceAnalog.h index 406f4d5..001414a 100644 --- a/src/displayapp/screens/WatchFaceAnalog.h +++ b/src/displayapp/screens/WatchFaceAnalog.h @@ -49,6 +49,7 @@ namespace Pinetime { uint8_t currentDay = 0; DirtyValue batteryPercentRemaining {0}; + DirtyValue isCharging {}; DirtyValue> currentDateTime; DirtyValue notificationState {false}; @@ -81,6 +82,7 @@ namespace Pinetime { Controllers::Settings& settingsController; void UpdateClock(); + void SetBatteryIcon(); lv_task_t* taskRefresh; }; diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 58ab619..3e755f8 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -102,12 +102,20 @@ WatchFaceDigital::~WatchFaceDigital() { } void WatchFaceDigital::Refresh() { + isCharging = batteryController.IsCharging(); + if (isCharging.IsUpdated()) { + lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging.Get())); + } + batteryPercentRemaining = batteryController.PercentRemaining(); if (batteryPercentRemaining.IsUpdated()) { auto batteryPercent = batteryPercentRemaining.Get(); + if (batteryPercent == 100) { + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); + } else { + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + } lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); - auto isCharging = batteryController.IsCharging() or batteryController.IsPowerPresent(); - lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging)); } bleState = bleController.IsConnected(); diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 48dc137..69a6067 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -44,6 +44,7 @@ namespace Pinetime { uint8_t currentDay = 0; DirtyValue batteryPercentRemaining {}; + DirtyValue isCharging {}; DirtyValue bleState {}; DirtyValue> currentDateTime {}; DirtyValue motionSensorOk {}; -- cgit v0.10.2 From ac2ccaeff6e713b0121b39a6ae5dfce15ea8680c Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 3 Sep 2021 14:57:07 +0300 Subject: Auto realign battery icon in Analog watch face diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index 843e557..53e7faf 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -68,6 +68,7 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, batteryIcon = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text(batteryIcon, Symbols::batteryHalf); lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + lv_obj_set_auto_realign(batteryIcon, true); notificationIcon = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); -- cgit v0.10.2 From b31b2425f8afd5022173852f5a78592b37104c39 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 3 Sep 2021 16:57:00 +0300 Subject: Use percentage instead of IsFull diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 164057c..b66da5e 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -32,10 +32,6 @@ namespace Pinetime { return isPowerPresent; } - bool IsFull() const { - return isFull; - } - private: static Battery* instance; nrf_saadc_value_t saadc_value; diff --git a/src/displayapp/screens/BatteryInfo.cpp b/src/displayapp/screens/BatteryInfo.cpp index 4dcf29c..25fd1ef 100644 --- a/src/displayapp/screens/BatteryInfo.cpp +++ b/src/displayapp/screens/BatteryInfo.cpp @@ -63,7 +63,7 @@ void BatteryInfo::Refresh() { if (batteryController.IsCharging()) { lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED); lv_label_set_text_static(status, "Charging"); - } else if (batteryController.IsFull()) { + } else if (batteryPercent == 100) { lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE); lv_label_set_text_static(status, "Fully charged"); } else if (batteryPercent < 10) { -- cgit v0.10.2 From 8f0771183c3872343100a2e974f37c91237da277 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 15 Sep 2021 12:25:41 +0300 Subject: Fix Error screen and optimize GetTouchInfo diff --git a/src/displayapp/screens/Error.cpp b/src/displayapp/screens/Error.cpp index 7ad52ad..75946ab 100644 --- a/src/displayapp/screens/Error.cpp +++ b/src/displayapp/screens/Error.cpp @@ -48,7 +48,3 @@ void Error::ButtonEventHandler() { Error::~Error() { lv_obj_clean(lv_scr_act()); } - -bool Error::Refresh() { - return running; -} diff --git a/src/displayapp/screens/Error.h b/src/displayapp/screens/Error.h index 58016d8..20dde7e 100644 --- a/src/displayapp/screens/Error.h +++ b/src/displayapp/screens/Error.h @@ -12,7 +12,6 @@ namespace Pinetime { Error(DisplayApp* app, System::BootErrors error); ~Error() override; - bool Refresh() override; void ButtonEventHandler(); private: lv_obj_t* btnOk; diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index 5feb17b..49d6ed0 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -71,6 +71,7 @@ bool Cst816S::Init() { Cst816S::TouchInfos Cst816S::GetTouchInfo() { Cst816S::TouchInfos info; + uint8_t touchData[7]; auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData)); if (ret != TwiMaster::ErrorCodes::NoError) { @@ -79,18 +80,16 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { } // This can only be 0 or 1 - auto nbTouchPoints = touchData[touchPointNumIndex] & 0x0f; + uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f; - auto xHigh = touchData[touchXHighIndex] & 0x0f; - auto xLow = touchData[touchXLowIndex]; - uint16_t x = (xHigh << 8) | xLow; + uint8_t xHigh = touchData[touchXHighIndex] & 0x0f; + uint8_t xLow = touchData[touchXLowIndex]; + info.x = (xHigh << 8) | xLow; - auto yHigh = touchData[touchYHighIndex] & 0x0f; - auto yLow = touchData[touchYLowIndex]; - uint16_t y = (yHigh << 8) | yLow; + uint8_t yHigh = touchData[touchYHighIndex] & 0x0f; + uint8_t yLow = touchData[touchYLowIndex]; + info.y = (yHigh << 8) | yLow; - info.x = x; - info.y = y; info.touching = (nbTouchPoints > 0); info.gesture = static_cast(touchData[gestureIndex]); diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index d15ce06..0fec841 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -58,7 +58,6 @@ namespace Pinetime { //static constexpr uint8_t touchXYIndex = 7; //static constexpr uint8_t touchMiscIndex = 8; - uint8_t touchData[7]; TwiMaster& twiMaster; uint8_t twiAddress; -- cgit v0.10.2 From d7dfe5d4edd89d6cbc1cf02b3681811f17da774a Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 21 Sep 2021 15:36:31 +0300 Subject: Remove unused variable diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index b9e471b..3000285 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -112,7 +112,6 @@ namespace Pinetime { Apps nextApp = Apps::None; DisplayApp::FullRefreshDirections nextDirection; - TickType_t lastWakeTime; }; } } -- cgit v0.10.2 From 980ac173888883b34367395fdf8ee76c0aea6f72 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 22 Sep 2021 13:58:45 +0300 Subject: Show plug icon while plugged in diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index d2ddae7..b43b229 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -74,7 +74,7 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { } else if (voltage < battery_min) { percentRemaining = 0; } else { - percentRemaining = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), 99); + percentRemaining = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), isCharging ? 99 : 100); } nrfx_saadc_uninit(); diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index 3e755f8..2ecab60 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -102,9 +102,9 @@ WatchFaceDigital::~WatchFaceDigital() { } void WatchFaceDigital::Refresh() { - isCharging = batteryController.IsCharging(); - if (isCharging.IsUpdated()) { - lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(isCharging.Get())); + powerPresent = batteryController.IsPowerPresent(); + if (powerPresent.IsUpdated()) { + lv_label_set_text(batteryPlug, BatteryIcon::GetPlugIcon(powerPresent.Get())); } batteryPercentRemaining = batteryController.PercentRemaining(); diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 69a6067..e27545f 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -44,7 +44,7 @@ namespace Pinetime { uint8_t currentDay = 0; DirtyValue batteryPercentRemaining {}; - DirtyValue isCharging {}; + DirtyValue powerPresent {}; DirtyValue bleState {}; DirtyValue> currentDateTime {}; DirtyValue motionSensorOk {}; -- cgit v0.10.2 From 7ba00b01577da988565094937e00f70b78e39ecc Mon Sep 17 00:00:00 2001 From: Daniel Jackson Date: Mon, 27 Sep 2021 02:42:53 +0100 Subject: Fix the size of the filesystem. Correct typo: 0x400000 - 0x0B4000 = 0x34C000. diff --git a/src/components/fs/FS.h b/src/components/fs/FS.h index 1f2eb7e..75ba16c 100644 --- a/src/components/fs/FS.h +++ b/src/components/fs/FS.h @@ -53,7 +53,7 @@ namespace Pinetime { * */ static constexpr size_t startAddress = 0x0B4000; - static constexpr size_t size = 0x3C0000; + static constexpr size_t size = 0x34C000; static constexpr size_t blockSize = 4096; bool resourcesValid = false; -- cgit v0.10.2 From 6aa945a4f5faf5f9e3ad589ebd5bd8bce4ef5dbf Mon Sep 17 00:00:00 2001 From: Sematre Date: Tue, 28 Sep 2021 21:36:24 +0200 Subject: Fix dead link in README diff --git a/README.md b/README.md index 0d5cad9..9b9c328 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ As of now, here is the list of achievements of this project: * **[Experimental]** [WebBLEWatch](https://hubmartin.github.io/WebBLEWatch/) Synchronize time directly from your web browser. [video](https://youtu.be/IakiuhVDdrY) * **[Experimental]** [Infini-iOS](https://github.com/xan-m/Infini-iOS) (on iOS) - OTA (Over-the-air) update via BLE - - [Bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader) based on [MCUBoot](https://juullabs-oss.github.io/mcuboot/) + - [Bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader) based on [MCUBoot](https://www.mcuboot.com) ## Documentation -- cgit v0.10.2 From d86ae69961231aaa177ed146ad829c93943f600c Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Tue, 28 Sep 2021 22:50:09 +0300 Subject: Alarm: Close the popup with information about the time until alarm with the back button Previously, pressing the back button would close the alarm app anyway. Now if you press on it and the popup with information is open, it will first close and the second press will close the application diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp index 959cb0b..371593a 100644 --- a/src/displayapp/screens/Alarm.cpp +++ b/src/displayapp/screens/Alarm.cpp @@ -174,6 +174,17 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { } } +bool Alarm::OnButtonPushed() { + if (txtMessage != nullptr && btnMessage != nullptr) { + lv_obj_del(txtMessage); + lv_obj_del(btnMessage); + txtMessage = nullptr; + btnMessage = nullptr; + return true; + } + return false; +} + void Alarm::UpdateAlarmTime() { lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes); alarmController.SetAlarmTime(alarmHours, alarmMinutes); diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index abf97eb..edd211b 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -31,6 +31,7 @@ namespace Pinetime { ~Alarm() override; void SetAlerting(); void OnButtonEvent(lv_obj_t* obj, lv_event_t event); + bool OnButtonPushed() override; private: bool running; -- cgit v0.10.2 From 05f8850acf163f255d58e6224a3f9382b42e6ed4 Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Wed, 29 Sep 2021 19:15:23 +0300 Subject: Fixes based on code reviews diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp index 371593a..6b45a36 100644 --- a/src/displayapp/screens/Alarm.cpp +++ b/src/displayapp/screens/Alarm.cpp @@ -120,10 +120,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { return; } if (obj == btnMessage) { - lv_obj_del(txtMessage); - lv_obj_del(btnMessage); - txtMessage = nullptr; - btnMessage = nullptr; + HideInfo(); return; } // If any other button was pressed, disable the alarm @@ -176,10 +173,7 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) { bool Alarm::OnButtonPushed() { if (txtMessage != nullptr && btnMessage != nullptr) { - lv_obj_del(txtMessage); - lv_obj_del(btnMessage); - txtMessage = nullptr; - btnMessage = nullptr; + HideInfo(); return true; } return false; @@ -235,6 +229,12 @@ void Alarm::ShowInfo() { } } +void Alarm::HideInfo() { + lv_obj_del(btnMessage); + txtMessage = nullptr; + btnMessage = nullptr; +} + void Alarm::SetRecurButtonState() { using Pinetime::Controllers::AlarmController; switch (alarmController.Recurrence()) { diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index edd211b..32a14d2 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -47,6 +47,7 @@ namespace Pinetime { void SetRecurButtonState(); void SetAlarm(); void ShowInfo(); + void HideInfo(); void ToggleRecurrence(); void UpdateAlarmTime(); }; -- cgit v0.10.2 From de89c86ca9e5a4f9807c81d55448d364275a86c4 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Thu, 30 Sep 2021 08:44:11 +0100 Subject: Add templates for bug reports and feature requests diff --git a/.github/ISSUE_TEMPLATE/bug-report.yaml b/.github/ISSUE_TEMPLATE/bug-report.yaml new file mode 100644 index 0000000..efcba56 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yaml @@ -0,0 +1,59 @@ +name: Bug Report +description: File a bug report +title: "[Bug]: " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + **Thanks for taking the time to fill out this bug report!** + *Please, before opening a bug report, check if similar issues already exist. In that case, use those issues to provide your feedback instead.* + - type: checkboxes + attributes: + options: + - label: I searched for similar bug reports and found none was relevant. + required: true + - type: input + id: desc-brief + attributes: + label: What happened? + description: A one-line description of the bug. + placeholder: "Ex. I woke up as a Kafkian insect this morning." + validations: + required: true + - type: input + id: desc-expected + attributes: + label: What should happen instead? + description: The behaviour you were expecting to see. + placeholder: "Ex. I was expecting to wake up as a human." + - type: textarea + id: desc-steps + attributes: + label: Reproduction steps + description: "How do you trigger this bug? Please walk us through it step by step." + validations: + required: true + - type: textarea + id: desc-long + attributes: + label: More details? + description: Give us more details about the bug and any personal attempts you made to fix it. + placeholder: Tell us more! + - type: input + id: version + attributes: + label: Version + description: | + What [version of the firmware](https://github.com/JF002/InfiniTime/blob/develop/doc/gettingStarted/gettingStarted-1.0.md#how-to-check-the-version-of-infinitime-and-the-bootloader) are you running? + If you are running an older version, please consider [updating to the latest firmware](https://github.com/JF002/InfiniTime/blob/develop/doc/gettingStarted/gettingStarted-1.0.md#how-to-update-your-pinetime). + If you are running directly from git, specify the branch or the commit hash directly. + placeholder: "Ex. v1.6.0 or develop or fc922b60" + validations: + required: true + - type: input + id: companion-app + attributes: + label: Companion app + description: Which companion app are you using (if relevant)? + placeholder: "Ex. Gadgetbridge v0.60.0, Siglo v0.9.4" diff --git a/.github/ISSUE_TEMPLATE/feature-request.yaml b/.github/ISSUE_TEMPLATE/feature-request.yaml new file mode 100644 index 0000000..33b059c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yaml @@ -0,0 +1,41 @@ +name: Feature Request +description: File a feature request +title: "[Feature Request]: " +labels: ["feature-request"] +body: + - type: markdown + attributes: + value: | + **Thanks for taking the time to fill out this feature request!** + *Please, before opening a feature request, check if similar issues already exist. In that case, use those issues to provide your feedback instead.* + - type: checkboxes + attributes: + options: + - label: I searched for similar feature request and found none was relevant. + required: true + - type: markdown + attributes: + value: | + **Note:** keep in mind that, while InfiniTime is usable, it is still under heavy development and as such it is continuously evolving. + Some features you want to see implemented might not be compatible with the current state of the project, or might not even be suitable to include *in the firmware* of the watch. + - type: input + id: desc-brief + attributes: + label: Pitch us your idea! + description: A one-line elevator pitch of the feature you'd like to see implemented. + placeholder: "Ex. My dog wants InfiniTime on its smart collar." + validations: + required: true + - type: textarea + id: desc-long + attributes: + label: Description + description: | + Give us a detailed description of the feature you are proposing. Mockups or a description of the possible use cases are highly appreciated. + Tell us why this should be included in the firmware. + placeholder: "Ex. Here is a drawing of my dog wearing an InfiniTime collar and smiling." + - type: markdown + id: companion-app + attributes: + value: | + If this requires features missing from other software (for example a companion app), please take care of opening any relevant feature request over there as well. -- cgit v0.10.2 From dafdf330627d6291acd56f16e8da8c914d19bb29 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 2 Oct 2021 03:22:12 +0000 Subject: Remove static declartion on batteryValue preventing read attribute from updating. diff --git a/src/components/ble/BatteryInformationService.cpp b/src/components/ble/BatteryInformationService.cpp index 7f17690..4ef0235 100644 --- a/src/components/ble/BatteryInformationService.cpp +++ b/src/components/ble/BatteryInformationService.cpp @@ -43,7 +43,7 @@ int BatteryInformationService::OnBatteryServiceRequested(uint16_t connectionHand ble_gatt_access_ctxt* context) { if (attributeHandle == batteryLevelHandle) { NRF_LOG_INFO("BATTERY : handle = %d", batteryLevelHandle); - static uint8_t batteryValue = batteryController.PercentRemaining(); + uint8_t batteryValue = batteryController.PercentRemaining(); int res = os_mbuf_append(context->om, &batteryValue, 1); return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; } -- cgit v0.10.2 From 6475330048fc759a94203a006672b47481cd80ef Mon Sep 17 00:00:00 2001 From: Avamander Date: Sun, 3 Oct 2021 17:26:04 +0300 Subject: Removed an unnecessary space and some punctuation Closes https://github.com/InfiniTimeOrg/InfiniTime/pull/233 diff --git a/doc/contribute.md b/doc/contribute.md index 0c34e2a..b84d6c9 100644 --- a/doc/contribute.md +++ b/doc/contribute.md @@ -18,18 +18,18 @@ You want to fix a bug, add a cool new functionality or improve the code? See *Ho The Pinetime is a cool open source project that deserves to be known. Talk about it around you, on social networks, on your blog,... and let people know that we are working on an open source firmware for a smartwatch! -# How to submit a pull request ? +# How to submit a pull request? ## TL;DR - - Create a branch from develop; - - Work on a single subject in this branch. Create multiple branches/pulls-requests if you want to work on multiple subjects (bugs, features,...); - - Test your modifications on the actual hardware; - - Check the code formatting against our coding conventions and [clang-format](../.clang-format) and [clang-tidy](../.clang-tidy); - - Clean your code and remove files that are not needed; - - Write documentation related to your new feature if applicable; - - Create a pull request and write a great description about it : what does your PR do, why, how,... Add pictures and video if possible; - - Wait for someone to review your PR and take part in the review process; + - Create a branch from develop + - Work on a single subject in this branch. Create multiple branches/pulls-requests if you want to work on multiple subjects (bugs, features,...) + - Test your modifications on the actual hardware + - Check the code formatting against our coding conventions and [clang-format](../.clang-format) and [clang-tidy](../.clang-tidy) + - Clean your code and remove files that are not needed + - Write documentation related to your new feature if applicable + - Create a pull request and write a great description about it: what does your PR do, why, how,... Add pictures and video if possible + - Wait for someone to review your PR and take part in the review process - Your PR will eventually be merged :) Your contributions are more than welcome! -- cgit v0.10.2 From 2aebbe3f474bfaa5058879bde045146f5561fb66 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 3 Oct 2021 16:47:01 +0200 Subject: GPIOTE fix of button and power detection experiment diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 5441c16..a2ff60f 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -158,19 +158,21 @@ void SystemTask::Work() { heartRateSensor.Disable(); heartRateApp.Start(); - nrf_gpio_cfg_sense_input(PinMap::Button, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High); + // Button nrf_gpio_cfg_output(15); nrf_gpio_pin_set(15); nrfx_gpiote_in_config_t pinConfig; - pinConfig.skip_gpio_setup = true; + pinConfig.skip_gpio_setup = false; pinConfig.hi_accuracy = false; pinConfig.is_watcher = false; - pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO; + pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_TOGGLE; pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown; nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler); + nrfx_gpiote_in_event_enable(PinMap::Button, true); + // Touchscreen nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low); pinConfig.skip_gpio_setup = true; @@ -181,18 +183,20 @@ void SystemTask::Work() { nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler); + // Power present pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE; pinConfig.pull = NRF_GPIO_PIN_NOPULL; pinConfig.is_watcher = false; pinConfig.hi_accuracy = false; - pinConfig.skip_gpio_setup = true; + pinConfig.skip_gpio_setup = false; nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler); + nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true); - if (nrf_gpio_pin_read(PinMap::PowerPresent)) { - nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); - } else { - nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); - } + // if (nrf_gpio_pin_read(PinMap::PowerPresent)) { + // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); + // } else { + // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); + // } idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback); dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback); -- cgit v0.10.2 From f5725714d13a66407b0556f8ac3cbd7e6db8901f Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 3 Oct 2021 17:00:38 +0200 Subject: Call battery controller update diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index a2ff60f..fc2c5cf 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -136,7 +136,6 @@ void SystemTask::Work() { touchPanel.Init(); dateTimeController.Register(this); batteryController.Register(this); - batteryController.Update(); motorController.Init(); motionSensor.SoftReset(); timerController.Register(this); @@ -197,6 +196,9 @@ void SystemTask::Work() { // } else { // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); // } + + // Update controller based on current gpio pin state, needs to be called after gpio config + batteryController.Update(); idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback); dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback); -- cgit v0.10.2 From 9ef1babb9dfea4be0ef2179254dc3dd8afd1d7e1 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Sun, 3 Oct 2021 17:03:08 +0200 Subject: Code cleanup diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index fc2c5cf..8412540 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -191,12 +191,6 @@ void SystemTask::Work() { nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true); - // if (nrf_gpio_pin_read(PinMap::PowerPresent)) { - // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); - // } else { - // nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); - // } - // Update controller based on current gpio pin state, needs to be called after gpio config batteryController.Update(); -- cgit v0.10.2 From a9f7153fdf92b097b14143b77645f6608ac1bf9c Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 4 Oct 2021 01:41:38 +0300 Subject: Improve battery percentage calculation and reporting While charging, percentage should only go up, and while discharging, percentage should only go down. diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index b43b229..0ef4ff1 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -69,18 +69,23 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) { // p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024 voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024; + uint8_t newPercent; if (isFull) { - percentRemaining = 100; + newPercent = 100; } else if (voltage < battery_min) { - percentRemaining = 0; + newPercent = 0; } else { - percentRemaining = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), isCharging ? 99 : 100); + newPercent = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), isCharging ? 99 : 100); + } + + if ((isPowerPresent && newPercent > percentRemaining) || (!isPowerPresent && newPercent < percentRemaining) || firstMeasurement) { + firstMeasurement = false; + percentRemaining = newPercent; + systemTask->PushMessage(System::Messages::BatteryPercentageUpdated); } nrfx_saadc_uninit(); isReading = false; - - systemTask->PushMessage(System::Messages::BatteryMeasurementDone); } } diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index c78ffb3..55c2630 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -42,6 +42,7 @@ namespace Pinetime { bool isFull = false; bool isCharging = false; bool isPowerPresent = false; + bool firstMeasurement = true; void SaadcInit(); diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index bd1de23..5aa218d 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -24,7 +24,7 @@ namespace Pinetime { SetOffAlarm, StopRinging, MeasureBatteryTimerExpired, - BatteryMeasurementDone, + BatteryPercentageUpdated, }; } } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 5441c16..0a53101 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -349,14 +349,10 @@ void SystemTask::Work() { motorController.RunForDuration(15); break; case Messages::MeasureBatteryTimerExpired: - sendBatteryNotification = true; batteryController.Update(); break; - case Messages::BatteryMeasurementDone: - if (sendBatteryNotification) { - sendBatteryNotification = false; - nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); - } + case Messages::BatteryPercentageUpdated: + nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); break; default: diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 1fcfeb8..879c1be 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -133,14 +133,12 @@ namespace Pinetime { TimerHandle_t dimTimer; TimerHandle_t idleTimer; TimerHandle_t measureBatteryTimer; - bool sendBatteryNotification = false; bool doNotGoToSleep = false; void GoToRunning(); void UpdateMotion(); bool stepCounterMustBeReset = false; static constexpr TickType_t batteryMeasurementPeriod = pdMS_TO_TICKS(10 * 60 * 1000); - TickType_t lastBatteryNotificationTime = 0; #if configUSE_TRACE_FACILITY == 1 SystemMonitor monitor; -- cgit v0.10.2 From aa83fa2dcfa096e86290c9742e8498bec411732b Mon Sep 17 00:00:00 2001 From: Clemens von Molo Date: Tue, 5 Oct 2021 15:19:44 +0200 Subject: Add docs for app creation and code structure diff --git a/README.md b/README.md index 9b9c328..ee1fad0 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,8 @@ As of now, here is the list of achievements of this project: ## Documentation ### Develop - + - [Rough structure of the code](doc/code/Intro.md) + - [How to implement an application](doc/code/Apps.md) - [Generate the fonts and symbols](src/displayapp/fonts/README.md) - [Creating a stopwatch in Pinetime(article)](https://pankajraghav.com/2021/04/03/PINETIME-STOPCLOCK.html) diff --git a/doc/code/Apps.md b/doc/code/Apps.md new file mode 100644 index 0000000..b19d596 --- /dev/null +++ b/doc/code/Apps.md @@ -0,0 +1,70 @@ +# Apps +This page will teach you: +- what apps in InfiniTime are +- how to implement your own app + +## Theory +Apps are the things you can lauch from the app selection you get by swiping down, but also the app launcher itself or the clock. Settings are also implemented as apps. Most screens you see are their own app, except for apps that have multiple screens (settings launcher, app launcher). +Every app in InfiniTime is it's own class. An object of the class is created when the app is launched and destroyed when the user exits the app. They run inside the "displayapp" task (briefly discussed [here](./Intro.md)). They are responsible for everything drawn on the screen when they are running. By default, apps only do something (as in a function is executed) when they are created or when a touch event is detected. + +## Interface +Every app class is has to be inside the namespace `Pinetime::Applications::Screens` and inherit from `Screen`. The constructor should have at least one parameter `DisplayApp* app`, which it needs for the constructor of its parent class Screen. Other parameters should be references to controllers that the app needs. A deconstructor is needed to clean up LVGL and restore any changes (for example re-enable sleeping). App classes can override `bool OnButtonPushed()`, `bool OnTouchEvent(TouchEvents event)` and `bool OnTouchEvent(uint16_t x, uint16_t y)` to implement their own functionality for those events. If an app only needs to display some text and do something upon a touch screen button press, it does not need to override any of these functions, as LVGL can also handle touch events for you. If your app needs to be updated continuously, yo can do so by adding a `Refresh()` function to your class and calling `lv_task_create` inside the constructor. + +## Creating your own app +A minimal app could look like this:
+MyApp.h: +```cpp +#pragma once + +#include +#include "displayapp/screens/Screen.h" + +namespace PineTime { + namespace Applications { + namespace Screens { + class MyApp : public Screen { + public: + MyApp(DisplayApp* app); + ~MyApp() override; + } + } + } +} +``` + +MyApp.cpp: +```cpp +#include "MyApp.h" +#include "displayapp/DisplayApp.h" + +using namespace Pinetime::Applications::Screens; + +MyApp::MyApp(DisplayApp* app) : Screen(app) { + lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + lv_obj_set_pos(container1, 30, 60); + lv_obj_set_width(container1, LV_HOR_RES - 50); + lv_obj_set_height(container1, LV_VER_RES - 60); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text_static(title,"My test application"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); +} + +MyApp::~MyApp() { + lv_obj_clean(lv_scr_act()); +} +``` +Both of these files should be in displayapp/screens/ or displayapp/screens/settings if it's a setting app. + +Now we have our very own app, but InfiniTime does not know about it yet. The first step is to include it in the compilation by adding it to CMakeLists.txt . The next step to making it launchable is to give your app an id. To do this, add an entry in the enum class `Pinetime::Applications::Apps`. Name this entry after your app. Add `#include "displayapp/screens/MyApp.h"` to the file displayapp/DisplayApp.cpp . Now, go to the function `DisplayApp::LoadApp` and add another case to the switch statement. The case will be the id you gave your app earlier. If your app needs any additional arguments, this is the place to pass them.
+ +If you want your app to be launched from the regular app launcher, go to displayapp/screens/ApplicationList.cpp. Add your app to one of the `CreateScreen` functions, or add another `CreateScreen` function if there are no empty spaces for your app.
+If your app is a setting, do the same procedure in displayapp/screens/settings/Settings.cpp . + +You should now be able to [build](../buildAndProgram.md) the firmware and flash it to your PineTime. Yay! diff --git a/doc/code/Intro.md b/doc/code/Intro.md new file mode 100644 index 0000000..3c7fee0 --- /dev/null +++ b/doc/code/Intro.md @@ -0,0 +1,20 @@ +# Introduction to the code +This page is meant to guide you through the source code, so you can find the relevant files for what you're working on. + +## FreeRTOS +Infinitime is based on FreeRTOS, a real-time operating system. FreeRTOS provides several quality of life abstractions (for example easy software timers) and most importantly supports multiple tasks. You can sort of imagine them as processes or threads on a full operating system. The main "process" creates at least one task and then starts the FreeRTOS task scheduler. This main "process" is the standard main() function inside main.cpp . The task scheduler is responsible for giving every task enough cpu time. As there is only one core on the SoC of the PineTime, real concurrency is impossible and the scheduler has to swap tasks in and out to emulate it. + +### Tasks +Tasks are created by calling `xTaskCreate` and passing a function with the signature `void functionName(void*)`. For more info on task creation see the [FreeRTOS Documentation](https://www.freertos.org/a00125.html). +In our case, main calls `systemTask.Start()`, which creates the **"MAIN" task**. The function running inside that task is `SystemTask::Work()`. Both functions are located inside systemtask/SystemTask.cpp . `SystemTask::Work()` initializes all the driver and controller objects. It also starts the **task "displayapp"**, which is responsible for launching and running apps, controlling the screen and handling touch events (or forwarding them to the active app). You can find the "displayapp" task inside displayapp/DisplayApp.cpp . +There are also other tasks that are responsible for Bluetooth ("ll" and "ble" inside libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c) and periodic tasks like heartrate measurements (heartratetask/HeartRateTask.cpp). + +## Controllers +Controllers in InfiniTime are singleton objects that can provide access to certain resources to apps. Some of them interface with drivers, others are the driver for the resource. The resources provided don't have to be hardware-based. They are declared in main.cpp and initialized in systemtask/SystemTask.cpp . Some controllers can be passed by reference to apps that need access to the resource (for example vibration motor). +They reside in components inside their own subfolder. + +## Apps +For more detail see the [Apps page](./Apps.md) + +## Bluetooth +Header files with short documentation for the functions are inside libs/mynewt-nimble/nimble/host/include/host/ . -- cgit v0.10.2 From b2141a9050c02bff6acd09b2f8dd824b2b5f8c34 Mon Sep 17 00:00:00 2001 From: Clemens von Molo Date: Tue, 5 Oct 2021 18:55:02 +0200 Subject: advise against unecessary additional tasks in docs diff --git a/doc/code/Intro.md b/doc/code/Intro.md index 3c7fee0..b7371f0 100644 --- a/doc/code/Intro.md +++ b/doc/code/Intro.md @@ -6,8 +6,9 @@ Infinitime is based on FreeRTOS, a real-time operating system. FreeRTOS provides ### Tasks Tasks are created by calling `xTaskCreate` and passing a function with the signature `void functionName(void*)`. For more info on task creation see the [FreeRTOS Documentation](https://www.freertos.org/a00125.html). -In our case, main calls `systemTask.Start()`, which creates the **"MAIN" task**. The function running inside that task is `SystemTask::Work()`. Both functions are located inside systemtask/SystemTask.cpp . `SystemTask::Work()` initializes all the driver and controller objects. It also starts the **task "displayapp"**, which is responsible for launching and running apps, controlling the screen and handling touch events (or forwarding them to the active app). You can find the "displayapp" task inside displayapp/DisplayApp.cpp . -There are also other tasks that are responsible for Bluetooth ("ll" and "ble" inside libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c) and periodic tasks like heartrate measurements (heartratetask/HeartRateTask.cpp). +In our case, main calls `systemTask.Start()`, which creates the **"MAIN" task**. The function running inside that task is `SystemTask::Work()`. You may also see this task being referred to as the **work task**. Both functions are located inside systemtask/SystemTask.cpp . `SystemTask::Work()` initializes all the driver and controller objects. It also starts the **task "displayapp"**, which is responsible for launching and running apps, controlling the screen and handling touch events (or forwarding them to the active app). You can find the "displayapp" task inside displayapp/DisplayApp.cpp . +There are also other tasks that are responsible for Bluetooth ("ll" and "ble" inside libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c) and periodic tasks like heartrate measurements (heartratetask/HeartRateTask.cpp).
+While it is possible for you to create your own task when you need it, it is recommended to just add functionality to `SystemTask::Work()` if possible. If you absolutely need to create another task, try to guess how much stack space (in words/4-byte packets) it will need instead of just typing in a large-ish number. You can use the define `configMINIMAL_STACK_SIZE` which is currently set to 120 words. ## Controllers Controllers in InfiniTime are singleton objects that can provide access to certain resources to apps. Some of them interface with drivers, others are the driver for the resource. The resources provided don't have to be hardware-based. They are declared in main.cpp and initialized in systemtask/SystemTask.cpp . Some controllers can be passed by reference to apps that need access to the resource (for example vibration motor). -- cgit v0.10.2 From 90fdea29b80016c6d0e6d518853c9251555ea695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Tue, 5 Oct 2021 19:58:58 +0200 Subject: Fixed feature request template according to https://github.com/InfiniTimeOrg/InfiniTime/pull/705#issuecomment-933820293 diff --git a/.github/ISSUE_TEMPLATE/feature-request.yaml b/.github/ISSUE_TEMPLATE/feature-request.yaml index 33b059c..31b5e27 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yaml +++ b/.github/ISSUE_TEMPLATE/feature-request.yaml @@ -1,7 +1,7 @@ name: Feature Request description: File a feature request title: "[Feature Request]: " -labels: ["feature-request"] +labels: ["feature request"] body: - type: markdown attributes: -- cgit v0.10.2 From f1aae6af49c212d98afeb6e86615c6ee90ae771c Mon Sep 17 00:00:00 2001 From: Clemens von Molo Date: Wed, 6 Oct 2021 14:30:16 +0200 Subject: multiple improvements to code docs diff --git a/doc/code/Apps.md b/doc/code/Apps.md index b19d596..6b4c383 100644 --- a/doc/code/Apps.md +++ b/doc/code/Apps.md @@ -4,11 +4,21 @@ This page will teach you: - how to implement your own app ## Theory -Apps are the things you can lauch from the app selection you get by swiping down, but also the app launcher itself or the clock. Settings are also implemented as apps. Most screens you see are their own app, except for apps that have multiple screens (settings launcher, app launcher). +Apps are the things you can launch from the app selection you get by swiping up. +At the moment, settings and even the app launcher itself or the clock are implemented very similarly, this might change in the future though. Every app in InfiniTime is it's own class. An object of the class is created when the app is launched and destroyed when the user exits the app. They run inside the "displayapp" task (briefly discussed [here](./Intro.md)). They are responsible for everything drawn on the screen when they are running. By default, apps only do something (as in a function is executed) when they are created or when a touch event is detected. ## Interface -Every app class is has to be inside the namespace `Pinetime::Applications::Screens` and inherit from `Screen`. The constructor should have at least one parameter `DisplayApp* app`, which it needs for the constructor of its parent class Screen. Other parameters should be references to controllers that the app needs. A deconstructor is needed to clean up LVGL and restore any changes (for example re-enable sleeping). App classes can override `bool OnButtonPushed()`, `bool OnTouchEvent(TouchEvents event)` and `bool OnTouchEvent(uint16_t x, uint16_t y)` to implement their own functionality for those events. If an app only needs to display some text and do something upon a touch screen button press, it does not need to override any of these functions, as LVGL can also handle touch events for you. If your app needs to be updated continuously, yo can do so by adding a `Refresh()` function to your class and calling `lv_task_create` inside the constructor. +Every app class has to be inside the namespace `Pinetime::Applications::Screens` and inherit from `Screen`. The constructor should have at least one parameter `DisplayApp* app`, which it needs for the constructor of its parent class Screen. Other parameters should be references to controllers that the app needs. A deconstructor is needed to clean up LVGL and restore any changes (for example re-enable sleeping). App classes can override `bool OnButtonPushed()`, `bool OnTouchEvent(TouchEvents event)` and `bool OnTouchEvent(uint16_t x, uint16_t y)` to implement their own functionality for those events. If an app only needs to display some text and do something upon a touch screen button press, it does not need to override any of these functions, as LVGL can also handle touch events for you. If you have any doubts, you can always look at how the other apps are doing things. + +### Continuous updating +If your app needs to be updated continuously, yo can do so by adding a `Refresh()` function to your class and calling `lv_task_create` inside the constructor. An example call could look like this:
+`taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);`
+With `taskRefresh` being a member variable of your class and of type `lv_task_t*`. Remember to delete the task again using `lv_task_del`. The function `RefreshTaskCallback` is inherited from screen and just calls your `Refresh` function. + +### Apps with multiple screens +InfiniTime provides a mini-library in [displayapp/screens/ScreenList.h](/src/displayapp/screens/ScreenList.h) which makes it relatively easy to add multiple screens to your app. To use it, #include it in the header file of your app and add a ScreenList member to your class. The template argument should be the number of screens you need. You will also need to add `CreateScreen` functions that return `std::unique_ptr` to your class, one for every screen you have. There are still some things left to to that I won't cover here. To figure them out, have a look at the "apps" ApplicationList, Settings and SystemInfo. + ## Creating your own app A minimal app could look like this:
@@ -16,19 +26,19 @@ MyApp.h: ```cpp #pragma once -#include #include "displayapp/screens/Screen.h" +#include namespace PineTime { - namespace Applications { - namespace Screens { - class MyApp : public Screen { - public: - MyApp(DisplayApp* app); - ~MyApp() override; - } - } + namespace Applications { + namespace Screens { + class MyApp : public Screen { + public: + MyApp(DisplayApp* app); + ~MyApp() override; + } } + } } ``` @@ -40,31 +50,23 @@ MyApp.cpp: using namespace Pinetime::Applications::Screens; MyApp::MyApp(DisplayApp* app) : Screen(app) { - lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); - lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); - lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); - lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - lv_obj_set_pos(container1, 30, 60); - lv_obj_set_width(container1, LV_HOR_RES - 50); - lv_obj_set_height(container1, LV_VER_RES - 60); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text_static(title,"My test application"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); + lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text_static(title,"My test application"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } MyApp::~MyApp() { - lv_obj_clean(lv_scr_act()); + lv_obj_clean(lv_scr_act()); } ``` -Both of these files should be in displayapp/screens/ or displayapp/screens/settings if it's a setting app. +Both of these files should be in [displayapp/screens/](/src/displayapp/screens/) or [displayapp/screens/settings/](/src/displayapp/screens/settings/) if it's a setting app. -Now we have our very own app, but InfiniTime does not know about it yet. The first step is to include it in the compilation by adding it to CMakeLists.txt . The next step to making it launchable is to give your app an id. To do this, add an entry in the enum class `Pinetime::Applications::Apps`. Name this entry after your app. Add `#include "displayapp/screens/MyApp.h"` to the file displayapp/DisplayApp.cpp . Now, go to the function `DisplayApp::LoadApp` and add another case to the switch statement. The case will be the id you gave your app earlier. If your app needs any additional arguments, this is the place to pass them.
+Now we have our very own app, but InfiniTime does not know about it yet. The first step is to include your MyApp.cpp (or any new cpp files for that matter) in the compilation by adding it to [CMakeLists.txt](/CMakeLists.txt). +The next step to making it launchable is to give your app an id. To do this, add an entry in the enum class `Pinetime::Applications::Apps` ([displayapp/Apps.h](/src/displayapp/Apps.h)). +Name this entry after your app. Add `#include "displayapp/screens/MyApp.h"` to the file [displayapp/DisplayApp.cpp](/src/displayapp/DisplayApp.cpp). Now, go to the function `DisplayApp::LoadApp` and add another case to the switch statement. The case will be the id you gave your app earlier. If your app needs any additional arguments, this is the place to pass them. -If you want your app to be launched from the regular app launcher, go to displayapp/screens/ApplicationList.cpp. Add your app to one of the `CreateScreen` functions, or add another `CreateScreen` function if there are no empty spaces for your app.
-If your app is a setting, do the same procedure in displayapp/screens/settings/Settings.cpp . +If you want your app to be launched from the regular app launcher, go to [displayapp/screens/ApplicationList.cpp](/src/displayapp/screens/ApplicationList.cpp). Add your app to one of the `CreateScreen` functions, or add another `CreateScreen` function if there are no empty spaces for your app.
+If your app is a setting, do the same procedure in [displayapp/screens/settings/Settings.cpp](/src/displayapp/screens/settings/Settings.cpp). You should now be able to [build](../buildAndProgram.md) the firmware and flash it to your PineTime. Yay! diff --git a/doc/code/Intro.md b/doc/code/Intro.md index b7371f0..8725351 100644 --- a/doc/code/Intro.md +++ b/doc/code/Intro.md @@ -2,20 +2,20 @@ This page is meant to guide you through the source code, so you can find the relevant files for what you're working on. ## FreeRTOS -Infinitime is based on FreeRTOS, a real-time operating system. FreeRTOS provides several quality of life abstractions (for example easy software timers) and most importantly supports multiple tasks. You can sort of imagine them as processes or threads on a full operating system. The main "process" creates at least one task and then starts the FreeRTOS task scheduler. This main "process" is the standard main() function inside main.cpp . The task scheduler is responsible for giving every task enough cpu time. As there is only one core on the SoC of the PineTime, real concurrency is impossible and the scheduler has to swap tasks in and out to emulate it. +Infinitime is based on FreeRTOS, a real-time operating system. FreeRTOS provides several quality of life abstractions (for example easy software timers) and most importantly supports multiple tasks. If you want to read up on real-time operating systems, you can look [here](https://www.freertos.org/implementation/a00002.html) and [here](https://www.freertos.org/features.html). The main "process" creates at least one task and then starts the FreeRTOS task scheduler. This main "process" is the standard main() function inside [main.cpp](/src/main.cpp). The task scheduler is responsible for giving every task enough cpu time. As there is only one core on the SoC of the PineTime, real concurrency is impossible and the scheduler has to swap tasks in and out to emulate it. ### Tasks Tasks are created by calling `xTaskCreate` and passing a function with the signature `void functionName(void*)`. For more info on task creation see the [FreeRTOS Documentation](https://www.freertos.org/a00125.html). -In our case, main calls `systemTask.Start()`, which creates the **"MAIN" task**. The function running inside that task is `SystemTask::Work()`. You may also see this task being referred to as the **work task**. Both functions are located inside systemtask/SystemTask.cpp . `SystemTask::Work()` initializes all the driver and controller objects. It also starts the **task "displayapp"**, which is responsible for launching and running apps, controlling the screen and handling touch events (or forwarding them to the active app). You can find the "displayapp" task inside displayapp/DisplayApp.cpp . -There are also other tasks that are responsible for Bluetooth ("ll" and "ble" inside libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c) and periodic tasks like heartrate measurements (heartratetask/HeartRateTask.cpp).
-While it is possible for you to create your own task when you need it, it is recommended to just add functionality to `SystemTask::Work()` if possible. If you absolutely need to create another task, try to guess how much stack space (in words/4-byte packets) it will need instead of just typing in a large-ish number. You can use the define `configMINIMAL_STACK_SIZE` which is currently set to 120 words. +In our case, main calls `systemTask.Start()`, which creates the **"MAIN" task**. The function running inside that task is `SystemTask::Work()`. You may also see this task being referred to as the **work task**. Both functions are located inside [systemtask/SystemTask.cpp](/src/systemtask/SystemTask.cpp). `SystemTask::Work()` initializes all the driver and controller objects. It also starts the **task "displayapp"**, which is responsible for launching and running apps, controlling the screen and handling touch events (or forwarding them to the active app). You can find the "displayapp" task inside [displayapp/DisplayApp.cpp](/src/displayapp/DisplayApp.cpp). +There are also other tasks that are responsible for Bluetooth ("ll" and "ble" inside [libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c](/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c)) and periodic tasks like heartrate measurements ([heartratetask/HeartRateTask.cpp](/src/heartratetask/HeartRateTask.cpp)).
+While it is possible for you to create your own task when you need it, it is recommended to just add functionality to `SystemTask::Work()` if possible. If you absolutely need to create another task, try to guess how much [stack space](https://www.freertos.org/FAQMem.html#StackSize) (in words/4-byte packets) it will need instead of just typing in a large-ish number. You can use the define `configMINIMAL_STACK_SIZE` which is currently set to 120 words. ## Controllers -Controllers in InfiniTime are singleton objects that can provide access to certain resources to apps. Some of them interface with drivers, others are the driver for the resource. The resources provided don't have to be hardware-based. They are declared in main.cpp and initialized in systemtask/SystemTask.cpp . Some controllers can be passed by reference to apps that need access to the resource (for example vibration motor). -They reside in components inside their own subfolder. +Controllers in InfiniTime are singleton objects that can provide access to certain resources to apps. Some of them interface with drivers, others are the driver for the resource. The resources provided don't have to be hardware-based. They are declared in main.cpp and initialized in [systemtask/SystemTask.cpp](/src/systemtask/SystemTask.cpp). Some controllers can be passed by reference to apps that need access to the resource (for example vibration motor). +They reside in [components/](/src/components/) inside their own subfolder. ## Apps For more detail see the [Apps page](./Apps.md) ## Bluetooth -Header files with short documentation for the functions are inside libs/mynewt-nimble/nimble/host/include/host/ . +Header files with short documentation for the functions are inside [libs/mynewt-nimble/nimble/host/include/host/](/src/libs/mynewt-nimble/nimble/host/include/host/). -- cgit v0.10.2 From 884c89c61cf6568ddbc79346110494aacae1176b Mon Sep 17 00:00:00 2001 From: Clemens von Molo Date: Wed, 6 Oct 2021 18:29:52 +0200 Subject: minor corrections and notice about ui guidelines in docs diff --git a/doc/code/Apps.md b/doc/code/Apps.md index 6b4c383..41c945a 100644 --- a/doc/code/Apps.md +++ b/doc/code/Apps.md @@ -6,13 +6,13 @@ This page will teach you: ## Theory Apps are the things you can launch from the app selection you get by swiping up. At the moment, settings and even the app launcher itself or the clock are implemented very similarly, this might change in the future though. -Every app in InfiniTime is it's own class. An object of the class is created when the app is launched and destroyed when the user exits the app. They run inside the "displayapp" task (briefly discussed [here](./Intro.md)). They are responsible for everything drawn on the screen when they are running. By default, apps only do something (as in a function is executed) when they are created or when a touch event is detected. +Every app in InfiniTime is it's own class. An instance of the class is created when the app is launched and destroyed when the user exits the app. They run inside the "displayapp" task (briefly discussed [here](./Intro.md)). They are responsible for everything drawn on the screen when they are running. By default, apps only do something (as in a function is executed) when they are created or when a touch event is detected. ## Interface Every app class has to be inside the namespace `Pinetime::Applications::Screens` and inherit from `Screen`. The constructor should have at least one parameter `DisplayApp* app`, which it needs for the constructor of its parent class Screen. Other parameters should be references to controllers that the app needs. A deconstructor is needed to clean up LVGL and restore any changes (for example re-enable sleeping). App classes can override `bool OnButtonPushed()`, `bool OnTouchEvent(TouchEvents event)` and `bool OnTouchEvent(uint16_t x, uint16_t y)` to implement their own functionality for those events. If an app only needs to display some text and do something upon a touch screen button press, it does not need to override any of these functions, as LVGL can also handle touch events for you. If you have any doubts, you can always look at how the other apps are doing things. ### Continuous updating -If your app needs to be updated continuously, yo can do so by adding a `Refresh()` function to your class and calling `lv_task_create` inside the constructor. An example call could look like this:
+If your app needs to be updated continuously, yo can do so by overriding the `Refresh()` function in your class and calling `lv_task_create` inside the constructor. An example call could look like this:
`taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);`
With `taskRefresh` being a member variable of your class and of type `lv_task_t*`. Remember to delete the task again using `lv_task_del`. The function `RefreshTaskCallback` is inherited from screen and just calls your `Refresh` function. @@ -50,8 +50,8 @@ MyApp.cpp: using namespace Pinetime::Applications::Screens; MyApp::MyApp(DisplayApp* app) : Screen(app) { - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); - lv_label_set_text_static(title,"My test application"); + lv_obj_t* title = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text_static(title, "My test application"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); } @@ -70,3 +70,5 @@ If you want your app to be launched from the regular app launcher, go to [displa If your app is a setting, do the same procedure in [displayapp/screens/settings/Settings.cpp](/src/displayapp/screens/settings/Settings.cpp). You should now be able to [build](../buildAndProgram.md) the firmware and flash it to your PineTime. Yay! + +Please remember to pay attention to the [UI guidelines](../ui_guidelines.md) when designing an app that you want to include in mainstream InfiniTime. -- cgit v0.10.2 From c3cc83ae17d7cbdd2707df12e89a600d76e5836d Mon Sep 17 00:00:00 2001 From: Clemens von Molo Date: Fri, 8 Oct 2021 14:59:45 +0200 Subject: More reasonable line lengths in Apps.md and Intro.md diff --git a/doc/code/Apps.md b/doc/code/Apps.md index 41c945a..b3bab04 100644 --- a/doc/code/Apps.md +++ b/doc/code/Apps.md @@ -6,18 +6,40 @@ This page will teach you: ## Theory Apps are the things you can launch from the app selection you get by swiping up. At the moment, settings and even the app launcher itself or the clock are implemented very similarly, this might change in the future though. -Every app in InfiniTime is it's own class. An instance of the class is created when the app is launched and destroyed when the user exits the app. They run inside the "displayapp" task (briefly discussed [here](./Intro.md)). They are responsible for everything drawn on the screen when they are running. By default, apps only do something (as in a function is executed) when they are created or when a touch event is detected. +Every app in InfiniTime is it's own class. +An instance of the class is created when the app is launched and destroyed when the user exits the app. +They run inside the "displayapp" task (briefly discussed [here](./Intro.md)). +Apps are responsible for everything drawn on the screen when they are running. +By default, apps only do something (as in a function is executed) when they are created or when a touch event is detected. ## Interface -Every app class has to be inside the namespace `Pinetime::Applications::Screens` and inherit from `Screen`. The constructor should have at least one parameter `DisplayApp* app`, which it needs for the constructor of its parent class Screen. Other parameters should be references to controllers that the app needs. A deconstructor is needed to clean up LVGL and restore any changes (for example re-enable sleeping). App classes can override `bool OnButtonPushed()`, `bool OnTouchEvent(TouchEvents event)` and `bool OnTouchEvent(uint16_t x, uint16_t y)` to implement their own functionality for those events. If an app only needs to display some text and do something upon a touch screen button press, it does not need to override any of these functions, as LVGL can also handle touch events for you. If you have any doubts, you can always look at how the other apps are doing things. +Every app class has to be inside the namespace `Pinetime::Applications::Screens` and inherit from `Screen`. +The constructor should have at least one parameter `DisplayApp* app`, which it needs for the constructor of its parent class Screen. +Other parameters should be references to controllers that the app needs. +A destructor is needed to clean up LVGL and restore any changes (for example re-enable sleeping). +App classes can override `bool OnButtonPushed()`, `bool OnTouchEvent(TouchEvents event)` and `bool OnTouchEvent(uint16_t x, uint16_t y)` to implement their own functionality for those events. +If an app only needs to display some text and do something upon a touch screen button press, +it does not need to override any of these functions, as LVGL can also handle touch events for you. +If you have any doubts, you can always look at how the other apps are doing things. ### Continuous updating -If your app needs to be updated continuously, yo can do so by overriding the `Refresh()` function in your class and calling `lv_task_create` inside the constructor. An example call could look like this:
+If your app needs to be updated continuously, yo can do so by overriding the `Refresh()` function in your class +and calling `lv_task_create` inside the constructor. +An example call could look like this:
`taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);`
-With `taskRefresh` being a member variable of your class and of type `lv_task_t*`. Remember to delete the task again using `lv_task_del`. The function `RefreshTaskCallback` is inherited from screen and just calls your `Refresh` function. +With `taskRefresh` being a member variable of your class and of type `lv_task_t*`. +Remember to delete the task again using `lv_task_del`. +The function `RefreshTaskCallback` is inherited from screen and just calls your `Refresh` function. ### Apps with multiple screens -InfiniTime provides a mini-library in [displayapp/screens/ScreenList.h](/src/displayapp/screens/ScreenList.h) which makes it relatively easy to add multiple screens to your app. To use it, #include it in the header file of your app and add a ScreenList member to your class. The template argument should be the number of screens you need. You will also need to add `CreateScreen` functions that return `std::unique_ptr` to your class, one for every screen you have. There are still some things left to to that I won't cover here. To figure them out, have a look at the "apps" ApplicationList, Settings and SystemInfo. +InfiniTime provides a mini-library in [displayapp/screens/ScreenList.h](/src/displayapp/screens/ScreenList.h) +which makes it relatively easy to add multiple screens to your app. +To use it, #include it in the header file of your app and add a ScreenList member to your class. +The template argument should be the number of screens you need. +You will also need to add `CreateScreen` functions that return `std::unique_ptr` +to your class, one for every screen you have. +There are still some things left to to that I won't cover here. +To figure them out, have a look at the "apps" ApplicationList, Settings and SystemInfo. ## Creating your own app @@ -60,15 +82,25 @@ MyApp::~MyApp() { lv_obj_clean(lv_scr_act()); } ``` -Both of these files should be in [displayapp/screens/](/src/displayapp/screens/) or [displayapp/screens/settings/](/src/displayapp/screens/settings/) if it's a setting app. - -Now we have our very own app, but InfiniTime does not know about it yet. The first step is to include your MyApp.cpp (or any new cpp files for that matter) in the compilation by adding it to [CMakeLists.txt](/CMakeLists.txt). -The next step to making it launchable is to give your app an id. To do this, add an entry in the enum class `Pinetime::Applications::Apps` ([displayapp/Apps.h](/src/displayapp/Apps.h)). -Name this entry after your app. Add `#include "displayapp/screens/MyApp.h"` to the file [displayapp/DisplayApp.cpp](/src/displayapp/DisplayApp.cpp). Now, go to the function `DisplayApp::LoadApp` and add another case to the switch statement. The case will be the id you gave your app earlier. If your app needs any additional arguments, this is the place to pass them. - -If you want your app to be launched from the regular app launcher, go to [displayapp/screens/ApplicationList.cpp](/src/displayapp/screens/ApplicationList.cpp). Add your app to one of the `CreateScreen` functions, or add another `CreateScreen` function if there are no empty spaces for your app.
+Both of these files should be in [displayapp/screens/](/src/displayapp/screens/) +or [displayapp/screens/settings/](/src/displayapp/screens/settings/) if it's a setting app. + +Now we have our very own app, but InfiniTime does not know about it yet. +The first step is to include your MyApp.cpp (or any new cpp files for that matter) +in the compilation by adding it to [CMakeLists.txt](/CMakeLists.txt). +The next step to making it launchable is to give your app an id. +To do this, add an entry in the enum class `Pinetime::Applications::Apps` ([displayapp/Apps.h](/src/displayapp/Apps.h)). +Name this entry after your app. Add `#include "displayapp/screens/MyApp.h"` to the file [displayapp/DisplayApp.cpp](/src/displayapp/DisplayApp.cpp). +Now, go to the function `DisplayApp::LoadApp` and add another case to the switch statement. +The case will be the id you gave your app earlier. +If your app needs any additional arguments, this is the place to pass them. + +If you want your app to be launched from the regular app launcher, go to [displayapp/screens/ApplicationList.cpp](/src/displayapp/screens/ApplicationList.cpp). +Add your app to one of the `CreateScreen` functions, or add another `CreateScreen` function if there are no empty spaces for your app.
If your app is a setting, do the same procedure in [displayapp/screens/settings/Settings.cpp](/src/displayapp/screens/settings/Settings.cpp). -You should now be able to [build](../buildAndProgram.md) the firmware and flash it to your PineTime. Yay! +You should now be able to [build](../buildAndProgram.md) the firmware +and flash it to your PineTime. Yay! -Please remember to pay attention to the [UI guidelines](../ui_guidelines.md) when designing an app that you want to include in mainstream InfiniTime. +Please remember to pay attention to the [UI guidelines](../ui_guidelines.md) +when designing an app that you want to include in mainstream InfiniTime. diff --git a/doc/code/Intro.md b/doc/code/Intro.md index 8725351..762102f 100644 --- a/doc/code/Intro.md +++ b/doc/code/Intro.md @@ -2,16 +2,37 @@ This page is meant to guide you through the source code, so you can find the relevant files for what you're working on. ## FreeRTOS -Infinitime is based on FreeRTOS, a real-time operating system. FreeRTOS provides several quality of life abstractions (for example easy software timers) and most importantly supports multiple tasks. If you want to read up on real-time operating systems, you can look [here](https://www.freertos.org/implementation/a00002.html) and [here](https://www.freertos.org/features.html). The main "process" creates at least one task and then starts the FreeRTOS task scheduler. This main "process" is the standard main() function inside [main.cpp](/src/main.cpp). The task scheduler is responsible for giving every task enough cpu time. As there is only one core on the SoC of the PineTime, real concurrency is impossible and the scheduler has to swap tasks in and out to emulate it. +Infinitime is based on FreeRTOS, a real-time operating system. +FreeRTOS provides several quality of life abstractions (for example easy software timers) +and most importantly supports multiple tasks. +If you want to read up on real-time operating systems, you can look [here](https://www.freertos.org/implementation/a00002.html) and [here](https://www.freertos.org/features.html). +The main "process" creates at least one task and then starts the FreeRTOS task scheduler. +This main "process" is the standard main() function inside [main.cpp](/src/main.cpp). +The task scheduler is responsible for giving every task enough cpu time. +As there is only one core on the SoC of the PineTime, real concurrency is impossible and the scheduler has to swap tasks in and out to emulate it. ### Tasks -Tasks are created by calling `xTaskCreate` and passing a function with the signature `void functionName(void*)`. For more info on task creation see the [FreeRTOS Documentation](https://www.freertos.org/a00125.html). -In our case, main calls `systemTask.Start()`, which creates the **"MAIN" task**. The function running inside that task is `SystemTask::Work()`. You may also see this task being referred to as the **work task**. Both functions are located inside [systemtask/SystemTask.cpp](/src/systemtask/SystemTask.cpp). `SystemTask::Work()` initializes all the driver and controller objects. It also starts the **task "displayapp"**, which is responsible for launching and running apps, controlling the screen and handling touch events (or forwarding them to the active app). You can find the "displayapp" task inside [displayapp/DisplayApp.cpp](/src/displayapp/DisplayApp.cpp). -There are also other tasks that are responsible for Bluetooth ("ll" and "ble" inside [libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c](/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c)) and periodic tasks like heartrate measurements ([heartratetask/HeartRateTask.cpp](/src/heartratetask/HeartRateTask.cpp)).
-While it is possible for you to create your own task when you need it, it is recommended to just add functionality to `SystemTask::Work()` if possible. If you absolutely need to create another task, try to guess how much [stack space](https://www.freertos.org/FAQMem.html#StackSize) (in words/4-byte packets) it will need instead of just typing in a large-ish number. You can use the define `configMINIMAL_STACK_SIZE` which is currently set to 120 words. +Tasks are created by calling `xTaskCreate` and passing a function with the signature `void functionName(void*)`. +For more info on task creation see the [FreeRTOS Documentation](https://www.freertos.org/a00125.html). +In our case, main calls `systemTask.Start()`, which creates the **"MAIN" task**. +The function running inside that task is `SystemTask::Work()`. +You may also see this task being referred to as the **work task**. +Both functions are located inside [systemtask/SystemTask.cpp](/src/systemtask/SystemTask.cpp). `SystemTask::Work()` initializes all the driver and controller objects. +It also starts the **task "displayapp"**, which is responsible for launching and running apps, controlling the screen and handling touch events (or forwarding them to the active app). +You can find the "displayapp" task inside [displayapp/DisplayApp.cpp](/src/displayapp/DisplayApp.cpp). +There are also other tasks that are responsible for Bluetooth ("ll" and "ble" inside [libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c](/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c)) +and periodic tasks like heartrate measurements ([heartratetask/HeartRateTask.cpp](/src/heartratetask/HeartRateTask.cpp)).
+While it is possible for you to create your own task when you need it, it is recommended to just add functionality to `SystemTask::Work()` if possible. +If you absolutely need to create another task, try to guess how much [stack space](https://www.freertos.org/FAQMem.html#StackSize) (in words/4-byte packets) +it will need instead of just typing in a large-ish number. +You can use the define `configMINIMAL_STACK_SIZE` which is currently set to 120 words. ## Controllers -Controllers in InfiniTime are singleton objects that can provide access to certain resources to apps. Some of them interface with drivers, others are the driver for the resource. The resources provided don't have to be hardware-based. They are declared in main.cpp and initialized in [systemtask/SystemTask.cpp](/src/systemtask/SystemTask.cpp). Some controllers can be passed by reference to apps that need access to the resource (for example vibration motor). +Controllers in InfiniTime are singleton objects that can provide access to certain resources to apps. +Some of them interface with drivers, others are the driver for the resource. +The resources provided don't have to be hardware-based. +They are declared in main.cpp and initialized in [systemtask/SystemTask.cpp](/src/systemtask/SystemTask.cpp). +Some controllers can be passed by reference to apps that need access to the resource (for example vibration motor). They reside in [components/](/src/components/) inside their own subfolder. ## Apps -- cgit v0.10.2 From fc2241fbf47d90510c8c01c3666f9fae5e56754b Mon Sep 17 00:00:00 2001 From: hubmartin Date: Fri, 8 Oct 2021 16:53:49 +0200 Subject: Add wake on charge event diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 5441c16..59c73d9 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -347,6 +347,9 @@ void SystemTask::Work() { case Messages::OnChargingEvent: batteryController.Update(); motorController.RunForDuration(15); + if (isSleeping && !isWakingUp) { + GoToRunning(); + } break; case Messages::MeasureBatteryTimerExpired: sendBatteryNotification = true; -- cgit v0.10.2 From 98e74a32179420a74527532c902516db28795c29 Mon Sep 17 00:00:00 2001 From: hubmartin Date: Fri, 8 Oct 2021 17:01:27 +0200 Subject: Call also ReloadIdleTimer diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 59c73d9..09c7e88 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -347,6 +347,7 @@ void SystemTask::Work() { case Messages::OnChargingEvent: batteryController.Update(); motorController.RunForDuration(15); + ReloadIdleTimer(); if (isSleeping && !isWakingUp) { GoToRunning(); } -- cgit v0.10.2 From 4f7c675ae3dac0a3d47a0c58d9481f080d53092d Mon Sep 17 00:00:00 2001 From: Avamander Date: Fri, 8 Oct 2021 18:38:45 +0300 Subject: Removed the title prefix diff --git a/.github/ISSUE_TEMPLATE/feature-request.yaml b/.github/ISSUE_TEMPLATE/feature-request.yaml index 31b5e27..092ef90 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yaml +++ b/.github/ISSUE_TEMPLATE/feature-request.yaml @@ -1,6 +1,6 @@ name: Feature Request description: File a feature request -title: "[Feature Request]: " +title: "" labels: ["feature request"] body: - type: markdown -- cgit v0.10.2 From 516f9de3e4926149d0cdae0d6e320b4bbbd072e2 Mon Sep 17 00:00:00 2001 From: coxtor Date: Fri, 8 Oct 2021 20:05:39 +0200 Subject: Add configuration instructions for Ubuntu devcontainers diff --git a/doc/buildWithVScode.md b/doc/buildWithVScode.md index c1df17b..23c9714 100644 --- a/doc/buildWithVScode.md +++ b/doc/buildWithVScode.md @@ -36,7 +36,17 @@ Using the [Remote-Containers](https://marketplace.visualstudio.com/items?itemNam More documentation is available in the [readme in .devcontainer](.devcontainer/readme.md) - +### DevContainer on Ubuntu +To use the DevContainer configuration on Ubuntu based systems two changes need to be made: + +1. Modify the file ``.devcontainer/devcontainer.json`` and add the argument ``"--net=host"`` to the ``"runArgs"`` parameter making the line look like this: +`` "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", "--net=host"], +`` +2. Modify the file ``.vscode/launch.json`` and change the argument of ``"gdbTarget"`` to ``"127.0.0.1:3333"``, making the line look like: +``"gdbTarget": "127.0.0.1:3333",`` +3. To start debugging launch openocd on your host system with the appropriate configuration, for example with a stlink-v2 the command is: +``openocd -f interface/stlink.cfg -f target/nrf52.cfg``. This launches openocd with the default ports ``3333``, ``4444`` and ``6666``. +4. In VsCode go to the Debug pane on the left of the screen and select the configuration ``Debug - Openocd docker Remote`` and hit the play button on the left. -- cgit v0.10.2 From 1777b9dee8f1189df29f627707b970995f0d4afe Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 9 Oct 2021 13:39:27 +0300 Subject: Don't measure and notify percentage on charging event. diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp index 0ef4ff1..e807f03 100644 --- a/src/components/battery/BatteryController.cpp +++ b/src/components/battery/BatteryController.cpp @@ -13,7 +13,7 @@ Battery::Battery() { nrf_gpio_cfg_input(PinMap::Charging, static_cast GPIO_PIN_CNF_PULL_Disabled); } -void Battery::Update() { +void Battery::ReadPowerState() { isCharging = !nrf_gpio_pin_read(PinMap::Charging); isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent); @@ -22,6 +22,10 @@ void Battery::Update() { } else if (!isPowerPresent) { isFull = false; } +} + +void Battery::MeasureVoltage() { + ReadPowerState(); if (isReading) { return; diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h index 55c2630..5a7394c 100644 --- a/src/components/battery/BatteryController.h +++ b/src/components/battery/BatteryController.h @@ -10,7 +10,8 @@ namespace Pinetime { public: Battery(); - void Update(); + void ReadPowerState(); + void MeasureVoltage(); void Register(System::SystemTask* systemTask); uint8_t PercentRemaining() const { diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 0a53101..ec8b5e4 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -136,7 +136,6 @@ void SystemTask::Work() { touchPanel.Init(); dateTimeController.Register(this); batteryController.Register(this); - batteryController.Update(); motorController.Init(); motionSensor.SoftReset(); timerController.Register(this); @@ -194,6 +193,8 @@ void SystemTask::Work() { nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH); } + batteryController.MeasureVoltage(); + idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback); dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback); measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback); @@ -345,11 +346,11 @@ void SystemTask::Work() { stepCounterMustBeReset = true; break; case Messages::OnChargingEvent: - batteryController.Update(); + batteryController.ReadPowerState(); motorController.RunForDuration(15); break; case Messages::MeasureBatteryTimerExpired: - batteryController.Update(); + batteryController.MeasureVoltage(); break; case Messages::BatteryPercentageUpdated: nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); -- cgit v0.10.2 From 977faebcb8b26212e0868b30e1af5c38076ff6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sat, 9 Oct 2021 21:17:59 +0200 Subject: Remove call to `batteryController.Update();` which was replaced by `batteryController.MeasureVoltage()`. diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 8674053..1238829 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -191,9 +191,6 @@ void SystemTask::Work() { nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler); nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true); - // Update controller based on current gpio pin state, needs to be called after gpio config - batteryController.Update(); - batteryController.MeasureVoltage(); idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback); -- cgit v0.10.2 From 7cbd56896aebcebaacae864403b91473986782a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 10 Oct 2021 16:08:19 +0200 Subject: DateTimeController : remove unused methods and variables. diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 26b69a2..e9c5d87 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -5,6 +5,12 @@ using namespace Pinetime::Controllers; +namespace { + char const* DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; + char const* MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; + char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; +} + void DateTime::SetCurrentTime(std::chrono::time_point t) { this->currentDateTime = t; UpdateTime(previousSystickCounter); // Update internal state without updating the time @@ -80,76 +86,18 @@ void DateTime::UpdateTime(uint32_t systickCounter) { } const char* DateTime::MonthShortToString() { - return DateTime::MonthsString[static_cast(month)]; -} - -const char* DateTime::MonthShortToStringLow() { - return DateTime::MonthsStringLow[static_cast(month)]; -} - -const char* DateTime::MonthsToStringLow() { - return DateTime::MonthsLow[static_cast(month)]; -} - -const char* DateTime::DayOfWeekToString() { - return DateTime::DaysString[static_cast(dayOfWeek)]; + return MonthsString[static_cast(month)]; } const char* DateTime::DayOfWeekShortToString() { - return DateTime::DaysStringShort[static_cast(dayOfWeek)]; -} - -const char* DateTime::DayOfWeekToStringLow() { - return DateTime::DaysStringLow[static_cast(dayOfWeek)]; -} - -const char* DateTime::DayOfWeekShortToStringLow() { - return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; -} - -const char* DateTime::MonthShortToString(Months month) { - return DateTime::MonthsString[static_cast(month)]; + return DaysStringShort[static_cast(dayOfWeek)]; } const char* DateTime::MonthShortToStringLow(Months month) { - return DateTime::MonthsStringLow[static_cast(month)]; -} - -const char* DateTime::MonthsToStringLow(Months month) { - return DateTime::MonthsLow[static_cast(month)]; -} - -const char* DateTime::DayOfWeekToString(Days dayOfWeek) { - return DateTime::DaysString[static_cast(dayOfWeek)]; -} - -const char* DateTime::DayOfWeekShortToString(Days dayOfWeek) { - return DateTime::DaysStringShort[static_cast(dayOfWeek)]; -} - -const char* DateTime::DayOfWeekToStringLow(Days dayOfWeek) { - return DateTime::DaysStringLow[static_cast(dayOfWeek)]; -} - -const char* DateTime::DayOfWeekShortToStringLow(Days dayOfWeek) { - return DateTime::DaysStringShortLow[static_cast(dayOfWeek)]; + return MonthsStringLow[static_cast(month)]; } void DateTime::Register(Pinetime::System::SystemTask* systemTask) { this->systemTask = systemTask; } -char const* DateTime::DaysStringLow[] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; - -char const* DateTime::DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; - -char const* DateTime::DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; - -char const* DateTime::DaysString[] = {"--", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"}; - -char const* DateTime::MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; - -char const* DateTime::MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - -char const* DateTime::MonthsLow[] = { - "--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h index c5f218d..77ed68e 100644 --- a/src/components/datetime/DateTimeController.h +++ b/src/components/datetime/DateTimeController.h @@ -59,20 +59,8 @@ namespace Pinetime { } const char* MonthShortToString(); - const char* MonthShortToStringLow(); - const char* MonthsToStringLow(); - const char* DayOfWeekToString(); const char* DayOfWeekShortToString(); - const char* DayOfWeekToStringLow(); - const char* DayOfWeekShortToStringLow(); - - static const char* MonthShortToString(Months month); static const char* MonthShortToStringLow(Months month); - static const char* MonthsToStringLow(Months month); - static const char* DayOfWeekToString(Days dayOfWeek); - static const char* DayOfWeekShortToString(Days dayOfWeek); - static const char* DayOfWeekToStringLow(Days dayOfWeek); - static const char* DayOfWeekShortToStringLow(Days dayOfWeek); std::chrono::time_point CurrentDateTime() const { return currentDateTime; @@ -99,14 +87,6 @@ namespace Pinetime { bool isMidnightAlreadyNotified = false; System::SystemTask* systemTask = nullptr; - - static char const* DaysString[]; - static char const* DaysStringShort[]; - static char const* DaysStringLow[]; - static char const* DaysStringShortLow[]; - static char const* MonthsString[]; - static char const* MonthsStringLow[]; - static char const* MonthsLow[]; }; } } -- cgit v0.10.2 From f2357b36e5142f3f143f466cac62aafcf7261d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 10 Oct 2021 16:18:14 +0200 Subject: Setting SetDate/SetTime : replace #defines by constexpr variables, NULL by nullptr and other small cleanings. diff --git a/src/displayapp/screens/settings/SettingSetDate.cpp b/src/displayapp/screens/settings/SettingSetDate.cpp index 705b7a9..ba3413e 100644 --- a/src/displayapp/screens/settings/SettingSetDate.cpp +++ b/src/displayapp/screens/settings/SettingSetDate.cpp @@ -5,33 +5,31 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" -#define POS_X_DAY -72 -#define POS_X_MONTH 0 -#define POS_X_YEAR 72 -#define POS_Y_PLUS -50 -#define POS_Y_TEXT -6 -#define POS_Y_MINUS 40 - using namespace Pinetime::Applications::Screens; namespace { - static void event_handler(lv_obj_t * obj, lv_event_t event) { - SettingSetDate* screen = static_cast(obj->user_data); + constexpr int16_t POS_X_DAY = -72; + constexpr int16_t POS_X_MONTH = 0; + constexpr int16_t POS_X_YEAR = 72; + constexpr int16_t POS_Y_PLUS = -50; + constexpr int16_t POS_Y_TEXT = -6; + constexpr int16_t POS_Y_MINUS = 40; + + void event_handler(lv_obj_t * obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); screen->HandleButtonPress(obj, event); } } -SettingSetDate::SettingSetDate( - Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : +SettingSetDate::SettingSetDate(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : Screen(app), - dateTimeController {dateTimeController} -{ - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + dateTimeController {dateTimeController} { + lv_obj_t * title = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(title, "Set current date"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); - lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * icon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); lv_label_set_text_static(icon, Symbols::clock); @@ -39,14 +37,14 @@ SettingSetDate::SettingSetDate( lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); dayValue = static_cast(dateTimeController.Day()); - lblDay = lv_label_create(lv_scr_act(), NULL); + lblDay = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_label_set_align(lblDay, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT); lv_obj_set_auto_realign(lblDay, true); monthValue = static_cast(dateTimeController.Month()); - lblMonth = lv_label_create(lv_scr_act(), NULL); + lblMonth = lv_label_create(lv_scr_act(), nullptr); UpdateMonthLabel(); lv_label_set_align(lblMonth, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMonth, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_TEXT); @@ -55,55 +53,55 @@ SettingSetDate::SettingSetDate( yearValue = static_cast(dateTimeController.Year()); if (yearValue < 2021) yearValue = 2021; - lblYear = lv_label_create(lv_scr_act(), NULL); + lblYear = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_label_set_align(lblYear, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT); lv_obj_set_auto_realign(lblYear, true); - btnDayPlus = lv_btn_create(lv_scr_act(), NULL); + btnDayPlus = lv_btn_create(lv_scr_act(), nullptr); btnDayPlus->user_data = this; lv_obj_set_size(btnDayPlus, 50, 40); lv_obj_align(btnDayPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_PLUS); lv_obj_set_style_local_value_str(btnDayPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnDayPlus, event_handler); - btnDayMinus = lv_btn_create(lv_scr_act(), NULL); + btnDayMinus = lv_btn_create(lv_scr_act(), nullptr); btnDayMinus->user_data = this; lv_obj_set_size(btnDayMinus, 50, 40); lv_obj_align(btnDayMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_MINUS); lv_obj_set_style_local_value_str(btnDayMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnDayMinus, event_handler); - btnMonthPlus = lv_btn_create(lv_scr_act(), NULL); + btnMonthPlus = lv_btn_create(lv_scr_act(), nullptr); btnMonthPlus->user_data = this; lv_obj_set_size(btnMonthPlus, 50, 40); lv_obj_align(btnMonthPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_PLUS); lv_obj_set_style_local_value_str(btnMonthPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnMonthPlus, event_handler); - btnMonthMinus = lv_btn_create(lv_scr_act(), NULL); + btnMonthMinus = lv_btn_create(lv_scr_act(), nullptr); btnMonthMinus->user_data = this; lv_obj_set_size(btnMonthMinus, 50, 40); lv_obj_align(btnMonthMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MONTH, POS_Y_MINUS); lv_obj_set_style_local_value_str(btnMonthMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnMonthMinus, event_handler); - btnYearPlus = lv_btn_create(lv_scr_act(), NULL); + btnYearPlus = lv_btn_create(lv_scr_act(), nullptr); btnYearPlus->user_data = this; lv_obj_set_size(btnYearPlus, 50, 40); lv_obj_align(btnYearPlus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_PLUS); lv_obj_set_style_local_value_str(btnYearPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnYearPlus, event_handler); - btnYearMinus = lv_btn_create(lv_scr_act(), NULL); + btnYearMinus = lv_btn_create(lv_scr_act(), nullptr); btnYearMinus->user_data = this; lv_obj_set_size(btnYearMinus, 50, 40); lv_obj_align(btnYearMinus, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_MINUS); lv_obj_set_style_local_value_str(btnYearMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnYearMinus, event_handler); - btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime = lv_btn_create(lv_scr_act(), nullptr); btnSetTime->user_data = this; lv_obj_set_size(btnSetTime, 120, 48); lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); @@ -116,7 +114,6 @@ SettingSetDate::~SettingSetDate() { } void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if (event != LV_EVENT_CLICKED) return; @@ -126,43 +123,37 @@ void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) { dayValue = 1; lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnDayMinus) { + } else if (object == btnDayMinus) { dayValue--; if (dayValue < 1) dayValue = MaximumDayOfMonth(); lv_label_set_text_fmt(lblDay, "%d", dayValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnMonthPlus) { + } else if (object == btnMonthPlus) { monthValue++; if (monthValue > 12) monthValue = 1; UpdateMonthLabel(); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); - } - else if (object == btnMonthMinus) { + } else if (object == btnMonthMinus) { monthValue--; if (monthValue < 1) monthValue = 12; UpdateMonthLabel(); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); - } - else if (object == btnYearPlus) { + } else if (object == btnYearPlus) { yearValue++; lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); - } - else if (object == btnYearMinus) { + } else if (object == btnYearMinus) { yearValue--; lv_label_set_text_fmt(lblYear, "%d", yearValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); CheckDay(); - } - else if (object == btnSetTime) { + } else if (object == btnSetTime) { NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue); dateTimeController.SetTime(static_cast(yearValue), static_cast(monthValue), @@ -202,7 +193,6 @@ void SettingSetDate::CheckDay() { } void SettingSetDate::UpdateMonthLabel() { - lv_label_set_text_static(lblMonth, - Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); + lv_label_set_text_static( + lblMonth, Pinetime::Controllers::DateTime::MonthShortToStringLow(static_cast(monthValue))); } - diff --git a/src/displayapp/screens/settings/SettingSetDate.h b/src/displayapp/screens/settings/SettingSetDate.h index 0f6317d..477337f 100644 --- a/src/displayapp/screens/settings/SettingSetDate.h +++ b/src/displayapp/screens/settings/SettingSetDate.h @@ -6,10 +6,8 @@ #include "displayapp/screens/Screen.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingSetDate : public Screen{ public: SettingSetDate(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController); @@ -17,8 +15,7 @@ namespace Pinetime { void HandleButtonPress(lv_obj_t *object, lv_event_t event); - private: - + private: Controllers::DateTime& dateTimeController; int dayValue; diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index 7083b80..194bf5e 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -5,34 +5,32 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" -#define POS_X_HOURS -72 -#define POS_X_MINUTES 0 -#define POS_X_SECONDS 72 -#define POS_Y_PLUS -50 -#define POS_Y_TEXT -6 -#define POS_Y_MINUS 40 -#define OFS_Y_COLON -2 - using namespace Pinetime::Applications::Screens; namespace { - static void event_handler(lv_obj_t * obj, lv_event_t event) { - SettingSetTime* screen = static_cast(obj->user_data); + constexpr int16_t POS_X_HOURS = -72; + constexpr int16_t POS_X_MINUTES = 0; + constexpr int16_t POS_X_SECONDS = 72; + constexpr int16_t POS_Y_PLUS = -50; + constexpr int16_t POS_Y_TEXT = -6; + constexpr int16_t POS_Y_MINUS = 40; + constexpr int16_t OFS_Y_COLON = -2; + + void event_handler(lv_obj_t * obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); screen->HandleButtonPress(obj, event); } } -SettingSetTime::SettingSetTime( - Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : +SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) : Screen(app), - dateTimeController {dateTimeController} -{ - lv_obj_t * title = lv_label_create(lv_scr_act(), NULL); + dateTimeController {dateTimeController} { + lv_obj_t * title = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(title, "Set current time"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); - lv_obj_t * icon = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * icon = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); lv_label_set_text_static(icon, Symbols::clock); @@ -40,68 +38,68 @@ SettingSetTime::SettingSetTime( lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); hoursValue = static_cast(dateTimeController.Hours()); - lblHours = lv_label_create(lv_scr_act(), NULL); + lblHours = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblHours, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_align(lblHours, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT); lv_obj_set_auto_realign(lblHours, true); - lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon1, ":"); lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblColon1, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_HOURS + POS_X_MINUTES) / 2, POS_Y_TEXT + OFS_Y_COLON); minutesValue = static_cast(dateTimeController.Minutes()); - lblMinutes = lv_label_create(lv_scr_act(), NULL); + lblMinutes = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblMinutes, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_label_set_align(lblMinutes, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT); lv_obj_set_auto_realign(lblMinutes, true); - lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblColon2, ":"); lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_MINUTES + POS_X_SECONDS) / 2, POS_Y_TEXT + OFS_Y_COLON); - lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), NULL); + lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); lv_label_set_text_static(lblSeconds, "00"); lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER); lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT); - btnHoursPlus = lv_btn_create(lv_scr_act(), NULL); + btnHoursPlus = lv_btn_create(lv_scr_act(), nullptr); btnHoursPlus->user_data = this; lv_obj_set_size(btnHoursPlus, 50, 40); lv_obj_align(btnHoursPlus, lv_scr_act(), LV_ALIGN_CENTER, -72, -50); lv_obj_set_style_local_value_str(btnHoursPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnHoursPlus, event_handler); - btnHoursMinus = lv_btn_create(lv_scr_act(), NULL); + btnHoursMinus = lv_btn_create(lv_scr_act(), nullptr); btnHoursMinus->user_data = this; lv_obj_set_size(btnHoursMinus, 50, 40); lv_obj_align(btnHoursMinus, lv_scr_act(), LV_ALIGN_CENTER, -72, 40); lv_obj_set_style_local_value_str(btnHoursMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnHoursMinus, event_handler); - btnMinutesPlus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesPlus = lv_btn_create(lv_scr_act(), nullptr); btnMinutesPlus->user_data = this; lv_obj_set_size(btnMinutesPlus, 50, 40); lv_obj_align(btnMinutesPlus, lv_scr_act(), LV_ALIGN_CENTER, 0, -50); lv_obj_set_style_local_value_str(btnMinutesPlus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "+"); lv_obj_set_event_cb(btnMinutesPlus, event_handler); - btnMinutesMinus = lv_btn_create(lv_scr_act(), NULL); + btnMinutesMinus = lv_btn_create(lv_scr_act(), nullptr); btnMinutesMinus->user_data = this; lv_obj_set_size(btnMinutesMinus, 50, 40); lv_obj_align(btnMinutesMinus, lv_scr_act(), LV_ALIGN_CENTER, 0, 40); lv_obj_set_style_local_value_str(btnMinutesMinus, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "-"); lv_obj_set_event_cb(btnMinutesMinus, event_handler); - btnSetTime = lv_btn_create(lv_scr_act(), NULL); + btnSetTime = lv_btn_create(lv_scr_act(), nullptr); btnSetTime->user_data = this; lv_obj_set_size(btnSetTime, 120, 48); lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); @@ -114,7 +112,6 @@ SettingSetTime::~SettingSetTime() { } void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { - if (event != LV_EVENT_CLICKED) return; @@ -124,29 +121,25 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { hoursValue = 0; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnHoursMinus) { + } else if (object == btnHoursMinus) { hoursValue--; if (hoursValue < 0) hoursValue = 23; lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnMinutesPlus) { + } else if (object == btnMinutesPlus) { minutesValue++; if (minutesValue > 59) minutesValue = 0; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnMinutesMinus) { + } else if (object == btnMinutesMinus) { minutesValue--; if (minutesValue < 0) minutesValue = 59; lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); - } - else if (object == btnSetTime) { + } else if (object == btnSetTime) { NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue); dateTimeController.SetTime(dateTimeController.Year(), static_cast(dateTimeController.Month()), diff --git a/src/displayapp/screens/settings/SettingSetTime.h b/src/displayapp/screens/settings/SettingSetTime.h index 63fb7d3..8ba41ea 100644 --- a/src/displayapp/screens/settings/SettingSetTime.h +++ b/src/displayapp/screens/settings/SettingSetTime.h @@ -6,10 +6,8 @@ #include "displayapp/screens/Screen.h" namespace Pinetime { - namespace Applications { namespace Screens { - class SettingSetTime : public Screen{ public: SettingSetTime(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController); @@ -17,8 +15,7 @@ namespace Pinetime { void HandleButtonPress(lv_obj_t *object, lv_event_t event); - private: - + private: Controllers::DateTime& dateTimeController; int hoursValue; @@ -30,7 +27,6 @@ namespace Pinetime { lv_obj_t * btnMinutesPlus; lv_obj_t * btnMinutesMinus; lv_obj_t * btnSetTime; - }; } } -- cgit v0.10.2 From 55ff9b0c81ff32caaa18069a26057ad18589d022 Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Fri, 10 Sep 2021 19:39:58 +0200 Subject: Add python packages click and cryptography to build instructions The script `tools/mcuboot/imgtool/main.py` imports the python packages `click` and `cryptography` to create the target `pinetime-mcuboot-app`. Add it tothe build instructions, as it was not installed on my system. https://github.com/JF002/InfiniTime/blob/6f9f0e8b0e42a5526d47ca664534fb6b0ccb6ace/tools/mcuboot/imgtool/main.py#L19 https://github.com/JF002/InfiniTime/blob/6f9f0e8b0e42a5526d47ca664534fb6b0ccb6ace/tools/mcuboot/imgtool/keys/__init__.py#L19 Also add the commands to install the python requirements into a python venv virtual environment. diff --git a/doc/buildAndProgram.md b/doc/buildAndProgram.md index e97bb30..5b22014 100644 --- a/doc/buildAndProgram.md +++ b/doc/buildAndProgram.md @@ -3,7 +3,14 @@ To build this project, you'll need: - A cross-compiler : [ARM-GCC (9-2020-q2-update)](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads/9-2020-q2-update) - The NRF52 SDK 15.3.0 : [nRF-SDK v15.3.0](https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/nRF5_SDK_15.3.0_59ac345.zip) - - The `cbor` and `intelhex` modules for Python 3 + - The Python 3 modules `cbor`, `intelhex`, `click` and `cryptography` modules for the `mcuboot` tool (see [requirements.txt](../tools/mcuboot/requirements.txt)) + - To to keep the system clean a python virtual environment (`venv`) can be used to install the python modules into + ```sh + python -m venv .venv + source .venv/bin/activate + python -m pip install wheel + python -m pip install -r tools/mcuboot/requirements.txt + ``` - A reasonably recent version of CMake (I use 3.16.5) ## Build steps -- cgit v0.10.2 From 7cd4929bfdb7f82778af8c3f6fed5fb107f1152b Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Thu, 9 Sep 2021 22:50:43 +0200 Subject: Paddle: compare ballX coordinate with horizontal resolution Fix the comment as the comparison checks if the ball is at the right side of the screen. Compare the x coordinate of the ball with the horizontal resolution of the screen, instead of the vertical resolution. On the PinePhone this does make no difference as we have square 240x240 screen. Change it anyways to be completely correct. diff --git a/src/displayapp/screens/Paddle.cpp b/src/displayapp/screens/Paddle.cpp index 3b6d60e..26c2368 100644 --- a/src/displayapp/screens/Paddle.cpp +++ b/src/displayapp/screens/Paddle.cpp @@ -47,8 +47,8 @@ void Paddle::Refresh() { dy *= -1; } - // checks if it has touched the side (left side) - if (ballX >= LV_VER_RES - ballSize - 1) { + // checks if it has touched the side (right side) + if (ballX >= LV_HOR_RES - ballSize - 1) { dx *= -1; } -- cgit v0.10.2 From fd4fbfddb9508ea6ed9073523edd3a5f29e8195a Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 13 Oct 2021 13:04:40 +0300 Subject: Flashlight brightness control diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index e763cda..20a6708 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -390,7 +390,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) break; case Apps::FlashLight: currentScreen = std::make_unique(this, *systemTask, brightnessController); - ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None); + ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::StopWatch: currentScreen = std::make_unique(this, *systemTask); diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 4bc5b55..dcb31a7 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -5,30 +5,41 @@ using namespace Pinetime::Applications::Screens; namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { - FlashLight* screen = static_cast(obj->user_data); + void event_handler(lv_obj_t* obj, lv_event_t event) { + auto* screen = static_cast(obj->user_data); screen->OnClickEvent(obj, event); } } FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, System::SystemTask& systemTask, - Controllers::BrightnessController& brightness) + Controllers::BrightnessController& brightnessController) : Screen(app), systemTask {systemTask}, - brightness {brightness} + brightnessController {brightnessController} { - brightness.Backup(); - brightness.Set(Controllers::BrightnessController::Levels::High); - // Set the background - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + brightnessController.Backup(); - flashLight = lv_label_create(lv_scr_act(), NULL); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + brightnessLevel = brightnessController.Level(); + + flashLight = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); lv_label_set_text_static(flashLight, Symbols::highlight); - lv_obj_align(flashLight, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_align(flashLight, nullptr, LV_ALIGN_CENTER, 0, 0); + + for (auto & i : indicators) { + i = lv_obj_create(lv_scr_act(), nullptr); + lv_obj_set_size(i, 15, 10); + lv_obj_set_style_local_border_width(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 2); + } + + lv_obj_align(indicators[1], flashLight, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); + lv_obj_align(indicators[0], indicators[1], LV_ALIGN_OUT_LEFT_MID, -8, 0); + lv_obj_align(indicators[2], indicators[1], LV_ALIGN_OUT_RIGHT_MID, 8, 0); + + SetIndicators(); + SetColors(); backgroundAction = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundAction, LV_LABEL_LONG_CROP); @@ -44,27 +55,80 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, FlashLight::~FlashLight() { lv_obj_clean(lv_scr_act()); - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - brightness.Restore(); + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + brightnessController.Restore(); systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); } -void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { - if (obj == backgroundAction) { - if (event == LV_EVENT_CLICKED) { - isOn = !isOn; - - if (isOn) { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - } else { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); - } +void FlashLight::SetColors() { + if (isOn) { + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + for (auto & i : indicators) { + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_WHITE); + lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); } + } else { + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + for (auto & i : indicators) { + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_BLACK); + lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + } + } +} + +void FlashLight::SetIndicators() { + using namespace Pinetime::Controllers; + + if (brightnessLevel == BrightnessController::Levels::High) { + lv_obj_set_state(indicators[1], LV_STATE_DEFAULT); + lv_obj_set_state(indicators[2], LV_STATE_DEFAULT); + } else if (brightnessLevel == BrightnessController::Levels::Medium) { + lv_obj_set_state(indicators[1], LV_STATE_DEFAULT); + lv_obj_set_state(indicators[2], LV_STATE_DISABLED); + } else { + lv_obj_set_state(indicators[1], LV_STATE_DISABLED); + lv_obj_set_state(indicators[2], LV_STATE_DISABLED); + } +} + +void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { + if (obj == backgroundAction && event == LV_EVENT_CLICKED) { + isOn = !isOn; + SetColors(); } } bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + using namespace Pinetime::Controllers; + + if (event == TouchEvents::SwipeLeft) { + if (brightnessLevel == BrightnessController::Levels::High) { + brightnessLevel = BrightnessController::Levels::Medium; + brightnessController.Set(brightnessLevel); + SetIndicators(); + } else if (brightnessLevel == BrightnessController::Levels::Medium) { + brightnessLevel = BrightnessController::Levels::Low; + brightnessController.Set(brightnessLevel); + SetIndicators(); + } + return true; + } + if (event == TouchEvents::SwipeRight) { + if (brightnessLevel == BrightnessController::Levels::Low) { + brightnessLevel = BrightnessController::Levels::Medium; + brightnessController.Set(brightnessLevel); + SetIndicators(); + } else if (brightnessLevel == BrightnessController::Levels::Medium) { + brightnessLevel = BrightnessController::Levels::High; + brightnessController.Set(brightnessLevel); + SetIndicators(); + } + return true; + } + return false; } diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 7f5ca6c..f2c65bb 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -1,10 +1,10 @@ #pragma once -#include #include "Screen.h" -#include -#include "systemtask/SystemTask.h" #include "components/brightness/BrightnessController.h" +#include "systemtask/SystemTask.h" +#include +#include namespace Pinetime { @@ -20,12 +20,18 @@ namespace Pinetime { void OnClickEvent(lv_obj_t* obj, lv_event_t event); private: + void SetIndicators(); + void SetColors(); + Pinetime::System::SystemTask& systemTask; - Controllers::BrightnessController& brightness; + Controllers::BrightnessController& brightnessController; + + Controllers::BrightnessController::Levels brightnessLevel; lv_obj_t* flashLight; lv_obj_t* backgroundAction; - bool isOn = true; + lv_obj_t* indicators[3]; + bool isOn = false; }; } } diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index 691c40c..dd62607 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -131,7 +131,7 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { if (object == btn2 && event == LV_EVENT_CLICKED) { running = false; - app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::None); + app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up); } else if (object == btn1 && event == LV_EVENT_CLICKED) { -- cgit v0.10.2 From 59ce48a3f3d01288eedf1d0f7e39fc6fabe7984e Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Tue, 7 Sep 2021 20:38:48 +0100 Subject: Make new notifications refresh idle timer diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index f79fd8e..f1c5165 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -250,12 +250,13 @@ void SystemTask::Work() { isDimmed = false; break; case Messages::TouchWakeUp: { - if(touchHandler.GetNewTouchInfo()) { + if (touchHandler.GetNewTouchInfo()) { auto gesture = touchHandler.GestureGet(); - if (gesture != Pinetime::Drivers::Cst816S::Gestures::None and ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and - settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or - (gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and - settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) { + if (gesture != Pinetime::Drivers::Cst816S::Gestures::None and + ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and + settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or + (gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and + settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) { GoToRunning(); } } @@ -276,6 +277,8 @@ void SystemTask::Work() { if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) { if (isSleeping && !isWakingUp) { GoToRunning(); + } else { + ReloadIdleTimer(); } displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification); } -- cgit v0.10.2 From 4a59e544ba7a2ccd051604acece0f03c5e5222e7 Mon Sep 17 00:00:00 2001 From: Quantum-cross <7065792+Quantum-cross@users.noreply.github.com> Date: Mon, 11 Oct 2021 17:12:36 -0400 Subject: fix building of Recovery image. diff --git a/src/displayapp/DisplayAppRecovery.h b/src/displayapp/DisplayAppRecovery.h index 425e0ac..9f5fb13 100644 --- a/src/displayapp/DisplayAppRecovery.h +++ b/src/displayapp/DisplayAppRecovery.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "TouchEvents.h" #include "Apps.h" #include "Messages.h" @@ -58,6 +59,7 @@ namespace Pinetime { Pinetime::Controllers::AlarmController& alarmController, Pinetime::Controllers::TouchHandler& touchHandler); void Start(); + void Start(Pinetime::System::BootErrors){ Start(); }; void PushMessage(Pinetime::Applications::Display::Messages msg); void Register(Pinetime::System::SystemTask* systemTask); -- cgit v0.10.2 From 1d76d9170e367b4d1f97f9a5e43bd6801724dfd3 Mon Sep 17 00:00:00 2001 From: mabuch Date: Fri, 15 Oct 2021 18:03:10 +0200 Subject: Replaced "JF002" in github URLs with "InfiniTimeOrg" diff --git a/README.md b/README.md index ee1fad0..6719aa3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # InfiniTime -[![Build PineTime Firmware](https://github.com/JF002/InfiniTime/workflows/Build%20PineTime%20Firmware/badge.svg?branch=master)](https://github.com/JF002/InfiniTime/actions) +[![Build PineTime Firmware](https://github.com/InfiniTimeOrg/InfiniTime/workflows/Build%20PineTime%20Firmware/badge.svg?branch=master)](https://github.com/InfiniTimeOrg/InfiniTime/actions) ![InfiniTime logo](images/infinitime-logo.jpg "InfiniTime Logo") diff --git a/doc/MemoryAnalysis.md b/doc/MemoryAnalysis.md index 3251c98..7304e3f 100644 --- a/doc/MemoryAnalysis.md +++ b/doc/MemoryAnalysis.md @@ -6,7 +6,7 @@ The PineTime is equipped with the following memories: Note that the NRF52832 cannot execute code stored in the external flash : we need to store the whole firmware in the internal flash memory, and use the external one to store graphicals assets, fonts... -This document describes how the RAM and Flash memories are used in InfiniTime and how to analyze and monitor their usage. It was written in the context of [this memory analysis effort](https://github.com/JF002/InfiniTime/issues/313). +This document describes how the RAM and Flash memories are used in InfiniTime and how to analyze and monitor their usage. It was written in the context of [this memory analysis effort](https://github.com/InfiniTimeOrg/InfiniTime/issues/313). ## Code sections A binary is composed of multiple sections. Most of the time, these sections are : .text, .rodata, .data and .bss but more sections can be defined in the linker script. @@ -38,7 +38,7 @@ In this analysis, I used [Linkermapviz](https://github.com/PromyLOPh/linkermapvi Using this tool, you can easily see the size of each symbol relative to the other one, and check what is using most of the space,... -Also, as Linkermapviz is written in Python, you can easily modify it to adapt it to your firmware, export data in another format,... For example, [I modified it to parse the contents of the MAP file and export it in a CSV file](https://github.com/JF002/InfiniTime/issues/313#issuecomment-842338620). I could later on open this file in LibreOffice Calc and use sort/filter functionality to search for specific symbols in specific files... +Also, as Linkermapviz is written in Python, you can easily modify it to adapt it to your firmware, export data in another format,... For example, [I modified it to parse the contents of the MAP file and export it in a CSV file](https://github.com/InfiniTimeOrg/InfiniTime/issues/313#issuecomment-842338620). I could later on open this file in LibreOffice Calc and use sort/filter functionality to search for specific symbols in specific files... ### Puncover [Puncover](https://github.com/HBehrens/puncover) is another useful tools that analyses the binary file generated by the compiler (the .out file that contains all debug information). It provides valuable information about the symbols (data and code): name, position, size, max stack of each functions, callers, callees... @@ -69,8 +69,8 @@ This way, you can easily check what needs to be optimized : we should find a way It's always a good idea to check the flash memory space when working on the project : this way, you can easily check that your developments are using a reasonable amount of space. ### Links - - Analysis with linkermapviz : https://github.com/JF002/InfiniTime/issues/313#issuecomment-842338620 - - Analysis with Puncover : https://github.com/JF002/InfiniTime/issues/313#issuecomment-847311392 + - Analysis with linkermapviz : https://github.com/InfiniTimeOrg/InfiniTime/issues/313#issuecomment-842338620 + - Analysis with Puncover : https://github.com/InfiniTimeOrg/InfiniTime/issues/313#issuecomment-847311392 ## RAM RAM memory contains all the data that can be modified at run-time: variables, stack, heap... @@ -93,7 +93,7 @@ int main() { In Infinitime 1.1, the biggest buffers are the buffers allocated for LVGL (14KB) and the one for FreeRTOS (16KB). Nimble also allocated 9KB of RAM. ### Stack -The stack will be used for everything except tasks, which have their own stack allocated by FreeRTOS. The stack is 8192B and is allocated in the [linker script](https://github.com/JF002/InfiniTime/blob/develop/nrf_common.ld#L148). +The stack will be used for everything except tasks, which have their own stack allocated by FreeRTOS. The stack is 8192B and is allocated in the [linker script](https://github.com/InfiniTimeOrg/InfiniTime/blob/develop/nrf_common.ld#L148). An easy way to monitor its usage is by filling the section with a known pattern at boot time, then use the firmware and dump the memory. You can then check the maximum stack usage by checking the address from the beginning of the stack that were overwritten. #### Fill the stack section by a known pattern: @@ -197,10 +197,10 @@ On the following dump, the maximum stack usage is 520 bytes (0xFFFF - 0xFDF8): According to my experimentations, we don't use the stack that much, and 8192 bytes is probably way too big for InfiniTime! #### Links - - https://github.com/JF002/InfiniTime/issues/313#issuecomment-851035070 + - https://github.com/InfiniTimeOrg/InfiniTime/issues/313#issuecomment-851035070 ### Heap -The heap is declared in the [linker script](https://github.com/JF002/InfiniTime/blob/develop/nrf_common.ld#L136) and its current size is 8192 bytes. The heap is used for dynamic memory allocation(`malloc()`, `new`...). +The heap is declared in the [linker script](https://github.com/InfiniTimeOrg/InfiniTime/blob/develop/nrf_common.ld#L136) and its current size is 8192 bytes. The heap is used for dynamic memory allocation(`malloc()`, `new`...). Heap monitoring is not easy, but it seems that we can use the following code to know the current usage of the heap: @@ -239,7 +239,7 @@ Using this technique, I was able to trace all malloc calls at boot (boot -> digi - hr task = 304 #### Links - - https://github.com/JF002/InfiniTime/issues/313#issuecomment-851035625 + - https://github.com/InfiniTimeOrg/InfiniTime/issues/313#issuecomment-851035625 - https://www.embedded.com/mastering-stack-and-heap-for-system-reliability-part-1-calculating-stack-size/ - https://www.embedded.com/mastering-stack-and-heap-for-system-reliability-part-2-properly-allocating-stacks/ - https://www.embedded.com/mastering-stack-and-heap-for-system-reliability-part-3-avoiding-heap-errors/ @@ -263,7 +263,7 @@ For example a simple lv_label needs **~140 bytes** of memory. I tried to monitor this max value while going through all the apps of InfiniTime 1.1 : the max value I've seen is **5660 bytes**. It means that we could probably **reduce the size of the buffer from 14KB to 6 - 10 KB** (we have to take the fragmentation of the memory into account). ### Links - - https://github.com/JF002/InfiniTime/issues/313#issuecomment-850890064 + - https://github.com/InfiniTimeOrg/InfiniTime/issues/313#issuecomment-850890064 ## FreeRTOS heap and task stack diff --git a/doc/buildAndProgram.md b/doc/buildAndProgram.md index e97bb30..feae8d7 100644 --- a/doc/buildAndProgram.md +++ b/doc/buildAndProgram.md @@ -9,7 +9,7 @@ To build this project, you'll need: ## Build steps ### Clone the repo ``` -git clone https://github.com/JF002/InfiniTime.git +git clone https://github.com/InfiniTimeOrg/InfiniTime.git cd InfiniTime git submodule update --init mkdir build @@ -31,9 +31,9 @@ CMake configures the project according to variables you specify the command line **WATCH_COLMI_P8**|Use pin configuration for Colmi P8 watch|`-DWATCH_COLMI_P8=1` ####(**) Note about **CMAKE_BUILD_TYPE**: -By default, this variable is set to *Release*. It compiles the code with size and speed optimizations. We use this value for all the binaries we publish when we [release](https://github.com/JF002/InfiniTime/releases) new versions of InfiniTime. +By default, this variable is set to *Release*. It compiles the code with size and speed optimizations. We use this value for all the binaries we publish when we [release](https://github.com/InfiniTimeOrg/InfiniTime/releases) new versions of InfiniTime. -The *Debug* mode disables all optimizations, which makes the code easier to debug. However, the binary size will likely be too big to fit in the internal flash memory. If you want to build and debug a *Debug* binary, you'll need to disable some parts of the code. For example, the icons for the **Navigation** app use a lot of memory space. You can comment the content of `m_iconMap` in the [Navigation](https://github.com/JF002/InfiniTime/blob/develop/src/displayapp/screens/Navigation.h#L148) application to free some memory. +The *Debug* mode disables all optimizations, which makes the code easier to debug. However, the binary size will likely be too big to fit in the internal flash memory. If you want to build and debug a *Debug* binary, you'll need to disable some parts of the code. For example, the icons for the **Navigation** app use a lot of memory space. You can comment the content of `m_iconMap` in the [Navigation](https://github.com/InfiniTimeOrg/InfiniTime/blob/develop/src/displayapp/screens/Navigation.h#L148) application to free some memory. ####(**) Note about **BUILD_DFU**: DFU files are the files you'll need to install your build of InfiniTime using OTA (over-the-air) mecanism. To generate the DFU file, the Python tool [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil) is needed on your system. Check that this tool is properly installed before enabling this option. diff --git a/doc/contribute.md b/doc/contribute.md index b84d6c9..2174643 100644 --- a/doc/contribute.md +++ b/doc/contribute.md @@ -2,7 +2,7 @@ ## Report bugs -Have you found a bug in the firmware? [Create an issue on Github](https://github.com/JF002/InfiniTime/issues) explaining the bug, how to reproduce it, the version of the firmware you use... +Have you found a bug in the firmware? [Create an issue on Github](https://github.com/InfiniTimeOrg/InfiniTime/issues) explaining the bug, how to reproduce it, the version of the firmware you use... ## Write and improve documentation diff --git a/doc/filesInReleaseNotes.md b/doc/filesInReleaseNotes.md index 1a37fef..6a5873c 100644 --- a/doc/filesInReleaseNotes.md +++ b/doc/filesInReleaseNotes.md @@ -1,9 +1,9 @@ # Using the releases -For each new *stable* version of IniniTime, a [release note](https://github.com/JF002/InfiniTime/releases) is created. It contains a description of the main changes in the release and some files you can use to flash the firmware to your Pinetime. +For each new *stable* version of IniniTime, a [release note](https://github.com/InfiniTimeOrg/InfiniTime/releases) is created. It contains a description of the main changes in the release and some files you can use to flash the firmware to your Pinetime. This page describes the files from the release notes and how to use them. -**NOTE :** the files included in different Releases could be different. This page describes the release notes of [version 0.7.1](https://github.com/JF002/InfiniTime/releases/tag/0.7.1), which is the version that is pre-programmed for the last batches of pinetimes but will be replaced with [1.0.0](https://github.com/jF002/infiniTime/releases/tag/1.0.0) around june 2021. +**NOTE :** the files included in different Releases could be different. This page describes the release notes of [version 0.7.1](https://github.com/InfiniTimeOrg/InfiniTime/releases/tag/0.7.1), which is the version that is pre-programmed for the last batches of pinetimes but will be replaced with [1.0.0](https://github.com/jF002/infiniTime/releases/tag/1.0.0) around june 2021. ## Files included in the release notes diff --git a/doc/gettingStarted/gettingStarted-1.0.md b/doc/gettingStarted/gettingStarted-1.0.md index 88ff207..3f8f38f 100644 --- a/doc/gettingStarted/gettingStarted-1.0.md +++ b/doc/gettingStarted/gettingStarted-1.0.md @@ -8,15 +8,15 @@ You might have already seen these words by reading the announcement, release not Basically, a **firmware** is just a software running on the embedded hardware of a device, the PineTime in this case. **InfiniTime** is based on 3 distinct **firmwares**: - - **[InfiniTime](https://github.com/JF002/InfiniTime)** itself, this is the *application firmware* running on the PineTime. This is the main firmware which provides most of the functionalities you'll use on a daily basis : bluetooth low-energy (BLE) connectivity, applications, watchfaces,... + - **[InfiniTime](https://github.com/InfiniTimeOrg/InfiniTime)** itself, this is the *application firmware* running on the PineTime. This is the main firmware which provides most of the functionalities you'll use on a daily basis : bluetooth low-energy (BLE) connectivity, applications, watchfaces,... - **[The bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader)** is responsible for safely applying **updates** of the *application firmware*, reverting them in case of issues and load the recovery firmware when requested. - - **The recovery firmware** is a specific *application firmware* than can be loaded by the bootloader on user request. This firmware can be useful in case of serious issue, when the main application firmware cannot perform an OTA update correctly. Currently, this recovery firmware is based on [InfiniTime 0.14.1](https://github.com/JF002/InfiniTime/releases/tag/0.14.1). + - **The recovery firmware** is a specific *application firmware* than can be loaded by the bootloader on user request. This firmware can be useful in case of serious issue, when the main application firmware cannot perform an OTA update correctly. Currently, this recovery firmware is based on [InfiniTime 0.14.1](https://github.com/InfiniTimeOrg/InfiniTime/releases/tag/0.14.1). **OTA** and **DFU** refer to the update of the firmware over BLE (**B**luetooth **L**ow **E**nergy). **OTA** means **O**ver **T**he **A**ir, this is a functionality that allows the user to update the firmware how their device using a wireless communication like BLE. When we talk about **DFU** (**D**igital **F**irmware **U**pdate), we refer to the file format and protocol used to send the update of the firmware to the watch over-the-air. InfiniTime implement the (legacy) DFU protocol from Nordic Semiconductor (NRF). ## How to check the version of InfiniTime and the bootloader? -Since September 2020, all PineTimes (devkits or sealed) are flashed using the **[first iteration of the bootloader](https://github.com/lupyuen/pinetime-rust-mynewt/releases/tag/v4.1.7)** and **[InfiniTime 0.7.1](https://github.com/JF002/InfiniTime/releases/tag/0.7.1)**. There was no recovery firmware at that time. +Since September 2020, all PineTimes (devkits or sealed) are flashed using the **[first iteration of the bootloader](https://github.com/lupyuen/pinetime-rust-mynewt/releases/tag/v4.1.7)** and **[InfiniTime 0.7.1](https://github.com/InfiniTimeOrg/InfiniTime/releases/tag/0.7.1)**. There was no recovery firmware at that time. The bootloader only runs when the watch starts (from an empty battery, for example) or after a reset (after a successful OTA or a manual reset - long push on the button). @@ -33,7 +33,7 @@ And for version >= 1.0 : ![InfiniTime 1.0 version](version-1.0.jpg) -PineTime shipped from June 2021 (to be confirmed) will be flashed with the [new version of the bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader/releases/tag/1.0.0), the [recovery firmware](https://github.com/JF002/InfiniTime/releases/tag/0.14.1) and [InfiniTime 1.0](https://github.com/JF002/InfiniTime/releases/tag/1.0.0). +PineTime shipped from June 2021 (to be confirmed) will be flashed with the [new version of the bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader/releases/tag/1.0.0), the [recovery firmware](https://github.com/InfiniTimeOrg/InfiniTime/releases/tag/0.14.1) and [InfiniTime 1.0](https://github.com/InfiniTimeOrg/InfiniTime/releases/tag/1.0.0). The bootloader is easily recognizable with it white pine cone that is progressively drawn in green. It also displays its own version on the bottom (1.0.0 as of now). @@ -56,9 +56,9 @@ If your PineTime is currently running InfiniTime 0.7.1 and the old bootloader, w Using the companion app of your choice, you'll need to apply the OTA procedure for these 3 firmwares in this sequence (failing to follow this specific order might temporarily or permanently brick your device): - 1. Flash the latest version of InfiniTime. The file to upload is named **pinetime-mcuboot-app-dfu-x.y.z.zip**. Here is the link to [InfiniTime 1.0](https://github.com/JF002/InfiniTime/releases/download/1.0.0/pinetime-mcuboot-app-dfu-1.0.0.zip). + 1. Flash the latest version of InfiniTime. The file to upload is named **pinetime-mcuboot-app-dfu-x.y.z.zip**. Here is the link to [InfiniTime 1.0](https://github.com/InfiniTimeOrg/InfiniTime/releases/download/1.0.0/pinetime-mcuboot-app-dfu-1.0.0.zip). 2. Update the bootloader by applying the OTA procedure with the file named [**reloader-mcuboot.zip** from the repo of the bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader/releases/download/1.0.0/reloader-mcuboot.zip). - 3. Install the recovery firmware by applying the OTA procedure with the file named [**pinetime-mcuboot-recovery-loader-dfu-0.14.1.zip** from the version 0.14.1 of InfiniTime](https://github.com/JF002/InfiniTime/releases/download/0.14.1/pinetime-mcuboot-recovery-loader-dfu-0.14.1.zip). + 3. Install the recovery firmware by applying the OTA procedure with the file named [**pinetime-mcuboot-recovery-loader-dfu-0.14.1.zip** from the version 0.14.1 of InfiniTime](https://github.com/InfiniTimeOrg/InfiniTime/releases/download/0.14.1/pinetime-mcuboot-recovery-loader-dfu-0.14.1.zip). You'll find more info about this process in [this wiki page](https://wiki.pine64.org/wiki/Upgrade_PineTime_to_InfiniTime_1.0.0). You can also see the procedure in video [here](https://video.codingfield.com/videos/watch/831077c5-16f3-47b4-9b2b-c4bbfecc6529) and [here (from Amazfish)](https://video.codingfield.com/videos/watch/f7bffb3d-a6a1-43c4-8f01-f4aeff4adf9e) diff --git a/doc/gettingStarted/ota-gadgetbridge-nrfconnect.md b/doc/gettingStarted/ota-gadgetbridge-nrfconnect.md index ffc27ed..57d1621 100644 --- a/doc/gettingStarted/ota-gadgetbridge-nrfconnect.md +++ b/doc/gettingStarted/ota-gadgetbridge-nrfconnect.md @@ -8,7 +8,7 @@ If you just want to flash or upgrade InfiniTime on your PineTime, this page is f - [How to flash InfiniTime using the SWD interface](#how-to-flash-infinitime-using-the-swd-interface) ## InfiniTime releases and versions -All releases of InfiniTime are available on the [release page of the GitHub repo](https://github.com/JF002/InfiniTime/releases). +All releases of InfiniTime are available on the [release page of the GitHub repo](https://github.com/InfiniTimeOrg/InfiniTime/releases). Versions that are tagged as **RELEASE CANDIDATE** are pre-release versions, that are available for testing before actually releasing a new stable version. If you want to help us debug the project and provide stable versions to other user, you can use them. If you want stable and tested version, you should not flash these release candidate version. diff --git a/src/displayapp/screens/PineTimeStyle.cpp b/src/displayapp/screens/PineTimeStyle.cpp index 6766ecb..fa88d45 100644 --- a/src/displayapp/screens/PineTimeStyle.cpp +++ b/src/displayapp/screens/PineTimeStyle.cpp @@ -1,5 +1,5 @@ /* - * This file is part of the Infinitime distribution (https://github.com/JF002/Infinitime). + * This file is part of the Infinitime distribution (https://github.com/InfiniTimeOrg/Infinitime). * Copyright (c) 2021 Kieran Cawthray. * * This program is free software: you can redistribute it and/or modify diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 475fbb8..cda0a48 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -267,7 +267,8 @@ std::unique_ptr SystemInfo::CreateScreen5() { "Public License v3\n" "#444444 Source code#\n" "#FFFF00 https://github.com/#\n" - "#FFFF00 JF002/InfiniTime#"); + "#FFFF00 InfiniTimeOrg/#\n" + "#FFFF00 InfiniTime#"); lv_label_set_align(label, LV_LABEL_ALIGN_CENTER); lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); return std::make_unique(4, 5, app, label); -- cgit v0.10.2 From ea1bc8192587cb95b89068043cdd44b104d2279e Mon Sep 17 00:00:00 2001 From: carlosperate Date: Sat, 16 Oct 2021 23:10:36 +0100 Subject: Docs: Clarify Docker image needs to be built 1st, fix URL and typos. diff --git a/doc/buildWithDocker.md b/doc/buildWithDocker.md index 2e4ecbb..a57893c 100644 --- a/doc/buildWithDocker.md +++ b/doc/buildWithDocker.md @@ -11,7 +11,9 @@ Based on Ubuntu 18.04 with the following build dependencies: ## Run a container to build the project -The `infinitime-build` image contains all the dependencies you need. The default `CMD` will compile sources found in `/sources`, so you need only mount your code. +The `infinitime-build` image contains all the dependencies you need. The default `CMD` will compile sources found in `/sources`, so you need only mount your code. + +Before continuing, make sure you first build the image as indicated in the [Build the image](#build-the-image) section, or check the [Using the image from Docker Hub](#using-the-image-from-docker-hub) section if you prefer to use a pre-made image. This example will build the firmware, generate the MCUBoot image and generate the DFU file. For cloning the repo, see [these instructions](../doc/buildAndProgram.md#clone-the-repo). Outputs will be written to **/build/output**: @@ -28,10 +30,10 @@ docker run --rm -it -v $(pwd):/sources infinitime-build /opt/build.sh pinetime-a The image is built using 1000:1000 for the user id and group id. If this is different to your user or group ids (run `id -u` and `id -g` to find out what your id values are if you are unsure), you will need to override them via the `--user` parameter in order to prevent permission errors with the output files (and the cmake build cache). -Running with this image is the same as above, you just specify the ids to `docker run` +Running with this image is the same as above, you just specify the ids to `docker run`: ```bash -docker run --rm -it -v $(pwd):/sources --user $(id -u):$(id -g) pfeerick/infinitime-build +docker run --rm -it -v $(pwd):/sources --user $(id -u):$(id -g) infinitime-build ``` Or you can specify your user id and group id (by number, not by name) directly: @@ -42,7 +44,7 @@ docker run --rm -it -v $(pwd):/sources --user 1234:1234 infinitime-build ## Using the image from Docker Hub -The image is avaiable via Docker Hub for both the amd64 and arm64v8 architectures at [pfeerick/infinitime-build](https://hub.docker.com/repository/docker/pfeerick/infinitime-build). +The image is available via Docker Hub for both the amd64 and arm64v8 architectures at [pfeerick/infinitime-build](https://hub.docker.com/r/pfeerick/infinitime-build). It can be pulled (downloaded) using the following command: -- cgit v0.10.2 From c4b8ff314abd436d0444ea884ccf142a0b82c8c8 Mon Sep 17 00:00:00 2001 From: carlosperate Date: Sun, 17 Oct 2021 00:31:21 +0100 Subject: Update git URLS, MCUboot is now independent w/ different GitHub org. diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1dd68f2..46e2fac 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -55,7 +55,7 @@ RUN unzip -q /tmp/nRF5_SDK_15.3.0_59ac345 -d /opt RUN rm /tmp/nRF5_SDK_15.3.0_59ac345 # McuBoot # RUN bash -c "source /opt/build.sh; GetMcuBoot;" -RUN git clone https://github.com/JuulLabs-OSS/mcuboot.git +RUN git clone https://github.com/mcu-tools/mcuboot.git RUN pip3 install -r ./mcuboot/scripts/requirements.txt RUN adduser infinitime diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh index 8f0d0fa..5dcdf91 100644 --- a/.devcontainer/build.sh +++ b/.devcontainer/build.sh @@ -43,7 +43,7 @@ GetGcc() { } GetMcuBoot() { - git clone https://github.com/JuulLabs-OSS/mcuboot.git "$TOOLS_DIR/mcuboot" + git clone https://github.com/mcu-tools/mcuboot.git "$TOOLS_DIR/mcuboot" pip3 install -r "$TOOLS_DIR/mcuboot/scripts/requirements.txt" } diff --git a/bootloader/README.md b/bootloader/README.md index c04e0e3..9f99602 100644 --- a/bootloader/README.md +++ b/bootloader/README.md @@ -1,5 +1,5 @@ # About this bootloader -The [bootloader](https://github.com/lupyuen/pinetime-rust-mynewt/tree/master/libs/pinetime_boot/src) is mostly developed by [Lup Yuen](https://github.com/lupyuen). It is based on [MCUBoot](https://juullabs-oss.github.io/mcuboot/) and [Mynewt](https://mynewt.apache.org/). +The [bootloader](https://github.com/lupyuen/pinetime-rust-mynewt/tree/master/libs/pinetime_boot/src) is mostly developed by [Lup Yuen](https://github.com/lupyuen). It is based on [MCUBoot](https://www.mcuboot.com) and [Mynewt](https://mynewt.apache.org/). The goal of this project is to provide a common bootloader for multiple (all?) Pinetime projects. It allows to upgrade the current bootloader and even replace the current application by another one that supports the same bootloader. @@ -86,7 +86,7 @@ make pinetime-mcuboot-app The binary is located in */src/pinetime-mcuboot-app.bin*. -It must me converted into a MCUBoot image using *imgtool.py* from [MCUBoot](https://github.com/JuulLabs-OSS/mcuboot/tree/master/scripts). Simply checkout the project and run the script /scripts/imgtool.py with the following command line: +It must me converted into a MCUBoot image using *imgtool.py* from [MCUBoot](https://github.com/mcu-tools/mcuboot/tree/master/scripts). Simply checkout the project and run the script /scripts/imgtool.py with the following command line: ` imgtool.py create --align 4 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header /src/pinetime-mcuboot-app.bin image.bin diff --git a/docker/build.sh b/docker/build.sh index 2fa7d92..d86e7c2 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -43,7 +43,7 @@ GetGcc() { } GetMcuBoot() { - git clone https://github.com/JuulLabs-OSS/mcuboot.git "$TOOLS_DIR/mcuboot" + git clone https://github.com/mcu-tools/mcuboot.git "$TOOLS_DIR/mcuboot" pip3 install -r "$TOOLS_DIR/mcuboot/scripts/requirements.txt" } -- cgit v0.10.2 From 2e7d4763dcf0e548e09a6ebc121cab80c37dcc23 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 16 Oct 2021 20:45:08 -0700 Subject: Add docs from infinitime Go library's repo and fix typos and grammar diff --git a/doc/ble.md b/doc/ble.md index 518b99c..cdb449d 100644 --- a/doc/ble.md +++ b/doc/ble.md @@ -2,23 +2,59 @@ ## Introduction This page describes the BLE implementation and API built in this firmware. -**Note** : I'm a beginner in BLE related technologies and the information of this document reflect my current knowledge and understanding of the BLE stack. These informations might be erroneous or incomplete. Feel free to submit a PR if you think you can improve these. +**Note** : I'm a beginner in BLE related technologies and the information of this document reflect my current knowledge and understanding of the BLE stack. This information might be erroneous or incomplete. Feel free to submit a PR if you think you can improve these. + +--- + +### Table of Contents + +- [BLE Connection](#ble-connection) +- [BLE UUIDs](#ble-uuids) +- [BLE Services](#ble-services) + - [CTS](#cts) + - [ANS](#ans) +- [Getting Information](#getting-information) + - [Firmware Version](#firmware-version) + - [Battery Level](#battery-level) + - [Heart Rate](#heart-rate) +- [Notifications](#notifications) + - [New Alert](#new-alert) + - [Notification Event](#notification-event) +- [Firmware Upgrades](#firmware-upgrades) + - [Step one](#step-one) + - [Step two](#step-two) + - [Step three](#step-three) + - [Step four](#step-four) + - [Step five](#step-five) + - [Step six](#step-six) + - [Step seven](#step-seven) + - [Step eight](#step-eight) + - [Step nine](#step-nine) +- [Music Control](#music-control) + - [Events](#events) + - [Status](#status) + - [Artist, Track, and Album](#artist-track-and-album) +- [Time](#time) + +--- ## BLE Connection -When starting the firmware start a BLE advertising : it sends small messages that can be received by any *central* device in range. This allows the device to announce its presence to other devices. +When starting, the firmware starts BLE advertising. It sends small messages that can be received by any *central* device in range. This allows the device to announce its presence to other devices. -A companion application (running on a PC, RaspberryPi, smartphone) which received this avertising packet can request a connection to the device. This connection procedure allows the 2 devices to negotiate communication parameters, security keys,... +A companion application (running on a PC, Raspberry Pi, smartphone, etc.) which receives this advertising packet can request a connection to the device. This connection procedure allows the 2 devices to negotiate communication parameters, security keys, etc. -When the connection is established, the pinetime will try to discover services running on the companion application. For now **CTS** (**C**urrent **T**ime **S**ervice) and **ANS** (**A**lert **N**otification **S**ervice) are supported. +When the connection is established, the PineTime will try to discover services running on the companion application. For now **CTS** (**C**urrent **T**ime **S**ervice) and **ANS** (**A**lert **N**otification **S**ervice) are supported. If **CTS** is detected, it'll request the current time to the companion application. If **ANS** is detected, it will listen to new notifications coming from the companion application. ![BLE connection sequence diagram](ble/connection_sequence.png "BLE connection sequence diagram") +--- + ## BLE UUIDs When possible, InfiniTime tries to implement BLE services defined by the BLE specification. -When the service does not exist in the BLE specification, InfiniTime implement custom services. As all BLE services, custom services are identified by a UUID. Here is how to define the UUID of custom services in InfiniTime: +When the service does not exist in the BLE specification, InfiniTime implements custom services. Custom services are identified by a UUID, as are all BLE services. Here is how to define the UUID of custom services in InfiniTime: ``` - Base UUID : xxxxxxxx-78fc-48fe-8e23-433b3a1942d0 @@ -38,6 +74,8 @@ The following custom services are implemented in InfiniTime: * Navigation Service : 00010000-78fc-48fe-8e23-433b3a1942d0 ``` +--- + ## BLE services [List of standard BLE services](https://www.bluetooth.com/specifications/gatt/services/) @@ -49,3 +87,197 @@ The following custom services are implemented in InfiniTime: ![ANS sequence diagram](./ble/ans_sequence.png "ANS sequence diagram") +--- + +### Getting Information + +The InfiniTime firmware exposes some information about itself through BLE. The BLE characteristic UUIDs for this information are as follows: + +- Firmware Version: `00002a26-0000-1000-8000-00805f9b34fb` +- Battery Level: `00002a19-0000-1000-8000-00805f9b34fb` +- Heart Rate: `00002a37-0000-1000-8000-00805f9b34fb` + +#### Firmware Version + +Reading a value from the firmware version characteristic will yield a UTF-8 encoded string containing the version of InfiniTime being run on the device. Example: `1.6.0`. + +#### Battery Level + +Reading from the battery level characteristic yields a single byte of data. This byte can be converted to an unsigned 8-bit integer which will be the battery percentage. This characteristic allows notify for updates as the value changes. + +#### Heart Rate + +Reading from the heart rate characteristic yields two bytes of data. I am not sure of the function of the first byte. It appears to always be zero. The second byte can be converted to an unsigned 8-bit integer which is the current heart rate. This characteristic also allows notify for updates as the value changes. + +--- + +### Notifications + +InfiniTime uses the Alert Notification Service (ANS) for notifications. The relevant UUIDs are as follows: + +- New Alert: `00002a46-0000-1000-8000-00805f9b34fb` +- Notification Event: `00020001-78fc-48fe-8e23-433b3a1942d0` + +#### New Alert + +The new alert characteristic allows sending new notifications to InfiniTime. It requires the following format: + +``` +\x00<\x00-separated data> +``` + +For example, here is what a normal notification looks like in Golang (language of `itd`): + +```go +// \x00 is the category for simple alert, and there is one new notifcation, hence \x01. +"\x00\x01\x00Test Title\x00Test Body" +``` + +A call notification looks like so: + +```go +// \x03 is the category for calls, and there is one new call notifcation, hence \x01. +"\x03\x01\x00Mary" +``` + +The `\x00` stands for hexadecimal `00` which means null. + +Here is the list of categories and commands: + +- Simple Alert: `0` +- Email: `1` +- News: `2` +- Call Notification: `3` +- Missed Call: `4` +- SMS/MMS: `5` +- Voicemail: `6` +- Schedule: `7` +- High Prioritized Alert: `8` +- Instant Message: `9` +- All Alerts: `0xFF` + +These lists and information were retrieved from the following pages in the Nordic docs: + +- [Alert Notification Service Client](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.2.0%2Fgroup__ble__ans__c.html) +- [Alert Notification Application](https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v13.0.0%2Fble_sdk_app_alert_notification.html) + +#### Notification Event + +A call notification in InfiniTime contains three buttons. Decline, Accept, and Mute. The notification event characteristic contains the button tapped by the user on a call notification. This characteristic only allows notify, **not** read. + +Enabling notifications from this characteristic, you get a single byte whenever the user taps a button on the call notification. This byte is an unsigned 8-bit integer that signifies one of the buttons. The numbers are as follows: + +- 0: Declined +- 1: Accepted +- 2: Muted + +--- + +### Firmware Upgrades + +Firmware upgrades in InfiniTime are probably the most complex of the BLE operations. It is a nine step process requiring multiple commands be sent to multiple characteristics. The relevant UUIDs are as follows: + +- Control Point: `00001531-1212-efde-1523-785feabcd123` +- Packet: `00001532-1212-efde-1523-785feabcd123` + +A DFU upgrade archive for InfiniTime consists of multiple files. The most important being the .bin and .dat files. The first is the actual firmware, while the second is a packet that initializes DFU. Both are needed for a DFU upgrade. + +The first thing to do is to enable notifications on the control point characteristic. This will be needed for verifying that the proper responses are being sent back from InfiniTime. + +#### Step one + +For the first step, write `0x01`, `0x04` to the control point characteristic. This will signal InfiniTime that a DFU upgrade is to be started. + +#### Step two + +In step two, send the total size in bytes of the firmware file to the packet characteristic. This value should be an unsigned 32-bit integer encoded as little-endian. In front of this integer should be 8 null bytes. This is because there are three items that can be updated and each 4 bytes is for one of those. The last four are for the InfiniTime application, so those are the ones that need to be set. + +#### Step three + +Before running step three, wait for a response from the control point. This response should be `0x10`, `0x01`, `0x01` which indicates a successful DFU start. In step three, send `0x02`, `0x00` to the control point. This will signal InfiniTime to expect the init packet on the packet characteristic. + +#### Step four + +The previous step prepared InfiniTime for this one. In this step, send the contents of the .dat init packet file to the packet characteristic. After this, send `0x02`, `0x01` indicating that the packet has been sent. + +#### Step five + +Before running this step, wait to receive `0x10`, `0x02`, `0x01` which indicates that the packet has been received. During this step, send the packet receipt interval to the control point. The firmware file will be sent in segments of 20 bytes each. The packet receipt interval indicates how many segments should be received before sending a receipt containing the amount of bytes received so that it can be confirmed to be the same as the amount sent. This is very useful for detecting packet loss. `itd` uses `0x08`, `0x0A` which indicates 10 segments. + +#### Step six + +In step six, write `0x03` to the control point, indicating that the firmware will be sent next on the packet characteristic. + +#### Step seven + +This step is the most difficult. Here, the actual firmware is sent to InfiniTime. + +As mentioned before, the firmware file must be split up into segments of 20 bytes each and sent to the packet characteristic one by one. Every 10 segments (or whatever you have set the interval to), check for a response starting with `0x11`. The rest of the response will be the amount of bytes received encoded as a little-endian unsigned 32-bit integer. Confirm that this matches the amount of bytes sent, and then continue sending more segments. + +#### Step eight + +Before running this step, wait to receive `0x10`, `0x03`, `0x01` which indicates a successful receipt of the firmware image. In this step, write `0x04` to the control point to signal InfiniTime to validate the image it has received. + +#### Step nine + +Before running this step, wait to receive `0x10`, `0x04`, `0x01` which indicates that the image has been validated. In this step, send `0x05` to the control point as a command with no response. This signals InfiniTime to activate the new firmware and reboot. + +Once all of these steps are complete, the DFU is complete. Don't forget to validate the firmware in the settings. + +--- + +### Music Control + +InfiniTime contains a music controller app which is meant to control the music playback and volume through the companion. + +The following UUIDs are relevant to this: + +- Events: `00000001-78fc-48fe-8e23-433b3a1942d0` +- Status: `00000002-78fc-48fe-8e23-433b3a1942d0` +- Artist: `00000003-78fc-48fe-8e23-433b3a1942d0` +- Track: `00000004-78fc-48fe-8e23-433b3a1942d0` +- Album: `00000005-78fc-48fe-8e23-433b3a1942d0` + +#### Events + +The events characteristic is meant to respond to user input in the music controller app. + +Enabling notifications on this characteristic gives you a single byte upon any event. This byte can be converted to an unsigned 8-bit integer which corresponds to each possible event. Here are the events: + +- App Opened: `0xe0` +- Play: `0x00` +- Pause: `0x01` +- Next: `0x03` +- Previous: `0x04` +- Volume up: `0x05` +- Volume down: `0x06` + +#### Status + +The status characteristic allows setting the playing status of music. Send `0x01` to the status characteristic for playing, and `0x01` for paused. + +#### Artist, Track, and Album + +These characteristics all work the same way. Simply send a UTF-8 encoded string to the relevant characteristic in order to set the value in the app. + +--- + +### Time + +InfiniTime allows setting its time via the Current Time Service (CTS) + +The UUID for the current time characteristic is: `00002a2b-0000-1000-8000-00805f9b34fb` + +This characteristic expects a particular format: + +- Year (`uint16`) +- Month (`uint8`) +- Day (`uint8`) +- Hour (`uint8`) +- Minute (`uint8`) +- Second (`uint8`) +- Weekday (`uint8`) +- Microsecond divided by `1e6*256` (`uint8`) +- Binary 0001 (`uint8`) + +Write all of these together, encoded as little-endian, to the current time characteristic. \ No newline at end of file -- cgit v0.10.2 From 75339323d24af0ffae60ac2b09fe6b364e6d6254 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 16 Oct 2021 20:52:25 -0700 Subject: Fix grammar mistakes diff --git a/doc/ble.md b/doc/ble.md index cdb449d..a46ee13 100644 --- a/doc/ble.md +++ b/doc/ble.md @@ -2,7 +2,7 @@ ## Introduction This page describes the BLE implementation and API built in this firmware. -**Note** : I'm a beginner in BLE related technologies and the information of this document reflect my current knowledge and understanding of the BLE stack. This information might be erroneous or incomplete. Feel free to submit a PR if you think you can improve these. +**Note** : I'm a beginner in BLE related technologies and the information in this document reflects my current knowledge and understanding of the BLE stack. This information might be erroneous or incomplete. Feel free to submit a PR if you think you can improve it. --- -- cgit v0.10.2 From 95618dd2388d5fbb271e73d52913747a0b42d9eb Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 16 Oct 2021 21:01:12 -0700 Subject: Fix error in music status docs diff --git a/doc/ble.md b/doc/ble.md index a46ee13..2f8ba41 100644 --- a/doc/ble.md +++ b/doc/ble.md @@ -254,7 +254,7 @@ Enabling notifications on this characteristic gives you a single byte upon any e #### Status -The status characteristic allows setting the playing status of music. Send `0x01` to the status characteristic for playing, and `0x01` for paused. +The status characteristic allows setting the playing status of music. Send `0x01` to the status characteristic for playing, and `0x00` for paused. #### Artist, Track, and Album -- cgit v0.10.2 From d1f50157c7e0c471ae0e260fdca82fc472635079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 17 Oct 2021 08:23:01 +0200 Subject: MotionService : fix typo and characteristic array size + send notification only if the host subscribed to them. diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp index 5b00f49..75a038a 100644 --- a/src/components/ble/HeartRateService.cpp +++ b/src/components/ble/HeartRateService.cpp @@ -8,7 +8,7 @@ constexpr ble_uuid16_t HeartRateService::heartRateServiceUuid; constexpr ble_uuid16_t HeartRateService::heartRateMeasurementUuid; namespace { - int HeartRateServiceServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { + int HeartRateServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { auto* heartRateService = static_cast(arg); return heartRateService->OnHeartRateRequested(conn_handle, attr_handle, ctxt); } @@ -19,7 +19,7 @@ HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Control : system {system}, heartRateController {heartRateController}, characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u, - .access_cb = HeartRateServiceServiceCallback, + .access_cb = HeartRateServiceCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, .val_handle = &heartRateMeasurementHandle}, @@ -56,6 +56,8 @@ int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t a } void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { + if(!heartRateMeasurementNotificationEnable) return; + uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value auto* om = ble_hs_mbuf_from_flat(buffer, 2); @@ -67,3 +69,13 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { ble_gattc_notify_custom(connectionHandle, heartRateMeasurementHandle, om); } + +void HeartRateService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { + if(attributeHandle == heartRateMeasurementHandle) + heartRateMeasurementNotificationEnable = true; +} + +void HeartRateService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { + if(attributeHandle == heartRateMeasurementHandle) + heartRateMeasurementNotificationEnable = false; +} \ No newline at end of file diff --git a/src/components/ble/HeartRateService.h b/src/components/ble/HeartRateService.h index 0b16703..4e4a5a4 100644 --- a/src/components/ble/HeartRateService.h +++ b/src/components/ble/HeartRateService.h @@ -2,6 +2,7 @@ #define min // workaround: nimble's min/max macros conflict with libstdc++ #define max #include +#include #undef max #undef min @@ -18,6 +19,9 @@ namespace Pinetime { int OnHeartRateRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context); void OnNewHeartRateValue(uint8_t hearRateValue); + void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle); + void UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle); + private: Pinetime::System::SystemTask& system; Controllers::HeartRateController& heartRateController; @@ -28,10 +32,11 @@ namespace Pinetime { static constexpr ble_uuid16_t heartRateMeasurementUuid {.u {.type = BLE_UUID_TYPE_16}, .value = heartRateMeasurementId}; - struct ble_gatt_chr_def characteristicDefinition[3]; + struct ble_gatt_chr_def characteristicDefinition[2]; struct ble_gatt_svc_def serviceDefinition[2]; uint16_t heartRateMeasurementHandle; + std::atomic_bool heartRateMeasurementNotificationEnable {false}; }; } } diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index 879421e..931c3ae 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -215,6 +215,16 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) { event->subscribe.prev_notify, event->subscribe.cur_notify, event->subscribe.prev_indicate); + + if(event->subscribe.reason == BLE_GAP_SUBSCRIBE_REASON_TERM) { + heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + } + else if(event->subscribe.prev_notify == 0 && event->subscribe.cur_notify == 1) { + heartRateService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + } + else if(event->subscribe.prev_notify == 1 && event->subscribe.cur_notify == 0) { + heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + } break; case BLE_GAP_EVENT_MTU: -- cgit v0.10.2 From 60a49af886f16b4bbd8012cd711374f3fdb94efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 17 Oct 2021 08:23:44 +0200 Subject: Add MotionService : expose step count and RAW X/Y/Z values to the host. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 07eabe1..a839e08 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -477,6 +477,7 @@ list(APPEND SOURCE_FILES components/ble/ImmediateAlertService.cpp components/ble/ServiceDiscovery.cpp components/ble/HeartRateService.cpp + components/ble/MotionService.cpp components/firmwarevalidator/FirmwareValidator.cpp components/motor/MotorController.cpp components/settings/Settings.cpp @@ -545,6 +546,7 @@ list(APPEND RECOVERY_SOURCE_FILES components/ble/ServiceDiscovery.cpp components/ble/NavigationService.cpp components/ble/HeartRateService.cpp + components/ble/MotionService.cpp components/firmwarevalidator/FirmwareValidator.cpp components/settings/Settings.cpp components/timer/TimerController.cpp @@ -652,6 +654,7 @@ set(INCLUDE_FILES components/ble/ServiceDiscovery.h components/ble/BleClient.h components/ble/HeartRateService.h + components/ble/MotionService.h components/settings/Settings.h components/timer/TimerController.h components/alarm/AlarmController.h diff --git a/src/components/ble/MotionService.cpp b/src/components/ble/MotionService.cpp new file mode 100644 index 0000000..2bb5289 --- /dev/null +++ b/src/components/ble/MotionService.cpp @@ -0,0 +1,124 @@ +#include "MotionService.h" +#include "components/motion//MotionController.h" +#include "systemtask/SystemTask.h" + +using namespace Pinetime::Controllers; + +namespace { + // 0002yyxx-78fc-48fe-8e23-433b3a1942d0 + constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) { + return ble_uuid128_t{ + .u = {.type = BLE_UUID_TYPE_128}, + .value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x02, 0x00 } + }; + } + + // 00020000-78fc-48fe-8e23-433b3a1942d0 + constexpr ble_uuid128_t BaseUuid() { + return CharUuid(0x00, 0x00); + } + + constexpr ble_uuid128_t motionServiceUuid {BaseUuid()}; + constexpr ble_uuid128_t stepCountCharUuid {CharUuid(0x01, 0x00)}; + constexpr ble_uuid128_t motionValuesCharUuid {CharUuid(0x02, 0x00)}; + + int MotionServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { + auto* motionService = static_cast(arg); + return motionService->OnStepCountRequested(conn_handle, attr_handle, ctxt); + } +} + +// TODO Refactoring - remove dependency to SystemTask +MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController) + : system {system}, + motionController {motionController}, + characteristicDefinition {{.uuid = &stepCountCharUuid.u, + .access_cb = MotionServiceCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, + .val_handle = &stepCountHandle}, + {.uuid = &motionValuesCharUuid.u, + .access_cb = MotionServiceCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, + .val_handle = &motionValuesHandle}, + {0}}, + serviceDefinition { + { + .type = BLE_GATT_SVC_TYPE_PRIMARY, + .uuid = &motionServiceUuid.u, + .characteristics = characteristicDefinition + }, + {0}, + } { + // TODO refactor to prevent this loop dependency (service depends on controller and controller depends on service) + motionController.SetService(this); +} + +void MotionService::Init() { + int res = 0; + res = ble_gatts_count_cfg(serviceDefinition); + ASSERT(res == 0); + + res = ble_gatts_add_svcs(serviceDefinition); + ASSERT(res == 0); +} + +int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) { + if (attributeHandle == stepCountHandle) { + NRF_LOG_INFO("Motion-stepcount : handle = %d", stepCountHandle); + uint32_t buffer = motionController.NbSteps(); + + int res = os_mbuf_append(context->om, &buffer, 4); + return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; + } else if(attributeHandle == motionValuesHandle) { + int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() }; + + int res = os_mbuf_append(context->om, buffer, 3 * sizeof(int16_t)); + return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; + } + return 0; +} + +void MotionService::OnNewStepCountValue(uint8_t stepCount) { + if(!stepCountNoficationEnabled) return; + + uint32_t buffer = stepCount; + auto* om = ble_hs_mbuf_from_flat(&buffer, 4); + + uint16_t connectionHandle = system.nimble().connHandle(); + + if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { + return; + } + + ble_gattc_notify_custom(connectionHandle, stepCountHandle, om); +} +void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) { + if(!motionValuesNoficationEnabled) return; + + int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() }; + auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t)); + + uint16_t connectionHandle = system.nimble().connHandle(); + + if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { + return; + } + + ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om); +} + +void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { + if(attributeHandle == stepCountHandle) + stepCountNoficationEnabled = true; + else if(attributeHandle == motionValuesHandle) + motionValuesNoficationEnabled = true; +} + +void MotionService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { + if(attributeHandle == stepCountHandle) + stepCountNoficationEnabled = false; + else if(attributeHandle == motionValuesHandle) + motionValuesNoficationEnabled = false; +} diff --git a/src/components/ble/MotionService.h b/src/components/ble/MotionService.h new file mode 100644 index 0000000..75ad518 --- /dev/null +++ b/src/components/ble/MotionService.h @@ -0,0 +1,39 @@ +#pragma once +#define min // workaround: nimble's min/max macros conflict with libstdc++ +#define max +#include +#include +#undef max +#undef min + +namespace Pinetime { + namespace System { + class SystemTask; + } + namespace Controllers { + class MotionController; + class MotionService { + public: + MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController); + void Init(); + int OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context); + void OnNewStepCountValue(uint8_t stepCount); + void OnNewMotionValues(int16_t x, int16_t y, int16_t z); + + void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle); + void UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle); + + private: + Pinetime::System::SystemTask& system; + Controllers::MotionController& motionController; + + struct ble_gatt_chr_def characteristicDefinition[3]; + struct ble_gatt_svc_def serviceDefinition[2]; + + uint16_t stepCountHandle; + uint16_t motionValuesHandle; + std::atomic_bool stepCountNoficationEnabled {false}; + std::atomic_bool motionValuesNoficationEnabled {false}; + }; + } +} diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index 931c3ae..09a9b99 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -23,7 +23,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::NotificationManager& notificationManager, Controllers::Battery& batteryController, Pinetime::Drivers::SpiNorFlash& spiNorFlash, - Controllers::HeartRateController& heartRateController) + Controllers::HeartRateController& heartRateController, + Controllers::MotionController& motionController) : systemTask {systemTask}, bleController {bleController}, dateTimeController {dateTimeController}, @@ -39,6 +40,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, batteryInformationService {batteryController}, immediateAlertService {systemTask, notificationManager}, heartRateService {systemTask, heartRateController}, + motionService{systemTask, motionController}, serviceDiscovery({¤tTimeClient, &alertNotificationClient}) { } @@ -81,6 +83,7 @@ void NimbleController::Init() { batteryInformationService.Init(); immediateAlertService.Init(); heartRateService.Init(); + motionService.Init(); int rc; rc = ble_hs_util_ensure_addr(0); diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h index 473bb1a..76f89ba 100644 --- a/src/components/ble/NimbleController.h +++ b/src/components/ble/NimbleController.h @@ -19,6 +19,7 @@ #include "NavigationService.h" #include "ServiceDiscovery.h" #include "HeartRateService.h" +#include "MotionService.h" namespace Pinetime { namespace Drivers { @@ -43,7 +44,8 @@ namespace Pinetime { Pinetime::Controllers::NotificationManager& notificationManager, Controllers::Battery& batteryController, Pinetime::Drivers::SpiNorFlash& spiNorFlash, - Controllers::HeartRateController& heartRateController); + Controllers::HeartRateController& heartRateController, + Controllers::MotionController& motionController); void Init(); void StartAdvertising(); int OnGAPEvent(ble_gap_event* event); @@ -95,6 +97,7 @@ namespace Pinetime { BatteryInformationService batteryInformationService; ImmediateAlertService immediateAlertService; HeartRateService heartRateService; + MotionService motionService; uint8_t addrType; // 1 = Random, 0 = PUBLIC uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE; diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index b0dbada..a2384d7 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -3,6 +3,14 @@ using namespace Pinetime::Controllers; void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) { + if (this->nbSteps != nbSteps && service != nullptr) { + service->OnNewStepCountValue(nbSteps); + } + + if(service != nullptr && (this->x != x || this->y != y || this->z != z)) { + service->OnNewMotionValues(x, y, z); + } + this->x = x; this->y = y; this->z = z; @@ -41,3 +49,6 @@ void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) { default: this->deviceType = DeviceTypes::Unknown; break; } } +void MotionController::SetService(Pinetime::Controllers::MotionService* service) { + this->service = service; +} diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index ff71509..c72d8a4 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -2,6 +2,7 @@ #include #include +#include namespace Pinetime { namespace Controllers { @@ -39,6 +40,7 @@ namespace Pinetime { } void Init(Pinetime::Drivers::Bma421::DeviceTypes types); + void SetService(Pinetime::Controllers::MotionService* service); private: uint32_t nbSteps; @@ -48,6 +50,7 @@ namespace Pinetime { int16_t lastYForWakeUp = 0; bool isSensorOk = false; DeviceTypes deviceType = DeviceTypes::Unknown; + Pinetime::Controllers::MotionService* service = nullptr; }; } } \ No newline at end of file diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index f1c5165..e0a5907 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -101,7 +101,8 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, heartRateApp(heartRateApp), fs {fs}, touchHandler {touchHandler}, - nimbleController(*this, bleController, dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) { + nimbleController(*this, bleController, dateTimeController, notificationManager, + batteryController, spiNorFlash, heartRateController, motionController) { } void SystemTask::Start() { -- cgit v0.10.2 From 31badd2eb3a46ed75a752f7b30015a1eaa205cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 17 Oct 2021 08:34:24 +0200 Subject: Add doc about the new motion service. diff --git a/doc/MotionService.md b/doc/MotionService.md new file mode 100644 index 0000000..0d0a551 --- /dev/null +++ b/doc/MotionService.md @@ -0,0 +1,17 @@ +# Motion Service +## Introduction +The motion service exposes step count and raw X/Y/Z motion value as READ and NOTIFY characteristics. + +## Service +The service UUID is **00020000-78fc-48fe-8e23-433b3a1942d0** + +## Characteristics +### Step count (UUID 00020001-78fc-48fe-8e23-433b3a1942d0) +The current number of steps represented as a single `uint32_t` (4 bytes) value. + +### Raw motion values (UUID 00020002-78fc-48fe-8e23-433b3a1942d0) +The current raw motion values. This is a 3 `int16_t` array: + + - [0] : X + - [1] : Y + - [2] : Z diff --git a/doc/ble.md b/doc/ble.md index 518b99c..89ad877 100644 --- a/doc/ble.md +++ b/doc/ble.md @@ -29,14 +29,15 @@ When the service does not exist in the BLE specification, InfiniTime implement c The following custom services are implemented in InfiniTime: - Since InfiniTime 0.8: - ``` - * Music Service : 00000000-78fc-48fe-8e23-433b3a1942d0 - ``` - + * Music Service : 00000000-78fc-48fe-8e23-433b3a1942d0 + + - Since InfiniTime 0.11: - ``` - * Navigation Service : 00010000-78fc-48fe-8e23-433b3a1942d0 - ``` + * [Navigation Service](NavigationService.md) : 00010000-78fc-48fe-8e23-433b3a1942d0 + + + - Since InfiniTime 1.7: + * [Motion Service](MotionService.md) : 00020000-78fc-48fe-8e23-433b3a1942d0 ## BLE services [List of standard BLE services](https://www.bluetooth.com/specifications/gatt/services/) -- cgit v0.10.2 From 2c5015add7a67f950e7f5f33e5bc84b7275b4ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 17 Oct 2021 08:42:49 +0200 Subject: Enable/disable notifications for motion service. diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index 09a9b99..1bcae1b 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -221,12 +221,15 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) { if(event->subscribe.reason == BLE_GAP_SUBSCRIBE_REASON_TERM) { heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + motionService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); } else if(event->subscribe.prev_notify == 0 && event->subscribe.cur_notify == 1) { heartRateService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + motionService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); } else if(event->subscribe.prev_notify == 1 && event->subscribe.cur_notify == 0) { heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); + motionService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle); } break; -- cgit v0.10.2 From b0c4ade926dfde0fc985ca6560fed9ff76d8c9fc Mon Sep 17 00:00:00 2001 From: stephanie-eng Date: Mon, 18 Oct 2021 00:35:47 -0400 Subject: Fixed Apps tutorial to compile properly Changed case in minimal example to properly reference Pinetime namespace diff --git a/doc/code/Apps.md b/doc/code/Apps.md index b3bab04..355b44b 100644 --- a/doc/code/Apps.md +++ b/doc/code/Apps.md @@ -51,7 +51,7 @@ MyApp.h: #include "displayapp/screens/Screen.h" #include -namespace PineTime { +namespace Pinetime { namespace Applications { namespace Screens { class MyApp : public Screen { -- cgit v0.10.2 From 86bcea9e99ac8f68251ca615320478f75a29aca9 Mon Sep 17 00:00:00 2001 From: NeroBurner Date: Mon, 18 Oct 2021 08:08:43 +0200 Subject: CI: add pintime-recovery to build jobs The recovery image "it is the last chance before a brick", as described in https://github.com/InfiniTimeOrg/InfiniTime/issues/742#issuecomment-943665960 So just build it to make sure it doesn't silently break, but don't upload it. diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bd24359..3b753a3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -153,6 +153,14 @@ jobs: name: pinetime-app.out path: build/src/pinetime-app*.out + ######################################################################################### + # Make but don't Upload the Recovery Firmware to be sure it builds correctly + + - name: Make pinetime-recovery + run: | + cd build + make pinetime-recovery + ######################################################################################### # Finish -- cgit v0.10.2 From 02d52d94d524d421043ff3b46dcc753051c7b5f7 Mon Sep 17 00:00:00 2001 From: Stephanie Date: Mon, 18 Oct 2021 12:18:35 -0400 Subject: Added missing semicolon diff --git a/doc/code/Apps.md b/doc/code/Apps.md index 355b44b..7c2d7a0 100644 --- a/doc/code/Apps.md +++ b/doc/code/Apps.md @@ -58,7 +58,7 @@ namespace Pinetime { public: MyApp(DisplayApp* app); ~MyApp() override; - } + }; } } } -- cgit v0.10.2 From e2d8397c0864c71e1dcf9afbdd9fdc5edc84132d Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Wed, 20 Oct 2021 15:37:56 +0300 Subject: Fix issue templates diff --git a/.github/ISSUE_TEMPLATE/bug-report.yaml b/.github/ISSUE_TEMPLATE/bug-report.yaml index efcba56..f0fb076 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yaml +++ b/.github/ISSUE_TEMPLATE/bug-report.yaml @@ -1,6 +1,5 @@ name: Bug Report description: File a bug report -title: "[Bug]: " labels: ["bug"] body: - type: markdown diff --git a/.github/ISSUE_TEMPLATE/feature-request.yaml b/.github/ISSUE_TEMPLATE/feature-request.yaml index 092ef90..26e4fa0 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yaml +++ b/.github/ISSUE_TEMPLATE/feature-request.yaml @@ -1,6 +1,5 @@ name: Feature Request description: File a feature request -title: "" labels: ["feature request"] body: - type: markdown -- cgit v0.10.2 From 76234de7d6aa997a892a8d845013d673ab4d3bcb Mon Sep 17 00:00:00 2001 From: Avamander Date: Wed, 20 Oct 2021 16:41:48 +0300 Subject: Fixed the feature request template diff --git a/.github/ISSUE_TEMPLATE/feature-request.yaml b/.github/ISSUE_TEMPLATE/feature-request.yaml index 092ef90..26e4fa0 100644 --- a/.github/ISSUE_TEMPLATE/feature-request.yaml +++ b/.github/ISSUE_TEMPLATE/feature-request.yaml @@ -1,6 +1,5 @@ name: Feature Request description: File a feature request -title: "" labels: ["feature request"] body: - type: markdown -- cgit v0.10.2 From b3a82288997556b04a64d452ec2067747f1fb706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Wed, 20 Oct 2021 20:52:04 +0200 Subject: Add mention to Call characteristic (which was missing in the doc) and change the UUID of the new Motion service from 00020000-* to 00030000-*. diff --git a/doc/ble.md b/doc/ble.md index 89ad877..8125e98 100644 --- a/doc/ble.md +++ b/doc/ble.md @@ -34,10 +34,14 @@ The following custom services are implemented in InfiniTime: - Since InfiniTime 0.11: * [Navigation Service](NavigationService.md) : 00010000-78fc-48fe-8e23-433b3a1942d0 + + + - Since InfiniTime 0.13 + * Call characteristic (extension to the Alert Notification Service): 00020001-78fc-48fe-8e23-433b3a1942d0 - Since InfiniTime 1.7: - * [Motion Service](MotionService.md) : 00020000-78fc-48fe-8e23-433b3a1942d0 + * [Motion Service](MotionService.md) : 00030000-78fc-48fe-8e23-433b3a1942d0 ## BLE services [List of standard BLE services](https://www.bluetooth.com/specifications/gatt/services/) diff --git a/src/components/ble/MotionService.cpp b/src/components/ble/MotionService.cpp index 2bb5289..e305021 100644 --- a/src/components/ble/MotionService.cpp +++ b/src/components/ble/MotionService.cpp @@ -9,7 +9,7 @@ namespace { constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) { return ble_uuid128_t{ .u = {.type = BLE_UUID_TYPE_128}, - .value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x02, 0x00 } + .value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00 } }; } -- cgit v0.10.2 From dcd209a3d1370a30fd27fd51a527b1eb6cf92480 Mon Sep 17 00:00:00 2001 From: xan-m <88455615+xan-m@users.noreply.github.com> Date: Thu, 21 Oct 2021 10:15:21 -0700 Subject: Changed name of iOS companion app I had to remove iOS from the app name, so this update changes the name and link here to reflect that change diff --git a/README.md b/README.md index 6719aa3..765aa86 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ As of now, here is the list of achievements of this project: * [Amazfish](https://openrepos.net/content/piggz/amazfish) (on SailfishOS and Linux) * [Siglo](https://github.com/alexr4535/siglo) (on Linux) * **[Experimental]** [WebBLEWatch](https://hubmartin.github.io/WebBLEWatch/) Synchronize time directly from your web browser. [video](https://youtu.be/IakiuhVDdrY) - * **[Experimental]** [Infini-iOS](https://github.com/xan-m/Infini-iOS) (on iOS) + * **[Experimental]** [InfiniLink](https://github.com/xan-m/InfiniLink) (on iOS) - OTA (Over-the-air) update via BLE - [Bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader) based on [MCUBoot](https://www.mcuboot.com) -- cgit v0.10.2 From f56bd4ce9de35edc0c9fb178c950f26c80d99b94 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 22 Oct 2021 12:42:06 +0300 Subject: Update coding style diff --git a/doc/contribute.md b/doc/contribute.md index 2174643..595a599 100644 --- a/doc/contribute.md +++ b/doc/contribute.md @@ -94,3 +94,10 @@ If there are no preconfigured rules for your IDE, you can use one of the existin - **Includes** : - files from the project : `#include "relative/path/to/the/file.h"` - external files and std : `#include ` + - Only use [primary spellings for operators and tokens](https://en.cppreference.com/w/cpp/language/operator_alternative) + - Use auto sparingly. Don't use auto for [fundamental/built-in types](https://en.cppreference.com/w/cpp/language/types) and [fixed width integer types](https://en.cppreference.com/w/cpp/types/integer), except when initializing with a cast to avoid duplicating the type name. + - Examples: + - `auto* app = static_cast(instance);` + - `auto number = static_cast(variable);` + - `uint8_t returnValue = MyFunction();` + - Use nullptr instead of NULL -- cgit v0.10.2 From d5dfa8087679b644c13e1d420b8ef2fc894b3b51 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 25 Oct 2021 12:53:14 +0300 Subject: Newer buttonhandler diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a839e08..e727b2b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -507,6 +507,7 @@ list(APPEND SOURCE_FILES components/heartrate/Ptagc.cpp components/heartrate/HeartRateController.cpp + buttonhandler/ButtonHandler.cpp touchhandler/TouchHandler.cpp ) @@ -567,6 +568,7 @@ list(APPEND RECOVERY_SOURCE_FILES components/heartrate/Ptagc.cpp components/motor/MotorController.cpp components/fs/FS.cpp + buttonhandler/ButtonHandler.cpp touchhandler/TouchHandler.cpp ) @@ -681,6 +683,7 @@ set(INCLUDE_FILES components/heartrate/Ptagc.h components/heartrate/HeartRateController.h components/motor/MotorController.h + buttonhandler/ButtonHandler.h touchhandler/TouchHandler.h ) diff --git a/src/buttonhandler/ButtonHandler.cpp b/src/buttonhandler/ButtonHandler.cpp new file mode 100644 index 0000000..997409e --- /dev/null +++ b/src/buttonhandler/ButtonHandler.cpp @@ -0,0 +1,85 @@ +#include "ButtonHandler.h" + +using namespace Pinetime::Controllers; + +void ButtonTimerCallback(TimerHandle_t xTimer) { + auto* buttonHandler = static_cast(pvTimerGetTimerID(xTimer)); + buttonHandler->HandleEvent(ButtonHandler::Timer); +} + +void ButtonHandler::Init(Pinetime::System::SystemTask* systemTask) { + this->systemTask = systemTask; + buttonTimer = xTimerCreate("buttonTimer", 0, pdFALSE, this, ButtonTimerCallback); +} + +void ButtonHandler::HandleEvent(events event) { + static constexpr TickType_t doubleClickTime = pdMS_TO_TICKS(200); + static constexpr TickType_t longPressTime = pdMS_TO_TICKS(400); + static constexpr TickType_t longerPressTime = pdMS_TO_TICKS(2000); + + if (systemTask->IsSleeping()) { + // This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping + systemTask->PushMessage(System::Messages::GoToRunning); + } else { + systemTask->PushMessage(System::Messages::ReloadIdleTimer); + } + + if (event == Press) { + buttonPressed = true; + } else if (event == Release) { + releaseTime = xTaskGetTickCount(); + buttonPressed = false; + } + + switch (state) { + case Idle: + if (event == Press) { + xTimerChangePeriod(buttonTimer, doubleClickTime, 0); + xTimerStart(buttonTimer, 0); + state = Pressed; + } + break; + case Pressed: + if (event == Press) { + if (xTaskGetTickCount() - releaseTime < doubleClickTime) { + systemTask->PushMessage(System::Messages::OnButtonDoubleClicked); + xTimerStop(buttonTimer, 0); + state = Idle; + } + } else if (event == Release) { + xTimerChangePeriod(buttonTimer, doubleClickTime, 0); + xTimerStart(buttonTimer, 0); + } else if (event == Timer) { + if (buttonPressed) { + xTimerChangePeriod(buttonTimer, longPressTime - doubleClickTime, 0); + xTimerStart(buttonTimer, 0); + state = Holding; + } else { + systemTask->PushMessage(System::Messages::OnButtonPushed); + state = Idle; + } + } + break; + case Holding: + if (event == Release) { + systemTask->PushMessage(System::Messages::OnButtonPushed); + xTimerStop(buttonTimer, 0); + state = Idle; + } else if (event == Timer) { + xTimerChangePeriod(buttonTimer, longerPressTime - longPressTime - doubleClickTime, 0); + xTimerStart(buttonTimer, 0); + systemTask->PushMessage(System::Messages::OnButtonLongPressed); + state = LongHeld; + } + break; + case LongHeld: + if (event == Release) { + xTimerStop(buttonTimer, 0); + state = Idle; + } else if (event == Timer) { + systemTask->PushMessage(System::Messages::OnButtonLongerPressed); + state = Idle; + } + break; + } +} diff --git a/src/buttonhandler/ButtonHandler.h b/src/buttonhandler/ButtonHandler.h new file mode 100644 index 0000000..5d5b57e --- /dev/null +++ b/src/buttonhandler/ButtonHandler.h @@ -0,0 +1,24 @@ +#pragma once + +#include "systemtask/SystemTask.h" +#include +#include + +namespace Pinetime { + namespace Controllers { + class ButtonHandler { + public: + enum events { Press, Release, Timer }; + void Init(Pinetime::System::SystemTask* systemTask); + void HandleEvent(events event); + + private: + Pinetime::System::SystemTask* systemTask = nullptr; + TickType_t releaseTime = 0; + TimerHandle_t buttonTimer; + bool buttonPressed = false; + enum states { Idle, Pressed, Holding, LongHeld }; + states state = Idle; + }; + } +} diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index abe5851..13ee004 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -260,6 +260,20 @@ void DisplayApp::Refresh() { } } break; + case Messages::ButtonLongPressed: + if (currentApp != Apps::Clock) { + LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::Down); + } + break; + case Messages::ButtonLongerPressed: + // Create reboot app and open it instead + LoadApp(Apps::SysInfo, DisplayApp::FullRefreshDirections::Up); + break; + case Messages::ButtonDoubleClicked: + if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) { + LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down); + } + break; case Messages::BleFirmwareUpdateStarted: LoadApp(Apps::FirmwareUpdate, DisplayApp::FullRefreshDirections::Down); diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h index d48b646..ab0a060 100644 --- a/src/displayapp/Messages.h +++ b/src/displayapp/Messages.h @@ -9,6 +9,9 @@ namespace Pinetime { UpdateBleConnection, TouchEvent, ButtonPushed, + ButtonLongPressed, + ButtonLongerPressed, + ButtonDoubleClicked, NewNotification, TimerDone, BleFirmwareUpdateStarted, diff --git a/src/main.cpp b/src/main.cpp index fc77235..b942fd4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,7 @@ #include "systemtask/SystemTask.h" #include "drivers/PinMap.h" #include "touchhandler/TouchHandler.h" +#include "buttonhandler/ButtonHandler.h" #if NRF_LOG_ENABLED #include "logging/NrfLogger.h" @@ -96,8 +97,6 @@ TimerHandle_t debounceTimer; TimerHandle_t debounceChargeTimer; Pinetime::Controllers::Battery batteryController; Pinetime::Controllers::Ble bleController; -static constexpr uint8_t pinTouchIrq = Pinetime::PinMap::Cst816sIrq; -static constexpr uint8_t pinPowerPresentIrq = Pinetime::PinMap::PowerPresent; Pinetime::Controllers::HeartRateController heartRateController; Pinetime::Applications::HeartRateTask heartRateApp(heartRateSensor, heartRateController); @@ -110,6 +109,7 @@ Pinetime::Controllers::MotionController motionController; Pinetime::Controllers::TimerController timerController; Pinetime::Controllers::AlarmController alarmController {dateTimeController}; Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl); +Pinetime::Controllers::ButtonHandler buttonHandler; Pinetime::Controllers::FS fs {spiNorFlash}; Pinetime::Controllers::Settings settingsController {fs}; @@ -153,7 +153,8 @@ Pinetime::System::SystemTask systemTask(spi, displayApp, heartRateApp, fs, - touchHandler); + touchHandler, + buttonHandler); /* Variable Declarations for variables in noinit SRAM Increment NoInit_MagicValue upon adding variables to this area @@ -176,11 +177,11 @@ void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action if (pin == Pinetime::PinMap::PowerPresent and action == NRF_GPIOTE_POLARITY_TOGGLE) { xTimerStartFromISR(debounceChargeTimer, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - return; + } else if (pin == Pinetime::PinMap::Button) { + // This activates on button release as well due to bouncing + xTimerStartFromISR(debounceTimer, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } - - xTimerStartFromISR(debounceTimer, &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } void DebounceTimerChargeCallback(TimerHandle_t xTimer) { @@ -188,9 +189,8 @@ void DebounceTimerChargeCallback(TimerHandle_t xTimer) { systemTask.PushMessage(Pinetime::System::Messages::OnChargingEvent); } -void DebounceTimerCallback(TimerHandle_t xTimer) { - xTimerStop(xTimer, 0); - systemTask.OnButtonPushed(); +void DebounceTimerCallback(TimerHandle_t /*unused*/) { + systemTask.PushMessage(Pinetime::System::Messages::HandleButtonEvent); } void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) { @@ -319,8 +319,8 @@ int main(void) { } nrf_gpio_cfg_default(Pinetime::PinMap::TwiScl); - debounceTimer = xTimerCreate("debounceTimer", 200, pdFALSE, (void*) 0, DebounceTimerCallback); - debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, (void*) 0, DebounceTimerChargeCallback); + debounceTimer = xTimerCreate("debounceTimer", 10, pdFALSE, nullptr, DebounceTimerCallback); + debounceChargeTimer = xTimerCreate("debounceTimerCharge", 200, pdFALSE, nullptr, DebounceTimerChargeCallback); // retrieve version stored by bootloader Pinetime::BootloaderVersion::SetVersion(NRF_TIMER2->CC[0]); diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index 5aa218d..b0bdbf3 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -15,12 +15,17 @@ namespace Pinetime { BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, - OnButtonEvent, + OnButtonPushed, + OnButtonLongPressed, + OnButtonLongerPressed, + OnButtonDoubleClicked, + HandleButtonEvent, OnDisplayTaskSleeping, EnableSleeping, DisableSleeping, OnNewDay, OnChargingEvent, + ReloadIdleTimer, SetOffAlarm, StopRinging, MeasureBatteryTimerExpired, diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index e0a5907..b7db0b9 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -25,7 +25,6 @@ #include "main.h" #include "BootErrors.h" - #include using namespace Pinetime::System; @@ -77,7 +76,8 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, Pinetime::Applications::DisplayApp& displayApp, Pinetime::Applications::HeartRateTask& heartRateApp, Pinetime::Controllers::FS& fs, - Pinetime::Controllers::TouchHandler& touchHandler) + Pinetime::Controllers::TouchHandler& touchHandler, + Pinetime::Controllers::ButtonHandler& buttonHandler) : spi {spi}, lcd {lcd}, spiNorFlash {spiNorFlash}, @@ -101,8 +101,15 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, heartRateApp(heartRateApp), fs {fs}, touchHandler {touchHandler}, - nimbleController(*this, bleController, dateTimeController, notificationManager, - batteryController, spiNorFlash, heartRateController, motionController) { + buttonHandler {buttonHandler}, + nimbleController(*this, + bleController, + dateTimeController, + notificationManager, + batteryController, + spiNorFlash, + heartRateController, + motionController) { } void SystemTask::Start() { @@ -163,6 +170,8 @@ void SystemTask::Work() { heartRateSensor.Disable(); heartRateApp.Start(); + buttonHandler.Init(this); + // Button nrf_gpio_cfg_output(15); nrf_gpio_pin_set(15); @@ -326,9 +335,32 @@ void SystemTask::Work() { ReloadIdleTimer(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); break; - case Messages::OnButtonEvent: - ReloadIdleTimer(); - displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed); + case Messages::OnButtonPushed: + if (!isSleeping && !isGoingToSleep) { + displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed); + } + break; + case Messages::OnButtonLongPressed: + if (!isSleeping) { + displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonLongPressed); + } + break; + case Messages::OnButtonLongerPressed: + if (!isSleeping) { + displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonLongerPressed); + } + break; + case Messages::OnButtonDoubleClicked: + if (!isSleeping) { + displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonDoubleClicked); + } + break; + case Messages::HandleButtonEvent: + if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) { + buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Release); + } else { + buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Press); + } break; case Messages::OnDisplayTaskSleeping: if (BootloaderVersion::IsValid()) { @@ -366,6 +398,9 @@ void SystemTask::Work() { case Messages::BatteryPercentageUpdated: nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); break; + case Messages::ReloadIdleTimer: + ReloadIdleTimer(); + break; default: break; @@ -414,20 +449,6 @@ void SystemTask::UpdateMotion() { } } -void SystemTask::OnButtonPushed() { - if (isGoingToSleep) - return; - if (!isSleeping) { - NRF_LOG_INFO("[systemtask] Button pushed"); - PushMessage(Messages::OnButtonEvent); - } else { - if (!isWakingUp) { - NRF_LOG_INFO("[systemtask] Button pushed, waking up"); - GoToRunning(); - } - } -} - void SystemTask::GoToRunning() { if (isGoingToSleep or (not isSleeping) or isWakingUp) return; diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 879c1be..9967f75 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -20,6 +20,7 @@ #include "components/alarm/AlarmController.h" #include "components/fs/FS.h" #include "touchhandler/TouchHandler.h" +#include "buttonhandler/ButtonHandler.h" #ifdef PINETIME_IS_RECOVERY #include "displayapp/DisplayAppRecovery.h" @@ -45,6 +46,7 @@ namespace Pinetime { } namespace Controllers { class TouchHandler; + class ButtonHandler; } namespace System { class SystemTask { @@ -71,12 +73,12 @@ namespace Pinetime { Pinetime::Applications::DisplayApp& displayApp, Pinetime::Applications::HeartRateTask& heartRateApp, Pinetime::Controllers::FS& fs, - Pinetime::Controllers::TouchHandler& touchHandler); + Pinetime::Controllers::TouchHandler& touchHandler, + Pinetime::Controllers::ButtonHandler& buttonHandler); void Start(); void PushMessage(Messages msg); - void OnButtonPushed(); void OnTouchEvent(); void OnIdle(); @@ -123,6 +125,7 @@ namespace Pinetime { Pinetime::Applications::HeartRateTask& heartRateApp; Pinetime::Controllers::FS& fs; Pinetime::Controllers::TouchHandler& touchHandler; + Pinetime::Controllers::ButtonHandler& buttonHandler; Pinetime::Controllers::NimbleController nimbleController; static void Process(void* instance); -- cgit v0.10.2 From b19a2a760b74f27c8d3db262bf43437f722f74bd Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 25 Oct 2021 13:40:43 +0300 Subject: Use enum classes, remove old comment diff --git a/src/buttonhandler/ButtonHandler.cpp b/src/buttonhandler/ButtonHandler.cpp index 997409e..b6067d2 100644 --- a/src/buttonhandler/ButtonHandler.cpp +++ b/src/buttonhandler/ButtonHandler.cpp @@ -4,7 +4,7 @@ using namespace Pinetime::Controllers; void ButtonTimerCallback(TimerHandle_t xTimer) { auto* buttonHandler = static_cast(pvTimerGetTimerID(xTimer)); - buttonHandler->HandleEvent(ButtonHandler::Timer); + buttonHandler->HandleEvent(ButtonHandler::Events::Timer); } void ButtonHandler::Init(Pinetime::System::SystemTask* systemTask) { @@ -12,7 +12,7 @@ void ButtonHandler::Init(Pinetime::System::SystemTask* systemTask) { buttonTimer = xTimerCreate("buttonTimer", 0, pdFALSE, this, ButtonTimerCallback); } -void ButtonHandler::HandleEvent(events event) { +void ButtonHandler::HandleEvent(Events event) { static constexpr TickType_t doubleClickTime = pdMS_TO_TICKS(200); static constexpr TickType_t longPressTime = pdMS_TO_TICKS(400); static constexpr TickType_t longerPressTime = pdMS_TO_TICKS(2000); @@ -24,61 +24,61 @@ void ButtonHandler::HandleEvent(events event) { systemTask->PushMessage(System::Messages::ReloadIdleTimer); } - if (event == Press) { + if (event == Events::Press) { buttonPressed = true; - } else if (event == Release) { + } else if (event == Events::Release) { releaseTime = xTaskGetTickCount(); buttonPressed = false; } switch (state) { - case Idle: - if (event == Press) { + case States::Idle: + if (event == Events::Press) { xTimerChangePeriod(buttonTimer, doubleClickTime, 0); xTimerStart(buttonTimer, 0); - state = Pressed; + state = States::Pressed; } break; - case Pressed: - if (event == Press) { + case States::Pressed: + if (event == Events::Press) { if (xTaskGetTickCount() - releaseTime < doubleClickTime) { systemTask->PushMessage(System::Messages::OnButtonDoubleClicked); xTimerStop(buttonTimer, 0); - state = Idle; + state = States::Idle; } - } else if (event == Release) { + } else if (event == Events::Release) { xTimerChangePeriod(buttonTimer, doubleClickTime, 0); xTimerStart(buttonTimer, 0); - } else if (event == Timer) { + } else if (event == Events::Timer) { if (buttonPressed) { xTimerChangePeriod(buttonTimer, longPressTime - doubleClickTime, 0); xTimerStart(buttonTimer, 0); - state = Holding; + state = States::Holding; } else { systemTask->PushMessage(System::Messages::OnButtonPushed); - state = Idle; + state = States::Idle; } } break; - case Holding: - if (event == Release) { + case States::Holding: + if (event == Events::Release) { systemTask->PushMessage(System::Messages::OnButtonPushed); xTimerStop(buttonTimer, 0); - state = Idle; - } else if (event == Timer) { + state = States::Idle; + } else if (event == Events::Timer) { xTimerChangePeriod(buttonTimer, longerPressTime - longPressTime - doubleClickTime, 0); xTimerStart(buttonTimer, 0); systemTask->PushMessage(System::Messages::OnButtonLongPressed); - state = LongHeld; + state = States::LongHeld; } break; - case LongHeld: - if (event == Release) { + case States::LongHeld: + if (event == Events::Release) { xTimerStop(buttonTimer, 0); - state = Idle; - } else if (event == Timer) { + state = States::Idle; + } else if (event == Events::Timer) { systemTask->PushMessage(System::Messages::OnButtonLongerPressed); - state = Idle; + state = States::Idle; } break; } diff --git a/src/buttonhandler/ButtonHandler.h b/src/buttonhandler/ButtonHandler.h index 5d5b57e..b4c36bd 100644 --- a/src/buttonhandler/ButtonHandler.h +++ b/src/buttonhandler/ButtonHandler.h @@ -8,17 +8,17 @@ namespace Pinetime { namespace Controllers { class ButtonHandler { public: - enum events { Press, Release, Timer }; + enum class Events : uint8_t { Press, Release, Timer }; void Init(Pinetime::System::SystemTask* systemTask); - void HandleEvent(events event); + void HandleEvent(Events event); private: + enum class States : uint8_t { Idle, Pressed, Holding, LongHeld }; Pinetime::System::SystemTask* systemTask = nullptr; TickType_t releaseTime = 0; TimerHandle_t buttonTimer; bool buttonPressed = false; - enum states { Idle, Pressed, Holding, LongHeld }; - states state = Idle; + States state = States::Idle; }; } } diff --git a/src/main.cpp b/src/main.cpp index b942fd4..53f78ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -178,7 +178,6 @@ void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action xTimerStartFromISR(debounceChargeTimer, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } else if (pin == Pinetime::PinMap::Button) { - // This activates on button release as well due to bouncing xTimerStartFromISR(debounceTimer, &xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken); } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index b7db0b9..8a4f894 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -357,9 +357,9 @@ void SystemTask::Work() { break; case Messages::HandleButtonEvent: if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) { - buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Release); + buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Events::Release); } else { - buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Press); + buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Events::Press); } break; case Messages::OnDisplayTaskSleeping: -- cgit v0.10.2 From 351c60a13167c05dfdbb0516f84077a4cd6adeec Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 25 Oct 2021 16:57:29 +0300 Subject: Return button action instead of pushing messages diff --git a/src/buttonhandler/ButtonActions.h b/src/buttonhandler/ButtonActions.h new file mode 100644 index 0000000..21be441 --- /dev/null +++ b/src/buttonhandler/ButtonActions.h @@ -0,0 +1,7 @@ +#pragma once + +namespace Pinetime { + namespace Controllers { + enum class ButtonActions { None, Click, DoubleClick, LongPress, LongerPress }; + } +} diff --git a/src/buttonhandler/ButtonHandler.cpp b/src/buttonhandler/ButtonHandler.cpp index b6067d2..91e8bbd 100644 --- a/src/buttonhandler/ButtonHandler.cpp +++ b/src/buttonhandler/ButtonHandler.cpp @@ -3,27 +3,19 @@ using namespace Pinetime::Controllers; void ButtonTimerCallback(TimerHandle_t xTimer) { - auto* buttonHandler = static_cast(pvTimerGetTimerID(xTimer)); - buttonHandler->HandleEvent(ButtonHandler::Events::Timer); + auto* sysTask = static_cast(pvTimerGetTimerID(xTimer)); + sysTask->PushMessage(Pinetime::System::Messages::HandleButtonTimerEvent); } void ButtonHandler::Init(Pinetime::System::SystemTask* systemTask) { - this->systemTask = systemTask; - buttonTimer = xTimerCreate("buttonTimer", 0, pdFALSE, this, ButtonTimerCallback); + buttonTimer = xTimerCreate("buttonTimer", 0, pdFALSE, systemTask, ButtonTimerCallback); } -void ButtonHandler::HandleEvent(Events event) { +ButtonActions ButtonHandler::HandleEvent(Events event) { static constexpr TickType_t doubleClickTime = pdMS_TO_TICKS(200); static constexpr TickType_t longPressTime = pdMS_TO_TICKS(400); static constexpr TickType_t longerPressTime = pdMS_TO_TICKS(2000); - if (systemTask->IsSleeping()) { - // This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping - systemTask->PushMessage(System::Messages::GoToRunning); - } else { - systemTask->PushMessage(System::Messages::ReloadIdleTimer); - } - if (event == Events::Press) { buttonPressed = true; } else if (event == Events::Release) { @@ -42,9 +34,9 @@ void ButtonHandler::HandleEvent(Events event) { case States::Pressed: if (event == Events::Press) { if (xTaskGetTickCount() - releaseTime < doubleClickTime) { - systemTask->PushMessage(System::Messages::OnButtonDoubleClicked); xTimerStop(buttonTimer, 0); state = States::Idle; + return ButtonActions::DoubleClick; } } else if (event == Events::Release) { xTimerChangePeriod(buttonTimer, doubleClickTime, 0); @@ -55,21 +47,21 @@ void ButtonHandler::HandleEvent(Events event) { xTimerStart(buttonTimer, 0); state = States::Holding; } else { - systemTask->PushMessage(System::Messages::OnButtonPushed); state = States::Idle; + return ButtonActions::Click; } } break; case States::Holding: if (event == Events::Release) { - systemTask->PushMessage(System::Messages::OnButtonPushed); xTimerStop(buttonTimer, 0); state = States::Idle; + return ButtonActions::Click; } else if (event == Events::Timer) { xTimerChangePeriod(buttonTimer, longerPressTime - longPressTime - doubleClickTime, 0); xTimerStart(buttonTimer, 0); - systemTask->PushMessage(System::Messages::OnButtonLongPressed); state = States::LongHeld; + return ButtonActions::LongPress; } break; case States::LongHeld: @@ -77,9 +69,10 @@ void ButtonHandler::HandleEvent(Events event) { xTimerStop(buttonTimer, 0); state = States::Idle; } else if (event == Events::Timer) { - systemTask->PushMessage(System::Messages::OnButtonLongerPressed); state = States::Idle; + return ButtonActions::LongerPress; } break; } + return ButtonActions::None; } diff --git a/src/buttonhandler/ButtonHandler.h b/src/buttonhandler/ButtonHandler.h index b4c36bd..44b20f1 100644 --- a/src/buttonhandler/ButtonHandler.h +++ b/src/buttonhandler/ButtonHandler.h @@ -1,5 +1,6 @@ #pragma once +#include "ButtonActions.h" #include "systemtask/SystemTask.h" #include #include @@ -10,11 +11,10 @@ namespace Pinetime { public: enum class Events : uint8_t { Press, Release, Timer }; void Init(Pinetime::System::SystemTask* systemTask); - void HandleEvent(Events event); + ButtonActions HandleEvent(Events event); private: enum class States : uint8_t { Idle, Pressed, Holding, LongHeld }; - Pinetime::System::SystemTask* systemTask = nullptr; TickType_t releaseTime = 0; TimerHandle_t buttonTimer; bool buttonPressed = false; diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index b0bdbf3..b714270 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -15,17 +15,13 @@ namespace Pinetime { BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, - OnButtonPushed, - OnButtonLongPressed, - OnButtonLongerPressed, - OnButtonDoubleClicked, HandleButtonEvent, + HandleButtonTimerEvent, OnDisplayTaskSleeping, EnableSleeping, DisableSleeping, OnNewDay, OnChargingEvent, - ReloadIdleTimer, SetOffAlarm, StopRinging, MeasureBatteryTimerExpired, diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 8a4f894..85cefb6 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -335,33 +335,25 @@ void SystemTask::Work() { ReloadIdleTimer(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); break; - case Messages::OnButtonPushed: - if (!isSleeping && !isGoingToSleep) { - displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed); - } - break; - case Messages::OnButtonLongPressed: - if (!isSleeping) { - displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonLongPressed); - } - break; - case Messages::OnButtonLongerPressed: - if (!isSleeping) { - displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonLongerPressed); - } - break; - case Messages::OnButtonDoubleClicked: - if (!isSleeping) { - displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonDoubleClicked); + case Messages::HandleButtonEvent: { + // This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping + if (IsSleeping()) { + GoToRunning(); + break; } - break; - case Messages::HandleButtonEvent: + + Controllers::ButtonActions action; if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) { - buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Events::Release); + action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release); } else { - buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Events::Press); + action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press); } - break; + HandleButtonAction(action); + } break; + case Messages::HandleButtonTimerEvent: { + auto action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Timer); + HandleButtonAction(action); + } break; case Messages::OnDisplayTaskSleeping: if (BootloaderVersion::IsValid()) { // First versions of the bootloader do not expose their version and cannot initialize the SPI NOR FLASH @@ -398,9 +390,6 @@ void SystemTask::Work() { case Messages::BatteryPercentageUpdated: nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); break; - case Messages::ReloadIdleTimer: - ReloadIdleTimer(); - break; default: break; @@ -449,6 +438,35 @@ void SystemTask::UpdateMotion() { } } +void SystemTask::HandleButtonAction(Controllers::ButtonActions action) { + if (IsSleeping()) { + return; + } + + ReloadIdleTimer(); + + using Actions = Controllers::ButtonActions; + + switch (action) { + case Actions::Click: + if (!isGoingToSleep) { + displayApp.PushMessage(Applications::Display::Messages::ButtonPushed); + } + break; + case Actions::DoubleClick: + displayApp.PushMessage(Applications::Display::Messages::ButtonDoubleClicked); + break; + case Actions::LongPress: + displayApp.PushMessage(Applications::Display::Messages::ButtonLongPressed); + break; + case Actions::LongerPress: + displayApp.PushMessage(Applications::Display::Messages::ButtonLongerPressed); + break; + default: + break; + } +} + void SystemTask::GoToRunning() { if (isGoingToSleep or (not isSleeping) or isWakingUp) return; diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 9967f75..d6045e9 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -21,6 +21,7 @@ #include "components/fs/FS.h" #include "touchhandler/TouchHandler.h" #include "buttonhandler/ButtonHandler.h" +#include "buttonhandler/ButtonActions.h" #ifdef PINETIME_IS_RECOVERY #include "displayapp/DisplayAppRecovery.h" @@ -138,6 +139,7 @@ namespace Pinetime { TimerHandle_t measureBatteryTimer; bool doNotGoToSleep = false; + void HandleButtonAction(Controllers::ButtonActions action); void GoToRunning(); void UpdateMotion(); bool stepCounterMustBeReset = false; -- cgit v0.10.2 From 887c409b135bb2f21f2fb5ae70a4d8831049d14d Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 25 Oct 2021 17:13:02 +0300 Subject: Only wake up on press. Fixes issue with longer press and sleep diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 85cefb6..51dbc3e 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -337,15 +337,14 @@ void SystemTask::Work() { break; case Messages::HandleButtonEvent: { // This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping - if (IsSleeping()) { - GoToRunning(); - break; - } - Controllers::ButtonActions action; if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) { action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release); } else { + if (IsSleeping()) { + GoToRunning(); + break; + } action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press); } HandleButtonAction(action); -- cgit v0.10.2 From 60a717b1a2272e61dfc4d297998da1c7672a8316 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Mon, 25 Oct 2021 17:45:48 +0300 Subject: Make it so special actions can be input while sleeping, like in #480 diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 51dbc3e..0a3f995 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -336,16 +336,17 @@ void SystemTask::Work() { displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent); break; case Messages::HandleButtonEvent: { - // This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping Controllers::ButtonActions action; if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) { action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release); } else { + action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press); + // This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping if (IsSleeping()) { + fastWakeUpDone = true; GoToRunning(); break; } - action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press); } HandleButtonAction(action); } break; @@ -448,7 +449,8 @@ void SystemTask::HandleButtonAction(Controllers::ButtonActions action) { switch (action) { case Actions::Click: - if (!isGoingToSleep) { + // If the first action after fast wakeup is a click, it should be ignored. + if (!fastWakeUpDone && !isGoingToSleep) { displayApp.PushMessage(Applications::Display::Messages::ButtonPushed); } break; @@ -462,8 +464,10 @@ void SystemTask::HandleButtonAction(Controllers::ButtonActions action) { displayApp.PushMessage(Applications::Display::Messages::ButtonLongerPressed); break; default: - break; + return; } + + fastWakeUpDone = false; } void SystemTask::GoToRunning() { diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index d6045e9..412878b 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -140,6 +140,8 @@ namespace Pinetime { bool doNotGoToSleep = false; void HandleButtonAction(Controllers::ButtonActions action); + bool fastWakeUpDone = false; + void GoToRunning(); void UpdateMotion(); bool stepCounterMustBeReset = false; -- cgit v0.10.2 From 0fc081fe03eddae41c8824cb3a55c054b653bb15 Mon Sep 17 00:00:00 2001 From: Steveis Date: Tue, 26 Oct 2021 16:57:20 +0100 Subject: Correctly define DFU diff --git a/doc/gettingStarted/gettingStarted-1.0.md b/doc/gettingStarted/gettingStarted-1.0.md index 3f8f38f..409b7c7 100644 --- a/doc/gettingStarted/gettingStarted-1.0.md +++ b/doc/gettingStarted/gettingStarted-1.0.md @@ -12,7 +12,7 @@ Basically, a **firmware** is just a software running on the embedded hardware of - **[The bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader)** is responsible for safely applying **updates** of the *application firmware*, reverting them in case of issues and load the recovery firmware when requested. - **The recovery firmware** is a specific *application firmware* than can be loaded by the bootloader on user request. This firmware can be useful in case of serious issue, when the main application firmware cannot perform an OTA update correctly. Currently, this recovery firmware is based on [InfiniTime 0.14.1](https://github.com/InfiniTimeOrg/InfiniTime/releases/tag/0.14.1). -**OTA** and **DFU** refer to the update of the firmware over BLE (**B**luetooth **L**ow **E**nergy). **OTA** means **O**ver **T**he **A**ir, this is a functionality that allows the user to update the firmware how their device using a wireless communication like BLE. When we talk about **DFU** (**D**igital **F**irmware **U**pdate), we refer to the file format and protocol used to send the update of the firmware to the watch over-the-air. InfiniTime implement the (legacy) DFU protocol from Nordic Semiconductor (NRF). +**OTA** and **DFU** refer to the update of the firmware over BLE (**B**luetooth **L**ow **E**nergy). **OTA** means **O**ver **T**he **A**ir, this is a functionality that allows the user to update the firmware how their device using a wireless communication like BLE. When we talk about **DFU** (**D**evice **F**irmware **U**pdate), we refer to the file format and protocol used to send the update of the firmware to the watch over-the-air. InfiniTime implement the (legacy) DFU protocol from Nordic Semiconductor (NRF). ## How to check the version of InfiniTime and the bootloader? -- cgit v0.10.2 From 71ce13d3095febf9dcdb0ddc6ca03b515fd7d57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Tue, 26 Oct 2021 20:31:18 +0200 Subject: Motion service : fix step notifications that were sent as a single byte instead of 4 (uint32_t). diff --git a/src/components/ble/MotionService.cpp b/src/components/ble/MotionService.cpp index e305021..b4786ab 100644 --- a/src/components/ble/MotionService.cpp +++ b/src/components/ble/MotionService.cpp @@ -80,7 +80,7 @@ int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attr return 0; } -void MotionService::OnNewStepCountValue(uint8_t stepCount) { +void MotionService::OnNewStepCountValue(uint32_t stepCount) { if(!stepCountNoficationEnabled) return; uint32_t buffer = stepCount; diff --git a/src/components/ble/MotionService.h b/src/components/ble/MotionService.h index 75ad518..1b4ac0a 100644 --- a/src/components/ble/MotionService.h +++ b/src/components/ble/MotionService.h @@ -17,7 +17,7 @@ namespace Pinetime { MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController); void Init(); int OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context); - void OnNewStepCountValue(uint8_t stepCount); + void OnNewStepCountValue(uint32_t stepCount); void OnNewMotionValues(int16_t x, int16_t y, int16_t z); void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle); -- cgit v0.10.2 From e051504deaf4db166c08ec9693c575006ee12c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Thu, 28 Oct 2021 20:56:17 +0200 Subject: Add doc : how to generate files needed by the factory. diff --git a/doc/buildAndProgram.md b/doc/buildAndProgram.md index 3e000a3..3686871 100644 --- a/doc/buildAndProgram.md +++ b/doc/buildAndProgram.md @@ -231,3 +231,33 @@ Loading section .sec7, size 0xdf08 lma 0x40000 Start address 0x0, load size 314200 Transfer rate: 45 KB/sec, 969 bytes/write. ``` + +### How to generate files needed by the factory +These files are needed by the Pine64 factory to flash InfiniTime as the default firmware on the PineTimes. + +Two files are needed: an **HEX (.hex)** file that contains the content of the internal flash memory (bootloader + InfiniTime) and a **binary (.bin)** file that contains the content of the external flash memory (recovery firmware). + +#### merged-internal.hex +First, convert the bootloader to hex: + ``` + /bin/arm-none-eabi-objcopy -I binary -O ihex ./bootloader.bin ./bootloader.hex + ``` +where `bootloader.bin` is the [last stable version](https://github.com/JF002/pinetime-mcuboot-bootloader/releases) of the [bootloader](https://github.com/JF002/pinetime-mcuboot-bootloader). + +Then, convert the MCUBoot image of InfiniTime: +``` +/bin/arm-none-eabi-objcopy -I binary -O ihex --change-addresses 0x8000 ./pinetime-mcuboot-app-image-1.6.0.bin ./pinetime-mcuboot-app-image-1.6.0.hex +``` +where `pinetime-mcuboot-app-image-1.6.0.bin` is [the bin of the last MCUBoot image](https://github.com/InfiniTimeOrg/InfiniTime/releases) of [InfiniTime](https://github.com/InfiniTimeOrg/InfiniTime). + +Pay attention to the parameter `--change-addresses 0x8000`. It's needed to ensure the image will be flashed at the offset expected by the bootloader (0x8000). + +Finally, merge them together with **mergehex**: +``` +/opt/mergehex/mergehex -m ./bootloader.hex ./pinetime-mcuboot-app-image-1.6.0.hex -o merged-internal.hex +``` + +This file must be flashed at offset **0x00** of the internal memory of the NRF52832. + +#### spinor.bin +This file is the MCUBoot image of the last stable version of the recovery firmware. It must be flashed at offset **0x00** of the external SPINOR flash memory. \ No newline at end of file -- cgit v0.10.2 From 456084499464e242faf36606edada10ab6056939 Mon Sep 17 00:00:00 2001 From: "James A. Jerkins" Date: Thu, 28 Oct 2021 20:38:59 -0500 Subject: Fix recovery firmware build diff --git a/src/displayapp/DisplayAppRecovery.h b/src/displayapp/DisplayAppRecovery.h index 9f5fb13..7286815 100644 --- a/src/displayapp/DisplayAppRecovery.h +++ b/src/displayapp/DisplayAppRecovery.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include "BootErrors.h" #include "TouchEvents.h" #include "Apps.h" #include "Messages.h" -- cgit v0.10.2 From 30520d262b8bae9868645462e196027389dce246 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Fri, 29 Oct 2021 13:10:34 +0300 Subject: Memory savings by replacing strings diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 343b72b..dd223b2 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -209,7 +209,7 @@ std::unique_ptr SystemInfo::CreateScreen4() { static constexpr uint8_t maxTaskCount = 9; TaskStatus_t tasksStatus[maxTaskCount]; - lv_obj_t* infoTask = lv_table_create(lv_scr_act(), NULL); + lv_obj_t* infoTask = lv_table_create(lv_scr_act(), nullptr); lv_table_set_col_cnt(infoTask, 4); lv_table_set_row_cnt(infoTask, maxTaskCount + 1); lv_obj_set_style_local_pad_all(infoTask, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 0); @@ -227,35 +227,37 @@ std::unique_ptr SystemInfo::CreateScreen4() { auto nb = uxTaskGetSystemState(tasksStatus, maxTaskCount, nullptr); std::sort(tasksStatus, tasksStatus + nb, sortById); for (uint8_t i = 0; i < nb && i < maxTaskCount; i++) { + char buffer[7] = {0}; - lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str()); - char state[2] = {0}; + sprintf(buffer, "%lu", tasksStatus[i].xTaskNumber); + lv_table_set_cell_value(infoTask, i + 1, 0, buffer); switch (tasksStatus[i].eCurrentState) { case eReady: case eRunning: - state[0] = 'R'; + buffer[0] = 'R'; break; case eBlocked: - state[0] = 'B'; + buffer[0] = 'B'; break; case eSuspended: - state[0] = 'S'; + buffer[0] = 'S'; break; case eDeleted: - state[0] = 'D'; + buffer[0] = 'D'; break; default: - state[0] = 'I'; // Invalid + buffer[0] = 'I'; // Invalid break; } - lv_table_set_cell_value(infoTask, i + 1, 1, state); + buffer[1] = '\0'; + lv_table_set_cell_value(infoTask, i + 1, 1, buffer); lv_table_set_cell_value(infoTask, i + 1, 2, tasksStatus[i].pcTaskName); if (tasksStatus[i].usStackHighWaterMark < 20) { - std::string str1 = std::to_string(tasksStatus[i].usStackHighWaterMark) + " low"; - lv_table_set_cell_value(infoTask, i + 1, 3, str1.c_str()); + sprintf(buffer, "%d low", tasksStatus[i].usStackHighWaterMark); } else { - lv_table_set_cell_value(infoTask, i + 1, 3, std::to_string(tasksStatus[i].usStackHighWaterMark).c_str()); + sprintf(buffer, "%d", tasksStatus[i].usStackHighWaterMark); } + lv_table_set_cell_value(infoTask, i + 1, 3, buffer); } return std::make_unique(3, 5, app, infoTask); } diff --git a/src/displayapp/screens/Twos.cpp b/src/displayapp/screens/Twos.cpp index 4201d50..d12ef90 100644 --- a/src/displayapp/screens/Twos.cpp +++ b/src/displayapp/screens/Twos.cpp @@ -1,10 +1,10 @@ #include "Twos.h" -#include -#include -#include #include -#include +#include +#include +#include #include +#include using namespace Pinetime::Applications::Screens; @@ -265,7 +265,9 @@ void Twos::updateGridDisplay(Tile grid[][4]) { for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { if (grid[row][col].value) { - lv_table_set_cell_value(gridDisplay, row, col, (std::to_string(grid[row][col].value)).c_str()); + char buffer[7]; + sprintf(buffer, "%d", grid[row][col].value); + lv_table_set_cell_value(gridDisplay, row, col, buffer); } else { lv_table_set_cell_value(gridDisplay, row, col, ""); } -- cgit v0.10.2 From 22f167dd0ae37a35fdfd9a8222c85384a4bc3b4c Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 30 Oct 2021 11:51:11 +0300 Subject: Ignore some warnings diff --git a/.clang-tidy b/.clang-tidy index 8b9e7c0..df52357 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,7 @@ Checks: '*, -altera-unroll-loops, -llvmlibc-callee-namespace, + -llvmlibc-restrict-system-libc-headers, -llvm-header-guard, -llvm-namespace-comment, -google-build-using-namespace, @@ -9,6 +10,7 @@ Checks: '*, -fuchsia-statically-constructed-objects, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-pro-type-static-cast-downcast, -cppcoreguidelines-pro-type-union-access, -cppcoreguidelines-pro-type-cstyle-cast, -cppcoreguidelines-pro-type-vararg, -- cgit v0.10.2 From e9c7ab4cfc82172a07c19a0c4877b4afd11412f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sat, 6 Nov 2021 19:01:19 +0100 Subject: Add data validity check and retries in CST816S driver. See https://github.com/InfiniTimeOrg/InfiniTime/issues/763#issuecomment-962436976. diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index 7fc8eca..46dd96d 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -32,6 +32,18 @@ bool Cst816S::Init() { twiMaster.Read(twiAddress, 0xa7, &dummy, 1); vTaskDelay(5); + static constexpr uint8_t maxRetries = 3; + bool isDeviceOk = false; + uint8_t retries = 0; + do { + isDeviceOk = CheckDeviceIds(); + retries++; + } while(!isDeviceOk && retries < maxRetries); + + if(!isDeviceOk) { + return false; + } + /* [2] EnConLR - Continuous operation can slide around [1] EnConUD - Slide up and down to enable continuous operation @@ -50,21 +62,7 @@ bool Cst816S::Init() { static constexpr uint8_t irqCtl = 0b01110000; twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1); - // There's mixed information about which register contains which information - if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { - chipId = 0xFF; - return false; - } - if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { - vendorId = 0xFF; - return false; - } - if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) { - fwVersion = 0xFF; - return false; - } - - return chipId == 0xb4 && vendorId == 0 && fwVersion == 1; + return true; } Cst816S::TouchInfos Cst816S::GetTouchInfo() { @@ -79,18 +77,33 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { // This can only be 0 or 1 uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f; - uint8_t xHigh = touchData[touchXHighIndex] & 0x0f; uint8_t xLow = touchData[touchXLowIndex]; - info.x = (xHigh << 8) | xLow; - + uint16_t x = (xHigh << 8) | xLow; uint8_t yHigh = touchData[touchYHighIndex] & 0x0f; uint8_t yLow = touchData[touchYLowIndex]; - info.y = (yHigh << 8) | yLow; + uint16_t y = (yHigh << 8) | yLow; + Gestures gesture = static_cast(touchData[gestureIndex]); + + // Validity check + if(x >= maxX || y >= maxY || + (gesture != Gestures::None && + gesture != Gestures::SlideDown && + gesture != Gestures::SlideUp && + gesture != Gestures::SlideLeft && + gesture != Gestures::SlideRight && + gesture != Gestures::SingleTap && + gesture != Gestures::DoubleTap && + gesture != Gestures::LongPress)) { + info.isValid = false; + return info; + } + info.x = x; + info.y = y; info.touching = (nbTouchPoints > 0); - info.gesture = static_cast(touchData[gestureIndex]); - + info.gesture = gesture; + info.isValid = true; return info; } @@ -108,3 +121,21 @@ void Cst816S::Wakeup() { Init(); NRF_LOG_INFO("[TOUCHPANEL] Wakeup"); } + +bool Cst816S::CheckDeviceIds() { + // There's mixed information about which register contains which information + if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { + chipId = 0xFF; + return false; + } + if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { + vendorId = 0xFF; + return false; + } + if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) { + fwVersion = 0xFF; + return false; + } + + return chipId == 0xb4 && vendorId == 0 && fwVersion == 1; +} diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index 0fec841..507dd4f 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -21,7 +21,7 @@ namespace Pinetime { uint16_t y = 0; Gestures gesture = Gestures::None; bool touching = false; - bool isValid = true; + bool isValid = false; }; Cst816S(TwiMaster& twiMaster, uint8_t twiAddress); @@ -45,6 +45,8 @@ namespace Pinetime { return fwVersion; } private: + bool CheckDeviceIds(); + // Unused/Unavailable commented out static constexpr uint8_t gestureIndex = 1; static constexpr uint8_t touchPointNumIndex = 2; @@ -58,6 +60,9 @@ namespace Pinetime { //static constexpr uint8_t touchXYIndex = 7; //static constexpr uint8_t touchMiscIndex = 8; + static constexpr uint8_t maxX = 240; + static constexpr uint8_t maxY = 240; + TwiMaster& twiMaster; uint8_t twiAddress; -- cgit v0.10.2 From 8d61419836bffa7c59cb41c33fe747bafe841af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 7 Nov 2021 16:19:06 +0100 Subject: Fix formatting following the code review. diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index 46dd96d..4aac19f 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -33,14 +33,14 @@ bool Cst816S::Init() { vTaskDelay(5); static constexpr uint8_t maxRetries = 3; - bool isDeviceOk = false; + bool isDeviceOk; uint8_t retries = 0; do { isDeviceOk = CheckDeviceIds(); retries++; - } while(!isDeviceOk && retries < maxRetries); + } while (!isDeviceOk && retries < maxRetries); - if(!isDeviceOk) { + if (!isDeviceOk) { return false; } -- cgit v0.10.2 From e6edf2155296864114a62cecbd0244c65c020a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 7 Nov 2021 18:00:34 +0100 Subject: Disable the warning that is displayed when the initialization of the touch controller fails, as some users reported that it was displayed when a valid touch controller was installed. diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 0a3f995..f2cc1df 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -144,9 +144,14 @@ void SystemTask::Work() { lcd.Init(); twiMaster.Init(); + /* + * TODO We disable this warning message until we ensure it won't be displayed + * on legitimate PineTime equipped with a compatible touch controller. + * (some users reported false positive). See https://github.com/InfiniTimeOrg/InfiniTime/issues/763 if (!touchPanel.Init()) { bootError = BootErrors::TouchController; } + */ dateTimeController.Register(this); batteryController.Register(this); motorController.Init(); -- cgit v0.10.2 From 76c43ebc82eb1d6580a10f292c83b0b18da135e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 7 Nov 2021 20:13:22 +0100 Subject: Fix previous commit, call touchPanel.Init() even if we disabled the touch controller boot error. diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index f2cc1df..4b03f9a 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -152,6 +152,7 @@ void SystemTask::Work() { bootError = BootErrors::TouchController; } */ + touchPanel.Init(); dateTimeController.Register(this); batteryController.Register(this); motorController.Init(); -- cgit v0.10.2 From 1d6455c28943efc0e51a91e6e7daa9045a372e50 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Tue, 9 Nov 2021 11:38:19 +0200 Subject: Fix Alarm app crashing on buttonpress diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index 32a14d2..487ba1d 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -40,7 +40,9 @@ namespace Pinetime { Controllers::AlarmController& alarmController; lv_obj_t *time, *btnEnable, *txtEnable, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp, *txtMinDown, - *txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnMessage, *txtMessage, *btnInfo, *txtInfo; + *txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnInfo, *txtInfo; + lv_obj_t* txtMessage = nullptr; + lv_obj_t* btnMessage = nullptr; enum class EnableButtonState { On, Off, Alerting }; void SetEnableButtonState(); -- cgit v0.10.2 From a57fda6ba4a29866083a1254ffdf92939d00e182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Thu, 11 Nov 2021 09:54:30 +0100 Subject: Set version to 1.7.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index a8ecb81..63257ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(pinetime VERSION 1.6.0 LANGUAGES C CXX ASM) +project(pinetime VERSION 1.7.0 LANGUAGES C CXX ASM) set(CMAKE_C_STANDARD 99) set(CMAKE_CXX_STANDARD 14) -- cgit v0.10.2