Changed the clock source. Stopwatch works. Need to add butttons.
This commit is contained in:
parent
1f8f527f9f
commit
ce91e1a7a6
|
@ -2,17 +2,34 @@
|
||||||
|
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
#include "lvgl/lvgl.h"
|
#include "lvgl/lvgl.h"
|
||||||
|
#include "projdefs.h"
|
||||||
|
#include "FreeRTOSConfig.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
// Anonymous namespace for local functions
|
// Anonymous namespace for local functions
|
||||||
namespace {
|
namespace {
|
||||||
std::tuple<int, int, int> convertMilliSecsToSegments(const int64_t& currentTime) {
|
std::tuple<int, int, int> convertTicksToTimeSegments(const TickType_t timeElapsed) {
|
||||||
const int milliSecs = (currentTime % 1000); // Get only the first two digits and ignore the last
|
const int timeElapsedMillis = (static_cast<float>(timeElapsed) / static_cast<float>(configTICK_RATE_HZ)) * 1000;
|
||||||
const int secs = (currentTime / 1000) % 60;
|
|
||||||
const int mins = (currentTime / 1000) / 60;
|
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);
|
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;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
|
||||||
|
@ -43,16 +60,16 @@ bool StopWatch::Refresh() {
|
||||||
lv_label_set_text(time, "00:00");
|
lv_label_set_text(time, "00:00");
|
||||||
lv_label_set_text(msecTime, "00");
|
lv_label_set_text(msecTime, "00");
|
||||||
if (currentEvent == Events::PLAY) {
|
if (currentEvent == Events::PLAY) {
|
||||||
startTime = dateTime.CurrentDateTime();
|
startTime = xTaskGetTickCount();
|
||||||
currentState = States::RUNNING;
|
currentState = States::RUNNING;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case States::RUNNING: {
|
case States::RUNNING: {
|
||||||
auto delta = std::chrono::duration_cast<std::chrono::microseconds>(dateTime.CurrentDateTime() - startTime);
|
auto timeElapsed = calculateDelta(startTime, xTaskGetTickCount());
|
||||||
timeElapsed = delta.count();
|
auto timeSeparated = convertTicksToTimeSegments(timeElapsed);
|
||||||
auto timeSeparated = convertMilliSecsToSegments(timeElapsed);
|
|
||||||
lv_label_set_text_fmt(time, "%02d:%02d", std::get<0>(timeSeparated), std::get<1>(timeSeparated));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
case States::HALTED: {
|
case States::HALTED: {
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
#include "../LittleVgl.h"
|
#include "../LittleVgl.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include "FreeRTOS.h"
|
||||||
|
#include "portmacro_cmsis.h"
|
||||||
|
|
||||||
namespace Pinetime::Applications::Screens {
|
namespace Pinetime::Applications::Screens {
|
||||||
|
|
||||||
|
@ -21,13 +22,12 @@ namespace Pinetime::Applications::Screens {
|
||||||
bool OnTouchEvent(uint16_t x, uint16_t y) override;
|
bool OnTouchEvent(uint16_t x, uint16_t y) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using timeUnit = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
|
|
||||||
const Pinetime::Controllers::DateTime& dateTime;
|
const Pinetime::Controllers::DateTime& dateTime;
|
||||||
bool running;
|
bool running;
|
||||||
States currentState;
|
States currentState;
|
||||||
Events currentEvent;
|
Events currentEvent;
|
||||||
timeUnit startTime;
|
TickType_t startTime;
|
||||||
int64_t timeElapsed;
|
TickType_t timeElapsed;
|
||||||
lv_obj_t *time, *msecTime;
|
lv_obj_t *time, *msecTime;
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user