Debug.ino 3.22 KB
/*
   Debug.ino - CLI library sample implementing a CLI for the Blink sample code

   Version 1.0, latest version, documentation and bugtracker available at:
                https://gitlab.lindenaar.net/arduino/CLI

   Copyright (c) 2019 Frederik Lindenaar

   This sketch demonstrates the debugging commands available as part of the CLI
   library. These commands are intended to eliminate the need to write code to
   check things in or connected to your microcontroller. Over time, additional
   commands will be added, when needed (feel free to submit your favorites for
   inclusion!). At this moment it makes the following commands available through
   the Serial Monitor (available from the Tools menu of the Arduino IDE):
     - eeprom_dump	dump the contents of the built-in EEPROM
     - i2c_scan         scan the I2C bus for slave devices
     - i2c_dump         dump the contents of I2C attached EEPROM or Memory
     - reset            restart the microcontroller (software reset)
     - help             show the available commands and how to use them

   For each of these commands the implementation is included in the CLI library.

   This sketch is free software: you can redistribute it and/or modify it under
   the terms of version 3 of the GNU General Public License as published by the
   Free Software Foundation, or (at your option) a later version of the license.

   This code is distributed in the hope that it will be useful but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along with
   this program.  If not, visit <http://www.gnu.org/licenses/> to download it.
*/

#include <CLI.h>
#include <Wire.h>

// Initialize the Debug Command Line Interface
const char banner[] PROGMEM = "Debug Sample CLI"; // Banner to show upon startup of the CLI
CLI CLI(Serial, banner);                          // Initialize the CLI, telling it to attach to Serial
EEPROM_Dump_Command EEPROM_Dump(CLI);             // Initialize/Register (built-in) eeprom_dump command
I2C_Scan_Command I2C_Scan(CLI);                   // Initialize/Register (built-in) i2c_scan command
I2C_Dump_Command I2C_Dump(CLI);                   // Initialize/Register (built-in) i2c_dump command
Reset_Command Reset(CLI);                         // Initialize/Register (built-in) reset command
Help_Command Help(CLI);                           // Initialize/Register (built-in) help command


// the setup function runs once when you reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);

  // Initialize the Serial port for the CLI
  while (!Serial); // For Leonardo: wait for serial USB to connect
  Serial.begin(9600);

  // Initialize the Wire Interface
  Wire.begin();
}


// the loop function runs over and over again forever
void loop() {
  // handle CLI, if this returns true a command is running. Set Builtin LED accordingly
  if (CLI.process()) {
    digitalWrite(LED_BUILTIN, HIGH); // turn LED on when processing CLI command
  } else {
    digitalWrite(LED_BUILTIN, LOW); // turn LED off when not processing CLI command
  }
}