diff --git a/app/gui/oven_control/dirtylevel.cpp b/app/gui/oven_control/dirtylevel.cpp index 4285c05..fd052f2 100644 --- a/app/gui/oven_control/dirtylevel.cpp +++ b/app/gui/oven_control/dirtylevel.cpp @@ -4,6 +4,7 @@ namespace { QDateTime cookStartTime; +bool cookStarted = false; qint64 cookingTime; int cookingCount; @@ -38,13 +39,18 @@ void decountState(int level) void DirtyLevel::cookStart() { + cookStarted = true; cookStartTime = QDateTime::currentDateTime(); - cookingCount++; + ::cookingCount++; } void DirtyLevel::cookEnd() { - cookingTime += cookStartTime.secsTo(QDateTime::currentDateTime()); + if (cookStarted) + { + cookStarted = true; + ::cookingTime += cookStartTime.secsTo(QDateTime::currentDateTime()); + } } void DirtyLevel::wash(int type) @@ -52,23 +58,23 @@ void DirtyLevel::wash(int type) switch (type) { case 1: - cookingTime = qMax(cookingTime - 2 * 3600, 0); + ::cookingTime = qMax(::cookingTime - 2 * 3600, (qint64) 0); decountState(1); break; case 2: - cookingTime = qMax(cookingTime - 3 * 3600, 0); + ::cookingTime = qMax(::cookingTime - 3 * 3600, (qint64) 0); decountState(1); break; case 3: - cookingTime = qMax(cookingTime - 4 * 3600, 0); + ::cookingTime = qMax(::cookingTime - 4 * 3600, (qint64) 0); decountState(2); break; case 4: - cookingTime = qMax(cookingTime - 10 * 3600, 0); + ::cookingTime = qMax(::cookingTime - 10 * 3600, (qint64) 0); decountState(2); break; case 5: - cookingTime = qMax(cookingTime - 2 * 3600, 0); + ::cookingTime = qMax(::cookingTime - 2 * 3600, (qint64) 0); decountState(1); break; } @@ -76,30 +82,50 @@ void DirtyLevel::wash(int type) int DirtyLevel::dirty() { - if (cookingCount < 1) + if (::cookingCount < 1) return 0; - if (cookingTime < 1 * 3600) + if (::cookingTime < 1 * 3600) return 1; - if (cookingTime < 3 * 3600) + if (::cookingTime < 3 * 3600) return 2; - if (cookingTime < 5 * 3600) + if (::cookingTime < 5 * 3600) return 3; - if (cookingTime < 7 * 3600) + if (::cookingTime < 7 * 3600) return 4; return 5; } int DirtyLevel::state() { - if (cookingCount < 1) + if (::cookingCount < 1) return 0; - if (cookingCount <= 5) + if (::cookingCount <= 5) return 1; - if (cookingCount <= 10) + if (::cookingCount <= 10) return 2; - if (cookingCount <= 15) + if (::cookingCount <= 15) return 3; - if (cookingCount <= 20) + if (::cookingCount <= 20) return 4; return 5; } + +void DirtyLevel::setCookingTime(qint64 secs) +{ + ::cookingTime = secs; +} + +int DirtyLevel::cookingTime() +{ + return ::cookingTime; +} + +int DirtyLevel::cookingCount() +{ + return ::cookingCount; +} + +void DirtyLevel::setCookingCount(int count) +{ + ::cookingCount = count; +} diff --git a/app/gui/oven_control/dirtylevel.h b/app/gui/oven_control/dirtylevel.h index efa487e..43d1383 100644 --- a/app/gui/oven_control/dirtylevel.h +++ b/app/gui/oven_control/dirtylevel.h @@ -1,6 +1,7 @@ #ifndef DIRTYLEVEL_H #define DIRTYLEVEL_H +#include namespace DirtyLevel { void cookStart(); @@ -9,6 +10,11 @@ void wash(int type); int dirty(); int state(); + +int cookingTime(); +void setCookingTime(qint64 secs); +int cookingCount(); +void setCookingCount(int count); } #endif // DIRTYLEVEL_H