2021-03-11 09:54:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/screens/Screen.h"
|
2021-03-11 09:54:14 +00:00
|
|
|
#include "components/datetime/DateTimeController.h"
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/LittleVgl.h"
|
2021-03-11 09:54:14 +00:00
|
|
|
|
2022-01-24 22:03:08 +00:00
|
|
|
#include <FreeRTOS.h>
|
2021-03-11 10:56:58 +00:00
|
|
|
#include "portmacro_cmsis.h"
|
2021-03-11 09:54:14 +00:00
|
|
|
|
2021-03-12 19:24:53 +00:00
|
|
|
#include <array>
|
2021-07-04 18:23:03 +00:00
|
|
|
#include "systemtask/SystemTask.h"
|
2021-03-12 19:24:53 +00:00
|
|
|
|
2021-03-11 09:54:14 +00:00
|
|
|
namespace Pinetime::Applications::Screens {
|
|
|
|
|
2021-03-20 21:42:13 +00:00
|
|
|
enum class States { Init, Running, Halted };
|
2021-03-11 09:54:14 +00:00
|
|
|
|
2021-03-12 08:43:13 +00:00
|
|
|
struct TimeSeparated_t {
|
|
|
|
int mins;
|
|
|
|
int secs;
|
2021-04-17 21:47:53 +00:00
|
|
|
int hundredths;
|
2021-03-12 08:43:13 +00:00
|
|
|
};
|
|
|
|
|
2021-03-13 13:53:37 +00:00
|
|
|
// A simple buffer to hold the latest two laps
|
2021-03-12 19:24:53 +00:00
|
|
|
template <int N> struct LapTextBuffer_t {
|
2021-03-20 21:42:13 +00:00
|
|
|
LapTextBuffer_t() : buffer {}, currentSize {}, capacity {N}, head {-1} {
|
2021-03-12 19:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void addLaps(const TimeSeparated_t& timeVal) {
|
2021-03-13 12:59:54 +00:00
|
|
|
head++;
|
2021-03-12 19:24:53 +00:00
|
|
|
head %= capacity;
|
2021-03-20 21:42:13 +00:00
|
|
|
buffer[head] = timeVal;
|
2021-03-12 19:24:53 +00:00
|
|
|
|
2021-03-20 21:42:13 +00:00
|
|
|
if (currentSize < capacity) {
|
|
|
|
currentSize++;
|
2021-03-12 19:24:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-13 12:59:54 +00:00
|
|
|
void clearBuffer() {
|
2021-03-20 21:42:13 +00:00
|
|
|
buffer = {};
|
|
|
|
currentSize = 0;
|
2021-03-13 12:59:54 +00:00
|
|
|
head = -1;
|
|
|
|
}
|
|
|
|
|
2021-03-12 19:24:53 +00:00
|
|
|
TimeSeparated_t* operator[](std::size_t idx) {
|
|
|
|
// Sanity check for out-of-bounds
|
|
|
|
if (idx >= 0 && idx < capacity) {
|
2021-03-20 21:42:13 +00:00
|
|
|
if (idx < currentSize) {
|
2021-03-13 13:53:37 +00:00
|
|
|
// This transformation is to ensure that head is always pointing to index 0.
|
2021-03-13 12:59:54 +00:00
|
|
|
const auto transformed_idx = (head - idx) % capacity;
|
2021-03-20 21:42:13 +00:00
|
|
|
return (&buffer[transformed_idx]);
|
2021-03-12 19:24:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-03-20 21:42:13 +00:00
|
|
|
std::array<TimeSeparated_t, N> buffer;
|
|
|
|
uint8_t currentSize;
|
2021-03-12 19:24:53 +00:00
|
|
|
uint8_t capacity;
|
|
|
|
int8_t head;
|
|
|
|
};
|
|
|
|
|
2021-03-11 09:54:14 +00:00
|
|
|
class StopWatch : public Screen {
|
|
|
|
public:
|
2021-07-04 18:23:03 +00:00
|
|
|
StopWatch(DisplayApp* app, System::SystemTask& systemTask);
|
2021-03-11 09:54:14 +00:00
|
|
|
~StopWatch() override;
|
2021-07-19 13:26:12 +00:00
|
|
|
void Refresh() override;
|
2021-04-17 21:47:53 +00:00
|
|
|
|
2021-03-11 22:41:24 +00:00
|
|
|
void playPauseBtnEventHandler(lv_event_t event);
|
2021-03-12 08:43:13 +00:00
|
|
|
void stopLapBtnEventHandler(lv_event_t event);
|
2021-07-04 18:23:03 +00:00
|
|
|
bool OnButtonPushed() override;
|
|
|
|
|
2022-04-09 10:57:58 +00:00
|
|
|
void Reset();
|
|
|
|
void Start();
|
|
|
|
void Pause();
|
2021-03-11 09:54:14 +00:00
|
|
|
|
|
|
|
private:
|
2021-07-04 18:23:03 +00:00
|
|
|
Pinetime::System::SystemTask& systemTask;
|
|
|
|
TickType_t timeElapsed;
|
2021-03-11 09:54:14 +00:00
|
|
|
States currentState;
|
2021-03-11 10:56:58 +00:00
|
|
|
TickType_t startTime;
|
2021-03-11 22:41:24 +00:00
|
|
|
TickType_t oldTimeElapsed;
|
2021-03-12 19:24:53 +00:00
|
|
|
TimeSeparated_t currentTimeSeparated; // Holds Mins, Secs, millisecs
|
|
|
|
LapTextBuffer_t<2> lapBuffer;
|
2021-07-04 18:23:03 +00:00
|
|
|
int lapNr = 0;
|
2021-03-12 08:43:13 +00:00
|
|
|
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
|
|
|
|
lv_obj_t *lapOneText, *lapTwoText;
|
2021-07-19 13:26:12 +00:00
|
|
|
|
|
|
|
lv_task_t* taskRefresh;
|
2021-03-11 09:54:14 +00:00
|
|
|
};
|
2021-03-15 20:35:36 +00:00
|
|
|
}
|