-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Show only during daylight * Create schedule class * Fix schedule * Remove hide/show
- Loading branch information
1 parent
2d68db6
commit ecbce45
Showing
6 changed files
with
156 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "Schedule.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef Schedule_h | ||
#define Schedule_h | ||
|
||
#include "common.h" | ||
|
||
const byte HOURS_IN_DAY = 24; | ||
|
||
template <class T> | ||
class Schedule | ||
{ | ||
public: | ||
Schedule(T defaultValue) | ||
{ | ||
_defaultValue = defaultValue; | ||
reset(); | ||
} | ||
|
||
void reset() | ||
{ | ||
for (byte i = 0; i < HOURS_IN_DAY; i++) | ||
{ | ||
_valuesForHour[i] = _defaultValue; | ||
} | ||
} | ||
|
||
T valueFor(byte hour) | ||
{ | ||
return _valuesForHour[hour]; | ||
} | ||
|
||
void setup(byte min, byte max, T value) | ||
{ | ||
for (byte i = min; i <= max; i++) | ||
{ | ||
_valuesForHour[i] = value; | ||
} | ||
} | ||
|
||
private: | ||
T _defaultValue; | ||
T _valuesForHour[HOURS_IN_DAY]; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <unity.h> | ||
#include "Schedule.h" | ||
|
||
Schedule<byte> target(10); | ||
|
||
void setUp(void) | ||
{ | ||
target.reset(); | ||
} | ||
|
||
void test_initializes(void) | ||
{ | ||
for (byte i = 0; i < HOURS_IN_DAY; i++) | ||
{ | ||
TEST_ASSERT_EQUAL(10, target.valueFor(i)); | ||
} | ||
} | ||
|
||
void test_setup_range(void) | ||
{ | ||
target.setup(5, 6, 12); | ||
for (byte i = 0; i < HOURS_IN_DAY; i++) | ||
{ | ||
if (i == 5 || i == 6) | ||
{ | ||
TEST_ASSERT_EQUAL(12, target.valueFor(i)); | ||
} | ||
else | ||
{ | ||
TEST_ASSERT_EQUAL(10, target.valueFor(i)); | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_initializes); | ||
RUN_TEST(test_setup_range); | ||
UNITY_END(); | ||
|
||
return 0; | ||
} |