/*----------------------------------------------------------------------------- * Author: Nelso G. Jost (nelsojost@gmail.com) * License: GPLv2 * Purpose: Read-Eval-Print-Loop functionality *---------------------------------------------------------------------------*/ #include #include "repl.h" #include "blinker.h" #define BUILTIN_LED 2 Blinker blinker(BUILTIN_LED); Ticker alog_ticker; void REPL_DWRITE(REPL * repl) { String arg_pin = repl->get_arg(1); String arg_value = repl->get_arg(2); int pin = arg_pin.toInt(); int value = !arg_value.toInt(); if (arg_pin == "led") pin = BUILTIN_LED; if (arg_value == "high") value = 0; if (arg_value == "low") value = 1; pinMode(pin, OUTPUT); digitalWrite(pin, value); repl->log("\n[INFO] Pin " + String(pin) + " was set to " + value? "HIGH":"LOW"); } void REPL_AREAD(REPL * repl) { int pin = repl->get_arg(1).toInt(); repl.log("\n[INFO] Read analog pin " + String(pin) + " value:" + String(analogRead(pin)); } void alog_callback(int pin, REPL * repl) { repl.log("a" + String(pin) + ":" + String(analogRead(pin))); } void REPL_ALOG(REPL * repl) { int pin = get_arg(1).toInt(); int interval = get_arg(2).toInt(); if (interval == 0) { alog_ticker.detach(); repl->log("\n[INFO] Deactivated datalog on analog pin " + String(pin) + "."); } else { alog_ticker.attach(interval, alog_callback, pin, repl); repl->log("\n[INFO] Activated datalog on analog pin " + String(pin) + " with " + String(interval) + " s interval."); } } void REPL_BLINK(REPL * repl) { float interval = repl->get_arg(1).toFloat(); if (interval == 0) { blinker.deactivate(); repl->log("\n[INFO] Deactivated blink builtin led (pin 2)."); } else { blinker.activate(interval); repl->log("\n[INFO] Activated blink builtin led (pin 2) with " String(interval) + " s interval."); } }