summaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--main.cpp53
1 files changed, 29 insertions, 24 deletions
diff --git a/main.cpp b/main.cpp
index de37652..4d00772 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,6 +5,7 @@
* Created on May 1, 2018, 6:18 PM
*/
+// Note: there is some debug code in uart.tpp that controls the RGB led
// #define DEBUG
// basic devices
@@ -54,7 +55,7 @@ std::vector<std::string> split(const std::string& str, const char sep)
return v;
}
-int main(int argc, char** argv)
+int main(int argc, char *argv[])
{
osc::initialize();
interrupts::initialize();
@@ -69,14 +70,14 @@ int main(int argc, char** argv)
io_pin<7> led3_pin(&LATEbits, &TRISEbits, &PORTEbits);
// build leds
- led led1(static_cast<gpio *>(&led1_pin), led::color::RED);
- led led2(static_cast<gpio *>(&led2_pin), led::color::GREEN);
- led led3(static_cast<gpio *>(&led3_pin), led::color::YELLOW);
+ led led_red(static_cast<gpio_pin *>(&led1_pin), led::color::RED);
+ led led_green(static_cast<gpio_pin *>(&led2_pin), led::color::GREEN);
+ led led_yellow(static_cast<gpio_pin *>(&led3_pin), led::color::YELLOW);
#ifdef DEBUG
- led1.set(1);
- led2.set(1);
- led3.set(1);
+ led_red.set(1);
+ led_green.set(1);
+ led_yellow.set(1);
uart::write<1>("started\n\r");
#endif
@@ -90,11 +91,15 @@ int main(int argc, char** argv)
do {
input += uart::read_wait<1>();
+ // Note: does not work with teraterm on windows
// DEL character
if (input.back() == '\x7f') {
input.pop_back();
- input.pop_back();
- uart::write<1>("\b \b");
+
+ if (input.size() > 1) {
+ input.pop_back();
+ uart::write<1>("\b \b");
+ }
}
} while (input.back() != '\r' && input.back() != '\n');
@@ -140,9 +145,9 @@ int main(int argc, char** argv)
if (command[0] == "show") {
if (command[1] == "led") {
if (command[2] == "all") {
- uart::print<1>(led1.to_string());
- uart::print<1>(led2.to_string());
- uart::print<1>(led3.to_string());
+ uart::print<1>(led_red.to_string());
+ uart::print<1>(led_green.to_string());
+ uart::print<1>(led_yellow.to_string());
}
}
}
@@ -162,31 +167,31 @@ int main(int argc, char** argv)
if (command[1] == "led") {
if (command[2] == "red") {
if (command[3] == "on") {
- led1.set(1);
+ led_red.set(1);
} else if (command[3] == "off") {
- led1.set(0);
+ led_red.set(0);
}
} else if (command[2] == "green") {
if (command[3] == "on") {
- led2.set(1);
+ led_green.set(1);
} else if (command[3] == "off") {
- led2.set(0);
+ led_green.set(0);
}
} else if (command[2] == "yellow") {
if (command[3] == "on") {
- led3.set(1);
+ led_yellow.set(1);
} else if (command[3] == "off") {
- led3.set(0);
+ led_yellow.set(0);
}
} else if (command[2] == "all") {
if (command[3] == "on") {
- led1.set(1);
- led2.set(1);
- led3.set(1);
+ led_red.set(1);
+ led_green.set(1);
+ led_yellow.set(1);
} else if (command[3] == "off") {
- led1.set(0);
- led2.set(0);
- led3.set(0);
+ led_red.set(0);
+ led_green.set(0);
+ led_yellow.set(0);
}
}
}