Skip to content

Commit

Permalink
Remove old view and log from modes
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1ol committed Oct 30, 2024
1 parent 4e824c4 commit 73ec01d
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 294 deletions.
6 changes: 2 additions & 4 deletions src/ModeProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Config.h"
#include "Tools.h"

uint8_t ModeProcessor::printLogHelper(Time (*timeGetter)(const void* ctx, uint8_t id, bool& current, const char*& mark),
void ModeProcessor::printTimeHelper(Time (*timeGetter)(const void* ctx, uint8_t id, bool& current, const char*& mark),
const void* ctx) const {
uint8_t id = 0;

Expand All @@ -18,7 +18,7 @@ uint8_t ModeProcessor::printLogHelper(Time (*timeGetter)(const void* ctx, uint8_
Time time = timeGetter(ctx, id, current, mark);

if (time == kBadTime)
return id;
return;

time.getFormatedTime(str, current, current);

Expand All @@ -39,6 +39,4 @@ uint8_t ModeProcessor::printLogHelper(Time (*timeGetter)(const void* ctx, uint8_
++id;
}
}

return id;
}
7 changes: 1 addition & 6 deletions src/ModeProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ class ModeProcessor {
virtual void reset() = 0;
virtual void switchMode() = 0;

virtual bool canSwitchView() const = 0;
virtual void switchView() = 0;

virtual void printLog() const = 0;

virtual const char* preview() const = 0;

protected:
uint8_t printLogHelper(Time (*timeGetter)(const void* ctx, uint8_t id, bool& current, const char*& mark),
void printTimeHelper(Time (*timeGetter)(const void* ctx, uint8_t id, bool& current, const char*& mark),
const void* ctx) const;
};
63 changes: 4 additions & 59 deletions src/Modes/FStopTestMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ FStopTestMode::FStopTestMode(bool splitGrade) : kSplit(splitGrade) {
m_initTime = 2_s;
m_FStopPartId = 5;
m_step = kSplit ? Step::baseTime : Step::initTime;
m_view = gSettings.logViewInTests ? RunView::log : RunView::common;
m_currentRun = kSplit ? 0 : 1;
}

Expand Down Expand Up @@ -49,34 +48,8 @@ void FStopTestMode::process() {
break;
}

switch (m_view) {
case RunView::common:
if (m_currentRun == 0)
gDisplay[0] << "Base printing";
else
gDisplay[0] << "Test #" << m_currentRun << " T:" << gTimer.total();

gDisplay[1] >> "f 1/" >> kFStopPartVarinatns[m_FStopPartId];

if (gTimer.state() == Timer::RUNNING) {
gTimer.printFormatedState();
return;
}

if (getStepTotalTime(m_currentRun) == kBadTime)
gDisplay[1] << "Finish";
else
gDisplay[1] << getPrintTime();
break;
case RunView::log: {
gDisplay[0] << "Run ";

bool logOverFlow = false;
printLog(logOverFlow);
if (logOverFlow)
m_view = RunView::common;
} break;
}
gDisplay[0] << "Run ";
printTimes();

if (gTimer.state() == Timer::STOPPED && gStartBtn.click() && getStepTotalTime(m_currentRun) != kBadTime)
gTimer.start(getPrintTime());
Expand Down Expand Up @@ -113,23 +86,8 @@ void FStopTestMode::reset() {
m_currentRun = kSplit ? 0 : 1;
}

void FStopTestMode::switchView() {
m_view = ADD_TO_ENUM(RunView, m_view, 1);
}

bool FStopTestMode::canSwitchView() const {
if (m_step != Step::run)
return false;

gDisplay[0] << "Run ";
bool overFlow = false;
printLog(overFlow);
gDisplay.reset();
return !overFlow;
}

void FStopTestMode::printLog(bool& logOverFlowed) const {
uint8_t id = printLogHelper(
void FStopTestMode::printTimes() const {
printTimeHelper(
[](const void* this__, uint8_t id, bool& current, const char*& mark) -> Time {
auto this_ = reinterpret_cast<const FStopTestMode*>(this__);

Expand All @@ -144,19 +102,6 @@ void FStopTestMode::printLog(bool& logOverFlowed) const {
return this_->getStepTotalTime(id);
},
this);

if (!kSplit)
++id;

if (m_step == Step::run && m_currentRun >= id)
logOverFlowed = true;
}

void FStopTestMode::printLog() const {
gDisplay[0] << "Log ";

bool unused;
printLog(unused);
}

const char* FStopTestMode::preview() const {
Expand Down
9 changes: 1 addition & 8 deletions src/Modes/FStopTestMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@

class FStopTestMode final : public ModeProcessor {
enum class Step { baseTime, initTime, fstopSet, run, last_ };
enum class RunView { common, log, last_ };

public:
FStopTestMode(bool splitGrade);
void process() override;
void reset() override;
void switchMode() override;

bool canSwitchView() const override;
void switchView() override;

void printLog() const override;

const char* preview() const override;

private:
void printLog(bool& logOverFlowed) const;
void printTimes() const;
Time getPrintTime() const;
Time getStepTotalTime(uint8_t step) const;

bool kSplit;
Step m_step;
RunView m_view;
uint8_t m_currentRun;
uint8_t m_FStopPartId;
Time m_baseTime;
Expand Down
61 changes: 4 additions & 57 deletions src/Modes/LinearTestMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LinearTestMode::LinearTestMode(bool splitGrade) : kSplit(splitGrade) {
m_initTime = 8_s;
m_stepTime = 2_s;
m_step = kSplit ? Step::baseTime : Step::initTime;
m_view = gSettings.logViewInTests ? RunView::log : RunView::common;
m_currentRun = kSplit ? 0 : 1;
}

Expand Down Expand Up @@ -41,32 +40,8 @@ void LinearTestMode::process() {
break;
}

switch (m_view) {
case RunView::common:
if (m_currentRun == 0)
gDisplay[0] << "Base printing";
else
gDisplay[0] << "Test #" << m_currentRun << " T:" << gTimer.total();

if (gTimer.state() == Timer::RUNNING) {
gTimer.printFormatedState();
return;
}

if (getTotalTime(m_currentRun) == kBadTime)
gDisplay[1] << "Finish";
else
gDisplay[1] << getPrintTime();
break;
case RunView::log: {
gDisplay[0] << "Run ";

bool logOverFlow = false;
printLog(logOverFlow);
if (logOverFlow)
m_view = RunView::common;
} break;
}
gDisplay[0] << "Run ";
printTimes();

if (gTimer.state() == Timer::STOPPED && gStartBtn.click() && getTotalTime(m_currentRun) != kBadTime)
gTimer.start(getPrintTime());
Expand Down Expand Up @@ -104,23 +79,8 @@ void LinearTestMode::reset() {
m_currentRun = kSplit ? 0 : 1;
}

void LinearTestMode::switchView() {
m_view = ADD_TO_ENUM(RunView, m_view, 1);
}

bool LinearTestMode::canSwitchView() const {
if (m_step != Step::run)
return false;

gDisplay[0] << "Run ";
bool overFlow = false;
printLog(overFlow);
gDisplay.reset();
return !overFlow;
}

void LinearTestMode::printLog(bool& logOverFlowed) const {
uint8_t id = printLogHelper(
void LinearTestMode::printTimes() const {
printTimeHelper(
[](const void* this__, uint8_t id, bool& current, const char*& mark) -> Time {
auto this_ = reinterpret_cast<const LinearTestMode*>(this__);

Expand All @@ -135,19 +95,6 @@ void LinearTestMode::printLog(bool& logOverFlowed) const {
return this_->getTotalTime(id);
},
this);

if (!kSplit)
++id;

if (m_step == Step::run && m_currentRun >= id)
logOverFlowed = true;
}

void LinearTestMode::printLog() const {
gDisplay[0] << "Log ";

bool unused;
printLog(unused);
}

const char* LinearTestMode::preview() const {
Expand Down
9 changes: 1 addition & 8 deletions src/Modes/LinearTestMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@

class LinearTestMode final : public ModeProcessor {
enum class Step { baseTime, initTime, stepTime, run, last_ };
enum class RunView { common, log, last_ };

public:
LinearTestMode(bool splitGrade);
void process() override;
void reset() override;
void switchMode() override;

bool canSwitchView() const override;
void switchView() override;

void printLog() const override;

const char* preview() const override;

private:
void printLog(bool& logOverFlowed) const;
void printTimes() const;
Time getPrintTime() const;
Time getTotalTime(uint8_t id) const;

bool kSplit;
Step m_step;
RunView m_view;
uint8_t m_currentRun;
Time m_baseTime;
Time m_initTime;
Expand Down
Loading

0 comments on commit 73ec01d

Please sign in to comment.