Skip to content

Commit

Permalink
Remote schedule update (#20)
Browse files Browse the repository at this point in the history
* Remotely update a schedule

* Add display schedule id
  • Loading branch information
matthewturner authored Sep 7, 2022
1 parent b68f121 commit 1e8ece2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/CommandReader/CommandReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ enum commands
CNONE = 0,
SET = 1,
SHOW = 2,
STATUS = 6
STATUS = 6,
SET_SCHEDULE = 7
};
typedef enum commands Commands;

Expand Down
25 changes: 25 additions & 0 deletions lib/Schedule/Schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class Schedule
Schedule(T defaultValue)
{
_defaultValue = defaultValue;
_identifier = 99;
reset();
}

Schedule(T defaultValue, byte identifier)
{
_defaultValue = defaultValue;
_identifier = identifier;
reset();
}

Expand All @@ -38,9 +46,26 @@ class Schedule
}
}

void update(uint32_t encodedSchedule)
{
uint32_t value = encodedSchedule % 10;
encodedSchedule /= 10;
uint32_t hour = encodedSchedule % 100;
encodedSchedule /= 100;
uint32_t identifier = encodedSchedule;

if (identifier != _identifier)
{
return;
}

_valuesForHour[hour] = value;
}

private:
T _defaultValue;
T _valuesForHour[HOURS_IN_DAY];
byte _identifier;
};

#endif
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ bool processingCommands()
clock.adjust(DateTime(command.Data));
stateMachine.transition(SHOWING);
break;
case Commands::SET_SCHEDULE:
Serial.print(F("Command: SET SCHEDULE "));
Serial.println(command.Data);
displaySchedule.update(command.Data);
stateMachine.transition(SHOWING);
break;
case Commands::STATUS:
Serial.println(F("Command: STATUS"));
reportStatus();
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ RTC_DS3231 clock;
EvtManager mgr;
Timezone *timezone;
Schedule<CRGB::HTMLColorCode> colorSchedule(CRGB::Red);
Schedule<bool> displaySchedule(false);
Schedule<bool> displaySchedule(false, 1);
Schedule<bool> separatorSchedule(false);
Schedule<byte> brightnessSchedule(5);
Schedule<Flags> minimalSchedule(Flags::NONE);
Expand Down
25 changes: 24 additions & 1 deletion test/test_schedule/test_schedule.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <unity.h>
#include "Schedule.h"

Schedule<byte> target(10);
Schedule<byte> target(10, 1);
Schedule<bool> targetBool(false, 1);

void setUp(void)
{
target.reset();
targetBool.reset();
}

void tearDown(void) {}
Expand Down Expand Up @@ -34,11 +36,32 @@ void test_setup_range(void)
}
}

void test_update_single_value(void)
{
target.update(1141);
TEST_ASSERT_EQUAL(1, target.valueFor(14));
}

void test_does_not_update_single_value(void)
{
target.update(5141);
TEST_ASSERT_EQUAL(10, target.valueFor(14));
}

void test_update_single_bool_value(void)
{
targetBool.update(1141);
TEST_ASSERT_EQUAL(true, targetBool.valueFor(14));
}

int main(int argc, char **argv)
{
UNITY_BEGIN();
RUN_TEST(test_initializes);
RUN_TEST(test_setup_range);
RUN_TEST(test_update_single_value);
RUN_TEST(test_does_not_update_single_value);
RUN_TEST(test_update_single_bool_value);
UNITY_END();

return 0;
Expand Down

0 comments on commit 1e8ece2

Please sign in to comment.