summaryrefslogtreecommitdiff
path: root/src/displayapp/screens
diff options
context:
space:
mode:
authorpanky-codes <pankaj.sarathy1992@gmail.com>2021-03-11 11:56:58 +0100
committerpanky-codes <pankaj.sarathy1992@gmail.com>2021-03-11 11:56:58 +0100
commitce91e1a7a6e7ccf674aabfb20770d13cb4eb3190 (patch)
tree20f43ac62f45d994d24a86d0756fa55ab3c3bc83 /src/displayapp/screens
parent1f8f527f9f99e7d0a17503ae095800ce80d51b14 (diff)
Changed the clock source. Stopwatch works. Need to add butttons.
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r--src/displayapp/screens/StopWatch.cpp33
-rw-r--r--src/displayapp/screens/StopWatch.h8
2 files changed, 29 insertions, 12 deletions
diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp
index 834471e0..2ccafb16 100644
--- a/src/displayapp/screens/StopWatch.cpp
+++ b/src/displayapp/screens/StopWatch.cpp
@@ -2,17 +2,34 @@
#include "Screen.h"
#include "lvgl/lvgl.h"
+#include "projdefs.h"
+#include "FreeRTOSConfig.h"
+#include "task.h"
#include <tuple>
// Anonymous namespace for local functions
namespace {
- std::tuple<int, int, int> convertMilliSecsToSegments(const int64_t& currentTime) {
- const int milliSecs = (currentTime % 1000); // Get only the first two digits and ignore the last
- const int secs = (currentTime / 1000) % 60;
- const int mins = (currentTime / 1000) / 60;
+ std::tuple<int, int, int> convertTicksToTimeSegments(const TickType_t timeElapsed) {
+ const int timeElapsedMillis = (static_cast<float>(timeElapsed) / static_cast<float>(configTICK_RATE_HZ)) * 1000;
+
+ const int milliSecs = (timeElapsedMillis % 1000) / 10; // Get only the first two digits and ignore the last
+ const int secs = (timeElapsedMillis / 1000) % 60;
+ const int mins = (timeElapsedMillis / 1000) / 60;
return std::make_tuple(mins, secs, milliSecs);
}
+
+ TickType_t calculateDelta(const TickType_t startTime, const TickType_t currentTime) {
+ TickType_t delta = 0;
+ // Take care of overflow
+ if (startTime > currentTime) {
+ delta = 0xffffffff - startTime;
+ delta += (currentTime + 1);
+ } else {
+ delta = currentTime - startTime;
+ }
+ return delta;
+ }
}
using namespace Pinetime::Applications::Screens;
@@ -43,16 +60,16 @@ bool StopWatch::Refresh() {
lv_label_set_text(time, "00:00");
lv_label_set_text(msecTime, "00");
if (currentEvent == Events::PLAY) {
- startTime = dateTime.CurrentDateTime();
+ startTime = xTaskGetTickCount();
currentState = States::RUNNING;
}
break;
}
case States::RUNNING: {
- auto delta = std::chrono::duration_cast<std::chrono::microseconds>(dateTime.CurrentDateTime() - startTime);
- timeElapsed = delta.count();
- auto timeSeparated = convertMilliSecsToSegments(timeElapsed);
+ auto timeElapsed = calculateDelta(startTime, xTaskGetTickCount());
+ auto timeSeparated = convertTicksToTimeSegments(timeElapsed);
lv_label_set_text_fmt(time, "%02d:%02d", std::get<0>(timeSeparated), std::get<1>(timeSeparated));
+ lv_label_set_text_fmt(msecTime, "%02d", std::get<2>(timeSeparated));
break;
}
case States::HALTED: {
diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h
index ecc1f276..4763fd1e 100644
--- a/src/displayapp/screens/StopWatch.h
+++ b/src/displayapp/screens/StopWatch.h
@@ -4,7 +4,8 @@
#include "components/datetime/DateTimeController.h"
#include "../LittleVgl.h"
-#include <chrono>
+#include "FreeRTOS.h"
+#include "portmacro_cmsis.h"
namespace Pinetime::Applications::Screens {
@@ -21,13 +22,12 @@ namespace Pinetime::Applications::Screens {
bool OnTouchEvent(uint16_t x, uint16_t y) override;
private:
- using timeUnit = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
const Pinetime::Controllers::DateTime& dateTime;
bool running;
States currentState;
Events currentEvent;
- timeUnit startTime;
- int64_t timeElapsed;
+ TickType_t startTime;
+ TickType_t timeElapsed;
lv_obj_t *time, *msecTime;
};
} \ No newline at end of file