summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--main.cpp44
1 files changed, 35 insertions, 9 deletions
diff --git a/main.cpp b/main.cpp
index 4fca3db..de37652 100644
--- a/main.cpp
+++ b/main.cpp
@@ -32,16 +32,24 @@ extern "C" {
std::vector<std::string> split(const std::string& str, const char sep)
{
std::vector<std::string> v;
+ std::string sub;
size_t last = 0;
size_t next = 0;
while ((next = str.find(sep, last)) != std::string::npos) {
- v.push_back(str.substr(last, next-last));
+ sub = str.substr(last, next-last);
+ if (!sub.empty()) {
+ v.push_back(sub);
+ }
+
last = next + 1;
}
-
- v.push_back(str.substr(last));
+
+ sub = str.substr(last);
+ if (!sub.empty()) {
+ v.push_back(sub);
+ }
return v;
}
@@ -153,15 +161,33 @@ int main(int argc, char** argv)
if (command[0] == "set") {
if (command[1] == "led") {
if (command[2] == "red") {
- led1.set((command[3] == "on"));
+ if (command[3] == "on") {
+ led1.set(1);
+ } else if (command[3] == "off") {
+ led1.set(0);
+ }
} else if (command[2] == "green") {
- led2.set((command[3] == "on"));
+ if (command[3] == "on") {
+ led2.set(1);
+ } else if (command[3] == "off") {
+ led2.set(0);
+ }
} else if (command[2] == "yellow") {
- led3.set((command[3] == "on"));
+ if (command[3] == "on") {
+ led3.set(1);
+ } else if (command[3] == "off") {
+ led3.set(0);
+ }
} else if (command[2] == "all") {
- led1.set((command[3] == "on"));
- led2.set((command[3] == "on"));
- led3.set((command[3] == "on"));
+ if (command[3] == "on") {
+ led1.set(1);
+ led2.set(1);
+ led3.set(1);
+ } else if (command[3] == "off") {
+ led1.set(0);
+ led2.set(0);
+ led3.set(0);
+ }
}
}
}