Skip to content

Commit

Permalink
Splitted duckscript stop() into stop() and stopAll()
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacehuhn committed Nov 16, 2019
1 parent d412ae6 commit 566ca87
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion esp_duck/cli.cpp
Expand Up @@ -258,7 +258,7 @@ namespace cli {

duckscript::stop(arg.getValue());

String response = "> stopped \"" + arg.getValue() + "\"";
String response = "> stopped " + arg.getValue();
print(response);
});

Expand Down
19 changes: 11 additions & 8 deletions esp_duck/duckscript.cpp
Expand Up @@ -36,13 +36,13 @@ namespace duckscript {

if (!f) {
debugln("File error");
stop();
stopAll();
return;
}

if (!f.available()) {
debugln("Reached end of file");
stop();
stopAll();
return;
}

Expand Down Expand Up @@ -74,14 +74,14 @@ namespace duckscript {

void repeat() {
if (!prevMessage) {
stop();
stopAll();
} else {
debugln("Repeating last message");
com::send(prevMessage, prevMessageLen);
}
}

void stop() {
void stopAll() {
if (running) {
if (f) f.close();
running = false;
Expand All @@ -90,10 +90,13 @@ namespace duckscript {
}

void stop(String fileName) {
if (running && f && (fileName == currentScript())) {
f.close();
running = false;
debugln("Stopped script");
if (fileName.length() == 0) stopAll();
else {
if (running && f && (fileName == currentScript())) {
f.close();
running = false;
debugln("Stopped script");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion esp_duck/duckscript.h
Expand Up @@ -14,7 +14,7 @@ namespace duckscript {

void nextLine();
void repeat();
void stop();
void stopAll();
void stop(String fileName);

bool isRunning();
Expand Down
4 changes: 2 additions & 2 deletions esp_duck/esp_duck.ino
Expand Up @@ -25,7 +25,7 @@ void setup() {
webserver::begin();

com::onDone(duckscript::nextLine);
com::onError(duckscript::stop);
com::onError(duckscript::stopAll);
com::onRepeat(duckscript::repeat);

if (spiffs::freeBytes() > 0) com::send(MSG_STARTED);
Expand All @@ -49,4 +49,4 @@ void loop() {
webserver::update();

debug_update();
}
}

0 comments on commit 566ca87

Please sign in to comment.