Skip to content

Commit 7dbb539

Browse files
committed
Merge pull request #1 from vbuyakov/master
fix example and library to correct processing of array of commands
2 parents e78c69c + 04c4da3 commit 7dbb539

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

Cron.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
RTC_DS1307 RTC;
1111

12-
Cron::Cron(TimedCommand *iTimedCommands, int iTimedCommandsSize) {
12+
Cron::Cron(TimedCommand **iTimedCommands, int iTimedCommandsSize) {
1313
timedCommands = iTimedCommands;
1414
timedCommandsSize = iTimedCommandsSize;
1515

@@ -20,12 +20,14 @@ Cron::Cron(TimedCommand *iTimedCommands, int iTimedCommandsSize) {
2020
Cron::~Cron() {
2121
}
2222

23+
24+
2325
void Cron::loop(){
2426
bool match = false;
2527
for (int i = 0; i< timedCommandsSize; i++){
26-
if (matchCron(timedCommands[i].getCronString(),getTime())){
27-
Command *command = timedCommands[i].getCommand();
28-
command->execute(timedCommands[i].getParameters());
28+
if (matchCron(timedCommands[i]->getCronString(),getTime())){
29+
Command *command = timedCommands[i]->getCommand();
30+
command->execute(timedCommands[i]->getParameters());
2931
match = true;
3032
}
3133
}

Cron.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
class Cron {
1616
public:
17-
Cron(TimedCommand*,int);
17+
Cron(TimedCommand **,int); // Get pointer to array of pointers
1818
virtual ~Cron();
1919
void loop();
2020
void printTime();
2121
void setTime(DateTime);
2222
boolean matchCron(String,DateTime);
2323
private:
24-
TimedCommand *timedCommands;
24+
TimedCommand **timedCommands;
2525
int timedCommandsSize;
2626
DateTime getTime();
2727
};

examples/ArduinoCronLibraryExample/ArduinoCronLibraryExample.ino

+37-2
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,55 @@
1111
SwitchOnCommand sonCommand;
1212
SwitchOffCommand sOffCommand;
1313

14+
// create timed command objects for each timed command
15+
// s.m.h.d.M.y,comand,parameters for command
1416
// create timed command objects for each timed command
1517
// s.m.h.d.M.y,comand,parameters for command
1618
TimedCommand command1("0.*.*.*.*.*",&sonCommand,"13");
1719
TimedCommand command2("5.*.*.*.*.*",&sOffCommand,"13");
1820

21+
TimedCommand command3("10.*.*.*.*.*",&sonCommand,"13");
22+
TimedCommand command4("15.*.*.*.*.*",&sOffCommand,"13");
23+
24+
TimedCommand command5("20.*.*.*.*.*",&sonCommand,"13");
25+
TimedCommand command6("25.*.*.*.*.*",&sOffCommand,"13");
26+
27+
TimedCommand command7("30.*.*.*.*.*",&sonCommand,"13");
28+
TimedCommand command8("35.*.*.*.*.*",&sOffCommand,"13");
29+
30+
TimedCommand command9("40.*.*.*.*.*",&sonCommand,"13");
31+
TimedCommand command10("45.*.*.*.*.*",&sOffCommand,"13");
32+
33+
34+
TimedCommand command11("50.*.*.*.*.*",&sonCommand,"13");
35+
TimedCommand command12("55.*.*.*.*.*",&sOffCommand,"13");
36+
1937
// create an array of timed commands
2038
TimedCommand *tCommands[] = {
2139
&command1,
22-
&command2
40+
&command2,
41+
42+
&command3,
43+
&command4,
44+
45+
&command5,
46+
&command6,
47+
48+
&command7,
49+
&command8,
50+
51+
&command9,
52+
&command10,
53+
54+
&command11,
55+
&command12
56+
57+
2358
};
2459

2560
// create a cron object and pass it the array of timed commands
2661
// and the count of timed commands
27-
Cron cron(tCommands[0],2);
62+
Cron cron(tCommands,12 );
2863

2964
void setup()
3065
{

0 commit comments

Comments
 (0)