Skip to content

Commit

Permalink
Serial.read implementation moved to supla_Timer function
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslawzygmunt committed Feb 21, 2018
1 parent c494d2d commit 5d3fd5b
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions libraries/SuplaDevice/examples/SuplaSomfy/SuplaSomfy.ino
Expand Up @@ -78,6 +78,38 @@ void showRSCommand() {
Serial.println("P [chanel] => PROGRAM");
}

void supla_Timer() {

if (Serial.available()) {
char cmd = (char)Serial.read();
if (isSpace((char)Serial.read())) {
int chanel = Serial.parseInt();
if (chanel >= 0 && chanel < RC_COUNT) {
switch (toupper(cmd)) {
case 'U': {
pushButton(chanel, UP);
break;
}
case 'S': {
pushButton(chanel, STOP);
break;
}
case 'D': {
pushButton(chanel, DOWN);
break;
}
case 'P': {
pushButton(chanel, PROG);
break;
}
}
}
}
}

}


void setup() {
Serial.begin(115200);

Expand All @@ -102,6 +134,7 @@ void setup() {
pin + 1); // 101 - Pin number where the 2nd relay is connected
}

SuplaDevice.setTimerFuncImpl(&supla_Timer);
SuplaDevice.setDigitalReadFuncImpl(&supla_DigitalRead);
SuplaDevice.setDigitalWriteFuncImpl(&supla_DigitalWrite);
SuplaDevice.setName("Somfy Remote");
Expand All @@ -117,33 +150,6 @@ void setup() {

void loop() {
SuplaDevice.iterate();

if (Serial.available()) {
char cmd = (char)Serial.read();
if (isSpace((char)Serial.read())) {
int chanel = Serial.parseInt();
if (chanel >= 0 && chanel < RC_COUNT) {
switch (toupper(cmd)) {
case 'U': {
pushButton(chanel, UP);
break;
}
case 'S': {
pushButton(chanel, STOP);
break;
}
case 'D': {
pushButton(chanel, DOWN);
break;
}
case 'P': {
pushButton(chanel, PROG);
break;
}
}
}
}
}
}

void testRemote() {
Expand Down

0 comments on commit 5d3fd5b

Please sign in to comment.